diff options
Diffstat (limited to 'Master/tlpkg/etc/test-code-for-papersize-in-perl.pl')
-rw-r--r-- | Master/tlpkg/etc/test-code-for-papersize-in-perl.pl | 136 |
1 files changed, 122 insertions, 14 deletions
diff --git a/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl b/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl index 49be2dbbd3e..1c9b6e4ba54 100644 --- a/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl +++ b/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl @@ -1,16 +1,11 @@ # # TODO TODO TODO -# what happens, especially with do_simple, if NO paper config line is -# found, so nothing has been set up. That happens with context already -# It seems that the dvipdfm/config, dvipdfmx.cfg, XDvi we are shipping -# already all have a line. But what happens if someone has a line -# hanging around? +# if no paperconfig line is found in do_simple it adds to the end of the +# file the new line, but this does not work on context because it +# has an \endinput at the end ... needs to be fixed # -# For dvipdfm(x) and xdvi I have fixed that by adding a line at the -# bottom. -# -# For context this doesn't work because there is an \endinput there!!! +# output is done to stdout, not the right config file # $^W = 1; use strict; @@ -107,6 +102,8 @@ if ($what eq "dvips") { do_dvipdfmx(@ARGV); } elsif ($what eq "context") { do_context(@ARGV); +} elsif ($what eq "pdftex") { + do_pdftex(@ARGV); } elsif ($what eq "xdvi") { do_xdvi(@ARGV); } else { @@ -115,7 +112,113 @@ if ($what eq "dvips") { } exit 0; +# +# pdftex pdftexconfig.tex format +# /--- pdftexconfig.tex --- +# |... +# |\pdfpagewidth=NNN true <unit> +# |\pdfpageheight=NNN true <unit> +# |... +# \------------------------ +# +# Reading is done via --progname=pdftex --format='tex' pdftexconfig.tex +# Writing is done to TEXMFSYSCONFIG/tex/generic/config/pdftexconfig.tex +# +sub do_pdftex { + my $newpaper = shift; + my $cf = `kpsewhich --progname=pdftex --format=tex pdftexconfig.tex`; + chomp($cf); + print STDERR "file used for pdftex: $cf\n"; + open(FOO, "<$cf") or die("cannot open file: $!"); + my @lines = <FOO>; + close(FOO); + + my ($cpw, $cph); + my ($cpwidx, $cphidx); + my $endinputidx; + # read the lines and the last pdfpageswidth/height wins + for my $idx (0..$#lines) { + my $l = $lines[$idx]; + if ($l =~ m/^\s*\\pdfpagewidth\s*=?\s*(.+)\s*$/) { + $cpw = $1; + $cpwidx = $idx; + next; + } + if ($l =~ m/^\s*\\pdfpageheight\s*=?\s*(.+)\s*$/) { + $cph = $1; + $cphidx = $idx; + next; + } + if ($l =~ m/^\s*\\endinput\s*/) { + $endinputidx = $idx; + next; + } + } + # trying to find the right papersize + # + my $currentpaper; + if (defined($cpw) && defined($cph)) { + for my $pname (keys %pdftex_papersize) { + my ($w, $h) = @{$pdftex_papersize{$pname}}; + if (($w eq $cpw) && ($h eq $cph)) { + $currentpaper = $pname; + last; + } + } + } else { + $currentpaper = "(undefined)"; + } + $currentpaper || ($currentpaper = "$cpw x $cph"); + if (defined($newpaper)) { + if ($newpaper eq "--list") { + print "$currentpaper\n"; + for my $p (keys %pdftex_papersize) { + print "$p\n" unless ($p eq $currentpaper); + } + } else { + my $found = 0; + for my $p (keys %pdftex_papersize) { + if ($p eq $newpaper) { + $found = 1; + last; + } + } + if ($found) { + my $newwline = + '\pdfpagewidth=' . ${$pdftex_papersize{$newpaper}}[0] . "\n"; + my $newhline = + '\pdfpageheight=' . ${$pdftex_papersize{$newpaper}}[1] . "\n"; + if (defined($cpwidx)) { + $lines[$cpwidx] = $newwline; + } else { + if (defined($endinputidx)) { + $lines[$endinputidx] = $newwline . $lines[$endinputidx]; + } else { + $lines[$#lines] = $newwline; + } + } + if (defined($cphidx)) { + $lines[$cphidx] = $newhline; + } else { + if (defined($endinputidx)) { + $lines[$endinputidx] = $newhline . $lines[$endinputidx]; + } else { + $lines[$#lines] = $newwline; + } + } + for (@lines) { print; } + } else { + warn "Not a valid paper size for pdftex: $newpaper\n"; + } + } + } else { + # just print the current value + print "current pdftex paper size: $currentpaper\n"; + } +} + +############################################### # # dvips config.ps format: # /--- config.ps --- @@ -260,7 +363,7 @@ sub do_context { return($ll); } }, "tex/context/user/cont-sys.rme", \@bla, - '\setuppapersize[a4][a4]', $newpaper); + 'a4', '\setuppapersize[a4][a4]', $newpaper); } @@ -286,7 +389,7 @@ sub do_xdvi { $ll =~ s/^\*paper:\s+(\w+)\s*$/\*paper: $np\n/; return($ll); }, "xdvi/XDvi", \@bla, - '*paper: a4', $newpaper); + '(not defined)', '*paper: a4', $newpaper); } @@ -312,7 +415,7 @@ sub do_dvipdfm_and_x { my ($ll,$np) = @_; $ll =~ s/^p\s+(\w+)\s*$/p $np\n/; return($ll); - }, $outp, $paplist, 'p a4', $newpaper); + }, $outp, $paplist, '(not defined)', 'p a4', $newpaper); } sub do_dvipdfm { @@ -347,9 +450,13 @@ sub do_dvipdfmx { # $firstre are shipped over to $bl # $outp .. location of the output file # $paplist .. ref to an array with the list of admissible paper sizes +# $defaultpaper .. default papersize (arbitrary string) if the $firstre is +# not found in the config file +# $defaultline .. the line to be added at the bottom of the file if +# no line has been found # $newpaper .. --list, new paper, or undef sub do_simple { - my ($inp, $prog, $firstre, $secondre, $bl, $outp, $paplist, $defaultline, $newpaper) = @_; + my ($inp, $prog, $firstre, $secondre, $bl, $outp, $paplist, $defaultpaper, $defaultline, $newpaper) = @_; print STDERR "file used for $prog: $inp\n"; @@ -360,7 +467,7 @@ sub do_simple { my $currentpaper; my @paperlines = grep (m/$firstre/,@lines); if (!@paperlines) { - $currentpaper = "(undefined)"; + $currentpaper = $defaultpaper; } else { if ($#paperlines > 0) { warn "Strange, more than one paper definiton, using the first one!\n"; @@ -400,6 +507,7 @@ sub do_simple { if (!$foundcfg) { push @newlines, &$bl($defaultline, $newpaper); } + # should save to $outf for (@newlines) { print; } } else { warn "Not a valid paper size for $prog: $newpaper\n"; |