tioga 1.11 → 1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Tioga_README +58 -35
- data/{split/scripts → bin}/tioga +1 -1
- data/{split → ext/Dobjects}/Dtable/dtable.c +81 -15
- data/{split → ext/Dobjects}/Dtable/dtable_intern.h +0 -0
- data/ext/Dobjects/Dtable/extconf.rb +7 -0
- data/{split → ext/Dobjects}/Dtable/include/dtable.h +0 -0
- data/{split → ext/Dobjects}/Dvector/dvector.c +361 -51
- data/{split → ext/Dobjects}/Dvector/dvector_intern.h +0 -0
- data/ext/Dobjects/Dvector/extconf.rb +22 -0
- data/{split/Dtable → ext/Dobjects/Dvector/include}/dvector.h +0 -0
- data/ext/Dobjects/Function/extconf.rb +7 -0
- data/{split → ext/Dobjects}/Function/function.c +636 -11
- data/{split → ext/Dobjects}/Function/joint_qsort.c +0 -0
- data/ext/Flate/extconf.rb +26 -0
- data/{split → ext}/Flate/flate.c +7 -3
- data/{split → ext}/Flate/flate_intern.h +0 -0
- data/{split → ext}/Flate/include/flate.h +0 -0
- data/ext/Flate/zlib/adler32.c +149 -0
- data/ext/Flate/zlib/compress.c +79 -0
- data/ext/Flate/zlib/crc32.c +423 -0
- data/ext/Flate/zlib/crc32.h +441 -0
- data/ext/Flate/zlib/deflate.c +1736 -0
- data/ext/Flate/zlib/deflate.h +331 -0
- data/ext/Flate/zlib/gzio.c +1026 -0
- data/ext/Flate/zlib/infback.c +623 -0
- data/ext/Flate/zlib/inffast.c +318 -0
- data/ext/Flate/zlib/inffast.h +11 -0
- data/ext/Flate/zlib/inffixed.h +94 -0
- data/ext/Flate/zlib/inflate.c +1368 -0
- data/ext/Flate/zlib/inflate.h +115 -0
- data/ext/Flate/zlib/inftrees.c +329 -0
- data/ext/Flate/zlib/inftrees.h +55 -0
- data/ext/Flate/zlib/trees.c +1219 -0
- data/ext/Flate/zlib/trees.h +128 -0
- data/ext/Flate/zlib/uncompr.c +61 -0
- data/ext/Flate/zlib/zlib.h +1357 -0
- data/ext/Flate/zlib/zutil.c +318 -0
- data/ext/Flate/zlib/zutil.h +269 -0
- data/ext/Tioga/FigureMaker/__shared_axes.c +1373 -0
- data/ext/Tioga/FigureMaker/__shared_makers.c +1303 -0
- data/{split/Tioga/pdf_font_dicts.c → ext/Tioga/FigureMaker/__shared_pdf_font_dicts.c} +0 -0
- data/{split/Tioga/pdfcolor.c → ext/Tioga/FigureMaker/__shared_pdfcolor.c} +0 -0
- data/{split/Tioga/pdfcoords.c → ext/Tioga/FigureMaker/__shared_pdfcoords.c} +0 -0
- data/{split/Tioga/pdffile.c → ext/Tioga/FigureMaker/__shared_pdffile.c} +0 -0
- data/{split/Tioga/pdfimage.c → ext/Tioga/FigureMaker/__shared_pdfimage.c} +0 -0
- data/{split/Tioga/pdfpath.c → ext/Tioga/FigureMaker/__shared_pdfpath.c} +0 -0
- data/{split/Tioga/pdftext.c → ext/Tioga/FigureMaker/__shared_pdftext.c} +0 -0
- data/{split/Tioga/texout.c → ext/Tioga/FigureMaker/__shared_texout.c} +0 -0
- data/ext/Tioga/FigureMaker/extconf.rb +7 -0
- data/{split/Tioga → ext/Tioga/FigureMaker}/figures.c +14 -2
- data/{split/Tioga → ext/Tioga/FigureMaker}/figures.h +0 -0
- data/{split/Tioga → ext/Tioga/FigureMaker}/generic.c +1 -2
- data/{split/Tioga → ext/Tioga/FigureMaker}/generic.h +0 -1
- data/{split/Tioga → ext/Tioga/FigureMaker}/init.c +0 -0
- data/{split/Tioga → ext/Tioga/FigureMaker}/pdfs.h +0 -0
- data/{split/Tioga → ext/Tioga/FigureMaker/shared}/axes.c +32 -7
- data/{split/Tioga → ext/Tioga/FigureMaker/shared}/makers.c +2 -2
- data/ext/Tioga/FigureMaker/shared/pdf_font_dicts.c +18253 -0
- data/ext/Tioga/FigureMaker/shared/pdfcolor.c +904 -0
- data/ext/Tioga/FigureMaker/shared/pdfcoords.c +518 -0
- data/ext/Tioga/FigureMaker/shared/pdffile.c +451 -0
- data/ext/Tioga/FigureMaker/shared/pdfimage.c +539 -0
- data/ext/Tioga/FigureMaker/shared/pdfpath.c +766 -0
- data/ext/Tioga/FigureMaker/shared/pdftext.c +710 -0
- data/ext/Tioga/FigureMaker/shared/texout.c +533 -0
- data/{split/Tioga → ext/Tioga/FigureMaker}/wrappers.c +5 -5
- data/{split/Tioga → ext/Tioga/FigureMaker}/wrappers.h +0 -0
- data/{split/Dtable → ext/includes}/defs.h +0 -0
- data/{split/Dtable → ext/includes}/namespace.h +0 -0
- data/{split/Dtable → ext/includes}/safe_double.h +0 -0
- data/{split → ext/includes}/symbols.c +0 -1
- data/{split/Dtable → ext/includes}/symbols.h +0 -0
- data/{split/Dtable/lib → lib/Dobjects}/Dtable_extras.rb +0 -0
- data/{split/Dvector/lib → lib/Dobjects}/Dvector_extras.rb +1 -0
- data/{split/Function/lib → lib/Dobjects}/Function_extras.rb +0 -0
- data/{split/Dvector/lib → lib/Dobjects}/Numeric_extras.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Arcs_and_Circles.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/ColorConstants.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Colorbars.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Colormaps.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Coordinate_Conversions.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Creating_Paths.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Doc.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Executive.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/FigMkr.rb +13 -70
- data/{split/Tioga/lib → lib/Tioga}/FigureConstants.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Figures_and_Plots.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Images.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Legends.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/MarkerConstants.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Markers.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Page_Frame_Bounds.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Rectangles.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Shading.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Special_Paths.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Strokes.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/TeX_Text.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/TexPreamble.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Titles_and_Labels.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Transparency.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Using_Paths.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/Utils.rb +74 -0
- data/{split/Tioga/lib → lib/Tioga}/X_and_Y_Axes.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/irb_tioga.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/maker.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/tioga.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/tioga_ui.rb +0 -0
- data/{split/Tioga/lib → lib/Tioga}/tioga_ui_cmds.rb +0 -0
- data/tests/Icon_Test.pdf +0 -0
- data/tests/benchmark_dvector_reads.rb +20 -42
- data/tests/tc_Dvector.rb +45 -4
- data/tests/tc_Flate.rb +4 -5
- data/tests/tc_Function.rb +79 -0
- data/tests/vg.log +1453 -0
- metadata +141 -122
- data/split/Dtable/extconf.rb +0 -4
- data/split/Dvector/defs.h +0 -39
- data/split/Dvector/extconf.rb +0 -4
- data/split/Dvector/include/dvector.h +0 -77
- data/split/Dvector/namespace.h +0 -59
- data/split/Dvector/safe_double.h +0 -104
- data/split/Dvector/symbols.h +0 -52
- data/split/Flate/defs.h +0 -39
- data/split/Flate/extconf.rb +0 -19
- data/split/Flate/namespace.h +0 -59
- data/split/Flate/safe_double.h +0 -104
- data/split/Flate/symbols.h +0 -52
- data/split/Function/defs.h +0 -39
- data/split/Function/dvector.h +0 -77
- data/split/Function/extconf.rb +0 -4
- data/split/Function/namespace.h +0 -59
- data/split/Function/safe_double.h +0 -104
- data/split/Function/symbols.h +0 -52
- data/split/Tioga/defs.h +0 -39
- data/split/Tioga/dtable.h +0 -35
- data/split/Tioga/dvector.h +0 -77
- data/split/Tioga/extconf.rb +0 -4
- data/split/Tioga/flate.h +0 -98
- data/split/Tioga/mk_tioga_sty.rb +0 -53
- data/split/Tioga/namespace.h +0 -59
- data/split/Tioga/safe_double.h +0 -104
- data/split/Tioga/symbols.h +0 -52
- data/split/defs.h +0 -39
- data/split/extconf.rb +0 -125
- data/split/mkmf2.rb +0 -1623
- data/split/namespace.h +0 -59
- data/split/safe_double.h +0 -104
- data/split/symbols.h +0 -52
@@ -0,0 +1,533 @@
|
|
1
|
+
/* texout.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
|
+
|
24
|
+
#define RADIANS_TO_DEGREES (180.0 / PI)
|
25
|
+
|
26
|
+
static FILE *fp; // for the TeX file
|
27
|
+
|
28
|
+
/* TeX text */
|
29
|
+
|
30
|
+
void c_rescale_text(OBJ_PTR fmkr, FM *p, double scaling_factor, int *ierr) {
|
31
|
+
double scale = scaling_factor * p->default_text_scale;
|
32
|
+
if (scaling_factor <= 0) { RAISE_ERROR("Sorry: text scaling must be positive", ierr); return; }
|
33
|
+
p->default_text_height_dx *= scaling_factor;
|
34
|
+
p->default_text_height_dy *= scaling_factor;
|
35
|
+
p->default_text_scale = scale;
|
36
|
+
}
|
37
|
+
|
38
|
+
static int String_Is_Blank(char *str) {
|
39
|
+
char c;
|
40
|
+
if (str == NULL) return 1;
|
41
|
+
while (1) {
|
42
|
+
c = *str++;
|
43
|
+
if (c == '\0') return 1;
|
44
|
+
if (!isspace(c)) break;
|
45
|
+
}
|
46
|
+
return 0;
|
47
|
+
}
|
48
|
+
|
49
|
+
static OBJ_PTR Get_Measure_Hash(OBJ_PTR fmkr, OBJ_PTR measure_name)
|
50
|
+
{
|
51
|
+
OBJ_PTR value;
|
52
|
+
int i;
|
53
|
+
OBJ_PTR measures_info = Obj_Attr_Get(fmkr, measures_info_ID, &i);
|
54
|
+
if(measure_name == OBJ_NIL) {
|
55
|
+
return OBJ_NIL;
|
56
|
+
}
|
57
|
+
if(! Hash_Has_Key_Obj(measures_info, measure_name)) {
|
58
|
+
value = Hash_New();
|
59
|
+
Hash_Set_Obj_Obj(measures_info, measure_name, value);
|
60
|
+
}
|
61
|
+
else
|
62
|
+
value = Hash_Get_Obj_Obj(measures_info, measure_name);
|
63
|
+
return value;
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
static void tex_show_rotated_text(OBJ_PTR fmkr, FM *p, char *text,
|
68
|
+
double x, double y, double scale,
|
69
|
+
double angle, int justification,
|
70
|
+
int alignment, OBJ_PTR measure_name)
|
71
|
+
{ // x and y are the device coords for the reference point of the text
|
72
|
+
char ref, jst;
|
73
|
+
double ft_ht, sz;
|
74
|
+
int dummy;
|
75
|
+
OBJ_PTR measures = Get_Measure_Hash(fmkr, measure_name);
|
76
|
+
if (String_Is_Blank(text)) return; /* blank strings break TeX! */
|
77
|
+
scale *= p->default_text_scale;
|
78
|
+
ft_ht = scale * p->default_font_size;
|
79
|
+
sz = ft_ht * ENLARGE;
|
80
|
+
ref = (alignment == ALIGNED_AT_BASELINE)? 'B' :
|
81
|
+
(alignment == ALIGNED_AT_BOTTOM)? 'b' :
|
82
|
+
(alignment == ALIGNED_AT_TOP)? 't' : 'c';
|
83
|
+
if (justification == 0) jst = 'c';
|
84
|
+
else if (justification > 0) jst = 'r';
|
85
|
+
else jst = 'l';
|
86
|
+
bbox_llx = MIN(bbox_llx, x - sz);
|
87
|
+
bbox_lly = MIN(bbox_lly, y - sz);
|
88
|
+
bbox_urx = MAX(bbox_urx, x + sz);
|
89
|
+
bbox_ury = MAX(bbox_ury, y + sz);
|
90
|
+
if (angle != 0.0)
|
91
|
+
fprintf(fp,"\\put(%d,%d){\\rotatebox{%.1f}{\\scalebox{%.2f}{\\makebox(0,0)[%c%c]{",
|
92
|
+
ROUND(x), ROUND(y), angle, scale, jst, ref);
|
93
|
+
else
|
94
|
+
fprintf(fp,"\\put(%d,%d){\\scalebox{%.2f}{\\makebox(0,0)[%c%c]{",
|
95
|
+
ROUND(x), ROUND(y), scale, jst, ref);
|
96
|
+
if(measure_name != OBJ_NIL)
|
97
|
+
fprintf(fp, "{\\tiogameasure{%s}{\\tiogasetfont{}",
|
98
|
+
CString_Ptr(measure_name,&dummy));
|
99
|
+
else
|
100
|
+
fprintf(fp, "{{\\tiogasetfont{}");
|
101
|
+
|
102
|
+
/* Moving the \BS out of the potential \tiogameasure input, so it does
|
103
|
+
not disturb the measure.
|
104
|
+
*/
|
105
|
+
fprintf(fp, (alignment == ALIGNED_AT_BASELINE)? "%s}\\BS" : "%s}", text);
|
106
|
+
fprintf(fp, angle != 0? "}}}}}\n" : "}}}}\n");
|
107
|
+
|
108
|
+
/* Now, we save measures informations if applicable*/
|
109
|
+
if(measures != OBJ_NIL) {
|
110
|
+
Hash_Set_Double(measures, "scale", scale);
|
111
|
+
/* [xy]anchor are saved in postscript points */
|
112
|
+
Hash_Set_Double(measures, "xanchor", ROUND(x) / ENLARGE);
|
113
|
+
Hash_Set_Double(measures, "yanchor", ROUND(y) / ENLARGE);
|
114
|
+
Hash_Set_Double(measures, "angle", angle);
|
115
|
+
Hash_Set_Double(measures, "just", justification);
|
116
|
+
Hash_Set_Double(measures, "align", alignment);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
static void Convert_Frame_Text_Position_To_Output_Location(FM *p, int frame_side, double offset,
|
121
|
+
double fraction, double *xp, double *yp, double *base_angle, char *text, int *ierr)
|
122
|
+
{
|
123
|
+
double page_x, page_y;
|
124
|
+
switch (frame_side) {
|
125
|
+
case LEFT:
|
126
|
+
page_x = p->page_width * p->frame_left - offset;
|
127
|
+
page_y = p->page_height * (p->frame_bottom + fraction * p->frame_height);
|
128
|
+
*base_angle = 90;
|
129
|
+
break;
|
130
|
+
case RIGHT:
|
131
|
+
page_x = p->page_width * p->frame_right + offset;
|
132
|
+
page_y = p->page_height * (p->frame_bottom + fraction * p->frame_height);
|
133
|
+
*base_angle = 90;
|
134
|
+
break;
|
135
|
+
case AT_X_ORIGIN:
|
136
|
+
if (0.0 > p->bounds_xmax || 0.0 < p->bounds_xmin) {
|
137
|
+
RAISE_ERROR_s("Sorry: x origin is not part of plot for (%s)", text, ierr); return; }
|
138
|
+
page_x = convert_figure_to_output_x(p, 0.0);
|
139
|
+
if (p->xaxis_reversed) offset = -offset;
|
140
|
+
page_x += offset;
|
141
|
+
page_y = p->page_height * (p->frame_bottom + fraction * p->frame_height);
|
142
|
+
*base_angle = 90;
|
143
|
+
break;
|
144
|
+
case TOP:
|
145
|
+
page_y = p->page_height * p->frame_top + offset;
|
146
|
+
page_x = p->page_width * (p->frame_left + fraction * p->frame_width);
|
147
|
+
*base_angle = 0;
|
148
|
+
break;
|
149
|
+
case BOTTOM:
|
150
|
+
page_y = p->page_height * p->frame_bottom - offset;
|
151
|
+
page_x = p->page_width * (p->frame_left + fraction * p->frame_width);
|
152
|
+
*base_angle = 0;
|
153
|
+
break;
|
154
|
+
case AT_Y_ORIGIN:
|
155
|
+
if (0.0 > p->bounds_ymax || 0.0 < p->bounds_ymin) {
|
156
|
+
RAISE_ERROR_s("Sorry: y origin is not part of plot for (%s)", text, ierr); return; }
|
157
|
+
page_y = convert_figure_to_output_y(p, 0.0);
|
158
|
+
if (p->yaxis_reversed) offset = -offset;
|
159
|
+
page_y += offset;
|
160
|
+
page_x = p->page_width * (p->frame_left + fraction * p->frame_width);
|
161
|
+
*base_angle = 0;
|
162
|
+
break;
|
163
|
+
default:
|
164
|
+
RAISE_ERROR_s("Sorry: invalid parameter for frame side in show text (%s)", text, ierr);
|
165
|
+
return;
|
166
|
+
}
|
167
|
+
*xp = p->page_left + page_x; *yp = p->page_bottom + page_y;
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
void c_show_rotated_text(OBJ_PTR fmkr, FM *p, char *text, int frame_side,
|
172
|
+
double shift, double fraction, double scale,
|
173
|
+
double angle, int justification, int alignment,
|
174
|
+
OBJ_PTR measure_name, int *ierr)
|
175
|
+
{
|
176
|
+
double x = 0, y = 0, base_angle = 0;
|
177
|
+
double ft_ht = p->default_text_scale * scale * p->default_font_size;
|
178
|
+
Convert_Frame_Text_Position_To_Output_Location(p, frame_side,
|
179
|
+
shift * ft_ht * ENLARGE,
|
180
|
+
fraction, &x, &y,
|
181
|
+
&base_angle, text, ierr);
|
182
|
+
tex_show_rotated_text(fmkr, p, text, x, y, scale, angle + base_angle,
|
183
|
+
justification, alignment, measure_name);
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
void c_show_rotated_label(OBJ_PTR fmkr, FM *p, char *text,
|
188
|
+
double xloc, double yloc, double scale, double angle, int justification, int alignment, OBJ_PTR measure_name, int *ierr) {
|
189
|
+
tex_show_rotated_text(fmkr, p, text, convert_figure_to_output_x(p, xloc), convert_figure_to_output_y(p, yloc),
|
190
|
+
scale, angle, justification, alignment, measure_name);
|
191
|
+
}
|
192
|
+
|
193
|
+
OBJ_PTR c_check_label_clip(OBJ_PTR fmkr, FM *p, double x, double y, int *ierr) {
|
194
|
+
x = convert_figure_to_frame_x(p,x);
|
195
|
+
y = convert_figure_to_frame_y(p,y);
|
196
|
+
if (x < p->label_left_margin || y < p->label_bottom_margin ||
|
197
|
+
1.0 - x < p->label_right_margin || 1.0 - y < p->label_top_margin) RETURN_FALSE;
|
198
|
+
RETURN_TRUE;
|
199
|
+
}
|
200
|
+
|
201
|
+
/* TeX File Management */
|
202
|
+
|
203
|
+
static long cur_pos;
|
204
|
+
|
205
|
+
static void Get_tex_name(char *ofile, char *filename, int maxlen)
|
206
|
+
{
|
207
|
+
char *dot;
|
208
|
+
strncpy(ofile, filename, maxlen);
|
209
|
+
dot = strrchr(ofile,'.');
|
210
|
+
if (dot != NULL) dot[0] = '\0';
|
211
|
+
strcat(ofile, "_figure.txt");
|
212
|
+
}
|
213
|
+
|
214
|
+
void Open_tex(OBJ_PTR fmkr, char *filename, bool quiet_mode, int *ierr)
|
215
|
+
{
|
216
|
+
char ofile[300];
|
217
|
+
Get_tex_name(ofile, filename, 300);
|
218
|
+
fp = fopen(ofile, "w");
|
219
|
+
fprintf(fp,"\\setlength{\\unitlength}{%fbp}%%\n", 1.0/ENLARGE);
|
220
|
+
cur_pos = ftell(fp);
|
221
|
+
fprintf(fp,"\\begin{picture}(xxxxxx,xxxxxx) %% (width,height)(xoffset,yoffset) -- Adjust the 2nd pair for registration adjustments\n"); /* this line is rewritten at the end */
|
222
|
+
fprintf(fp,"\\def\\BS{\\phantom{\\Huge\\scalebox{0}[2]{\\hbox{\\rotatebox{180}{O}O}}}}\n");
|
223
|
+
// graphicx seems to vertically align baseline (B) like center (c),
|
224
|
+
// so we add BS (Big Strut) to make them look the same
|
225
|
+
}
|
226
|
+
|
227
|
+
void Close_tex(OBJ_PTR fmkr, bool quiet_mode, int *ierr)
|
228
|
+
{
|
229
|
+
double x, y, xoff, yoff;
|
230
|
+
x = bbox_urx - bbox_llx; if (x < 0) x = bbox_urx = bbox_llx = 0;
|
231
|
+
y = bbox_ury - bbox_lly; if (y < 0) y = bbox_ury = bbox_lly = 0;
|
232
|
+
xoff = bbox_llx + Get_tex_xoffset(fmkr,ierr)*ENLARGE;
|
233
|
+
yoff = bbox_lly + Get_tex_yoffset(fmkr,ierr)*ENLARGE;
|
234
|
+
fprintf(fp,"\\end{picture}");
|
235
|
+
fseek(fp, cur_pos, SEEK_SET);
|
236
|
+
fprintf(fp,"\\begin{picture}(%03d,%03d)(%02d,%d)", ROUND(x), ROUND(y), ROUND(xoff), ROUND(yoff));
|
237
|
+
fclose(fp);
|
238
|
+
}
|
239
|
+
|
240
|
+
|
241
|
+
static void Write_preview_header(OBJ_PTR fmkr, FILE *file, int *ierr) {
|
242
|
+
fprintf(file, "\\documentclass{%s}\n\n", Get_tex_preview_documentclass(fmkr,ierr));
|
243
|
+
/* we print out the preamble generated from tioga.sty.in */
|
244
|
+
fprintf(file, "%% Tioga preamble generated from tioga.sty.in\n");
|
245
|
+
fprintf(file, "%s\n", Get_tex_preview_generated_preamble(fmkr,ierr));
|
246
|
+
fprintf(file, "%% User-specified preamble\n");
|
247
|
+
fprintf(file, "%s\n\n", Get_tex_preamble(fmkr,ierr));
|
248
|
+
fprintf(file, "%% Command to format numeric labels on xaxis\n");
|
249
|
+
fprintf(file, "\\newcommand{\\tiogaxaxisnumericlabel}[1]{%s}\n\n", Get_xaxis_numeric_label_tex(fmkr,ierr));
|
250
|
+
fprintf(file, "%% Command to format numeric labels on yaxis\n");
|
251
|
+
fprintf(file, "\\newcommand{\\tiogayaxisnumericlabel}[1]{%s}\n\n", Get_yaxis_numeric_label_tex(fmkr,ierr));
|
252
|
+
fprintf(file, "%% Color constants definitions\n");
|
253
|
+
fprintf(file, "%s\n\n", CString_Ptr(COLOR_PREAMBLE(fmkr,ierr),ierr));
|
254
|
+
fprintf(file, "%% Set page margins, page size and orientation.\n");
|
255
|
+
fprintf(file, "\t\\usepackage[pdftex,tmargin=0pt,lmargin=0pt,"
|
256
|
+
"rmargin=0pt,bmargin=0pt,\n");
|
257
|
+
fprintf(file, "\tpaperwidth=%s,paperheight=%s,\n",
|
258
|
+
Get_tex_preview_paper_width(fmkr,ierr),
|
259
|
+
Get_tex_preview_paper_height(fmkr,ierr));
|
260
|
+
fprintf(file, "\thoffset=%s,voffset=%s\n",
|
261
|
+
Get_tex_preview_hoffset(fmkr,ierr),
|
262
|
+
Get_tex_preview_voffset(fmkr,ierr));
|
263
|
+
fprintf(file, "\t]{geometry}\n");
|
264
|
+
|
265
|
+
fprintf(file, "\n%% We need the graphicx package and the calc package.\n");
|
266
|
+
fprintf(file, "\t\\usepackage{graphicx}\n");
|
267
|
+
fprintf(file, "\t\\usepackage{calc}\n\n");
|
268
|
+
fprintf(file, "\t%% This is necessary to avoid getting the picture on the second page\n");
|
269
|
+
fprintf(file, "\t\\topskip=0pt\n\n");
|
270
|
+
|
271
|
+
/* now, the commands to customize the font used */
|
272
|
+
fprintf(file, "\\settiogafontsize[10pt]{%s}\n", Get_tex_fontsize(fmkr,ierr));
|
273
|
+
fprintf(file, "\\settiogafontfamily{\\%s}\n", Get_tex_fontfamily(fmkr,ierr));
|
274
|
+
fprintf(file, "\\settiogafontseries{\\%s}\n", Get_tex_fontseries(fmkr,ierr));
|
275
|
+
fprintf(file, "\\settiogafontshape{\\%s}\n", Get_tex_fontshape(fmkr,ierr));
|
276
|
+
}
|
277
|
+
|
278
|
+
|
279
|
+
static void Write_figure_command(OBJ_PTR fmkr, char *simple_name, FILE *file, int *ierr) {
|
280
|
+
char *minwhitespace;
|
281
|
+
|
282
|
+
if (Get_tex_preview_fullpage(fmkr,ierr)) {
|
283
|
+
minwhitespace = Get_tex_preview_minwhitespace(fmkr,ierr);
|
284
|
+
if (minwhitespace == NULL) {
|
285
|
+
fprintf(file, "\\tiogafigurefullpage{%s}\n", simple_name);
|
286
|
+
} else {
|
287
|
+
fprintf(file, "\\tiogafigurefullpage[%s]{%s}\n", minwhitespace, simple_name);
|
288
|
+
}
|
289
|
+
} else {
|
290
|
+
const char * command = Get_tex_preview_tiogafigure_command(fmkr,ierr);
|
291
|
+
if(strcmp(command, "tiogafigureshow")) {
|
292
|
+
fprintf(file, "\\%s{%s}{%s}{%s}\n", Get_tex_preview_tiogafigure_command(fmkr,ierr), simple_name,
|
293
|
+
Get_tex_preview_figure_width(fmkr,ierr), Get_tex_preview_figure_height(fmkr,ierr));
|
294
|
+
} else { /* no need for extra arguments for tiogafigureshow */
|
295
|
+
fprintf(file, "\\%s{%s}\n", Get_tex_preview_tiogafigure_command(fmkr,ierr), simple_name);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
|
301
|
+
void Create_wrapper(OBJ_PTR fmkr, char *fname, bool quiet_mode, int *ierr)
|
302
|
+
{ // create the wrapper TeX file to combine the text and graphics to make a figure
|
303
|
+
char *dot;
|
304
|
+
char tex_fname[100], base_name[100], simple_name[100];
|
305
|
+
FILE *file;
|
306
|
+
if ((dot=strrchr(fname,'.')) != NULL) {
|
307
|
+
strncpy(base_name, fname, dot-fname); base_name[dot-fname] = '\0';
|
308
|
+
snprintf(tex_fname, sizeof(tex_fname), "%s.tex", base_name);
|
309
|
+
}
|
310
|
+
else {
|
311
|
+
strcpy(base_name, fname);
|
312
|
+
snprintf(tex_fname, sizeof(tex_fname), "%s.tex", fname);
|
313
|
+
}
|
314
|
+
if ((dot=strrchr(base_name,'/')) != NULL) {
|
315
|
+
strcpy(simple_name, dot+1);
|
316
|
+
}
|
317
|
+
else {
|
318
|
+
strcpy(simple_name, base_name);
|
319
|
+
}
|
320
|
+
file = fopen(tex_fname, "w");
|
321
|
+
fprintf(file, "%% Tioga preview LaTeX file for %s_figure.pdf and %s_figure.txt\n\n", base_name, base_name);
|
322
|
+
|
323
|
+
Write_preview_header(fmkr, file, ierr);
|
324
|
+
|
325
|
+
fprintf(file, "\n%% Here's the page with the figure.\n");
|
326
|
+
fprintf(file, "\\begin{document}\n");
|
327
|
+
fprintf(file, "\\pagestyle{%s}\n", Get_tex_preview_pagestyle(fmkr,ierr));
|
328
|
+
/* necessary to get the position right */
|
329
|
+
fprintf(file, "\\noindent");
|
330
|
+
Write_figure_command(fmkr, simple_name, file, ierr);
|
331
|
+
fprintf(file, "\\end{document}\n");
|
332
|
+
fclose(file);
|
333
|
+
}
|
334
|
+
|
335
|
+
void Init_tex(int *ierr)
|
336
|
+
{
|
337
|
+
}
|
338
|
+
|
339
|
+
void Rename_tex(char *oldname, char *newname, int *ierr)
|
340
|
+
{
|
341
|
+
char old_ofile[300], new_ofile[300];
|
342
|
+
Get_tex_name(old_ofile, oldname, 300);
|
343
|
+
Get_tex_name(new_ofile, newname, 300);
|
344
|
+
rename(old_ofile, new_ofile); // from stdio.h
|
345
|
+
}
|
346
|
+
|
347
|
+
void private_make_portfolio(char *name, OBJ_PTR fignums, OBJ_PTR fignames, int *ierr)
|
348
|
+
{
|
349
|
+
FILE *file;
|
350
|
+
int i, len, numfigs, j;
|
351
|
+
char tex_fname[256];
|
352
|
+
snprintf(tex_fname, sizeof(tex_fname), "%s.tex", name);
|
353
|
+
file = fopen(tex_fname, "w");
|
354
|
+
if (file == NULL) {
|
355
|
+
RAISE_ERROR_s("Sorry: can't open %s.\n", tex_fname, ierr); return; }
|
356
|
+
fprintf(file, "%% Tioga Portfolio %s\n\n", name);
|
357
|
+
fprintf(file, "\\documentclass{article}\n");
|
358
|
+
fprintf(file, "\\usepackage{pdfpages}\n");
|
359
|
+
fprintf(file, "\\begin{document}\n");
|
360
|
+
fprintf(file, "%% Start of figures, one per page\n\n");
|
361
|
+
len = Array_Len(fignames,ierr);
|
362
|
+
if (fignums == OBJ_NIL) {
|
363
|
+
for (i=0; i < len; i++) {
|
364
|
+
fprintf(file, "\\includepdf{%s.pdf}\n", Get_String(fignames, i, ierr));
|
365
|
+
if (*ierr != 0) return;
|
366
|
+
}
|
367
|
+
} else {
|
368
|
+
numfigs = Array_Len(fignums,ierr);
|
369
|
+
if (*ierr != 0) return;
|
370
|
+
for (i=0; i < numfigs; i++) {
|
371
|
+
OBJ_PTR n = Array_Entry(fignums,i,ierr);
|
372
|
+
if (*ierr != 0) return;
|
373
|
+
j = Number_to_int(n,ierr);
|
374
|
+
if (j >= 0 && j < len) {
|
375
|
+
fprintf(file, "\\includepdf{%s.pdf}\n", Get_String(fignames, j, ierr));
|
376
|
+
if (*ierr != 0) return;
|
377
|
+
}
|
378
|
+
else {
|
379
|
+
fclose(file);
|
380
|
+
RAISE_ERROR("Requested figure numbers must be >= 0 and < num_figures.", ierr);
|
381
|
+
return;
|
382
|
+
}
|
383
|
+
}
|
384
|
+
}
|
385
|
+
fprintf(file, "\n\\end{document}\n");
|
386
|
+
fclose(file);
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
/*
|
391
|
+
Stores and transforms measures as printed by pdflatex.
|
392
|
+
|
393
|
+
Takes sizes in bp.
|
394
|
+
|
395
|
+
*/
|
396
|
+
void c_private_save_measure(OBJ_PTR fmkr, OBJ_PTR measure_name,
|
397
|
+
double width, double height, double depth)
|
398
|
+
{
|
399
|
+
double angle, scale;
|
400
|
+
int just, align;
|
401
|
+
/* Page coordinates in bp before applying rotation ! */
|
402
|
+
double xl,xr,yt,yb;
|
403
|
+
double xa,ya;
|
404
|
+
OBJ_PTR measures = Get_Measure_Hash(fmkr, measure_name);
|
405
|
+
int dummy;
|
406
|
+
|
407
|
+
/* The following really should not happen */
|
408
|
+
if(measures == OBJ_NIL) {
|
409
|
+
fprintf(stderr, "Warning: got hash = OBJ_NIL in %s, line %d\n",
|
410
|
+
__FILE__, __LINE__);
|
411
|
+
return;
|
412
|
+
}
|
413
|
+
|
414
|
+
/* Storing measured sizes */
|
415
|
+
Hash_Set_Double(measures, "tex_measured_width", width);
|
416
|
+
Hash_Set_Double(measures, "tex_measured_height", height);
|
417
|
+
Hash_Set_Double(measures, "tex_measured_depth", depth);
|
418
|
+
|
419
|
+
angle = Hash_Get_Double(measures, "angle");
|
420
|
+
scale = Hash_Get_Double(measures, "scale");
|
421
|
+
just = Hash_Get_Double(measures, "just");
|
422
|
+
align = Hash_Get_Double(measures, "align");
|
423
|
+
|
424
|
+
/* Setting the appropriate scale */
|
425
|
+
width *= scale;
|
426
|
+
height *= scale;
|
427
|
+
depth *= scale;
|
428
|
+
/* Now setting the width and height in */
|
429
|
+
Hash_Set_Double(measures, "width", width);
|
430
|
+
Hash_Set_Double(measures, "height", height);
|
431
|
+
Hash_Set_Double(measures, "depth", depth);
|
432
|
+
|
433
|
+
xa = Hash_Get_Double(measures, "xanchor");
|
434
|
+
ya = Hash_Get_Double(measures, "yanchor");
|
435
|
+
|
436
|
+
/* Now, we try to compute the precise position of
|
437
|
+
the points of the box surrounding the text.
|
438
|
+
*/
|
439
|
+
|
440
|
+
/* First, before rotation: */
|
441
|
+
switch(just) {
|
442
|
+
case 1: /* Right-justified */
|
443
|
+
xr = xa;
|
444
|
+
xl = xa - width;
|
445
|
+
break;
|
446
|
+
case 0: /* Centered */
|
447
|
+
xr = xa + width/2;
|
448
|
+
xl = xa - width/2;
|
449
|
+
break;
|
450
|
+
case -1: /* Left-justified */
|
451
|
+
xl = xa;
|
452
|
+
xr = xa + width;
|
453
|
+
break;
|
454
|
+
default:
|
455
|
+
fprintf(stderr, "Invalid justification = %d at %s, line %d\n",
|
456
|
+
just, __FILE__, __LINE__);
|
457
|
+
xl = xa;
|
458
|
+
xr = xa + width/2;
|
459
|
+
}
|
460
|
+
|
461
|
+
/* First, before rotation: */
|
462
|
+
switch(align) {
|
463
|
+
case ALIGNED_AT_BASELINE:
|
464
|
+
yt = ya + height;
|
465
|
+
yb = ya - depth;
|
466
|
+
break;
|
467
|
+
case ALIGNED_AT_BOTTOM:
|
468
|
+
yt = ya + height + depth;
|
469
|
+
yb = ya;
|
470
|
+
break;
|
471
|
+
case ALIGNED_AT_TOP:
|
472
|
+
yb = ya - height - depth;
|
473
|
+
yt = ya;
|
474
|
+
break;
|
475
|
+
default: /* Centered */
|
476
|
+
yb = ya - 0.5*(height + depth);
|
477
|
+
yt = ya + 0.5*(height + depth);
|
478
|
+
}
|
479
|
+
|
480
|
+
/* Now, rotation */
|
481
|
+
if(angle == 0.0) {
|
482
|
+
/* xbl = x of 'bottom left' */
|
483
|
+
Hash_Set_Double(measures, "xbl", xl);
|
484
|
+
Hash_Set_Double(measures, "ybl", yb);
|
485
|
+
Hash_Set_Double(measures, "xtl", xl);
|
486
|
+
Hash_Set_Double(measures, "ytl", yt);
|
487
|
+
Hash_Set_Double(measures, "xbr", xr);
|
488
|
+
Hash_Set_Double(measures, "ybr", yb);
|
489
|
+
Hash_Set_Double(measures, "xtr", xr);
|
490
|
+
Hash_Set_Double(measures, "ytr", yt);
|
491
|
+
}
|
492
|
+
else {
|
493
|
+
double s = - sin(angle * PI/180);
|
494
|
+
double c = cos(angle * PI/180);
|
495
|
+
Hash_Set_Double(measures, "xbl",
|
496
|
+
xa + (xl-xa)*c + (yb - ya) * s);
|
497
|
+
Hash_Set_Double(measures, "ybl",
|
498
|
+
ya - (xl-xa)*s + (yb - ya) * c);
|
499
|
+
Hash_Set_Double(measures, "xtl",
|
500
|
+
xa + (xl-xa)*c + (yt - ya) * s);
|
501
|
+
Hash_Set_Double(measures, "ytl",
|
502
|
+
ya - (xl-xa)*s + (yt - ya) * c);
|
503
|
+
Hash_Set_Double(measures, "xbr",
|
504
|
+
xa + (xr-xa)*c + (yb - ya) * s);
|
505
|
+
Hash_Set_Double(measures, "ybr",
|
506
|
+
ya - (xr-xa)*s + (yb - ya) * c);
|
507
|
+
Hash_Set_Double(measures, "xtr",
|
508
|
+
xa + (xr-xa)*c + (yt - ya) * s);
|
509
|
+
Hash_Set_Double(measures, "ytr",
|
510
|
+
ya - (xr-xa)*s + (yt - ya) * c);
|
511
|
+
}
|
512
|
+
|
513
|
+
/* We transform coordinates into an array
|
514
|
+
(topleft, topright, botright, botleft)
|
515
|
+
of arrays (xy) of doubles
|
516
|
+
*/
|
517
|
+
OBJ_PTR points = Array_New(0);
|
518
|
+
OBJ_PTR current_point = OBJ_NIL;
|
519
|
+
int i;
|
520
|
+
for(i = 0; i < 8; i++) {
|
521
|
+
char buf[4];
|
522
|
+
if(! (i % 2)) {
|
523
|
+
current_point = Array_New(0);
|
524
|
+
Array_Push(points, current_point, &dummy);
|
525
|
+
}
|
526
|
+
snprintf(buf, sizeof(buf), "%c%c%c",
|
527
|
+
(i%2 ? 'y' : 'x'),
|
528
|
+
(i/4 ? 't' : 'b'),
|
529
|
+
((i >= 2) && (i < 6) ? 'r' : 'l'));
|
530
|
+
Array_Push(current_point, Hash_Get_Obj(measures, buf), &dummy);
|
531
|
+
}
|
532
|
+
Hash_Set_Obj(measures, "points", points);
|
533
|
+
}
|