[lasem] svg_symbol: implement overflow, viewBox and preserveAspectRatio



commit 7fc6af7f442d58aaf681f4f4ded935a2838aea37
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Fri Mar 6 00:05:49 2015 +0100

    svg_symbol: implement overflow, viewBox and preserveAspectRatio

 src/lsmsvgsymbolelement.c |   74 +++++++++++++++++++++++++++++++++++++++++++++
 src/lsmsvgsymbolelement.h |    3 ++
 src/lsmsvguseelement.c    |   19 ++++++-----
 3 files changed, 87 insertions(+), 9 deletions(-)
---
diff --git a/src/lsmsvgsymbolelement.c b/src/lsmsvgsymbolelement.c
index 744f3c8..fa75ee8 100644
--- a/src/lsmsvgsymbolelement.c
+++ b/src/lsmsvgsymbolelement.c
@@ -22,7 +22,9 @@
  */
 
 #include <lsmsvgsymbolelement.h>
+#include <lsmsvguseelement.h>
 #include <lsmsvgview.h>
+#include <lsmsvgtraits.h>
 #include <lsmdebug.h>
 #include <lsmdomdocument.h>
 #include <stdio.h>
@@ -41,6 +43,49 @@ lsm_svg_symbol_element_get_node_name (LsmDomNode *node)
 
 /* LsmSvgGraphic implementation */
 
+static void
+_symbol_element_render (LsmSvgElement *self, LsmSvgView *view)
+{
+       LsmSvgSymbolElement *symbol = LSM_SVG_SYMBOL_ELEMENT (self);
+       LsmSvgUseElement *use_element;
+       LsmSvgElement *element;
+       LsmSvgStyle *style;
+       LsmBox viewport;
+       gboolean is_viewbox_defined;
+
+       element = lsm_svg_view_get_referencing_element (view);
+       if (!LSM_IS_SVG_USE_ELEMENT (element))
+               return;
+
+       use_element = LSM_SVG_USE_ELEMENT (element);
+
+       style = lsm_svg_view_get_current_style (view);
+
+       viewport.x = 0;
+       viewport.y = 0;
+       viewport.width = lsm_svg_view_normalize_length (view, &use_element->width.length, 
LSM_SVG_LENGTH_DIRECTION_HORIZONTAL);
+       viewport.height = lsm_svg_view_normalize_length (view, &use_element->height.length, 
LSM_SVG_LENGTH_DIRECTION_VERTICAL);
+
+       is_viewbox_defined = lsm_attribute_is_defined ((LsmAttribute *) &symbol->viewbox);
+
+       if (is_viewbox_defined && (symbol->viewbox.value.width == 0.0 ||
+                                  symbol->viewbox.value.height == 0.0))
+               return;
+
+       if (viewport.width <= 0.0 || viewport.height <= 0.0)
+               return;
+
+       lsm_debug_render ("[LsmSvgSymbolElement::render] viewport %g, %g, %g, %g",
+                  viewport.x, viewport.y, viewport.width, viewport.height);
+
+       lsm_svg_view_push_viewport (view, &viewport, is_viewbox_defined ? &symbol->viewbox.value : NULL,
+                                   &symbol->preserve_aspect_ratio.value, style->overflow->value);
+
+       LSM_SVG_ELEMENT_CLASS (parent_class)->render (self, view);
+
+       lsm_svg_view_pop_viewport (view);
+}
+
 /* LsmSvgSymbolElement implementation */
 
 LsmDomNode *
@@ -49,6 +94,13 @@ lsm_svg_symbol_element_new (void)
        return g_object_new (LSM_TYPE_SVG_SYMBOL_ELEMENT, NULL);
 }
 
