fb7f572727d77e7801c9cfab30c27e265c9f7998
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)
101 {
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);
124 }
126 static guint
127 nr_arena_glyphs_update(NRArenaItem *item, NRRectL */*area*/, NRGC *gc, guint /*state*/, guint /*reset*/)
128 {
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 = static_cast<NR::ICoord>(floor(bbox.x0));
215 item->bbox.y0 = static_cast<NR::ICoord>(floor(bbox.y0));
216 item->bbox.x1 = static_cast<NR::ICoord>(ceil (bbox.x1));
217 item->bbox.y1 = static_cast<NR::ICoord>(ceil (bbox.y1));
219 return NR_ARENA_ITEM_STATE_ALL;
220 }
222 static guint
223 nr_arena_glyphs_clip(NRArenaItem *item, NRRectL */*area*/, NRPixBlock */*pb*/)
224 {
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;
234 }
236 static NRArenaItem *
237 nr_arena_glyphs_pick(NRArenaItem *item, Geom::Point p, gdouble delta, unsigned int /*sticky*/)
238 {
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 + delta >= item->bbox.x0) && (y + delta >= item->bbox.y0) && (x - delta <= item->bbox.x1) && (y - delta <= item->bbox.y1)) return item;
251 return NULL;
252 }
254 void
255 nr_arena_glyphs_set_path(NRArenaGlyphs *glyphs, SPCurve */*curve*/, unsigned int /*lieutenant*/, font_instance *font, gint glyph, Geom::Matrix const *transform)
256 {
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);
274 }
276 void
277 nr_arena_glyphs_set_style(NRArenaGlyphs *glyphs, SPStyle *style)
278 {
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);
287 }
289 static guint
290 nr_arena_glyphs_fill_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
291 {
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;
302 }
304 static guint
305 nr_arena_glyphs_stroke_mask(NRArenaGlyphs *glyphs, NRRectL *area, NRPixBlock *m)
306 {
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;
314 }
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)
329 {
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;
340 }
342 static void
343 nr_arena_glyphs_group_class_init(NRArenaGlyphsGroupClass *klass)
344 {
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;
360 }
362 static void
363 nr_arena_glyphs_group_init(NRArenaGlyphsGroup *group)
364 {
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;
371 }
373 static void
374 nr_arena_glyphs_group_finalize(NRObject *object)
375 {
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);
394 }
396 static guint
397 nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
398 {
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;
434 }
437 static unsigned int
438 nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int /*flags*/)
439 {
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;
447 bool print_colors_preview = (item->arena->rendermode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW);
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 }
516 if (print_colors_preview)
517 nr_arena_separate_color_plates(&rgba);
519 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
520 pb->empty = FALSE;
521 }
523 nr_pixblock_release(&m);
524 }
526 /* Stroke */
527 if (!style->stroke.isNone() && !(item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE)) {
528 NRPixBlock m;
529 guint32 rgba;
530 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
532 // if memory allocation failed, abort
533 if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) {
534 nr_pixblock_release (&m);
535 return (item->state);
536 }
538 m.visible_area = pb->visible_area;
539 /* Render children stroke mask */
540 for (child = group->children; child != NULL; child = child->next) {
541 ret = nr_arena_glyphs_stroke_mask(NR_ARENA_GLYPHS(child), area, &m);
542 if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) {
543 nr_pixblock_release(&m);
544 return ret;
545 }
546 }
547 /* Composite into buffer */
548 if (style->stroke.isPaintserver()) {
549 if (ggroup->stroke_painter) {
550 nr_arena_render_paintserver_fill(pb, area, ggroup->stroke_painter, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value), &m);
551 }
552 } else if (style->stroke.isColor()) {
553 if ( item->render_opacity ) {
554 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) *
555 SP_SCALE24_TO_FLOAT(style->opacity.value) );
556 } else {
557 rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) );
558 }
560 if (print_colors_preview)
561 nr_arena_separate_color_plates(&rgba);
563 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
564 pb->empty = FALSE;
565 } else {
566 // nothing
567 }
568 nr_pixblock_release(&m);
569 }
571 return ret;
572 }
574 static unsigned int
575 nr_arena_glyphs_group_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
576 {
577 NRArenaGroup *group = NR_ARENA_GROUP(item);
579 guint ret = item->state;
581 /* Render children fill mask */
582 for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
583 ret = nr_arena_glyphs_fill_mask(NR_ARENA_GLYPHS(child), area, pb);
584 if (!(ret & NR_ARENA_ITEM_STATE_RENDER)) return ret;
585 }
587 return ret;
588 }
590 static NRArenaItem *
591 nr_arena_glyphs_group_pick(NRArenaItem *item, Geom::Point p, gdouble delta, unsigned int sticky)
592 {
593 NRArenaItem *picked = NULL;
595 if (((NRArenaItemClass *) group_parent_class)->pick)
596 picked = ((NRArenaItemClass *) group_parent_class)->pick(item, p, delta, sticky);
598 if (picked) picked = item;
600 return picked;
601 }
603 void
604 nr_arena_glyphs_group_clear(NRArenaGlyphsGroup *sg)
605 {
606 NRArenaGroup *group = NR_ARENA_GROUP(sg);
608 nr_arena_item_request_render(NR_ARENA_ITEM(group));
610 while (group->children) {
611 nr_arena_item_remove_child(NR_ARENA_ITEM(group), group->children);
612 }
613 }
615 void
616 nr_arena_glyphs_group_add_component(NRArenaGlyphsGroup *sg, font_instance *font, int glyph, Geom::Matrix const &transform)
617 {
618 NRArenaGroup *group;
620 group = NR_ARENA_GROUP(sg);
622 Geom::PathVector const * pathv = ( font
623 ? font->PathVector(glyph)
624 : NULL );
625 if ( pathv ) {
626 nr_arena_item_request_render(NR_ARENA_ITEM(group));
628 NRArenaItem *new_arena = NRArenaGlyphs::create(group->arena);
629 nr_arena_item_append_child(NR_ARENA_ITEM(group), new_arena);
630 nr_arena_item_unref(new_arena);
631 nr_arena_glyphs_set_path(NR_ARENA_GLYPHS(new_arena), NULL, FALSE, font, glyph, &transform);
632 nr_arena_glyphs_set_style(NR_ARENA_GLYPHS(new_arena), sg->style);
633 }
634 }
636 void
637 nr_arena_glyphs_group_set_style(NRArenaGlyphsGroup *sg, SPStyle *style)
638 {
639 nr_return_if_fail(sg != NULL);
640 nr_return_if_fail(NR_IS_ARENA_GLYPHS_GROUP(sg));
642 NRArenaGroup *group = NR_ARENA_GROUP(sg);
644 if (style) sp_style_ref(style);
645 if (sg->style) sp_style_unref(sg->style);
646 sg->style = style;
648 for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
649 nr_return_if_fail(NR_IS_ARENA_GLYPHS(child));
650 nr_arena_glyphs_set_style(NR_ARENA_GLYPHS(child), sg->style);
651 }
653 nr_arena_item_request_update(NR_ARENA_ITEM(sg), NR_ARENA_ITEM_STATE_ALL, FALSE);
654 }
656 void
657 nr_arena_glyphs_group_set_paintbox(NRArenaGlyphsGroup *gg, NRRect const *pbox)
658 {
659 nr_return_if_fail(gg != NULL);
660 nr_return_if_fail(NR_IS_ARENA_GLYPHS_GROUP(gg));
661 nr_return_if_fail(pbox != NULL);
663 if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
664 gg->paintbox.x0 = pbox->x0;
665 gg->paintbox.y0 = pbox->y0;
666 gg->paintbox.x1 = pbox->x1;
667 gg->paintbox.y1 = pbox->y1;
668 } else {
669 /* fixme: We kill warning, although not sure what to do here (Lauris) */
670 gg->paintbox.x0 = gg->paintbox.y0 = 0.0F;
671 gg->paintbox.x1 = gg->paintbox.y1 = 256.0F;
672 }
674 nr_arena_item_request_update(NR_ARENA_ITEM(gg), NR_ARENA_ITEM_STATE_ALL, FALSE);
675 }
678 /*
679 Local Variables:
680 mode:c++
681 c-file-style:"stroustrup"
682 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
683 indent-tabs-mode:nil
684 fill-column:99
685 End:
686 */
687 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :