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



commit 726b3cd6242b2386c1aa0d864377d0694af04488
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Thu Dec 31 16:58:12 2009 +0100

    [Mathml] Migration to lsm_attribute_manager WIP.
    
    lsm_mathml_space_attribute

 src/lsmmathmlattributes.c        |  132 +++++++++++++++----------------------
 src/lsmmathmlattributes.h        |   25 ++++----
 src/lsmmathmlfractionelement.c   |    8 ++-
 src/lsmmathmloperatorelement.c   |   59 ++++++++++-------
 src/lsmmathmlpresentationtoken.c |   10 ++-
 src/lsmmathmlscriptelement.c     |   13 ++--
 src/lsmmathmlspaceelement.c      |   36 +++++-----
 src/lsmmathmlstyleelement.c      |   37 +++++++----
 src/lsmmathmltraits.c            |   44 ++++++++++++-
 src/lsmmathmltraits.h            |    5 +-
 10 files changed, 206 insertions(+), 163 deletions(-)
---
diff --git a/src/lsmmathmlattributes.c b/src/lsmmathmlattributes.c
index 4a369f6..72640b6 100644
--- a/src/lsmmathmlattributes.c
+++ b/src/lsmmathmlattributes.c
@@ -20,6 +20,7 @@
  */
 
 #include <lsmmathmlattributes.h>
+#include <lsmmathmlstyle.h>
 
 gboolean
 lsm_mathml_boolean_attribute_inherit (LsmMathmlBooleanAttribute *attribute, gboolean value)
@@ -86,11 +87,60 @@ lsm_mathml_script_level_attribute_apply	(LsmMathmlScriptLevelAttribute *attribut
 }
 
 double
-lsm_mathml_length_attribute_normalize (LsmMathmlLengthAttribute *attribute, double default_value, double font_size)
+lsm_mathml_length_attribute_normalize (LsmMathmlLengthAttribute *attribute,
+				       const LsmMathmlLength *default_value,
+				       const LsmMathmlStyle *style)
 {
 	g_return_val_if_fail (attribute != NULL, 0.0);
 
-	attribute->value = lsm_mathml_length_normalize (&attribute->length, default_value, font_size);
+	attribute->value = lsm_mathml_length_normalize (&attribute->length, default_value, style->math_size);
+
+	return attribute->value;
+}
+
+double
+lsm_mathml_space_attribute_normalize (LsmMathmlSpaceAttribute *attribute,
+				      const LsmMathmlSpace *default_value,
+				      const LsmMathmlStyle *style)
+{
+	g_return_val_if_fail (attribute != NULL, 0.0);
+	g_return_val_if_fail (default_value != NULL, 0.0);
+	g_return_val_if_fail (style != NULL, 0.0);
+
+	if (attribute->base.value == NULL)
+		attribute->space = *default_value;
+
+	switch (attribute->space.name) {
+		case LSM_MATHML_SPACE_NAME_VERY_VERY_THIN:
+			attribute->value = style->very_very_thin_math_space;
+			break;
+		case LSM_MATHML_SPACE_NAME_VERY_THIN:
+			attribute->value = style->very_thin_math_space;
+			break;
+		case LSM_MATHML_SPACE_NAME_THIN:
+			attribute->value = style->thin_math_space;
+			break;
+		case LSM_MATHML_SPACE_NAME_MEDIUM:
+			attribute->value = style->medium_math_space;
+			break;
+		case LSM_MATHML_SPACE_NAME_THICK:
+			attribute->value = style->thick_math_space;
+			break;
+		case LSM_MATHML_SPACE_NAME_VERY_THICK:
+			attribute->value = style->very_thick_math_space;
+			break;
+		case LSM_MATHML_SPACE_NAME_VERY_VERY_THICK:
+			attribute->value = style->very_very_thick_math_space;
+			break;
+		case LSM_MATHML_SPACE_NAME_INFINITY:
+			attribute->value = G_MAXDOUBLE;
+			break;
+		case LSM_MATHML_SPACE_NAME_ERROR:
+		default:
+			attribute->value = lsm_mathml_length_normalize (&attribute->space.length,
+									&default_value->length,
+									style->math_size);
+	}
 
 	return attribute->value;
 }
