tioga 1.6 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Tioga_README +35 -10
  2. data/split/Dvector/dvector.c +264 -22
  3. data/split/Dvector/lib/Dvector_extras.rb +30 -2
  4. data/split/Flate/extconf.rb +1 -1
  5. data/split/Function/function.c +112 -2
  6. data/split/Tioga/figures.c +76 -77
  7. data/split/Tioga/figures.h +375 -490
  8. data/split/Tioga/generic.c +254 -0
  9. data/split/Tioga/generic.h +236 -0
  10. data/split/Tioga/init.c +434 -320
  11. data/split/Tioga/lib/Creating_Paths.rb +11 -1
  12. data/split/Tioga/lib/FigMkr.rb +263 -65
  13. data/split/Tioga/lib/Legends.rb +4 -2
  14. data/split/Tioga/lib/Markers.rb +3 -2
  15. data/split/Tioga/lib/Special_Paths.rb +22 -23
  16. data/split/Tioga/lib/TeX_Text.rb +79 -1
  17. data/split/Tioga/lib/TexPreamble.rb +14 -0
  18. data/split/Tioga/lib/Utils.rb +5 -1
  19. data/split/Tioga/pdfs.h +7 -45
  20. data/split/Tioga/{axes.c → shared/axes.c} +210 -197
  21. data/split/Tioga/{makers.c → shared/makers.c} +442 -211
  22. data/split/Tioga/{pdf_font_dicts.c → shared/pdf_font_dicts.c} +0 -0
  23. data/split/Tioga/shared/pdfcolor.c +628 -0
  24. data/split/Tioga/shared/pdfcoords.c +443 -0
  25. data/split/Tioga/{pdffile.c → shared/pdffile.c} +56 -52
  26. data/split/Tioga/{pdfimage.c → shared/pdfimage.c} +103 -211
  27. data/split/Tioga/shared/pdfpath.c +766 -0
  28. data/split/Tioga/{pdftext.c → shared/pdftext.c} +121 -99
  29. data/split/Tioga/shared/texout.c +524 -0
  30. data/split/Tioga/wrappers.c +489 -0
  31. data/split/Tioga/wrappers.h +259 -0
  32. data/split/extconf.rb +4 -0
  33. data/split/mkmf2.rb +12 -1
  34. data/tests/benchmark_dvector_reads.rb +112 -0
  35. data/tests/tc_Dvector.rb +35 -3
  36. data/tests/tc_Function.rb +32 -0
  37. metadata +65 -52
  38. data/split/Tioga/pdfcolor.c +0 -486
  39. data/split/Tioga/pdfcoords.c +0 -523
  40. data/split/Tioga/pdfpath.c +0 -913
  41. data/split/Tioga/texout.c +0 -380
