[lasem] mpadded: basic support of mpadded attributes



commit 3c5ada40bb1862ed0aeb64058d128679eb12d2cf
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Wed Feb 4 00:25:21 2015 +0100

    mpadded: basic support of mpadded attributes

 src/lsmmathmlpaddedelement.c |   79 ++++++++++++++++++++++++++++++++++++++++++
 src/lsmmathmlpaddedelement.h |    5 +++
 2 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/src/lsmmathmlpaddedelement.c b/src/lsmmathmlpaddedelement.c
index daba1e8..a81a08a 100644
--- a/src/lsmmathmlpaddedelement.c
+++ b/src/lsmmathmlpaddedelement.c
@@ -23,6 +23,8 @@
 
 #include <lsmmathmlpaddedelement.h>
 
+static GObjectClass *parent_class;
+
 /* LsmDomNode implementation */
 
 static const char *
@@ -31,6 +33,44 @@ lsm_mathml_padded_element_get_node_name (LsmDomNode *node)
        return "mpadded";
 }
 
+/* LsmMathmlElement implementation */
+
+static const LsmMathmlLength length_default = {0.0, LSM_MATHML_UNIT_PT};
+
+static void
+_update (LsmMathmlElement *self, LsmMathmlStyle *style)
+{
+       LsmMathmlPaddedElement *padded = LSM_MATHML_PADDED_ELEMENT (self);
+
+       lsm_mathml_length_attribute_normalize (&padded->height, 0.0, &length_default, style);
+       lsm_mathml_length_attribute_normalize (&padded->depth, 0.0, &length_default, style);
+       lsm_mathml_length_attribute_normalize (&padded->width, 0.0, &length_default, style);
+       lsm_mathml_length_attribute_normalize (&padded->left_space, 0.0, &length_default, style);
+}
+
+static const LsmMathmlBbox *
+_measure (LsmMathmlElement *self, LsmMathmlView *view, const LsmMathmlBbox *bbox)
+{
+       LsmMathmlPaddedElement *padded = LSM_MATHML_PADDED_ELEMENT (self);
+
+       LSM_MATHML_ELEMENT_CLASS (parent_class)->measure (self, view, bbox);
+
+       self->bbox.height += padded->height.value;
+       self->bbox.depth += padded->depth.value;
+       self->bbox.width += padded->width.value + padded->left_space.value;
+
+       return &self->bbox;
+}
+
+static void
+_layout (LsmMathmlElement *self, LsmMathmlView *view,
+        double x, double y, const LsmMathmlBbox *bbox)
+{
+       LsmMathmlPaddedElement *padded = LSM_MATHML_PADDED_ELEMENT (self);
+
+       LSM_MATHML_ELEMENT_CLASS (parent_class)->layout (self, view, x + padded->left_space.value, y, bbox);
+}
+
 /* LsmMathmlPaddedElement implementation */
 
 LsmDomNode *
@@ -46,12 +86,51 @@ lsm_mathml_padded_element_init (LsmMathmlPaddedElement *element)
 
 /* LsmMathmlPaddedElement class */
 
+static const LsmAttributeInfos _attribute_infos[] = {
+       {
+               .name = "height",
+               .attribute_offset = offsetof (LsmMathmlPaddedElement, height),
+               .trait_class = &lsm_mathml_length_trait_class,
+               .trait_default = &length_default
+       },
+       {
+               .name = "depth",
+               .attribute_offset = offsetof (LsmMathmlPaddedElement, depth),
+               .trait_class = &lsm_mathml_length_trait_class,
+               .trait_default = &length_default
+       },
+       {
+               .name = "width",
+               .attribute_offset = offsetof (LsmMathmlPaddedElement, width),
+               .trait_class = &lsm_mathml_length_trait_class,
+               .trait_default = &length_default
+       },
+       {
+               .name = "lspace",
+               .attribute_offset = offsetof (LsmMathmlPaddedElement, left_space),
+               .trait_class = &lsm_mathml_length_trait_class,
+               .trait_default = &length_default
+       }
+};
+
 static void
 lsm_mathml_padded_element_class_init (LsmMathmlPaddedElementClass *klass)
 {
        LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (klass);
+       LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_CLASS (klass);
+
+       parent_class = g_type_class_peek_parent (klass);
 
        d_node_class->get_node_name = lsm_mathml_padded_element_get_node_name;
+
+       m_element_class->attribute_manager = lsm_attribute_manager_duplicate 
(m_element_class->attribute_manager);
+       m_element_class->update = _update;
+       m_element_class->measure = _measure;
+       m_element_class->layout = _layout;
+
+       lsm_attribute_manager_add_attributes (m_element_class->attribute_manager,
+                                             G_N_ELEMENTS (_attribute_infos),
+                                             _attribute_infos);
 }
 
 G_DEFINE_TYPE (LsmMathmlPaddedElement, lsm_mathml_padded_element, LSM_TYPE_MATHML_PRESENTATION_CONTAINER)
diff --git a/src/lsmmathmlpaddedelement.h b/src/lsmmathmlpaddedelement.h
index 0d8db90..c597412 100644
--- a/src/lsmmathmlpaddedelement.h
+++ b/src/lsmmathmlpaddedelement.h
@@ -40,6 +40,11 @@ typedef struct _LsmMathmlPaddedElementClass LsmMathmlPaddedElementClass;
 
 struct _LsmMathmlPaddedElement {
        LsmMathmlPresentationContainer presentation_container;
+
+       LsmMathmlLengthAttribute height;
+       LsmMathmlLengthAttribute depth;
+       LsmMathmlLengthAttribute width;
+       LsmMathmlLengthAttribute left_space;
 };
 
 struct _LsmMathmlPaddedElementClass {


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