@@ -505,80 +555,6 @@ lsm_mathml_attribute_map_add_enum_list (LsmMathmlAttributeMap *map,
 	lsm_mathml_attribute_map_add_attribute_full (map, name, offset, &enum_list_attribute_class);
 }
 
-void
-lsm_mathml_space_attribute_parse (LsmMathmlSpaceAttribute *attribute,
-				  LsmMathmlSpace *style_value,
-				  LsmMathmlStyle *style)
-{
-	const char *string;
-
-	g_return_if_fail (attribute != NULL);
-	g_return_if_fail (style != NULL);
-
-	string = lsm_mathml_attribute_get_value ((LsmMathmlAttribute *) attribute);
-	if (string == NULL) {
-		attribute->space = *style_value;
-	} else {
-		attribute->space.name = lsm_mathml_space_name_from_string (string);
-		if (attribute->space.name == LSM_MATHML_SPACE_NAME_ERROR) {
-			LsmMathmlUnit unit;
-			char *unit_str;
-			double value;
-
-			value = g_strtod (string, &unit_str);
-			unit = lsm_mathml_unit_from_string (unit_str);
-
-			if (unit == LSM_MATHML_UNIT_NONE) {
-				unit = style_value->length.unit;
-				value *= style_value->length.value;
-			} else if (unit == LSM_MATHML_UNIT_PERCENT) {
-				unit = style_value->length.unit;
-				value *= style_value->length.value / 100.0;
-			}
-
-			attribute->space.length.unit = unit;
-			attribute->space.length.value = value;
-		} else {
-			attribute->space.length.value = 0.0;
-			attribute->space.length.unit = LSM_MATHML_UNIT_PX;
-		}
-
-		*style_value = attribute->space;
-	}
-
-	switch (attribute->space.name) {
-		case LSM_MATHML_SPACE_NAME_VERY_VERY_THIN:
-			attribute->value = style->very_very_thin_math_space;
-			break;
-		case LSM_MATHML_SPACE_NAME_VERY_THIN:
-			attribute->value = style->very_thin_math_space;
-			break;
-		case LSM_MATHML_SPACE_NAME_THIN:
-			attribute->value = style->thin_math_space;
-			break;
-		case LSM_MATHML_SPACE_NAME_MEDIUM:
-			attribute->value = style->medium_math_space;
-			break;
-		case LSM_MATHML_SPACE_NAME_THICK:
-			attribute->value = style->thick_math_space;
-			break;
-		case LSM_MATHML_SPACE_NAME_VERY_THICK:
-			attribute->value = style->very_thick_math_space;
-			break;
-		case LSM_MATHML_SPACE_NAME_VERY_VERY_THICK:
-			attribute->value = style->very_very_thick_math_space;
-			break;
-		case LSM_MATHML_SPACE_NAME_INFINITY:
-			attribute->value = G_MAXDOUBLE;
-			break;
-		case LSM_MATHML_SPACE_NAME_ERROR:
-		default:
-			attribute->value = lsm_mathml_length_normalize (&attribute->space.length,
-									style_value->length.value,
-									style->math_size);
-	}
-}
-
 static void
 lsm_mathml_space_list_attribute_finalize (void *abstract)
 {
@@ -695,12 +671,12 @@ lsm_mathml_space_list_attribute_parse (LsmMathmlSpaceListAttribute *attribute,
 
 					attribute->values[i] = lsm_mathml_length_normalize
 						(&attribute->space_list->spaces[i].length,
-						 style_value->spaces[index].length.value,
+						 &style_value->spaces[index].length,
 						 style->math_size);
 				} else
 					attribute->values[i] = lsm_mathml_length_normalize
 						(&attribute->space_list->spaces[i].length,
-						 0.0,
+						 NULL,
 						 style->math_size);
 		}
 	}
diff --git a/src/lsmmathmlattributes.h b/src/lsmmathmlattributes.h
index 5be5f7d..cd2a491 100644
--- a/src/lsmmathmlattributes.h
+++ b/src/lsmmathmlattributes.h
@@ -85,8 +85,19 @@ typedef struct {
         double value;
 } LsmMathmlLengthAttribute;
 
