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



commit b99418c092ed53aa6a49226f7458b76f2f217173
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Dec 28 19:08:22 2009 +0100

    [Mathml] Migration to lsm_attribute_manager WIP.
    
    lsm_mathml_enum_attribute

 src/lsmmathmlattributes.c        |   58 ++------------
 src/lsmmathmlattributes.h        |   38 +++------
 src/lsmmathmlenums.c             |   18 ++++-
 src/lsmmathmlenums.h             |   10 ++-
 src/lsmmathmlmathelement.c       |   37 ++++++---
 src/lsmmathmloperatorelement.c   |   17 +++--
 src/lsmmathmlpresentationtoken.c |   46 +++++++-----
 src/lsmmathmlstyleelement.c      |   42 ++++++----
 src/lsmmathmltableelement.c      |   13 ++-
 src/lsmmathmltraits.c            |  154 ++++++++++++++++++++++++++++++++++++++
 src/lsmmathmltraits.h            |    7 ++
 11 files changed, 299 insertions(+), 141 deletions(-)
---
diff --git a/src/lsmmathmlattributes.c b/src/lsmmathmlattributes.c
index 2a10dc2..db1b25f 100644
--- a/src/lsmmathmlattributes.c
+++ b/src/lsmmathmlattributes.c
@@ -30,6 +30,15 @@ lsm_mathml_boolean_attribute_inherit (LsmMathmlBooleanAttribute *attribute, gboo
 	return attribute->value;
 }
 
