C   6

global.c

Guest on 20th July 2021 03:10:59 PM

  1. /* global.c
  2.    Copyright (C)  Eugene K. Ressler, Jr.
  3.  
  4. This file is part of Sketch, a small, simple system for making
  5. 3d drawings with LaTeX and the PSTricks or TikZ package.
  6.  
  7. Sketch is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3, or (at your option)
  10. any later version.
  11.  
  12. Sketch is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Sketch; see the file COPYING.txt.  If not, see
  19. http://www.gnu.org/copyleft */
  20.  
  21. #include "global.h"
  22.  
  23. GLOBAL_ENV __the_global_env[1];
  24.  
  25. // must match GEOL_lang definitions in global.h
  26. char *output_language_str[] = {
  27.   "PSTricks,LaTeX",
  28.   "PGF/TikZ,LaTeX",
  29.   "PSTricks,ConTeXt",
  30.   "PGF/TikZ,ConTeXt",
  31. };
  32.  
  33. void
  34. init_global_env (GLOBAL_ENV * env, PST_VERSION *pst_version)
  35. {
  36.   env->set_p_mask = 0;
  37.   set_ident (env->camera);
  38.   copy_pt_3d (env->bb1, origin_3d);
  39.   copy_pt_3d (env->bb2, origin_3d);
  40.   init_opts (env->opts);
  41.   env->baseline = 0;
  42.   env->output_language = GEOL_PSTRICKS | GEOL_LATEX;
  43.   *env->pst_version = *pst_version;
  44. }
  45.  
  46. void
  47. set_global_baseline (GLOBAL_ENV * env, FLOAT baseline, SRC_LINE line)
  48. {
  49.   if (baseline == NO_BASELINE)
  50.     return;
  51.   if (global_env_is_set_p (env, GE_BASELINE))
  52.     {
  53.       err (line, "baseline is already set");
  54.       return;
  55.     }
  56.   env->set_p_mask |= bit (GE_BASELINE);
  57.   env->baseline = baseline;
  58. }
  59.  
  60. void
  61. set_global_env_extent (GLOBAL_ENV * env, POINT_3D p1, POINT_3D p2,
  62.                        SRC_LINE line)
  63. {
  64.   if (global_env_is_set_p (env, GE_EXTENT))
  65.     {
  66.       err (line, "bounding box is already set");
  67.       return;
  68.     }
  69.   env->set_p_mask |= bit (GE_EXTENT);
  70.   copy_pt_3d (env->bb1, p1);
  71.   copy_pt_3d (env->bb2, p2);
  72. }
  73.  
  74. int
  75. get_transformed_global_env_extent (BOX_3D * extent, GLOBAL_ENV * env)
  76. {
  77.   POINT_3D t;
  78.   int i;
  79.  
  80.   if (!global_env_is_set_p (env, GE_EXTENT))
  81.     return 0;
  82.  
  83.   init_box_3d (extent);
  84.   if (global_env_is_set_p (env, GE_CAMERA))
  85.     {
  86.       for (i = 0; i < 8; i++)
  87.         {
  88.           t[X] = (i & 1) ? env->bb1[X] : env->bb2[X];
  89.           t[Y] = (i & 2) ? env->bb1[Y] : env->bb2[Y];
  90.           t[Z] = (i & 4) ? env->bb1[Z] : env->bb2[Z];
  91.           transform_pt_3d (t, env->camera, t);
  92.           fold_min_max_pt_3d (extent, t);
  93.         }
  94.     }
  95.   else
  96.     {
  97.       fold_min_max_pt_3d (extent, env->bb1);
  98.       fold_min_max_pt_3d (extent, env->bb2);
  99.     }
  100.   return 1;
  101. }
  102.  
  103. void
  104. set_global_env_opts (GLOBAL_ENV * env, char *opt_str, SRC_LINE line)
  105. {
  106.   if (global_env_is_set_p (env, GE_OPTS))
  107.     {
  108.       err (line, "global options are already set");
  109.       return;
  110.     }
  111.   env->set_p_mask |= bit (GE_OPTS);
  112.   setup_opts (env->opts, opt_str, no_line);
  113. }
  114.  
  115. void
  116. set_global_env_frame (GLOBAL_ENV * env, char *opt_str, SRC_LINE line)
  117. {
  118.   if (global_env_is_set_p (env, GE_FRAME))
  119.     {
  120.       err (line, "frame is already set");
  121.       return;
  122.     }
  123.   env->set_p_mask |= bit (GE_FRAME);
  124.   safe_free (env->frame_opts);
  125.   env->frame_opts = opt_str ? safe_strdup (opt_str) : NULL;
  126. }
  127.  
  128. void
  129. set_global_env_camera (GLOBAL_ENV * env, TRANSFORM camera, SRC_LINE line)
  130. {
  131.   if (global_env_is_set_p (env, GE_CAMERA))
  132.     {
  133.       err (line, "camera is already set");
  134.       return;
  135.     }
  136.   env->set_p_mask |= bit (GE_CAMERA);
  137.   copy_transform (env->camera, camera);
  138. }
  139.  
  140. void
  141. set_global_output_language (GLOBAL_ENV * env, int output_language,
  142.                             SRC_LINE line)
  143. {
  144.   if (global_env_is_set_p (env, GE_OUTPUT_LANGUAGE))
  145.     {
  146.       err (line, "output language is already set");
  147.       return;
  148.     }
  149.   env->set_p_mask |= bit (GE_OUTPUT_LANGUAGE);
  150.   env->output_language = output_language;
  151. }
  152.  
  153. int
  154. get_global_output_language (int * output_language, GLOBAL_ENV * env)
  155. {
  156.   *output_language = env->output_language;
  157.   return global_env_is_set_p (env, GE_OUTPUT_LANGUAGE);
  158. }
  159.  
  160. int cmp_with_global_pst_version(GLOBAL_ENV * env,
  161.                                 char * version_str,
  162.                                 SRC_LINE line)
  163. {
  164.   PST_VERSION v[1];
  165.  
  166.   parse_pst_version(v, version_str, line);
  167.   return pst_version_cmp(env->pst_version, v);
  168. }

Raw Paste


Login or Register to edit or fork this paste. It's free.