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
#!/usr/bin/env bash

#
# papersize.bash - Single source of truth for GNU troff papersizes
#
# Generates a list of paper formats which can then be transformed
# into generated code for gropdf, papersize.tmac, and libgroff.
# See accompanying gropdf.pl.awk, papersize.tmac.awk, paper.cpp.awk.
#

# Generate paper format for given series and start dimensions
# Returns lines that specify the paper format name and dimensions (width x 
height)
# and dimension unit indicator metric implying millimeters, e.g.:
# a4 210 297 metric
function iso() {
  series=$1 # The name of the series
  width=$2  # The starting width
  height=$3 # The starting height
  count=$4  # The number of formats to generate, e.g. 10 = A0-A10
  for format in $(seq 0 $count); do
    metric $series$format $width $height
    tmp=$height
    height=$width
    width=$(( tmp / 2 ))
  done
}

# Prints the given first 3 arguments and
# appends the metric dimension unit indicator implying millimeters, e.g.:
# $1 $2 $3 metric
function metric() {
  echo ${1:-unknown} ${2:-0} ${3:-0} metric
}

# Prints the given first 3 arguments and
# appends the imperial dimension unit indicator implying inches, e.g.:
# $1 $2 $3 imperial
function imperial() {
  echo ${1:-unknown} ${2:-0} ${3:-0} imperial
}

#
# Single source of truth for papersizes
#

# ISO Papersizes specified in millimeters
iso a  841 1189 10 
iso b 1000 1414 10 
iso c  917 1297 10 
iso d  771 1090  8 

# ISO Envelopes
metric dl 220 110

# US Papersizes specified in inches
imperial letter     8.5  11
imperial legal      8.5  14
imperial jrlegal    5     8
imperial tabloid   11    17
imperial ledger    17    11
imperial statement  5.5   8.5
# These dimensions for executive paper format are what all printer 
manufacturers use.
imperial executive  7.25 10.5

