summaryrefslogtreecommitdiffstats
path: root/contrib/pic2graph
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:44:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:44:05 +0000
commitd318611dd6f23fcfedd50e9b9e24620b102ba96a (patch)
tree8b9eef82ca40fdd5a8deeabf07572074c236095d /contrib/pic2graph
parentInitial commit. (diff)
downloadgroff-upstream.tar.xz
groff-upstream.zip
Adding upstream version 1.23.0.upstream/1.23.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'contrib/pic2graph')
-rw-r--r--contrib/pic2graph/pic2graph.1.man234
-rw-r--r--contrib/pic2graph/pic2graph.am40
-rw-r--r--contrib/pic2graph/pic2graph.sh122
3 files changed, 396 insertions, 0 deletions
diff --git a/contrib/pic2graph/pic2graph.1.man b/contrib/pic2graph/pic2graph.1.man
new file mode 100644
index 0000000..f3c1c1e
--- /dev/null
+++ b/contrib/pic2graph/pic2graph.1.man
@@ -0,0 +1,234 @@
+.TH pic2graph @MAN1EXT@ "@MDATE@" "groff @VERSION@"
+.SH Name
+pic2graph \- convert a
+.I pic
+diagram into a cropped image
+.
+.
+.\" ====================================================================
+.\" Legal Terms
+.\" ====================================================================
+.\"
+.\" This documentation is released to the public domain.
+.
+.
+.\" Save and disable compatibility mode (for, e.g., Solaris 10/11).
+.do nr *groff_pic2graph_1_man_C \n[.cp]
+.cp 0
+.
+.\" Define fallback for groff 1.23's MR macro if the system lacks it.
+.nr do-fallback 0
+.if !\n(.f .nr do-fallback 1 \" mandoc
+.if \n(.g .if !d MR .nr do-fallback 1 \" older groff
+.if !\n(.g .nr do-fallback 1 \" non-groff *roff
+.if \n[do-fallback] \{\
+. de MR
+. ie \\n(.$=1 \
+. I \%\\$1
+. el \
+. IR \%\\$1 (\\$2)\\$3
+. .
+.\}
+.rr do-fallback
+.
+.
+.\" ====================================================================
+.SH Synopsis
+.\" ====================================================================
+.
+.SY pic2graph
+.RB [ \-unsafe ]
+.RB [ \-format\~\c
+.IR output-format ]
+.RB [ \-eqn\~\c
+.IR delimiters ]
+.RI [ convert-argument \~.\|.\|.]
+.YS
+.
+.
+.SY pic2graph
+.B \-\-help
+.YS
+.
+.
+.SY pic2graph
+.B \-v
+.
+.SY pic2graph
+.B \-\-version
+.YS
+.
+.
+.\" ====================================================================
+.SH Description
+.\" ====================================================================
+.
+.I pic2graph
+reads a
+.MR @g@pic @MAN1EXT@
+program from the standard input and writes an image file,
+by default in Portable Network Graphics (PNG) format,
+to the standard output.
+.
+It furthermore translates
+.MR @g@eqn @MAN1EXT@
+constructs, so it can be used for generating images of mathematical
+formulae.
+.
+.
+.PP
+The input PIC code should
+.I not
+be wrapped with the
+.B .PS
+and
+.BR .PE / .PF
+macros that normally guard it within
+.MR groff @MAN1EXT@
+documents.
+.
+.
+.\" FIXME: How old? This text hasn't been touched since 2008 at latest.
+.\" Older versions of
+.\" .I \%convert
+.\" will produce a black-on-white graphic; newer ones may produce a
+.\" black-on-transparent graphic.
+.
+.PP
+Arguments not recognized by
+.I pic2graph
+are passed to the ImageMagick or GraphicsMagick program
+.MR convert 1 .
+.
+.
+By specifying these, you can give your image a border,
+.\" Transparent backgrounds are the default in 2018.
+.\" force the background transparent,
+set the image's pixel density,
+or perform other useful transformations.
+.
+.
+.PP
+The output image is clipped using
+.IR \%convert 's
+.B \-trim
+option to the smallest possible bounding box that contains all the black
+pixels.
+.
+.
+.\" ====================================================================
+.SH Options
+.\" ====================================================================
+.
+.B \-\-help
+displays a usage message,
+while
+.B \-v
+and
+.B \-\-version
+show version information;
+all exit afterward.
+.
+.TP
+.BI \-eqn\~ delimiters
+Use
+.I delimiters
+as the opening and closing
+characters that delimit
+.I @g@eqn
+directives;
+the default is \(lq$$\(rq.
+.
+The option argument
+.I delimiters
+should be a two-character string,
+but an empty string (\(dq\(dq) is accepted as a directive to disable
+.I @g@eqn
+processing.
+.
+.
+.TP
+.BI \-format\~ output-format
+Write the image in
+.IR output-format ,
+which must be understood by
+.IR \%convert ;
+the default is PNG.
+.
+.
+.TP
+.B \-unsafe
+Run
+.I groff
+in
+.I unsafe
+mode, enabling the PIC command
+.B sh
+to execute arbitrary Unix shell commands.
+.
+The
+.I groff
+default is to forbid this.
+.
+.
+.\" ====================================================================
+.SH Environment
+.\" ====================================================================
+.
+.TP
+.I \%GROFF_TMPDIR
+.TQ
+.I \%TMPDIR
+.TQ
+.I TMP
+.TQ
+.I TEMP
+These environment variables are searched in the given order to determine
+the directory where temporary files will be created.
+.
+If none are set,
+.I /tmp
+is used.
+.
+.
+.\" ====================================================================
+.SH Authors
+.\" ====================================================================
+.
+.I pic2graph
+was written by
+.MT esr@\:thyrsus\:.com
+Eric S.\& Raymond
+.ME ,
+based on a recipe by W.\& Richard Stevens.
+.
+.
+.\" ====================================================================
+.SH "See also"
+.\" ====================================================================
+.
+W.\& Richard Stevens,
+.UR http://\:www\:.kohala\:.com/\:start/\:troff/\:pic2html\:.html
+.I Turning PIC into HTML
+.UE
+.
+.
+.PP
+.MR eqn2graph @MAN1EXT@ ,
+.MR grap2graph @MAN1EXT@ ,
+.MR @g@pic @MAN1EXT@ ,
+.MR @g@eqn @MAN1EXT@ ,
+.MR groff @MAN1EXT@ ,
+.MR convert 1
+.
+.
+.\" Restore compatibility mode (for, e.g., Solaris 10/11).
+.cp \n[*groff_pic2graph_1_man_C]
+.do rr *groff_pic2graph_1_man_C
+.
+.
+.\" Local Variables:
+.\" fill-column: 72
+.\" mode: nroff
+.\" End:
+.\" vim: set filetype=groff textwidth=72:
diff --git a/contrib/pic2graph/pic2graph.am b/contrib/pic2graph/pic2graph.am
new file mode 100644
index 0000000..9788270
--- /dev/null
+++ b/contrib/pic2graph/pic2graph.am
@@ -0,0 +1,40 @@
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# pic2graph.am
+#
+
+pic2graph_srcdir = $(top_srcdir)/contrib/pic2graph
+man1_MANS += contrib/pic2graph/pic2graph.1
+bin_SCRIPTS += pic2graph
+EXTRA_DIST += \
+ contrib/pic2graph/pic2graph.sh \
+ contrib/pic2graph/pic2graph.1.man
+
+pic2graph: $(pic2graph_srcdir)/pic2graph.sh
+ $(AM_V_GEN)sed -e "s|[@]g[@]|$(g)|g" \
+ -e "s|[@]VERSION[@]|$(VERSION)|" \
+ -e $(SH_SCRIPT_SED_CMD) $(pic2graph_srcdir)/pic2graph.sh \
+ >$@ \
+ && chmod +x $@
+
+
+# Local Variables:
+# fill-column: 72
+# mode: makefile-automake
+# End:
+# vim: set autoindent filetype=automake textwidth=72:
diff --git a/contrib/pic2graph/pic2graph.sh b/contrib/pic2graph/pic2graph.sh
new file mode 100644
index 0000000..b229914
--- /dev/null
+++ b/contrib/pic2graph/pic2graph.sh
@@ -0,0 +1,122 @@
+#! /bin/sh
+#
+# pic2graph -- compile PIC image descriptions to bitmap images
+#
+# by Eric S. Raymond <esr@thyrsus.com>, July 2002
+
+# In Unixland, the magic is in knowing what to string together...
+#
+# Take a pic/eqn diagram on stdin, emit cropped bitmap on stdout.
+# The pic markup should *not* be wrapped in .PS/.PE, this script will do that.
+# An -unsafe 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). An -eqn option changes the eqn delimiters.
+# All other options are passed to convert(1). The default format in 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. Only the -U option of gpic(1) is relevant. -C doesn't matter because
+# we're generating our own .PS/.PE, -[ntcz] are irrelevant because we're
+# generating Postscript.
+#
+# 2. Ditto for groff(1), though it's a longer and more tedious demonstration.
+#
+# 3. Many options of convert(1) are potentially relevant (especially
+# -density, -interlace, -transparency, -border, and -comment).
+#
+# Thus, we pass -U to gpic and groff, and everything else to convert(1).
+#
+# We don't have complete option coverage on eqn because this is primarily
+# intended as a pic translator; we can live with eqn defaults.
+#
+groffpic_opts=""
+convert_opts=""
+convert_trim_arg="-trim"
+format="png"
+eqndelim='$$'
+
+while [ "$1" ]
+do
+ case $1 in
+ -unsafe)
+ groffpic_opts="-U";;
+ -format)
+ format=$2
+ shift;;
+ -eqn)
+ eqndelim=$2
+ shift;;
+ -v | --version)
+ echo "GNU pic2graph (groff) version @VERSION@"
+ exit 0;;
+ --help)
+ echo "usage: pic2graph [ option ...] < in > out"
+ exit 0;;
+ *)
+ convert_opts="$convert_opts $1";;
+ esac
+ shift
+done
+
+if [ "$eqndelim" ]
+then
+ eqndelim="delim $eqndelim"
+fi
+
+# create temporary directory
+tmp=
+for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp
+do
+ test -n "$d" && break
+done
+
+if ! test -d "$d"
+then
+ echo "$0: error: temporary directory \"$d\" does not exist or is" \
+ "not a directory" >&2
+ exit 1
+fi
+
+if ! tmp=`(umask 077 && mktemp -d -q "$d/pic2graph-XXXXXX") 2> /dev/null`
+then
+ # mktemp failed--not installed or is a version that doesn't support those
+ # flags? Fall back to older method which uses more predictable naming.
+ #
+ # $RANDOM is a Bashism. The fallback of $PPID is not good pseudorandomness,
+ # but is supported by the stripped-down dash shell, for instance.
+ tmp="$d/pic2graph$$-${RANDOM:-$PPID}"
+ (umask 077 && mkdir "$tmp") 2> /dev/null
+fi
+
+if ! test -d "$tmp"
+then
+ echo "$0: error: cannot create temporary directory \"$tmp\"" >&2
+ exit 1
+fi
+
+# See if the installed version of convert(1) is new enough to support the -trim
+# option. Versions that didn't were described as "old" as early as 2008.
+is_convert_recent=`convert -help | grep -e -trim`
+if test -z "$is_convert_recent"
+then
+ echo "$0: warning: falling back to old '-crop 0x0' trim method" >&2
+ convert_trim_arg="-crop 0x0"
+fi
+
+trap 'exit_status=$?; rm -rf "$tmp" && exit $exit_status' EXIT INT TERM
+
+# Here goes:
+# 1. Wrap the input in dummy .PS/PE macros (and add possibly null .EQ/.EN)
+# 2. Process through eqn and pic to emit troff markup.
+# 3. Process through groff to emit Postscript.
+# 4. Use convert(1) to crop the PostScript and turn it into a bitmap.
+(echo ".EQ"; echo $eqndelim; echo ".EN"; echo ".PS"; cat; echo ".PE") | \
+ groff -e -p $groffpic_opts -Tps -P-pletter > "$tmp"/pic2graph.ps \
+ && convert $convert_trim_arg $convert_opts "$tmp"/pic2graph.ps \
+ "$tmp"/pic2graph.$format \
+ && cat "$tmp"/pic2graph.$format
+
+# End