From 847b504be937b13d472024555b5abd7f094aa739 Mon Sep 17 00:00:00 2001 From: wl Date: Fri, 31 Aug 2012 12:17:33 +0000 Subject: Add `pdfmom' to handle mom documents with gropdf. * Makefile.in (OTHERDIRS): Move contrib/mom to be run after devices/gropdf. * src/devices/gropdf/gropdf.pl: Various fixes: . Correct image scaling issue. . Handle relative horizontal movement 'h' followed by absolute vertical movement 'V'. . Correct handling of track kerning. * src/devices/gropdf/pdfmom.pl: New wrapper for mom (pdfmom) using gropdf or grops driver. * src/devices/gropdf/pdfmom.man: New man page. * src/devices/gropdf/Makefile.sub: Updated to handle new files. --- src/devices/gropdf/Makefile.sub | 17 +++-- src/devices/gropdf/gropdf.pl | 15 +++-- src/devices/gropdf/pdfmom.man | 140 ++++++++++++++++++++++++++++++++++++++++ src/devices/gropdf/pdfmom.pl | 82 +++++++++++++++++++++++ 4 files changed, 244 insertions(+), 10 deletions(-) create mode 100644 src/devices/gropdf/pdfmom.man create mode 100644 src/devices/gropdf/pdfmom.pl (limited to 'src') diff --git a/src/devices/gropdf/Makefile.sub b/src/devices/gropdf/Makefile.sub index 30991e52..6aa409d4 100644 --- a/src/devices/gropdf/Makefile.sub +++ b/src/devices/gropdf/Makefile.sub @@ -1,4 +1,4 @@ -# Copyright (C) 2011 Free Software Foundation, Inc. +# Copyright (C) 2011-2012 Free Software Foundation, Inc. # Written by Deri James # # This file is part of groff. @@ -17,10 +17,12 @@ # along with this program. If not, see . MAN1=\ - gropdf.n + gropdf.n \ + pdfmom.n CMDFILES=\ - gropdf + gropdf \ + pdfmom MOSTLYCLEANADD=\ gropdf \ @@ -30,7 +32,7 @@ MOSTLYCLEANADD=\ RM=rm -f -all: gropdf +all: gropdf pdfmom gropdf: gropdf.pl $(SH_DEPS_SED_SCRIPT) @@ -42,6 +44,13 @@ gropdf: gropdf.pl $(SH_DEPS_SED_SCRIPT) -e "s|@RT_SEP@|$(RT_SEP)|" $(srcdir)/gropdf.pl >$@ chmod +x $@ +pdfmom: pdfmom.pl $(SH_DEPS_SED_SCRIPT) + $(RM) $@ + sed -f $(SH_DEPS_SED_SCRIPT) \ + -e "s|@VERSION@|$(version)$(revision)|" \ + -e "s|@PERLPATH@|$(PERLPATH)|" $(srcdir)/pdfmom.pl >$@ + chmod +x $@ + install_data: -test -d $(DESTDIR)$(bindir) || $(mkinstalldirs) $(DESTDIR)$(bindir) for f in $(CMDFILES); do \ diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl index 0084b952..d8a21e25 100644 --- a/src/devices/gropdf/gropdf.pl +++ b/src/devices/gropdf/gropdf.pl @@ -907,13 +907,13 @@ sub do_x { IsGraphic(); my $bbox=$incfil{$fil}->[1]; - my $xscale=$wid/($bbox->[2]-$bbox->[0]+1); - my $yscale=($hgt<=0)?$xscale:($hgt/($bbox->[3]-$bbox->[1]+1)); + my $xscale=$wid/($bbox->[2]-$bbox->[0]); + my $yscale=($hgt<=0)?$xscale:($hgt/($bbox->[3]-$bbox->[1])); $xscale=($wid<=0)?$yscale:$xscale; $xscale=$yscale if $yscale < $xscale; $yscale=$xscale if $xscale < $yscale; - $wid=($bbox->[2]-$bbox->[0]+1)*$xscale; - $hgt=($bbox->[3]-$bbox->[1]+1)*$yscale; + $wid=($bbox->[2]-$bbox->[0])*$xscale; + $hgt=($bbox->[3]-$bbox->[1])*$yscale; if ($flag eq '-C' and $ll > $wid) { @@ -2978,7 +2978,7 @@ sub do_V } - $nomove=$pendmv=0; +# $nomove=$pendmv=0; $poschg=1; } @@ -2997,6 +2997,7 @@ sub TextWid { my $txt=shift; my $w=0; + my $ck=0; foreach my $c (split('',$txt)) { @@ -3005,7 +3006,9 @@ sub TextWid $w+=$widtbl->[$cn]; } - return($w/$unitwidth); + $ck=length($txt)*$curkern; + + return(($w/$unitwidth)+$ck); } sub do_t diff --git a/src/devices/gropdf/pdfmom.man b/src/devices/gropdf/pdfmom.man new file mode 100644 index 00000000..ef05d5e9 --- /dev/null +++ b/src/devices/gropdf/pdfmom.man @@ -0,0 +1,140 @@ +.ig +Copyright (C) 2012 + Free Software Foundation, Inc. +written by Deri James +and Peter Schaffter +# +# 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 . + +use strict; +my @cmd; +my $dev='pdf'; + +while (my $c=shift) +{ + if (substr($c,0,2) eq '-T') + { + if (length($c) > 2) + { + $dev=substr($c,2); + } + else + { + $dev=shift; + } + + next; + } + elsif ($c eq '-z' or $c eq '-Z') + { + $dev=$c; + next; + } + + elsif ($c eq '-v') + { + print "GNU pdfmom (groff) version @VERSION@\n"; + exit; + } + + push(@cmd,$c); +} + +my $cmdstring=join(' ',@cmd); + +if ($dev eq 'pdf') +{ + system("groff -Tpdf -dPDF.EXPORT=1 -mom -z $cmdstring 2>&1 | grep '^.ds' | groff -Tpdf -mom - $cmdstring"); +} +elsif ($dev eq 'ps') +{ + system("pdfroff -mpdfmark -mom --no-toc $cmdstring"); +} +elsif ($dev eq '-z') # pseudo dev - just compile for warnings +{ + system("groff -Tpdf -mom -z $cmdstring"); +} +elsif ($dev eq '-Z') # pseudo dev - produce troff output +{ + system("groff -Tpdf -mom -Z $cmdstring"); +} +else +{ + print STDERR "Not compatible with device '-T $dev'\n"; + exit 1; +} + -- cgit v1.2.1