tioga 1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Tioga_README +372 -0
- data/lgpl.txt +504 -0
- data/split/Dtable/defs.h +33 -0
- data/split/Dtable/dtable.c +1928 -0
- data/split/Dtable/dtable_intern.h +144 -0
- data/split/Dtable/dvector.h +61 -0
- data/split/Dtable/extconf.rb +4 -0
- data/split/Dtable/include/dtable.h +35 -0
- data/split/Dtable/lib/Dtable_extras.rb +90 -0
- data/split/Dtable/namespace.h +47 -0
- data/split/Dtable/safe_double.h +104 -0
- data/split/Dtable/symbols.c +92 -0
- data/split/Dtable/symbols.h +52 -0
- data/split/Dvector/defs.h +33 -0
- data/split/Dvector/dvector.c +5486 -0
- data/split/Dvector/dvector_intern.h +142 -0
- data/split/Dvector/extconf.rb +4 -0
- data/split/Dvector/include/dvector.h +61 -0
- data/split/Dvector/lib/Dvector_extras.rb +328 -0
- data/split/Dvector/lib/Numeric_extras.rb +134 -0
- data/split/Dvector/namespace.h +47 -0
- data/split/Dvector/safe_double.h +104 -0
- data/split/Dvector/symbols.c +92 -0
- data/split/Dvector/symbols.h +52 -0
- data/split/Flate/defs.h +33 -0
- data/split/Flate/extconf.rb +19 -0
- data/split/Flate/flate.c +156 -0
- data/split/Flate/flate_intern.h +97 -0
- data/split/Flate/include/flate.h +98 -0
- data/split/Flate/namespace.h +47 -0
- data/split/Flate/safe_double.h +104 -0
- data/split/Flate/symbols.c +92 -0
- data/split/Flate/symbols.h +52 -0
- data/split/Function/defs.h +33 -0
- data/split/Function/dvector.h +61 -0
- data/split/Function/extconf.rb +4 -0
- data/split/Function/function.c +988 -0
- data/split/Function/joint_qsort.c +258 -0
- data/split/Function/lib/Function_extras.rb +44 -0
- data/split/Function/namespace.h +47 -0
- data/split/Function/safe_double.h +104 -0
- data/split/Function/symbols.c +92 -0
- data/split/Function/symbols.h +52 -0
- data/split/Tioga/axes.c +774 -0
- data/split/Tioga/defs.h +33 -0
- data/split/Tioga/dtable.h +35 -0
- data/split/Tioga/dvector.h +61 -0
- data/split/Tioga/extconf.rb +4 -0
- data/split/Tioga/figures.c +672 -0
- data/split/Tioga/figures.h +855 -0
- data/split/Tioga/flate.h +98 -0
- data/split/Tioga/init.c +524 -0
- data/split/Tioga/lib/Arcs_and_Circles.rb +64 -0
- data/split/Tioga/lib/ColorConstants.rb +274 -0
- data/split/Tioga/lib/Colorbars.rb +10 -0
- data/split/Tioga/lib/Colormaps.rb +105 -0
- data/split/Tioga/lib/Coordinate_Conversions.rb +194 -0
- data/split/Tioga/lib/Creating_Paths.rb +94 -0
- data/split/Tioga/lib/Doc.rb +91 -0
- data/split/Tioga/lib/Executive.rb +515 -0
- data/split/Tioga/lib/FigMkr.rb +2224 -0
- data/split/Tioga/lib/FigureConstants.rb +125 -0
- data/split/Tioga/lib/Figures_and_Plots.rb +268 -0
- data/split/Tioga/lib/Images.rb +278 -0
- data/split/Tioga/lib/Legends.rb +190 -0
- data/split/Tioga/lib/MarkerConstants.rb +122 -0
- data/split/Tioga/lib/Markers.rb +129 -0
- data/split/Tioga/lib/Page_Frame_Bounds.rb +567 -0
- data/split/Tioga/lib/Rectangles.rb +94 -0
- data/split/Tioga/lib/Shading.rb +100 -0
- data/split/Tioga/lib/Special_Paths.rb +307 -0
- data/split/Tioga/lib/Strokes.rb +129 -0
- data/split/Tioga/lib/TeX_Text.rb +454 -0
- data/split/Tioga/lib/TexPreamble.rb +358 -0
- data/split/Tioga/lib/Titles_and_Labels.rb +306 -0
- data/split/Tioga/lib/Transparency.rb +89 -0
- data/split/Tioga/lib/Using_Paths.rb +164 -0
- data/split/Tioga/lib/Utils.rb +74 -0
- data/split/Tioga/lib/X_and_Y_Axes.rb +749 -0
- data/split/Tioga/lib/irb_tioga.rb +122 -0
- data/split/Tioga/lib/tioga.rb +1 -0
- data/split/Tioga/lib/tioga_ui.rb +5 -0
- data/split/Tioga/lib/tioga_ui_cmds.rb +793 -0
- data/split/Tioga/makers.c +989 -0
- data/split/Tioga/mk_tioga_sty.rb +53 -0
- data/split/Tioga/namespace.h +47 -0
- data/split/Tioga/pdf_font_dicts.c +18253 -0
- data/split/Tioga/pdfcolor.c +486 -0
- data/split/Tioga/pdfcoords.c +505 -0
- data/split/Tioga/pdffile.c +342 -0
- data/split/Tioga/pdfimage.c +536 -0
- data/split/Tioga/pdfpath.c +914 -0
- data/split/Tioga/pdfs.h +229 -0
- data/split/Tioga/pdftext.c +443 -0
- data/split/Tioga/safe_double.h +104 -0
- data/split/Tioga/symbols.c +92 -0
- data/split/Tioga/symbols.h +52 -0
- data/split/Tioga/texout.c +380 -0
- data/split/defs.h +33 -0
- data/split/extconf.rb +107 -0
- data/split/mkmf2.rb +1612 -0
- data/split/namespace.h +47 -0
- data/split/safe_double.h +104 -0
- data/split/scripts/tioga +4 -0
- data/split/symbols.c +92 -0
- data/split/symbols.h +52 -0
- data/tests/dtable_test.data +6 -0
- data/tests/dvector_read_test.data +1 -0
- data/tests/dvector_test.data +101 -0
- data/tests/tc_Dtable.rb +221 -0
- data/tests/tc_Dvector.rb +791 -0
- data/tests/tc_FMkr.rb +162 -0
- data/tests/tc_Flate.rb +45 -0
- data/tests/tc_Function.rb +111 -0
- data/tests/ts_Tioga.rb +38 -0
- metadata +163 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
/**********************************************************************
|
2
|
+
|
3
|
+
safe_double.h: small abstraction for storing double without endianess
|
4
|
+
problems
|
5
|
+
|
6
|
+
Copyright (C) 2006 Vincent Fourmond
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify
|
9
|
+
it under the terms of the GNU General Library Public License as published
|
10
|
+
by the Free Software Foundation; either version 2 of the License, or
|
11
|
+
(at your option) any later version.
|
12
|
+
|
13
|
+
This program is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
GNU Library General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Library General Public License
|
19
|
+
along with this program; if not, write to the Free Software
|
20
|
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
|
22
|
+
**********************************************************************/
|
23
|
+
|
24
|
+
/* This file provides two functions: store_double and get_double, which
|
25
|
+
can be used in a 'safe' way to store doubles and retrive them
|
26
|
+
in a hopefully platform-independent form. However, it just
|
27
|
+
stores it without regards to that if ieee754.h isn't found...
|
28
|
+
*/
|
29
|
+
|
30
|
+
#ifndef _DOUBLE_H
|
31
|
+
#define _DOUBLE_H
|
32
|
+
|
33
|
+
#define STORE_LOWER_BYTE(a,p) do {\
|
34
|
+
*(p++) = (a) & 0xFF; (a) >>= 8; }\
|
35
|
+
while(0)
|
36
|
+
#define STORE_UNSIGNED(a,p) for(i = 0; i < 4; i++) STORE_LOWER_BYTE(a,p);
|
37
|
+
#define GET_UNSIGNED(a,p) do { a = 0; for(i = 0; i < 4; i++) \
|
38
|
+
(a) |= *(p++) << (i * 8); } while (0)
|
39
|
+
|
40
|
+
#ifdef HAVE_IEEE754_H
|
41
|
+
#include <ieee754.h>
|
42
|
+
|
43
|
+
|
44
|
+
static inline void store_double(double a, unsigned char * p)
|
45
|
+
{
|
46
|
+
unsigned int tmp;
|
47
|
+
int i;
|
48
|
+
union ieee754_double d;
|
49
|
+
d.d = a;
|
50
|
+
/* we store it with lower bytes firts */
|
51
|
+
tmp = d.ieee.mantissa1;
|
52
|
+
STORE_UNSIGNED(tmp, p);
|
53
|
+
tmp = d.ieee.negative << 31 |
|
54
|
+
d.ieee.exponent << 20 |
|
55
|
+
d.ieee.mantissa0;
|
56
|
+
STORE_UNSIGNED(tmp, p);
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
static inline double get_double(const unsigned char * p)
|
61
|
+
{
|
62
|
+
unsigned int tmp;
|
63
|
+
int i;
|
64
|
+
union ieee754_double d;
|
65
|
+
GET_UNSIGNED(tmp, p);
|
66
|
+
d.ieee.mantissa1 = tmp;
|
67
|
+
GET_UNSIGNED(tmp, p);
|
68
|
+
d.ieee.mantissa0 = tmp & 0xFFFFF;
|
69
|
+
d.ieee.exponent = (tmp >> 20) & 0x7FF;
|
70
|
+
d.ieee.negative = (tmp >> 31) & 0x1;
|
71
|
+
return d.d;
|
72
|
+
}
|
73
|
+
|
74
|
+
#else
|
75
|
+
|
76
|
+
union basic_double{
|
77
|
+
double d;
|
78
|
+
struct {
|
79
|
+
unsigned int a:32;
|
80
|
+
unsigned int b:32;
|
81
|
+
} i;
|
82
|
+
};
|
83
|
+
|
84
|
+
static inline void store_double(double a, unsigned char * p)
|
85
|
+
{
|
86
|
+
union basic_double d;
|
87
|
+
int i;
|
88
|
+
d.d = a;
|
89
|
+
STORE_UNSIGNED(d.i.a, p);
|
90
|
+
STORE_UNSIGNED(d.i.b, p);
|
91
|
+
}
|
92
|
+
|
93
|
+
static inline double get_double(const unsigned char * p)
|
94
|
+
{
|
95
|
+
union basic_double d;
|
96
|
+
int i;
|
97
|
+
GET_UNSIGNED(d.i.a, p);
|
98
|
+
GET_UNSIGNED(d.i.b, p);
|
99
|
+
return d.d;
|
100
|
+
}
|
101
|
+
|
102
|
+
#endif /* HAVE_IEEE754_H */
|
103
|
+
|
104
|
+
#endif /* _DOUBLE_H */
|
@@ -0,0 +1,92 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (C) 2006 Vincent Fourmond
|
3
|
+
|
4
|
+
Symbols is free software; you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Library Public License as published
|
6
|
+
by the Free Software Foundation; either version 2 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
Symbols is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Library General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Library General Public License
|
15
|
+
along with Dvector; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
/* Simple code for sharing C symbols across different Ruby libraries */
|
21
|
+
|
22
|
+
#include <ruby.h>
|
23
|
+
#include <intern.h>
|
24
|
+
|
25
|
+
#include <namespace.h>
|
26
|
+
|
27
|
+
|
28
|
+
/* MV stands for Module Variable */
|
29
|
+
#define MV_SYMBOLS "@_exported_C_symbols"
|
30
|
+
/* modified to use instance variables instead of global class variables:
|
31
|
+
this way, children don't overwrite the parent's export table
|
32
|
+
*/
|
33
|
+
|
34
|
+
|
35
|
+
/* makes sure that the hash is registered for the given
|
36
|
+
module and returns it */
|
37
|
+
static VALUE get_symbol_hash(VALUE module)
|
38
|
+
{
|
39
|
+
VALUE hash;
|
40
|
+
ID mv_id = rb_intern(MV_SYMBOLS);
|
41
|
+
if(RTEST(rb_ivar_defined(module, mv_id)))
|
42
|
+
{
|
43
|
+
hash = rb_ivar_get(module, mv_id);
|
44
|
+
Check_Type(hash, T_HASH);
|
45
|
+
return hash;
|
46
|
+
}
|
47
|
+
else
|
48
|
+
{
|
49
|
+
/* module variable uninitialized, we need to make sure it's here */
|
50
|
+
hash = rb_hash_new();
|
51
|
+
rb_ivar_set(module, mv_id, hash);
|
52
|
+
return hash;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
/* registers a symbol in the given module. This one is the internal
|
57
|
+
function */
|
58
|
+
PRIVATE void rb_export_symbol(VALUE module, const char * symbol_name,
|
59
|
+
void * symbol)
|
60
|
+
{
|
61
|
+
VALUE hash = get_symbol_hash(module);
|
62
|
+
rb_hash_aset(hash, rb_str_new2(symbol_name),LONG2NUM((long) symbol));
|
63
|
+
}
|
64
|
+
|
65
|
+
PRIVATE void * rb_import_symbol_no_raise(VALUE module,
|
66
|
+
const char * symbol_name)
|
67
|
+
{
|
68
|
+
VALUE hash = rb_iv_get(module, MV_SYMBOLS);
|
69
|
+
if(TYPE(hash) != T_HASH)
|
70
|
+
return NULL; /* doesn't fail, but the importing module
|
71
|
+
should definitely check the return value. Beware
|
72
|
+
of segfaults ! */
|
73
|
+
VALUE symbol = rb_hash_aref(hash, rb_str_new2(symbol_name));
|
74
|
+
|
75
|
+
if(TYPE(symbol) == T_FIXNUM || TYPE(symbol) == T_BIGNUM)
|
76
|
+
return (void *) NUM2LONG(symbol);
|
77
|
+
return NULL;
|
78
|
+
}
|
79
|
+
|
80
|
+
/* same as before, but raises something is the return value is NULL,
|
81
|
+
which is probably best as a default behavior*/
|
82
|
+
PRIVATE void * rb_import_symbol(VALUE module, const char * symbol_name)
|
83
|
+
{
|
84
|
+
void * symbol = rb_import_symbol_no_raise(module, symbol_name);
|
85
|
+
if(symbol)
|
86
|
+
return symbol;
|
87
|
+
/* we get the name of the module: */
|
88
|
+
VALUE module_name = rb_funcall(module, rb_intern("to_s"), 0);
|
89
|
+
rb_raise(rb_eRuntimeError, "The symbol %s was not found in "
|
90
|
+
"module %s", symbol_name,
|
91
|
+
rb_string_value_cstr(&module_name));
|
92
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#ifndef _SYMBOLS_H
|
2
|
+
#define _SYMBOLS_H
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
/* A small layer for exporting and importing symbols from
|
6
|
+
a compiled module */
|
7
|
+
|
8
|
+
#include <namespace.h>
|
9
|
+
|
10
|
+
|
11
|
+
PRIVATE void rb_export_symbol(VALUE module, const char * symbol_name,
|
12
|
+
void * symbol);
|
13
|
+
PRIVATE void * rb_import_symbol(VALUE module, const char * symbol_name);
|
14
|
+
PRIVATE void * rb_import_symbol_no_raise(VALUE module,
|
15
|
+
const char * symbol_name);
|
16
|
+
|
17
|
+
/* a shortcut for exporting something with the same name */
|
18
|
+
#define RB_EXPORT_SYMBOL(module, name) \
|
19
|
+
rb_export_symbol(module, #name, name)
|
20
|
+
|
21
|
+
/* A shortcut for getting a symbol */
|
22
|
+
|
23
|
+
#define DECLARE_SYMBOL(ret_type,name,args) \
|
24
|
+
typedef ret_type (*rb_export_##name##_type) args;\
|
25
|
+
PRIVATE rb_export_##name##_type name
|
26
|
+
|
27
|
+
#define IMPLEMENT_SYMBOL(name)\
|
28
|
+
PRIVATE rb_export_##name##_type name = 0;
|
29
|
+
|
30
|
+
#define RB_IMPORT_SYMBOL(module, name) \
|
31
|
+
name = (rb_export_##name##_type) rb_import_symbol(module, #name)
|
32
|
+
|
33
|
+
|
34
|
+
/* These three macro enable a simple use of function declaration: this way,
|
35
|
+
you can type in a header file that is used by the importer:
|
36
|
+
|
37
|
+
DECLARE_SYMBOL(int, biniou, (int, int));
|
38
|
+
|
39
|
+
in one file of the importer code, you write
|
40
|
+
|
41
|
+
IMPLEMENT_SYMBOL(biniou);
|
42
|
+
|
43
|
+
and in the Init_... function, you write:
|
44
|
+
|
45
|
+
RB_IMPORT_SYMBOL(module, biniou);
|
46
|
+
|
47
|
+
and you can just use biniou as if it was a function declared as
|
48
|
+
usual in the header file
|
49
|
+
*/
|
50
|
+
#endif
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,380 @@
|
|
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_text_scale_set(FM *p, double scale)
|
31
|
+
{
|
32
|
+
double factor = scale / p->default_text_scale;
|
33
|
+
if (factor <= 0) rb_raise(rb_eArgError, "Sorry: text scaling must be positive");
|
34
|
+
p->default_text_height_dx *= factor;
|
35
|
+
p->default_text_height_dy *= factor;
|
36
|
+
p->default_text_scale = scale;
|
37
|
+
}
|
38
|
+
|
39
|
+
VALUE FM_rescale_text(VALUE fmkr, VALUE scaling_factor) // updates default text heights too
|
40
|
+
{
|
41
|
+
FM *p = Get_FM(fmkr);
|
42
|
+
scaling_factor = rb_Float(scaling_factor);
|
43
|
+
c_text_scale_set(p, NUM2DBL(scaling_factor) * p->default_text_scale);
|
44
|
+
return fmkr;
|
45
|
+
}
|
46
|
+
|
47
|
+
int String_Is_Blank(char *str) {
|
48
|
+
char c;
|
49
|
+
if (str == NULL) return 1;
|
50
|
+
while (1) {
|
51
|
+
c = *str++;
|
52
|
+
if (c == '\0') return 1;
|
53
|
+
if (!isspace(c)) break;
|
54
|
+
}
|
55
|
+
return 0;
|
56
|
+
}
|
57
|
+
|
58
|
+
void tex_show_rotated_text(FM *p, char *text, double x, double y, double scale, double angle, int justification, int alignment)
|
59
|
+
{ // x and y are the device coords for the reference point of the text
|
60
|
+
char ref, jst;
|
61
|
+
double ft_ht, sz;
|
62
|
+
if (String_Is_Blank(text)) return; /* blank strings break TeX! */
|
63
|
+
scale *= p->default_text_scale;
|
64
|
+
ft_ht = scale * p->default_font_size;
|
65
|
+
sz = ft_ht * ENLARGE;
|
66
|
+
ref = (alignment == ALIGNED_AT_BASELINE)? 'B' :
|
67
|
+
(alignment == ALIGNED_AT_BOTTOM)? 'b' :
|
68
|
+
(alignment == ALIGNED_AT_TOP)? 't' : 'c';
|
69
|
+
if (justification == 0) jst = 'c';
|
70
|
+
else if (justification > 0) jst = 'r';
|
71
|
+
else jst = 'l';
|
72
|
+
bbox_llx = MIN(bbox_llx, x - sz);
|
73
|
+
bbox_lly = MIN(bbox_lly, y - sz);
|
74
|
+
bbox_urx = MAX(bbox_urx, x + sz);
|
75
|
+
bbox_ury = MAX(bbox_ury, y + sz);
|
76
|
+
if (angle != 0.0)
|
77
|
+
fprintf(fp,"\\put(%d,%d){\\rotatebox{%.1f}{\\scalebox{%.2f}{\\makebox(0,0)[%c%c]{\\tiogasetfont",
|
78
|
+
ROUND(x), ROUND(y), angle, scale, jst, ref);
|
79
|
+
else
|
80
|
+
fprintf(fp,"\\put(%d,%d){\\scalebox{%.2f}{\\makebox(0,0)[%c%c]{\\tiogasetfont",
|
81
|
+
ROUND(x), ROUND(y), scale, jst, ref);
|
82
|
+
fprintf(fp, (alignment == ALIGNED_AT_BASELINE)? "{%s\\BS" : "{%s", text);
|
83
|
+
fprintf(fp, angle != 0? "}}}}}\n" : "}}}}\n");
|
84
|
+
}
|
85
|
+
|
86
|
+
static void Convert_Frame_Text_Position_To_Output_Location(FM *p, int frame_side, double offset,
|
87
|
+
double fraction, double *xp, double *yp, double *base_angle, char *text)
|
88
|
+
{
|
89
|
+
double page_x, page_y;
|
90
|
+
switch (frame_side) {
|
91
|
+
case LEFT:
|
92
|
+
page_x = p->page_width * p->frame_left - offset;
|
93
|
+
page_y = p->page_height * (p->frame_bottom + fraction * p->frame_height);
|
94
|
+
*base_angle = 90;
|
95
|
+
break;
|
96
|
+
case RIGHT:
|
97
|
+
page_x = p->page_width * p->frame_right + offset;
|
98
|
+
page_y = p->page_height * (p->frame_bottom + fraction * p->frame_height);
|
99
|
+
*base_angle = 90;
|
100
|
+
break;
|
101
|
+
case AT_X_ORIGIN:
|
102
|
+
if (0.0 > p->bounds_xmax || 0.0 < p->bounds_xmin)
|
103
|
+
rb_raise(rb_eArgError, "Sorry: x origin is not part of plot for (%s)", text);
|
104
|
+
page_x = convert_figure_to_output_x(p, 0.0);
|
105
|
+
if (p->xaxis_reversed) offset = -offset;
|
106
|
+
page_x += offset;
|
107
|
+
page_y = p->page_height * (p->frame_bottom + fraction * p->frame_height);
|
108
|
+
*base_angle = 90;
|
109
|
+
break;
|
110
|
+
case TOP:
|
111
|
+
page_y = p->page_height * p->frame_top + offset;
|
112
|
+
page_x = p->page_width * (p->frame_left + fraction * p->frame_width);
|
113
|
+
*base_angle = 0;
|
114
|
+
break;
|
115
|
+
case BOTTOM:
|
116
|
+
page_y = p->page_height * p->frame_bottom - offset;
|
117
|
+
page_x = p->page_width * (p->frame_left + fraction * p->frame_width);
|
118
|
+
*base_angle = 0;
|
119
|
+
break;
|
120
|
+
case AT_Y_ORIGIN:
|
121
|
+
if (0.0 > p->bounds_ymax || 0.0 < p->bounds_ymin)
|
122
|
+
rb_raise(rb_eArgError, "Sorry: y origin is not part of plot for (%s)", text);
|
123
|
+
page_y = convert_figure_to_output_y(p, 0.0);
|
124
|
+
if (p->yaxis_reversed) offset = -offset;
|
125
|
+
page_y += offset;
|
126
|
+
page_x = p->page_width * (p->frame_left + fraction * p->frame_width);
|
127
|
+
*base_angle = 0;
|
128
|
+
break;
|
129
|
+
default: rb_raise(rb_eArgError, "Sorry: invalid parameter for frame side in show text (%s)", text);
|
130
|
+
}
|
131
|
+
*xp = p->page_left + page_x; *yp = p->page_bottom + page_y;
|
132
|
+
}
|
133
|
+
|
134
|
+
void c_show_rotated_text(FM *p, char *text, int frame_side, double shift, double fraction,
|
135
|
+
double scale, double angle, int justification, int alignment)
|
136
|
+
{
|
137
|
+
double x, y, base_angle, ft_ht = p->default_text_scale * scale * p->default_font_size;
|
138
|
+
Convert_Frame_Text_Position_To_Output_Location(p, frame_side, shift*ft_ht*ENLARGE, fraction, &x, &y, &base_angle, text);
|
139
|
+
tex_show_rotated_text(p, text, x, y, scale, angle + base_angle, justification, alignment);
|
140
|
+
}
|
141
|
+
|
142
|
+
VALUE FM_show_rotated_text(VALUE fmkr, VALUE text, VALUE frame_side, VALUE shift,
|
143
|
+
VALUE fraction, VALUE scale, VALUE angle, VALUE justification, VALUE alignment)
|
144
|
+
{
|
145
|
+
FM *p = Get_FM(fmkr);
|
146
|
+
text = rb_String(text);
|
147
|
+
frame_side = rb_Integer(frame_side);
|
148
|
+
shift = rb_Float(shift);
|
149
|
+
fraction = rb_Float(fraction);
|
150
|
+
scale = rb_Float(scale);
|
151
|
+
angle = rb_Float(angle);
|
152
|
+
justification = rb_Integer(justification);
|
153
|
+
alignment = rb_Integer(alignment);
|
154
|
+
c_show_rotated_text(p, RSTRING(text)->ptr, NUM2INT(frame_side), NUM2DBL(shift),
|
155
|
+
NUM2DBL(fraction), NUM2DBL(scale), NUM2DBL(angle), NUM2INT(justification), NUM2INT(alignment));
|
156
|
+
return fmkr;
|
157
|
+
}
|
158
|
+
|
159
|
+
void c_show_rotated_label(FM *p, char *text,
|
160
|
+
double xloc, double yloc, double scale, double angle, int justification, int alignment)
|
161
|
+
{
|
162
|
+
tex_show_rotated_text(p, text, convert_figure_to_output_x(p, xloc), convert_figure_to_output_y(p, yloc),
|
163
|
+
scale, angle, justification, alignment);
|
164
|
+
}
|
165
|
+
|
166
|
+
VALUE FM_show_rotated_label(VALUE fmkr, VALUE text,
|
167
|
+
VALUE xloc, VALUE yloc, VALUE scale, VALUE angle, VALUE justification, VALUE alignment)
|
168
|
+
{
|
169
|
+
FM *p = Get_FM(fmkr);
|
170
|
+
text = rb_String(text);
|
171
|
+
xloc = rb_Float(xloc);
|
172
|
+
yloc = rb_Float(yloc);
|
173
|
+
scale = rb_Float(scale);
|
174
|
+
angle = rb_Float(angle);
|
175
|
+
justification = rb_Integer(justification);
|
176
|
+
alignment = rb_Integer(alignment);
|
177
|
+
c_show_rotated_label(p, RSTRING(text)->ptr, NUM2DBL(xloc), NUM2DBL(yloc),
|
178
|
+
NUM2DBL(scale), NUM2DBL(angle), NUM2INT(justification), NUM2INT(alignment));
|
179
|
+
return fmkr;
|
180
|
+
}
|
181
|
+
|
182
|
+
VALUE FM_check_label_clip(VALUE fmkr, VALUE xloc, VALUE yloc)
|
183
|
+
{
|
184
|
+
FM *p = Get_FM(fmkr);
|
185
|
+
xloc = rb_Float(xloc);
|
186
|
+
yloc = rb_Float(yloc);
|
187
|
+
double x = NUM2DBL(xloc), y = NUM2DBL(yloc);
|
188
|
+
x = convert_figure_to_frame_x(p,x);
|
189
|
+
y = convert_figure_to_frame_y(p,y);
|
190
|
+
if (x < p->label_left_margin || y < p->label_bottom_margin ||
|
191
|
+
1.0 - x < p->label_right_margin || 1.0 - y < p->label_top_margin) return Qfalse;
|
192
|
+
return Qtrue;
|
193
|
+
}
|
194
|
+
|
195
|
+
/* TeX File Management */
|
196
|
+
|
197
|
+
static long cur_pos;
|
198
|
+
|
199
|
+
static void Get_tex_name(char *ofile, char *filename, int maxlen)
|
200
|
+
{
|
201
|
+
char *dot;
|
202
|
+
strncpy(ofile, filename, maxlen);
|
203
|
+
dot = strrchr(ofile,'.');
|
204
|
+
if (dot != NULL) dot[0] = '\0';
|
205
|
+
strcat(ofile, "_figure.txt");
|
206
|
+
}
|
207
|
+
|
208
|
+
void Open_tex(VALUE fmkr, char *filename, bool quiet_mode)
|
209
|
+
{
|
210
|
+
char ofile[300];
|
211
|
+
Get_tex_name(ofile, filename, 300);
|
212
|
+
fp = fopen(ofile, "w");
|
213
|
+
fprintf(fp,"\\setlength{\\unitlength}{%fbp}%%\n", 1.0/ENLARGE);
|
214
|
+
cur_pos = ftell(fp);
|
215
|
+
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 */
|
216
|
+
fprintf(fp,"\\def\\BS{\\phantom{\\Huge\\scalebox{0}[2]{\\hbox{\\rotatebox{180}{O}O}}}}\n");
|
217
|
+
// graphicx seems to vertically align baseline (B) like center (c),
|
218
|
+
// so we add BS (Big Strut) to make them look the same
|
219
|
+
fmkr = Qnil; // unused
|
220
|
+
}
|
221
|
+
|
222
|
+
void Close_tex(VALUE fmkr, bool quiet_mode)
|
223
|
+
{
|
224
|
+
double x, y, xoff, yoff;
|
225
|
+
x = bbox_urx - bbox_llx; if (x < 0) x = bbox_urx = bbox_llx = 0;
|
226
|
+
y = bbox_ury - bbox_lly; if (y < 0) y = bbox_ury = bbox_lly = 0;
|
227
|
+
xoff = bbox_llx + Get_tex_xoffset(fmkr)*ENLARGE;
|
228
|
+
yoff = bbox_lly + Get_tex_yoffset(fmkr)*ENLARGE;
|
229
|
+
fprintf(fp,"\\end{picture}");
|
230
|
+
fseek(fp, cur_pos, SEEK_SET);
|
231
|
+
fprintf(fp,"\\begin{picture}(%03d,%03d)(%02d,%d)", ROUND(x), ROUND(y), ROUND(xoff), ROUND(yoff));
|
232
|
+
fclose(fp);
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
void Write_preview_header(VALUE fmkr, FILE *file) {
|
237
|
+
VALUE tmp;
|
238
|
+
fprintf(file, "\\documentclass{%s}\n\n", Get_tex_preview_documentclass(fmkr));
|
239
|
+
/* we print out the preamble generated from tioga.sty.in */
|
240
|
+
fprintf(file, "%% Tioga preamble generated from tioga.sty.in\n");
|
241
|
+
fprintf(file, "%s\n", Get_tex_preview_generated_preamble(fmkr));
|
242
|
+
fprintf(file, "%% User-specified preamble\n");
|
243
|
+
fprintf(file, "%s\n\n", Get_tex_preamble(fmkr));
|
244
|
+
fprintf(file, "%% Command to format numeric labels on xaxis\n");
|
245
|
+
fprintf(file, "\\newcommand{\\tiogaxaxisnumericlabel}[1]{%s}\n\n", Get_xaxis_numeric_label_tex(fmkr));
|
246
|
+
fprintf(file, "%% Command to format numeric labels on yaxis\n");
|
247
|
+
fprintf(file, "\\newcommand{\\tiogayaxisnumericlabel}[1]{%s}\n\n", Get_yaxis_numeric_label_tex(fmkr));
|
248
|
+
fprintf(file, "%% Color constants definitions\n");
|
249
|
+
tmp = rb_const_get(CLASS_OF(fmkr), rb_intern("COLOR_PREAMBLE"));
|
250
|
+
fprintf(file, "%s\n\n", StringValueCStr(tmp));
|
251
|
+
fprintf(file, "%% Set page margins, page size and orientation.\n");
|
252
|
+
fprintf(file, "\t\\usepackage[pdftex,tmargin=0pt,lmargin=0pt,"
|
253
|
+
"rmargin=0pt,bmargin=0pt,\n");
|
254
|
+
fprintf(file, "\tpaperwidth=%s,paperheight=%s,\n",
|
255
|
+
Get_tex_preview_paper_width(fmkr),
|
256
|
+
Get_tex_preview_paper_height(fmkr));
|
257
|
+
fprintf(file, "\thoffset=%s,voffset=%s\n",
|
258
|
+
Get_tex_preview_hoffset(fmkr),
|
259
|
+
Get_tex_preview_voffset(fmkr));
|
260
|
+
fprintf(file, "\t]{geometry}\n");
|
261
|
+
|
262
|
+
fprintf(file, "\n%% We need the graphicx package and the calc package.\n");
|
263
|
+
fprintf(file, "\t\\usepackage{graphicx}\n");
|
264
|
+
fprintf(file, "\t\\usepackage{calc}\n\n");
|
265
|
+
fprintf(file, "\t%% This is necessary to avoid getting the picture on the second page\n");
|
266
|
+
fprintf(file, "\t\\topskip=0pt\n\n");
|
267
|
+
|
268
|
+
/* now, the commands to customize the font used */
|
269
|
+
fprintf(file, "\\settiogafontsize[10pt]{%s}\n", Get_tex_fontsize(fmkr));
|
270
|
+
fprintf(file, "\\settiogafontfamily{\\%s}\n", Get_tex_fontfamily(fmkr));
|
271
|
+
fprintf(file, "\\settiogafontseries{\\%s}\n", Get_tex_fontseries(fmkr));
|
272
|
+
fprintf(file, "\\settiogafontshape{\\%s}\n", Get_tex_fontshape(fmkr));
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
void Write_figure_command(VALUE fmkr, char *simple_name, FILE *file) {
|
277
|
+
char *minwhitespace;
|
278
|
+
|
279
|
+
if (Get_tex_preview_fullpage(fmkr)) {
|
280
|
+
minwhitespace = Get_tex_preview_minwhitespace(fmkr);
|
281
|
+
if (minwhitespace == NULL) {
|
282
|
+
fprintf(file, "\\tiogafigurefullpage{%s}\n", simple_name);
|
283
|
+
} else {
|
284
|
+
fprintf(file, "\\tiogafigurefullpage[%s]{%s}\n", minwhitespace, simple_name);
|
285
|
+
}
|
286
|
+
} else {
|
287
|
+
const char * command = Get_tex_preview_tiogafigure_command(fmkr);
|
288
|
+
if(strcmp(command, "tiogafigureshow")) {
|
289
|
+
fprintf(file, "\\%s{%s}{%s}{%s}\n", Get_tex_preview_tiogafigure_command(fmkr), simple_name,
|
290
|
+
Get_tex_preview_figure_width(fmkr), Get_tex_preview_figure_height(fmkr));
|
291
|
+
} else { /* no need for extra arguments for tiogafigureshow */
|
292
|
+
fprintf(file, "\\%s{%s}\n", Get_tex_preview_tiogafigure_command(fmkr), simple_name);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
void Create_wrapper(VALUE fmkr, char *fname, bool quiet_mode)
|
299
|
+
{ // create the wrapper TeX file to combine the text and graphics to make a figure
|
300
|
+
char *dot;
|
301
|
+
char tex_fname[100], base_name[100], simple_name[100];
|
302
|
+
FILE *file;
|
303
|
+
if ((dot=strrchr(fname,'.')) != NULL) {
|
304
|
+
strncpy(base_name, fname, dot-fname); base_name[dot-fname] = '\0';
|
305
|
+
sprintf(tex_fname, "%s.tex", base_name);
|
306
|
+
}
|
307
|
+
else {
|
308
|
+
strcpy(base_name, fname);
|
309
|
+
sprintf(tex_fname, "%s.tex", fname);
|
310
|
+
}
|
311
|
+
if ((dot=strrchr(base_name,'/')) != NULL) {
|
312
|
+
strcpy(simple_name, dot+1);
|
313
|
+
}
|
314
|
+
else {
|
315
|
+
strcpy(simple_name, base_name);
|
316
|
+
}
|
317
|
+
file = fopen(tex_fname, "w");
|
318
|
+
fprintf(file, "%% Tioga preview LaTeX file for %s_figure.pdf and %s_figure.txt\n\n", base_name, base_name);
|
319
|
+
|
320
|
+
Write_preview_header(fmkr, file);
|
321
|
+
|
322
|
+
fprintf(file, "\n%% Here's the page with the figure.\n");
|
323
|
+
fprintf(file, "\\begin{document}\n");
|
324
|
+
fprintf(file, "\\pagestyle{%s}\n", Get_tex_preview_pagestyle(fmkr));
|
325
|
+
/* necessary to get the position right */
|
326
|
+
fprintf(file, "\\noindent");
|
327
|
+
Write_figure_command(fmkr, simple_name, file);
|
328
|
+
fprintf(file, "\\end{document}\n");
|
329
|
+
fclose(file);
|
330
|
+
}
|
331
|
+
|
332
|
+
void Init_tex(void)
|
333
|
+
{
|
334
|
+
}
|
335
|
+
|
336
|
+
void Rename_tex(char *oldname, char *newname)
|
337
|
+
{
|
338
|
+
char old_ofile[300], new_ofile[300];
|
339
|
+
Get_tex_name(old_ofile, oldname, 300);
|
340
|
+
Get_tex_name(new_ofile, newname, 300);
|
341
|
+
rename(old_ofile, new_ofile); // from stdio.h
|
342
|
+
}
|
343
|
+
|
344
|
+
void private_make_portfolio(char *name, VALUE fignums, VALUE fignames)
|
345
|
+
{
|
346
|
+
FILE *file;
|
347
|
+
int i, len, numfigs, j;
|
348
|
+
char tex_fname[256];
|
349
|
+
sprintf(tex_fname, "%s.tex", name);
|
350
|
+
file = fopen(tex_fname, "w");
|
351
|
+
if (file == NULL)
|
352
|
+
rb_raise(rb_eArgError, "Sorry: can't open %s.\n", tex_fname);
|
353
|
+
fprintf(file, "%% Tioga Portfolio %s\n\n", name);
|
354
|
+
fprintf(file, "\\documentclass{article}\n");
|
355
|
+
fprintf(file, "\\usepackage{pdfpages}\n");
|
356
|
+
fprintf(file, "\\begin{document}\n");
|
357
|
+
fprintf(file, "%% Start of figures, one per page\n\n");
|
358
|
+
fignames = rb_Array(fignames);
|
359
|
+
len = RARRAY(fignames)->len;
|
360
|
+
if (fignums == Qnil) {
|
361
|
+
for (i=0; i < len; i++) {
|
362
|
+
fprintf(file, "\\includepdf{%s.pdf}\n", Get_String(fignames, i));
|
363
|
+
}
|
364
|
+
} else {
|
365
|
+
fignums = rb_Array(fignums);
|
366
|
+
numfigs = RARRAY(fignums)->len;
|
367
|
+
for (i=0; i < numfigs; i++) {
|
368
|
+
j = NUM2INT(RARRAY(fignums)->ptr[i]);
|
369
|
+
if (j >= 0 && j < len) fprintf(file, "\\includepdf{%s.pdf}\n", Get_String(fignames, j));
|
370
|
+
else {
|
371
|
+
fclose(file);
|
372
|
+
rb_raise(rb_eArgError, "Requested figure numbers must be >= 0 and < num_figures.");
|
373
|
+
}
|
374
|
+
}
|
375
|
+
}
|
376
|
+
fprintf(file, "\n\\end{document}\n");
|
377
|
+
fclose(file);
|
378
|
+
}
|
379
|
+
|
380
|
+
|