paper.cpp revision 151497
1168404Spjd// -*- C++ -*-
2168404Spjd/* Copyright (C) 2002, 2003, 2004
3168404Spjd   Free Software Foundation, Inc.
4168404Spjd     Written by Werner Lemberg (wl@gnu.org)
5168404Spjd
6168404SpjdThis file is part of groff.
7168404Spjd
8168404Spjdgroff is free software; you can redistribute it and/or modify it under
9168404Spjdthe terms of the GNU General Public License as published by the Free
10168404SpjdSoftware Foundation; either version 2, or (at your option) any later
11168404Spjdversion.
12168404Spjd
13168404Spjdgroff is distributed in the hope that it will be useful, but WITHOUT ANY
14168404SpjdWARRANTY; without even the implied warranty of MERCHANTABILITY or
15168404SpjdFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16168404Spjdfor more details.
17168404Spjd
18168404SpjdYou should have received a copy of the GNU General Public License along
19168404Spjdwith groff; see the file COPYING.  If not, write to the Free Software
20168404SpjdFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21168404Spjd
22168404Spjd#include "lib.h"
23168404Spjd#include "paper.h"
24168404Spjd
25168404Spjdpaper papersizes[NUM_PAPERSIZES];
26168404Spjd
27168404Spjd// length and width in mm
28168404Spjdstatic void add_iso_paper(char series, int offset,
29168404Spjd			  int start_length, int start_width)
30168404Spjd{
31168404Spjd  int length = start_length;
32168404Spjd  int width = start_width;
33168404Spjd  for (int i = 0; i < 8; i++)
34168404Spjd  {
35168404Spjd    char *p = new char[3];
36168404Spjd    p[0] = series;
37168404Spjd    p[1] = '0' + i;
38168404Spjd    p[2] = '\0';
39168404Spjd    papersizes[offset + i].name = p;
40168404Spjd    // convert mm to inch
41168404Spjd    papersizes[offset + i].length = (double)length / 25.4;
42168404Spjd    papersizes[offset + i].width = (double)width / 25.4;
43168404Spjd    // after division by two, values must be rounded down to the next
44168404Spjd    // integer (as specified by ISO)
45168404Spjd    int tmp = length;
46168404Spjd    length = width;
47168404Spjd    width = tmp / 2;
48168404Spjd  }
49168404Spjd}
50168404Spjd
51168404Spjd// length and width in inch
52168404Spjdstatic void add_american_paper(const char *name, int idx,
53168404Spjd			       double length, double width )
54168404Spjd{
55168404Spjd  char *p = new char[strlen(name) + 1];
56168404Spjd  strcpy(p, name);
57168404Spjd  papersizes[idx].name = p;
58168404Spjd  papersizes[idx].length = length;
59168404Spjd  papersizes[idx].width = width;
60168404Spjd}
61168404Spjd
62168404Spjdint papersize_init::initialised = 0;
63168404Spjd
64168404Spjdpapersize_init::papersize_init()
65168404Spjd{
66168404Spjd  if (initialised)
67168404Spjd    return;
68168404Spjd  initialised = 1;
69168404Spjd  add_iso_paper('a', 0, 1189, 841);
70168404Spjd  add_iso_paper('b', 8, 1414, 1000);
71168404Spjd  add_iso_paper('c', 16, 1297, 917);
72168404Spjd  add_iso_paper('d', 24, 1090, 771);
73168404Spjd  add_american_paper("letter", 32, 11, 8.5);
74168404Spjd  add_american_paper("legal", 33, 14, 8.5);
75168404Spjd  add_american_paper("tabloid", 34, 17, 11);
76168404Spjd  add_american_paper("ledger", 35, 11, 17);
77168404Spjd  add_american_paper("statement", 36, 8.5, 5.5);
78168404Spjd  add_american_paper("executive", 37, 10, 7.5);
79168404Spjd  // the next three entries are for grolj4
80168404Spjd  add_american_paper("com10", 38, 9.5, 4.125);
81168404Spjd  add_american_paper("monarch", 39, 7.5, 3.875);
82168404Spjd  // this is an ISO format, but it easier to use add_american_paper
83168404Spjd  add_american_paper("dl", 40, 220/25.4, 110/25.4);
84168404Spjd}
85168404Spjd