Code

Revert recent refactoring changes by johnce because they break the build, which canno...
[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);
219     return NR_ARENA_ITEM_STATE_ALL;
222 static guint
223 nr_arena_glyphs_clip(NRArenaItem *item, NRRectL */*area*/, NRPixBlock */*pb*/)
225     NRArenaGlyphs *glyphs;
227     glyphs = NR_ARENA_GLYPHS(item);
229     if (!glyphs->font ) return item->state;
231     /* TODO : render to greyscale pixblock provided for clipping */
233     return item->state;
236 static NRArenaItem *
237 nr_arena_glyphs_pick(NRArenaItem *item, Geom::Point p, gdouble /*delta*/, unsigned int /*sticky*/)
239     NRArenaGlyphs *glyphs;
241     glyphs = NR_ARENA_GLYPHS(item);
243     if (!glyphs->font ) return NULL;
244     if (!glyphs->style) return NULL;
246     double const x = p[Geom::X];
247     double const y = p[Geom::Y];
248     /* With text we take a simple approach: pick if the point is in a characher bbox */
249     if ((x >= item->bbox.x0) && (y >= item->bbox.y0) && (x <= item->bbox.x1) && (y <= item->bbox.y1)) return item;
251     return NULL;
254 void
255 nr_arena_glyphs_set_path(NRArenaGlyphs *glyphs, SPCurve */*curve*/, unsigned int /*lieutenant*/, font_instance *font, gint glyph, Geom::Matrix const *transform)
257     nr_return_if_fail(glyphs != NULL);
258     nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs));
260     nr_arena_item_request_render(NR_ARENA_ITEM(glyphs));
262     if (transform) {
263         glyphs->g_transform = *transform;
264     } else {
265         glyphs->g_transform.setIdentity();
266     }
268     if (font) font->Ref();
269     if (glyphs->font) glyphs->font->Unref();
270     glyphs->font=font;
271     glyphs->glyph = glyph;
273     nr_arena_item_request_update(NR_ARENA_ITEM(glyphs), NR_ARENA_ITEM_STATE_ALL, FALSE);
276 void
277 nr_arena_glyphs_set_style(NRArenaGlyphs *glyphs, SPStyle *style)
279     nr_return_if_fail(glyphs != NULL);
280     nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs));
282     if (style) sp_style_ref(style);
283     if (glyphs->style) sp_style_unref(glyphs->style);
284     glyphs->style = style;
286     nr_arena_item_request_update(NR_ARENA_ITEM(glyphs), NR_ARENA_ITEM_STATE_ALL, FALSE);
289 static guint
290 nr_arena_glyphs_fill_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
292     /* fixme: area == m->area, so merge these */
294     NRArenaItem *item = NR_ARENA_ITEM(glyphs);
296     if (glyphs->rfont && nr_rect_l_test_intersect_ptr(area, &item->bbox)) {
297         raster_glyph *g = glyphs->rfont->GetGlyph(glyphs->glyph);
298         if ( g ) g->Blit(Geom::Point(glyphs->x, glyphs->y), *m);
299     }
301     return item->state;
304 static guint
305 nr_arena_glyphs_stroke_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
307     NRArenaItem *item = NR_ARENA_ITEM(glyphs);
308     if (glyphs->sfont && nr_rect_l_test_intersect_ptr(area, &item->bbox)) {
309         raster_glyph *g=glyphs->sfont->GetGlyph(glyphs->glyph);
310         if ( g ) g->Blit(Geom::Point(glyphs->x, glyphs->y),*m);
311     }
313     return item->state;
316 static void nr_arena_glyphs_group_class_init(NRArenaGlyphsGroupClass *klass);
317 static void nr_arena_glyphs_group_init(NRArenaGlyphsGroup *group);
318 static void nr_arena_glyphs_group_finalize(NRObject *object);
320 static guint nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
321 static unsigned int nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
322 static unsigned int nr_arena_glyphs_group_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
323 static NRArenaItem *nr_arena_glyphs_group_pick(NRArenaItem *item, Geom::Point p, gdouble delta, unsigned int sticky);
325 static NRArenaGroupClass *group_parent_class;
327 NRType
328 nr_arena_glyphs_group_get_type(void)
330     static NRType type = 0;
331     if (!type) {
332         type = nr_object_register_type(NR_TYPE_ARENA_GROUP,
333                                        "NRArenaGlyphsGroup",
334                                        sizeof(NRArenaGlyphsGroupClass),
335                                        sizeof(NRArenaGlyphsGroup),
336                                        (void (*)(NRObjectClass *)) nr_arena_glyphs_group_class_init,
337                                        (void (*)(NRObject *)) nr_arena_glyphs_group_init);
338     }
339     return type;
342 static void
343 nr_arena_glyphs_group_class_init(NRArenaGlyphsGroupClass *klass)
345     NRObjectClass *object_class;
346     NRArenaItemClass *item_class;
348     object_class = (NRObjectClass *) klass;
349     item_class = (NRArenaItemClass *) klass;
351     group_parent_class = (NRArenaGroupClass *) ((NRObjectClass *) klass)->parent;
353     object_class->finalize = nr_arena_glyphs_group_finalize;
354     object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaGlyphsGroup>;
356     item_class->update = nr_arena_glyphs_group_update;
357     item_class->render = nr_arena_glyphs_group_render;
358     item_class->clip = nr_arena_glyphs_group_clip;
359     item_class->pick = nr_arena_glyphs_group_pick;
362 static void
363 nr_arena_glyphs_group_init(NRArenaGlyphsGroup *group)
365     group->style = NULL;
366     group->paintbox.x0 = group->paintbox.y0 = 0.0F;
367     group->paintbox.x1 = group->paintbox.y1 = 1.0F;
369     group->fill_painter = NULL;
370     group->stroke_painter = NULL;
373 static void
374 nr_arena_glyphs_group_finalize(NRObject *object)
376     NRArenaGlyphsGroup *group=static_cast<NRArenaGlyphsGroup *>(object);
378     if (group->fill_painter) {
379         sp_painter_free(group->fill_painter);
380         group->fill_painter = NULL;
381     }
383     if (group->stroke_painter) {
384         sp_painter_free(group->stroke_painter);
385         group->stroke_painter = NULL;
386     }
388     if (group->style) {
389         sp_style_unref(group->style);
390         group->style = NULL;
391     }
393     ((NRObjectClass *) group_parent_class)->finalize(object);
396 static guint
397 nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
399     NRArenaGlyphsGroup *group = NR_ARENA_GLYPHS_GROUP(item);
401     if (group->fill_painter) {
402         sp_painter_free(group->fill_painter);
403         group->fill_painter = NULL;
404     }
406     if (group->stroke_painter) {
407         sp_painter_free(group->stroke_painter);
408         group->stroke_painter = NULL;
409     }
411     item->render_opacity = TRUE;
412     if (group->style->fill.isPaintserver()) {
413         group->fill_painter = sp_paint_server_painter_new(SP_STYLE_FILL_SERVER(group->style),
414                                                           gc->transform, gc->parent->transform,
415                                                           &group->paintbox);
416         item->render_opacity = FALSE;
417     }
419     if (group->style->stroke.isPaintserver()) {
420         group->stroke_painter = sp_paint_server_painter_new(SP_STYLE_STROKE_SERVER(group->style),
421                                                             gc->transform, gc->parent->transform,
422                                                             &group->paintbox);
423         item->render_opacity = FALSE;
424     }
426     if ( item->render_opacity == TRUE && !group->style->stroke.isNone() && !group->style->fill.isNone() ) {
427         item->render_opacity=FALSE;
428     }
430     if (((NRArenaItemClass *) group_parent_class)->update)
431         return ((NRArenaItemClass *) group_parent_class)->update(item, area, gc, state, reset);
433     return NR_ARENA_ITEM_STATE_ALL;
437 static unsigned int
438 nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int /*flags*/)
440     NRArenaItem *child;
442     NRArenaGroup *group = NR_ARENA_GROUP(item);
443     NRArenaGlyphsGroup *ggroup = NR_ARENA_GLYPHS_GROUP(item);
444     SPStyle const *style = ggroup->style;
446     guint ret = item->state;
448     if (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
450         if (!ct)
451             return item->state;
453         guint32 rgba = item->arena->outlinecolor;
454         // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat
455         // by setting color channels in the "wrong" order
456         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));
457         cairo_set_tolerance(ct, 1.25); // low quality, but good enough for outline mode
459         for (child = group->children; child != NULL; child = child->next) {
460             NRArenaGlyphs *g = NR_ARENA_GLYPHS(child);
462             Geom::PathVector const * pathv = g->font->PathVector(g->glyph);
464             cairo_new_path(ct);
465             Geom::Matrix transform = g->g_transform * group->ctm;
466             feed_pathvector_to_cairo (ct, *pathv, transform, to_2geom((pb->area).upgrade()), false, 0);
467             cairo_fill(ct);
468             pb->empty = FALSE;
469         }
471         return ret;
472     }
476     /* Fill */
477     if (!style->fill.isNone() || item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
478         NRPixBlock m;
479         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
481         // if memory allocation failed, abort
482         if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) {
483             nr_pixblock_release (&m);
484             return (item->state);
485         }
487         m.visible_area = pb->visible_area;
489         /* Render children fill mask */
490         for (child = group->children; child != NULL; child = child->next) {
491             ret = nr_arena_glyphs_fill_mask(NR_ARENA_GLYPHS(child), area, &m);
492             if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) {
493                 nr_pixblock_release(&m);
494                 return ret;
495             }
496         }
498         /* Composite into buffer */
499         if (style->fill.isPaintserver()) {
500             if (ggroup->fill_painter) {
501                 nr_arena_render_paintserver_fill(pb, area, ggroup->fill_painter, SP_SCALE24_TO_FLOAT(style->fill_opacity.value), &m);
502             }
503         } else if (style->fill.isColor() || item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
504             guint32 rgba;
505             if (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) {
506                 // In outline mode, render fill only, using outlinecolor
507                 rgba = item->arena->outlinecolor;
508             } else if ( item->render_opacity ) {
509                 rgba = style->fill.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->fill_opacity.value) *
510                                                          SP_SCALE24_TO_FLOAT(style->opacity.value) );
511             } else {
512                 rgba = style->fill.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->fill_opacity.value) );
513             }
514             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
515             pb->empty = FALSE;
516         }
518         nr_pixblock_release(&m);
519     }
521     /* Stroke */
522     if (!style->stroke.isNone() && !(item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE)) {
523         NRPixBlock m;
524         guint32 rgba;
525         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
527         // if memory allocation failed, abort
528         if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) {
529             nr_pixblock_release (&m);
530             return (item->state);
531         }
533         m.visible_area = pb->visible_area;
534         /* Render children stroke mask */
535         for (child = group->children; child != NULL; child = child->next) {
536             ret = nr_arena_glyphs_stroke_mask(NR_ARENA_GLYPHS(child), area, &m);
537             if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) {
538                 nr_pixblock_release(&m);
539                 return ret;
540             }
541         }
542         /* Composite into buffer */
543         if (style->stroke.isPaintserver()) {
544             if (ggroup->stroke_painter) {
545                 nr_arena_render_paintserver_fill(pb, area, ggroup->stroke_painter, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value), &m);
546             }
547         } else if (style->stroke.isColor()) {
548             if ( item->render_opacity ) {
549                 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) *
550                                                            SP_SCALE24_TO_FLOAT(style->opacity.value) );
551             } else {
552                 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) );
553             }
554             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
555             pb->empty = FALSE;
556         } else {
557             // nothing
558         }
559         nr_pixblock_release(&m);
560     }
562     return ret;
565 static unsigned int
566 nr_arena_glyphs_group_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
568     NRArenaGroup *group = NR_ARENA_GROUP(item);
570     guint ret = item->state;
572     /* Render children fill mask */
573     for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
574         ret = nr_arena_glyphs_fill_mask(NR_ARENA_GLYPHS(child), area, pb);
575         if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) return ret;
576     }
578     return ret;
581 static NRArenaItem *
582 nr_arena_glyphs_group_pick(NRArenaItem *item, Geom::Point p, gdouble delta, unsigned int sticky)
584     NRArenaItem *picked = NULL;
586     if (((NRArenaItemClass *) group_parent_class)->pick)
587         picked = ((NRArenaItemClass *) group_parent_class)->pick(item, p, delta, sticky);
589     if (picked) picked = item;
591     return picked;
594 void
595 nr_arena_glyphs_group_clear(NRArenaGlyphsGroup *sg)
597     NRArenaGroup *group = NR_ARENA_GROUP(sg);
599     nr_arena_item_request_render(NR_ARENA_ITEM(group));
601     while (group->children) {
602         nr_arena_item_remove_child(NR_ARENA_ITEM(group), group->children);
603     }
606 void
607 nr_arena_glyphs_group_add_component(NRArenaGlyphsGroup *sg, font_instance *font, int glyph, Geom::Matrix const &transform)
609     NRArenaGroup *group;
611     group = NR_ARENA_GROUP(sg);
613     Geom::PathVector const * pathv = ( font
614                                        ? font->PathVector(glyph)
615                                        : NULL );
616     if ( pathv ) {
617         nr_arena_item_request_render(NR_ARENA_ITEM(group));
619         NRArenaItem *new_arena = NRArenaGlyphs::create(group->arena);
620         nr_arena_item_append_child(NR_ARENA_ITEM(group), new_arena);
621         nr_arena_item_unref(new_arena);
622         nr_arena_glyphs_set_path(NR_ARENA_GLYPHS(new_arena), NULL, FALSE, font, glyph, &transform);
623         nr_arena_glyphs_set_style(NR_ARENA_GLYPHS(new_arena), sg->style);
624     }
627 void
628 nr_arena_glyphs_group_set_style(NRArenaGlyphsGroup *sg, SPStyle *style)
630     nr_return_if_fail(sg != NULL);
631     nr_return_if_fail(NR_IS_ARENA_GLYPHS_GROUP(sg));
633     NRArenaGroup *group = NR_ARENA_GROUP(sg);
635     if (style) sp_style_ref(style);
636     if (sg->style) sp_style_unref(sg->style);
637     sg->style = style;
639     for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
640         nr_return_if_fail(NR_IS_ARENA_GLYPHS(child));
641         nr_arena_glyphs_set_style(NR_ARENA_GLYPHS(child), sg->style);
642     }
644     nr_arena_item_request_update(NR_ARENA_ITEM(sg), NR_ARENA_ITEM_STATE_ALL, FALSE);
647 void
648 nr_arena_glyphs_group_set_paintbox(NRArenaGlyphsGroup *gg, NRRect const *pbox)
650     nr_return_if_fail(gg != NULL);
651     nr_return_if_fail(NR_IS_ARENA_GLYPHS_GROUP(gg));
652     nr_return_if_fail(pbox != NULL);
654     if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
655         gg->paintbox.x0 = pbox->x0;
656         gg->paintbox.y0 = pbox->y0;
657         gg->paintbox.x1 = pbox->x1;
658         gg->paintbox.y1 = pbox->y1;
659     } else {
660         /* fixme: We kill warning, although not sure what to do here (Lauris) */
661         gg->paintbox.x0 = gg->paintbox.y0 = 0.0F;
662         gg->paintbox.x1 = gg->paintbox.y1 = 256.0F;
663     }
665     nr_arena_item_request_update(NR_ARENA_ITEM(gg), NR_ARENA_ITEM_STATE_ALL, FALSE);
669 /*
670   Local Variables:
671   mode:c++
672   c-file-style:"stroustrup"
673   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
674   indent-tabs-mode:nil
675   fill-column:99
676   End:
677 */
678 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :