LCOV - code coverage report
Current view: top level - libs/libgroff - paper.cpp (source / functions) Hit Total Coverage
Test: GNU roff Lines: 39 39 100.0 %
Date: 2026-01-16 17:51:41 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright 2002-2024 Free Software Foundation, Inc.
       2             :      Written by Werner Lemberg (wl@gnu.org)
       3             : 
       4             : This file is part of groff, the GNU roff typesetting system.
       5             : 
       6             : groff is free software; you can redistribute it and/or modify it under
       7             : the terms of the GNU General Public License as published by the Free
       8             : Software Foundation, either version 3 of the License, or
       9             : (at your option) any later version.
      10             : 
      11             : groff is distributed in the hope that it will be useful, but WITHOUT ANY
      12             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14             : for more details.
      15             : 
      16             : You should have received a copy of the GNU General Public License
      17             : along with this program.  If not, see <http://www.gnu.org/licenses/>. */
      18             : 
      19             : #ifdef HAVE_CONFIG_H
      20             : #include <config.h>
      21             : #endif
      22             : 
      23             : #include "lib.h"
      24             : 
      25             : #include "paper.h"
      26             : 
      27             : paper papersizes[NUM_PAPERSIZES];
      28             : 
      29             : // length and width in mm
      30       15860 : static void add_iso_paper(char series, int offset,
      31             :                           int start_length, int start_width)
      32             : {
      33       15860 :   int length = start_length;
      34       15860 :   int width = start_width;
      35      142740 :   for (int i = 0; i < 8; i++)
      36             :   {
      37      126880 :     char *p = new char[3];
      38      126880 :     p[0] = series;
      39      126880 :     p[1] = '0' + i;
      40      126880 :     p[2] = '\0';
      41      126880 :     papersizes[offset + i].name = p;
      42             :     // convert mm to inch
      43      126880 :     papersizes[offset + i].length = (double)length / 25.4;
      44      126880 :     papersizes[offset + i].width = (double)width / 25.4;
      45             :     // after division by two, values must be rounded down to the next
      46             :     // integer (as specified by ISO)
      47      126880 :     int tmp = length;
      48      126880 :     length = width;
      49      126880 :     width = tmp / 2;
      50             :   }
      51       15860 : }
      52             : 
      53             : // length and width in inch
      54       35685 : static void add_american_paper(const char *name, int idx,
      55             :                                double length, double width )
      56             : {
      57       35685 :   char *p = new char[strlen(name) + 1];
      58       35685 :   strcpy(p, name);
      59       35685 :   papersizes[idx].name = p;
      60       35685 :   papersizes[idx].length = length;
      61       35685 :   papersizes[idx].width = width;
      62       35685 : }
      63             : 
      64             : int papersize_init::initialised = 0;
      65             : 
      66        7992 : papersize_init::papersize_init()
      67             : {
      68        7992 :   if (initialised)
      69        4027 :     return;
      70        3965 :   initialised = 1;
      71        3965 :   add_iso_paper('a', 0, 1189, 841);
      72        3965 :   add_iso_paper('b', 8, 1414, 1000);
      73        3965 :   add_iso_paper('c', 16, 1297, 917);
      74        3965 :   add_iso_paper('d', 24, 1090, 771);
      75        3965 :   add_american_paper("letter", 32, 11, 8.5);
      76        3965 :   add_american_paper("legal", 33, 14, 8.5);
      77        3965 :   add_american_paper("tabloid", 34, 17, 11);
      78        3965 :   add_american_paper("ledger", 35, 11, 17);
      79        3965 :   add_american_paper("statement", 36, 8.5, 5.5);
      80        3965 :   add_american_paper("executive", 37, 10, 7.5);
      81             :   // the next three entries are for grolj4
      82        3965 :   add_american_paper("com10", 38, 9.5, 4.125);
      83        3965 :   add_american_paper("monarch", 39, 7.5, 3.875);
      84             :   // this is an ISO format, but it easier to use add_american_paper
      85        3965 :   add_american_paper("dl", 40, 220/25.4, 110/25.4);
      86             : }
      87             : 
      88             : // Local Variables:
      89             : // fill-column: 72
      90             : // mode: C++
      91             : // End:
      92             : // vim: set cindent noexpandtab shiftwidth=2 textwidth=72:

Generated by: LCOV version 1.14