a_closepl.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
  3. The GNU plotutils package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU plotutils package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. /* This file contains the closepl method, which is a standard part of
  16. libplot. It closes a Plotter object.
  17. For an AIPlotter objects, we prepare an Illustrator header for the page.
  18. After the header comes the graphics code for all objects, which we have
  19. saved in a resizable outbuf structure for the page. Then a trailer.
  20. AI format supports only single-page documents. */
  21. #include "sys-defines.h"
  22. #include "extern.h"
  23. /* song and dance to define time_t, and declare both time() and ctime() */
  24. #ifdef HAVE_SYS_TYPES_H
  25. #include <sys/types.h> /* for time_t on some pre-ANSI Unix systems */
  26. #endif
  27. #ifdef TIME_WITH_SYS_TIME
  28. #include <sys/time.h> /* for time() on some pre-ANSI Unix systems */
  29. #include <time.h> /* for ctime() */
  30. #else /* not TIME_WITH_SYS_TIME, include only one (prefer <sys/time.h>) */
  31. #ifdef HAVE_SYS_TIME_H
  32. #include <sys/time.h>
  33. #else /* not HAVE_SYS_TIME_H */
  34. #include <time.h>
  35. #endif /* not HAVE_SYS_TIME_H */
  36. #endif /* not TIME_WITH_SYS_TIME */
  37. static const char * const _ai_symbol_reencoding = "32/space\n/exclam\n/universal\n/numbersign\n/existential\n/percent\n/ampersand\n/suchthat\n/parenleft\n/parenright\n/asteriskmath\n/plus\n/comma\n/minus\n/period\n/slash\n/zero\n/one\n/two\n/three\n/four\n/five\n/six\n/seven\n/eight\n/nine\n/colon\n/semicolon\n/less\n/equal\n/greater\n/question\n/congruent\n/Alpha\n/Beta\n/Chi\n/Delta\n/Epsilon\n/Phi\n/Gamma\n/Eta\n/Iota\n/theta1\n/Kappa\n/Lambda\n/Mu\n/Nu\n/Omicron\n/Pi\n/Theta\n/Rho\n/Sigma\n/Tau\n/Upsilon\n/sigma1\n/Omega\n/Xi\n/Psi\n/Zeta\n/bracketleft\n/therefore\n/bracketright\n/perpendicular\n/underscore\n/radicalex\n/alpha\n/beta\n/chi\n/delta\n/epsilon\n/phi\n/gamma\n/eta\n/iota\n/phi1\n/kappa\n/lambda\n/mu\n/nu\n/omicron\n/pi\n/theta\n/rho\n/sigma\n/tau\n/upsilon\n/omega1\n/omega\n/xi\n/psi\n/zeta\n/braceleft\n/bar\n/braceright\n/similar\n161/Upsilon1\n/minute\n/lessequal\n/fraction\n/infinity\n/florin\n/club\n/diamond\n/heart\n/spade\n/arrowboth\n/arrowleft\n/arrowup\n/arrowright\n/arrowdown\n/degree\n/plusminus\n/second\n/greaterequal\n/multiply\n/proportional\n/partialdiff\n/bullet\n/divide\n/notequal\n/equivalence\n/approxequal\n/ellipsis\n/arrowvertex\n/arrowhorizex\n/carriagereturn\n/aleph\n/Ifraktur\n/Rfraktur\n/weierstrass\n/circlemultiply\n/circleplus\n/emptyset\n/intersection\n/union\n/propersuperset\n/reflexsuperset\n/notsubset\n/propersubset\n/reflexsubset\n/element\n/notelement\n/angle\n/gradient\n/registerserif\n/copyrightserif\n/trademarkserif\n/product\n/radical\n/dotmath\n/logicalnot\n/logicaland\n/logicalor\n/arrowdblboth\n/arrowdblleft\n/arrowdblup\n/arrowdblright\n/arrowdbldown\n/lozenge\n/angleleft\n/registersans\n/copyrightsans\n/trademarksans\n/summation\n/parenlefttp\n/parenleftex\n/parenleftbt\n/bracketlefttp\n/bracketleftex\n/bracketleftbt\n/bracelefttp\n/braceleftmid\n/braceleftbt\n/braceex\n241/angleright\n/integral\n/integraltp\n/integralex\n/integralbt\n/parenrighttp\n/parenrightex\n/parenrightbt\n/bracketrighttp\n/bracketrightex\n/bracketrightbt\n/bracerighttp\n/bracerightmid\n/bracerightbt\n";
  38. static const char * const _ai_zapf_dingbats_reencoding = "32/space\n/a1\n/a2\n/a202\n/a3\n/a4\n/a5\n/a119\n/a118\n/a117\n/a11\n/a12\n/a13\n/a14\n/a15\n/a16\n/a105\n/a17\n/a18\n/a19\n/a20\n/a21\n/a22\n/a23\n/a24\n/a25\n/a26\n/a27\n/a28\n/a6\n/a7\n/a8\n/a9\n/a10\n/a29\n/a30\n/a31\n/a32\n/a33\n/a34\n/a35\n/a36\n/a37\n/a38\n/a39\n/a40\n/a41\n/a42\n/a43\n/a44\n/a45\n/a46\n/a47\n/a48\n/a49\n/a50\n/a51\n/a52\n/a53\n/a54\n/a55\n/a56\n/a57\n/a58\n/a59\n/a60\n/a61\n/a62\n/a63\n/a64\n/a65\n/a66\n/a67\n/a68\n/a69\n/a70\n/a71\n/a72\n/a73\n/a74\n/a203\n/a75\n/a204\n/a76\n/a77\n/a78\n/a79\n/a81\n/a82\n/a83\n/a84\n/a97\n/a98\n/a99\n/a100\n160/space\n/a101\n/a102\n/a103\n/a104\n/a106\n/a107\n/a108\n/a112\n/a111\n/a110\n/a109\n/a120\n/a121\n/a122\n/a123\n/a124\n/a125\n/a126\n/a127\n/a128\n/a129\n/a130\n/a131\n/a132\n/a133\n/a134\n/a135\n/a136\n/a137\n/a138\n/a139\n/a140\n/a141\n/a142\n/a143\n/a144\n/a145\n/a146\n/a147\n/a148\n/a149\n/a150\n/a151\n/a152\n/a153\n/a154\n/a155\n/a156\n/a157\n/a158\n/a159\n/a160\n/a161\n/a163\n/a164\n/a196\n/a165\n/a192\n/a166\n/a167\n/a168\n/a169\n/a170\n/a171\n/a172\n/a173\n/a162\n/a174\n/a175\n/a176\n/a177\n/a178\n/a179\n/a193\n/a180\n/a199\n/a181\n/a200\n/a182\n241/a201\n/a183\n/a184\n/a197\n/a185\n/a194\n/a198\n/a186\n/a195\n/a187\n/a188\n/a189\n/a190\n/a191\n";
  39. bool
  40. _pl_a_end_page (S___(Plotter *_plotter))
  41. {
  42. bool fonts_used = false;
  43. int i;
  44. /* Beginning of Page Header */
  45. {
  46. char *time_s;
  47. double x_min, x_max, y_min, y_max;
  48. double xmid, ymid;
  49. int ixmid, iymid;
  50. time_t clock;
  51. plOutbuf *page_header;
  52. /* first, prepare AI header, and write it to a plOutbuf */
  53. page_header = _new_outbuf ();
  54. /* compute center of viewport in device coors (i.e. points) */
  55. xmid = 0.5 * (_plotter->data->xmin + _plotter->data->xmax);
  56. ymid = 0.5 * (_plotter->data->ymin + _plotter->data->ymax);
  57. ixmid = IROUND(xmid);
  58. iymid = IROUND(ymid);
  59. /* emit first few comment lines */
  60. sprintf (page_header->point, "\
  61. %%!PS-Adobe-3.0\n\
  62. %%%%Creator: GNU libplot drawing library %s\n\
  63. %%%%For: (Unknown) (Unknown)\n\
  64. %%%%Title: (Untitled)\n",
  65. PL_LIBPLOT_VER_STRING);
  66. _update_buffer (page_header);
  67. /* emit creation date and time, if possible */
  68. time(&clock);
  69. time_s = ctime(&clock);
  70. if (time_s != NULL)
  71. {
  72. char weekday[32], month[32], day[32], hour_min_sec[32], year[32];
  73. int num_matched;
  74. num_matched = sscanf (time_s, "%s %s %s %s %s",
  75. weekday, month, day, hour_min_sec, year);
  76. if (num_matched == 5)
  77. {
  78. sprintf (page_header->point, "\
  79. %%%%CreationDate: (%s %s %s) (%s)\n",
  80. day, month, year, hour_min_sec);
  81. _update_buffer (page_header);
  82. }
  83. }
  84. /* emit bounding box for the page */
  85. _bbox_of_outbuf (_plotter->data->page, &x_min, &x_max, &y_min, &y_max);
  86. if (x_min > x_max || y_min > y_max) /* no objects */
  87. /* place degenerate box at center of page */
  88. sprintf (page_header->point, "\
  89. %%%%BoundingBox: %d %d %d %d\n",
  90. ixmid, iymid, ixmid, iymid);
  91. else
  92. /* emit true bounding box */
  93. sprintf (page_header->point, "\
  94. %%%%BoundingBox: %d %d %d %d\n",
  95. IROUND(x_min - 0.5), IROUND(y_min - 0.5),
  96. IROUND(x_max + 0.5), IROUND(y_max + 0.5));
  97. _update_buffer (page_header);
  98. if (_plotter->ai_version >= AI_VERSION_5)
  99. /* emit hi-res bounding box too */
  100. {
  101. if (x_min > x_max || y_min > y_max) /* empty page */
  102. /* place degenerate box at center of page */
  103. sprintf (page_header->point, "\
  104. %%%%HiResBoundingBox: %.4f %.4f %.4f %.4f\n",
  105. xmid, ymid, xmid, ymid);
  106. else
  107. /* emit true bounding box */
  108. sprintf (page_header->point, "\
  109. %%%%HiResBoundingBox: %.4f %.4f %.4f %.4f\n",
  110. x_min, y_min, x_max, y_max);
  111. _update_buffer (page_header);
  112. }
  113. /* emit process colors used */
  114. sprintf (page_header->point, "\
  115. %%%%DocumentProcessColors:");
  116. _update_buffer (page_header);
  117. if (_plotter->ai_cyan_used)
  118. {
  119. sprintf (page_header->point, " Cyan");
  120. _update_buffer (page_header);
  121. }
  122. if (_plotter->ai_magenta_used)
  123. {
  124. sprintf (page_header->point, " Magenta");
  125. _update_buffer (page_header);
  126. }
  127. if (_plotter->ai_yellow_used)
  128. {
  129. sprintf (page_header->point, " Yellow");
  130. _update_buffer (page_header);
  131. }
  132. if (_plotter->ai_black_used)
  133. {
  134. sprintf (page_header->point, " Black");
  135. _update_buffer (page_header);
  136. }
  137. sprintf (page_header->point, "\n");
  138. _update_buffer (page_header);
  139. /* tell AI to include any PS [or PCL] fonts that are needed */
  140. sprintf (page_header->point, "\
  141. %%%%DocumentFonts: ");
  142. _update_buffer (page_header);
  143. for (i = 0; i < PL_NUM_PS_FONTS; i++)
  144. if (_plotter->data->page->ps_font_used[i])
  145. {
  146. if (fonts_used) /* not first font */
  147. sprintf (page_header->point,
  148. "%%%%+ %s\n", _pl_g_ps_font_info[i].ps_name);
  149. else /* first font */
  150. sprintf (page_header->point,
  151. "%s\n", _pl_g_ps_font_info[i].ps_name);
  152. _update_buffer (page_header);
  153. fonts_used = true;
  154. }
  155. for (i = 0; i < PL_NUM_PCL_FONTS; i++)
  156. if (_plotter->data->page->pcl_font_used[i])
  157. {
  158. if (fonts_used) /* not first font */
  159. sprintf (page_header->point,
  160. "%%%%+ %s\n", _pl_g_pcl_font_info[i].ps_name);
  161. else /* first font */
  162. sprintf (page_header->point,
  163. "%s\n", _pl_g_pcl_font_info[i].ps_name);
  164. _update_buffer (page_header);
  165. fonts_used = true;
  166. }
  167. if (!fonts_used)
  168. {
  169. sprintf (page_header->point, "\n");
  170. _update_buffer (page_header);
  171. }
  172. /* tell AI or print spooler that we need procsets */
  173. if (_plotter->ai_version == AI_VERSION_5)
  174. {
  175. sprintf (page_header->point, "\
  176. %%%%DocumentNeededResources: procset Adobe_level2_AI5 1.0 0\n\
  177. %%%%+ procset Adobe_typography_AI5 1.0 0\n\
  178. %%%%+ procset Adobe_Illustrator_AI6_vars Adobe_Illustrator_AI6\n\
  179. %%%%+ procset Adobe_Illustrator_AI5 1.0 0\n");
  180. _update_buffer (page_header);
  181. /* claim to be AI 7.0 (that's what `3' means) */
  182. sprintf (page_header->point, "\
  183. %%AI5_FileFormat 3\n");
  184. _update_buffer (page_header);
  185. }
  186. else /* AI_VERSION_3 */
  187. {
  188. sprintf (page_header->point, "\
  189. %%%%DocumentNeededResources: procset Adobe_packedarray 2.0 0\n\
  190. %%%%+ procset Adobe_cmykcolor 1.1 0\n\
  191. %%%%+ procset Adobe_cshow 1.1 0\n\
  192. %%%%+ procset Adobe_customcolor 1.0 0\n\
  193. %%%%+ procset Adobe_typography_AI3 1.0 1\n\
  194. %%%%+ procset Adobe_pattern_AI3 1.0 0\n\
  195. %%%%+ procset Adobe_Illustrator_AI3 1.0 1\n");
  196. _update_buffer (page_header);
  197. }
  198. /* AI3 directives. */
  199. /* tell AI whether or not we're monochrome */
  200. sprintf (page_header->point, "\
  201. %%AI3_ColorUsage: ");
  202. _update_buffer (page_header);
  203. if (_plotter->ai_cyan_used || _plotter->ai_magenta_used || _plotter->ai_yellow_used)
  204. sprintf (page_header->point, "Color\n");
  205. else
  206. sprintf (page_header->point, "Black&White\n");
  207. _update_buffer (page_header);
  208. /* no linked images are embedded in this file */
  209. sprintf (page_header->point, "\
  210. %%AI7_ImageSettings: 0\n");
  211. _update_buffer (page_header);
  212. /* place degenerate template box at center of viewport (used for
  213. centering, in case size of artboard changes between successive
  214. versions of AI) */
  215. sprintf (page_header->point, "\
  216. %%AI3_TemplateBox: %d %d %d %d\n",
  217. ixmid, iymid, ixmid, iymid);
  218. _update_buffer (page_header);
  219. /* nominal imageable area of the page (used only by Macintosh version
  220. of AI?): we specify our horizontal range, and the full page height */
  221. sprintf (page_header->point, "\
  222. %%AI3_TileBox: %d %d %d %d\n",
  223. IROUND(_plotter->data->xmin),
  224. 0,
  225. IROUND(_plotter->data->xmax),
  226. IROUND(72 * _plotter->data->page_data->ysize));
  227. _update_buffer (page_header);
  228. sprintf (page_header->point, "\
  229. %%AI3_DocumentPreview: None\n");
  230. _update_buffer (page_header);
  231. /* AI5 directives. */
  232. /* Note: AI5_ArtFlags consists of nine 0/1 flags that describe the
  233. settings found in the Document Setup dialogue; meaning of each `1'
  234. is: use page setup / use print tiles / show placed images / preview
  235. patterns / split long paths / tile full pages / use printer's
  236. default screens / use auto default screens [meaningful only if
  237. previous flag = 1] / use compatible gradient printing */
  238. /* Note: we could add an %AI5_OpenToView line, between the
  239. %AI5_NumLayers line and the %AI5_OpenViewLayers line. Such a line
  240. would look like
  241. %AI5_OpenToView: -318 780 -2 624 379 18 0 1 98 74 0 0
  242. with 12 parameters. It specifies the size, location, and
  243. orientation of the artwork within the AI display, when the file is
  244. opened. Parameters are:
  245. 1,2. (ulx, uly). Position, in integer artwork coors, of upper left
  246. corner of AI's artwork window.
  247. 3. zoom. Integer zoom factor (a negative number represents 1/x).
  248. 4,5. w,h. Width and height of the artwork window, in pixels.
  249. Allegedly floating point, not integer.
  250. 6. view_style. An integer specifying what's displayed
  251. (e.g. 25=artwork, 26=preview, 30=preview selection).
  252. 7. ruler. 0/1 flag, 1 means show ruler.
  253. 8. tiling. 0/1 flag, 1 means show tiling.
  254. 9,10. (ul_monx, ul_mony). Upper left corner of the artwork window
  255. on the monitor, in integer coordinates. (!)
  256. 11. grid. 0/1 flag, 1 means display grid.
  257. 12. snap_grid. 0/1 flag, 1 means snap to grid. */
  258. if (_plotter->ai_version >= AI_VERSION_5)
  259. {
  260. sprintf (page_header->point, "\
  261. %%AI5_ArtSize: %d %d\n\
  262. %%AI5_RulerUnits: %d\n\
  263. %%AI5_ArtFlags: 1 0 0 1 0 0 1 1 0\n\
  264. %%AI5_TargetResolution: 800\n\
  265. %%AI5_NumLayers: 1\n\
  266. %%AI5_OpenViewLayers: 7\n",
  267. /* For `ArtSize' (size of the artboard in points), we
  268. specify the entire physical page. */
  269. /* page width */
  270. IROUND(72 * _plotter->data->page_data->xsize),
  271. /* page height */
  272. IROUND(72 * _plotter->data->page_data->ysize),
  273. /* label AI's rulers with centimeters or inches
  274. (4 = cm, 0 = in) */
  275. _plotter->data->page_data->metric ? 4 : 0);
  276. _update_buffer (page_header);
  277. }
  278. /* following three may be used only by old Macintosh versions of AI? */
  279. /* so-called page origin, taken to be lower left corner of nominal
  280. imageable area (see above) */
  281. sprintf (page_header->point, "\
  282. %%%%PageOrigin:%d %d\n",
  283. IROUND(_plotter->data->xmin), 0);
  284. _update_buffer (page_header);
  285. /* paper rectangle, relative to the lower left corner of the nominal
  286. imageable area (see above) */
  287. sprintf (page_header->point, "\
  288. %%%%AI3_PaperRect:%d %d %d %d\n",
  289. -IROUND(_plotter->data->xmin),
  290. IROUND(72 * _plotter->data->page_data->ysize),
  291. IROUND(72 * _plotter->data->page_data->xsize - _plotter->data->xmin),
  292. 0);
  293. _update_buffer (page_header);
  294. /* margins on all sides of the paper, i.e. the offsets between page
  295. edges and the nominal imageable area (see above) */
  296. sprintf (page_header->point, "\
  297. %%%%AI3_Margin:%d %d %d %d\n",
  298. IROUND(_plotter->data->xmin),
  299. 0,
  300. IROUND(-(72 * _plotter->data->page_data->xsize - _plotter->data->xmax)),
  301. 0);
  302. _update_buffer (page_header);
  303. /* gridlines; parameters are:
  304. num. horizontal points between gridlines /
  305. num. horizontal subdivisions /
  306. num. vertical points between gridlines /
  307. num. vertical subdivisions /
  308. gridlines in front/back of artwork (0/1) /
  309. grid style lines/dots (0/1) /
  310. RGB for gridlines /
  311. RGB for subdivisions */
  312. if (_plotter->data->page_data->metric)
  313. /* visible grid spacing = 1 cm, 3 subdivisions / division */
  314. sprintf (page_header->point, "\
  315. %%AI7_GridSettings: %.4f 3 %.4f 3 1 0 0.8 0.8 0.8 0.9 0.9 0.9\n",
  316. 72.0/2.54, 72.0/2.54);
  317. else
  318. /* visible grid spacing = 1 in, 8 subdivisions / division */
  319. sprintf (page_header->point, "\
  320. %%AI7_GridSettings: 72 8 72 8 1 0 0.8 0.8 0.8 0.9 0.9 0.9\n");
  321. _update_buffer (page_header);
  322. sprintf (page_header->point, "\
  323. %%%%EndComments\n");
  324. _update_buffer (page_header);
  325. /* Prolog section: include the procsets */
  326. if (_plotter->ai_version == AI_VERSION_5)
  327. sprintf (page_header->point, "\
  328. %%%%BeginProlog\n\
  329. %%%%IncludeResource: procset Adobe_level2_AI5 1.0 0\n\
  330. %%%%IncludeResource: procset Adobe_typography_AI5 1.0 0\n\
  331. %%%%IncludeResource: procset Adobe_Illustrator_AI6_vars Adobe_Illustrator_AI6\n\
  332. %%%%IncludeResource: procset Adobe_Illustrator_AI5 1.0 0\n\
  333. %%%%EndProlog\n");
  334. else /* AI_VERSION_3 */
  335. sprintf (page_header->point, "\
  336. %%%%BeginProlog\n\
  337. %%%%IncludeResource: procset Adobe_packedarray 2.0 0\n\
  338. Adobe_packedarray /initialize get exec\n\
  339. %%%%IncludeResource: procset Adobe_cmykcolor 1.1 0\n\
  340. %%%%IncludeResource: procset Adobe_cshow 1.1 0\n\
  341. %%%%IncludeResource: procset Adobe_customcolor 1.0 0\n\
  342. %%%%IncludeResource: procset Adobe_typography_AI3 1.0 1\n\
  343. %%%%IncludeResource: procset Adobe_pattern_AI3 1.0 0\n\
  344. %%%%IncludeResource: procset Adobe_Illustrator_AI3 1.0 1\n\
  345. %%%%EndProlog\n");
  346. _update_buffer (page_header);
  347. /* beginning of Setup section */
  348. sprintf (page_header->point, "\
  349. %%%%BeginSetup\n");
  350. _update_buffer (page_header);
  351. /* include fonts if any */
  352. if (fonts_used)
  353. {
  354. for (i = 0; i < PL_NUM_PS_FONTS; i++)
  355. if (_plotter->data->page->ps_font_used[i])
  356. {
  357. sprintf (page_header->point, "\
  358. %%%%IncludeFont: %s\n",
  359. _pl_g_ps_font_info[i].ps_name);
  360. _update_buffer (page_header);
  361. }
  362. for (i = 0; i < PL_NUM_PCL_FONTS; i++)
  363. if (_plotter->data->page->pcl_font_used[i])
  364. {
  365. sprintf (page_header->point, "\
  366. %%%%IncludeFont: %s\n",
  367. _pl_g_pcl_font_info[i].ps_name);
  368. _update_buffer (page_header);
  369. }
  370. }
  371. /* do setup of procsets */
  372. if (_plotter->ai_version == AI_VERSION_5)
  373. sprintf (page_header->point, "\
  374. Adobe_level2_AI5 /initialize get exec\n\
  375. Adobe_Illustrator_AI5_vars Adobe_Illustrator_AI5 Adobe_typography_AI5 /initialize get exec\n\
  376. Adobe_ColorImage_AI6 /initialize get exec\n\
  377. Adobe_Illustrator_AI5 /initialize get exec\n");
  378. else /* AI_VERSION_3 */
  379. sprintf (page_header->point, "\
  380. Adobe_cmykcolor /initialize get exec\n\
  381. Adobe_cshow /initialize get exec\n\
  382. Adobe_customcolor /initialize get exec\n\
  383. Adobe_typography_AI3 /initialize get exec\n\
  384. Adobe_pattern_AI3 /initialize get exec\n\
  385. Adobe_Illustrator_AI3 /initialize get exec\n");
  386. _update_buffer (page_header);
  387. if (fonts_used)
  388. /* do whatever font reencodings are needed */
  389. {
  390. /* don't modify StandardEncoding */
  391. sprintf (page_header->point, "[\n\
  392. TE\n");
  393. _update_buffer (page_header);
  394. /* reencode each used font */
  395. for (i = 0; i < PL_NUM_PS_FONTS; i++)
  396. if (_plotter->data->page->ps_font_used[i])
  397. {
  398. const char *reencoding;
  399. if (_pl_g_ps_font_info[i].iso8859_1) /* ISO-Latin-1 font */
  400. reencoding = "";
  401. else if (strcmp (_pl_g_ps_font_info[i].ps_name, "ZapfDingbats")== 0)
  402. reencoding = _ai_zapf_dingbats_reencoding;
  403. else if (strcmp (_pl_g_ps_font_info[i].ps_name, "Symbol") == 0)
  404. reencoding = _ai_symbol_reencoding;
  405. else /* don't know what to do */
  406. reencoding = "";
  407. sprintf (page_header->point, "\
  408. %%AI3_BeginEncoding: _%s %s\n\
  409. [%s/_%s/%s 0 0 0 TZ\n\
  410. %%AI3_EndEncoding AdobeType\n",
  411. _pl_g_ps_font_info[i].ps_name, _pl_g_ps_font_info[i].ps_name,
  412. reencoding,
  413. _pl_g_ps_font_info[i].ps_name, _pl_g_ps_font_info[i].ps_name);
  414. _update_buffer (page_header);
  415. }
  416. for (i = 0; i < PL_NUM_PCL_FONTS; i++)
  417. if (_plotter->data->page->pcl_font_used[i])
  418. {
  419. sprintf (page_header->point, "\
  420. %%AI3_BeginEncoding: _%s %s\n\
  421. [/_%s/%s 0 0 0 TZ\n\
  422. %%AI3_EndEncoding TrueType\n",
  423. _pl_g_pcl_font_info[i].ps_name, _pl_g_pcl_font_info[i].ps_name,
  424. _pl_g_pcl_font_info[i].ps_name, _pl_g_pcl_font_info[i].ps_name);
  425. _update_buffer (page_header);
  426. }
  427. }
  428. /* end of Setup section */
  429. sprintf (page_header->point, "\
  430. %%%%EndSetup\n");
  431. _update_buffer (page_header);
  432. if (_plotter->ai_version >= AI_VERSION_5)
  433. /* objects will belong to layer #1 (if layers are supported) */
  434. {
  435. /* 10 layer attributes, of which the first 6 are 0/1 flags, with
  436. `1' meaning: visible / preview / enabled / printing layer /
  437. dimmed / has multilayer masks. The next attribute is a color
  438. ID for the layer (0 = light blue), and the final three
  439. attributes are intensities of R,G,B, on a 0..255 scale
  440. (79,128,255 apparently being what AI normally uses) */
  441. sprintf (page_header->point, "\
  442. %%AI5_BeginLayer\n\
  443. 1 1 1 1 0 0 0 79 128 255 Lb\n\
  444. (Layer 1) Ln\n");
  445. _update_buffer (page_header);
  446. }
  447. /* place header in the plOutbuf of page */
  448. _plotter->data->page->header = page_header;
  449. }
  450. /* End of Page Header */
  451. /* Beginning of Page Trailer */
  452. {
  453. plOutbuf *page_trailer;
  454. page_trailer = _new_outbuf ();
  455. if (_plotter->ai_version >= AI_VERSION_5)
  456. /* after outputing objects, must end layer */
  457. {
  458. sprintf (page_trailer->point, "\
  459. LB\n\
  460. %%AI5_EndLayer--\n");
  461. _update_buffer (page_trailer);
  462. }
  463. sprintf (page_trailer->point, "\
  464. %%%%PageTrailer\n\
  465. gsave annotatepage grestore showpage\n");
  466. _update_buffer (page_trailer);
  467. /* trailer: terminate procsets */
  468. if (_plotter->ai_version == AI_VERSION_5)
  469. sprintf (page_trailer->point, "\
  470. %%%%Trailer\n\
  471. Adobe_Illustrator_AI5 /terminate get exec\n\
  472. Adobe_ColorImage_AI6 /terminate get exec\n\
  473. Adobe_typography_AI5 /terminate get exec\n\
  474. Adobe_level2_AI5 /terminate get exec\n\
  475. %%%%EOF\n");
  476. else /* AI_VERSION_3 */
  477. sprintf (page_trailer->point, "\
  478. %%%%Trailer\n\
  479. Adobe_Illustrator_AI3 /terminate get exec\n\
  480. Adobe_pattern_AI3 /terminate get exec\n\
  481. Adobe_typography_AI3 /terminate get exec\n\
  482. Adobe_customcolor /terminate get exec\n\
  483. Adobe_cshow /terminate get exec\n\
  484. Adobe_cmykcolor /terminate get exec\n\
  485. Adobe_packedarray /terminate get exec\n\
  486. %%%%EOF\n");
  487. _update_buffer (page_trailer);
  488. /* place header in the plOutbuf of the page */
  489. _plotter->data->page->trailer = page_trailer;
  490. }
  491. /* End of Page Trailer */
  492. return true;
  493. }