gdevmeds.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (C) 1998 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gdevmeds.c,v 1.2 2000/09/19 19:00:13 lpd Exp $ */
  16. /*
  17. * Media selection support for printer drivers
  18. *
  19. * Select from a NULL terminated list of media the smallest medium which is
  20. * almost equal or larger then the actual imagesize.
  21. *
  22. * Written by Ulrich Schmid, uschmid@mail.hh.provi.de.
  23. */
  24. #include "gdevmeds.h"
  25. #define CM * 0.01
  26. #define INCH * 0.0254
  27. #define TOLERANCE 0.1 CM
  28. private const struct {
  29. const char* name;
  30. float width;
  31. float height;
  32. float priority;
  33. } media[] = {
  34. #define X(name, width, height) {name, width, height, 1 / (width * height)}
  35. X("a0", 83.9611 CM, 118.816 CM),
  36. X("a1", 59.4078 CM, 83.9611 CM),
  37. X("a2", 41.9806 CM, 59.4078 CM),
  38. X("a3", 29.7039 CM, 41.9806 CM),
  39. X("a4", 20.9903 CM, 29.7039 CM),
  40. X("a5", 14.8519 CM, 20.9903 CM),
  41. X("a6", 10.4775 CM, 14.8519 CM),
  42. X("a7", 7.40833 CM, 10.4775 CM),
  43. X("a8", 5.22111 CM, 7.40833 CM),
  44. X("a9", 3.70417 CM, 5.22111 CM),
  45. X("a10", 2.61056 CM, 3.70417 CM),
  46. X("archA", 9 INCH, 12 INCH),
  47. X("archB", 12 INCH, 18 INCH),
  48. X("archC", 18 INCH, 24 INCH),
  49. X("archD", 24 INCH, 36 INCH),
  50. X("archE", 36 INCH, 48 INCH),
  51. X("b0", 100.048 CM, 141.393 CM),
  52. X("b1", 70.6967 CM, 100.048 CM),
  53. X("b2", 50.0239 CM, 70.6967 CM),
  54. X("b3", 35.3483 CM, 50.0239 CM),
  55. X("b4", 25.0119 CM, 35.3483 CM),
  56. X("b5", 17.6742 CM, 25.0119 CM),
  57. X("flsa", 8.5 INCH, 13 INCH),
  58. X("flse", 8.5 INCH, 13 INCH),
  59. X("halfletter", 5.5 INCH, 8.5 INCH),
  60. X("ledger", 17 INCH, 11 INCH),
  61. X("legal", 8.5 INCH, 14 INCH),
  62. X("letter", 8.5 INCH, 11 INCH),
  63. X("note", 7.5 INCH, 10 INCH),
  64. X("executive", 7.25 INCH, 10.5 INCH),
  65. X("com10", 4.125 INCH, 9.5 INCH),
  66. X("dl", 11 CM, 22 CM),
  67. X("c5", 16.2 CM, 22.9 CM),
  68. X("monarch", 3.875 INCH, 7.5 INCH)};
  69. int select_medium(gx_device_printer *pdev, const char **available, int default_index)
  70. {
  71. int i, j, index = default_index;
  72. float priority = 0;
  73. float width = pdev->width / pdev->x_pixels_per_inch INCH;
  74. float height = pdev->height / pdev->y_pixels_per_inch INCH;
  75. for (i = 0; available[i]; i++) {
  76. for (j = 0; j < sizeof(media) / sizeof(media[0]); j++) {
  77. if (!strcmp(available[i], media[j].name) &&
  78. media[j].width + TOLERANCE > width &&
  79. media[j].height + TOLERANCE > height &&
  80. media[j].priority > priority) {
  81. index = i;
  82. priority = media[j].priority;
  83. }
  84. }
  85. }
  86. return index;
  87. }