groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PROPOSAL] Generating consistent papersizes


From: Alexis
Subject: [PROPOSAL] Generating consistent papersizes
Date: Sat, 5 Aug 2023 21:47:45 +0200

Hi folks,

in brief: while looking into paper sizes available in GNU troff I
noticed some inconsistencies in the device support, e.g.: grops(1)
accepts the dl paper size, yet gropdf(1) does not recognize it and
gropdf accepts l-suffixed paper size variants, e.g. a4l yet grops
does not.

In detail: I'd like to print envelopes using groff, looking at
tmac/papersizes.tmac I was happy to see that the dl format was already
defined. Unfortunately gropdf ignores dl as an unrecognized paper format:

  % echo '\\$' | ./dist/bin/groff -Tps -P-pdl | ps2pdf - - | pdfinfo - | grep 
^Page[^s]
  Page size:       312 x 624 pts
  Page rot:        0
  % echo '\\$' | ./dist/bin/groff -Tpdf -P-pdl | pdfinfo - | grep ^Page[^s]
  $HOME/Developer/groff/build/dist/bin/gropdf: warning: ignoring unrecognized 
paper format(s) 'dl'
  Page size:       595 x 842 pts (A4)
  Page rot:        0

Continuing with my experiments I was delighted that gropdf accepts
l-suffixed paper sizes to indicate landscape format, e.g. a4l.
Additionally specifying the -l flag in actually flips the result
back into portrait again:

  % echo -e "\\&" | ./dist/bin/groff -dpaper=dll -Tpdf -P-pa4l | pdfinfo - | 
grep ^Page[^s]
  Page size:       842 x 595 pts (A4)
  Page rot:        0
  echo -e "\\&" | ./dist/bin/groff -dpaper=dll -Tpdf -P-pa4l -P-l | pdfinfo - | 
grep ^Page[^s]
  Page size:       842 x 595 pts (A4)
  Page rot:        90

Unfortunately l-suffixed paper sizes aren't recognized by grops:

  % echo -e "\\&" | ./dist/bin/groff -dpaper=dll -Tps -P-pa4l | ps2pdf - - | 
pdfinfo - | grep ^Page[^s]
  grops: error: ignoring invalid custom paper format 'a4l'
  Page size:       612 x 792 pts (letter)
  Page rot:        0

Taking a closer look at the sources there seem to be various places
where paper sizes are defined, so far I've found:

  - tmac/papersize.tmac
      used to processes the -dpaper= groff option

  - src/devices/gropdf/gropdf.pl
       used to handle arguments given to the -p option

  - src/libs/libgroff/paper.cpp, src/libs/libgroff/font.cpp
      used to handle papersize directives in DESC files

  - src/devices/grolbp/lbp.cpp, src/devices/grolj4/lj4.cpp
      if I understand correctly
      used to define paper format indexes in physical printers

Being an avid proponent of single sources of truth I set out to prototype
a solution that defines dimension-based paper formats in a single place
and can be used to generate code for where the paper sizes are needed
in groff.

The prototype consists of a simple bash script (papersizes.bash)
acting as the single source of truth for paper sizes and
generating lines specifying a paper format, e.g.:

  % ./papersizes.bash | grep -E '(dl|monarch)'
  dl 220 110 metric
  monarch 7.5 3.875 imperial

Each line consists of the paper format name, width, height and dimension
unit indicator (metric or imperial)

These lines are then processed by simple awk scripts to generate the
desired output format, which may include transforming the dimension
values into other units, e.g. points:

  % ./papersizes.bash | /usr/bin/env LC_NUMERIC=C awk -f 
papersizes2gropdf.pl.awk | sed -e '7,47d'
  my %ppsz=(
          'a0'=>[2384,3370],
          'a1'=>[1684,2384],
          'a2'=>[1191,1684],
          'a3'=>[842,1191],
          'a4'=>[595,842],
          'tabloid'=>[792,1224],
          'ledger'=>[1224,792],
          'statement'=>[396,612],
          'executive'=>[522,756],
          'monarch'=>[540,279],
          'com10'=>[684,297],
  );

The generated code can then be manually inserted into the appropriate
source files. The prototype includes transformation scripts for
gropdf.pl, papersizes.tmac, and paper.cpp.
The attached patch (generated-papersizes.patch) contain the changes made
with the prototype.

Attached is another patch (l-suffix-papersize.patch), that changes
font::scan_papersize, so that it will also accept l-suffixed paper sizes,
e.g. a4l, and swap the paper width and height to change the paper format
to landscape.

Taking a closer look at papersizes.bash you may notice that additional
paper sizes have been defined, e.g. jrlegal (Junior Legal) and 7-10
formats in the B and C series. I also added the historical D series from
DIN 476, more for testing purposes and out of interest than anything else.

Another thing I noticed is that the dl format is defined in portrait
format, i.e. 11c x 22c (width x height) in papersize.tmac, I'm probably
missing something related to printers and paper feeds, yet to me
defining the dl format in landscape, i.e. 22c x 11c makes more sense
as they open on the long side.
I took the liberty of re-defining dl in landscape format in
papersizes.bash, and can imagine such a change possibly having too
grave implications to be accepted.

I'd like to get a conversation going of whether folks see the need to
update and possibly even improve the current definition of paper sizes
and whether there is merit to an approach as proposed by the prototype.
How could something like this be done in a way that possibly better fits
groff's development philosophy? Does autoconf support code generation?
Should papersizes.bash be rewritten in Perl?


Best
Alexis

Attachment: papersizes.bash
Description: Text document

Attachment: papersizes2gropdf.pl.awk
Description: Text document

Attachment: papersizes2papersize.tmac.awk
Description: Text document

Attachment: papersizes2paper.cpp.awk
Description: Text document

Attachment: generated-papersizes.patch
Description: Text document

Attachment: l-suffix-papersize.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]