+unsigned int
+lsm_mathml_enum_attribute_inherit (LsmMathmlEnumAttribute *attribute, unsigned int value)
+{
+	if (attribute->base.value == NULL)
+		attribute->value = value;
+
+	return attribute->value;
+}
+
 double
 lsm_mathml_double_attribute_inherit (LsmMathmlDoubleAttribute *attribute, double value)
 {
@@ -596,55 +605,6 @@ lsm_mathml_color_attribute_parse (LsmMathmlColorAttribute *attribute,
 }
 
 void
-lsm_mathml_mode_attribute_parse (LsmMathmlEnumAttribute *attribute,
-				 unsigned int *style_value)
-{
-	return lsm_mathml_enum_attribute_parse (attribute, style_value, lsm_mathml_mode_from_string);
-}
-
-void
-lsm_mathml_display_attribute_parse (LsmMathmlEnumAttribute *attribute,
-				    unsigned int *style_value)
-{
-	return lsm_mathml_enum_attribute_parse (attribute, style_value, lsm_mathml_display_from_string);
-}
-
-void
-lsm_mathml_form_attribute_parse (LsmMathmlEnumAttribute *attribute,
-				 unsigned int *style_value)
-{
-	return lsm_mathml_enum_attribute_parse (attribute, style_value, lsm_mathml_form_from_string);
-}
-
-void
-lsm_mathml_font_style_attribute_parse (LsmMathmlEnumAttribute *attribute,
-				       unsigned int *style_value)
-{
-	return lsm_mathml_enum_attribute_parse (attribute, style_value, lsm_mathml_font_style_from_string);
-}
-
-void
-lsm_mathml_font_weight_attribute_parse (LsmMathmlEnumAttribute *attribute,
-					unsigned int *style_value)
-{
-	return lsm_mathml_enum_attribute_parse (attribute, style_value, lsm_mathml_font_weight_from_string);
-}
-
-void
-lsm_mathml_variant_attribute_parse (LsmMathmlEnumAttribute *attribute,
-				    unsigned int *style_value)
-{
-	return lsm_mathml_enum_attribute_parse (attribute, style_value, lsm_mathml_variant_from_string);
-}
-
-void
-lsm_mathml_line_attribute_parse (LsmMathmlEnumAttribute *attribute,
-				 unsigned int *style_value)
-{
-	return lsm_mathml_enum_attribute_parse (attribute, style_value, lsm_mathml_line_from_string);
-}
-
-void
 lsm_mathml_space_attribute_parse (LsmMathmlSpaceAttribute *attribute,
 				  LsmMathmlSpace *style_value,
 				  LsmMathmlStyle *style)
diff --git a/src/lsmmathmlattributes.h b/src/lsmmathmlattributes.h
index f181ea7..1b96aa4 100644
--- a/src/lsmmathmlattributes.h
+++ b/src/lsmmathmlattributes.h
@@ -43,6 +43,11 @@ typedef struct {
 
 typedef struct {
 	LsmAttribute base;
+	unsigned int value;
+} LsmMathmlEnumAttribute;
+
+typedef struct {
+	LsmAttribute base;
 	double value;
 } LsmMathmlDoubleAttribute;
 
@@ -51,9 +56,14 @@ typedef struct {
 	char *value;
 } LsmMathmlStringAttribute;
 
-gboolean	lsm_mathml_boolean_attribute_inherit 	(LsmMathmlBooleanAttribute *attribute, gboolean value);
-double 		lsm_mathml_double_attribute_inherit 	(LsmMathmlDoubleAttribute *attribute, double value);
-const char *	lsm_mathml_string_attribute_inherit	(LsmMathmlStringAttribute *attribute, const char *string);
+gboolean		lsm_mathml_boolean_attribute_inherit 	(LsmMathmlBooleanAttribute *attribute,
+								 gboolean value);
+unsigned int		lsm_mathml_enum_attribute_inherit	(LsmMathmlEnumAttribute *attribute,
+								 unsigned int value);
+double 			lsm_mathml_double_attribute_inherit 	(LsmMathmlDoubleAttribute *attribute,
+								 double value);
+const char *		lsm_mathml_string_attribute_inherit	(LsmMathmlStringAttribute *attribute,
+								 const char *string);
 
 typedef struct {
 	LsmAttribute base;
@@ -142,11 +152,6 @@ typedef unsigned int (*LsmDomNamedConvert) (const char *string);
 #define LSM_MATHML_SPACE_EM_VERY_VERY_THICK	0.388889
 
 typedef struct {
-	LsmMathmlAttribute attr;
-	unsigned int value;
-} LsmMathmlEnumAttribute;
-
-typedef struct {
 	unsigned int n_values;
 	unsigned int *values;
 } LsmMathmlEnumList;
@@ -208,9 +213,6 @@ typedef struct {
 	double *values;
 } LsmMathmlSpaceListAttribute;
 
-void 		lsm_mathml_enum_attribute_parse 	(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *default_value,
-							 LsmDomNamedConvert convert);
 void 		lsm_mathml_enum_list_attribute_parse 	(LsmMathmlEnumListAttribute *attribute,
 							 LsmMathmlEnumList *style_value,
 							 LsmDomNamedConvert convert);
@@ -225,20 +227,6 @@ void 		lsm_mathml_attribute_map_add_enum_list 	(LsmMathmlAttributeMap *map,
 
 void 		lsm_mathml_script_level_attribute_parse	(LsmMathmlScriptLevelAttribute *attribute,
 							 int *default_value);
-void 		lsm_mathml_mode_attribute_parse 	(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *style_value);
-void 		lsm_mathml_display_attribute_parse 	(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *style_value);
-void 		lsm_mathml_form_attribute_parse	 	(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *style_value);
-void 		lsm_mathml_font_style_attribute_parse 	(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *style_value);
-void 		lsm_mathml_font_weight_attribute_parse 	(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *style_value);
-void 		lsm_mathml_variant_attribute_parse 	(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *style_value);
-void		lsm_mathml_line_attribute_parse		(LsmMathmlEnumAttribute *attribute,
-							 unsigned int *style_value);
 void		lsm_mathml_color_attribute_parse	(LsmMathmlColorAttribute *attribute,
 							 LsmMathmlColor *default_color);
 void 		lsm_mathml_space_attribute_parse 	(LsmMathmlSpaceAttribute *attribute,
diff --git a/src/lsmmathmlenums.c b/src/lsmmathmlenums.c
index a4ac14c..182590e 100644
--- a/src/lsmmathmlenums.c
+++ b/src/lsmmathmlenums.c
@@ -128,25 +128,39 @@ lsm_mathml_unit_from_string (const char *string)
 static const char *lsm_mathml_font_style_strings[] = {
 	"normal",
 	"italic",
+	""
 };
 
+const char *
+lsm_mathml_font_style_to_string (LsmMathmlFontStyle font_style)
+{
+	return lsm_mathml_font_style_strings[CLAMP (font_style, 0, LSM_MATHML_FONT_STYLE_ERROR)];
+}
+
 LsmMathmlFontStyle
 lsm_mathml_font_style_from_string (const char *string)
 {
 	return lsm_mathml_value_from_string (string, lsm_mathml_font_style_strings,
-					  G_N_ELEMENTS (lsm_mathml_font_style_strings));
+					     G_N_ELEMENTS (lsm_mathml_font_style_strings));
 }
 
 static const char *lsm_mathml_font_weight_strings[] = {
 	"normal",
 	"bold",
+	""
 };
 
+const char *
+lsm_mathml_font_weight_to_string (LsmMathmlFontWeight font_weight)
+{
+	return lsm_mathml_font_weight_strings[CLAMP (font_weight, 0, LSM_MATHML_FONT_WEIGHT_ERROR)];
+}
+
 LsmMathmlFontWeight
 lsm_mathml_font_weight_from_string (const char *string)
 {
 	return lsm_mathml_value_from_string (string, lsm_mathml_font_weight_strings,
-					  G_N_ELEMENTS (lsm_mathml_font_weight_strings));
+					     G_N_ELEMENTS (lsm_mathml_font_weight_strings));
 }
 
 static const char *lsm_mathml_variant_strings[] = {
diff --git a/src/lsmmathmlenums.h b/src/lsmmathmlenums.h
index 0c3e401..9113de4 100644
--- a/src/lsmmathmlenums.h
+++ b/src/lsmmathmlenums.h
@@ -78,7 +78,7 @@ typedef enum {
 	LSM_MATHML_UNIT_PERCENT
 } LsmMathmlUnit;
 
-const char * 		lsm_mathml_unit_to_string 			(LsmMathmlUnit unit);
+const char * 		lsm_mathml_unit_to_string 		(LsmMathmlUnit unit);
 LsmMathmlUnit 		lsm_mathml_unit_from_string 		(const char *string);
 
 typedef enum {
@@ -87,7 +87,8 @@ typedef enum {
 	LSM_MATHML_FONT_STYLE_ERROR
 } LsmMathmlFontStyle;
 
-LsmMathmlFontStyle 	lsm_mathml_font_style_from_string 		(const char *string);
+const char * 		lsm_mathml_font_style_to_string 	(LsmMathmlFontStyle font_style);
+LsmMathmlFontStyle 	lsm_mathml_font_style_from_string 	(const char *string);
 
 typedef enum {
 	LSM_MATHML_FONT_WEIGHT_NORMAL,
@@ -95,6 +96,7 @@ typedef enum {
 	LSM_MATHML_FONT_WEIGHT_ERROR
 } LsmMathmlFontWeight;
 
+const char * 		lsm_mathml_font_weight_to_string 	(LsmMathmlFontWeight font_weight);
 LsmMathmlFontWeight 	lsm_mathml_font_weight_from_string 	(const char *string);
 
 /* Keep in sync with lsm_mathml_pango_options in lsm_mathml_view */
@@ -116,8 +118,8 @@ typedef enum {
 	LSM_MATHML_VARIANT_ERROR
 } LsmMathmlVariant;
 
-const char * 		lsm_mathml_variant_to_string 	(LsmMathmlVariant variant);
-LsmMathmlVariant 		lsm_mathml_variant_from_string 	(const char *string);
+const char * 		lsm_mathml_variant_to_string 		(LsmMathmlVariant variant);
+LsmMathmlVariant 	lsm_mathml_variant_from_string 		(const char *string);
 void	 		lsm_mathml_variant_set_font_style	(LsmMathmlVariant *variant, LsmMathmlFontStyle style);
 void 			lsm_mathml_variant_set_font_weight	(LsmMathmlVariant *variant, LsmMathmlFontWeight weight);
 
diff --git a/src/lsmmathmlmathelement.c b/src/lsmmathmlmathelement.c
index 21e81a0..99abe5b 100644
--- a/src/lsmmathmlmathelement.c
+++ b/src/lsmmathmlmathelement.c
@@ -40,15 +40,15 @@ static void
 _update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
 	LsmMathmlMathElement *math_element = LSM_MATHML_MATH_ELEMENT (self);
-	LsmMathmlMode default_mode = (style->display == LSM_MATHML_DISPLAY_INLINE) ?
-		LSM_MATHML_MODE_INLINE : LSM_MATHML_MODE_DISPLAY;
+	LsmMathmlMode default_mode;
 
-	lsm_mathml_mode_attribute_parse (&math_element->mode, &default_mode);
+	default_mode = lsm_mathml_enum_attribute_inherit (&math_element->mode,
+							  (style->display == LSM_MATHML_DISPLAY_INLINE) ?
+							  LSM_MATHML_MODE_INLINE : LSM_MATHML_MODE_DISPLAY);
 
-	style->display = (default_mode == LSM_MATHML_MODE_INLINE) ?
-		LSM_MATHML_DISPLAY_INLINE : LSM_MATHML_DISPLAY_BLOCK;
-
-	lsm_mathml_display_attribute_parse (&math_element->display, &style->display);
+	style->display = lsm_mathml_enum_attribute_inherit (&math_element->display,
+							    (default_mode == LSM_MATHML_MODE_INLINE) ?
+							    LSM_MATHML_DISPLAY_INLINE : LSM_MATHML_DISPLAY_BLOCK);
 }
 
 /* LsmMathmlMathElement implementation */
@@ -166,6 +166,19 @@ lsm_mathml_math_element_finalize (GObject *object)
 
 /* LsmMathmlMathElement class */
 
+static const LsmAttributeInfos _attribute_infos[] = {
+	{
+		.name = "display",
+		.attribute_offset = offsetof (LsmMathmlMathElement, display),
+		.trait_class = &lsm_mathml_display_trait_class,
+	},
+	{
+		.name = "mode",
+		.attribute_offset = offsetof (LsmMathmlMathElement, mode),
+		.trait_class = &lsm_mathml_mode_trait_class,
+	}
+};
+
 static void
 lsm_mathml_math_element_class_init (LsmMathmlMathElementClass *math_class)
 {
@@ -180,13 +193,11 @@ lsm_mathml_math_element_class_init (LsmMathmlMathElementClass *math_class)
 	d_node_class->get_node_name = lsm_mathml_math_element_get_node_name;
 
 	m_element_class->update = _update;
+	m_element_class->attribute_manager = lsm_attribute_manager_duplicate (m_element_class->attribute_manager);
 
-	m_element_class->attributes = lsm_mathml_attribute_map_duplicate (m_element_class->attributes);
-
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mode",
-					  offsetof (LsmMathmlMathElement, mode));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "display",
-					  offsetof (LsmMathmlMathElement, display));
+	lsm_attribute_manager_add_attributes (m_element_class->attribute_manager,
+					      G_N_ELEMENTS (_attribute_infos),
+					      _attribute_infos);
 }
 
 G_DEFINE_TYPE (LsmMathmlMathElement, lsm_mathml_math_element, LSM_TYPE_MATHML_ELEMENT)
diff --git a/src/lsmmathmloperatorelement.c b/src/lsmmathmloperatorelement.c
index 5a39dca..3fd4c62 100644
--- a/src/lsmmathmloperatorelement.c
+++ b/src/lsmmathmloperatorelement.c
@@ -63,7 +63,7 @@ lsm_mathml_operator_element_dictionary_lookup (LsmMathmlOperatorElement *operato
 	} else
 		form = LSM_MATHML_FORM_INFIX;
 
-	lsm_mathml_form_attribute_parse (&operator->form, &form);
+	form = lsm_mathml_enum_attribute_inherit (&operator->form, form);
 
 	entry = lsm_mathml_operator_dictionary_lookup (text, form);
 
@@ -210,6 +210,11 @@ lsm_mathml_operator_element_init (LsmMathmlOperatorElement *self)
 
 static const LsmAttributeInfos _attribute_infos[] = {
 	{
+		.name = "form",
+		.attribute_offset = offsetof (LsmMathmlOperatorElement, form),
+		.trait_class = &lsm_mathml_form_trait_class
+	},
+	{
 		.name = "fence",
 		.attribute_offset = offsetof (LsmMathmlOperatorElement, fence),
 		.trait_class = &lsm_mathml_boolean_trait_class
@@ -269,16 +274,14 @@ lsm_mathml_operator_element_class_init (LsmMathmlOperatorElementClass *operator_
 
 	m_element_class->attributes = lsm_mathml_attribute_map_duplicate (m_element_class->attributes);
 
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "form",
-					  offsetof (LsmMathmlOperatorElement, form));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "lspace",
-					  offsetof (LsmMathmlOperatorElement, left_space));
+						offsetof (LsmMathmlOperatorElement, left_space));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "rspace",
-					  offsetof (LsmMathmlOperatorElement, right_space));
+						offsetof (LsmMathmlOperatorElement, right_space));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "minsize",
-					  offsetof (LsmMathmlOperatorElement, min_size));
+						offsetof (LsmMathmlOperatorElement, min_size));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "maxsize",
-					  offsetof (LsmMathmlOperatorElement, max_size));
+						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 0104f67..2e8be4a 100644
--- a/src/lsmmathmlpresentationtoken.c
+++ b/src/lsmmathmlpresentationtoken.c
@@ -92,8 +92,6 @@ lsm_mathml_presentation_token_get_text (LsmMathmlPresentationToken *self)
 static void
 lsm_mathml_presentation_token_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
