/contrib/groff/src/libs/libgroff/paper.cpp

https://bitbucket.org/freebsd/freebsd-head/ · C++ · 84 lines · 51 code · 6 blank · 27 comment · 2 complexity · 5ade3d7ba37a2e0f64ace31a18f3374a MD5 · raw file

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