read_cfg.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Function: read_cfg
  2. ** added #include <stdlib.h> 7/98 Richard Nairn
  3. #include <unistd.h>
  4. **
  5. ** This function reads the configuration file to get the printer info.
  6. **
  7. ** Author: Paul W. Carlson April 1992
  8. */
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <math.h>
  14. #include <grass/gis.h>
  15. #include <grass/glocale.h>
  16. #include "ps_info.h"
  17. #include "paper.h"
  18. #define FIELD(x) strcmp(x,field)==0
  19. extern int rotate_plot;
  20. /* Set page to one of predefined papers */
  21. int set_paper(char *pname)
  22. {
  23. int i;
  24. G_debug(3, "set_paper(): pname = %s", pname);
  25. /* Set default (a4) */
  26. PS.level = 2;
  27. PS.page_width = (rotate_plot) ? 11.69 : 8.27;
  28. PS.page_height = (rotate_plot) ? 8.27 : 11.69;
  29. PS.left_marg = 0.5;
  30. PS.right_marg = 0.5;
  31. PS.top_marg = 1.0;
  32. PS.bot_marg = 1.0;
  33. PS.res = 75;
  34. i = 0;
  35. while (papers[i].name != NULL) {
  36. if (G_strcasecmp(papers[i].name, pname) == 0) {
  37. PS.page_width =
  38. (rotate_plot) ? papers[i].page_height : papers[i].page_width;
  39. PS.page_height =
  40. (rotate_plot) ? papers[i].page_width : papers[i].page_height;
  41. PS.left_marg =
  42. (rotate_plot) ? papers[i].right_marg : papers[i].left_marg;
  43. PS.right_marg =
  44. (rotate_plot) ? papers[i].left_marg : papers[i].right_marg;
  45. PS.top_marg =
  46. (rotate_plot) ? papers[i].bot_marg : papers[i].top_marg;
  47. PS.bot_marg =
  48. (rotate_plot) ? papers[i].top_marg : papers[i].bot_marg;
  49. PS.res = 75;
  50. G_debug(4, " paper w = %f h = %f", PS.page_width,
  51. PS.page_height);
  52. return 0;
  53. }
  54. i++;
  55. }
  56. G_warning(_("Paper '%s' not found, using defaults"), pname);
  57. return -1;
  58. }
  59. /* Reset map size and position */
  60. void reset_map_location(void)
  61. {
  62. double w, h;
  63. /* First reset origin if necessary */
  64. if (PS.map_y_loc < PS.top_marg)
  65. PS.map_y_loc = PS.top_marg;
  66. if (PS.map_x_orig < PS.left_marg)
  67. PS.map_x_orig = PS.left_marg;
  68. PS.map_y_orig = PS.page_height - PS.map_y_loc;
  69. w = PS.page_width - PS.map_x_orig - PS.right_marg;
  70. h = PS.page_height - PS.map_y_loc - PS.bot_marg;
  71. if (PS.map_width <= 0 || PS.map_width > w)
  72. /* not specified or greater than available space */
  73. PS.map_width = w;
  74. if (PS.map_height <= 0 || PS.map_height > h)
  75. PS.map_height = h;
  76. PS.min_y = 72.0 * PS.map_y_orig;
  77. G_debug(3, "map: w = %f h = %f", PS.map_width, PS.map_height);
  78. }
  79. void print_papers(void)
  80. {
  81. int i;
  82. i = 0;
  83. while (papers[i].name != NULL) {
  84. fprintf(stdout, "%s %f %f %f %f %f %f\n", papers[i].name,
  85. papers[i].page_width, papers[i].page_height,
  86. papers[i].left_marg, papers[i].right_marg, papers[i].top_marg,
  87. papers[i].bot_marg);
  88. i++;
  89. }
  90. }