-	LsmMathmlFontStyle font_style;
-	LsmMathmlFontWeight font_weight;
 	LsmMathmlPresentationToken *token = LSM_MATHML_PRESENTATION_TOKEN (self);
 
 	if (token->type == LSM_MATHML_PRESENTATION_TOKEN_TYPE_IDENTIFIER) {
@@ -103,19 +101,13 @@ lsm_mathml_presentation_token_update (LsmMathmlElement *self, LsmMathmlStyle *st
 		g_free (text);
 	}
 
-	font_style = LSM_MATHML_FONT_STYLE_ERROR;
-	lsm_mathml_font_style_attribute_parse (&token->font_style, &font_style);
-
-	font_weight = LSM_MATHML_FONT_WEIGHT_ERROR;
-	lsm_mathml_font_weight_attribute_parse (&token->font_weight, &font_weight);
-
-	lsm_mathml_variant_set_font_style (&style->math_variant, font_style);
-	lsm_mathml_variant_set_font_weight (&style->math_variant, font_weight);
+	lsm_mathml_variant_set_font_style (&style->math_variant, token->font_style.value);
+	lsm_mathml_variant_set_font_weight (&style->math_variant, token->font_weight.value);
 
 	lsm_mathml_style_set_math_family (style,
 					  lsm_mathml_string_attribute_inherit (&token->math_family,
 									       style->math_family));
-	lsm_mathml_variant_attribute_parse (&token->math_variant, &style->math_variant);
+	style->math_variant = lsm_mathml_enum_attribute_inherit (&token->math_variant, style->math_variant);
 	lsm_mathml_color_attribute_parse (&token->math_color, &style->math_color);
 	lsm_mathml_color_attribute_parse (&token->math_background, &style->math_background);
 	style->math_size = lsm_mathml_length_attribute_normalize (&token->math_size, style->math_size,
@@ -198,11 +190,16 @@ lsm_mathml_text_element_new (void)
 }
 
 static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+static const LsmMathmlFontStyle font_style_default = LSM_MATHML_FONT_STYLE_ERROR;
+static const LsmMathmlFontWeight font_weight_default = LSM_MATHML_FONT_WEIGHT_ERROR;
 
 static void
-lsm_mathml_presentation_token_init (LsmMathmlPresentationToken *token)
+lsm_mathml_presentation_token_init (LsmMathmlPresentationToken *self)
 {
-	token->math_size.length = length_default;
+	self->math_size.length = length_default;
+
+	self->font_weight.value = font_weight_default;
+	self->font_style.value = font_style_default;
 }
 
 /* LsmMathmlPresentationToken class */
@@ -219,6 +216,11 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.trait_class = &lsm_mathml_length_trait_class,
 		.trait_default = &length_default
 	},
