ps_map.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Function: ps_map
  2. **
  3. ** This function writes the PostScript output file.
  4. **
  5. ** Author: Paul W. Carlson March 1992
  6. */
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include "vector.h"
  10. #include "border.h"
  11. #include "colortable.h"
  12. #include "local_proto.h"
  13. extern int do_mapinfo;
  14. extern int do_vlegend;
  15. extern int eps_output;
  16. extern int rotate_plot;
  17. extern int ps_copies;
  18. int ps_map(void)
  19. {
  20. long current_offset;
  21. const char *date;
  22. int urx, ury;
  23. /* get date */
  24. date = G_date();
  25. /* write the PostScript header */
  26. write_PS_header();
  27. /* create the PostScript procs */
  28. make_procs();
  29. /* set number of copies */
  30. if (ps_copies > 1)
  31. fprintf(PS.fp, "/#copies %d def\n", ps_copies);
  32. /* Set page size */
  33. if (!eps_output) {
  34. if (!rotate_plot) {
  35. urx = (int)72.0 *PS.page_width;
  36. ury = (int)72.0 *PS.page_height;
  37. }
  38. else {
  39. urx = (int)72.0 *PS.page_height;
  40. ury = (int)72.0 *PS.page_width;
  41. }
  42. fprintf(PS.fp, "<< /PageSize [ %d %d ] >> setpagedevice\n", urx,
  43. ury);
  44. }
  45. /* rotate map? */
  46. if (rotate_plot) {
  47. fprintf(PS.fp, "%.2f 0.0 TR\n", 72.0 * PS.page_height);
  48. fprintf(PS.fp, "90 rotate\n");
  49. }
  50. /* do the map header */
  51. if (PS.do_header)
  52. do_map_header(date);
  53. /* size the map */
  54. map_setup();
  55. /* do the raster stuff, if any */
  56. if (PS.do_raster || grp.do_group)
  57. PS_raster_plot();
  58. /* do the outline, if requested */
  59. if (PS.do_outline)
  60. ps_outline();
  61. /* do the masked vector plots, if any */
  62. if (vector.count) {
  63. do_vectors(0);
  64. do_vpoints(0);
  65. }
  66. /* do the masked points/lines, if any */
  67. do_plt(0);
  68. /* do masking, if required */
  69. PS_make_mask();
  70. if (PS.mask_needed)
  71. do_masking();
  72. /* do the unmasked vector plots, if any */
  73. if (vector.count)
  74. do_vectors(1);
  75. /* do the grid, if any */
  76. if (PS.grid_cross)
  77. do_grid_cross();
  78. else
  79. do_grid();
  80. /* do geo-grid, if any */
  81. do_geogrid();
  82. /* do the grid numbers, if any */
  83. if (PS.grid_numbers > 0)
  84. do_grid_numbers();
  85. if (PS.geogrid_numbers > 0)
  86. do_geogrid_numbers();
  87. /* do the labels from paint/labels, if any */
  88. do_labels(0);
  89. /* restore the unclipped graphics state */
  90. fprintf(PS.fp, "grestore ");
  91. /* do the unmasked vector points, if any */
  92. if (vector.count)
  93. do_vpoints(1);
  94. /* do the unmasked points, lines and eps if any */
  95. do_plt(1);
  96. /* do the labels specified in script file */
  97. do_labels(1);
  98. /* show the map info */
  99. if (do_mapinfo)
  100. map_info();
  101. /* show the vector legend */
  102. if (do_vlegend && vector.count)
  103. PS_vlegend();
  104. /* Make scalebar */
  105. if (PS.do_scalebar)
  106. do_scalebar();
  107. /* put border around map */
  108. if (PS.do_border && brd.r >= 0.) { /* if color wasn't "none" */
  109. fprintf(PS.fp, "%.3f %.3f %.3f C\n", brd.r, brd.g, brd.b);
  110. fprintf(PS.fp, "%.8f W\n", brd.width);
  111. box_draw(PS.map_top - 0.5, PS.map_bot + 0.5,
  112. PS.map_left + 0.5, PS.map_right - 0.5);
  113. }
  114. /* do the colortable, if requested */
  115. if (PS.do_colortable) {
  116. if (ct.discrete == TRUE)
  117. PS_colortable();
  118. else
  119. PS_fcolortable();
  120. }
  121. /* do comments, if any */
  122. if (PS.commentfile != NULL)
  123. do_comment();
  124. /* do any PostScript include files */
  125. if (PS.num_psfiles)
  126. do_psfiles();
  127. /* write the bounding box */
  128. current_offset = G_ftell(PS.fp);
  129. write_bounding_box();
  130. G_fseek(PS.fp, current_offset, SEEK_SET);
  131. fprintf(PS.fp, "showpage\n");
  132. fprintf(PS.fp, "%%%%Trailer\n");
  133. fprintf(PS.fp, "%%%%EOF\n");
  134. fclose(PS.fp);
  135. return 0;
  136. }