-double 		lsm_mathml_length_attribute_normalize	(LsmMathmlLengthAttribute *atribute, double default_value,
-							 double font_size);
+double 		lsm_mathml_length_attribute_normalize	(LsmMathmlLengthAttribute *atribute,
+							 const LsmMathmlLength *default_value,
+							 const LsmMathmlStyle *style);
+
+typedef struct {
+	LsmAttribute base;
+	LsmMathmlSpace space;
+	double value;
+} LsmMathmlSpaceAttribute;
+
+double 		lsm_mathml_space_attribute_normalize 	(LsmMathmlSpaceAttribute *attribute,
+							 const LsmMathmlSpace *default_value,
+							 const LsmMathmlStyle *style);
 
 /*******************************/
 
@@ -170,12 +181,6 @@ typedef struct {
 
 typedef struct {
 	LsmMathmlAttribute attr;
-	LsmMathmlSpace space;
-	double value;
-} LsmMathmlSpaceAttribute;
-
-typedef struct {
-	LsmMathmlAttribute attr;
 	LsmMathmlSpaceList *space_list;
 	double *values;
 } LsmMathmlSpaceListAttribute;
@@ -191,10 +196,6 @@ void 		lsm_mathml_attribute_map_add_enum_list 	(LsmMathmlAttributeMap *map,
 							 char const *name,
 							 ptrdiff_t offset);
 
-void 		lsm_mathml_space_attribute_parse 	(LsmMathmlSpaceAttribute *attribute,
-							 LsmMathmlSpace *style_value,
-							 LsmMathmlStyle *style);
-
 void 		lsm_mathml_space_list_attribute_parse 	(LsmMathmlSpaceListAttribute *attribute,
 							 LsmMathmlSpaceList *style_value,
 							 const LsmMathmlStyle *style);
diff --git a/src/lsmmathmlfractionelement.c b/src/lsmmathmlfractionelement.c
index 469fcca..7afcc34 100644
--- a/src/lsmmathmlfractionelement.c
+++ b/src/lsmmathmlfractionelement.c
@@ -47,10 +47,12 @@ static void
 lsm_mathml_fraction_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
 	LsmMathmlFractionElement *fraction = LSM_MATHML_FRACTION_ELEMENT (self);
+	LsmMathmlLength length;
 
-	style->line_thickness = lsm_mathml_length_attribute_normalize (&fraction->line_thickness,
-								       style->line_thickness,
-								       style->math_size);
+	length.unit = LSM_MATHML_UNIT_PT;
+
+	length.value = style->line_thickness;
+	style->line_thickness = lsm_mathml_length_attribute_normalize (&fraction->line_thickness, &length, style);
 
 	fraction->display = style->display;
 }
diff --git a/src/lsmmathmloperatorelement.c b/src/lsmmathmloperatorelement.c
index 3fd4c62..febcd91 100644
--- a/src/lsmmathmloperatorelement.c
+++ b/src/lsmmathmloperatorelement.c
@@ -105,9 +105,9 @@ lsm_mathml_operator_element_update (LsmMathmlElement *self, LsmMathmlStyle *styl
 		    lsm_mathml_form_to_string (entry->form), entry->name);
 
 	space = entry->left_space;
-	lsm_mathml_space_attribute_parse (&operator_element->left_space, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->left_space, &space, style);
 	space = entry->right_space;
-	lsm_mathml_space_attribute_parse (&operator_element->right_space, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->right_space, &space, style);
 	lsm_mathml_boolean_attribute_inherit (&operator_element->stretchy, entry->stretchy);
 	lsm_mathml_boolean_attribute_inherit (&operator_element->fence, entry->fence);
 	lsm_mathml_boolean_attribute_inherit (&operator_element->accent, entry->accent);