+	{
+		.name = "mathvariant",
+		.attribute_offset = offsetof (LsmMathmlPresentationToken, math_variant),
+		.trait_class = &lsm_mathml_variant_trait_class,
+	},
 	/* Deprecated attributes */
 	{
 		.name = "fontfamily",
@@ -230,6 +232,18 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.attribute_offset = offsetof (LsmMathmlPresentationToken, math_size),
 		.trait_class = &lsm_mathml_length_trait_class,
 		.trait_default = &length_default
+	},
+	{
+		.name = "fontstyle",
+		.attribute_offset = offsetof (LsmMathmlPresentationToken, font_style),
+		.trait_class = &lsm_mathml_font_style_trait_class,
+		.trait_default = &font_style_default
+	},
+	{
+		.name = "fontweight",
+		.attribute_offset = offsetof (LsmMathmlPresentationToken, font_weight),
+		.trait_class = &lsm_mathml_font_weight_trait_class,
+		.trait_default = &font_weight_default
 	}
 };
 
@@ -260,8 +274,6 @@ lsm_mathml_presentation_token_class_init (LsmMathmlPresentationTokenClass *m_tok
 
 	m_element_class->attributes = lsm_mathml_attribute_map_duplicate (m_element_class->attributes);
 
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mathvariant",
-					     offsetof (LsmMathmlPresentationToken, math_variant));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mathcolor",
 					     offsetof (LsmMathmlPresentationToken, math_color));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mathbackground",
