[lasem/mml-attrs] [Mathml] Migration to lsm_attribute_manager WIP.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [lasem/mml-attrs] [Mathml] Migration to lsm_attribute_manager WIP.
- Date: Tue, 29 Dec 2009 19:19:32 +0000 (UTC)
commit 19a063b85539fb4864eeff5531bfa78ff5368f7e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Tue Dec 29 19:02:13 2009 +0100
[Mathml] Migration to lsm_attribute_manager WIP.
lsm_mathml_script_level_attribute
src/lsmmathmlattributes.c | 43 +++++++++++++++++--------------------------
src/lsmmathmlattributes.h | 15 ++++++++-------
src/lsmmathmlenums.h | 6 ++++++
src/lsmmathmlstyleelement.c | 16 ++++++++++------
src/lsmmathmltraits.c | 31 +++++++++++++++++++++++++++++++
src/lsmmathmltraits.h | 7 +++++++
6 files changed, 79 insertions(+), 39 deletions(-)
---
diff --git a/src/lsmmathmlattributes.c b/src/lsmmathmlattributes.c
index f72c70b..a897088 100644
--- a/src/lsmmathmlattributes.c
+++ b/src/lsmmathmlattributes.c
@@ -68,6 +68,23 @@ lsm_mathml_string_attribute_inherit (LsmMathmlStringAttribute *attribute, const
return attribute->value;
}
+int
+lsm_mathml_script_level_attribute_apply (LsmMathmlScriptLevelAttribute *attribute,
+ int script_level)
+{
+ if (attribute->base.value == NULL) {
+ attribute->value.level = script_level;
+ attribute->value.sign = LSM_MATHML_SCRIPT_LEVEL_SIGN_NONE;
+
+ return script_level;
+ }
+
+ if (attribute->value.sign == LSM_MATHML_SCRIPT_LEVEL_SIGN_NONE)
+ return attribute->value.level;
+
+ return script_level + attribute->value.level;
+}
+
double
lsm_mathml_length_attribute_normalize (LsmMathmlLengthAttribute *attribute, double default_value, double font_size)
{
@@ -493,32 +510,6 @@ lsm_mathml_attribute_map_add_enum_list (LsmMathmlAttributeMap *map,
}
void
-lsm_mathml_script_level_attribute_parse (LsmMathmlScriptLevelAttribute *attribute,
- int *style_value)
-{
- const char *string;
- int value;
-
- g_return_if_fail (attribute != NULL);
- g_return_if_fail (style_value != NULL);
-
- string = lsm_mathml_attribute_get_value ((LsmMathmlAttribute *) attribute);
- if (string == NULL) {
- attribute->value = *style_value;
- return;
- }
-
- value = atoi (string);
- if (string[0] == '+')
- attribute->value = value + *style_value;
- else if (string[0] == '-')
- attribute->value = value - *style_value;
- else
- attribute->value = value;
- *style_value = attribute->value;
-}
-
-void
lsm_mathml_space_attribute_parse (LsmMathmlSpaceAttribute *attribute,
LsmMathmlSpace *style_value,
LsmMathmlStyle *style)
diff --git a/src/lsmmathmlattributes.h b/src/lsmmathmlattributes.h
index 01ec6b4..1aa718c 100644
--- a/src/lsmmathmlattributes.h
+++ b/src/lsmmathmlattributes.h
@@ -52,6 +52,11 @@ typedef struct {
typedef struct {
LsmAttribute base;
+ LsmMathmlScriptLevel value;
+} LsmMathmlScriptLevelAttribute;
+
+typedef struct {
+ LsmAttribute base;
LsmMathmlColor color;
} LsmMathmlColorAttribute;
@@ -71,6 +76,9 @@ LsmMathmlColor lsm_mathml_color_attribute_inherit (LsmMathmlColorAttribute *at
const char * lsm_mathml_string_attribute_inherit (LsmMathmlStringAttribute *attribute,
const char *string);
+int lsm_mathml_script_level_attribute_apply (LsmMathmlScriptLevelAttribute *attribute,
+ int script_level);
+
typedef struct {
LsmAttribute base;
LsmMathmlLength length;
@@ -162,11 +170,6 @@ typedef struct {
typedef struct {
LsmMathmlAttribute attr;
- int value;
-} LsmMathmlScriptLevelAttribute;
-
-typedef struct {
- LsmMathmlAttribute attr;
LsmMathmlSpace space;
double value;
} LsmMathmlSpaceAttribute;
@@ -189,8 +192,6 @@ void lsm_mathml_attribute_map_add_enum_list (LsmMathmlAttributeMap *map,
char const *name,
ptrdiff_t offset);
-void lsm_mathml_script_level_attribute_parse (LsmMathmlScriptLevelAttribute *attribute,
- int *default_value);
void lsm_mathml_space_attribute_parse (LsmMathmlSpaceAttribute *attribute,
LsmMathmlSpace *style_value,
LsmMathmlStyle *style);
diff --git a/src/lsmmathmlenums.h b/src/lsmmathmlenums.h
index 9113de4..84a6135 100644
--- a/src/lsmmathmlenums.h
+++ b/src/lsmmathmlenums.h
@@ -163,6 +163,12 @@ typedef enum {
const char * lsm_mathml_line_to_string (LsmMathmlLine line);
LsmMathmlLine lsm_mathml_line_from_string (const char *string);
+typedef enum {
+ LSM_MATHML_SCRIPT_LEVEL_SIGN_NONE,
+ LSM_MATHML_SCRIPT_LEVEL_SIGN_PLUS,
+ LSM_MATHML_SCRIPT_LEVEL_SIGN_MINUS
+} LsmMathmlScriptLevelSign;
+
G_END_DECLS
#endif
diff --git a/src/lsmmathmlstyleelement.c b/src/lsmmathmlstyleelement.c
index db1a2c2..84cbe2f 100644
--- a/src/lsmmathmlstyleelement.c
+++ b/src/lsmmathmlstyleelement.c
@@ -40,6 +40,7 @@ static void
lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
{
gboolean display_style;
+ int new_script_level;
LsmMathmlStyleElement *style_element = LSM_MATHML_STYLE_ELEMENT (self);
@@ -53,7 +54,10 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
style->script_min_size,
style->math_size);
- lsm_mathml_script_level_attribute_parse (&style_element->script_level, &style->script_level);
+ new_script_level = lsm_mathml_script_level_attribute_apply (&style_element->script_level,
+ style->script_level);
+
+ lsm_mathml_style_change_script_level (style, new_script_level - style->script_level);
/* token */
@@ -143,6 +147,11 @@ static const LsmAttributeInfos _attribute_infos[] = {
.trait_class = &lsm_mathml_boolean_trait_class
},
{
+ .name = "scriptlevel",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, script_level),
+ .trait_class = &lsm_mathml_script_level_trait_class
+ },
+ {
.name = "scriptminsize",
.attribute_offset = offsetof (LsmMathmlStyleElement, script_min_size),
.trait_class = &lsm_mathml_length_trait_class,
@@ -273,11 +282,6 @@ lsm_mathml_style_element_class_init (LsmMathmlStyleElementClass *style_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, "scriptlevel",
- offsetof (LsmMathmlStyleElement, script_level));
}
G_DEFINE_TYPE (LsmMathmlStyleElement, lsm_mathml_style_element, LSM_TYPE_MATHML_PRESENTATION_CONTAINER)
diff --git a/src/lsmmathmltraits.c b/src/lsmmathmltraits.c
index 4492020..5911845 100644
--- a/src/lsmmathmltraits.c
+++ b/src/lsmmathmltraits.c
@@ -224,6 +224,37 @@ const LsmTraitClass lsm_mathml_form_trait_class = {
};
static void
+lsm_mathml_script_level_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+ LsmMathmlScriptLevel *value = (LsmMathmlScriptLevel *) abstract_trait;
+
+ value->level = atoi (string);
+ if (string[0] == '+')
+ value->sign = LSM_MATHML_SCRIPT_LEVEL_SIGN_PLUS;
+ else if (string[0] == '-')
+ value->sign = LSM_MATHML_SCRIPT_LEVEL_SIGN_MINUS;
+ else
+ value->sign = LSM_MATHML_SCRIPT_LEVEL_SIGN_NONE;
+}
+
+static char *
+lsm_mathml_script_level_trait_to_string (LsmTrait *abstract_trait)
+{
+ LsmMathmlScriptLevel *value = (LsmMathmlScriptLevel *) abstract_trait;
+
+ if (value->sign == LSM_MATHML_SCRIPT_LEVEL_SIGN_PLUS)
+ return g_strdup_printf ("+%d", value->level);
+
+ return g_strdup_printf ("%d", value->level);
+}
+
+const LsmTraitClass lsm_mathml_script_level_trait_class = {
+ .size = sizeof (int),
+ .from_string = lsm_mathml_script_level_trait_from_string,
+ .to_string = lsm_mathml_script_level_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 b40d4d7..f17936a 100644
--- a/src/lsmmathmltraits.h
+++ b/src/lsmmathmltraits.h
@@ -56,6 +56,11 @@ typedef struct {
GType lsm_mathml_length_get_type (void);
double lsm_mathml_length_normalize (const LsmMathmlLength *length, double default_value, double font_size);
+typedef struct {
+ LsmMathmlScriptLevelSign sign;
+ int level;
+} LsmMathmlScriptLevel;
+
#define LSM_TYPE_MATHML_SPACE (lsm_mathml_space_get_type())
typedef struct {
@@ -88,6 +93,8 @@ 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_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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]