Home | History | Annotate | Line # | Download | only in libgroff
      1 /*	$NetBSD: paper.cpp,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $	*/
      2 
      3 // -*- C++ -*-
      4 /* Copyright (C) 2002, 2003, 2004
      5    Free Software Foundation, Inc.
      6      Written by Werner Lemberg (wl (at) gnu.org)
      7 
      8 This file is part of groff.
      9 
     10 groff is free software; you can redistribute it and/or modify it under
     11 the terms of the GNU General Public License as published by the Free
     12 Software Foundation; either version 2, or (at your option) any later
     13 version.
     14 
     15 groff is distributed in the hope that it will be useful, but WITHOUT ANY
     16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
     17 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     18 for more details.
     19 
     20 You should have received a copy of the GNU General Public License along
     21 with groff; see the file COPYING.  If not, write to the Free Software
     22 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
     23 
     24 #include "lib.h"
     25 #include "paper.h"
     26 
     27 paper papersizes[NUM_PAPERSIZES];
     28 
     29 // length and width in mm
     30 static void add_iso_paper(char series, int offset,
     31 			  int start_length, int start_width)
     32 {
     33   int length = start_length;
     34   int width = start_width;
     35   for (int i = 0; i < 8; i++)
     36   {
     37     char *p = new char[3];
     38     p[0] = series;
     39     p[1] = '0' + i;
     40     p[2] = '\0';
     41     papersizes[offset + i].name = p;
     42     // convert mm to inch
     43     papersizes[offset + i].length = (double)length / 25.4;
     44     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     int tmp = length;
     48     length = width;
     49     width = tmp / 2;
     50   }
     51 }
     52 
     53 // length and width in inch
     54 static void add_american_paper(const char *name, int idx,
     55 			       double length, double width )
     56 {
     57   char *p = new char[strlen(name) + 1];
     58   strcpy(p, name);
     59   papersizes[idx].name = p;
     60   papersizes[idx].length = length;
     61   papersizes[idx].width = width;
     62 }
     63 
     64 int papersize_init::initialised = 0;
     65 
     66 papersize_init::papersize_init()
     67 {
     68   if (initialised)
     69     return;
     70   initialised = 1;
     71   add_iso_paper('a', 0, 1189, 841);
     72   add_iso_paper('b', 8, 1414, 1000);
     73   add_iso_paper('c', 16, 1297, 917);
     74   add_iso_paper('d', 24, 1090, 771);
     75   add_american_paper("letter", 32, 11, 8.5);
     76   add_american_paper("legal", 33, 14, 8.5);
     77   add_american_paper("tabloid", 34, 17, 11);
     78   add_american_paper("ledger", 35, 11, 17);
     79   add_american_paper("statement", 36, 8.5, 5.5);
     80   add_american_paper("executive", 37, 10, 7.5);
     81   // the next three entries are for grolj4
     82   add_american_paper("com10", 38, 9.5, 4.125);
     83   add_american_paper("monarch", 39, 7.5, 3.875);
     84   // this is an ISO format, but it easier to use add_american_paper
     85   add_american_paper("dl", 40, 220/25.4, 110/25.4);
     86 }
     87