@@ -271,10 +283,6 @@ lsm_mathml_presentation_token_class_init (LsmMathmlPresentationTokenClass *m_tok
 
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "color",
 					     offsetof (LsmMathmlPresentationToken, math_color));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "fontweight",
-					     offsetof (LsmMathmlPresentationToken, font_weight));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "fontstyle",
-					     offsetof (LsmMathmlPresentationToken, font_style));
 }
 
 G_DEFINE_TYPE (LsmMathmlPresentationToken, lsm_mathml_presentation_token, LSM_TYPE_MATHML_ELEMENT)
diff --git a/src/lsmmathmlstyleelement.c b/src/lsmmathmlstyleelement.c
index b15fdc0..d17bf73 100644
--- a/src/lsmmathmlstyleelement.c
+++ b/src/lsmmathmlstyleelement.c
@@ -39,8 +39,6 @@ lsm_mathml_style_element_get_node_name (LsmDomNode *node)
 static void
 lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
-	LsmMathmlFontStyle font_style;
-	LsmMathmlFontWeight font_weight;
 	gboolean display_style;
 
 	LsmMathmlStyleElement *style_element = LSM_MATHML_STYLE_ELEMENT (self);
@@ -60,14 +58,8 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 
 	/* token */
 
-	font_style = LSM_MATHML_FONT_STYLE_ERROR;
-	lsm_mathml_font_style_attribute_parse (&style_element->font_style, &font_style);
-
-	font_weight = LSM_MATHML_FONT_WEIGHT_ERROR;
-	lsm_mathml_font_weight_attribute_parse (&style_element->font_weight, &font_weight);
-
-	lsm_mathml_variant_set_font_style (&style->math_variant, font_style);
-	lsm_mathml_variant_set_font_weight (&style->math_variant, font_weight);
+	lsm_mathml_variant_set_font_style (&style->math_variant, style_element->font_style.value);
+	lsm_mathml_variant_set_font_weight (&style->math_variant, style_element->font_weight.value);
 
 
 	lsm_mathml_style_set_math_family (style,
@@ -75,7 +67,7 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 									       style->math_family));
 	lsm_mathml_color_attribute_parse (&style_element->math_color, &style->math_color);
 	lsm_mathml_color_attribute_parse (&style_element->math_background, &style->math_background);
