[lasem/mml-attrs] [Mathml] Migration to lsm_attribute_manager WIP.



commit 59e4c445de4bde2f9d731136f0814b3c5dbb6182
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Tue Nov 17 23:24:04 2009 +0100

    [Mathml] Migration to lsm_attribute_manager WIP.
    
    lsm_mathml_unsigned_attribute
    lsm_mathml_double_attribute

 src/lsmmathmlattributes.c       |   16 ++++++++++++-
 src/lsmmathmlattributes.h       |   17 ++++++++++++--
 src/lsmmathmlstyleelement.c     |   13 ++++++++--
 src/lsmmathmltablecellelement.c |   36 ++++++++++++++++++++++++++-----
 src/lsmmathmltraits.c           |   45 +++++++++++++++++++++++++++++++++++++++
 src/lsmmathmltraits.h           |    2 +
 src/lsmmathmlunderoverelement.c |   12 +++++-----
 7 files changed, 121 insertions(+), 20 deletions(-)
---
diff --git a/src/lsmmathmlattributes.c b/src/lsmmathmlattributes.c
index f739ced..578387a 100644
--- a/src/lsmmathmlattributes.c
+++ b/src/lsmmathmlattributes.c
@@ -30,11 +30,22 @@
 #include <glib-object.h>
 #include <math.h>
 
-void
+gboolean
 lsm_mathml_boolean_attribute_inherit (LsmMathmlBooleanAttribute *attribute, gboolean value)
 {
 	if (attribute->base.value == NULL)
 		attribute->value = value;
+
+	return attribute->value;
+}
+
+double
+lsm_mathml_double_attribute_inherit (LsmMathmlDoubleAttribute *attribute, double value)
+{
+	if (attribute->base.value == NULL)
+		attribute->value = value;
+
+	return attribute->value;
 }
 
 /**************************/
@@ -374,7 +385,6 @@ lsm_mathml_boolean_attribute_parse (LsmMathmlBooleanAttribute *attribute,
 	attribute->value = (strcmp (string, "true") == 0);
 	*style_value = attribute->value;
 }
