tioga 1.11 → 1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/Tioga_README +58 -35
  2. data/{split/scripts → bin}/tioga +1 -1
  3. data/{split → ext/Dobjects}/Dtable/dtable.c +81 -15
  4. data/{split → ext/Dobjects}/Dtable/dtable_intern.h +0 -0
  5. data/ext/Dobjects/Dtable/extconf.rb +7 -0
  6. data/{split → ext/Dobjects}/Dtable/include/dtable.h +0 -0
  7. data/{split → ext/Dobjects}/Dvector/dvector.c +361 -51
  8. data/{split → ext/Dobjects}/Dvector/dvector_intern.h +0 -0
  9. data/ext/Dobjects/Dvector/extconf.rb +22 -0
  10. data/{split/Dtable → ext/Dobjects/Dvector/include}/dvector.h +0 -0
  11. data/ext/Dobjects/Function/extconf.rb +7 -0
  12. data/{split → ext/Dobjects}/Function/function.c +636 -11
  13. data/{split → ext/Dobjects}/Function/joint_qsort.c +0 -0
  14. data/ext/Flate/extconf.rb +26 -0
  15. data/{split → ext}/Flate/flate.c +7 -3
  16. data/{split → ext}/Flate/flate_intern.h +0 -0
  17. data/{split → ext}/Flate/include/flate.h +0 -0
  18. data/ext/Flate/zlib/adler32.c +149 -0
  19. data/ext/Flate/zlib/compress.c +79 -0
  20. data/ext/Flate/zlib/crc32.c +423 -0
  21. data/ext/Flate/zlib/crc32.h +441 -0
  22. data/ext/Flate/zlib/deflate.c +1736 -0
  23. data/ext/Flate/zlib/deflate.h +331 -0
  24. data/ext/Flate/zlib/gzio.c +1026 -0
  25. data/ext/Flate/zlib/infback.c +623 -0
  26. data/ext/Flate/zlib/inffast.c +318 -0
  27. data/ext/Flate/zlib/inffast.h +11 -0
  28. data/ext/Flate/zlib/inffixed.h +94 -0
  29. data/ext/Flate/zlib/inflate.c +1368 -0
  30. data/ext/Flate/zlib/inflate.h +115 -0
  31. data/ext/Flate/zlib/inftrees.c +329 -0
  32. data/ext/Flate/zlib/inftrees.h +55 -0
  33. data/ext/Flate/zlib/trees.c +1219 -0
  34. data/ext/Flate/zlib/trees.h +128 -0
  35. data/ext/Flate/zlib/uncompr.c +61 -0
  36. data/ext/Flate/zlib/zlib.h +1357 -0
  37. data/ext/Flate/zlib/zutil.c +318 -0
  38. data/ext/Flate/zlib/zutil.h +269 -0
  39. data/ext/Tioga/FigureMaker/__shared_axes.c +1373 -0
  40. data/ext/Tioga/FigureMaker/__shared_makers.c +1303 -0
  41. data/{split/Tioga/pdf_font_dicts.c → ext/Tioga/FigureMaker/__shared_pdf_font_dicts.c} +0 -0
  42. data/{split/Tioga/pdfcolor.c → ext/Tioga/FigureMaker/__shared_pdfcolor.c} +0 -0
  43. data/{split/Tioga/pdfcoords.c → ext/Tioga/FigureMaker/__shared_pdfcoords.c} +0 -0
  44. data/{split/Tioga/pdffile.c → ext/Tioga/FigureMaker/__shared_pdffile.c} +0 -0
  45. data/{split/Tioga/pdfimage.c → ext/Tioga/FigureMaker/__shared_pdfimage.c} +0 -0
  46. data/{split/Tioga/pdfpath.c → ext/Tioga/FigureMaker/__shared_pdfpath.c} +0 -0
  47. data/{split/Tioga/pdftext.c → ext/Tioga/FigureMaker/__shared_pdftext.c} +0 -0
  48. data/{split/Tioga/texout.c → ext/Tioga/FigureMaker/__shared_texout.c} +0 -0
  49. data/ext/Tioga/FigureMaker/extconf.rb +7 -0
  50. data/{split/Tioga → ext/Tioga/FigureMaker}/figures.c +14 -2
  51. data/{split/Tioga → ext/Tioga/FigureMaker}/figures.h +0 -0
  52. data/{split/Tioga → ext/Tioga/FigureMaker}/generic.c +1 -2
  53. data/{split/Tioga → ext/Tioga/FigureMaker}/generic.h +0 -1
  54. data/{split/Tioga → ext/Tioga/FigureMaker}/init.c +0 -0
  55. data/{split/Tioga → ext/Tioga/FigureMaker}/pdfs.h +0 -0
  56. data/{split/Tioga → ext/Tioga/FigureMaker/shared}/axes.c +32 -7
  57. data/{split/Tioga → ext/Tioga/FigureMaker/shared}/makers.c +2 -2
  58. data/ext/Tioga/FigureMaker/shared/pdf_font_dicts.c +18253 -0
  59. data/ext/Tioga/FigureMaker/shared/pdfcolor.c +904 -0
  60. data/ext/Tioga/FigureMaker/shared/pdfcoords.c +518 -0
  61. data/ext/Tioga/FigureMaker/shared/pdffile.c +451 -0
  62. data/ext/Tioga/FigureMaker/shared/pdfimage.c +539 -0
  63. data/ext/Tioga/FigureMaker/shared/pdfpath.c +766 -0
  64. data/ext/Tioga/FigureMaker/shared/pdftext.c +710 -0
  65. data/ext/Tioga/FigureMaker/shared/texout.c +533 -0
  66. data/{split/Tioga → ext/Tioga/FigureMaker}/wrappers.c +5 -5
  67. data/{split/Tioga → ext/Tioga/FigureMaker}/wrappers.h +0 -0
  68. data/{split/Dtable → ext/includes}/defs.h +0 -0
  69. data/{split/Dtable → ext/includes}/namespace.h +0 -0
  70. data/{split/Dtable → ext/includes}/safe_double.h +0 -0
  71. data/{split → ext/includes}/symbols.c +0 -1
  72. data/{split/Dtable → ext/includes}/symbols.h +0 -0
  73. data/{split/Dtable/lib → lib/Dobjects}/Dtable_extras.rb +0 -0
  74. data/{split/Dvector/lib → lib/Dobjects}/Dvector_extras.rb +1 -0
  75. data/{split/Function/lib → lib/Dobjects}/Function_extras.rb +0 -0
  76. data/{split/Dvector/lib → lib/Dobjects}/Numeric_extras.rb +0 -0
  77. data/{split/Tioga/lib → lib/Tioga}/Arcs_and_Circles.rb +0 -0
  78. data/{split/Tioga/lib → lib/Tioga}/ColorConstants.rb +0 -0
  79. data/{split/Tioga/lib → lib/Tioga}/Colorbars.rb +0 -0
  80. data/{split/Tioga/lib → lib/Tioga}/Colormaps.rb +0 -0
  81. data/{split/Tioga/lib → lib/Tioga}/Coordinate_Conversions.rb +0 -0
  82. data/{split/Tioga/lib → lib/Tioga}/Creating_Paths.rb +0 -0
  83. data/{split/Tioga/lib → lib/Tioga}/Doc.rb +0 -0
  84. data/{split/Tioga/lib → lib/Tioga}/Executive.rb +0 -0
  85. data/{split/Tioga/lib → lib/Tioga}/FigMkr.rb +13 -70
  86. data/{split/Tioga/lib → lib/Tioga}/FigureConstants.rb +0 -0
  87. data/{split/Tioga/lib → lib/Tioga}/Figures_and_Plots.rb +0 -0
  88. data/{split/Tioga/lib → lib/Tioga}/Images.rb +0 -0
  89. data/{split/Tioga/lib → lib/Tioga}/Legends.rb +0 -0
  90. data/{split/Tioga/lib → lib/Tioga}/MarkerConstants.rb +0 -0
  91. data/{split/Tioga/lib → lib/Tioga}/Markers.rb +0 -0
  92. data/{split/Tioga/lib → lib/Tioga}/Page_Frame_Bounds.rb +0 -0
  93. data/{split/Tioga/lib → lib/Tioga}/Rectangles.rb +0 -0
  94. data/{split/Tioga/lib → lib/Tioga}/Shading.rb +0 -0
  95. data/{split/Tioga/lib → lib/Tioga}/Special_Paths.rb +0 -0
  96. data/{split/Tioga/lib → lib/Tioga}/Strokes.rb +0 -0
  97. data/{split/Tioga/lib → lib/Tioga}/TeX_Text.rb +0 -0
  98. data/{split/Tioga/lib → lib/Tioga}/TexPreamble.rb +0 -0
  99. data/{split/Tioga/lib → lib/Tioga}/Titles_and_Labels.rb +0 -0
  100. data/{split/Tioga/lib → lib/Tioga}/Transparency.rb +0 -0
  101. data/{split/Tioga/lib → lib/Tioga}/Using_Paths.rb +0 -0
  102. data/{split/Tioga/lib → lib/Tioga}/Utils.rb +74 -0
  103. data/{split/Tioga/lib → lib/Tioga}/X_and_Y_Axes.rb +0 -0
  104. data/{split/Tioga/lib → lib/Tioga}/irb_tioga.rb +0 -0
  105. data/{split/Tioga/lib → lib/Tioga}/maker.rb +0 -0
  106. data/{split/Tioga/lib → lib/Tioga}/tioga.rb +0 -0
  107. data/{split/Tioga/lib → lib/Tioga}/tioga_ui.rb +0 -0
  108. data/{split/Tioga/lib → lib/Tioga}/tioga_ui_cmds.rb +0 -0
  109. data/tests/Icon_Test.pdf +0 -0
  110. data/tests/benchmark_dvector_reads.rb +20 -42
  111. data/tests/tc_Dvector.rb +45 -4
  112. data/tests/tc_Flate.rb +4 -5
  113. data/tests/tc_Function.rb +79 -0
  114. data/tests/vg.log +1453 -0
  115. metadata +141 -122
  116. data/split/Dtable/extconf.rb +0 -4
  117. data/split/Dvector/defs.h +0 -39
  118. data/split/Dvector/extconf.rb +0 -4
  119. data/split/Dvector/include/dvector.h +0 -77
  120. data/split/Dvector/namespace.h +0 -59
  121. data/split/Dvector/safe_double.h +0 -104
  122. data/split/Dvector/symbols.h +0 -52
  123. data/split/Flate/defs.h +0 -39
  124. data/split/Flate/extconf.rb +0 -19
  125. data/split/Flate/namespace.h +0 -59
  126. data/split/Flate/safe_double.h +0 -104
  127. data/split/Flate/symbols.h +0 -52
  128. data/split/Function/defs.h +0 -39
  129. data/split/Function/dvector.h +0 -77
  130. data/split/Function/extconf.rb +0 -4
  131. data/split/Function/namespace.h +0 -59
  132. data/split/Function/safe_double.h +0 -104
  133. data/split/Function/symbols.h +0 -52
  134. data/split/Tioga/defs.h +0 -39
  135. data/split/Tioga/dtable.h +0 -35
  136. data/split/Tioga/dvector.h +0 -77
  137. data/split/Tioga/extconf.rb +0 -4
  138. data/split/Tioga/flate.h +0 -98
  139. data/split/Tioga/mk_tioga_sty.rb +0 -53
  140. data/split/Tioga/namespace.h +0 -59
  141. data/split/Tioga/safe_double.h +0 -104
  142. data/split/Tioga/symbols.h +0 -52
  143. data/split/defs.h +0 -39
  144. data/split/extconf.rb +0 -125
  145. data/split/mkmf2.rb +0 -1623
  146. data/split/namespace.h +0 -59
  147. data/split/safe_double.h +0 -104
  148. data/split/symbols.h +0 -52
@@ -0,0 +1,710 @@
1
+ /* pdftext.c */
2
+ /*
3
+ Copyright (C) 2005 Bill Paxton
4
+
5
+ This file is part of Tioga.
6
+
7
+ Tioga is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Library Public License as published
9
+ by the Free Software Foundation; either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Tioga 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 Library General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Library General Public License
18
+ along with Tioga; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ */
21
+
22
+ #include "figures.h"
23
+ #include "pdfs.h"
24
+
25
+
26
+ void
27
+ Init_Font_Dictionary(void)
28
+ {
29
+ int i, num_fonts = num_pdf_standard_fonts;
30
+ Font_Dictionary *font_info;
31
+ for (i = 0; i < num_fonts; i++) {
32
+ font_info = (Font_Dictionary *)calloc(1, sizeof(Font_Dictionary));
33
+ font_info->afm = &afm_array[i];
34
+ font_info->font_num = font_info->afm->font_num;
35
+ font_info->in_use = false;
36
+ font_info->next = font_dictionaries;
37
+ font_dictionaries = font_info;
38
+ }
39
+ }
40
+
41
+
42
+ static void
43
+ Write_Font_Dictionary(FILE *file, Old_Font_Dictionary *fi)
44
+ {
45
+ int i;
46
+ fprintf(file, "{\n");
47
+ fprintf(file, "\t%i, // font_num\n", fi->font_num);
48
+ fprintf(file, "\t\"%s\", // font_name\n", fi->font_name);
49
+ fprintf(file, "\t%4i, // firstChar\n", fi->firstChar);
50
+ fprintf(file, "\t%4i, // lastChar\n", fi->lastChar);
51
+
52
+ fprintf(file, "\t{ // char_width\n");
53
+ for (i=0; i<255; i++)
54
+ fprintf(file, "\t\t%4i, // %i\n", fi->char_width[i], i);
55
+ fprintf(file, "\t\t%4i }, // char_width\n", fi->char_width[255]);
56
+
57
+ fprintf(file, "\t{ // char_llx\n");
58
+ for (i=0; i<255; i++) fprintf(file, "\t\t%4i, // %i\n", fi->char_llx[i], i);
59
+ fprintf(file, "\t\t%4i }, // char_llx\n", fi->char_llx[255]);
60
+
61
+ fprintf(file, "\t{ // char_lly\n");
62
+ for (i=0; i<255; i++) fprintf(file, "\t\t%4i, // %i\n", fi->char_lly[i], i);
63
+ fprintf(file, "\t\t4%i }, // char_lly\n", fi->char_lly[255]);
64
+
65
+ fprintf(file, "\t{ // char_urx\n");
66
+ for (i=0; i<255; i++) fprintf(file, "\t\t%4i, // %i\n", fi->char_urx[i], i);
67
+ fprintf(file, "\t\t%4i }, // char_urx\n", fi->char_urx[255]);
68
+
69
+ fprintf(file, "\t{ // char_ury\n");
70
+ for (i=0; i<255; i++) fprintf(file, "\t\t%4i, // %i\n", fi->char_ury[i], i);
71
+ fprintf(file, "\t\t%4i }, // char_ury\n", fi->char_ury[255]);
72
+
73
+ fprintf(file, "\t%i, // flags\n", fi->flags);
74
+ fprintf(file, "\t%i, // fnt_llx\n", fi->fnt_llx);
75
+ fprintf(file, "\t%i, // fnt_lly\n", fi->fnt_lly);
76
+ fprintf(file, "\t%i, // fnt_urx\n", fi->fnt_urx);
77
+ fprintf(file, "\t%i, // fnt_ury\n", fi->fnt_ury);
78
+ fprintf(file, "\t%i, // italicAngle\n", fi->italicAngle);
79
+ fprintf(file, "\t%i, // ascent\n", fi->ascent);
80
+ fprintf(file, "\t%i, // descent\n", fi->descent);
81
+ fprintf(file, "\t%i, // capHeight\n", fi->capHeight);
82
+ fprintf(file, "\t%i // stemV\n", fi->stemV);
83
+
84
+ fprintf(file, "} // %s\n", fi->font_name);
85
+ }
86
+
87
+
88
+ static void
89
+ WriteFontDictsToFile(void)
90
+ {
91
+ Old_Font_Dictionary *font_info;
92
+ FILE *file;
93
+ file = fopen("pdf_font_dicts.c", "w");
94
+ fprintf(file, "Font_Dict_Array font_dictionaries[]"
95
+ " = { // afm info for PDF fonts \n");
96
+ for (font_info = old_font_dictionaries; font_info != NULL;
97
+ font_info = font_info->next) {
98
+ Write_Font_Dictionary(file, font_info);
99
+ if (font_info->next != NULL) fprintf(file, ",\n");
100
+ }
101
+ fprintf(file, "}; // end of font_dictionaries declaration \n");
102
+ fclose(file);
103
+ }
104
+
105
+
106
+ static void
107
+ Record_Font_In_Use(Font_Dictionary *font_info, int font_number)
108
+ {
109
+ if (font_info->in_use) return;
110
+ font_info->afm->font_num = font_number;
111
+ font_info->obj_num = next_available_object_number++;
112
+ font_info->in_use = true;
113
+ if (font_number > num_pdf_standard_fonts) {
114
+ font_info->widths_obj_num = next_available_object_number++;
115
+ font_info->descriptor_obj_num = next_available_object_number++;
116
+ }
117
+ }
118
+
119
+
120
+ #define DEBUG 0
121
+ #define MAXSTR 100
122
+
123
+ static Font_Dictionary *
124
+ GetFontDict(char *font_name, int font_number, int *ierr)
125
+ {
126
+ Font_Dictionary *font_info;
127
+ for (font_info = font_dictionaries; font_info != NULL;
128
+ font_info = font_info->next) {
129
+ if (strcmp(font_name, font_info->afm->font_name) == 0) {
130
+ Record_Font_In_Use(font_info, font_number);
131
+ return font_info;
132
+ }
133
+ }
134
+ RAISE_ERROR_s("Sorry: invalid font name (%s)", font_name, ierr);
135
+ return NULL;
136
+ }
137
+
138
+
139
+ static Font_Dictionary *
140
+ GetFontInfo(int font_number, int *ierr)
141
+ {
142
+ Font_Dictionary *f;
143
+ for (f = font_dictionaries; f != NULL; f = f->next) {
144
+ if (f->font_num == font_number) {
145
+ Record_Font_In_Use(f, font_number);
146
+ return f;
147
+ }
148
+ }
149
+ if (font_number > 0 && font_number <= num_predefined_fonts)
150
+ return GetFontDict(predefined_Fonts[font_number], font_number, ierr);
151
+ return NULL;
152
+ }
153
+
154
+
155
+ OBJ_PTR
156
+ c_register_font(OBJ_PTR fmkr, FM *p, char *font_name, int *ierr)
157
+ {
158
+ Font_Dictionary *f;
159
+ int i;
160
+ for (f = font_dictionaries; f != NULL; f = f->next) {
161
+ if (strcmp(f->afm->font_name, font_name) == 0)
162
+ return Integer_New(f->afm->font_num);
163
+ }
164
+ for (i = 1; i <= num_predefined_fonts; i++) {
165
+ if (strcmp(predefined_Fonts[i], font_name)==0) {
166
+ f = GetFontDict(font_name, i, ierr);
167
+ if (f == NULL)
168
+ RAISE_ERROR_s("Error in reading font metrics for %s", font_name,
169
+ ierr);
170
+ return Integer_New(i);
171
+ }
172
+ }
173
+ f = GetFontDict(font_name, next_available_font_number, ierr);
174
+ if (f == NULL) RAISE_ERROR_s("Error in reading font metrics for %s",
175
+ font_name, ierr);
176
+ next_available_font_number++;
177
+ return Integer_New(next_available_font_number);
178
+ }
179
+
180
+
181
+ bool
182
+ Used_Any_Fonts(void)
183
+ {
184
+ Font_Dictionary *f;
185
+ for (f = font_dictionaries; f != NULL; f = f->next) {
186
+ if (f->in_use) return true;
187
+ }
188
+ return false;
189
+ }
190
+
191
+
192
+ void
193
+ Clear_Fonts_In_Use_Flags(void)
194
+ {
195
+ Font_Dictionary *f;
196
+ for (f = font_dictionaries; f != NULL; f = f->next) {
197
+ f->in_use = false;
198
+ }
199
+ }
200
+
201
+
202
+ void
203
+ Write_Font_Descriptors(void)
204
+ {
205
+ Font_Dictionary *f;
206
+ for (f = font_dictionaries; f != NULL; f = f->next) {
207
+ if (!f->in_use || f->font_num <= num_pdf_standard_fonts) continue;
208
+ Record_Object_Offset(f->descriptor_obj_num);
209
+ fprintf(OF, "%i 0 obj << /Type /FontDescriptor /FontName /%s\n",
210
+ f->descriptor_obj_num, f->afm->font_name);
211
+ fprintf(OF, " /Flags %i /FontBBox [ %i %i %i %i ]\n",
212
+ f->afm->flags, f->afm->fnt_llx, f->afm->fnt_lly, f->afm->fnt_urx,
213
+ f->afm->fnt_ury);
214
+ fprintf(OF, " /ItalicAngle %i /Ascent %i /Descent %i "
215
+ "/CapHeight %i /StemV %i\n", f->afm->italicAngle, f->afm->ascent,
216
+ f->afm->descent, f->afm->capHeight, f->afm->stemV);
217
+ fprintf(OF, ">> endobj\n");
218
+ }
219
+ }
220
+
221
+
222
+ void
223
+ Write_Font_Widths(void)
224
+ {
225
+ Font_Dictionary *f;
226
+ int i, cnt = 0;
227
+ for (f = font_dictionaries; f != NULL; f = f->next) {
228
+ if (!f->in_use || f->font_num <= num_pdf_standard_fonts) continue;
229
+ Record_Object_Offset(f->widths_obj_num);
230
+ fprintf(OF, "%i 0 obj [\n ", f->widths_obj_num);
231
+ for (i = f->afm->firstChar; i <= f->afm->lastChar; i++) {
232
+ fprintf(OF, "%i ", f->afm->char_width[i]);
233
+ if (++cnt % 16 == 0) fprintf(OF, "\n ");
234
+ }
235
+ fprintf(OF, "\n] endobj\n");
236
+ }
237
+ }
238
+
239
+
240
+ void
241
+ Write_Font_Dictionaries(void)
242
+ {
243
+ if (0) WriteFontDictsToFile(); // creates pdf_font_dicts.c
244
+ Font_Dictionary *f;
245
+ for (f = font_dictionaries; f != NULL; f = f->next) {
246
+ if (!f->in_use) continue;
247
+ Record_Object_Offset(f->obj_num);
248
+ fprintf(OF, "%i 0 obj << /Type /Font /Subtype /Type1 /BaseFont /%s",
249
+ f->obj_num, f->afm->font_name);
250
+ if (strcmp(f->afm->font_name,"Symbol") != 0
251
+ && strcmp(f->afm->font_name,"ZapfDingbats") != 0)
252
+ fprintf(OF, " /Encoding /MacRomanEncoding\n");
253
+ else
254
+ fprintf(OF, "\n");
255
+ if (f->font_num > num_pdf_standard_fonts)
256
+ fprintf(OF, " /FirstChar %i /LastChar %i /Widths %i 0 R "
257
+ "/FontDescriptor %i 0 R\n", f->afm->firstChar,
258
+ f->afm->lastChar, f->widths_obj_num, f->descriptor_obj_num);
259
+ fprintf(OF, ">> endobj\n");
260
+ }
261
+ }
262
+
263
+
264
+ static void
265
+ GetStringInfo(FM *p, int font_number, unsigned char *text, double ft_ht,
266
+ double *llx_ptr, double *lly_ptr, double *urx_ptr,
267
+ double *ury_ptr, double *width_ptr, int *ierr)
268
+ {
269
+ Font_Dictionary *fontinfo = GetFontInfo(font_number, ierr);
270
+ if (*ierr != 0) return;
271
+ if (fontinfo == NULL) {
272
+ RAISE_ERROR_i("Sorry: invalid font number (%i): "
273
+ "must register font before use it.", font_number, ierr);
274
+ return;
275
+ }
276
+ unsigned char *c_ptr = text, c;
277
+ double width = 0, llx, lly, urx, ury;
278
+ if (fontinfo == NULL || text == NULL || text[0] == '\0') {
279
+ *width_ptr = *llx_ptr = *lly_ptr = *urx_ptr = *ury_ptr = 0;
280
+ return;
281
+ }
282
+ c = *c_ptr;
283
+ llx = fontinfo->afm->char_llx[c];
284
+ lly = fontinfo->afm->char_lly[c];
285
+ ury = fontinfo->afm->char_ury[c];
286
+ while ((c = *c_ptr++) != '\0') {
287
+ width += fontinfo->afm->char_width[c];
288
+ if (fontinfo->afm->char_ury[c] > ury) ury = fontinfo->afm->char_ury[c];
289
+ if (fontinfo->afm->char_lly[c] < lly) lly = fontinfo->afm->char_lly[c];
290
+ }
291
+ urx = llx + width;
292
+ *width_ptr = width * ft_ht * 1e-3;
293
+ *llx_ptr = ft_ht * 1e-3 * llx;
294
+ *lly_ptr = ft_ht * 1e-3 * lly;
295
+ *ury_ptr = ft_ht * 1e-3 * ury;
296
+ *urx_ptr = ft_ht * 1e-3 * (urx - 70.0); // adjust for extra white
297
+ // space on right
298
+ }
299
+
300
+
301
+ OBJ_PTR
302
+ c_marker_string_info(OBJ_PTR fmkr, FM *p, int fnt, unsigned char *text,
303
+ double scale, int *ierr)
304
+ {
305
+ double ft_ht = (p->default_text_scale * scale * p->default_font_size
306
+ * ENLARGE);
307
+ int ft_height = ROUND(ft_ht);
308
+ ft_ht = ft_height;
309
+ double llx, lly, urx, ury, width;
310
+ GetStringInfo(p, fnt, text, ft_ht, &llx, &lly, &urx, &ury, &width, ierr);
311
+ if (*ierr != 0) RETURN_NIL;
312
+ OBJ_PTR result = Array_New(5);
313
+ width = convert_output_to_figure_dx(p, width);
314
+ llx = convert_output_to_figure_dx(p, llx);
315
+ urx = convert_output_to_figure_dx(p, urx);
316
+ lly = convert_output_to_figure_dy(p, lly);
317
+ ury = convert_output_to_figure_dy(p, ury);
318
+ Array_Store(result, 0, Float_New(width), ierr);
319
+ Array_Store(result, 1, Float_New(llx), ierr);
320
+ Array_Store(result, 2, Float_New(lly), ierr);
321
+ Array_Store(result, 3, Float_New(urx), ierr);
322
+ Array_Store(result, 4, Float_New(ury), ierr);
323
+ return result;
324
+ }
325
+
326
+
327
+ #define TRANSFORM_VEC(dx,dy) tmp = dx; dx = (dx) * a + (dy) * c; dy = tmp * b + (dy) * d;
328
+
329
+
330
+ static void
331
+ c_rotated_string_at_points(OBJ_PTR fmkr, FM *p, double rotation,
332
+ int font_number, unsigned char *text, double scale,
333
+ int n, double *xs, double *ys, int alignment,
334
+ int just, double horizontal_scaling,
335
+ double vertical_scaling, double italic_angle,
336
+ double ascent_angle, int *ierr)
337
+ {
338
+ double ft_ht = (p->default_text_scale * scale * p->default_font_size
339
+ * ENLARGE);
340
+ int i, ft_height = ROUND(ft_ht), justification = just - 1;
341
+ ft_ht = ft_height;
342
+ if (constructing_path) {
343
+ RAISE_ERROR("Sorry: must not be constructing a path when show marker",
344
+ ierr);
345
+ return;
346
+ }
347
+ double llx, lly, urx, ury, width, shiftx, shifty, tmp;
348
+ // the initial transform
349
+ double a = horizontal_scaling, b = 0.0, c = 0.0, d = vertical_scaling;
350
+ GetStringInfo(p, font_number, text, ft_ht, &llx, &lly, &urx, &ury, &width,
351
+ ierr);
352
+ if (*ierr != 0) return;
353
+ // translate according to justification and alignment
354
+ // note that we use the bbox to calculate shifts so 'center' means
355
+ // center of bbox
356
+ if (italic_angle != 0) {
357
+ double skew = sin(italic_angle / RADIANS_TO_DEGREES);
358
+ c -= skew * a;
359
+ d -= skew * b;
360
+ }
361
+ if (ascent_angle != 0) {
362
+ double skew = sin(ascent_angle / RADIANS_TO_DEGREES);
363
+ a += skew * c;
364
+ b += skew * d;
365
+ }
366
+ if (rotation != 0) {
367
+ double xa, xb, xc, xd; // new transform
368
+ double cs = cos(rotation / RADIANS_TO_DEGREES);
369
+ double sn = sin(rotation / RADIANS_TO_DEGREES);
370
+ xa = cs * a + sn * c;
371
+ xb = cs * b + sn * d;
372
+ xc = -sn * a + cs * c;
373
+ xd = -sn * b + cs * d;
374
+ a = xa;
375
+ b = xb;
376
+ c = xc;
377
+ d = xd;
378
+ }
379
+ switch (justification) {
380
+ case LEFT_JUSTIFIED:
381
+ shiftx = 0; break;
382
+ case CENTERED: // CENTERED for marker means centered on BBOX
383
+ shiftx = -(urx + llx) / 2;
384
+ break;
385
+ case RIGHT_JUSTIFIED:
386
+ shiftx = -width;
387
+ // the following hack compensates for Arrowhead bbox in
388
+ // ZaphDingbats needed to make tip of arrowhead fall on the
389
+ // reference point correctly
390
+ if (font_number == 14 && strlen((char *)text) == 1
391
+ && text[0] == 0344) {
392
+ shiftx *= 0.9;
393
+ }
394
+ break;
395
+ default:
396
+ RAISE_ERROR_i("Sorry: invalid setting for marker justification (%i)",
397
+ justification, ierr);
398
+ return;
399
+ }
400
+ switch (alignment) {
401
+ case ALIGNED_AT_TOP: shifty = -ury; break;
402
+ case ALIGNED_AT_MIDHEIGHT: shifty = -(ury + lly)/2; break;
403
+ case ALIGNED_AT_BASELINE: shifty = 0; break;
404
+ case ALIGNED_AT_BOTTOM: shifty = -lly; break;
405
+ default:
406
+ RAISE_ERROR_i("Sorry: invalid setting for marker alignment (%i)",
407
+ alignment, ierr);
408
+ return;
409
+ }
410
+ // transform the bbox
411
+ // if we're rotated we'll need all 4 corners of bbox
412
+ double llx2 = llx, lly2 = lly, urx2 = urx, ury2 = ury;
413
+ TRANSFORM_VEC(llx, lly)
414
+ TRANSFORM_VEC(urx, ury)
415
+ TRANSFORM_VEC(llx2, ury2)
416
+ TRANSFORM_VEC(urx2, lly2)
417
+ TRANSFORM_VEC(shiftx, shifty)
418
+ fprintf(TF, "BT /F%i %i Tf\n", font_number, ft_height);
419
+ if (0 && horizontal_scaling != 1.0) {
420
+ fprintf(TF, "%d Tz\n", ROUND(100 * ABS(horizontal_scaling)));
421
+ }
422
+ double x, y, prev_x = 0, prev_y = 0, dx, dy;
423
+ //int idx, idy;
424
+ for (i = 0; i < n; i++) {
425
+ unsigned char *cp = text, char_code;
426
+ x = convert_figure_to_output_x(p, xs[i]) + shiftx;
427
+ y = convert_figure_to_output_y(p, ys[i]) + shifty;
428
+ if(!is_okay_number(x) || !is_okay_number(y))
429
+ continue; // we forget this point if at least one coordinate
430
+ // is not 'real'
431
+ update_bbox(p, x + llx, y + lly);
432
+ update_bbox(p, x + urx, y + ury);
433
+ update_bbox(p, x + llx2, y + ury2);
434
+ update_bbox(p, x + urx2, y + lly2);
435
+ dx = x - prev_x; dy = y - prev_y;
436
+ //idx = ROUND(dx); idy = ROUND(dy);
437
+ //prev_x = prev_x + idx; prev_y = prev_y + idy;
438
+ prev_x = prev_x + dx; prev_y = prev_y + dy;
439
+ if (b == 0 && c == 0 && a == 1 && d == 1) {
440
+ //fprintf(TF, "%i %i Td (", idx, idy);
441
+ fprintf(TF, "%0.6f %0.6f Td (", dx, dy);
442
+ }
443
+ else { // need high precision when doing rotations
444
+ fprintf(TF, "%0.6f %0.6f %0.6f %0.6f %0.6f %0.6f Tm (",
445
+ a, b, c, d, x, y);
446
+ }
447
+ while ((char_code = *cp++) != '\0') {
448
+ if (char_code == '\\')
449
+ fprintf(TF, "\\\\");
450
+ else if (char_code == '(' || char_code == ')')
451
+ fprintf(TF, "\\%c", char_code);
452
+ else
453
+ fprintf(TF, "%c", char_code);
454
+ }
455
+ fprintf(TF, ") Tj\n");
456
+ }
457
+ fprintf(TF, "ET\n");
458
+ }
459
+
460
+
461
+ static OBJ_PTR get1_obj(bool is_list, OBJ_PTR obj, int indx, int* ierr) {
462
+ if (is_list) {
463
+ int len;
464
+ len = Array_Len(obj, ierr); if (*ierr != 0) return 0.0;
465
+ obj = Array_Entry(obj, indx % len, ierr); if (*ierr != 0) return 0.0;
466
+ }
467
+ return obj;
468
+ }
469
+
470
+
471
+ static double get1_dbl(bool is_list, OBJ_PTR obj, int indx, int* ierr) {
472
+ if (is_list) {
473
+ int len = Array_Len(obj, ierr); if (*ierr != 0) return 0.0;
474
+ return Array_Entry_double(obj, indx % len, ierr); if (*ierr != 0) return 0.0;
475
+ }
476
+ return Number_to_double(obj, ierr);
477
+ }
478
+
479
+
480
+ static int get1_int(bool is_list, OBJ_PTR obj, int indx, int* ierr) {
481
+ if (is_list) {
482
+ int len = Array_Len(obj, ierr); if (*ierr != 0) return 0.0;
483
+ return Array_Entry_int(obj, indx % len, ierr); if (*ierr != 0) return 0.0;
484
+ }
485
+ return Number_to_int(obj, ierr);
486
+ }
487
+
488
+
489
+ void
490
+ c_private_show_marker(OBJ_PTR fmkr, FM *p, OBJ_PTR args, int *ierr)
491
+ {
492
+ OBJ_PTR marker_obj, font_obj, mode_obj, align_obj, just_obj, stroke_width_obj, string, x, y, x_vec, y_vec,
493
+ h_scale_obj, v_scale_obj, scale_obj, it_angle_obj, ascent_angle_obj, angle_obj,
494
+ fill_color_obj, stroke_color_obj;
495
+ int c, alignment, justification, fnt_num, n, num_times, num_per_call, i, mode, len;
496
+ double h_scale, v_scale, scale, it_angle, ascent_angle, angle;
497
+ unsigned char *text = NULL, buff[2];
498
+ double *xs, *ys, xloc, yloc, prev_line_width = -1;
499
+ double stroke_color_R = 0.0, stroke_color_G = 0.0, stroke_color_B = 0.0;
500
+ double fill_color_R = 0.0, fill_color_G = 0.0, fill_color_B = 0.0;
501
+ double prev_stroke_color_R, prev_stroke_color_G, prev_stroke_color_B;
502
+ double prev_fill_color_R, prev_fill_color_G, prev_fill_color_B;
503
+ OBJ_PTR fill_color, stroke_color, marker;
504
+ bool do_lists, fill_color_is_list, stroke_color_is_list, stroke_width_is_list, h_scale_is_list;
505
+ bool it_angle_is_list, ascent_angle_is_list, angle_is_list, v_scale_is_list, scale_is_list;
506
+ bool align_is_list, just_is_list, marker_is_list, mode_is_list, font_is_list;
507
+
508
+ i = 0;
509
+ marker_obj = Array_Entry(args, i, ierr); i++;
510
+ font_obj = Array_Entry(args, i, ierr); i++;
511
+ mode_obj = Array_Entry(args, i, ierr); i++;
512
+ align_obj = Array_Entry(args, i, ierr); i++;
513
+ just_obj = Array_Entry(args, i, ierr); i++;
514
+ stroke_width_obj = Array_Entry(args, i, ierr); i++;
515
+ string = Array_Entry(args, i, ierr); i++;
516
+ x = Array_Entry(args, i, ierr); i++;
517
+ y = Array_Entry(args, i, ierr); i++;
518
+ x_vec = Array_Entry(args, i, ierr); i++;
519
+ y_vec = Array_Entry(args, i, ierr); i++;
520
+ h_scale_obj = Array_Entry(args, i, ierr); i++;
521
+ v_scale_obj = Array_Entry(args, i, ierr); i++;
522
+ scale_obj = Array_Entry(args, i, ierr); i++;
523
+ it_angle_obj = Array_Entry(args, i, ierr); i++;
524
+ ascent_angle_obj = Array_Entry(args, i, ierr); i++;
525
+ angle_obj = Array_Entry(args, i, ierr); i++;
526
+ fill_color_obj = Array_Entry(args, i, ierr); i++;
527
+ stroke_color_obj = Array_Entry(args, i, ierr); i++;
528
+
529
+ if (x == OBJ_NIL) {
530
+ long xlen, ylen;
531
+ xs = Vector_Data_for_Read(x_vec, &xlen, ierr);
532
+ if (*ierr != 0) return;
533
+ ys = Vector_Data_for_Read(y_vec, &ylen, ierr);
534
+ if (*ierr != 0) return;
535
+ if (xlen != ylen) {
536
+ RAISE_ERROR("Sorry: must have same number xs and ys "
537
+ "for showing markers", ierr);
538
+ return;
539
+ }
540
+ if (xlen <= 0) return;
541
+ n = xlen;
542
+ }
543
+ else {
544
+ xloc = Number_to_double(x, ierr); xs = &xloc;
545
+ yloc = Number_to_double(y, ierr); ys = &yloc;
546
+ if (*ierr != 0) return;
547
+ n = 1;
548
+ }
549
+
550
+ prev_stroke_color_R = p->stroke_color_R;
551
+ prev_stroke_color_G = p->stroke_color_G;
552
+ prev_stroke_color_B = p->stroke_color_B;
553
+ prev_fill_color_R = p->fill_color_R;
554
+ prev_fill_color_G = p->fill_color_G;
555
+ prev_fill_color_B = p->fill_color_B;
556
+ prev_line_width = p->line_width;
557
+
558
+ if (marker_obj == OBJ_NIL) {
559
+ marker_is_list = false;
560
+ } else {
561
+ marker = Array_Entry(marker_obj, 0, ierr); if (*ierr != 0) return;
562
+ marker_is_list = !Is_Kind_of_Number(marker);
563
+ }
564
+
565
+ fill_color = Array_Entry(fill_color_obj, 0, ierr); if (*ierr != 0) return;
566
+ stroke_color = Array_Entry(stroke_color_obj, 0, ierr); if (*ierr != 0) return;
567
+ fill_color_is_list = !Is_Kind_of_Number(fill_color);
568
+ stroke_color_is_list = !Is_Kind_of_Number(stroke_color);
569
+
570
+ font_is_list = (font_obj != OBJ_NIL) && (!Is_Kind_of_Integer(font_obj));
571
+ align_is_list = !Is_Kind_of_Integer(align_obj);
572
+ just_is_list = !Is_Kind_of_Integer(just_obj);
573
+ mode_is_list = (mode_obj != OBJ_NIL) && (!Is_Kind_of_Number(mode_obj));
574
+ stroke_width_is_list = stroke_width_obj != OBJ_NIL && !Is_Kind_of_Number(stroke_width_obj);
575
+ h_scale_is_list = !Is_Kind_of_Number(h_scale_obj);
576
+ v_scale_is_list = !Is_Kind_of_Number(v_scale_obj);
577
+ scale_is_list = !Is_Kind_of_Number(scale_obj);
578
+ it_angle_is_list = !Is_Kind_of_Number(it_angle_obj);
579
+ ascent_angle_is_list = !Is_Kind_of_Number(ascent_angle_obj);
580
+ angle_is_list = !Is_Kind_of_Number(angle_obj);
581
+
582
+ do_lists = fill_color_is_list || stroke_color_is_list || h_scale_is_list || v_scale_is_list || scale_is_list ||
583
+ align_is_list || just_is_list || it_angle_is_list || ascent_angle_is_list || angle_is_list;
584
+
585
+ if (do_lists) {
586
+ num_times = n; num_per_call = 1;
587
+ } else {
588
+ num_times = 1; num_per_call = n;
589
+ }
590
+
591
+ for (i=0; i<num_times; i++) {
592
+ alignment = get1_int(align_is_list, align_obj, i, ierr); if (*ierr != 0) return;
593
+ justification = 1+get1_int(just_is_list, just_obj, i, ierr); if (*ierr != 0) return;
594
+ h_scale = get1_dbl(h_scale_is_list, h_scale_obj, i, ierr); if (*ierr != 0) return;
595
+ v_scale = get1_dbl(v_scale_is_list, v_scale_obj, i, ierr); if (*ierr != 0) return;
596
+ scale = get1_dbl(scale_is_list, scale_obj, i, ierr); if (*ierr != 0) return;
597
+ it_angle = get1_dbl(it_angle_is_list, it_angle_obj, i, ierr); if (*ierr != 0) return;
598
+ ascent_angle = get1_dbl(ascent_angle_is_list, ascent_angle_obj, i, ierr); if (*ierr != 0) return;
599
+ angle = get1_dbl(angle_is_list, angle_obj, i, ierr); if (*ierr != 0) return;
600
+ fill_color = get1_obj(fill_color_is_list, fill_color_obj, i, ierr); if (*ierr != 0) return;
601
+ stroke_color = get1_obj(stroke_color_is_list, stroke_color_obj, i, ierr); if (*ierr != 0) return;
602
+
603
+ if (mode_obj != OBJ_NIL) {
604
+ mode = get1_int(mode_is_list, mode_obj, i, ierr); if (*ierr != 0) return;
605
+ } else {
606
+ mode = FILL;
607
+ }
608
+
609
+ if (font_obj != OBJ_NIL) {
610
+ fnt_num = get1_int(font_is_list, font_obj, i, ierr); if (*ierr != 0) return;
611
+ } else {
612
+ fnt_num = 1; // Times_Roman = 1
613
+ }
614
+
615
+ if (marker_obj == OBJ_NIL) {
616
+ text = (unsigned char *)(String_Ptr(string, ierr));
617
+ if (*ierr != 0) return;
618
+ } else {
619
+ marker = get1_obj(marker_is_list, marker_obj, i, ierr); if (*ierr != 0) return;
620
+ font_obj = Array_Entry(marker, 0, ierr); if (*ierr != 0) return;
621
+ fnt_num = Number_to_int(font_obj, ierr); if (*ierr != 0) return;
622
+
623
+ OBJ_PTR glyph_obj = Array_Entry(marker, 1, ierr); if (*ierr != 0) return;
624
+ c = Number_to_int(glyph_obj, ierr); if (*ierr != 0) return;
625
+
626
+ if (mode_obj == OBJ_NIL) {
627
+ len = Array_Len(marker, ierr); if (*ierr != 0) return;
628
+ if (len == 3) {
629
+ mode = STROKE;
630
+ if (stroke_width_obj == OBJ_NIL) {
631
+ OBJ_PTR s = Array_Entry(marker, 2, ierr); if (*ierr != 0) return;
632
+ double width = Number_to_double(s,ierr); if (*ierr != 0) return;
633
+ if (*ierr != 0) return;
634
+ fprintf(TF, "%0.6f w\n", width * ENLARGE);
635
+ }
636
+ }
637
+ }
638
+
639
+ font_obj = Array_Entry(marker, 0, ierr);
640
+ if (*ierr != 0) return;
641
+ fnt_num = Number_to_int(font_obj, ierr); if (*ierr != 0) return;
642
+
643
+ if (c < 0 || c > 255) {
644
+ RAISE_ERROR_i("Sorry: invalid character code (%i) : "
645
+ "must be between 0 and 255", c, ierr);
646
+ return;
647
+ }
648
+ text = buff; text[0] = c; text[1] = '\0';
649
+ }
650
+
651
+ if (stroke_width_obj != OBJ_NIL) {
652
+ double width = get1_dbl(stroke_width_is_list, stroke_width_obj, i, ierr); if (*ierr != 0) return;
653
+ if (*ierr != 0) return;
654
+ fprintf(TF, "%0.6f w\n", width * ENLARGE);
655
+ }
656
+
657
+ if (mode_obj != OBJ_NIL) {
658
+ mode = get1_int(mode_is_list, mode_obj, i, ierr); if (*ierr != 0) return;
659
+ }
660
+
661
+ fprintf(TF, "%d Tr\n", mode);
662
+
663
+ if (stroke_color != OBJ_NIL &&
664
+ (mode == STROKE || mode == FILL_AND_STROKE
665
+ || mode == STROKE_AND_CLIP || mode == FILL_STROKE_AND_CLIP)) {
666
+ Unpack_RGB(stroke_color, &stroke_color_R, &stroke_color_G,
667
+ &stroke_color_B, ierr);
668
+ if (*ierr != 0) return;
669
+ if (stroke_color_R != p->stroke_color_R
670
+ || stroke_color_G != p->stroke_color_G
671
+ || stroke_color_B != p->stroke_color_B) {
672
+ c_stroke_color_set_RGB(fmkr, p, stroke_color_R, stroke_color_G,
673
+ stroke_color_B, ierr);
674
+ if (*ierr != 0) return;
675
+ }
676
+ }
677
+
678
+ if (fill_color != OBJ_NIL &&
679
+ (mode == FILL || mode == FILL_AND_STROKE
680
+ || mode == FILL_AND_CLIP || mode == FILL_STROKE_AND_CLIP)) {
681
+ Unpack_RGB(fill_color, &fill_color_R, &fill_color_G, &fill_color_B,
682
+ ierr);
683
+ if (*ierr != 0) return;
684
+ if (fill_color_R != p->fill_color_R
685
+ || fill_color_G != p->fill_color_G
686
+ || fill_color_B != p->fill_color_B) {
687
+ c_fill_color_set_RGB(fmkr, p, fill_color_R, fill_color_G,
688
+ fill_color_B, ierr);
689
+ if (*ierr != 0) return;
690
+ }
691
+ }
692
+
693
+ c_rotated_string_at_points(fmkr, p, angle, fnt_num, text, scale, num_per_call, xs+i, ys+i,
694
+ alignment, justification, h_scale, v_scale, it_angle, ascent_angle, ierr);
695
+
696
+ if (prev_line_width != p->line_width) c_line_width_set(fmkr, p, prev_line_width, ierr);
697
+ if (prev_fill_color_R != p->fill_color_R
698
+ || prev_fill_color_G != p->fill_color_G
699
+ || prev_fill_color_B != p->fill_color_B)
700
+ c_fill_color_set_RGB(fmkr, p, prev_fill_color_R, prev_fill_color_G,
701
+ prev_fill_color_B, ierr);
702
+ if (prev_stroke_color_R != p->stroke_color_R
703
+ || prev_stroke_color_G != p->stroke_color_G
704
+ || prev_stroke_color_B != p->stroke_color_B)
705
+ c_stroke_color_set_RGB(fmkr, p, prev_stroke_color_R, prev_stroke_color_G,
706
+ prev_stroke_color_B, ierr);
707
+
708
+ }
709
+
710
+ }