@@ -119,9 +119,9 @@ lsm_mathml_operator_element_update (LsmMathmlElement *self, LsmMathmlStyle *styl
 	lsm_mathml_boolean_attribute_inherit (&operator_element->movable_limits, entry->movable_limits);
 	lsm_mathml_boolean_attribute_inherit (&operator_element->separator, entry->separator);
 	space = entry->min_size;
-	lsm_mathml_space_attribute_parse (&operator_element->min_size, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->min_size, &space, style);
 	space = entry->max_size;
-	lsm_mathml_space_attribute_parse (&operator_element->max_size, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->max_size, &space, style);
 	lsm_mathml_boolean_attribute_inherit (&operator_element->symmetric, entry->symmetric);
 
 	operator_element->is_large_op = operator_element->large_op.value &&
@@ -215,14 +215,14 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.trait_class = &lsm_mathml_form_trait_class
 	},
 	{
-		.name = "fence",
-		.attribute_offset = offsetof (LsmMathmlOperatorElement, fence),
-		.trait_class = &lsm_mathml_boolean_trait_class
+		.name = "lspace",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, left_space),
+		.trait_class = &lsm_mathml_space_trait_class
 	},
 	{
-		.name = "separator",
-		.attribute_offset = offsetof (LsmMathmlOperatorElement, separator),
-		.trait_class = &lsm_mathml_boolean_trait_class,
+		.name = "rspace",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, right_space),
+		.trait_class = &lsm_mathml_space_trait_class
 	},
 	{
 		.name = "stretchy",
@@ -230,8 +230,13 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.trait_class = &lsm_mathml_boolean_trait_class,
 	},
 	{
-		.name = "symmetric",
-		.attribute_offset = offsetof (LsmMathmlOperatorElement, symmetric),
+		.name = "fence",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, fence),
+		.trait_class = &lsm_mathml_boolean_trait_class
+	},
+	{
+		.name = "accent",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, accent),
 		.trait_class = &lsm_mathml_boolean_trait_class,
 	},
 	{
@@ -245,8 +250,23 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.trait_class = &lsm_mathml_boolean_trait_class,
 	},
 	{
-		.name = "accent",
-		.attribute_offset = offsetof (LsmMathmlOperatorElement, accent),
+		.name = "separator",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, separator),
+		.trait_class = &lsm_mathml_boolean_trait_class,
+	},
+	{
+		.name = "minsize",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, min_size),
+		.trait_class = &lsm_mathml_space_trait_class
+	},
+	{
+		.name = "maxsize",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, max_size),
+		.trait_class = &lsm_mathml_space_trait_class
+	},
+	{
+		.name = "symmetric",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, symmetric),
 		.trait_class = &lsm_mathml_boolean_trait_class,
 	}
 };
@@ -271,17 +291,6 @@ lsm_mathml_operator_element_class_init (LsmMathmlOperatorElementClass *operator_
 	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);
-
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "lspace",
-						offsetof (LsmMathmlOperatorElement, left_space));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "rspace",
-						offsetof (LsmMathmlOperatorElement, right_space));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "minsize",
-						offsetof (LsmMathmlOperatorElement, min_size));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "maxsize",
-						offsetof (LsmMathmlOperatorElement, max_size));
 }
 
 G_DEFINE_TYPE (LsmMathmlOperatorElement, lsm_mathml_operator_element, LSM_TYPE_MATHML_PRESENTATION_TOKEN)
diff --git a/src/lsmmathmlpresentationtoken.c b/src/lsmmathmlpresentationtoken.c
index 97727a7..fd0d6f9 100644
--- a/src/lsmmathmlpresentationtoken.c
+++ b/src/lsmmathmlpresentationtoken.c
@@ -93,11 +93,13 @@ static void
 lsm_mathml_presentation_token_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
 	LsmMathmlPresentationToken *token = LSM_MATHML_PRESENTATION_TOKEN (self);
+	LsmMathmlLength length;
 
 	if (token->type == LSM_MATHML_PRESENTATION_TOKEN_TYPE_IDENTIFIER) {
 		char *text;
 		text = lsm_mathml_presentation_token_get_text (token);
-		style->math_variant = g_utf8_strlen (text, -1) > 1 ? LSM_MATHML_VARIANT_NORMAL : LSM_MATHML_VARIANT_ITALIC;
+		style->math_variant = g_utf8_strlen (text, -1) > 1 ?
+			LSM_MATHML_VARIANT_NORMAL : LSM_MATHML_VARIANT_ITALIC;
 		g_free (text);
 	}
 
@@ -110,8 +112,10 @@ lsm_mathml_presentation_token_update (LsmMathmlElement *self, LsmMathmlStyle *st
 	style->math_variant = lsm_mathml_enum_attribute_inherit (&token->math_variant, style->math_variant);
 	style->math_color = lsm_mathml_color_attribute_inherit (&token->math_color, style->math_color);
 	style->math_background = lsm_mathml_color_attribute_inherit (&token->math_background, style->math_background);
-	style->math_size = lsm_mathml_length_attribute_normalize (&token->math_size, style->math_size,
-								  style->math_size);
+
+	length.unit = LSM_MATHML_UNIT_PT;
+	length.value = style->math_size;
+	style->math_size = lsm_mathml_length_attribute_normalize (&token->math_size, &length, style);
 }
 
 static const LsmMathmlBbox *