-#endif
 
 void
 lsm_mathml_unsigned_attribute_parse (LsmMathmlUnsignedAttribute *attribute,
@@ -414,6 +424,8 @@ lsm_mathml_double_attribute_parse (LsmMathmlDoubleAttribute *attribute,
 	*style_value = attribute->value;
 }
 
+#endif
+
 void
 lsm_mathml_string_attribute_parse (LsmMathmlStringAttribute *attribute,
 				char **style_value)
diff --git a/src/lsmmathmlattributes.h b/src/lsmmathmlattributes.h
index 8b8051c..2332c07 100644
--- a/src/lsmmathmlattributes.h
+++ b/src/lsmmathmlattributes.h
@@ -36,7 +36,18 @@ typedef struct {
 	gboolean value;
 } LsmMathmlBooleanAttribute;
 
-void		lsm_mathml_boolean_attribute_inherit (LsmMathmlBooleanAttribute *attribute, gboolean value);
+typedef struct {
+	LsmAttribute base;
+	unsigned int value;
+} LsmMathmlUnsignedAttribute;
+
+typedef struct {
+	LsmAttribute base;
+	double value;
+} LsmMathmlDoubleAttribute;
+
+gboolean	lsm_mathml_boolean_attribute_inherit 	(LsmMathmlBooleanAttribute *attribute, gboolean value);
+double 		lsm_mathml_double_attribute_inherit 	(LsmMathmlDoubleAttribute *attribute, double value);
 
 /*******************************/
 
@@ -120,7 +131,6 @@ typedef struct {
 	LsmMathmlAttribute attr;
 	gboolean value;
 } LsmMathmlBooleanAttribute;
-#endif
 
 typedef struct {
 	LsmMathmlAttribute attr;
@@ -132,6 +142,7 @@ typedef struct {
 	double value;
 } LsmMathmlDoubleAttribute;
 
+#endif
 typedef struct {
 	LsmMathmlAttribute attr;
 	char *value;
@@ -224,11 +235,11 @@ typedef struct {
 #if 0
 void 		lsm_mathml_boolean_attribute_parse	(LsmMathmlBooleanAttribute *attribute,
 							 gboolean *default_value);
-#endif
 void 		lsm_mathml_unsigned_attribute_parse	(LsmMathmlUnsignedAttribute *attribute,
 							 unsigned *default_value);
 void 		lsm_mathml_double_attribute_parse	(LsmMathmlDoubleAttribute *attribute,
 							 double *default_value);
+#endif
 void		lsm_mathml_string_attribute_parse	(LsmMathmlStringAttribute *attribute,
 							 char **default_value);
 void 		lsm_mathml_enum_attribute_parse 	(LsmMathmlEnumAttribute *attribute,
diff --git a/src/lsmmathmlstyleelement.c b/src/lsmmathmlstyleelement.c
index caf9477..b59a44f 100644
--- a/src/lsmmathmlstyleelement.c
+++ b/src/lsmmathmlstyleelement.c
@@ -50,7 +50,9 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 	lsm_mathml_boolean_attribute_inherit (&style_element->display_style, display_style);
 	style->display = style_element->display_style.value ? LSM_MATHML_DISPLAY_BLOCK : LSM_MATHML_DISPLAY_INLINE;
 
-	lsm_mathml_double_attribute_parse (&style_element->script_size_multiplier, &style->script_size_multiplier);
+/*        lsm_mathml_double_attribute_parse (&style_element->script_size_multiplier, &style->script_size_multiplier);*/
+	style->script_size_multiplier = lsm_mathml_double_attribute_inherit (&style_element->script_size_multiplier,
+									     style->script_size_multiplier);
 	lsm_mathml_color_attribute_parse (&style_element->math_background, &style->math_background);
 	lsm_mathml_length_attribute_parse (&style_element->script_min_size,
 					&style->script_min_size,
@@ -129,6 +131,11 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.name = "displaystyle",
 		.attribute_offset = offsetof (LsmMathmlStyleElement, display_style),
 		.trait_class = &lsm_mathml_boolean_trait_class
+	},
+	{
+		.name = "scriptsizemultiplier",
+		.attribute_offset = offsetof (LsmMathmlStyleElement, script_size_multiplier),
+		.trait_class = &lsm_mathml_double_trait_class
 	}
 };
 
@@ -155,8 +162,8 @@ lsm_mathml_style_element_class_init (LsmMathmlStyleElementClass *style_class)
 					  offsetof (LsmMathmlStyleElement, script_level));
 /*        lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "displaystyle",*/
 /*                                          offsetof (LsmMathmlStyleElement, display_style));*/
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "scriptsizemultiplier",
-					  offsetof (LsmMathmlStyleElement, script_size_multiplier));
+/*        lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "scriptsizemultiplier",*/
+/*                                          offsetof (LsmMathmlStyleElement, script_size_multiplier));*/
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "scriptminsize",
 					  offsetof (LsmMathmlStyleElement, script_min_size));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "background",
diff --git a/src/lsmmathmltablecellelement.c b/src/lsmmathmltablecellelement.c
index 88622a3..1292e2d 100644
--- a/src/lsmmathmltablecellelement.c
+++ b/src/lsmmathmltablecellelement.c
@@ -34,6 +34,7 @@ lsm_mathml_table_cell_get_node_name (LsmDomNode *node)
 
 /* LsmMathmlElement implementation */
 
+#if 0
 static void
 lsm_mathml_table_cell_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
@@ -46,6 +47,7 @@ lsm_mathml_table_cell_element_update (LsmMathmlElement *self, LsmMathmlStyle *st
 	span = 1;
 	lsm_mathml_unsigned_attribute_parse (&cell->column_span, &span);
 }
+#endif
 
 static const LsmMathmlBbox *
 lsm_mathml_table_cell_element_measure (LsmMathmlElement *self, LsmMathmlView *view, const LsmMathmlBbox *bbox)
@@ -82,6 +84,8 @@ lsm_mathml_table_cell_element_get_spans (const LsmMathmlTableCellElement *self,
 		*column_span = self->column_span.value;
 }
 
+static const unsigned int span_default = 1;
+
 LsmDomNode *
 lsm_mathml_table_cell_element_new (void)
 {
@@ -95,6 +99,21 @@ lsm_mathml_table_cell_element_init (LsmMathmlTableCellElement *self)
 
 /* LsmMathmlTableCellElement class */
 
+static const LsmAttributeInfos _attribute_infos[] = {
+	{
+		.name = "rowspan",
+		.attribute_offset = offsetof (LsmMathmlTableCellElement, row_span),
+		.trait_class = &lsm_mathml_unsigned_trait_class,
+		.trait_default = &span_default
+	},
+	{
+		.name = "columnspan",
+		.attribute_offset = offsetof (LsmMathmlTableCellElement, column_span),
+		.trait_class = &lsm_mathml_unsigned_trait_class,
+		.trait_default = &span_default
+	}
+};
+
 static void
 lsm_mathml_table_cell_element_class_init (LsmMathmlTableCellElementClass *table_cell_class)
 {
@@ -105,16 +124,21 @@ lsm_mathml_table_cell_element_class_init (LsmMathmlTableCellElementClass *table_
 
 	d_node_class->get_node_name = lsm_mathml_table_cell_get_node_name;
 
-	m_element_class->update = lsm_mathml_table_cell_element_update;
+/*        m_element_class->update = lsm_mathml_table_cell_element_update;*/
 	m_element_class->measure = lsm_mathml_table_cell_element_measure;
 	m_element_class->layout = lsm_mathml_table_cell_element_layout;
+	m_element_class->attribute_manager = lsm_attribute_manager_duplicate (m_element_class->attribute_manager);
+
+	lsm_attribute_manager_add_attributes (m_element_class->attribute_manager,
+					      G_N_ELEMENTS (_attribute_infos),
+					      _attribute_infos);
 
-	m_element_class->attributes = lsm_mathml_attribute_map_duplicate (m_element_class->attributes);
+/*        m_element_class->attributes = lsm_mathml_attribute_map_duplicate (m_element_class->attributes);*/
 
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "rowspan",
-					  offsetof (LsmMathmlTableCellElement, row_span));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "columnspan",
-					  offsetof (LsmMathmlTableCellElement, column_span));
+/*        lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "rowspan",*/
+/*                                          offsetof (LsmMathmlTableCellElement, row_span));*/
+/*        lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "columnspan",*/
+/*                                          offsetof (LsmMathmlTableCellElement, column_span));*/
 }
 
 G_DEFINE_TYPE (LsmMathmlTableCellElement, lsm_mathml_table_cell_element, LSM_TYPE_MATHML_ELEMENT)
diff --git a/src/lsmmathmltraits.c b/src/lsmmathmltraits.c
index e2c31a4..2de4614 100644
--- a/src/lsmmathmltraits.c
+++ b/src/lsmmathmltraits.c
@@ -22,6 +22,7 @@
 #include <lsmmathmltraits.h>
 #include <math.h>
 #include <string.h>
+#include <stdlib.h>
 
 static void
 lsm_mathml_boolean_trait_from_string (LsmTrait *abstract_trait, char *string)
@@ -44,3 +45,47 @@ const LsmTraitClass lsm_mathml_boolean_trait_class = {
 	.from_string = lsm_mathml_boolean_trait_from_string,
 	.to_string = lsm_mathml_boolean_trait_to_string
 };
+
+static void
+lsm_mathml_unsigned_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	unsigned int *value = (unsigned int *) abstract_trait;
+
+	*value = atoi (string);
+}
+
+static char *
+lsm_mathml_unsigned_trait_to_string (LsmTrait *abstract_trait)
+{
+	unsigned int *value = (unsigned int *) abstract_trait;
+
+	return g_strdup_printf ("%u", *value);
+}
+
+const LsmTraitClass lsm_mathml_unsigned_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_unsigned_trait_from_string,
+	.to_string = lsm_mathml_unsigned_trait_to_string
+};
+
+static void
+lsm_mathml_double_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	double *value = (double *) abstract_trait;
+
+	*value = atof (string);
+}
+
+static char *
+lsm_mathml_double_trait_to_string (LsmTrait *abstract_trait)
+{
+	double *value = (double *) abstract_trait;
+
+	return g_strdup_printf ("%g", *value);
+}
+
+const LsmTraitClass lsm_mathml_double_trait_class = {
+	.size = sizeof (double),
+	.from_string = lsm_mathml_double_trait_from_string,
+	.to_string = lsm_mathml_double_trait_to_string
+};
diff --git a/src/lsmmathmltraits.h b/src/lsmmathmltraits.h
index 8295f48..a8f73aa 100644
--- a/src/lsmmathmltraits.h
+++ b/src/lsmmathmltraits.h
@@ -27,6 +27,8 @@
 G_BEGIN_DECLS
 
 extern const LsmTraitClass lsm_mathml_boolean_trait_class;
