1114402Sru// -*- C++ -*-
2151497Sru/* Copyright (C) 2002, 2003, 2004
3114402Sru   Free Software Foundation, Inc.
4114402Sru     Written by Werner Lemberg (wl@gnu.org)
5114402Sru
6114402SruThis file is part of groff.
7114402Sru
8114402Srugroff is free software; you can redistribute it and/or modify it under
9114402Sruthe terms of the GNU General Public License as published by the Free
10114402SruSoftware Foundation; either version 2, or (at your option) any later
11114402Sruversion.
12114402Sru
13114402Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
14114402SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
15114402SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16114402Srufor more details.
17114402Sru
18114402SruYou should have received a copy of the GNU General Public License along
19114402Sruwith groff; see the file COPYING.  If not, write to the Free Software
20151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21114402Sru
22114402Sru#include "lib.h"
23114402Sru#include "paper.h"
24114402Sru
25114402Srupaper papersizes[NUM_PAPERSIZES];
26114402Sru
27114402Sru// length and width in mm
28114402Srustatic void add_iso_paper(char series, int offset,
29114402Sru			  int start_length, int start_width)
30114402Sru{
31114402Sru  int length = start_length;
32114402Sru  int width = start_width;
33114402Sru  for (int i = 0; i < 8; i++)
34114402Sru  {
35114402Sru    char *p = new char[3];
36114402Sru    p[0] = series;
37114402Sru    p[1] = '0' + i;
38114402Sru    p[2] = '\0';
39114402Sru    papersizes[offset + i].name = p;
40114402Sru    // convert mm to inch
41114402Sru    papersizes[offset + i].length = (double)length / 25.4;
42114402Sru    papersizes[offset + i].width = (double)width / 25.4;
43114402Sru    // after division by two, values must be rounded down to the next
44114402Sru    // integer (as specified by ISO)
45114402Sru    int tmp = length;
46114402Sru    length = width;
47114402Sru    width = tmp / 2;
48114402Sru  }
49114402Sru}
50114402Sru
51114402Sru// length and width in inch
52151497Srustatic void add_american_paper(const char *name, int idx,
53114402Sru			       double length, double width )
54114402Sru{
55114402Sru  char *p = new char[strlen(name) + 1];
56114402Sru  strcpy(p, name);
57151497Sru  papersizes[idx].name = p;
58151497Sru  papersizes[idx].length = length;
59151497Sru  papersizes[idx].width = width;
60114402Sru}
61114402Sru
62114402Sruint papersize_init::initialised = 0;
63114402Sru
64114402Srupapersize_init::papersize_init()
65114402Sru{
66114402Sru  if (initialised)
67114402Sru    return;
68114402Sru  initialised = 1;
69114402Sru  add_iso_paper('a', 0, 1189, 841);
70114402Sru  add_iso_paper('b', 8, 1414, 1000);
71114402Sru  add_iso_paper('c', 16, 1297, 917);
72114402Sru  add_iso_paper('d', 24, 1090, 771);
73114402Sru  add_american_paper("letter", 32, 11, 8.5);
74114402Sru  add_american_paper("legal", 33, 14, 8.5);
75114402Sru  add_american_paper("tabloid", 34, 17, 11);
76114402Sru  add_american_paper("ledger", 35, 11, 17);
77114402Sru  add_american_paper("statement", 36, 8.5, 5.5);
78114402Sru  add_american_paper("executive", 37, 10, 7.5);
79114402Sru  // the next three entries are for grolj4
80114402Sru  add_american_paper("com10", 38, 9.5, 4.125);
81114402Sru  add_american_paper("monarch", 39, 7.5, 3.875);
82114402Sru  // this is an ISO format, but it easier to use add_american_paper
83114402Sru  add_american_paper("dl", 40, 220/25.4, 110/25.4);
84114402Sru}
85