-	lsm_mathml_variant_attribute_parse (&style_element->math_variant, &style->math_variant);
+	style->math_variant = lsm_mathml_enum_attribute_inherit (&style_element->math_variant, style->math_variant);
 	style->math_size = lsm_mathml_length_attribute_normalize (&style_element->math_size,
 								  style->math_size,
 								  style->math_size);
@@ -120,6 +112,8 @@ lsm_mathml_style_element_new (void)
 }
 
 static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+static const LsmMathmlFontStyle font_style_default = LSM_MATHML_FONT_STYLE_ERROR;
+static const LsmMathmlFontWeight font_weight_default = LSM_MATHML_FONT_WEIGHT_ERROR;
 
 static void
 lsm_mathml_style_element_init (LsmMathmlStyleElement *self)
@@ -134,6 +128,9 @@ lsm_mathml_style_element_init (LsmMathmlStyleElement *self)
 	self->very_very_thick_math_space.length = length_default;
 	self->math_size.length = length_default;
 	self->line_thickness.length = length_default;
+
+	self->font_weight.value = font_weight_default;
+	self->font_style.value = font_style_default;
 }
 
 /* LsmMathmlStyleElement class */
@@ -209,6 +206,11 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.trait_default = &length_default
 	},
 	{
+		.name = "mathvariant",
+		.attribute_offset = offsetof (LsmMathmlStyleElement, math_variant),
+		.trait_class = &lsm_mathml_variant_trait_class,
+	},
+	{
 		.name = "linethickness",
 		.attribute_offset = offsetof (LsmMathmlStyleElement, line_thickness),
 		.trait_class = &lsm_mathml_length_trait_class,
@@ -219,6 +221,18 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.name = "fontfamily",
 		.attribute_offset = offsetof (LsmMathmlStyleElement, math_family),
 		.trait_class = &lsm_mathml_string_trait_class
+	},
+	{
+		.name = "fontstyle",
+		.attribute_offset = offsetof (LsmMathmlStyleElement, font_style),
+		.trait_class = &lsm_mathml_font_style_trait_class,
+		.trait_default = &font_style_default
+	},
+	{
+		.name = "fontweight",
+		.attribute_offset = offsetof (LsmMathmlStyleElement, font_weight),
+		.trait_class = &lsm_mathml_font_weight_trait_class,
+		.trait_default = &font_weight_default
 	}
 };
 
