From 75f10a5becbbac22add148221712ad41e3b8e61c Mon Sep 17 00:00:00 2001 From: wlemb Date: Wed, 2 Jul 2003 15:35:01 +0000 Subject: first import --- contrib/grap2graph/.cvsignore | 2 + contrib/grap2graph/Makefile.sub | 19 +++++++++ contrib/grap2graph/grap2graph.man | 89 +++++++++++++++++++++++++++++++++++++++ contrib/grap2graph/grap2graph.sh | 68 ++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 contrib/grap2graph/.cvsignore create mode 100644 contrib/grap2graph/Makefile.sub create mode 100644 contrib/grap2graph/grap2graph.man create mode 100644 contrib/grap2graph/grap2graph.sh diff --git a/contrib/grap2graph/.cvsignore b/contrib/grap2graph/.cvsignore new file mode 100644 index 00000000..44f3433a --- /dev/null +++ b/contrib/grap2graph/.cvsignore @@ -0,0 +1,2 @@ +grap2graph +grap2graph.n diff --git a/contrib/grap2graph/Makefile.sub b/contrib/grap2graph/Makefile.sub new file mode 100644 index 00000000..5527618e --- /dev/null +++ b/contrib/grap2graph/Makefile.sub @@ -0,0 +1,19 @@ +MAN1=grap2graph.n +CLEANADD=grap2graph + +all: grap2graph + +grap2graph: grap2graph.sh + rm -f $@; \ + sed -e "s|@g@|$(g)|g" \ + -e "s|@VERSION@|$(version)$(revision)|" \ + -e $(SH_SCRIPT_SED_CMD) $(srcdir)/grap2graph.sh >$@; \ + chmod +x $@ + +install_data: grap2graph + -test -d $(bindir) || $(mkinstalldirs) $(bindir) + -rm -f $(bindir)/grap2graph + $(INSTALL_SCRIPT) grap2graph $(bindir)/grap2graph + +uninstall_sub: + -rm -f $(bindir)/grap2graph diff --git a/contrib/grap2graph/grap2graph.man b/contrib/grap2graph/grap2graph.man new file mode 100644 index 00000000..548e1808 --- /dev/null +++ b/contrib/grap2graph/grap2graph.man @@ -0,0 +1,89 @@ +.\" $Id: grap2graph.man,v 1.1.1.1 2003/07/02 15:35:01 wlemb Exp $ +.\" This documentation is released to the public domain. +. +. +.TH GRAP2GRAPH @MAN1EXT@ @MDATE@ "Groff Version @VERSION@" +.IX grap2graph +.SH NAME +grap2graph \- convert a grap diagram into a cropped bitmap image +. +. +.SH SYNOPSIS +.B grap2graph +[ +.B \-unsafe +] +[ +.BI \-resolution\ M\fR|\fPMxN +] +[ +.BI \-format\ fmt +] +. +. +.SH DESCRIPTION +Reads a grap program as input; produces an image file (by default in +Portable Network Graphics format) suitable for the Web as output. +For a description of the grap language, see +.BR grap (1). +.P +Your graph specification should \fInot\fR be wrapped with the \&.G1 and +\&.G2 macros that normally guard it within +.BR groff (@MAN1EXT@) +macros. +.P +The output image will be a black-on-white graphic clipped to the +smallest possible bounding box that contains all the black pixels. +By specifying command-line options to be passed to +.BR convert (1) +you can give it a border, set the background transparent, set the +image's pixel density, or perform other useful transformations. +.P +This program uses +.BR grap (1), +.BR @g@pic (@MAN1EXT@), +.BR groff (@MAN1EXT@), +and the ImageMagick +.BR convert (1) +program. +These programs must be installed on your system and accessible on your +$PATH for \fBgrap2graph\fR to work. +. +. +.SH OPTIONS +.TP +.B \-unsafe +Run +.BR @g@pic (@MAN1EXT@) +and +.BR groff (@MAN1EXT@) +in the `unsafe' mode enabling the PIC macro +.B sh +to execute arbitrary commands. +The default is to forbid this. +.TP +.BI \-format\ fmt +Specify an output format; the default is PNG (Portable Network Graphics). +Any format that +.BR convert (1) +can emit is supported. +.PP +Command-line switches and arguments not listed above are passed to +.BR convert (1). +. +. +.SH "SEE ALSO" +.BR pic2graph (@MAN1EXT@), +.BR eqn2graph (@MAN1EXT@), +.BR @g@pic (@MAN1EXT@), +.BR groff (@MAN1EXT@), +.BR gs (1), +.BR convert (1). +. +. +.SH AUTHOR +Eric S. Raymond +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/grap2graph/grap2graph.sh b/contrib/grap2graph/grap2graph.sh new file mode 100644 index 00000000..a5380afb --- /dev/null +++ b/contrib/grap2graph/grap2graph.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# +# grap2graph -- compile graph description descriptions to bitmap images +# +# by Eric S. Raymond , May 2003 +# +# In Unixland, the magic is in knowing what to string together... +# +# Take grap description on stdin, emit cropped bitmap on stdout. +# The pic markup should *not* be wrapped in .G1/.G2, this script will do that. +# A -U option on the command line enables gpic/groff "unsafe" mode. +# A -format FOO option changes the image output format to any format +# supported by convert(1). All other options are passed to convert(1). +# The default format is PNG. +# + +# Requires the groff suite and the ImageMagick tools. Both are open source. +# This code is released to the public domain. +# +# Here are the assumptions behind the option processing: +# +# 1. None of the options of grap(1) are relevant. +# +# 2. Only the -U option of groff(1) is relevant. +# +# 3. Many options of convert(1) are potentially relevant, (especially +# -density, -interlace, -transparency, -border, and -comment). +# +# Thus, we pass -U to groff(1), and everything else to convert(1). +# +# $Id: grap2graph.sh,v 1.1.1.1 2003/07/02 15:35:01 wlemb Exp $ +# +groff_opts="" +convert_opts="" +format="png" + +while [ "$1" ] +do + case $1 in + -unsafe) + groff_opts="-U";; + -format) + format=$2 + shift;; + -v | --version) + echo "GNU grap2graph (groff) version @VERSION@" + exit 0;; + --help) + echo "usage: grap2graph [ option ...] < in > out" + exit 0;; + *) + convert_opts="$convert_opts $1";; + esac + shift +done + +# Here goes: +# 1. Add .G1/.G2. +# 2. Process through grap(1) to emit pic markup. +# 3. Process through groff(1) with pic preprocessing to emit Postscript. +# 4. Use convert(1) to crop the Postscript and turn it into a bitmap. +tmp=/usr/tmp/grap2graph-$$ +trap "rm ${tmp}.*" 0 2 15 +(echo ".G1"; cat; echo ".G2") | grap | groff -p $groff_opts -Tps | \ + convert -crop 0x0 $convert_opts - ${tmp}.${format} \ + && cat ${tmp}.${format} + +# End -- cgit v1.2.1