Code

Rounding errors in feComposite: patch by Preben S (bug 318134)
[inkscape.git] / src / display / nr-arena-glyphs.cpp
1 #define __NR_ARENA_GLYPHS_C__
3 /*
4  * RGBA display list system for inkscape
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 2002 Lauris Kaplinski
10  *
11  * Released under GNU GPL
12  *
13  */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
19 #include <libnr/nr-blit.h>
20 #include <libnr/nr-convert2geom.h>
21 #include <2geom/matrix.h>
22 #include "../style.h"
23 #include "nr-arena.h"
24 #include "nr-arena-glyphs.h"
25 #include <cairo.h>
26 #include "inkscape-cairo.h"
28 #ifdef test_glyph_liv
29 #include "../display/canvas-bpath.h"
30 #include <libnrtype/font-instance.h>
31 #include <libnrtype/raster-glyph.h>
32 #include <libnrtype/RasterFont.h>
34 // defined in nr-arena-shape.cpp
35 void nr_pixblock_render_shape_mask_or(NRPixBlock &m, Shape *theS);
36 #endif
38 #ifdef ENABLE_SVG_FONTS
39 #include "nr-svgfonts.h"
40 #endif //#ifdef ENABLE_SVG_FONTS
42 static void nr_arena_glyphs_class_init(NRArenaGlyphsClass *klass);
43 static void nr_arena_glyphs_init(NRArenaGlyphs *glyphs);
44 static void nr_arena_glyphs_finalize(NRObject *object);
46 static guint nr_arena_glyphs_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
47 static guint nr_arena_glyphs_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
48 static NRArenaItem *nr_arena_glyphs_pick(NRArenaItem *item, Geom::Point p, double delta, unsigned int sticky);
50 static NRArenaItemClass *glyphs_parent_class;
52 NRType
53 nr_arena_glyphs_get_type(void)
54 {
55     static NRType type = 0;
56     if (!type) {
57         type = nr_object_register_type(NR_TYPE_ARENA_ITEM,
58                                        "NRArenaGlyphs",
59                                        sizeof(NRArenaGlyphsClass),
60                                        sizeof(NRArenaGlyphs),
61                                        (void (*)(NRObjectClass *)) nr_arena_glyphs_class_init,
62                                        (void (*)(NRObject *)) nr_arena_glyphs_init);
63     }
64     return type;
65 }
67 static void
68 nr_arena_glyphs_class_init(NRArenaGlyphsClass *klass)
69 {
70     NRObjectClass *object_class;
71     NRArenaItemClass *item_class;
73     object_class = (NRObjectClass *) klass;
74     item_class = (NRArenaItemClass *) klass;
76     glyphs_parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent;
78     object_class->finalize = nr_arena_glyphs_finalize;
79     object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaGlyphs>;
81     item_class->update = nr_arena_glyphs_update;
82     item_class->clip = nr_arena_glyphs_clip;
83     item_class->pick = nr_arena_glyphs_pick;
84 }
86 static void
87 nr_arena_glyphs_init(NRArenaGlyphs *glyphs)
88 {
89     glyphs->style = NULL;
90     glyphs->g_transform.setIdentity();
91     glyphs->font = NULL;
92     glyphs->glyph = 0;
94     glyphs->rfont = NULL;
95     glyphs->sfont = NULL;
96     glyphs->x = glyphs->y = 0.0;
97 }
99 static void
100 nr_arena_glyphs_finalize(NRObject *object)
102     NRArenaGlyphs *glyphs = static_cast<NRArenaGlyphs *>(object);
104     if (glyphs->rfont) {
105         glyphs->rfont->Unref();
106         glyphs->rfont=NULL;
107     }
108     if (glyphs->sfont) {
109         glyphs->sfont->Unref();
110         glyphs->sfont=NULL;
111     }
113     if (glyphs->font) {
114         glyphs->font->Unref();
115         glyphs->font=NULL;
116     }
118     if (glyphs->style) {
119         sp_style_unref(glyphs->style);
120         glyphs->style = NULL;
121     }
123     ((NRObjectClass *) glyphs_parent_class)->finalize(object);
126 static guint
127 nr_arena_glyphs_update(NRArenaItem *item, NRRectL */*area*/, NRGC *gc, guint /*state*/, guint /*reset*/)
129     NRArenaGlyphs *glyphs;
130     raster_font *rfont;
132     glyphs = NR_ARENA_GLYPHS(item);
134     if (!glyphs->font || !glyphs->style)
135         return NR_ARENA_ITEM_STATE_ALL;
136     if ((glyphs->style->fill.isNone()) && (glyphs->style->stroke.isNone()))
137         return NR_ARENA_ITEM_STATE_ALL;
139     NRRect bbox;
140     bbox.x0 = bbox.y0 = NR_HUGE;
141     bbox.x1 = bbox.y1 = -NR_HUGE;
143     float const scale = gc->transform.descrim();
145     if (!glyphs->style->fill.isNone()) {
146         Geom::Matrix t;
147         t = glyphs->g_transform * gc->transform;
148         glyphs->x = t[4];
149         glyphs->y = t[5];
150         t[4]=0;
151         t[5]=0;
152         rfont = glyphs->font->RasterFont(t, 0);
153         if (glyphs->rfont) glyphs->rfont->Unref();
154         glyphs->rfont = rfont;
156         if (glyphs->style->stroke.isNone() || fabs(glyphs->style->stroke_width.computed * scale) <= 0.01) { // Optimization: do fill bbox only if there's no stroke
157             NRRect narea;
158             if ( glyphs->rfont ) glyphs->rfont->BBox(glyphs->glyph, &narea);
159             bbox.x0 = narea.x0 + glyphs->x;
160             bbox.y0 = narea.y0 + glyphs->y;
161             bbox.x1 = narea.x1 + glyphs->x;
162             bbox.y1 = narea.y1 + glyphs->y;
163         }
164     }
166     if (!glyphs->style->stroke.isNone()) {
167         /* Build state data */
168         Geom::Matrix t;
169         t = glyphs->g_transform * gc->transform;
170         glyphs->x = t[4];
171         glyphs->y = t[5];
172         t[4]=0;
173         t[5]=0;
175         if ( fabs(glyphs->style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
176             font_style nstyl;
177             nstyl.transform = t;
178             nstyl.stroke_width=MAX(0.125, glyphs->style->stroke_width.computed * scale);
179             if ( glyphs->style->stroke_linecap.computed == SP_STROKE_LINECAP_BUTT ) nstyl.stroke_cap=butt_straight;
180             if ( glyphs->style->stroke_linecap.computed == SP_STROKE_LINECAP_ROUND ) nstyl.stroke_cap=butt_round;
181             if ( glyphs->style->stroke_linecap.computed == SP_STROKE_LINECAP_SQUARE ) nstyl.stroke_cap=butt_square;
182             if ( glyphs->style->stroke_linejoin.computed == SP_STROKE_LINEJOIN_MITER ) nstyl.stroke_join=join_pointy;
183             if ( glyphs->style->stroke_linejoin.computed == SP_STROKE_LINEJOIN_ROUND ) nstyl.stroke_join=join_round;
184             if ( glyphs->style->stroke_linejoin.computed == SP_STROKE_LINEJOIN_BEVEL ) nstyl.stroke_join=join_straight;
185             nstyl.stroke_miter_limit = glyphs->style->stroke_miterlimit.value;
186             nstyl.nbDash=0;
187             nstyl.dash_offset = 0;
188             nstyl.dashes=NULL;
189             if ( glyphs->style->stroke_dash.n_dash > 0 ) {
190                 nstyl.dash_offset = glyphs->style->stroke_dash.offset * scale;
191                 nstyl.nbDash=glyphs->style->stroke_dash.n_dash;
192                 nstyl.dashes=(double*)malloc(nstyl.nbDash*sizeof(double));
193                 for (int i = 0; i < nstyl.nbDash; i++) nstyl.dashes[i]= glyphs->style->stroke_dash.dash[i] * scale;
194             }
195             rfont = glyphs->font->RasterFont( nstyl);
196             if ( nstyl.dashes ) free(nstyl.dashes);
197             if (glyphs->sfont) glyphs->sfont->Unref();
198             glyphs->sfont = rfont;
200             NRRect narea;
201             if ( glyphs->sfont ) glyphs->sfont->BBox(glyphs->glyph, &narea);
202             narea.x0-=nstyl.stroke_width;
203             narea.y0-=nstyl.stroke_width;
204             narea.x1+=nstyl.stroke_width;
205             narea.y1+=nstyl.stroke_width;
206             bbox.x0 = narea.x0 + glyphs->x;
207             bbox.y0 = narea.y0 + glyphs->y;
208             bbox.x1 = narea.x1 + glyphs->x;
209             bbox.y1 = narea.y1 + glyphs->y;
210         }
211     }
212     if (nr_rect_d_test_empty(bbox)) return NR_ARENA_ITEM_STATE_ALL;
214     item->bbox.x0 = (gint32)(bbox.x0 - 1.0);
215     item->bbox.y0 = (gint32)(bbox.y0 - 1.0);
216     item->bbox.x1 = (gint32)(bbox.x1 + 1.0);
217     item->bbox.y1 = (gint32)(bbox.y1 + 1.0);
218     nr_arena_request_render_rect(item->arena, &item->bbox);
220     return NR_ARENA_ITEM_STATE_ALL;
223 static guint
224 nr_arena_glyphs_clip(NRArenaItem *item, NRRectL */*area*/, NRPixBlock */*pb*/)
226     NRArenaGlyphs *glyphs;
228     glyphs = NR_ARENA_GLYPHS(item);
230     if (!glyphs->font ) return item->state;
232     /* TODO : render to greyscale pixblock provided for clipping */
234     return item->state;
237 static NRArenaItem *
238 nr_arena_glyphs_pick(NRArenaItem *item, Geom::Point p, gdouble /*delta*/, unsigned int /*sticky*/)
240     NRArenaGlyphs *glyphs;
242     glyphs = NR_ARENA_GLYPHS(item);
244     if (!glyphs->font ) return NULL;
245     if (!glyphs->style) return NULL;
247     double const x = p[Geom::X];
248     double const y = p[Geom::Y];
249     /* With text we take a simple approach: pick if the point is in a characher bbox */
250     if ((x >= item->bbox.x0) && (y >= item->bbox.y0) && (x <= item->bbox.x1) && (y <= item->bbox.y1)) return item;
252     return NULL;
255 void
256 nr_arena_glyphs_set_path(NRArenaGlyphs *glyphs, SPCurve */*curve*/, unsigned int /*lieutenant*/, font_instance *font, gint glyph, Geom::Matrix const *transform)
258     nr_return_if_fail(glyphs != NULL);
259     nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs));
261     nr_arena_item_request_render(NR_ARENA_ITEM(glyphs));
263     if (transform) {
264         glyphs->g_transform = *transform;
265     } else {
266         glyphs->g_transform.setIdentity();
267     }
269     if (font) font->Ref();
270     if (glyphs->font) glyphs->font->Unref();
271     glyphs->font=font;
272     glyphs->glyph = glyph;
274     nr_arena_item_request_update(NR_ARENA_ITEM(glyphs), NR_ARENA_ITEM_STATE_ALL, FALSE);
277 void
278 nr_arena_glyphs_set_style(NRArenaGlyphs *glyphs, SPStyle *style)
280     nr_return_if_fail(glyphs != NULL);
281     nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs));
283     if (style) sp_style_ref(style);
284     if (glyphs->style) sp_style_unref(glyphs->style);
285     glyphs->style = style;
287     nr_arena_item_request_update(NR_ARENA_ITEM(glyphs), NR_ARENA_ITEM_STATE_ALL, FALSE);
290 static guint
291 nr_arena_glyphs_fill_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
293     /* fixme: area == m->area, so merge these */
295     NRArenaItem *item = NR_ARENA_ITEM(glyphs);
297     if (glyphs->rfont && nr_rect_l_test_intersect_ptr(area, &item->bbox)) {
298         raster_glyph *g = glyphs->rfont->GetGlyph(glyphs->glyph);
299         if ( g ) g->Blit(Geom::Point(glyphs->x, glyphs->y), *m);
300     }
302     return item->state;
305 static guint
306 nr_arena_glyphs_stroke_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
308     NRArenaItem *item = NR_ARENA_ITEM(glyphs);
309     if (glyphs->sfont && nr_rect_l_test_intersect_ptr(area, &item->bbox)) {
310         raster_glyph *g=glyphs->sfont->GetGlyph(glyphs->glyph);
311         if ( g ) g->Blit(Geom::Point(glyphs->x, glyphs->y),*m);
312     }
314     return item->state;
317 static void nr_arena_glyphs_group_class_init(NRArenaGlyphsGroupClass *klass);
318 static void nr_arena_glyphs_group_init(NRArenaGlyphsGroup *group);
319 static void nr_arena_glyphs_group_finalize(NRObject *object);
321 static guint nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
322 static unsigned int nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
323 static unsigned int nr_arena_glyphs_group_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
324 static NRArenaItem *nr_arena_glyphs_group_pick(NRArenaItem *item, Geom::Point p, gdouble delta, unsigned int sticky);
326 static NRArenaGroupClass *group_parent_class;
328 NRType
329 nr_arena_glyphs_group_get_type(void)
331     static NRType type = 0;
332     if (!type) {
333         type = nr_object_register_type(NR_TYPE_ARENA_GROUP,
334                                        "NRArenaGlyphsGroup",
335                                        sizeof(NRArenaGlyphsGroupClass),
336                                        sizeof(NRArenaGlyphsGroup),
337                                        (void (*)(NRObjectClass *)) nr_arena_glyphs_group_class_init,
338                                        (void (*)(NRObject *)) nr_arena_glyphs_group_init);
339     }
340     return type;
343 static void
344 nr_arena_glyphs_group_class_init(NRArenaGlyphsGroupClass *klass)
346     NRObjectClass *object_class;
347     NRArenaItemClass *item_class;
349     object_class = (NRObjectClass *) klass;
350     item_class = (NRArenaItemClass *) klass;
352     group_parent_class = (NRArenaGroupClass *) ((NRObjectClass *) klass)->parent;
354     object_class->finalize = nr_arena_glyphs_group_finalize;
355     object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaGlyphsGroup>;
357     item_class->update = nr_arena_glyphs_group_update;
358     item_class->render = nr_arena_glyphs_group_render;
359     item_class->clip = nr_arena_glyphs_group_clip;
360     item_class->pick = nr_arena_glyphs_group_pick;
363 static void
364 nr_arena_glyphs_group_init(NRArenaGlyphsGroup *group)
366     group->style = NULL;
367     group->paintbox.x0 = group->paintbox.y0 = 0.0F;
368     group->paintbox.x1 = group->paintbox.y1 = 1.0F;
370     group->fill_painter = NULL;
371     group->stroke_painter = NULL;
374 static void
375 nr_arena_glyphs_group_finalize(NRObject *object)
377     NRArenaGlyphsGroup *group=static_cast<NRArenaGlyphsGroup *>(object);
379     if (group->fill_painter) {
380         sp_painter_free(group->fill_painter);
381         group->fill_painter = NULL;
382     }
384     if (group->stroke_painter) {
385         sp_painter_free(group->stroke_painter);
386         group->stroke_painter = NULL;
387     }
389     if (group->style) {
390         sp_style_unref(group->style);
391         group->style = NULL;
392     }
394     ((NRObjectClass *) group_parent_class)->finalize(object);
397 static guint
398 nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
400     NRArenaGlyphsGroup *group = NR_ARENA_GLYPHS_GROUP(item);
402     if (group->fill_painter) {
403         sp_painter_free(group->fill_painter);
404         group->fill_painter = NULL;
405     }
407     if (group->stroke_painter) {
408         sp_painter_free(group->stroke_painter);
409         group->stroke_painter = NULL;
410     }
412     item->render_opacity = TRUE;
413     if (group->style->fill.isPaintserver()) {
414         group->fill_painter = sp_paint_server_painter_new(SP_STYLE_FILL_SERVER(group->style),
415                                                           gc->transform, gc->parent->transform,
416                                                           &group->paintbox);
417         item->render_opacity = FALSE;
418     }
420     if (group->style->stroke.isPaintserver()) {
421         group->stroke_painter = sp_paint_server_painter_new(SP_STYLE_STROKE_SERVER(group->style),
422                                                             gc->transform, gc->parent->transform,
423                                                             &group->paintbox);
424         item->render_opacity = FALSE;
425     }
427     if ( item->render_opacity == TRUE && !group->style->stroke.isNone() && !group->style->fill.isNone() ) {
428         item->render_opacity=FALSE;
429     }
431     if (((NRArenaItemClass *) group_parent_class)->update)
432         return ((NRArenaItemClass *) group_parent_class)->update(item, area, gc, state, reset);
434     return NR_ARENA_ITEM_STATE_ALL;
438 static unsigned int
439 nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int /*flags*/)
441     NRArenaItem *child;
443     NRArenaGroup *group = NR_ARENA_GROUP(item);
444     NRArenaGlyphsGroup *ggroup = NR_ARENA_GLYPHS_GROUP(item);
445     SPStyle const *style = ggroup->style;
447     guint ret = item->state;
449     if (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
451         if (!ct)
452             return item->state;
454         guint32 rgba = item->arena->outlinecolor;
455         // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat
456         // by setting color channels in the "wrong" order
457         cairo_set_source_rgba(ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
458         cairo_set_tolerance(ct, 1.25); // low quality, but good enough for outline mode
460         for (child = group->children; child != NULL; child = child->next) {
461             NRArenaGlyphs *g = NR_ARENA_GLYPHS(child);
463             Geom::PathVector const * pathv = g->font->PathVector(g->glyph);
465             cairo_new_path(ct);
466             Geom::Matrix transform = g->g_transform * group->ctm;
467             feed_pathvector_to_cairo (ct, *pathv, transform, to_2geom((pb->area).upgrade()), false, 0);
468             cairo_fill(ct);
469             pb->empty = FALSE;
470         }
472         return ret;
473     }
477     /* Fill */
478     if (!style->fill.isNone() || item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
479         NRPixBlock m;
480         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
482         // if memory allocation failed, abort
483         if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) {
484             nr_pixblock_release (&m);
485             return (item->state);
486         }
488         m.visible_area = pb->visible_area;
490         /* Render children fill mask */
491         for (child = group->children; child != NULL; child = child->next) {
492             ret = nr_arena_glyphs_fill_mask(NR_ARENA_GLYPHS(child), area, &m);
493             if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) {
494                 nr_pixblock_release(&m);
495                 return ret;
496             }
497         }
499         /* Composite into buffer */
500         if (style->fill.isPaintserver()) {
501             if (ggroup->fill_painter) {
502                 nr_arena_render_paintserver_fill(pb, area, ggroup->fill_painter, SP_SCALE24_TO_FLOAT(style->fill_opacity.value), &m);
503             }
504         } else if (style->fill.isColor() || item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
505             guint32 rgba;
506             if (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
507                 // In outline mode, render fill only, using outlinecolor
508                 rgba = item->arena->outlinecolor;
509             } else if ( item->render_opacity ) {
510                 rgba = style->fill.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->fill_opacity.value) *
511                                                          SP_SCALE24_TO_FLOAT(style->opacity.value) );
512             } else {
513                 rgba = style->fill.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->fill_opacity.value) );
514             }
515             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
516             pb->empty = FALSE;
517         }
519         nr_pixblock_release(&m);
520     }
522     /* Stroke */
523     if (!style->stroke.isNone() && !(item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE)) {
524         NRPixBlock m;
525         guint32 rgba;
526         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
528         // if memory allocation failed, abort
529         if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) {
530             nr_pixblock_release (&m);
531             return (item->state);
532         }
534         m.visible_area = pb->visible_area;
535         /* Render children stroke mask */
536         for (child = group->children; child != NULL; child = child->next) {
537             ret = nr_arena_glyphs_stroke_mask(NR_ARENA_GLYPHS(child), area, &m);
538             if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) {
539                 nr_pixblock_release(&m);
540                 return ret;
541             }
542         }
543         /* Composite into buffer */
544         if (style->stroke.isPaintserver()) {
545             if (ggroup->stroke_painter) {
546                 nr_arena_render_paintserver_fill(pb, area, ggroup->stroke_painter, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value), &m);
547             }
548         } else if (style->stroke.isColor()) {
549             if ( item->render_opacity ) {
550                 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) *
551                                                            SP_SCALE24_TO_FLOAT(style->opacity.value) );
552             } else {
553                 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) );
554             }
555             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
556             pb->empty = FALSE;
557         } else {
558             // nothing
559         }
560         nr_pixblock_release(&m);
561     }
563     return ret;
566 static unsigned int
567 nr_arena_glyphs_group_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
569     NRArenaGroup *group = NR_ARENA_GROUP(item);
571     guint ret = item->state;
573     /* Render children fill mask */
574     for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
575         ret = nr_arena_glyphs_fill_mask(NR_ARENA_GLYPHS(child), area, pb);
576         if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) return ret;
577     }
579     return ret;
582 static NRArenaItem *
583 nr_arena_glyphs_group_pick(NRArenaItem *item, Geom::Point p, gdouble delta, unsigned int sticky)
585     NRArenaItem *picked = NULL;
587     if (((NRArenaItemClass *) group_parent_class)->pick)
588         picked = ((NRArenaItemClass *) group_parent_class)->pick(item, p, delta, sticky);
590     if (picked) picked = item;
592     return picked;
595 void
596 nr_arena_glyphs_group_clear(NRArenaGlyphsGroup *sg)
598     NRArenaGroup *group = NR_ARENA_GROUP(sg);
600     nr_arena_item_request_render(NR_ARENA_ITEM(group));
602     while (group->children) {
603         nr_arena_item_remove_child(NR_ARENA_ITEM(group), group->children);
604     }
607 void
608 nr_arena_glyphs_group_add_component(NRArenaGlyphsGroup *sg, font_instance *font, int glyph, Geom::Matrix const &transform)
610     NRArenaGroup *group;
612     group = NR_ARENA_GROUP(sg);
614     Geom::PathVector const * pathv = ( font
615                                        ? font->PathVector(glyph)
616                                        : NULL );
617     if ( pathv ) {
618         nr_arena_item_request_render(NR_ARENA_ITEM(group));
620         NRArenaItem *new_arena = NRArenaGlyphs::create(group->arena);
621         nr_arena_item_append_child(NR_ARENA_ITEM(group), new_arena);
622         nr_arena_item_unref(new_arena);
623         nr_arena_glyphs_set_path(NR_ARENA_GLYPHS(new_arena), NULL, FALSE, font, glyph, &transform);
624         nr_arena_glyphs_set_style(NR_ARENA_GLYPHS(new_arena), sg->style);
625     }
628 void
629 nr_arena_glyphs_group_set_style(NRArenaGlyphsGroup *sg, SPStyle *style)
631     nr_return_if_fail(sg != NULL);
632     nr_return_if_fail(NR_IS_ARENA_GLYPHS_GROUP(sg));
634     NRArenaGroup *group = NR_ARENA_GROUP(sg);
636     if (style) sp_style_ref(style);
637     if (sg->style) sp_style_unref(sg->style);
638     sg->style = style;
640     for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
641         nr_return_if_fail(NR_IS_ARENA_GLYPHS(child));
642         nr_arena_glyphs_set_style(NR_ARENA_GLYPHS(child), sg->style);
643     }
645     nr_arena_item_request_update(NR_ARENA_ITEM(sg), NR_ARENA_ITEM_STATE_ALL, FALSE);
648 void
649 nr_arena_glyphs_group_set_paintbox(NRArenaGlyphsGroup *gg, NRRect const *pbox)
651     nr_return_if_fail(gg != NULL);
652     nr_return_if_fail(NR_IS_ARENA_GLYPHS_GROUP(gg));
653     nr_return_if_fail(pbox != NULL);
655     if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
656         gg->paintbox.x0 = pbox->x0;
657         gg->paintbox.y0 = pbox->y0;
658         gg->paintbox.x1 = pbox->x1;
659         gg->paintbox.y1 = pbox->y1;
660     } else {
661         /* fixme: We kill warning, although not sure what to do here (Lauris) */
662         gg->paintbox.x0 = gg->paintbox.y0 = 0.0F;
663         gg->paintbox.x1 = gg->paintbox.y1 = 256.0F;
664     }
666     nr_arena_item_request_update(NR_ARENA_ITEM(gg), NR_ARENA_ITEM_STATE_ALL, FALSE);
670 /*
671   Local Variables:
672   mode:c++
673   c-file-style:"stroustrup"
674   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
675   indent-tabs-mode:nil
676   fill-column:99
677   End:
678 */
679 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :