diff options
author | wl <wl> | 2012-05-20 13:58:09 +0000 |
---|---|---|
committer | wl <wl> | 2012-05-20 13:58:09 +0000 |
commit | 0ba10d251a10e8b7453fad8877e529a5c2e26f96 (patch) | |
tree | 816dea7244660f65e6fae78b540b8dafafbd949a /src | |
parent | 496b379176b94e41aa03f7779bb3bac06e91c783 (diff) | |
download | groff-0ba10d251a10e8b7453fad8877e529a5c2e26f96.tar.gz |
* doc/groff.texinfo: Add extra info about `.asciify'.
Document new gropdf options -u and -s.
* src/devices/gropdf/gropdf.man: Remove references to Type 42 fonts,
they do not work in PDFs.
Document new option -s which adds `statistics' line to end of PDF
file showing number of pages in document. This has always been the
default behaviour (to add this line), all other software seems to
ignore it as intended, but `gs' sometimes complains, so the default
is now to omit the statistics.
Document new option -u[cmapfilename] to allow a user ToUnicode CMap
instead of gropdf's default. If no `cmapfilename' given then do not
include any ToUnicode CMap.
* src/devices/gropdf/gropdf.pl <top>: Allow `bundled' flags on
command line (i.e. -de = -d -e).
Use $RT_SEP as multi path separator, not hard coded `:'. Update all
users.
New flags -u and -s.
Once a custom papersize has been set as \X'papersize x,y' make it
sticky so all following pages use custom size.
When importing pdf with \X'pdf: pdfpic ...' do not compress objects
which are already compressed! This caused problems with PDFs
created with ImageMagick, now fixed.
(IsText, PutLine, do_t): The troff `u' command can contain a kerning
adjustment number, this was not being handled, now fixed.
(do_c): The troff `c' command was not being handled correctly, now
fixed.
(FindChar, RemapChr, do_N): Handle fonts with more than 255 glyphs.
($ucmap): Define CMap ToUnicode to convert ligatures
(fl,fi,ff,ffl,ffi) back to individual characters, useful for
cut'n'paste and text searching.
(LoadFont): Handle it.
(ToPoints, GetPoints): Handle `z' unit.
(do_x, FixPDFColour, PutHotSpot): Allow Annotation colour to be
groff colour, i.e. 0-65535 *3, or #rrggbb, or #rrrrbbbbgggg.
(do_p):The papersize width/length in switch -p were reversed,
corrected.
* src/devices/gropdf/Makefile.sub (gropdf): Use $RT_SEP.
Use $fontpath rather than $fontdir (this ensures site-font is
included in searches).
* tmac/pdf.tmac (PDFBOOKMARK.VIEW, PDFHREF.VIEW, PDFPAGE.Y): Fix
strings.
(pdfbookmark): Correct handling of bookmark levels.
Convert \[em] to hyphen in bookmarks
Rather use -N than -T for "named" bookmarks (-T already used for "tag"
in pdfmark.tmac)
(.pdfclean): New macro which attempts to asciify bookmark text.
(.pdfpagename): New wrapper macro for \X'pdf: pagename'.
(.pdfswitchtopage): New wrapper macro for \X'pdf: switchtopage'.
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/gropdf/Makefile.sub | 5 | ||||
-rw-r--r-- | src/devices/gropdf/gropdf.man | 114 | ||||
-rw-r--r-- | src/devices/gropdf/gropdf.pl | 218 |
3 files changed, 236 insertions, 101 deletions
diff --git a/src/devices/gropdf/Makefile.sub b/src/devices/gropdf/Makefile.sub index c876c925..30991e52 100644 --- a/src/devices/gropdf/Makefile.sub +++ b/src/devices/gropdf/Makefile.sub @@ -30,7 +30,7 @@ MOSTLYCLEANADD=\ RM=rm -f -all: gropdf +all: gropdf gropdf: gropdf.pl $(SH_DEPS_SED_SCRIPT) @@ -38,7 +38,8 @@ gropdf: gropdf.pl $(SH_DEPS_SED_SCRIPT) sed -f $(SH_DEPS_SED_SCRIPT) \ -e "s|@VERSION@|$(version)$(revision)|" \ -e "s|@PERLPATH@|$(PERLPATH)|" \ - -e "s|@GROFF_FONT_DIR@|$(fontdir)|" $(srcdir)/gropdf.pl >$@ + -e "s|@GROFF_FONT_DIR@|$(fontpath)|" \ + -e "s|@RT_SEP@|$(RT_SEP)|" $(srcdir)/gropdf.pl >$@ chmod +x $@ install_data: diff --git a/src/devices/gropdf/gropdf.man b/src/devices/gropdf/gropdf.man index a26a314b..d7953e09 100644 --- a/src/devices/gropdf/gropdf.man +++ b/src/devices/gropdf/gropdf.man @@ -1,5 +1,5 @@ .ig -Copyright (C) 2011 +Copyright (C) 2011-2012 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of @@ -43,12 +43,13 @@ gropdf \- PDF driver for groff .SH SYNOPSIS . .SY gropdf -.OP \-delv +.OP \-delvs .OP \-F dir \#.OP \-I dir .OP \-p papersize \#.OP \-w n .OP \-y foundry +.OP \-u [cmapfile] .RI [ files .IR .\|.\|. ] .YS @@ -188,7 +189,30 @@ Set the foundry to use for selecting fonts of the same name. . .TP .B \-e -Forces gropdf to embed ALL fonts (even the 14 base PDF fonts). +Forces +.B gropdf +to embed ALL fonts (even the 14 base PDF fonts). +. +.TP +.B \-s +Append a comment line to end of PDF showing statistics, +i.e. number of pages in document. +Ghostscript's +.B ps2pdf +complains about this line if it is included, but works anyway. +. +.TP +.B \-u +.TQ +.BI \-u cmapfilename +.B Gropdf +normally includes a ToUnicode CMap with any font created using +.B text.enc +as the encoding file, +this makes it easier to search for words which contain ligatures. +You can include your own CMap by specifying a +.I cmapfilename +or have no CMap at all by omitting the argument. . . .SH USAGE @@ -677,17 +701,17 @@ The following tags are supported: .BI "\[rs]X'pdf: pdfpic " "file alignment width height line-length" ' Place an image of the specified .I width -containing the PDF drawing from file +containing the PDF drawing from file .I file -of desired +of desired .I width and .I height -(if +(if .I height is missing or zero then it is scaled proportionally). . -If +If .I alignment is .B \-L @@ -701,7 +725,7 @@ a .I linelength greater than the width of the drawing is required as well. . -If +If .I width is specified as zero then the width is scaled in proportion to the height. . @@ -804,52 +828,7 @@ will now load successfully. .SS TrueType and other font formats . .B gropdf -does not support TrueType fonts natively within the PDF files it generates -(but does support any fonts if they are in an imported PDF). -. -However, TrueType fonts can be used with -.B gropdf -if converted first to -.B Type\~42 -format, a special PostScript wrapper equivalent to the PFA format mentioned -in -.BR \%pfbtops (@MAN1EXT@). -. -There are several different methods to generate a Type\~42 -wrapper and most of them involve the use of a PostScript -interpreter such as Ghostscript \[en] see -.BR gs (1). -. -.LP -Yet, the easiest method involves the use of the application -.BR ttftot42 (1). -. -This program uses -.BR freetype (3) -(version 1.3.1) to generate Type\~42 -font wrappers and well-formed AFM files that can be fed to the -.BR \%afmtodit (@MAN1EXT@) -script to create appropriate metric files. -. -The resulting font wrappers should be added to groff's -.B download -file. -. -.B ttftot42 -source code can be downloaded from -.UR ftp://\:www.giga.or.at/\:pub/\:nih/\:ttftot42/ -ftp://\:www.giga.or.at/\:pub/\:nih/\:ttftot42/ -.UE . -. -.LP -Another solution for creating Type\~42 wrappers is to use FontForge, -available from -.UR http://\:fontforge.sf.net -http://\:fontforge.sf.net -.UE . -. -This font editor can convert most outline font formats. -. +does not support any other fonts except Adobe Type 1 (PFA or PFB). . .SH FONT INSTALLATION . @@ -865,8 +844,8 @@ as a step-by-step font installation guide for .LI Convert your font to something groff understands. . -This is either a PostScript Type\~1 font in either PFA or PFB format or a -PostScript Type\~42 font, together with an AFM file. +This is either a PostScript Type\~1 font in either PFA or PFB, +together with an AFM file. . .IP The very first line in a PFA/PFB file contains this: @@ -880,29 +859,6 @@ The very first line in a PFA/PFB file contains this: A PFB file has this also in the first line, but the string is preceded with some binary bytes. . -.IP -The very first characters in a Type\~42 font file look like this: -. -.RS -.IP -.B %!PS-TrueTypeFont -.RE -. -.IP -This is a wrapper format for TrueType fonts. -. -Old PS printers might not support it (this is, they don't have a -built-in TrueType font interpreter). -. -.IP -For TrueType fonts, try -.B ttftot42 -or -.BR fontforge . -For all other font formats use -.B fontforge -which can convert most outline font formats. -. .LI Convert the AFM file to a groff font description file with the .BR \%afmtodit (@MAN1EXT@) diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl index 9dbc4884..ad198bcc 100644 --- a/src/devices/gropdf/gropdf.pl +++ b/src/devices/gropdf/gropdf.pl @@ -23,13 +23,14 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. use strict; -use Getopt::Long; +use Getopt::Long qw(:config bundling); use Compress::Zlib; my %cfg; $cfg{GROFF_VERSION}='@VERSION@'; $cfg{GROFF_FONT_PATH}='@GROFF_FONT_DIR@'; +$cfg{RT_SEP}='@RT_SEP@'; binmode(STDOUT); my @obj; # Array of PDF objects @@ -98,6 +99,8 @@ my $n_flg=1; my $pginsert=-1; # Growth point for kids array my %pgnames; # 'names' of pages for switchtopage my @outlines=(); # State of Bookmark Outlines at end of each page +my $custompaper=0; # Has there been an X papersize +my $textenccmap=''; # CMap for groff text.enc encoding my %ppsz=( 'ledger'=>[1224,792], 'legal'=>[612,1008], @@ -128,6 +131,29 @@ my %ppsz=( 'ledger'=>[1224,792], 'c5'=>[459,649], 'c6'=>[323,459] ); +my $ucmap=<<'EOF'; +/CIDInit /ProcSet findresource begin +12 dict begin +begincmap +/CIDSystemInfo +<< /Registry (Adobe) +/Ordering (UCS) +/Supplement 0 +>> def +/CMapName /Adobe-Identity-UCS def +/CMapType 2 def +1 begincodespacerange +<0000> <FFFF> +endcodespacerange +2 beginbfrange +<008b> <008f> [<00660066> <00660069> <0066006c> <006600660069> <00660066006C>] +<00ad> <00ad> <002d> +endbfrange +endcmap +CMapName currentdict /CMap defineresource pop +end +end +EOF my $fd; my $frot; @@ -135,10 +161,12 @@ my $fpsz; my $embedall=0; my $debug=0; my $version=0; +my $stats=0; +my $unicodemap; #Load_Config(); -GetOptions("F=s" => \$fd, 'l' => \$frot, 'p=s' => \$fpsz, 'd!' => \$debug, 'v' => \$version, 'e' => \$embedall, 'y=s' => \$Foundry); +GetOptions("F=s" => \$fd, 'l' => \$frot, 'p=s' => \$fpsz, 'd!' => \$debug, 'v' => \$version, 'e' => \$embedall, 'y=s' => \$Foundry, 's' => \$stats, 'u:s' => \$unicodemap); if ($version) { @@ -146,11 +174,30 @@ if ($version) exit; } +if (defined($unicodemap)) +{ + if ($unicodemap eq '') + { + $ucmap=''; + } + elsif (-r $unicodemap) + { + local $/; + open(F,"<$unicodemap") or die "gropdf: Failed to open '$unicodemap'"; + ($ucmap)=(<F>); + close(F); + } + else + { + Msg(0,"Failed to find '$unicodemap' - ignoring"); + } +} + # Search for 'font directory': paths in -f opt, shell var GROFF_FONT_PATH, default paths my $fontdir=$cfg{GROFF_FONT_PATH}; -$fontdir=$ENV{GROFF_FONT_PATH}.':'.$fontdir if exists($ENV{GROFF_FONT_PATH}); -$fontdir=$fd.':'.$fontdir if defined($fd); +$fontdir=$ENV{GROFF_FONT_PATH}.$cfg{RT_SEP}.$fontdir if exists($ENV{GROFF_FONT_PATH}); +$fontdir=$fd.$cfg{RT_SEP}.$fontdir if defined($fd); $rot=90 if $frot; $matrix="0 1 -1 0" if $frot; @@ -267,6 +314,19 @@ my $info=BuildObj(++$objct,\%info); PutObj($objct); +foreach my $fontno (keys %fontlst) +{ + my $o=$fontlst{$fontno}->{FNT}; + my $p=GetObj($fontlst{$fontno}->{OBJ}); + + if (exists($p->{LastChar}) and $p->{LastChar} > 255) + { + $p->{LastChar} = 255; + splice(@{$o->{GNO}},256); + splice(@{$o->{WID}},256); + } +} + foreach my $o (3..$objct) { PutObj($o) if (!exists($obj[$o]->{XREF})); @@ -287,7 +347,8 @@ foreach my $xr (@obj) printf("%010d 00000 n \n",$xr->{XREF}); } -print "trailer\n<<\n/Info $info\n/Root 1 0 R\n/Size $objct\n>>\nstartxref\n$fct\n\%\%EOF\n\% Pages=$pages->{Count}\n"; +print "trailer\n<<\n/Info $info\n/Root 1 0 R\n/Size $objct\n>>\nstartxref\n$fct\n\%\%EOF\n"; +print "\% Pages=$pages->{Count}\n" if $stats; sub MakeMatrix @@ -431,6 +492,10 @@ sub ToPoints { return($num*6); } + elsif ($unit eq 'z') + { + return($num/$unitwidth); + } else { Msg(1,"Unknown scaling factor '$unit'"); @@ -488,7 +553,7 @@ sub OpenFile return if -r "$fnm" and open($$f,"<$fnm"); } - my (@dirs)=split(':',$dirs); + my (@dirs)=split($cfg{RT_SEP},$dirs); foreach my $dir (@dirs) { @@ -683,6 +748,7 @@ sub do_x my $annot=$obj[$objct]; $annot->{DATA}->{Type}='/Annot'; FixRect($annot->{DATA}->{Rect}); # Y origin to ll + FixPDFColour($annot->{DATA}); push(@{$cpage->{Annots}},$annotno); } elsif ($pdfmark=~m/(.+) \/OUT/) @@ -988,11 +1054,54 @@ sub do_x @mediabox=(0,0,$px,$py); my @mb=@mediabox; $matrixchg=1; + $custompaper=1; $cpage->{MediaBox}=\@mb; } } } +sub FixPDFColour +{ + my $o=shift; + my $a=$o->{C}; + my @r=(); + my $c=$a->[0]; + + if ($#{$a}==3) + { + if ($c > 1) + { + foreach my $j (0..2) + { + push(@r,sprintf("%1.3f",$a->[$j]/0xffff)); + } + + $o->{C}=\@r; + } + } + elsif (substr($c,0,1) eq '#') + { + if (length($c) == 7) + { + foreach my $j (0..2) + { + push(@r,sprintf("%1.3f",hex(substr($c,$j*2+1,2))/0xff)); + } + + $o->{C}=\@r; + } + elsif (length($c) == 14) + { + foreach my $j (0..2) + { + push(@r,sprintf("%1.3f",hex(substr($c,$j*4+2,4))/0xffff)); + } + + $o->{C}=\@r; + } + } +} + sub PutHotSpot { my $endx=shift; @@ -1005,6 +1114,7 @@ sub PutHotSpot my $annot=$obj[$objct]; $annot->{DATA}->{Type}='/Annot'; $annot->{DATA}->{Rect}=[$mark->{xpos},$mark->{ypos}-$mark->{rsb},$endx+$mark->{lead},$mark->{ypos}-$mark->{rst}]; + FixPDFColour($annot->{DATA}); FixRect($annot->{DATA}->{Rect}); # Y origin to ll push(@{$cpage->{Annots}},$annotno); } @@ -1029,7 +1139,7 @@ sub GetPoints { my $val=shift; - $val=ToPoints($1,$2) if ($val=~m/(-?[\d.]+)([cipn])/); + $val=ToPoints($1,$2) if ($val=~m/(-?[\d.]+)([cipnz])/); return $val; } @@ -1762,7 +1872,7 @@ sub PutObj $obj[$ono]->{XREF}=$fct; if (exists($obj[$ono]->{STREAM})) { - if (!$debug) + if (!$debug && !exists($obj[$ono]->{DATA}->{'Filter'})) { $obj[$ono]->{STREAM}=Compress::Zlib::compress($obj[$ono]->{STREAM}); $obj[$ono]->{DATA}->{'Filter'}=['/FlateDecode']; @@ -1899,7 +2009,7 @@ sub LoadFont } $r[0]='u0020' if $r[3] == 32; - next if $r[3] >255; +# next if $r[3] >255; $fnt{GNM}->{$r[0]}=$r[3]; $fnt{GNO}->[$r[3]]='/'.$r[4]; $fnt{WID}->[$r[3]]=$p[0]; @@ -2007,10 +2117,21 @@ sub LoadFont $fontlst{$fontno}->{FNT}=\%fnt; } - PutObj($fno); - PutObj($fno+1); - PutObj($fno+2) if defined($obj[$fno+2]); - PutObj($fno+3) if defined($obj[$fno+3]); + if (defined($fnt{encoding}) and $fnt{encoding} eq 'text.enc' and $ucmap ne '') + { + if ($textenccmap eq '') + { + $textenccmap = BuildObj($objct+1,{}); + $objct++; + $obj[$objct]->{STREAM}=$ucmap; + } + $obj[$fno]->{DATA}->{'ToUnicode'}=$textenccmap; + } + +# PutObj($fno); +# PutObj($fno+1); +# PutObj($fno+2) if defined($obj[$fno+2]); +# PutObj($fno+3) if defined($obj[$fno+3]); } sub GetType1 @@ -2164,6 +2285,7 @@ sub do_p if ($cpageno > 0) { + $cpage->{MediaBox}=\@mediabox if $custompaper; PutObj($cpageno); OutStream($cpageno+1); } @@ -2189,7 +2311,7 @@ sub do_p $stream="q 1 0 0 1 0 0 cm\n"; $mode='g'; $curfill=''; - @mediabox=@defaultmb; +# @mediabox=@defaultmb; } sub do_f @@ -2248,6 +2370,7 @@ sub IsText $whtsz=$fontlst{$cft}->{FNT}->{spacewidth}*$cftsz; $stream.="/F$cft $cftsz Tf\n"; } + $stream.="$curkern Tc\n"; } if ($poschg or $matrixchg) @@ -2256,6 +2379,7 @@ sub IsText $stream.="$matrix ".PutXY($xpos,$ypos)." Tm\n", $poschg=0; $tmxpos=$xpos; $matrixchg=0; + $stream.="$curkern Tc\n"; } if ($fontchg) @@ -2768,8 +2892,16 @@ sub PutLine # $wt+=$whtsz/$cftsz; # } - $stream.=sprintf( "%.3f Tw ",-($whtsz+$wt*$cftsz)/$unitwidth ); - $stream.="[("; + $stream.=sprintf( "%.3f Tw ",-($whtsz+$wt*$cftsz)/$unitwidth-$curkern ); + if (!defined($lin[0]->[0]) and defined($lin[0]->[1])) + { + $stream.="[ $lin[0]->[1] ("; + shift @lin; + } + else + { + $stream.="[("; + } foreach my $wd (@lin) { @@ -2787,6 +2919,7 @@ sub PutLine } else { + $wwt=sprintf("%.3f",$wwt); $stream.="$wd->[0]) $wwt (" if defined($wd->[0]); } } @@ -2936,11 +3069,13 @@ sub do_t PutLine(0) if $#lin > -1; MakeMatrix(1); $stream.="$matrix ".PutXY($xpos,$ypos)." Tm\n", $poschg=0; + $stream.="$curkern Tc\n"; $stream.="0 Tw "; $stream.="($par) Tj\n"; MakeMatrix(); $stream.="$matrix ".PutXY($xpos,$ypos)." Tm\n", $poschg=0; $matrixchg=0; + $stream.="$curkern Tc\n"; return; } @@ -3021,11 +3156,14 @@ sub do_C sub FindChar { my $chnm=shift; + my $fnt=$fontlst{$cft}->{FNT}; - if (exists($fontlst{$cft}->{FNT}->{GNM}->{$chnm})) + if (exists($fnt->{GNM}->{$chnm})) { - my $ch=$fontlst{$cft}->{FNT}->{GNM}->{$chnm}; - return(chr($ch),$fontlst{$cft}->{FNT}->{WID}->[$ch]*$cftsz); + my $ch=$fnt->{GNM}->{$chnm}; + $ch=RemapChr($ch,$fnt,$chnm) if ($ch > 255); + + return(chr($ch),$fnt->{WID}->[$ch]*$cftsz); } else { @@ -3033,6 +3171,33 @@ sub FindChar } } +sub RemapChr +{ + my $ch=shift; + my $fnt=shift; + my $chnm=shift; + my $unused=0; + + foreach my $un (2..$#{$fnt->{GNO}}) + { + $unused=$un,last if $fnt->{GNO}->[$un] eq '/.notdef'; + } + + if (--$unused <= 255) + { + $fnt->{GNM}->{$chnm}=$unused++; + $fnt->{GNO}->[$unused]=$fnt->{GNO}->[$ch+1]; + $fnt->{WID}->[$unused]=$fnt->{WID}->[$ch+1]; + $ch=$unused-1; + return($ch); + } + else + { + Msg(0,"Too many glyphs used in font '$cft'"); + return(32); + } +} + sub do_c { my $par=shift; @@ -3040,7 +3205,7 @@ sub do_c push(@ahead,substr($par,1)); $par=substr($par,0,1); my $ch=ord($par); - do_t($ch); + do_N($ch); $nomove=$fontlst{$cft}->{FNT}->{WID}->[$ch]*$cftsz; } @@ -3048,6 +3213,19 @@ sub do_N { my $par=shift; + if ($par > 255) + { + my $fnt=$fontlst{$cft}->{FNT}; + my $chnm=''; + + foreach my $c (keys %{$fnt->{GNM}}) + { + $chnm=$c,last if $fnt->{GNM}->{$c} == $par; + } + + $par=RemapChr($par,$fnt,$chnm); + } + do_t(chr($par)); $nomove=$fontlst{$cft}->{FNT}->{WID}->[$par]*$cftsz; } |