@@ -246,8 +260,6 @@ lsm_mathml_style_element_class_init (LsmMathmlStyleElementClass *style_class)
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "background",
 					  offsetof (LsmMathmlStyleElement, math_background));
 
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mathvariant",
-					  offsetof (LsmMathmlStyleElement, math_variant));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mathcolor",
 					  offsetof (LsmMathmlStyleElement, math_color));
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mathbackground",
@@ -257,10 +269,6 @@ lsm_mathml_style_element_class_init (LsmMathmlStyleElementClass *style_class)
 
 	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "color",
 					  offsetof (LsmMathmlStyleElement, math_color));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "fontweight",
-					  offsetof (LsmMathmlStyleElement, font_weight));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "fontstyle",
-					  offsetof (LsmMathmlStyleElement, font_style));
 }
 
 G_DEFINE_TYPE (LsmMathmlStyleElement, lsm_mathml_style_element, LSM_TYPE_MATHML_PRESENTATION_CONTAINER)
diff --git a/src/lsmmathmltableelement.c b/src/lsmmathmltableelement.c
index 3689111..edc7cfe 100644
--- a/src/lsmmathmltableelement.c
+++ b/src/lsmmathmltableelement.c
@@ -84,9 +84,6 @@ lsm_mathml_table_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 	enum_attribute = LSM_MATHML_LINE_NONE;
 	lsm_mathml_line_list_attribute_parse (&table->column_lines, &enum_list);
 
-	enum_attribute = LSM_MATHML_LINE_NONE;
-	lsm_mathml_line_attribute_parse (&table->frame, &enum_attribute);
-
 	space_list = lsm_mathml_space_list_new (2);
 
 	space_list->spaces[0].length.value = 0.4;
@@ -426,6 +423,7 @@ lsm_mathml_table_element_new (void)
 }
 
 static const gboolean equal_default = FALSE;
+static const LsmMathmlLine frame_default = LSM_MATHML_LINE_NONE;
 
 static void
 lsm_mathml_table_element_init (LsmMathmlTableElement *table)
@@ -439,6 +437,7 @@ lsm_mathml_table_element_init (LsmMathmlTableElement *table)
 
 	table->equal_columns.value = equal_default;
 	table->equal_rows.value = equal_default;
+	table->frame.value = frame_default;
 }
 
 static void
@@ -470,6 +469,12 @@ static const LsmAttributeInfos _attribute_infos[] = {
 		.attribute_offset = offsetof (LsmMathmlTableElement, equal_columns),
 		.trait_class = &lsm_mathml_boolean_trait_class,
 		.trait_default = &equal_default
+	},
+	{
+		.name = "frame",
+		.attribute_offset = offsetof (LsmMathmlTableElement, frame),
+		.trait_class = &lsm_mathml_line_trait_class,
+		.trait_default = &frame_default
 	}
 };
 
@@ -512,8 +517,6 @@ lsm_mathml_table_element_class_init (LsmMathmlTableElementClass *table_class)
 					   offsetof (LsmMathmlTableElement, row_lines));
 	lsm_mathml_attribute_map_add_enum_list (m_element_class->attributes, "columnlines",
 					   offsetof (LsmMathmlTableElement, column_lines));
-	lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "frame",
-					  offsetof (LsmMathmlTableElement, frame));
 	lsm_mathml_attribute_map_add_space_list (m_element_class->attributes, "framespacing",
 					   offsetof (LsmMathmlTableElement, frame_spacing));
 }
diff --git a/src/lsmmathmltraits.c b/src/lsmmathmltraits.c
index 05804f3..df15fc0 100644
--- a/src/lsmmathmltraits.c
+++ b/src/lsmmathmltraits.c
@@ -69,6 +69,160 @@ const LsmTraitClass lsm_mathml_unsigned_trait_class = {
 };
 
 static void
