tioga 1.7 → 1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,534 @@
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
+
26
+ /* Frame and Bounds */
27
+ void
28
+ Recalc_Font_Hts(FM *p)
29
+ {
30
+ double dx, dy; // font height in output coords
31
+ dx = dy = ENLARGE * p->default_font_size * p->default_text_scale;
32
+ dx = convert_output_to_page_dx(p, dx);
33
+ dx = convert_page_to_frame_dx(p, dx);
34
+ p->default_text_height_dx = convert_frame_to_figure_dx(p, dx);
35
+ dy = convert_output_to_page_dy(p, dy);
36
+ dy = convert_page_to_frame_dy(p, dy);
37
+ p->default_text_height_dy = convert_frame_to_figure_dy(p, dy);
38
+ }
39
+
40
+
41
+ void
42
+ c_set_subframe(OBJ_PTR fmkr, FM *p,
43
+ double left_margin, double right_margin, double top_margin,
44
+ double bottom_margin, int *ierr)
45
+ {
46
+ double x, y, w, h;
47
+ if (left_margin < 0 || right_margin < 0 || top_margin < 0
48
+ || bottom_margin < 0) {
49
+ RAISE_ERROR("Sorry: margins for set_subframe must be non-negative",
50
+ ierr);
51
+ return;
52
+ }
53
+ if (left_margin + right_margin >= 1.0) {
54
+ RAISE_ERROR_gg("Sorry: margins too large: left_margin (%g) "
55
+ "right_margin (%g)", left_margin, right_margin, ierr);
56
+ return;
57
+ }
58
+ if (top_margin + bottom_margin >= 1.0) {
59
+ RAISE_ERROR_gg("Sorry: margins too large: top_margin (%g) "
60
+ "bottom_margin (%g)", top_margin, bottom_margin, ierr);
61
+ return;
62
+ }
63
+ x = p->frame_left += left_margin * p->frame_width;
64
+ p->frame_right -= right_margin * p->frame_width;
65
+ p->frame_top -= top_margin * p->frame_height;
66
+ y = p->frame_bottom += bottom_margin * p->frame_height;
67
+ w = p->frame_width = p->frame_right - p->frame_left;
68
+ h = p->frame_height = p->frame_top - p->frame_bottom;
69
+ Recalc_Font_Hts(p);
70
+ }
71
+
72
+
73
+ void
74
+ c_private_set_bounds(OBJ_PTR fmkr, FM *p, double left, double right,
75
+ double top, double bottom, int *ierr)
76
+ {
77
+ if (constructing_path) {
78
+ RAISE_ERROR("Sorry: must finish with current path before calling "
79
+ "set_bounds", ierr);
80
+ return;
81
+ }
82
+ p->bounds_left = left; p->bounds_right = right;
83
+ p->bounds_bottom = bottom; p->bounds_top = top;
84
+ if (left < right) {
85
+ p->xaxis_reversed = false;
86
+ p->bounds_xmin = left; p->bounds_xmax = right;
87
+ }
88
+ else if (right < left) {
89
+ p->xaxis_reversed = true;
90
+ p->bounds_xmin = right; p->bounds_xmax = left;
91
+ }
92
+ else { // left == right
93
+ p->xaxis_reversed = false;
94
+ if (left > 0.0) {
95
+ p->bounds_xmin = left * (1.0 - 1e-6);
96
+ p->bounds_xmax = left * (1.0 + 1e-6);
97
+ }
98
+ else if (left < 0.0) {
99
+ p->bounds_xmin = left * (1.0 + 1e-6);
100
+ p->bounds_xmax = left * (1.0 - 1e-6);
101
+ }
102
+ else {
103
+ p->bounds_xmin = -1e-6; p->bounds_xmax = 1e-6;
104
+ }
105
+ }
106
+ if (bottom < top) {
107
+ p->yaxis_reversed = false;
108
+ p->bounds_ymin = bottom; p->bounds_ymax = top;
109
+ }
110
+ else if (top < bottom) {
111
+ p->yaxis_reversed = true;
112
+ p->bounds_ymin = top; p->bounds_ymax = bottom;
113
+ }
114
+ else { // top == bottom
115
+ p->yaxis_reversed = false;
116
+ if (bottom > 0.0) {
117
+ p->bounds_ymin = bottom * (1.0 - 1e-6);
118
+ p->bounds_ymax = bottom * (1.0 + 1e-6);
119
+ }
120
+ else if (bottom < 0.0) {
121
+ p->bounds_ymin = bottom * (1.0 + 1e-6);
122
+ p->bounds_ymax = bottom * (1.0 - 1e-6);
123
+ }
124
+ else {
125
+ p->bounds_xmin = -1e-6; p->bounds_xmax = 1e-6;
126
+ }
127
+ }
128
+ p->bounds_width = p->bounds_xmax - p->bounds_xmin;
129
+ p->bounds_height = p->bounds_ymax - p->bounds_ymin;
130
+ Recalc_Font_Hts(p);
131
+ }
132
+
133
+
134
+ // Conversions
135
+
136
+ OBJ_PTR
137
+ c_convert_to_degrees(OBJ_PTR fmkr, FM *p, double dx, double dy, int *ierr)
138
+ { // dx and dy in figure coords
139
+ double angle;
140
+ if (dx == 0.0 && dy == 0.0) angle = 0.0;
141
+ else if (dx > 0.0 && dy == 0.0)
142
+ angle = (p->bounds_left > p->bounds_right)? 180.0 : 0.0;
143
+ else if (dx < 0.0 && dy == 0.0)
144
+ angle = (p->bounds_left > p->bounds_right)? 0.0 : 180.0;
145
+ else if (dx == 0.0 && dy > 0.0)
146
+ angle = (p->bounds_bottom > p->bounds_top)? -90.0 : 90.0;
147
+ else if (dx == 0.0 && dy < 0.0)
148
+ angle = (p->bounds_bottom > p->bounds_top)? 90.0 : -90.0;
149
+ else
150
+ angle = atan2(convert_figure_to_output_dy(p, dy),
151
+ convert_figure_to_output_dx(p, dx)) * RADIANS_TO_DEGREES;
152
+ return Float_New(angle);
153
+ }
154
+
155
+
156
+ OBJ_PTR
157
+ c_convert_inches_to_output(OBJ_PTR fmkr, FM *p, double val, int *ierr)
158
+ {
159
+ val = convert_inches_to_output(val);
160
+ return Float_New(val);
161
+ }
162
+
163
+
164
+ OBJ_PTR
165
+ c_convert_output_to_inches(OBJ_PTR fmkr, FM *p, double val, int *ierr)
166
+ {
167
+ val = convert_output_to_inches(val);
168
+ return Float_New(val);
169
+ }
170
+
171
+
172
+ OBJ_PTR
173
+ 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
+
180
+ OBJ_PTR
181
+ c_convert_output_to_mm(OBJ_PTR fmkr, FM *p, double val, int *ierr)
182
+ {
183
+ val = convert_output_to_mm(val);
184
+ return Float_New(val);
185
+ }
186
+
187
+
188
+ OBJ_PTR
189
+ c_convert_page_to_output_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
190
+ {
191
+ val = convert_page_to_output_x(p, val);
192
+ return Float_New(val);
193
+ }
194
+
195
+
196
+ OBJ_PTR
197
+ c_convert_page_to_output_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
198
+ {
199
+ val = convert_page_to_output_y(p, val);
200
+ return Float_New(val);
201
+ }
202
+
203
+
204
+ OBJ_PTR
205
+ c_convert_page_to_output_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
206
+ {
207
+ val = convert_page_to_output_dx(p, val);
208
+ return Float_New(val);
209
+ }
210
+
211
+
212
+ OBJ_PTR
213
+ c_convert_page_to_output_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
214
+ {
215
+ val = convert_page_to_output_dy(p, val);
216
+ return Float_New(val);
217
+ }
218
+
219
+
220
+ OBJ_PTR
221
+ c_convert_output_to_page_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
222
+ {
223
+ val = convert_output_to_page_x(p, val);
224
+ return Float_New(val);
225
+ }
226
+
227
+
228
+ OBJ_PTR
229
+ c_convert_output_to_page_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
230
+ {
231
+ val = convert_output_to_page_y(p, val);
232
+ return Float_New(val);
233
+ }
234
+
235
+
236
+ OBJ_PTR
237
+ c_convert_output_to_page_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
238
+ {
239
+ val = convert_output_to_page_dx(p, val);
240
+ return Float_New(val);
241
+ }
242
+
243
+
244
+ OBJ_PTR
245
+ c_convert_output_to_page_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
246
+ {
247
+ val = convert_output_to_page_dy(p, val);
248
+ return Float_New(val);
249
+ }
250
+
251
+
252
+ OBJ_PTR
253
+ c_convert_frame_to_page_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
254
+ {
255
+ val = convert_frame_to_page_x(p, val);
256
+ return Float_New(val);
257
+ }
258
+
259
+
260
+ OBJ_PTR
261
+ c_convert_frame_to_page_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
262
+ {
263
+ val = convert_frame_to_page_y(p, val);
264
+ return Float_New(val);
265
+ }
266
+
267
+
268
+ OBJ_PTR
269
+ c_convert_frame_to_page_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
270
+ {
271
+ val = convert_frame_to_page_dx(p, val);
272
+ return Float_New(val);
273
+ }
274
+
275
+
276
+ OBJ_PTR
277
+ c_convert_frame_to_page_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
278
+ {
279
+ val = convert_frame_to_page_dy(p, val);
280
+ return Float_New(val);
281
+ }
282
+
283
+
284
+ OBJ_PTR
285
+ c_convert_page_to_frame_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
286
+ {
287
+ val = convert_page_to_frame_x(p, val);
288
+ return Float_New(val);
289
+ }
290
+
291
+
292
+ OBJ_PTR
293
+ c_convert_page_to_frame_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
294
+ {
295
+ val = convert_page_to_frame_y(p, val);
296
+ return Float_New(val);
297
+ }
298
+
299
+
300
+ OBJ_PTR
301
+ c_convert_page_to_frame_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
302
+ {
303
+ val = convert_page_to_frame_dx(p, val);
304
+ return Float_New(val);
305
+ }
306
+
307
+
308
+ OBJ_PTR
309
+ c_convert_page_to_frame_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
310
+ {
311
+ val = convert_page_to_frame_dy(p, val);
312
+ return Float_New(val);
313
+ }
314
+
315
+ OBJ_PTR
316
+ c_convert_figure_to_frame_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
317
+ {
318
+ val = convert_figure_to_frame_x(p, val);
319
+ return Float_New(val);
320
+ }
321
+
322
+
323
+ OBJ_PTR
324
+ c_convert_figure_to_frame_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
325
+ {
326
+ val = convert_figure_to_frame_y(p, val);
327
+ return Float_New(val);
328
+ }
329
+
330
+
331
+ OBJ_PTR
332
+ c_convert_figure_to_frame_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
333
+ {
334
+ val = convert_figure_to_frame_dx(p, val);
335
+ return Float_New(val);
336
+ }
337
+
338
+
339
+ OBJ_PTR
340
+ c_convert_figure_to_frame_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
341
+ {
342
+ val = convert_figure_to_frame_dy(p, val);
343
+ return Float_New(val);
344
+ }
345
+
346
+
347
+ OBJ_PTR
348
+ c_convert_frame_to_figure_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
349
+ {
350
+ val = convert_frame_to_figure_x(p, val);
351
+ return Float_New(val);
352
+ }
353
+
354
+
355
+ OBJ_PTR
356
+ c_convert_frame_to_figure_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
357
+ {
358
+ val = convert_frame_to_figure_y(p, val);
359
+ return Float_New(val);
360
+ }
361
+
362
+
363
+ OBJ_PTR
364
+ c_convert_frame_to_figure_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
365
+ {
366
+ val = convert_frame_to_figure_dx(p, val);
367
+ return Float_New(val);
368
+ }
369
+
370
+
371
+ OBJ_PTR
372
+ c_convert_frame_to_figure_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
373
+ {
374
+ val = convert_frame_to_figure_dy(p, val);
375
+ return Float_New(val);
376
+ }
377
+
378
+
379
+ double
380
+ convert_figure_to_output_x(FM *p, double x)
381
+ {
382
+ x = convert_figure_to_frame_x(p, x);
383
+ x = convert_frame_to_page_x(p, x);
384
+ x = convert_page_to_output_x(p, x);
385
+ return x;
386
+ }
387
+
388
+
389
+ double
390
+ convert_figure_to_output_dy(FM *p, double dy)
391
+ {
392
+ dy = convert_figure_to_frame_dy(p, dy);
393
+ dy = convert_frame_to_page_dy(p, dy);
394
+ dy = convert_page_to_output_dy(p, dy);
395
+ return dy;
396
+ }
397
+
398
+
399
+ double
400
+ convert_figure_to_output_dx(FM *p, double dx)
401
+ {
402
+ dx = convert_figure_to_frame_dx(p, dx);
403
+ dx = convert_frame_to_page_dx(p, dx);
404
+ dx = convert_page_to_output_dx(p, dx);
405
+ return dx;
406
+ }
407
+
408
+
409
+ double
410
+ convert_figure_to_output_y(FM *p, double y)
411
+ {
412
+ y = convert_figure_to_frame_y(p, y);
413
+ y = convert_frame_to_page_y(p, y);
414
+ y = convert_page_to_output_y(p, y);
415
+ return y;
416
+ }
417
+
418
+
419
+ OBJ_PTR
420
+ c_convert_figure_to_output_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
421
+ {
422
+ return Float_New(convert_figure_to_output_x(p, val));
423
+ }
424
+
425
+
426
+ OBJ_PTR
427
+ c_convert_figure_to_output_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
428
+ {
429
+ return Float_New(convert_figure_to_output_y(p, val));
430
+ }
431
+
432
+
433
+ OBJ_PTR
434
+ c_convert_figure_to_output_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
435
+ {
436
+ return Float_New(convert_figure_to_output_dx(p, val));
437
+ }
438
+
439
+
440
+ OBJ_PTR
441
+ c_convert_figure_to_output_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
442
+ {
443
+ return Float_New(convert_figure_to_output_dy(p, val));
444
+ }
445
+
446
+
447
+ double
448
+ convert_output_to_figure_x(FM *p, double x)
449
+ {
450
+ x = convert_output_to_page_x(p, x);
451
+ x = convert_page_to_frame_x(p, x);
452
+ x = convert_frame_to_figure_x(p, x);
453
+ return x;
454
+ }
455
+
456
+
457
+ double
458
+ convert_output_to_figure_dy(FM *p, double dy)
459
+ {
460
+ dy = convert_output_to_page_dy(p, dy);
461
+ dy = convert_page_to_frame_dy(p, dy);
462
+ dy = convert_frame_to_figure_dy(p, dy);
463
+ return dy;
464
+ }
465
+
466
+
467
+ double
468
+ convert_output_to_figure_dx(FM *p, double dx)
469
+ {
470
+ dx = convert_output_to_page_dx(p, dx);
471
+ dx = convert_page_to_frame_dx(p, dx);
472
+ dx = convert_frame_to_figure_dx(p, dx);
473
+ return dx;
474
+ }
475
+
476
+
477
+ double
478
+ convert_output_to_figure_y(FM *p, double y)
479
+ {
480
+ y = convert_output_to_page_y(p, y);
481
+ y = convert_page_to_frame_y(p, y);
482
+ y = convert_frame_to_figure_y(p, y);
483
+ return y;
484
+ }
485
+
486
+
487
+ OBJ_PTR
488
+ c_convert_output_to_figure_x(OBJ_PTR fmkr, FM *p, double val, int *ierr)
489
+ {
490
+ return Float_New(convert_output_to_figure_x(p, val));
491
+ }
492
+
493
+
494
+ OBJ_PTR
495
+ c_convert_output_to_figure_y(OBJ_PTR fmkr, FM *p, double val, int *ierr)
496
+ {
497
+ return Float_New(convert_output_to_figure_y(p, val));
498
+ }
499
+
500
+
501
+ OBJ_PTR
502
+ c_convert_output_to_figure_dx(OBJ_PTR fmkr, FM *p, double val, int *ierr)
503
+ {
504
+ return Float_New(convert_output_to_figure_dx(p, val));
505
+ }
506
+
507
+
508
+ OBJ_PTR
509
+ c_convert_output_to_figure_dy(OBJ_PTR fmkr, FM *p, double val, int *ierr)
510
+ {
511
+ return Float_New(convert_output_to_figure_dy(p, val));
512
+ }
513
+
514
+
515
+ void
516
+ c_private_set_default_font_size(OBJ_PTR fmkr, FM *p, double size, int *ierr)
517
+ {
518
+ p->default_font_size = size;
519
+ Recalc_Font_Hts(p);
520
+ }
521
+
522
+
523
+ void
524
+ c_doing_subplot(OBJ_PTR fmkr, FM *p, int *ierr)
525
+ {
526
+ p->in_subplot = true;
527
+ }
528
+
529
+
530
+ void
531
+ c_doing_subfigure(OBJ_PTR fmkr, FM *p, int *ierr)
532
+ {
533
+ p->root_figure = false;
534
+ }