作図ソフト dia の改良版
Révision | 7e7327a576fd001f03fd0fc24980d2b74ec94021 (tree) |
---|---|
l'heure | 2014-09-14 21:12:37 |
Auteur | Hans Breuer <hans@breu...> |
Commiter | Hans Breuer |
svg: optimize SvgRenderer::draw_object() with matrix
by inlining the group drwaing we can create a single transform for the
whole group rather than transformation groups for every object in it.
@@ -895,3 +895,9 @@ group_transform (Group *group, const DiaMatrix *m) | ||
895 | 895 | } |
896 | 896 | group_update_data (group); |
897 | 897 | } |
898 | + | |
899 | +const DiaMatrix * | |
900 | +group_get_transform (Group *group) | |
901 | +{ | |
902 | + return group->matrix; | |
903 | +} |
@@ -34,6 +34,8 @@ GList *group_objects(DiaObject *group); | ||
34 | 34 | |
35 | 35 | void group_destroy_shallow(DiaObject *group); |
36 | 36 | void group_transform (Group *group, const DiaMatrix *mat); |
37 | +const DiaMatrix *group_get_transform (Group *group); | |
38 | + | |
37 | 39 | #define IS_GROUP(obj) ((obj)->type == &group_type) |
38 | 40 | |
39 | 41 | G_END_DECLS |
@@ -486,6 +486,7 @@ EXPORTS | ||
486 | 486 | |
487 | 487 | group_create |
488 | 488 | group_create_with_matrix |
489 | + group_get_transform | |
489 | 490 | group_destroy_shallow |
490 | 491 | group_objects |
491 | 492 | group_type |
@@ -43,6 +43,7 @@ | ||
43 | 43 | #include "diagramdata.h" |
44 | 44 | #include "dia_xml_libxml.h" |
45 | 45 | #include "object.h" |
46 | +#include "group.h" | |
46 | 47 | #include "textline.h" |
47 | 48 | #include "dia_svg.h" |
48 | 49 |
@@ -333,28 +334,50 @@ draw_object(DiaRenderer *self, | ||
333 | 334 | /* modifying the root pointer so everything below us gets into the new node */ |
334 | 335 | renderer->root = group = xmlNewNode (renderer->svg_name_space, (const xmlChar *)"g"); |
335 | 336 | |
336 | - if (matrix) { | |
337 | - gchar *s = dia_svg_from_matrix (matrix, renderer->scale); | |
338 | - xmlSetProp(renderer->root, (const xmlChar *)"transform", (xmlChar *) s); | |
339 | - g_free (s); | |
340 | - } | |
337 | + if (IS_GROUP (object) && !matrix) { | |
338 | + /* group_draw() is applying it's matrix to every child, but we can do | |
339 | + * better with inline version of group drawing | |
340 | + */ | |
341 | + const DiaMatrix *gm = group_get_transform ((Group *)object); | |
342 | + GList *objs = group_objects (object); | |
343 | + | |
344 | + if (gm) { | |
345 | + gchar *s = dia_svg_from_matrix (gm, renderer->scale); | |
346 | + xmlSetProp(renderer->root, (const xmlChar *)"transform", (xmlChar *) s); | |
347 | + g_free (s); | |
348 | + } | |
349 | + while (objs) { | |
350 | + DiaObject *obj = (DiaObject *)objs->data; | |
341 | 351 | |
342 | - object->ops->draw(object, DIA_RENDERER (renderer)); | |
343 | - | |
344 | - /* no easy way to count? */ | |
345 | - child = renderer->root->children; | |
346 | - while (child != NULL) { | |
347 | - child = child->next; | |
348 | - ++n_children; | |
349 | - } | |
350 | - renderer->root = g_queue_pop_tail (svg_renderer->parents); | |
351 | - /* if there is only one element added to the group node unpack it again */ | |
352 | - if (1 == n_children && !matrix) { | |
353 | - xmlAddChild (renderer->root, group->children); | |
354 | - xmlUnlinkNode (group); /* dont free the children */ | |
355 | - xmlFree (group); | |
356 | - } else { | |
352 | + obj->ops->draw(obj, DIA_RENDERER (renderer)); | |
353 | + objs = objs->next; | |
354 | + } | |
355 | + renderer->root = g_queue_pop_tail (svg_renderer->parents); | |
357 | 356 | xmlAddChild (renderer->root, group); |
357 | + } else { | |
358 | + if (matrix) { | |
359 | + gchar *s = dia_svg_from_matrix (matrix, renderer->scale); | |
360 | + xmlSetProp(renderer->root, (const xmlChar *)"transform", (xmlChar *) s); | |
361 | + g_free (s); | |
362 | + } | |
363 | + | |
364 | + object->ops->draw(object, DIA_RENDERER (renderer)); | |
365 | + | |
366 | + /* no easy way to count? */ | |
367 | + child = renderer->root->children; | |
368 | + while (child != NULL) { | |
369 | + child = child->next; | |
370 | + ++n_children; | |
371 | + } | |
372 | + renderer->root = g_queue_pop_tail (svg_renderer->parents); | |
373 | + /* if there is only one element added to the group node unpack it again */ | |
374 | + if (1 == n_children && !matrix) { | |
375 | + xmlAddChild (renderer->root, group->children); | |
376 | + xmlUnlinkNode (group); /* dont free the children */ | |
377 | + xmlFree (group); | |
378 | + } else { | |
379 | + xmlAddChild (renderer->root, group); | |
380 | + } | |
358 | 381 | } |
359 | 382 | } |
360 | 383 |