• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作図ソフト dia の改良版


Commit MetaInfo

Revision7e7327a576fd001f03fd0fc24980d2b74ec94021 (tree)
Zeit2014-09-14 21:12:37
AutorHans Breuer <hans@breu...>
CommiterHans Breuer

Log Message

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.

Ändern Zusammenfassung

Diff

--- a/lib/group.c
+++ b/lib/group.c
@@ -895,3 +895,9 @@ group_transform (Group *group, const DiaMatrix *m)
895895 }
896896 group_update_data (group);
897897 }
898+
899+const DiaMatrix *
900+group_get_transform (Group *group)
901+{
902+ return group->matrix;
903+}
--- a/lib/group.h
+++ b/lib/group.h
@@ -34,6 +34,8 @@ GList *group_objects(DiaObject *group);
3434
3535 void group_destroy_shallow(DiaObject *group);
3636 void group_transform (Group *group, const DiaMatrix *mat);
37+const DiaMatrix *group_get_transform (Group *group);
38+
3739 #define IS_GROUP(obj) ((obj)->type == &group_type)
3840
3941 G_END_DECLS
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -486,6 +486,7 @@ EXPORTS
486486
487487 group_create
488488 group_create_with_matrix
489+ group_get_transform
489490 group_destroy_shallow
490491 group_objects
491492 group_type
--- a/plug-ins/svg/render_svg.c
+++ b/plug-ins/svg/render_svg.c
@@ -43,6 +43,7 @@
4343 #include "diagramdata.h"
4444 #include "dia_xml_libxml.h"
4545 #include "object.h"
46+#include "group.h"
4647 #include "textline.h"
4748 #include "dia_svg.h"
4849
@@ -333,28 +334,50 @@ draw_object(DiaRenderer *self,
333334 /* modifying the root pointer so everything below us gets into the new node */
334335 renderer->root = group = xmlNewNode (renderer->svg_name_space, (const xmlChar *)"g");
335336
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;
341351
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);
357356 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+ }
358381 }
359382 }
360383