ps_header.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Function: write_PS_header
  2. **
  3. ** Author: Paul W. Carlson 3/92
  4. */
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <grass/gis.h>
  8. #include <grass/raster.h>
  9. #include "ps_info.h"
  10. static long bb_offset;
  11. extern int eps_output;
  12. extern int rotate_plot;
  13. int write_PS_header(void)
  14. {
  15. struct Categories cats;
  16. int cats_ok;
  17. if (PS.do_raster)
  18. cats_ok = Rast_read_cats(PS.cell_name, PS.cell_mapset, &cats) >= 0;
  19. /* write PostScript header */
  20. /*fprintf(PS.fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); */
  21. if (eps_output)
  22. fprintf(PS.fp, "%%!PS-Adobe-3.0 EPSF-3.0\n");
  23. else
  24. fprintf(PS.fp, "%%!PS-Adobe-3.0\n");
  25. bb_offset = G_ftell(PS.fp);
  26. fprintf(PS.fp, " ");
  27. fprintf(PS.fp, " \n");
  28. fprintf(PS.fp, "%%%%Title: ");
  29. if (PS.do_raster && cats_ok)
  30. fprintf(PS.fp, "%s\n", cats.title);
  31. else
  32. fprintf(PS.fp, "Mapset = %s\n", PS.cell_mapset);
  33. fprintf(PS.fp, "%%%%EndComments\n");
  34. return 0;
  35. }
  36. int write_bounding_box(void)
  37. {
  38. int llx, lly, urx, ury;
  39. if (!rotate_plot) {
  40. /*
  41. llx = (int) 72.0 * PS.left_marg;
  42. lly = (int) 72.0 * PS.bot_marg;
  43. urx = (int) 72.0 * (PS.page_width - PS.right_marg);
  44. ury = (int) 72.0 * (PS.page_height - PS.top_marg);
  45. */
  46. /* BBox should be as above but then such box is displayed in gv and I think that people
  47. * expect full page. Also id rectangle is drawn around printable area half of such
  48. * line would be clipped out */
  49. llx = 0;
  50. lly = 0;
  51. urx = (int)72.0 *PS.page_width;
  52. ury = (int)72.0 *PS.page_height;
  53. }
  54. else {
  55. llx = 0;
  56. lly = 0;
  57. urx = (int)72.0 *PS.page_height;
  58. ury = (int)72.0 *PS.page_width;
  59. }
  60. G_fseek(PS.fp, bb_offset, SEEK_SET);
  61. fprintf(PS.fp, "%%%%BoundingBox: %d %d %d %d", llx, lly, urx, ury);
  62. return 0;
  63. }