diff --git a/src/lsmmathmlscriptelement.c b/src/lsmmathmlscriptelement.c
index 4880529..ef13f9c 100644
--- a/src/lsmmathmlscriptelement.c
+++ b/src/lsmmathmlscriptelement.c
@@ -112,13 +112,14 @@ static void
 lsm_mathml_script_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
 	LsmMathmlScriptElement *script = LSM_MATHML_SCRIPT_ELEMENT (self);
+	LsmMathmlLength length;
 
-	style->superscript_shift = lsm_mathml_length_attribute_normalize (&script->superscript_shift,
-									  style->superscript_shift,
-									  style->math_size);
-	style->subscript_shift = lsm_mathml_length_attribute_normalize (&script->subscript_shift,
-									style->subscript_shift,
-									style->math_size);
+	length.unit = LSM_MATHML_UNIT_PT;
+
+	length.value = style->superscript_shift;
+	style->superscript_shift = lsm_mathml_length_attribute_normalize (&script->superscript_shift, &length, style);
+	length.value = style->subscript_shift;
+	style->subscript_shift = lsm_mathml_length_attribute_normalize (&script->subscript_shift, &length, style);
 
 	script->display = style->display;
 }
diff --git a/src/lsmmathmlspaceelement.c b/src/lsmmathmlspaceelement.c
index a4ce289..e67d845 100644
--- a/src/lsmmathmlspaceelement.c
+++ b/src/lsmmathmlspaceelement.c
@@ -45,16 +45,13 @@ static void
 lsm_mathml_space_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
 	LsmMathmlSpaceElement *space_element = LSM_MATHML_SPACE_ELEMENT (self);
-	LsmMathmlSpace space;
+	static LsmMathmlSpace space = {.name = LSM_MATHML_SPACE_NAME_ERROR,
+		{ .unit = LSM_MATHML_UNIT_PX, .value = 0.0}};
+	static LsmMathmlLength length = {.unit = LSM_MATHML_UNIT_PX, .value = 0.0};
 
-	space.length.unit = LSM_MATHML_UNIT_EM;
-	space.length.value = 0;
-	space.name = LSM_MATHML_SPACE_NAME_ERROR;
-
-	lsm_mathml_space_attribute_parse (&space_element->width, &space, style);
-
-	lsm_mathml_length_attribute_normalize (&space_element->height, 0.0, style->math_size);
-	lsm_mathml_length_attribute_normalize (&space_element->depth, 0.0, style->math_size);
+	lsm_mathml_space_attribute_normalize (&space_element->width, &space, style);
+	lsm_mathml_length_attribute_normalize (&space_element->height, &length, style);
+	lsm_mathml_length_attribute_normalize (&space_element->depth, &length, style);
 }
 
 static const LsmMathmlBbox *
@@ -85,11 +82,13 @@ lsm_mathml_space_element_new (void)
 	return g_object_new (LSM_TYPE_MATHML_SPACE_ELEMENT, NULL);
 }
 
+static const LsmMathmlSpace space_default = {LSM_MATHML_SPACE_NAME_ERROR, {0.0, LSM_MATHML_UNIT_EM}};
 static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
 
 static void
 lsm_mathml_space_element_init (LsmMathmlSpaceElement *self)
 {
+	self->width.space = space_default;
 	self->height.length = length_default;
 	self->depth.length = length_default;
 }
@@ -98,16 +97,22 @@ lsm_mathml_space_element_init (LsmMathmlSpaceElement *self)
 
 static const LsmAttributeInfos _attribute_infos[] = {
 	{
-		.name = "height",
-		.attribute_offset = offsetof (LsmMathmlSpaceElement, height),
-		.trait_class = &lsm_mathml_length_trait_class,
-		.trait_default = &length_default
+		.name = "width",
+		.attribute_offset = offsetof (LsmMathmlSpaceElement, width),
+		.trait_class = &lsm_mathml_space_trait_class,
+		.trait_default = &space_default
 	},
 	{
 		.name = "depth",
 		.attribute_offset = offsetof (LsmMathmlSpaceElement, depth),
 		.trait_class = &lsm_mathml_length_trait_class,
 		.trait_default = &length_default
+	},
+	{
+		.name = "height",
+		.attribute_offset = offsetof (LsmMathmlSpaceElement, height),
+		.trait_class = &lsm_mathml_length_trait_class,
+		.trait_default = &length_default
 	}
 };
 