@@ -0,0 +1,443 @@
1
+ /* pdfcoords.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
+ /* Frame and Bounds */
26
+ void Recalc_Font_Hts(FM *p)
27
+ {
28
+ double dx, dy;
29
+ dx = dy = ENLARGE * p->default_font_size * p->default_text_scale; // font height in output coords
30
+ dx = convert_output_to_page_dx(p,dx);
31
+ dx = convert_page_to_frame_dx(p,dx);
32
+ p->default_text_height_dx = convert_frame_to_figure_dx(p,dx);
33
+ dy = convert_output_to_page_dy(p,dy);
34
+ dy = convert_page_to_frame_dy(p,dy);
35
+ p->default_text_height_dy = convert_frame_to_figure_dy(p,dy);
36
+ }
37
+
38
+ void c_set_subframe(OBJ_PTR fmkr, FM *p,
39
+ double left_margin, double right_margin, double top_margin, double bottom_margin, int *ierr)
40
+ {
41
+ double x, y, w, h;
42
+ if (left_margin < 0 || right_margin < 0 || top_margin < 0 || bottom_margin < 0) {
43
+ RAISE_ERROR("Sorry: margins for set_subframe must be non-negative", ierr); return; }
44
+ if (left_margin + right_margin >= 1.0) {
45
+ RAISE_ERROR_gg("Sorry: margins too large: left_margin (%g) right_margin (%g)", left_margin, right_margin, ierr); return; }
46
+ if (top_margin + bottom_margin >= 1.0) {
47
+ RAISE_ERROR_gg("Sorry: margins too large: top_margin (%g) bottom_margin (%g)", top_margin, bottom_margin, ierr); return; }
48
+ x = p->frame_left += left_margin * p->frame_width;
49
+ p->frame_right -= right_margin * p->frame_width;
50
+ p->frame_top -= top_margin * p->frame_height;
51
+ y = p->frame_bottom += bottom_margin * p->frame_height;
52
+ w = p->frame_width = p->frame_right - p->frame_left;
53
+ h = p->frame_height = p->frame_top - p->frame_bottom;
54
+ Recalc_Font_Hts(p);
55
+ }
56
+
57
+
58
+
59
+ static void c_set_bounds(FM *p, double left, double right, double top, double bottom, int *ierr)
60
+ {
61
+ if (constructing_path) {
62
+ RAISE_ERROR("Sorry: must finish with current path before calling set_bounds", ierr); return; }
63
+ p->bounds_left = left; p->bounds_right = right;
64
+ p->bounds_bottom = bottom; p->bounds_top = top;
65
+ if (left < right) {
66
+ p->xaxis_reversed = false;
67
+ p->bounds_xmin = left; p->bounds_xmax = right;
68
+ } else if (right < left) {
69
+ p->xaxis_reversed = true;
70
+ p->bounds_xmin = right; p->bounds_xmax = left;
71
+ } else { // left == right
72
+ p->xaxis_reversed = false;
73
+ if (left > 0.0) {
74
+ p->bounds_xmin = left * (1.0 - 1e-6); p->bounds_xmax = left * (1.0 + 1e-6);
75
+ } else if (left < 0.0) {
76
+ p->bounds_xmin = left * (1.0 + 1e-6); p->bounds_xmax = left * (1.0 - 1e-6);
77
+ } else {
78
+ p->bounds_xmin = -1e-6; p->bounds_xmax = 1e-6;
79
+ }
80
+ }
81
+ if (bottom < top) {
82
+ p->yaxis_reversed = false;
83
+ p->bounds_ymin = bottom; p->bounds_ymax = top;
84
+ } else if (top < bottom) {
85
+ p->yaxis_reversed = true;
86
+ p->bounds_ymin = top; p->bounds_ymax = bottom;
87
+ } else { // top == bottom
88
+ p->yaxis_reversed = false;
89
+ if (bottom > 0.0) {
90
+ p->bounds_ymin = bottom * (1.0 - 1e-6); p->bounds_ymax = bottom * (1.0 + 1e-6);
91
+ } else if (bottom < 0.0) {
92
+ p->bounds_ymin = bottom * (1.0 + 1e-6); p->bounds_ymax = bottom * (1.0 - 1e-6);
93
+ } else {
94
+ p->bounds_xmin = -1e-6; p->bounds_xmax = 1e-6;
95
+ }
96
+ }
97
+ p->bounds_width = p->bounds_xmax - p->bounds_xmin;
98
+ p->bounds_height = p->bounds_ymax - p->bounds_ymin;
99
+ Recalc_Font_Hts(p);
100
+ }
101
+
102
+ void c_private_set_bounds(OBJ_PTR fmkr, FM *p,
103
+ double left, double right, double top, double bottom, int *ierr)
104
+ {
105
+ if (constructing_path) {
106
+ RAISE_ERROR("Sorry: must finish with current path before calling set_bounds", ierr); return; }
107
+ p->bounds_left = left; p->bounds_right = right;
108
+ p->bounds_bottom = bottom; p->bounds_top = top;
109
+ if (left < right) {
110
+ p->xaxis_reversed = false;
111
+ p->bounds_xmin = left; p->bounds_xmax = right;
112
+ } else if (right < left) {
113
+ p->xaxis_reversed = true;
114
+ p->bounds_xmin = right; p->bounds_xmax = left;
115
+ } else { // left == right
116
+ p->xaxis_reversed = false;
117
+ if (left > 0.0) {
118
+ p->bounds_xmin = left * (1.0 - 1e-6); p->bounds_xmax = left * (1.0 + 1e-6);
119
+ } else if (left < 0.0) {
120
+ p->bounds_xmin = left * (1.0 + 1e-6); p->bounds_xmax = left * (1.0 - 1e-6);
121
+ } else {
122
+ p->bounds_xmin = -1e-6; p->bounds_xmax = 1e-6;
123
+ }
124
+ }
125
+ if (bottom < top) {
126
+ p->yaxis_reversed = false;
127
+ p->bounds_ymin = bottom; p->bounds_ymax = top;
128
+ } else if (top < bottom) {
129
+ p->yaxis_reversed = true;
130
+ p->bounds_ymin = top; p->bounds_ymax = bottom;
131
+ } else { // top == bottom
132
+ p->yaxis_reversed = false;
133
+ if (bottom > 0.0) {
134
+ p->bounds_ymin = bottom * (1.0 - 1e-6); p->bounds_ymax = bottom * (1.0 + 1e-6);
135
+ } else if (bottom < 0.0) {
136
+ p->bounds_ymin = bottom * (1.0 + 1e-6); p->bounds_ymax = bottom * (1.0 - 1e-6);
137
+ } else {
138
+ p->bounds_xmin = -1e-6; p->bounds_xmax = 1e-6;
139
+ }
140
+ }
141
+ p->bounds_width = p->bounds_xmax - p->bounds_xmin;
142
+ p->bounds_height = p->bounds_ymax - p->bounds_ymin;
143
+ Recalc_Font_Hts(p);
144
+ }
145
+
146
+
147
+ // Conversions
148
+
149
+
150
+ OBJ_PTR c_convert_to_degrees(OBJ_PTR fmkr, FM *p, double dx, double dy, int *ierr) { // dx and dy in figure coords
151
+ double angle;
152
+ if (dx == 0.0 && dy == 0.0) angle = 0.0;
153
+ else if (dx > 0.0 && dy == 0.0) angle = (p->bounds_left > p->bounds_right)? 180.0 : 0.0;
154
+ else if (dx < 0.0 && dy == 0.0) angle = (p->bounds_left > p->bounds_right)? 0.0 : 180.0;
155
+ else if (dx == 0.0 && dy > 0.0) angle = (p->bounds_bottom > p->bounds_top)? -90.0 : 90.0;
156
+ else if (dx == 0.0 && dy < 0.0) angle = (p->bounds_bottom > p->bounds_top)? 90.0 : -90.0;
157
+ else angle = atan2(convert_figure_to_output_dy(p,dy),convert_figure_to_output_dx(p,dx))*RADIANS_TO_DEGREES;
158
+ return Float_New(angle);
159
+ }
160
+
161
+ OBJ_PTR c_convert_inches_to_output(OBJ_PTR fmkr, FM *p, double val, int *ierr)
162
+ {
163
+ val = convert_inches_to_output(val);
164
+ return Float_New(val);
165
+ }
166
+
167
+ OBJ_PTR c_convert_output_to_inches(OBJ_PTR fmkr, FM *p, double val, int *ierr)
168
+ {
169
+ val = convert_output_to_inches(val);
170
+ return Float_New(val);
171
+ }
172
+
173
+ OBJ_PTR c_convert_mm_to_output(OBJ_PTR fmkr, FM *p, double val, int *ierr)
174
+ {
175
+ val = convert_mm_to_output(val);
176
+ return Float_New(val);
177
+ }
178
+
179
+ OBJ_PTR c_convert_output_to_mm(OBJ_PTR fmkr, FM *p, double val, int *ierr)
180
+ {
181
+ val = convert_output_to_mm(val);
182
+ return Float_New(val);
183
+ }
184
+
185
+ OBJ_PTR c_convert_page_to_output_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
186
+ {
187
+ val = convert_page_to_output_x(p,val);
188
+ return Float_New(val);
189
+ }
190
+
191
+ OBJ_PTR c_convert_page_to_output_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
192
+ {
193
+ val = convert_page_to_output_y(p,val);
194
+ return Float_New(val);
195
+ }
196
+
197
+ OBJ_PTR c_convert_page_to_output_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
198
+ {
199
+ val = convert_page_to_output_dx(p,val);
200
+ return Float_New(val);
201
+ }
202
+
203
+ OBJ_PTR c_convert_page_to_output_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
204
+ {
205
+ val = convert_page_to_output_dy(p,val);
206
+ return Float_New(val);
207
+ }
208
+
209
+ OBJ_PTR c_convert_output_to_page_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
210
+ {
211
+ val = convert_output_to_page_x(p,val);
212
+ return Float_New(val);
213
+ }
214
+
215
+ OBJ_PTR c_convert_output_to_page_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
216
+ {
217
+ val = convert_output_to_page_y(p,val);
218
+ return Float_New(val);
219
+ }
220
+
221
+ OBJ_PTR c_convert_output_to_page_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
222
+ {
223
+ val = convert_output_to_page_dx(p,val);
224
+ return Float_New(val);
225
+ }
226
+
227
+ OBJ_PTR c_convert_output_to_page_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
228
+ {
229
+ val = convert_output_to_page_dy(p,val);
230
+ return Float_New(val);
231
+ }
232
+
233
+ OBJ_PTR c_convert_frame_to_page_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
234
+ {
235
+ val = convert_frame_to_page_x(p,val);
236
+ return Float_New(val);
237
+ }
238
+
239
+ OBJ_PTR c_convert_frame_to_page_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
240
+ {
241
+ val = convert_frame_to_page_y(p,val);
242
+ return Float_New(val);
243
+ }
244
+
245
+ OBJ_PTR c_convert_frame_to_page_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
246
+ {
247
+ val = convert_frame_to_page_dx(p,val);
248
+ return Float_New(val);
249
+ }
250
+
251
+ OBJ_PTR c_convert_frame_to_page_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
252
+ {
253
+ val = convert_frame_to_page_dy(p,val);
254
+ return Float_New(val);
255
+ }
256
+
257
+ OBJ_PTR c_convert_page_to_frame_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
258
+ {
259
+ val = convert_page_to_frame_x(p,val);
260
+ return Float_New(val);
261
+ }
262
+
263
+ OBJ_PTR c_convert_page_to_frame_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
264
+ {
265
+ val = convert_page_to_frame_y(p,val);
266
+ return Float_New(val);
267
+ }
268
+
269
+ OBJ_PTR c_convert_page_to_frame_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
270
+ {
271
+ val = convert_page_to_frame_dx(p,val);
272
+ return Float_New(val);
273
+ }
274
+
275
+ OBJ_PTR c_convert_page_to_frame_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
276
+ {
277
+ val = convert_page_to_frame_dy(p,val);
278
+ return Float_New(val);
279
+ }
280
+
281
+ OBJ_PTR c_convert_figure_to_frame_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
282
+ {
283
+ val = convert_figure_to_frame_x(p,val);
284
+ return Float_New(val);
285
+ }
286
+
287
+ OBJ_PTR c_convert_figure_to_frame_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
288
+ {
289
+ val = convert_figure_to_frame_y(p,val);
290
+ return Float_New(val);
291
+ }
292
+
293
+ OBJ_PTR c_convert_figure_to_frame_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
294
+ {
295
+ val = convert_figure_to_frame_dx(p,val);
296
+ return Float_New(val);
297
+ }
298
+
299
+ OBJ_PTR c_convert_figure_to_frame_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
300
+ {
301
+ val = convert_figure_to_frame_dy(p,val);
302
+ return Float_New(val);
303
+ }
304
+
305
+ OBJ_PTR c_convert_frame_to_figure_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
306
+ {
307
+ val = convert_frame_to_figure_x(p,val);
308
+ return Float_New(val);
309
+ }
310
+
311
+ OBJ_PTR c_convert_frame_to_figure_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
312
+ {
313
+ val = convert_frame_to_figure_y(p,val);
314
+ return Float_New(val);
315
+ }
316
+
317
+ OBJ_PTR c_convert_frame_to_figure_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
318
+ {
319
+ val = convert_frame_to_figure_dx(p,val);
320
+ return Float_New(val);
321
+ }
322
+
323
+ OBJ_PTR c_convert_frame_to_figure_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
324
+ {
325
+ val = convert_frame_to_figure_dy(p,val);
326
+ return Float_New(val);
327
+ }
328
+
329
+ double convert_figure_to_output_x(FM *p, double x)
330
+ {
331
+ x = convert_figure_to_frame_x(p,x);
332
+ x = convert_frame_to_page_x(p,x);
333
+ x = convert_page_to_output_x(p,x);
334
+ return x;
335
+ }
336
+
337
+ double convert_figure_to_output_dy(FM *p, double dy)
338
+ {
339
+ dy = convert_figure_to_frame_dy(p,dy);
340
+ dy = convert_frame_to_page_dy(p,dy);
341
+ dy = convert_page_to_output_dy(p,dy);
342
+ return dy;
343
+ }
344
+
345
+ double convert_figure_to_output_dx(FM *p, double dx)
346
+ {
347
+ dx = convert_figure_to_frame_dx(p,dx);
348
+ dx = convert_frame_to_page_dx(p,dx);
349
+ dx = convert_page_to_output_dx(p,dx);
350
+ return dx;
351
+ }
352
+
353
+ double convert_figure_to_output_y(FM *p, double y)
354
+ {
355
+ y = convert_figure_to_frame_y(p,y);
356
+ y = convert_frame_to_page_y(p,y);
357
+ y = convert_page_to_output_y(p,y);
358
+ return y;
359
+ }
360
+
361
+ OBJ_PTR c_convert_figure_to_output_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
362
+ {
363
+ return Float_New(convert_figure_to_output_x(p,val));
364
+ }
365
+
366
+ OBJ_PTR c_convert_figure_to_output_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
367
+ {
368
+ return Float_New(convert_figure_to_output_y(p,val));
369
+ }
370
+
371
+ OBJ_PTR c_convert_figure_to_output_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
372
+ {
373
+ return Float_New(convert_figure_to_output_dx(p,val));
374
+ }
375
+
376
+ OBJ_PTR c_convert_figure_to_output_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
377
+ {
378
+ return Float_New(convert_figure_to_output_dy(p,val));
379
+ }
380
+
381
+ double convert_output_to_figure_x(FM *p, double x)
382
+ {
383
+ x = convert_output_to_page_x(p,x);
384
+ x = convert_page_to_frame_x(p,x);
385
+ x = convert_frame_to_figure_x(p,x);
386
+ return x;
387
+ }
388
+
389
+ double convert_output_to_figure_dy(FM *p, double dy)
390
+ {
391
+ dy = convert_output_to_page_dy(p,dy);
392
+ dy = convert_page_to_frame_dy(p,dy);
393
+ dy = convert_frame_to_figure_dy(p,dy);
394
+ return dy;
395
+ }
396
+
397
+ double convert_output_to_figure_dx(FM *p, double dx)
398
+ {
399
+ dx = convert_output_to_page_dx(p,dx);
400
+ dx = convert_page_to_frame_dx(p,dx);
401
+ dx = convert_frame_to_figure_dx(p,dx);
402
+ return dx;
403
+ }
404
+
405
+ double convert_output_to_figure_y(FM *p, double y)
406
+ {
407
+ y = convert_output_to_page_y(p,y);
408
+ y = convert_page_to_frame_y(p,y);
409
+ y = convert_frame_to_figure_y(p,y);
410
+ return y;
411
+ }
412
+
413
+ OBJ_PTR c_convert_output_to_figure_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
414
+ {
415
+ return Float_New(convert_output_to_figure_x(p,val));
416
+ }
417
+
418
+ OBJ_PTR c_convert_output_to_figure_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
419
+ {
420
+ return Float_New(convert_output_to_figure_y(p,val));
421
+ }
422
+
423
+ OBJ_PTR c_convert_output_to_figure_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
424
+ { return Float_New(convert_output_to_figure_dx(p,val)); }
425
+
426
+ OBJ_PTR c_convert_output_to_figure_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
427
+ { return Float_New(convert_output_to_figure_dy(p,val)); }
428
+
429
+ void c_private_set_default_font_size(OBJ_PTR fmkr, FM *p, double size, int *ierr) {
430
+ p->default_font_size = size;
431
+ Recalc_Font_Hts(p);
432
+ }
433
+
434
+ void c_doing_subplot(OBJ_PTR fmkr, FM *p, int *ierr)
435
+ {
436
+ p->in_subplot = true;
437
+ }
438
+
439
+ void c_doing_subfigure(OBJ_PTR fmkr, FM *p, int *ierr)
440
+ {
441
+ p->root_figure = false;
442
+ }
443
+
@@ -48,9 +48,9 @@ char *predefined_Fonts[] = { /* must match the font numbers in FigureConstants.r
48
48
  int num_predefined_fonts = 14;
49
49
  int num_pdf_standard_fonts = 14;
50
50
 
51
- long int *obj_offsets, capacity_obj_offsets, stream_start, stream_end, length_offset, xref_offset;
52
- int num_objects, next_available_object_number, next_available_gs_number, next_available_xo_number;
53
- int next_available_shade_number, next_available_font_number;
51
+ long *obj_offsets, capacity_obj_offsets, stream_start, stream_end, length_offset, xref_offset;
52
+ long num_objects, next_available_object_number, next_available_gs_number, next_available_xo_number;
53
+ long next_available_shade_number, next_available_font_number;
54
54
  Stroke_Opacity_State *stroke_opacities = NULL;
55
55
  Fill_Opacity_State *fill_opacities = NULL;
56
56
  XObject_Info *xobj_list = NULL;
@@ -63,7 +63,7 @@ FILE *TF = NULL; // for the temp file
63
63
 
64
64
  /* PDF File Management */
65
65
 
66
- void Free_XObjects(void)
66
+ static void Free_XObjects(int *ierr)
67
67
  {
68
68
  XObject_Info *xo;
69
69
  while (xobj_list != NULL) {
@@ -72,19 +72,19 @@ void Free_XObjects(void)
72
72
  switch (xo->xobj_subtype) {
73
73
  case JPG_SUBTYPE: Free_JPG((JPG_Info *)xo); break;
74
74
  case SAMPLED_SUBTYPE: Free_Sampled((Sampled_Info *)xo); break;
75
- default: rb_raise(rb_eArgError, "Invalid XObject subtype (%i)", xo->xobj_subtype);
75
+ default: RAISE_ERROR_i("Invalid XObject subtype (%i)", xo->xobj_subtype, ierr); return;
76
76
  }
77
77
  free(xo);
78
78
  }
79
79
  }
80
80
 
81
- void Init_pdf(void)
81
+ void Init_pdf(int *ierr)
82
82
  {
83
83
  int i;
84
84
  writing_file = false;
85
85
  capacity_obj_offsets = 1000;
86
86
  num_objects = 0;
87
- obj_offsets = ALLOC_N(long int, capacity_obj_offsets);
87
+ obj_offsets = ALLOC_N_long(capacity_obj_offsets);
88
88
  for (i=0; i < capacity_obj_offsets; i++) obj_offsets[i] = 0;
89
89
  }
90
90
 
@@ -93,7 +93,7 @@ void Record_Object_Offset(int obj_number)
93
93
  long int offset = ftell(OF);
94
94
  if (obj_number >= capacity_obj_offsets) {
95
95
  int size_increment = 50, i;
96
- REALLOC_N(obj_offsets, long int, obj_number + size_increment);
96
+ REALLOC_long(&obj_offsets, obj_number + size_increment);
97
97
  capacity_obj_offsets = obj_number + size_increment;
98
98
  for (i=num_objects; i < capacity_obj_offsets; i++) obj_offsets[i] = 0;
99
99
  }
@@ -101,17 +101,18 @@ void Record_Object_Offset(int obj_number)
101
101
  if (obj_number >= num_objects) num_objects = obj_number + 1;
102
102
  }