+extern const LsmTraitClass lsm_mathml_unsigned_trait_class;
+extern const LsmTraitClass lsm_mathml_double_trait_class;
 
 G_END_DECLS
 
diff --git a/src/lsmmathmlunderoverelement.c b/src/lsmmathmlunderoverelement.c
index 047b192..6f7fff6 100644
--- a/src/lsmmathmlunderoverelement.c
+++ b/src/lsmmathmlunderoverelement.c
@@ -157,7 +157,7 @@ lsm_mathml_under_over_element_update_children (LsmMathmlElement *self, LsmMathml
 		}
 
 /*                lsm_mathml_boolean_attribute_parse (&under_over->accent_under, &accent_under);*/
-		lsm_mathml_boolean_attribute_inherit (&under_over->accent_under, accent_under);
+		accent_under = lsm_mathml_boolean_attribute_inherit (&under_over->accent_under, accent_under);
 
 		if (!under_over->accent_under.value)
 			lsm_mathml_style_change_script_level (style, +1);
@@ -179,7 +179,7 @@ lsm_mathml_under_over_element_update_children (LsmMathmlElement *self, LsmMathml
 		}
 
 /*                lsm_mathml_boolean_attribute_parse (&under_over->accent, &accent);*/
-		lsm_mathml_boolean_attribute_inherit (&under_over->accent, accent);
+		accent = lsm_mathml_boolean_attribute_inherit (&under_over->accent, accent);
 
 		if (!under_over->accent.value)
 			lsm_mathml_style_change_script_level (overscript_style, +1);
@@ -200,10 +200,10 @@ lsm_mathml_under_over_element_update_children (LsmMathmlElement *self, LsmMathml
 		}
 	}
 
-/*        under_over->under_space = accent_under ? accent_v_space : v_space;*/
-/*        under_over->over_space  = accent       ? accent_v_space : v_space;*/
-	under_over->under_space = under_over->accent_under.value ? accent_v_space : v_space;
-	under_over->over_space  = under_over->accent.value       ? accent_v_space : v_space;
+	under_over->under_space = accent_under ? accent_v_space : v_space;
+	under_over->over_space  = accent       ? accent_v_space : v_space;
+/*        under_over->under_space = under_over->accent_under.value ? accent_v_space : v_space;*/
+/*        under_over->over_space  = under_over->accent.value       ? accent_v_space : v_space;*/
 
 	under_over->as_script = under_over->display == LSM_MATHML_DISPLAY_INLINE && movable_limits;
 



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