58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'ext/mathematical/mathematical.c', line 58
static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_LatexCode, VALUE rb_TempFile) {
Check_Type (rb_LatexCode, T_STRING);
Check_Type (rb_TempFile, T_STRING);
const char *latex_code = StringValueCStr(rb_LatexCode);
int latex_size = strlen(latex_code);
const char *tempfile = StringValueCStr(rb_TempFile);
// convert the TeX math to MathML
char * mathml = itex2MML_parse(latex_code, latex_size);
if (mathml == 0) rb_raise(rb_eRuntimeError, "Failed to parse itex");
int mathml_size = strlen(mathml);
LsmDomDocument *document;
document = lsm_dom_document_new_from_memory(mathml, mathml_size, NULL);
g_free (mathml);
if (document == NULL) rb_raise(rb_eRuntimeError, "Failed to create document");
LsmDomView *view;
double ppi = NUM2DBL(rb_iv_get(self, "@ppi"));
double zoom = NUM2DBL(rb_iv_get(self, "@zoom"));
view = lsm_dom_document_create_view (document);
lsm_dom_view_set_resolution (view, ppi);
double width_pt = 2.0, height_pt = 2.0;
unsigned int height, width;
lsm_dom_view_get_size (view, &width_pt, &height_pt, NULL);
lsm_dom_view_get_size_pixels (view, &width, &height, NULL);
width_pt *= zoom;
height_pt *= zoom;
width *= zoom;
height *= zoom;
cairo_t *cairo;
cairo_surface_t *surface;
surface = cairo_svg_surface_create (tempfile, width_pt, height_pt);
cairo = cairo_create (surface);
cairo_surface_destroy (surface);
cairo_scale (cairo, zoom, zoom);
lsm_dom_view_render (view, cairo, 0, 0);
cairo_destroy (cairo);
g_object_unref (view);
g_object_unref (document);
return 0;
}
|