103
103
 
104
- static void Write_XObjects(void)
104
+ static void Write_XObjects(int *ierr)
105
105
  {
106
106
  XObject_Info *xo;
107
107
  for (xo = xobj_list; xo != NULL; xo = xo->next) {
108
108
  Record_Object_Offset(xo->obj_num);
109
109
  fprintf(OF, "%i 0 obj << /Type /XObject ", xo->obj_num);
110
110
  switch (xo->xobj_subtype) {
111
- case JPG_SUBTYPE: Write_JPG((JPG_Info *)xo); break;
112
- case SAMPLED_SUBTYPE: Write_Sampled((Sampled_Info *)xo); break;
113
- default: rb_raise(rb_eArgError, "Invalid XObject subtype (%i)", xo->xobj_subtype);
111
+ case JPG_SUBTYPE: Write_JPG((JPG_Info *)xo, ierr); break;
112
+ case SAMPLED_SUBTYPE: Write_Sampled((Sampled_Info *)xo, ierr); break;
113
+ default: RAISE_ERROR_i("Invalid XObject subtype (%i)", xo->xobj_subtype, ierr);
114
114
  }
115
+ if (*ierr != 0) return;
115
116
  fprintf(OF, ">> endobj\n");
116
117
  }
117
118
  }
@@ -123,9 +124,9 @@ static void Write_XObjects(void)
123
124
  #define CATALOG_OBJ 5
