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