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