+static const LsmBox viewbox_default =           {0.0, 0.0, 0.0, 0.0};
+static const LsmSvgPreserveAspectRatio preserve_aspect_ratio_default = {
+       .defer = FALSE,
+       .align = LSM_SVG_ALIGN_X_MID_Y_MID,
+       .meet_or_slice = LSM_SVG_MEET_OR_SLICE_MEET
+};
+
 static void
 lsm_svg_symbol_element_init (LsmSvgSymbolElement *self)
 {
@@ -56,6 +108,21 @@ lsm_svg_symbol_element_init (LsmSvgSymbolElement *self)
 
 /* LsmSvgSymbolElement class */
 
+static const LsmAttributeInfos lsm_svg_symbol_element_attribute_infos[] = {
+       {
+               .name = "viewBox",
+               .attribute_offset = offsetof (LsmSvgSymbolElement, viewbox),
+               .trait_class = &lsm_box_trait_class,
+               .trait_default = &viewbox_default
+       },
+       {
+               .name = "preserveAspectRatio",
+               .attribute_offset = offsetof (LsmSvgSymbolElement, preserve_aspect_ratio),
+               .trait_class = &lsm_svg_preserve_aspect_ratio_trait_class,
+               .trait_default = &preserve_aspect_ratio_default
+       }
+};
+
 static void
 lsm_svg_symbol_element_class_init (LsmSvgSymbolElementClass *klass)
 {
@@ -69,6 +136,13 @@ lsm_svg_symbol_element_class_init (LsmSvgSymbolElementClass *klass)
        s_element_class->category =
                LSM_SVG_ELEMENT_CATEGORY_CONTAINER |
                LSM_SVG_ELEMENT_CATEGORY_STRUCTURAL;
+
+       s_element_class->render = _symbol_element_render;
+       s_element_class->attribute_manager = lsm_attribute_manager_duplicate 
(s_element_class->attribute_manager);
+
+       lsm_attribute_manager_add_attributes (s_element_class->attribute_manager,
+                                             G_N_ELEMENTS (lsm_svg_symbol_element_attribute_infos),
+                                             lsm_svg_symbol_element_attribute_infos);
 }
 
 G_DEFINE_TYPE (LsmSvgSymbolElement, lsm_svg_symbol_element, LSM_TYPE_SVG_ELEMENT)
diff --git a/src/lsmsvgsymbolelement.h b/src/lsmsvgsymbolelement.h
index 907826c..5f6534a 100644
--- a/src/lsmsvgsymbolelement.h
+++ b/src/lsmsvgsymbolelement.h
@@ -40,6 +40,9 @@ typedef struct _LsmSvgSymbolElementClass LsmSvgSymbolElementClass;
 
 struct _LsmSvgSymbolElement {
        LsmSvgElement element;
+
+       LsmSvgViewboxAttribute                  viewbox;
+       LsmSvgPreserveAspectRatioAttribute      preserve_aspect_ratio;
 };
 
 struct _LsmSvgSymbolElementClass {
diff --git a/src/lsmsvguseelement.c b/src/lsmsvguseelement.c
index 22adfd3..bb0406f 100644
--- a/src/lsmsvguseelement.c
+++ b/src/lsmsvguseelement.c
@@ -164,15 +164,16 @@ lsm_svg_use_element_new (void)
        return g_object_new (LSM_TYPE_SVG_USE_ELEMENT, NULL);
 }
 
-static const LsmSvgLength length_default =      { .value_unit =   0.0, .type = LSM_SVG_LENGTH_TYPE_PX};
+static const LsmSvgLength position_default =    { .value_unit =   0.0, .type = LSM_SVG_LENGTH_TYPE_PX};
+static const LsmSvgLength size_default =        { .value_unit =   100.0, .type = 
LSM_SVG_LENGTH_TYPE_PERCENTAGE};
 
 static void
 lsm_svg_use_element_init (LsmSvgUseElement *self)
 {
-       self->x.length = length_default;
-       self->y.length = length_default;
-       self->width.length = length_default;
-       self->height.length = length_default;
+       self->x.length = position_default;
+       self->y.length = position_default;
+       self->width.length = size_default;
+       self->height.length = size_default;
 }
 
 /* LsmSvgUseElement class */
@@ -182,25 +183,25 @@ static const LsmAttributeInfos lsm_svg_use_element_attribute_infos[] = {
                .name = "x",
                .attribute_offset = offsetof (LsmSvgUseElement, x),
                .trait_class = &lsm_svg_length_trait_class,
-               .trait_default = &length_default
+               .trait_default = &position_default
        },
        {
                .name = "y",
                .attribute_offset = offsetof (LsmSvgUseElement, y),
                .trait_class = &lsm_svg_length_trait_class,
-               .trait_default = &length_default
+               .trait_default = &position_default
        },
        {
                .name = "width",
                .attribute_offset = offsetof (LsmSvgUseElement, width),
                .trait_class = &lsm_svg_length_trait_class,
-               .trait_default = &length_default
+               .trait_default = &size_default
        },
        {
                .name = "height",
                .attribute_offset = offsetof (LsmSvgUseElement, height),
                .trait_class = &lsm_svg_length_trait_class,
-               .trait_default = &length_default
+               .trait_default = &size_default
        },
        {
                .name = "xlink:href",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]