summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-12-06 23:21:18 +0100
committerGuillaume Seguin <guillaume@segu.in>2007-12-06 23:21:18 +0100
commit95149d31a987d79d6e2dd06a4fdcd6f310d36a84 (patch)
tree3bacd4c13fe872af20b587feda59efdf8e7ea8e7
parentd5a3ad3fa9ea4254d20484ab7187bdcb02477f52 (diff)
downloadgmathlib-95149d31a987d79d6e2dd06a4fdcd6f310d36a84.tar.gz
gmathlib-95149d31a987d79d6e2dd06a4fdcd6f310d36a84.tar.bz2
* Add support for integral symbols in Cairo renderer
-rw-r--r--cairo/gmathcairo_renderers.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/cairo/gmathcairo_renderers.c b/cairo/gmathcairo_renderers.c
index a4da1ae..9c262f6 100644
--- a/cairo/gmathcairo_renderers.c
+++ b/cairo/gmathcairo_renderers.c
@@ -1003,6 +1003,141 @@ render_product (GMathCairoContext *ccontext, GMathSymbol *symbol, float size)
return boxed;
}
+/* Render an integral symbol */
+GMathBoxed*
+render_integral (GMathCairoContext *ccontext, GMathSymbol *symbol, float size)
+{
+ GMathBoxed *boxed;
+ cairo_surface_t *surface;
+ GMathBoxed **children;
+ cairo_surface_t *main_surf;
+ cairo_t *cr;
+ int width, height, width0, height0, width1;
+ int dwr, dhr, dwt, dht, dwb, dhb;
+ int x, y, x0, y0;
+ float size_small = size * 0.5;
+
+ if (!symbol || !symbol->children[2])
+ return NULL;
+
+ children = g_new0 (GMathBoxed*, 3);
+
+ dwr = dwt = dwb = 0;
+ dhr = dht = dhb = 0;
+
+ children[2] = gmathcairo_render_symbol (ccontext, symbol->children[2],
+ size);
+ if (!children[2])
+ {
+ g_free (children);
+ return NULL;
+ }
+ width = dwr = children[2]->box.width;
+ height = dhr = children[2]->box.height;
+
+ height0 = height;
+ width0 = height0 * 0.6;
+ main_surf = draw_integral (width0, height0);
+
+ width += width0;
+ width1 = width0;
+
+ if (symbol->children[1])
+ {
+ children[1] = gmathcairo_render_symbol (ccontext, symbol->children[1],
+ size_small);
+ if (ccontext->editor_mode && !children[1])
+ children[1] = gmathcairo_render_empty (ccontext,
+ symbol->children[1],
+ size_small);
+ if (children[1])
+ {
+ dwt = children[1]->box.width;
+ dht = children[1]->box.height;
+ width += dwt;
+ width1 += dwt;
+ }
+ }
+ if (symbol->children[0])
+ {
+ children[0] = gmathcairo_render_symbol (ccontext, symbol->children[0],
+ size_small);
+ if (ccontext->editor_mode && !children[0])
+ children[0] = gmathcairo_render_empty (ccontext,
+ symbol->children[0],
+ size_small);
+ if (children[0])
+ {
+ dwb = children[0]->box.width;
+ dhb = children[0]->box.height;
+ if (dwb > dwt + 0.6 * width0)
+ {
+ width += dwb - dwt - 0.6 * width0;
+ width1 += dwb - dwt - 0.6 * width0;
+ }
+ }
+ }
+
+ x0 = 0;
+ y0 = 0;
+
+ boxed = gmathboxed_new (symbol);
+ gmathboxed_resize (boxed, width, height);
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ boxed->surface = surface;
+ cr = cairo_create (surface);
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ cairo_save (cr);
+ cairo_set_source_surface (cr, main_surf, x0, y0);
+ cairo_paint (cr);
+ cairo_restore (cr);
+ cairo_surface_destroy (main_surf);
+
+ if (children[2])
+ {
+ x = width1;
+ y = y0 + (height - dhr) / 2;
+ gmathboxed_add_child (boxed, children[2], x, y);
+ cairo_save (cr);
+ cairo_set_source_surface (cr, children[2]->surface, x, y);
+ cairo_paint (cr);
+ cairo_restore (cr);
+ gmathboxed_destroy_surface (children[2]);
+ }
+
+ if (children[1])
+ {
+ x = x0 + width0;
+ y = 0;
+ gmathboxed_add_child (boxed, children[1], x, y);
+ cairo_save (cr);
+ cairo_set_source_surface (cr, children[1]->surface, x, y);
+ cairo_paint (cr);
+ cairo_restore (cr);
+ gmathboxed_destroy_surface (children[1]);
+ }
+
+ if (children[0])
+ {
+ x = x0 + width0 * 0.6;
+ y = height - dhb;
+ gmathboxed_add_child (boxed, children[0], x, y);
+ cairo_save (cr);
+ cairo_set_source_surface (cr, children[0]->surface, x, y);
+ cairo_paint (cr);
+ cairo_restore (cr);
+ gmathboxed_destroy_surface (children[0]);
+ }
+
+ /* Free things */
+ cairo_destroy (cr);
+ g_free (children);
+
+ return boxed;
+}
+
/* Register renderers */
void
gmathcairo_register_renderers (GMathCairoContext *ccontext)
@@ -1026,6 +1161,7 @@ gmathcairo_register_renderers (GMathCairoContext *ccontext)
gmathcairocontext_register_renderer (ccontext, "super", render_super);
gmathcairocontext_register_renderer (ccontext, "sum", render_sum);
gmathcairocontext_register_renderer (ccontext, "product", render_product);
+ gmathcairocontext_register_renderer (ccontext, "integral", render_integral);
/* Special chars */
gmathcairocontext_register_renderer (ccontext, "alpha", render_char);