@@ -131,11 +136,6 @@ lsm_mathml_space_element_class_init (LsmMathmlSpaceElementClass *space_class)
 	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);
-
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "width",
-					  offsetof (LsmMathmlSpaceElement, width));
 }
 
 G_DEFINE_TYPE (LsmMathmlSpaceElement, lsm_mathml_space_element, LSM_TYPE_MATHML_ELEMENT)
diff --git a/src/lsmmathmlstyleelement.c b/src/lsmmathmlstyleelement.c
index 84cbe2f..c6f657b 100644
--- a/src/lsmmathmlstyleelement.c
+++ b/src/lsmmathmlstyleelement.c
@@ -39,10 +39,12 @@ lsm_mathml_style_element_get_node_name (LsmDomNode *node)
 static void
 lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
+	LsmMathmlStyleElement *style_element = LSM_MATHML_STYLE_ELEMENT (self);
+	LsmMathmlLength length;
 	gboolean display_style;
 	int new_script_level;
 
-	LsmMathmlStyleElement *style_element = LSM_MATHML_STYLE_ELEMENT (self);
+	length.unit = LSM_MATHML_UNIT_PT;
 
 	display_style = style->display == LSM_MATHML_DISPLAY_BLOCK;
 	lsm_mathml_boolean_attribute_inherit (&style_element->display_style, display_style);
@@ -50,9 +52,9 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 
 	style->script_size_multiplier = lsm_mathml_double_attribute_inherit (&style_element->script_size_multiplier,
 									     style->script_size_multiplier);
+	length.value = style->script_min_size;
 	style->script_min_size = lsm_mathml_length_attribute_normalize (&style_element->script_min_size,
-								       style->script_min_size,
-								       style->math_size);
+								        &length, style);
 
 	new_script_level = lsm_mathml_script_level_attribute_apply (&style_element->script_level,
 								    style->script_level);
@@ -73,39 +75,46 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 	style->math_background = lsm_mathml_color_attribute_inherit (&style_element->math_background,
 								     style->math_background);
 	style->math_variant = lsm_mathml_enum_attribute_inherit (&style_element->math_variant, style->math_variant);
+	length.value = style->math_size;
 	style->math_size = lsm_mathml_length_attribute_normalize (&style_element->math_size,
-								  style->math_size,
-								  style->math_size);
+								  &length, style);
 
 	/* mstyle */
 
+	length.value = style->very_very_thin_math_space;
 	style->very_very_thin_math_space =
 		lsm_mathml_length_attribute_normalize (&style_element->very_very_thin_math_space,
-						       style->very_very_thin_math_space, style->math_size);
+						       &length, style);
+	length.value = style->very_thin_math_space;
 	style->very_thin_math_space =
 		lsm_mathml_length_attribute_normalize (&style_element->very_thin_math_space,
-						       style->very_thin_math_space, style->math_size);
+						       &length, style);
+	length.value = style->thin_math_space;
 	style->thin_math_space =
 		lsm_mathml_length_attribute_normalize (&style_element->thin_math_space,
-						       style->thin_math_space, style->math_size);
+						       &length, style);
+	length.value = style->medium_math_space;
 	style->medium_math_space =
 		lsm_mathml_length_attribute_normalize (&style_element->medium_math_space,
-						       style->medium_math_space, style->math_size);
+						       &length, style);
+	length.value = style->thick_math_space;
 	style->thick_math_space =
 		lsm_mathml_length_attribute_normalize (&style_element->thick_math_space,
-						       style->thick_math_space, style->math_size);
+						       &length, style);
+	length.value = style->very_thick_math_space;
 	style->very_thick_math_space =
 		lsm_mathml_length_attribute_normalize (&style_element->very_thick_math_space,
-						       style->very_thick_math_space, style->math_size);
+						       &length, style);
+	length.value = style->very_very_thick_math_space;
 	style->very_very_thick_math_space =
 		lsm_mathml_length_attribute_normalize (&style_element->very_very_thick_math_space,
-						       style->very_very_thick_math_space, style->math_size);
+						       &length, style);
 
 	/* mfrac */
 
+	length.value = style->line_thickness;
 	style->line_thickness = lsm_mathml_length_attribute_normalize (&style_element->line_thickness,
-								       style->line_thickness,
-								       style->math_size);
+								       &length, style);
 }
 
 /* LsmMathmlStyleElement implementation */
diff --git a/src/lsmmathmltraits.c b/src/lsmmathmltraits.c
index 5911845..bd392dc 100644
--- a/src/lsmmathmltraits.c
+++ b/src/lsmmathmltraits.c
@@ -427,7 +427,9 @@ const LsmTraitClass lsm_mathml_length_trait_class = {
 };
 
 double
-lsm_mathml_length_normalize (const LsmMathmlLength *length, double default_value, double font_size)
+lsm_mathml_length_normalize (const LsmMathmlLength *length,
+			     const LsmMathmlLength *default_length,
+			     double font_size)
 {
 	double value;
 
@@ -457,10 +459,10 @@ lsm_mathml_length_normalize (const LsmMathmlLength *length, double default_value
 			value = length->value * font_size * 0.5;
 			break;
 		case LSM_MATHML_UNIT_PERCENT:
-			value = default_value * length->value / 100.0;
+			value = length->value * lsm_mathml_length_normalize (default_length, NULL, font_size) / 100.0;
 			break;
 		case LSM_MATHML_UNIT_NONE:
-			value = default_value * length->value;
+			value = length->value * lsm_mathml_length_normalize (default_length, NULL, font_size);
 			break;
 		default:
 			value = 0;
@@ -493,6 +495,42 @@ lsm_mathml_space_get_type (void)
 	return our_type;
 }
 
+
+static void
+lsm_mathml_space_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlSpace *space = (LsmMathmlSpace *) abstract_trait;
+	char *unit_str;
+
+	space->name = lsm_mathml_space_name_from_string (string);
+	if (space->name == LSM_MATHML_SPACE_NAME_ERROR) {
+		space->length.value = g_strtod (string, &unit_str);
+		space->length.unit = lsm_mathml_unit_from_string (unit_str);
+	} else {
+		space->length.value = 0.0;
+		space->length.unit = LSM_MATHML_UNIT_PX;
+	}
+}
+
+static char *
+lsm_mathml_space_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlSpace *space = (LsmMathmlSpace *) abstract_trait;
+
+	if (space->name != LSM_MATHML_SPACE_NAME_ERROR)
+		return g_strdup (lsm_mathml_space_name_to_string (space->name));
+
+	return g_strdup_printf ("%g %s", space->length.value,
+				lsm_mathml_unit_to_string (space->length.unit));
+}
+
+const LsmTraitClass lsm_mathml_space_trait_class = {
+	.size = sizeof (char *),
+	.from_string = lsm_mathml_space_trait_from_string,
+	.to_string = lsm_mathml_space_trait_to_string
+};
+
+
 GType
 lsm_mathml_space_list_get_type (void)
 {
diff --git a/src/lsmmathmltraits.h b/src/lsmmathmltraits.h
index f17936a..35e8711 100644
--- a/src/lsmmathmltraits.h
+++ b/src/lsmmathmltraits.h
@@ -54,7 +54,9 @@ typedef struct {
 } LsmMathmlLength;
 
 GType lsm_mathml_length_get_type (void);
-double 	lsm_mathml_length_normalize 	(const LsmMathmlLength *length, double default_value, double font_size);
+double 	lsm_mathml_length_normalize 	(const LsmMathmlLength *length,
+					 const LsmMathmlLength *default_length,
+					 double font_size);
 
 typedef struct {
 	LsmMathmlScriptLevelSign sign;
@@ -98,6 +100,7 @@ extern const LsmTraitClass lsm_mathml_script_level_trait_class;
 extern const LsmTraitClass lsm_mathml_double_trait_class;
 extern const LsmTraitClass lsm_mathml_string_trait_class;
 extern const LsmTraitClass lsm_mathml_length_trait_class;
+extern const LsmTraitClass lsm_mathml_space_trait_class;
 
 extern const LsmTraitClass lsm_mathml_color_trait_class;
 



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