+lsm_mathml_display_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlDisplay *value = (LsmMathmlDisplay *) abstract_trait;
+
+	*value = lsm_mathml_display_from_string (string);
+}
+
+static char *
+lsm_mathml_display_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlDisplay *value = (LsmMathmlDisplay *) abstract_trait;
+
+	return g_strdup (lsm_mathml_display_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_display_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_display_trait_from_string,
+	.to_string = lsm_mathml_display_trait_to_string
+};
+
+static void
+lsm_mathml_mode_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlMode *value = (LsmMathmlMode *) abstract_trait;
+
+	*value = lsm_mathml_mode_from_string (string);
+}
+
+static char *
+lsm_mathml_mode_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlMode *value = (LsmMathmlMode *) abstract_trait;
+
+	return g_strdup (lsm_mathml_mode_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_mode_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_mode_trait_from_string,
+	.to_string = lsm_mathml_mode_trait_to_string
+};
+
+static void
+lsm_mathml_line_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlLine *value = (LsmMathmlLine *) abstract_trait;
+
+	*value = lsm_mathml_line_from_string (string);
+}
+
+static char *
+lsm_mathml_line_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlLine *value = (LsmMathmlLine *) abstract_trait;
+
+	return g_strdup (lsm_mathml_line_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_line_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_line_trait_from_string,
+	.to_string = lsm_mathml_line_trait_to_string
+};
+
+static void
+lsm_mathml_font_style_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlFontStyle *value = (LsmMathmlFontStyle *) abstract_trait;
+
+	*value = lsm_mathml_font_style_from_string (string);
+}
+
+static char *
+lsm_mathml_font_style_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlFontStyle *value = (LsmMathmlFontStyle *) abstract_trait;
+
+	return g_strdup (lsm_mathml_font_style_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_font_style_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_font_style_trait_from_string,
+	.to_string = lsm_mathml_font_style_trait_to_string
+};
+
+static void
+lsm_mathml_font_weight_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlFontWeight *value = (LsmMathmlFontWeight *) abstract_trait;
+
+	*value = lsm_mathml_font_weight_from_string (string);
+}
+
+static char *
+lsm_mathml_font_weight_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlFontWeight *value = (LsmMathmlFontWeight *) abstract_trait;
+
+	return g_strdup (lsm_mathml_font_weight_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_font_weight_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_font_weight_trait_from_string,
+	.to_string = lsm_mathml_font_weight_trait_to_string
+};
+
+static void
+lsm_mathml_variant_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlVariant *value = (LsmMathmlVariant *) abstract_trait;
+
+	*value = lsm_mathml_variant_from_string (string);
+}
+
+static char *
+lsm_mathml_variant_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlVariant *value = (LsmMathmlVariant *) abstract_trait;
+
+	return g_strdup (lsm_mathml_variant_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_variant_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_variant_trait_from_string,
+	.to_string = lsm_mathml_variant_trait_to_string
+};
+
+static void
+lsm_mathml_form_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmMathmlForm *value = (LsmMathmlForm *) abstract_trait;
+
+	*value = lsm_mathml_form_from_string (string);
+}
+
+static char *
+lsm_mathml_form_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmMathmlForm *value = (LsmMathmlForm *) abstract_trait;
+
+	return g_strdup (lsm_mathml_form_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_form_trait_class = {
+	.size = sizeof (unsigned),
+	.from_string = lsm_mathml_form_trait_from_string,
+	.to_string = lsm_mathml_form_trait_to_string
+};
+
+static void
 lsm_mathml_double_trait_from_string (LsmTrait *abstract_trait, char *string)
 {
 	double *value = (double *) abstract_trait;
diff --git a/src/lsmmathmltraits.h b/src/lsmmathmltraits.h
index dd30ebe..52fda1b 100644
--- a/src/lsmmathmltraits.h
+++ b/src/lsmmathmltraits.h
@@ -29,6 +29,13 @@ G_BEGIN_DECLS
 
 extern const LsmTraitClass lsm_mathml_boolean_trait_class;
 extern const LsmTraitClass lsm_mathml_unsigned_trait_class;
+extern const LsmTraitClass lsm_mathml_display_trait_class;
+extern const LsmTraitClass lsm_mathml_mode_trait_class;
+extern const LsmTraitClass lsm_mathml_line_trait_class;
+extern const LsmTraitClass lsm_mathml_font_style_trait_class;
+extern const LsmTraitClass lsm_mathml_font_weight_trait_class;
+extern const LsmTraitClass lsm_mathml_variant_trait_class;
+extern const LsmTraitClass lsm_mathml_form_trait_class;
 extern const LsmTraitClass lsm_mathml_double_trait_class;
 extern const LsmTraitClass lsm_mathml_string_trait_class;
 



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