# US Envelopes
imperial monarch 7.5  3.875
imperial com10   9.5  4.125
# Transforms papersize input lines generated by ./genpapersize.bash into
# a Perl papersize lookup table ($ppsz) for use in src/devices/gropdf/gropdf.pl
BEGIN { print "my %ppsz=(" }
/metric$/{ d = 25.4 }
/imperial$/{ d = 1 }
{
  # printf with %.0f is deliberately chosen to get more accurate point values 
after "rounding"
  printf "\t'%s'=>[%.0f,%.0f],\n", $1, ($2 / d * 72), ($3 / d * 72)
}
END { print ");" }
# Transforms papersize input lines generated by ./genpapersize.bash into
# a troff requests defining papersize string for use in tmac/papersize.tmac.
# Note: The .ds request are grouped inside a \{\ \}, so it is easier to
# manually replace them, e.g. in Vim: /^\.  \{/
c%
BEGIN { print ".  \\{\\" }
/metric$/{ w = ($2 / 10); l = ($3 / 10); u = "c" }
/imperial$/{ w = $2; l = $3; u = "i" }
{
  print ".  ds paper-" $1 "-length", l u
  print ".  ds paper-" $1 "-width", w u
}
END { print ".  \\}" }
# Transforms papersize input lines generated by ./genpapersize.bash into
# a C++ code that initializes lookup table (papersizes) for use in 
src/libs/libgroff/paper.cpp
BEGIN {
  print "\n\
#include \"lib.h\"\n\
#include \"paper.h\"\n\
int papersize_init::initialised = 0;\n\
papersize_init::papersize_init()\n\
{\n\
  if (initialised)\n\
    return;\n\
  initialised = 1;\
  "
}
/metric$/{ d = 25.4 }
/imperial$/{ d = 1 }
{
  idx = NR-1
  print "  papersizes[" idx "].name = \"" $1 "\";"
  print "  papersizes[" idx "].width = " ($2 / d) ";"
  print "  papersizes[" idx "].length = " ($3 / d ) ";"
}
END {
  print "}"
  print "unsigned short num_papersizes = " NR ";"
  print "paper papersizes[" NR "];"
}
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index 0e1b612a5..8c744704c 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -150,20 +150,17 @@ my $bgbox='';             # Draw commands for boxes on 
this page
 $noslide=1 if exists($ENV{GROPDF_NOSLIDE}) and $ENV{GROPDF_NOSLIDE};
 
 my %ppsz=(
-       'ledger'=>[1224,792],
-       'legal'=>[612,1008],
-       'letter'=>[612,792],
        'a0'=>[2384,3370],
        'a1'=>[1684,2384],
        'a2'=>[1191,1684],
        'a3'=>[842,1191],
        'a4'=>[595,842],
        'a5'=>[420,595],
-       'a6'=>[297,420],
-       'a7'=>[210,297],
-       'a8'=>[148,210],
-       'a9'=>[105,148],
-       'a10'=>[73,105],
+       'a6'=>[298,420],
+       'a7'=>[210,298],
+       'a8'=>[147,210],
+       'a9'=>[105,147],
+       'a10'=>[74,105],
        'b0'=>[2835,4008],
        'b1'=>[2004,2835],
        'b2'=>[1417,2004],
@@ -171,6 +168,10 @@ my %ppsz=(
        'b4'=>[709,1001],
        'b5'=>[499,709],
        'b6'=>[354,499],
+       'b7'=>[249,354],
+       'b8'=>[176,249],
+       'b9'=>[125,176],
+       'b10'=>[88,125],
        'c0'=>[2599,3677],
        'c1'=>[1837,2599],
        'c2'=>[1298,1837],
@@ -178,7 +179,29 @@ my %ppsz=(
        'c4'=>[649,918],
        'c5'=>[459,649],
        'c6'=>[323,459],
-       'com10'=>[297,684],
+       'c7'=>[230,323],
+       'c8'=>[162,230],
+       'c9'=>[113,162],
+       'c10'=>[79,113],
+       'd0'=>[2186,3090],
+       'd1'=>[1545,2186],
+       'd2'=>[1091,1545],
+       'd3'=>[771,1091],
+       'd4'=>[544,771],
+       'd5'=>[386,544],
+       'd6'=>[272,386],
+       'd7'=>[193,272],
+       'd8'=>[136,193],
+       'dl'=>[624,312],
+       'letter'=>[612,792],
+       'legal'=>[612,1008],
+       'jrlegal'=>[360,576],
+       'tabloid'=>[792,1224],
+       'ledger'=>[1224,792],
+       'statement'=>[396,612],
+       'executive'=>[522,756],
+       'monarch'=>[540,279],
+       'com10'=>[684,297],
 );
 
 my $ucmap=<<'EOF';
diff --git a/src/include/paper.h b/src/include/paper.h
index ed789c4b6..553f782b3 100644
--- a/src/include/paper.h
+++ b/src/include/paper.h
@@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public 
License
 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 struct paper {
-  char *name;
+  const char *name;
   double length;               // in PS points
   double width;                        // in PS points
 };
@@ -30,7 +30,5 @@ public:
   papersize_init();
 } _papersize_init;
 
-// A0-A7, B0-B7, C0-C7, D0-D7, 8 American paper sizes, 1 special size */
-#define NUM_PAPERSIZES 4*8 + 8 + 1
-
 extern paper papersizes[];
+extern unsigned short num_papersizes;
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index c1af12ca9..97017d0b2 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -746,7 +746,7 @@ again:
   }
   else {
     int i;
-    for (i = 0; i < NUM_PAPERSIZES; i++)
+    for (i = 0; i < num_papersizes; i++) {
       if (strcasecmp(papersizes[i].name, pp) == 0) {
        if (length)
          *length = papersizes[i].length;
@@ -756,6 +756,7 @@ again:
          *size = papersizes[i].name;
        return true;
       }
+    }
     if (attempt_file_open) {
       FILE *fp = fopen(p, "r");
       if (fp != 0) {
diff --git a/src/libs/libgroff/paper.cpp b/src/libs/libgroff/paper.cpp
index 842f3690c..d5c56b2a7 100644
--- a/src/libs/libgroff/paper.cpp
+++ b/src/libs/libgroff/paper.cpp
@@ -20,43 +20,6 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include "lib.h"
 #include "paper.h"
 
-paper papersizes[NUM_PAPERSIZES];
-
-// length and width in mm
-static void add_iso_paper(char series, int offset,
-                         int start_length, int start_width)
-{
-  int length = start_length;
-  int width = start_width;
-  for (int i = 0; i < 8; i++)
-  {
-    char *p = new char[3];
-    p[0] = series;
-    p[1] = '0' + i;
-    p[2] = '\0';
-    papersizes[offset + i].name = p;
-    // convert mm to inch
-    papersizes[offset + i].length = (double)length / 25.4;
-    papersizes[offset + i].width = (double)width / 25.4;
-    // after division by two, values must be rounded down to the next
-    // integer (as specified by ISO)
-    int tmp = length;
-    length = width;
-    width = tmp / 2;
-  }
-}
-
-// length and width in inch
-static void add_american_paper(const char *name, int idx,
-                              double length, double width )
-{
-  char *p = new char[strlen(name) + 1];
-  strcpy(p, name);
-  papersizes[idx].name = p;
-  papersizes[idx].length = length;
-  papersizes[idx].width = width;
-}
-
 int papersize_init::initialised = 0;
 
 papersize_init::papersize_init()
@@ -64,19 +27,163 @@ papersize_init::papersize_init()
   if (initialised)
     return;
   initialised = 1;
-  add_iso_paper('a', 0, 1189, 841);
-  add_iso_paper('b', 8, 1414, 1000);
-  add_iso_paper('c', 16, 1297, 917);
-  add_iso_paper('d', 24, 1090, 771);
-  add_american_paper("letter", 32, 11, 8.5);
-  add_american_paper("legal", 33, 14, 8.5);
-  add_american_paper("tabloid", 34, 17, 11);
-  add_american_paper("ledger", 35, 11, 17);
-  add_american_paper("statement", 36, 8.5, 5.5);
-  add_american_paper("executive", 37, 10, 7.5);
-  // the next three entries are for grolj4
-  add_american_paper("com10", 38, 9.5, 4.125);
-  add_american_paper("monarch", 39, 7.5, 3.875);
-  // this is an ISO format, but it easier to use add_american_paper
-  add_american_paper("dl", 40, 220/25.4, 110/25.4);
+  papersizes[0].name = "a0";
+  papersizes[0].width = 33.1102;
+  papersizes[0].length = 46.811;
+  papersizes[1].name = "a1";
+  papersizes[1].width = 23.3858;
+  papersizes[1].length = 33.1102;
+  papersizes[2].name = "a2";
+  papersizes[2].width = 16.5354;
+  papersizes[2].length = 23.3858;
+  papersizes[3].name = "a3";
+  papersizes[3].width = 11.6929;
+  papersizes[3].length = 16.5354;
+  papersizes[4].name = "a4";
+  papersizes[4].width = 8.26772;
+  papersizes[4].length = 11.6929;
+  papersizes[5].name = "a5";
+  papersizes[5].width = 5.82677;
+  papersizes[5].length = 8.26772;
+  papersizes[6].name = "a6";
+  papersizes[6].width = 4.13386;
+  papersizes[6].length = 5.82677;
+  papersizes[7].name = "a7";
+  papersizes[7].width = 2.91339;
+  papersizes[7].length = 4.13386;
+  papersizes[8].name = "a8";
+  papersizes[8].width = 2.04724;
+  papersizes[8].length = 2.91339;
+  papersizes[9].name = "a9";
+  papersizes[9].width = 1.45669;
+  papersizes[9].length = 2.04724;
+  papersizes[10].name = "a10";
+  papersizes[10].width = 1.02362;
+  papersizes[10].length = 1.45669;
+  papersizes[11].name = "b0";
+  papersizes[11].width = 39.3701;
+  papersizes[11].length = 55.6693;
+  papersizes[12].name = "b1";
+  papersizes[12].width = 27.8346;
+  papersizes[12].length = 39.3701;
+  papersizes[13].name = "b2";
+  papersizes[13].width = 19.685;
+  papersizes[13].length = 27.8346;
+  papersizes[14].name = "b3";
+  papersizes[14].width = 13.8976;
+  papersizes[14].length = 19.685;
+  papersizes[15].name = "b4";
+  papersizes[15].width = 9.84252;
+  papersizes[15].length = 13.8976;
+  papersizes[16].name = "b5";
+  papersizes[16].width = 6.92913;
+  papersizes[16].length = 9.84252;
+  papersizes[17].name = "b6";
+  papersizes[17].width = 4.92126;
+  papersizes[17].length = 6.92913;
+  papersizes[18].name = "b7";
+  papersizes[18].width = 3.46457;
+  papersizes[18].length = 4.92126;
+  papersizes[19].name = "b8";
+  papersizes[19].width = 2.44094;
+  papersizes[19].length = 3.46457;
+  papersizes[20].name = "b9";
+  papersizes[20].width = 1.73228;
+  papersizes[20].length = 2.44094;
+  papersizes[21].name = "b10";
+  papersizes[21].width = 1.22047;
+  papersizes[21].length = 1.73228;
+  papersizes[22].name = "c0";
+  papersizes[22].width = 36.1024;
+  papersizes[22].length = 51.063;
+  papersizes[23].name = "c1";
+  papersizes[23].width = 25.5118;
+  papersizes[23].length = 36.1024;
+  papersizes[24].name = "c2";
+  papersizes[24].width = 18.0315;
+  papersizes[24].length = 25.5118;
+  papersizes[25].name = "c3";
+  papersizes[25].width = 12.7559;
+  papersizes[25].length = 18.0315;
+  papersizes[26].name = "c4";
+  papersizes[26].width = 9.01575;
+  papersizes[26].length = 12.7559;
+  papersizes[27].name = "c5";
+  papersizes[27].width = 6.37795;
+  papersizes[27].length = 9.01575;
+  papersizes[28].name = "c6";
+  papersizes[28].width = 4.48819;
+  papersizes[28].length = 6.37795;
+  papersizes[29].name = "c7";
+  papersizes[29].width = 3.18898;
+  papersizes[29].length = 4.48819;
+  papersizes[30].name = "c8";
+  papersizes[30].width = 2.24409;
+  papersizes[30].length = 3.18898;
+  papersizes[31].name = "c9";
+  papersizes[31].width = 1.5748;
+  papersizes[31].length = 2.24409;
+  papersizes[32].name = "c10";
+  papersizes[32].width = 1.10236;
+  papersizes[32].length = 1.5748;
+  papersizes[33].name = "d0";
+  papersizes[33].width = 30.3543;
+  papersizes[33].length = 42.9134;
+  papersizes[34].name = "d1";
+  papersizes[34].width = 21.4567;
+  papersizes[34].length = 30.3543;
+  papersizes[35].name = "d2";
+  papersizes[35].width = 15.1575;
+  papersizes[35].length = 21.4567;
+  papersizes[36].name = "d3";
+  papersizes[36].width = 10.7087;
+  papersizes[36].length = 15.1575;
+  papersizes[37].name = "d4";
+  papersizes[37].width = 7.55906;
+  papersizes[37].length = 10.7087;
+  papersizes[38].name = "d5";
+  papersizes[38].width = 5.35433;
+  papersizes[38].length = 7.55906;
+  papersizes[39].name = "d6";
+  papersizes[39].width = 3.77953;
+  papersizes[39].length = 5.35433;
+  papersizes[40].name = "d7";
+  papersizes[40].width = 2.67717;
+  papersizes[40].length = 3.77953;
+  papersizes[41].name = "d8";
+  papersizes[41].width = 1.88976;
+  papersizes[41].length = 2.67717;
+  papersizes[42].name = "letter";
+  papersizes[42].width = 8.5;
+  papersizes[42].length = 11;
+  papersizes[43].name = "legal";
+  papersizes[43].width = 8.5;
+  papersizes[43].length = 14;
+  papersizes[44].name = "jrlegal";
+  papersizes[44].width = 5;
+  papersizes[44].length = 8;
+  papersizes[45].name = "tabloid";
+  papersizes[45].width = 11;
+  papersizes[45].length = 17;
+  papersizes[46].name = "ledger";
+  papersizes[46].width = 17;
+  papersizes[46].length = 11;
+  papersizes[47].name = "statement";
+  papersizes[47].width = 5.5;
+  papersizes[47].length = 8.5;
+  papersizes[48].name = "executive";
+  papersizes[48].width = 7.5;
+  papersizes[48].length = 10;
+  papersizes[49].name = "monarch";
+  papersizes[49].width = 7.5;
+  papersizes[49].length = 3.875;
+  papersizes[50].name = "com10";
+  papersizes[50].width = 9.5;
+  papersizes[50].length = 4.125;
+  papersizes[51].name = "dl";
+  papersizes[51].width = 8.66142;
+  papersizes[51].length = 4.33071;
 }
+
+unsigned short num_papersizes = 52;
+paper papersizes[52];
diff --git a/tmac/papersize.tmac b/tmac/papersize.tmac
index e10219ad5..06fe5a1c6 100644
--- a/tmac/papersize.tmac
+++ b/tmac/papersize.tmac
@@ -36,7 +36,14 @@
 .  ds paper-a5-width 14.8c
 .  ds paper-a6-length 14.8c
 .  ds paper-a6-width 10.5c
-.
+.  ds paper-a7-length 10.5c
+.  ds paper-a7-width 7.4c
+.  ds paper-a8-length 7.4c
+.  ds paper-a8-width 5.2c
+.  ds paper-a9-length 5.2c
+.  ds paper-a9-width 3.7c
+.  ds paper-a10-length 3.7c
+.  ds paper-a10-width 2.6c
 .  ds paper-b0-length 141.4c
 .  ds paper-b0-width 100c
 .  ds paper-b1-length 100c
@@ -51,7 +58,14 @@
 .  ds paper-b5-width 17.6c
 .  ds paper-b6-length 17.6c
 .  ds paper-b6-width 12.5c
-.
+.  ds paper-b7-length 12.5c
+.  ds paper-b7-width 8.8c
+.  ds paper-b8-length 8.8c
+.  ds paper-b8-width 6.2c
+.  ds paper-b9-length 6.2c
+.  ds paper-b9-width 4.4c
+.  ds paper-b10-length 4.4c
+.  ds paper-b10-width 3.1c
 .  ds paper-c0-length 129.7c
 .  ds paper-c0-width 91.7c
 .  ds paper-c1-length 91.7c
@@ -66,8 +80,15 @@
 .  ds paper-c5-width 16.2c
 .  ds paper-c6-length 16.2c
 .  ds paper-c6-width 11.4c
-.
-.  ds paper-d0-length 109.0c
+.  ds paper-c7-length 11.4c
+.  ds paper-c7-width 8.1c
+.  ds paper-c8-length 8.1c
+.  ds paper-c8-width 5.7c
+.  ds paper-c9-length 5.7c
+.  ds paper-c9-width 4c
+.  ds paper-c10-length 4c
+.  ds paper-c10-width 2.8c
+.  ds paper-d0-length 109c
 .  ds paper-d0-width 77.1c
 .  ds paper-d1-length 77.1c
 .  ds paper-d1-width 54.5c
@@ -81,28 +102,30 @@
 .  ds paper-d5-width 13.6c
 .  ds paper-d6-length 13.6c
 .  ds paper-d6-width 9.6c
-.
+.  ds paper-d7-length 9.6c
+.  ds paper-d7-width 6.8c
+.  ds paper-d8-length 6.8c
+.  ds paper-d8-width 4.8c
 .  ds paper-letter-length 11i
 .  ds paper-letter-width 8.5i
 .  ds paper-legal-length 14i
 .  ds paper-legal-width 8.5i
+.  ds paper-jrlegal-length 8i
+.  ds paper-jrlegal-width 5i
 .  ds paper-tabloid-length 17i
 .  ds paper-tabloid-width 11i
 .  ds paper-ledger-length 11i
 .  ds paper-ledger-width 17i
 .  ds paper-statement-length 8.5i
 .  ds paper-statement-width 5.5i
-.  \" These dimensions for executive paper format are what all printer
-.  \" manufacturers use.
-.  ds paper-executive-length 10.5i
-.  ds paper-executive-width 7.25i
-.
-.  ds paper-com10-length 9.5i
-.  ds paper-com10-width 4.125i
-.  ds paper-monarch-length 7.5i
-.  ds paper-monarch-width 3.875i
-.  ds paper-dl-length 22c
-.  ds paper-dl-width 11c
+.  ds paper-executive-length 10i
+.  ds paper-executive-width 7.5i
+.  ds paper-monarch-length 3.875i
+.  ds paper-monarch-width 7.5i
+.  ds paper-com10-length 4.125i
+.  ds paper-com10-width 9.5i
+.  ds paper-dl-length 11c
+.  ds paper-dl-width 22c
 .
 .  \" Save the input parameter for a later diagnostic.
 .  ds paper-arg \*[paper]\"
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 97017d0b2..923b501c9 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -22,6 +22,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <ctype.h>
 #include <math.h>
 #include <stdlib.h>
+#include <string.h>
 #include <wchar.h>
 
 #include "errarg.h"
@@ -746,7 +747,22 @@ again:
   }
   else {
     int i;
+    char *bb = NULL;
+    size_t lc = strlen(pp)-1;
+    if (pp[lc] == 'l') {
+       bb = new char[lc];
+       strncpy(bb, pp, lc);
+    }
     for (i = 0; i < num_papersizes; i++) {
+      if (bb &&  strcasecmp(papersizes[i].name, bb) == 0) {
+       if (length)
+         *length = papersizes[i].width;
+       if (width)
+         *width = papersizes[i].length;
+       if (size)
+         *size = papersizes[i].name;
+       return true;
+      }
       if (strcasecmp(papersizes[i].name, pp) == 0) {
        if (length)
          *length = papersizes[i].length;
@@ -757,6 +773,7 @@ again:
        return true;
       }
     }
+    delete[] bb;
     if (attempt_file_open) {
       FILE *fp = fopen(p, "r");
       if (fp != 0) {

Reply via email to