Code

No more NRMatrix or NRPoint.
[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-path.h>
21 #include <libnr/n-art-bpath.h>
22 #include <libnr/nr-matrix-ops.h>
23 #include <libnr/nr-matrix-fns.h>
24 #include "../style.h"
25 #include "nr-arena.h"
26 #include "nr-arena-glyphs.h"
27 #include <cairo.h>
28 #include "inkscape-cairo.h"
30 #ifdef test_glyph_liv
31 #include "../display/canvas-bpath.h"
32 #include <libnrtype/font-instance.h>
33 #include <libnrtype/raster-glyph.h>
34 #include <libnrtype/RasterFont.h>
36 // defined in nr-arena-shape.cpp
37 void nr_pixblock_render_shape_mask_or(NRPixBlock &m, Shape *theS);
38 #endif
40 static void nr_arena_glyphs_class_init(NRArenaGlyphsClass *klass);
41 static void nr_arena_glyphs_init(NRArenaGlyphs *glyphs);
42 static void nr_arena_glyphs_finalize(NRObject *object);
44 static guint nr_arena_glyphs_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
45 static guint nr_arena_glyphs_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
46 static NRArenaItem *nr_arena_glyphs_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
48 static NRArenaItemClass *glyphs_parent_class;
50 NRType
51 nr_arena_glyphs_get_type(void)
52 {
53     static NRType type = 0;
54     if (!type) {
55         type = nr_object_register_type(NR_TYPE_ARENA_ITEM,
56                                        "NRArenaGlyphs",
57                                        sizeof(NRArenaGlyphsClass),
58                                        sizeof(NRArenaGlyphs),
59                                        (void (*)(NRObjectClass *)) nr_arena_glyphs_class_init,
60                                        (void (*)(NRObject *)) nr_arena_glyphs_init);
61     }
62     return type;
63 }
65 static void
66 nr_arena_glyphs_class_init(NRArenaGlyphsClass *klass)
67 {
68     NRObjectClass *object_class;
69     NRArenaItemClass *item_class;
71     object_class = (NRObjectClass *) klass;
72     item_class = (NRArenaItemClass *) klass;
74     glyphs_parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent;
76     object_class->finalize = nr_arena_glyphs_finalize;
77     object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaGlyphs>;
79     item_class->update = nr_arena_glyphs_update;
80     item_class->clip = nr_arena_glyphs_clip;
81     item_class->pick = nr_arena_glyphs_pick;
82 }
84 static void
85 nr_arena_glyphs_init(NRArenaGlyphs *glyphs)
86 {
87     glyphs->style = NULL;
88     glyphs->g_transform.set_identity();
89     glyphs->font = NULL;
90     glyphs->glyph = 0;
92     glyphs->rfont = NULL;
93     glyphs->sfont = NULL;
94     glyphs->x = glyphs->y = 0.0;
95 }
97 static void
98 nr_arena_glyphs_finalize(NRObject *object)
99 {
100     NRArenaGlyphs *glyphs = static_cast<NRArenaGlyphs *>(object);
102     if (glyphs->rfont) {
103         glyphs->rfont->Unref();
104         glyphs->rfont=NULL;
105     }
106     if (glyphs->sfont) {
107         glyphs->sfont->Unref();
108         glyphs->sfont=NULL;
109     }
111     if (glyphs->font) {
112         glyphs->font->Unref();
113         glyphs->font=NULL;
114     }
116     if (glyphs->style) {
117         sp_style_unref(glyphs->style);
118         glyphs->style = NULL;
119     }
121     ((NRObjectClass *) glyphs_parent_class)->finalize(object);
124 static guint
125 nr_arena_glyphs_update(NRArenaItem *item, NRRectL */*area*/, NRGC *gc, guint /*state*/, guint /*reset*/)
127     NRArenaGlyphs *glyphs;
128     raster_font *rfont;
130     glyphs = NR_ARENA_GLYPHS(item);
132     if (!glyphs->font || !glyphs->style)
133         return NR_ARENA_ITEM_STATE_ALL;
134     if ((glyphs->style->fill.isNone()) && (glyphs->style->stroke.isNone()))
135         return NR_ARENA_ITEM_STATE_ALL;
137     NRRect bbox;
138     bbox.x0 = bbox.y0 = NR_HUGE;
139     bbox.x1 = bbox.y1 = -NR_HUGE;
141     float const scale = NR::expansion(gc->transform);
143     if (!glyphs->style->fill.isNone()) {
144         NR::Matrix t;
145         t = glyphs->g_transform * gc->transform;
146         glyphs->x = t[4];
147         glyphs->y = t[5];
148         t[4]=0;
149         t[5]=0;
150         rfont = glyphs->font->RasterFont(t, 0);
151         if (glyphs->rfont) glyphs->rfont->Unref();
152         glyphs->rfont = rfont;
154         if (glyphs->style->stroke.isNone() || fabs(glyphs->style->stroke_width.computed * scale) <= 0.01) { // Optimization: do fill bbox only if there's no stroke
155             NRRect narea;
156             if ( glyphs->rfont ) glyphs->rfont->BBox(glyphs->glyph, &narea);
157             bbox.x0 = narea.x0 + glyphs->x;
158             bbox.y0 = narea.y0 + glyphs->y;
159             bbox.x1 = narea.x1 + glyphs->x;
160             bbox.y1 = narea.y1 + glyphs->y;
161         }
162     }
164     if (!glyphs->style->stroke.isNone()) {
165         /* Build state data */
166         NR::Matrix t;
167         t = glyphs->g_transform * gc->transform;
168         glyphs->x = t[4];
169         glyphs->y = t[5];
170         t[4]=0;
171         t[5]=0;
173         if ( fabs(glyphs->style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
174             font_style nstyl;
175             nstyl.transform = t;
176             nstyl.stroke_width=MAX(0.125, glyphs->style->stroke_width.computed * scale);
177             if ( glyphs->style->stroke_linecap.computed == SP_STROKE_LINECAP_BUTT ) nstyl.stroke_cap=butt_straight;
178             if ( glyphs->style->stroke_linecap.computed == SP_STROKE_LINECAP_ROUND ) nstyl.stroke_cap=butt_round;
179             if ( glyphs->style->stroke_linecap.computed == SP_STROKE_LINECAP_SQUARE ) nstyl.stroke_cap=butt_square;
180             if ( glyphs->style->stroke_linejoin.computed == SP_STROKE_LINEJOIN_MITER ) nstyl.stroke_join=join_pointy;
181             if ( glyphs->style->stroke_linejoin.computed == SP_STROKE_LINEJOIN_ROUND ) nstyl.stroke_join=join_round;
182             if ( glyphs->style->stroke_linejoin.computed == SP_STROKE_LINEJOIN_BEVEL ) nstyl.stroke_join=join_straight;
183             nstyl.stroke_miter_limit = glyphs->style->stroke_miterlimit.value;
184             nstyl.nbDash=0;
185             nstyl.dash_offset = 0;
186             nstyl.dashes=NULL;
187             if ( glyphs->style->stroke_dash.n_dash > 0 ) {
188                 nstyl.dash_offset = glyphs->style->stroke_dash.offset * scale;
189                 nstyl.nbDash=glyphs->style->stroke_dash.n_dash;
190                 nstyl.dashes=(double*)malloc(nstyl.nbDash*sizeof(double));
191                 for (int i = 0; i < nstyl.nbDash; i++) nstyl.dashes[i]= glyphs->style->stroke_dash.dash[i] * scale;
192             }
193             rfont = glyphs->font->RasterFont( nstyl);
194             if ( nstyl.dashes ) free(nstyl.dashes);
195             if (glyphs->sfont) glyphs->sfont->Unref();
196             glyphs->sfont = rfont;
198             NRRect narea;
199             if ( glyphs->sfont ) glyphs->sfont->BBox(glyphs->glyph, &narea);
200             narea.x0-=nstyl.stroke_width;
201             narea.y0-=nstyl.stroke_width;
202             narea.x1+=nstyl.stroke_width;
203             narea.y1+=nstyl.stroke_width;
204             bbox.x0 = narea.x0 + glyphs->x;
205             bbox.y0 = narea.y0 + glyphs->y;
206             bbox.x1 = narea.x1 + glyphs->x;
207             bbox.y1 = narea.y1 + glyphs->y;
208         }
209     }
210     if (nr_rect_d_test_empty(&bbox)) return NR_ARENA_ITEM_STATE_ALL;
212     item->bbox.x0 = (gint32)(bbox.x0 - 1.0);
213     item->bbox.y0 = (gint32)(bbox.y0 - 1.0);
214     item->bbox.x1 = (gint32)(bbox.x1 + 1.0);
215     item->bbox.y1 = (gint32)(bbox.y1 + 1.0);
216     nr_arena_request_render_rect(item->arena, &item->bbox);
218     return NR_ARENA_ITEM_STATE_ALL;
221 static guint
222 nr_arena_glyphs_clip(NRArenaItem *item, NRRectL */*area*/, NRPixBlock */*pb*/)
224     NRArenaGlyphs *glyphs;
226     glyphs = NR_ARENA_GLYPHS(item);
228     if (!glyphs->font ) return item->state;
230     /* TODO : render to greyscale pixblock provided for clipping */
232     return item->state;
235 static NRArenaItem *
236 nr_arena_glyphs_pick(NRArenaItem *item, NR::Point p, gdouble /*delta*/, unsigned int /*sticky*/)
238     NRArenaGlyphs *glyphs;
240     glyphs = NR_ARENA_GLYPHS(item);
242     if (!glyphs->font ) return NULL;
243     if (!glyphs->style) return NULL;
245     double const x = p[NR::X];
246     double const y = p[NR::Y];
247     /* With text we take a simple approach: pick if the point is in a characher bbox */
248     if ((x >= item->bbox.x0) && (y >= item->bbox.y0) && (x <= item->bbox.x1) && (y <= item->bbox.y1)) return item;
250     return NULL;
253 void
254 nr_arena_glyphs_set_path(NRArenaGlyphs *glyphs, SPCurve */*curve*/, unsigned int /*lieutenant*/, font_instance *font, gint glyph, NR::Matrix const *transform)
256     nr_return_if_fail(glyphs != NULL);
257     nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs));
259     nr_arena_item_request_render(NR_ARENA_ITEM(glyphs));
261     if (transform) {
262         glyphs->g_transform = *transform;
263     } else {
264         glyphs->g_transform.set_identity();
265     }
267     if (font) font->Ref();
268     if (glyphs->font) glyphs->font->Unref();
269     glyphs->font=font;
270     glyphs->glyph = glyph;
272     nr_arena_item_request_update(NR_ARENA_ITEM(glyphs), NR_ARENA_ITEM_STATE_ALL, FALSE);
275 void
276 nr_arena_glyphs_set_style(NRArenaGlyphs *glyphs, SPStyle *style)
278     nr_return_if_fail(glyphs != NULL);
279     nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs));
281     if (style) sp_style_ref(style);
282     if (glyphs->style) sp_style_unref(glyphs->style);
283     glyphs->style = style;
285     nr_arena_item_request_update(NR_ARENA_ITEM(glyphs), NR_ARENA_ITEM_STATE_ALL, FALSE);
288 static guint
289 nr_arena_glyphs_fill_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
291     /* fixme: area == m->area, so merge these */
293     NRArenaItem *item = NR_ARENA_ITEM(glyphs);
295     if (glyphs->rfont && nr_rect_l_test_intersect(area, &item->bbox)) {
296         raster_glyph *g = glyphs->rfont->GetGlyph(glyphs->glyph);
297         if ( g ) g->Blit(NR::Point(glyphs->x, glyphs->y), *m);
298     }
300     return item->state;
303 static guint
304 nr_arena_glyphs_stroke_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
306     NRArenaItem *item = NR_ARENA_ITEM(glyphs);
307     if (glyphs->sfont && nr_rect_l_test_intersect(area, &item->bbox)) {
308         raster_glyph *g=glyphs->sfont->GetGlyph(glyphs->glyph);
309         if ( g ) g->Blit(NR::Point(glyphs->x, glyphs->y),*m);
310     }
312     return item->state;
315 static void nr_arena_glyphs_group_class_init(NRArenaGlyphsGroupClass *klass);
316 static void nr_arena_glyphs_group_init(NRArenaGlyphsGroup *group);
317 static void nr_arena_glyphs_group_finalize(NRObject *object);
319 static guint nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
320 static unsigned int nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
321 static unsigned int nr_arena_glyphs_group_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
322 static NRArenaItem *nr_arena_glyphs_group_pick(NRArenaItem *item, NR::Point p, gdouble delta, unsigned int sticky);
324 static NRArenaGroupClass *group_parent_class;
326 NRType
327 nr_arena_glyphs_group_get_type(void)
329     static NRType type = 0;
330     if (!type) {
331         type = nr_object_register_type(NR_TYPE_ARENA_GROUP,
332                                        "NRArenaGlyphsGroup",
333                                        sizeof(NRArenaGlyphsGroupClass),
334                                        sizeof(NRArenaGlyphsGroup),
335                                        (void (*)(NRObjectClass *)) nr_arena_glyphs_group_class_init,
336                                        (void (*)(NRObject *)) nr_arena_glyphs_group_init);
337     }
338     return type;
341 static void
342 nr_arena_glyphs_group_class_init(NRArenaGlyphsGroupClass *klass)
344     NRObjectClass *object_class;
345     NRArenaItemClass *item_class;
347     object_class = (NRObjectClass *) klass;
348     item_class = (NRArenaItemClass *) klass;
350     group_parent_class = (NRArenaGroupClass *) ((NRObjectClass *) klass)->parent;
352     object_class->finalize = nr_arena_glyphs_group_finalize;
353     object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaGlyphsGroup>;
355     item_class->update = nr_arena_glyphs_group_update;
356     item_class->render = nr_arena_glyphs_group_render;
357     item_class->clip = nr_arena_glyphs_group_clip;
358     item_class->pick = nr_arena_glyphs_group_pick;
361 static void
362 nr_arena_glyphs_group_init(NRArenaGlyphsGroup *group)
364     group->style = NULL;
365     group->paintbox.x0 = group->paintbox.y0 = 0.0F;
366     group->paintbox.x1 = group->paintbox.y1 = 1.0F;
368     group->fill_painter = NULL;
369     group->stroke_painter = NULL;
372 static void
373 nr_arena_glyphs_group_finalize(NRObject *object)
375     NRArenaGlyphsGroup *group=static_cast<NRArenaGlyphsGroup *>(object);
377     if (group->fill_painter) {
378         sp_painter_free(group->fill_painter);
379         group->fill_painter = NULL;
380     }
382     if (group->stroke_painter) {
383         sp_painter_free(group->stroke_painter);
384         group->stroke_painter = NULL;
385     }
387     if (group->style) {
388         sp_style_unref(group->style);
389         group->style = NULL;
390     }
392     ((NRObjectClass *) group_parent_class)->finalize(object);
395 static guint
396 nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
398     NRArenaGlyphsGroup *group = NR_ARENA_GLYPHS_GROUP(item);
400     if (group->fill_painter) {
401         sp_painter_free(group->fill_painter);
402         group->fill_painter = NULL;
403     }
405     if (group->stroke_painter) {
406         sp_painter_free(group->stroke_painter);
407         group->stroke_painter = NULL;
408     }
410     item->render_opacity = TRUE;
411     if (group->style->fill.isPaintserver()) {
412         group->fill_painter = sp_paint_server_painter_new(SP_STYLE_FILL_SERVER(group->style),
413                                                           gc->transform, gc->parent->transform,
414                                                           &group->paintbox);
415         item->render_opacity = FALSE;
416     }
418     if (group->style->stroke.isPaintserver()) {
419         group->stroke_painter = sp_paint_server_painter_new(SP_STYLE_STROKE_SERVER(group->style),
420                                                             gc->transform, gc->parent->transform,
421                                                             &group->paintbox);
422         item->render_opacity = FALSE;
423     }
425     if ( item->render_opacity == TRUE && !group->style->stroke.isNone() && !group->style->fill.isNone() ) {
426         item->render_opacity=FALSE;
427     }
429     if (((NRArenaItemClass *) group_parent_class)->update)
430         return ((NRArenaItemClass *) group_parent_class)->update(item, area, gc, state, reset);
432     return NR_ARENA_ITEM_STATE_ALL;
436 static unsigned int
437 nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int /*flags*/)
439     NRArenaItem *child;
441     NRArenaGroup *group = NR_ARENA_GROUP(item);
442     NRArenaGlyphsGroup *ggroup = NR_ARENA_GLYPHS_GROUP(item);
443     SPStyle const *style = ggroup->style;
445     guint ret = item->state;
447     if (item->arena->rendermode == RENDERMODE_OUTLINE) {
449         if (!ct)
450             return item->state;
452         guint32 rgba = item->arena->outlinecolor;
453         // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat
454         // by setting color channels in the "wrong" order
455         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));
456         cairo_set_tolerance(ct, 1.25); // low quality, but good enough for outline mode
458         for (child = group->children; child != NULL; child = child->next) {
459             NRArenaGlyphs *g = NR_ARENA_GLYPHS(child);
461             NArtBpath *bpath = (NArtBpath *) g->font->ArtBPath(g->glyph);
463             cairo_new_path(ct);
464             NR::Matrix g_t(g->g_transform);
465             feed_curve_to_cairo (ct, bpath, g_t * group->ctm, (pb->area).upgrade(), false, 0);
466             cairo_fill(ct);
467             pb->empty = FALSE;
468         }
470         return ret;
471     }
475     /* Fill */
476     if (!style->fill.isNone() || item->arena->rendermode == RENDERMODE_OUTLINE) {
477         NRPixBlock m;
478         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
480         // if memory allocation failed, abort
481         if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) {
482             nr_pixblock_release (&m);
483             return (item->state);
484         }
486         m.visible_area = pb->visible_area;
488         /* Render children fill mask */
489         for (child = group->children; child != NULL; child = child->next) {
490             ret = nr_arena_glyphs_fill_mask(NR_ARENA_GLYPHS(child), area, &m);
491             if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) {
492                 nr_pixblock_release(&m);
493                 return ret;
494             }
495         }
497         /* Composite into buffer */
498         if (style->fill.isPaintserver()) {
499             if (ggroup->fill_painter) {
500                 nr_arena_render_paintserver_fill(pb, area, ggroup->fill_painter, SP_SCALE24_TO_FLOAT(style->fill_opacity.value), &m);
501             }
502         } else if (style->fill.isColor() || item->arena->rendermode == RENDERMODE_OUTLINE) {
503             guint32 rgba;
504             if (item->arena->rendermode == RENDERMODE_OUTLINE) {
505                 // In outline mode, render fill only, using outlinecolor
506                 rgba = item->arena->outlinecolor;
507             } else if ( item->render_opacity ) {
508                 rgba = style->fill.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->fill_opacity.value) *
509                                                          SP_SCALE24_TO_FLOAT(style->opacity.value) );
510             } else {
511                 rgba = style->fill.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->fill_opacity.value) );
512             }
513             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
514             pb->empty = FALSE;
515         }
517         nr_pixblock_release(&m);
518     }
520     /* Stroke */
521     if (!style->stroke.isNone() && !(item->arena->rendermode == RENDERMODE_OUTLINE)) {
522         NRPixBlock m;
523         guint32 rgba;
524         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
526         // if memory allocation failed, abort
527         if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) {
528             nr_pixblock_release (&m);
529             return (item->state);
530         }
532         m.visible_area = pb->visible_area;
533         /* Render children stroke mask */
534         for (child = group->children; child != NULL; child = child->next) {
535             ret = nr_arena_glyphs_stroke_mask(NR_ARENA_GLYPHS(child), area, &m);
536             if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) {
537                 nr_pixblock_release(&m);
538                 return ret;
539             }
540         }
541         /* Composite into buffer */
542         if (style->stroke.isPaintserver()) {
543             if (ggroup->stroke_painter) {
544                 nr_arena_render_paintserver_fill(pb, area, ggroup->stroke_painter, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value), &m);
545             }
546         } else if (style->stroke.isColor()) {
547             if ( item->render_opacity ) {
548                 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) *
549                                                            SP_SCALE24_TO_FLOAT(style->opacity.value) );
550             } else {
551                 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) );
552             }
553             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
554             pb->empty = FALSE;
555         } else {
556             // nothing
557         }
558         nr_pixblock_release(&m);
559     }
561     return ret;
564 static unsigned int
565 nr_arena_glyphs_group_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
567     NRArenaGroup *group = NR_ARENA_GROUP(item);
569     guint ret = item->state;
571     /* Render children fill mask */
572     for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
573         ret = nr_arena_glyphs_fill_mask(NR_ARENA_GLYPHS(child), area, pb);
574         if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) return ret;
575     }
577     return ret;
580 static NRArenaItem *
581 nr_arena_glyphs_group_pick(NRArenaItem *item, NR::Point p, gdouble delta, unsigned int sticky)
583     NRArenaItem *picked = NULL;
585     if (((NRArenaItemClass *) group_parent_class)->pick)
586         picked = ((NRArenaItemClass *) group_parent_class)->pick(item, p, delta, sticky);
588     if (picked) picked = item;
590     return picked;
593 void
594 nr_arena_glyphs_group_clear(NRArenaGlyphsGroup *sg)
596     NRArenaGroup *group = NR_ARENA_GROUP(sg);
598     nr_arena_item_request_render(NR_ARENA_ITEM(group));
600     while (group->children) {
601         nr_arena_item_remove_child(NR_ARENA_ITEM(group), group->children);
602     }
605 void
606 nr_arena_glyphs_group_add_component(NRArenaGlyphsGroup *sg, font_instance *font, int glyph, NR::Matrix const *transform)
608     NRArenaGroup *group;
609     NRBPath bpath;
611     group = NR_ARENA_GROUP(sg);
613     bpath.path = ( font
614                    ? (NArtBpath *) font->ArtBPath(glyph)
615                    : NULL );
616     if ( bpath.path ) {
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 :