124
125
  #define FIRST_OTHER_OBJ 6
125
126
 
126
- static void Free_Records()
127
+ static void Free_Records(int *ierr)
127
128
  {
128
- Free_Stroke_Opacities(); Free_Fill_Opacities(); Free_XObjects(); Free_Shadings(); Free_Functions();
129
+ Free_Stroke_Opacities(); Free_Fill_Opacities(); Free_XObjects(ierr); Free_Shadings(); Free_Functions();
129
130
  }
130
131
 
131
132
  static void Get_pdf_name(char *ofile, char *filename, int maxlen)
@@ -137,13 +138,13 @@ static void Get_pdf_name(char *ofile, char *filename, int maxlen)
137
138
  strcat(ofile, "_figure.pdf");
138
139
  }
139
140
 
140
- void Open_pdf(VALUE fmkr, char *filename, bool quiet_mode)
141
- {
142
- FM *p = Get_FM(fmkr);
141
+ void Open_pdf(OBJ_PTR fmkr, FM *p, char *filename, bool quiet_mode, int *ierr) {
143
142
  int i;
144
- if (writing_file) rb_raise(rb_eArgError, "Sorry: cannot start a new output file until finish current one.");
143
+ if (writing_file) {
144
+ RAISE_ERROR("Sorry: cannot start a new output file until finish current one.", ierr); return; }
145
145
  Clear_Fonts_In_Use_Flags();
146
- Free_Records();
146
+ Free_Records(ierr);
147
+ if (*ierr != 0) return;
147
148
  next_available_object_number = FIRST_OTHER_OBJ;
148
149
  next_available_font_number = num_predefined_fonts + 1;
149
150
  next_available_gs_number = 1;
@@ -153,10 +154,10 @@ void Open_pdf(VALUE fmkr, char *filename, bool quiet_mode)
153
154
  time_t now = time(NULL);
154
155
  char ofile[300], timestring[100];
155
156
  Get_pdf_name(ofile, filename, 300);
156
- if ((OF = fopen(ofile, "w")) == NULL)
157
- rb_raise(rb_eArgError, "Sorry: can't open %s.\n", filename);
158
- if ((TF = tmpfile()) == NULL)
159
- rb_raise(rb_eArgError, "Sorry: can't create temp file for writing PDF file %s.\n", filename);
157
+ if ((OF = fopen(ofile, "w")) == NULL) {
158
+ RAISE_ERROR_s("Sorry: can't open %s.\n", filename, ierr); return; }
159
+ if ((TF = tmpfile()) == NULL) {
160
+ RAISE_ERROR_s("Sorry: can't create temp file for writing PDF file %s.\n", filename, ierr); return; }
160
161
  /* open PDF file and write header */
161
162
  fprintf(OF, "%%PDF-1.4\n");
162
163
  strcpy(timestring, ctime(&now));
@@ -178,25 +179,22 @@ void Open_pdf(VALUE fmkr, char *filename, bool quiet_mode)
178
179
  Get_pdf_xoffset(), Get_pdf_yoffset());
179
180
  /* set stroke and fill colors to black */
180
181
  have_current_point = constructing_path = false;
181
- c_line_width_set(p, p->line_width);
182
- c_line_cap_set(p, p->line_cap);
183
- c_line_join_set(p, p->line_join);
184
- c_miter_limit_set(p, p->miter_limit);
185
- FM_line_type_set(fmkr, p->line_type);
186
- FM_stroke_color_set(fmkr, p->stroke_color);
187
- FM_fill_color_set(fmkr, p->fill_color);
182
+ c_line_width_set(fmkr, p, p->line_width, ierr);
183
+ c_line_cap_set(fmkr, p, p->line_cap, ierr);
184
+ c_line_join_set(fmkr, p, p->line_join, ierr);
185
+ c_miter_limit_set(fmkr, p, p->miter_limit, ierr);
186
+ c_line_type_set(fmkr, p, Get_line_type(fmkr, ierr), ierr);
187
+ c_stroke_color_set_RGB(fmkr, p, p->stroke_color_R, p->stroke_color_G, p->stroke_color_B, ierr);
188
+ c_fill_color_set_RGB(fmkr, p, p->fill_color_R, p->fill_color_G, p->fill_color_B, ierr);
188
189
  // initialize clip region
189
190
  bbox_llx = bbox_lly = 1e5;
190
191
  bbox_urx = bbox_ury = -1e5;
191
192
  }
