groff: update vendor branch to v1.20.1
[dragonfly.git] / contrib / groff / src / libs / libgroff / paper.cpp
CommitLineData
92d0a6a6 1// -*- C++ -*-
4d3e9548 2/* Copyright (C) 2002, 2003, 2004, 2009
92d0a6a6
JR
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
4d3e9548
JL
10Software Foundation, either version 3 of the License, or
11(at your option) any later version.
92d0a6a6
JR
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
4d3e9548
JL
18You should have received a copy of the GNU General Public License
19along with this program. If not, see <http://www.gnu.org/licenses/>. */
92d0a6a6
JR
20
21#include "lib.h"
22#include "paper.h"
23
24paper papersizes[NUM_PAPERSIZES];
25
26// length and width in mm
27static void add_iso_paper(char series, int offset,
28 int start_length, int start_width)
29{
30 int length = start_length;
31 int width = start_width;
32 for (int i = 0; i < 8; i++)
33 {
34 char *p = new char[3];
35 p[0] = series;
36 p[1] = '0' + i;
37 p[2] = '\0';
38 papersizes[offset + i].name = p;
39 // convert mm to inch
40 papersizes[offset + i].length = (double)length / 25.4;
41 papersizes[offset + i].width = (double)width / 25.4;
42 // after division by two, values must be rounded down to the next
43 // integer (as specified by ISO)
44 int tmp = length;
45 length = width;
46 width = tmp / 2;
47 }
48}
49
50// length and width in inch
51static void add_american_paper(const char *name, int idx,
52 double length, double width )
53{
54 char *p = new char[strlen(name) + 1];
55 strcpy(p, name);
56 papersizes[idx].name = p;
57 papersizes[idx].length = length;
58 papersizes[idx].width = width;
59}
60
61int papersize_init::initialised = 0;
62
63papersize_init::papersize_init()
64{
65 if (initialised)
66 return;
67 initialised = 1;
68 add_iso_paper('a', 0, 1189, 841);
69 add_iso_paper('b', 8, 1414, 1000);
70 add_iso_paper('c', 16, 1297, 917);
71 add_iso_paper('d', 24, 1090, 771);
72 add_american_paper("letter", 32, 11, 8.5);
73 add_american_paper("legal", 33, 14, 8.5);
74 add_american_paper("tabloid", 34, 17, 11);
75 add_american_paper("ledger", 35, 11, 17);
76 add_american_paper("statement", 36, 8.5, 5.5);
77 add_american_paper("executive", 37, 10, 7.5);
78 // the next three entries are for grolj4
79 add_american_paper("com10", 38, 9.5, 4.125);
80 add_american_paper("monarch", 39, 7.5, 3.875);
81 // this is an ISO format, but it easier to use add_american_paper
82 add_american_paper("dl", 40, 220/25.4, 110/25.4);
83}