192
193
 
193
- void Start_Axis_Standard_State(FM *p, VALUE color, double line_width) {
194
+ void Start_Axis_Standard_State(OBJ_PTR fmkr, FM *p, double r, double g, double b, double line_width, int *ierr) {
194
195
  fprintf(TF, "q 2 J [] 0 d\n");
195
- c_line_width_set(p, line_width);
196
- if (color != Qnil)
197
- FM_stroke_color_set(p->fm, color);
198
- else
199
- fprintf(TF, "0 0 0 RG\n"); // black
196
+ c_line_width_set(fmkr, p, line_width, ierr);
197
+ c_stroke_color_set_RGB(fmkr, p, r, g, b, ierr);
200
198
  /* 2 J sets the line cap style to square cap */
201
199
  /* set stroke and fill colors to black. set line type to solid */
202
200
  }
@@ -213,29 +211,33 @@ void Write_grestore(void)
213
211
  fprintf(TF, "Q\n");
214
212
  }
215
213
 
216
- void Print_Xref(long int offset) {
214
+ void c_pdf_gsave(OBJ_PTR fmkr, FM *p, int *ierr) { Write_gsave(); }
215
+ void c_pdf_grestore(OBJ_PTR fmkr, FM *p, int *ierr) { Write_grestore(); }
216
+
217
+ static void Print_Xref(long int offset) {
217
218
  char line[80];
218
219
  int i, len;
219
- sprintf(line, "%li", offset);
220
+ snprintf(line,sizeof(line), "%li", offset);
220
221
  len = strlen(line);
221
222
  for (i=0; i < 10-len; i++) fputc('0', OF);
222
223
  fprintf(OF, "%s 00000 n \n", line);
223
224
  }
224
225
 
225
- static void Write_Stream(void)
226
+ static void Write_Stream(int *ierr)
226
227
  {
227
228
  long int len = ftell(TF);
228
229
  unsigned long int new_len = (len * 11) / 10 + 100;
229
230
  unsigned char *buffer, *dest_buffer;
230
231
  rewind(TF);
231
- buffer = ALLOC_N(unsigned char, len+1);
232
- dest_buffer = ALLOC_N(unsigned char, new_len+1);
232
+ buffer = ALLOC_N_unsigned_char(len+1);
233
+ dest_buffer = ALLOC_N_unsigned_char(new_len+1);
233
234
  fread(buffer, 1, len, TF);
234
235
  fclose(TF);
235
236
  if (FLATE_ENCODE) {
236
- if (flate_compress(dest_buffer, &new_len, buffer, len) != FLATE_OK) {
237
+ if (do_flate_compress(dest_buffer, &new_len, buffer, len) != FLATE_OK) {
237
238
  free(buffer); free(dest_buffer);
238
- rb_raise(rb_eArgError, "Error compressing PDF stream data");
239
+ RAISE_ERROR("Error compressing PDF stream data", ierr);
240
+ return;
239
241
  }
240
242
  fwrite(dest_buffer, 1, new_len, OF);
241
243
  } else {
@@ -244,15 +246,15 @@ static void Write_Stream(void)
244
246
  free(buffer); free(dest_buffer);
245
247
  }
246
248
 
247
- void Close_pdf(VALUE fmkr, bool quiet_mode)
249
+ void Close_pdf(OBJ_PTR fmkr, FM *p, bool quiet_mode, int *ierr)
248
250
  {
249
- FM *p = Get_FM(fmkr);
250
251
  int i;
251
252
  double llx, lly, urx, ury, xoff, yoff;
252
- if (!writing_file) rb_raise(rb_eArgError, "Sorry: cannot End_Output if not writing file.");
253
+ if (!writing_file) { RAISE_ERROR("Sorry: cannot End_Output if not writing file.", ierr); return; }
253
254
  writing_file = false;
254
- if (constructing_path) rb_raise(rb_eArgError, "Sorry: must finish with current path before ending file");
255
- Write_Stream();
255
+ if (constructing_path) { RAISE_ERROR("Sorry: must finish with current path before ending file", ierr); return; }
256
+ Write_Stream(ierr);
257
+ if (*ierr != 0) return;
256
258
  stream_end = ftell(OF);
257
259
  fprintf(OF, "endstream\nendobj\n");
258
260
  Record_Object_Offset(PAGE_OBJ);
@@ -269,7 +271,7 @@ void Close_pdf(VALUE fmkr, bool quiet_mode)
269
271
  lly = bbox_lly / ENLARGE + yoff - MARGIN;
270
272
  urx = bbox_urx / ENLARGE + xoff + MARGIN;
271
273
  ury = bbox_ury / ENLARGE + yoff + MARGIN;
272
- if (urx < llx || ury < lly) rb_raise(rb_eArgError, "Sorry: Empty plot!");
274
+ if (urx < llx || ury < lly) { RAISE_ERROR("Sorry: Empty plot!", ierr); return; }
273
275
  fprintf(OF, "%d %d %d %d", ROUND(llx), ROUND(lly), ROUND(urx), ROUND(ury));
274
276
  fprintf(OF, " ]\n/Contents %i 0 R\n/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n", STREAM_OBJ);
275
277
  if (Used_Any_Fonts()) {
@@ -318,8 +320,10 @@ void Close_pdf(VALUE fmkr, bool quiet_mode)
318
320
  Write_Font_Widths();
319
321
  Write_Stroke_Opacity_Objects();
320
322
  Write_Fill_Opacity_Objects();
321
- Write_XObjects();
322
- Write_Functions();
323
+ Write_XObjects(ierr);
324
+ if (*ierr != 0) return;
325
+ Write_Functions(ierr);
326
+ if (*ierr != 0) return;
323
327
  Write_Shadings();
324
328
  xref_offset = ftell(OF);
325
329
  fprintf(OF, "xref\n0 %i\n0000000000 65535 f \n", num_objects);
@@ -329,7 +333,7 @@ void Close_pdf(VALUE fmkr, bool quiet_mode)
329
333
  fseek(OF, length_offset, SEEK_SET);
330
334
  fprintf(OF, "%li", stream_end - stream_start);
331
335
  fclose(OF);
332
- Free_Records();
336
+ Free_Records(ierr);
333
337
  }
334
338
 
335
339
  void Rename_pdf(char *oldname, char *newname)