[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: Sun, 27 Dec 2009 21:25:35 +0000 (UTC)
commit 6a616cb41aad4ca3bdd309051c8a536876d21e6e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sun Dec 27 18:16:00 2009 +0100
[Mathml] Migration to lsm_attribute_manager WIP.
lsm_mathml_length_attribute
src/lsmmathmlattributes.c | 201 ++++++++------------------------------
src/lsmmathmlattributes.h | 29 ++----
src/lsmmathmlelement.c | 4 +-
src/lsmmathmlfractionelement.c | 20 +++--
src/lsmmathmlmathelement.c | 47 +++-------
src/lsmmathmlpresentationtoken.c | 24 +++--
src/lsmmathmlscriptelement.c | 46 +++++++--
src/lsmmathmlspaceelement.c | 41 +++++---
src/lsmmathmlstyle.c | 16 +--
src/lsmmathmlstyle.h | 33 +++----
src/lsmmathmlstyleelement.c | 156 +++++++++++++++++++----------
src/lsmmathmltraits.c | 94 ++++++++++++++++++
src/lsmmathmltraits.h | 14 +++
13 files changed, 385 insertions(+), 340 deletions(-)
---
diff --git a/src/lsmmathmlattributes.c b/src/lsmmathmlattributes.c
index 4a6948f..2a10dc2 100644
--- a/src/lsmmathmlattributes.c
+++ b/src/lsmmathmlattributes.c
@@ -20,15 +20,6 @@
*/
#include <lsmmathmlattributes.h>
-#include <lsmmathmlstyle.h>
-#include <lsmdebug.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib/gmem.h>
-#include <glib/ghash.h>
-#include <glib-object.h>
-#include <math.h>
gboolean
lsm_mathml_boolean_attribute_inherit (LsmMathmlBooleanAttribute *attribute, gboolean value)
@@ -59,6 +50,26 @@ lsm_mathml_string_attribute_inherit (LsmMathmlStringAttribute *attribute, const
return attribute->value;
}
+double
+lsm_mathml_length_attribute_normalize (LsmMathmlLengthAttribute *attribute, double default_value, double font_size)
+{
+ g_return_val_if_fail (attribute != NULL, 0.0);
+
+ attribute->value = lsm_mathml_length_normalize (&attribute->length, default_value, font_size);
+
+ return attribute->value;
+}
+
+#include <lsmmathmlstyle.h>
+#include <lsmdebug.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib/gmem.h>
+#include <glib/ghash.h>
+#include <glib-object.h>
+#include <math.h>
+
/**************************/
typedef struct {
@@ -486,30 +497,6 @@ lsm_mathml_color_get_type (void)
return our_type;
}
-static LsmMathmlLength *
-lsm_mathml_length_copy (LsmMathmlLength *length)
-{
- LsmMathmlLength *copy;
-
- copy = g_new (LsmMathmlLength, 1);
- memcpy (copy, length, sizeof (LsmMathmlLength));
-
- return copy;
-}
-
-GType
-lsm_mathml_length_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- our_type = g_boxed_type_register_static
- ("LsmMathmlLength",
- (GBoxedCopyFunc) lsm_mathml_length_copy,
- (GBoxedFreeFunc) g_free);
- return our_type;
-}
-
static LsmMathmlSpace *
lsm_mathml_space_copy (LsmMathmlSpace *space)
{
@@ -547,37 +534,6 @@ lsm_mathml_space_list_get_type (void)
return our_type;
}
-double
-lsm_mathml_length_compute (const LsmMathmlLength *length, double default_value, double font_size)
-{
- g_return_val_if_fail (length != NULL, 0.0);
-
- switch (length->unit) {
- case LSM_MATHML_UNIT_PX:
- case LSM_MATHML_UNIT_PT:
- return length->value;
- case LSM_MATHML_UNIT_PC:
- return length->value * 72.0 / 6.0;
- case LSM_MATHML_UNIT_CM:
- return length->value * 72.0 / 2.54;
- case LSM_MATHML_UNIT_MM:
- return length->value * 72.0 / 25.4;
- case LSM_MATHML_UNIT_IN:
- return length->value * 72.0;
- case LSM_MATHML_UNIT_EM:
- return length->value * font_size;
- case LSM_MATHML_UNIT_EX:
- return length->value * font_size * 0.5;
- case LSM_MATHML_UNIT_PERCENT:
- return default_value * length->value / 100.0;
- case LSM_MATHML_UNIT_NONE:
- return default_value * length->value;
- }
-
- return 0.0;
-}
-
-
void
lsm_mathml_script_level_attribute_parse (LsmMathmlScriptLevelAttribute *attribute,
int *style_value)
@@ -689,53 +645,6 @@ lsm_mathml_line_attribute_parse (LsmMathmlEnumAttribute *attribute,
}
void
-lsm_mathml_length_attribute_parse (LsmMathmlLengthAttribute *attribute,
- LsmMathmlLength *style_value,
- double font_size)
-{
- const char *string;
- char *unit_str;
-
- 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->length = *style_value;
- } else {
- LsmMathmlUnit unit;
- 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->unit;
- if (unit_str[0] != '\0') {
- if (strcmp (unit_str, "big") == 0) {
- value = 1.5;
- } else if (strcmp (unit_str, "small") == 0) {
- value = 0.75;
- } else if (strcmp (unit_str, "normal") == 0) {
- value = 1.0;
- }
- }
- value *= style_value->value;
- } else if (unit == LSM_MATHML_UNIT_PERCENT) {
- unit = style_value->unit;
- value *= style_value->value / 100.0;
- }
-
- attribute->length.unit = unit;
- attribute->length.value = value;
-
- *style_value = attribute->length;
- }
-
- attribute->value = lsm_mathml_length_compute (&attribute->length, style_value->value, font_size);
-}
-
-void
lsm_mathml_space_attribute_parse (LsmMathmlSpaceAttribute *attribute,
LsmMathmlSpace *style_value,
LsmMathmlStyle *style)
@@ -778,48 +687,34 @@ lsm_mathml_space_attribute_parse (LsmMathmlSpaceAttribute *attribute,
switch (attribute->space.name) {
case LSM_MATHML_SPACE_NAME_VERY_VERY_THIN:
- attribute->value = lsm_mathml_length_compute (&style->very_very_thin_math_space,
- style->very_very_thin_math_space_value,
- style->math_size_value);
+ attribute->value = style->very_very_thin_math_space;
break;
case LSM_MATHML_SPACE_NAME_VERY_THIN:
- attribute->value = lsm_mathml_length_compute (&style->very_thin_math_space,
- style->very_thin_math_space_value,
- style->math_size_value);
+ attribute->value = style->very_thin_math_space;
break;
case LSM_MATHML_SPACE_NAME_THIN:
- attribute->value = lsm_mathml_length_compute (&style->thin_math_space,
- style->thin_math_space_value,
- style->math_size_value);
+ attribute->value = style->thin_math_space;
break;
case LSM_MATHML_SPACE_NAME_MEDIUM:
- attribute->value = lsm_mathml_length_compute (&style->medium_math_space,
- style->medium_math_space_value,
- style->math_size_value);
+ attribute->value = style->medium_math_space;
break;
case LSM_MATHML_SPACE_NAME_THICK:
- attribute->value = lsm_mathml_length_compute (&style->thick_math_space,
- style->thick_math_space_value,
- style->math_size_value);
+ attribute->value = style->thick_math_space;
break;
case LSM_MATHML_SPACE_NAME_VERY_THICK:
- attribute->value = lsm_mathml_length_compute (&style->very_thick_math_space,
- style->very_thick_math_space_value,
- style->math_size_value);
+ attribute->value = style->very_thick_math_space;
break;
case LSM_MATHML_SPACE_NAME_VERY_VERY_THICK:
- attribute->value = lsm_mathml_length_compute (&style->very_very_thick_math_space,
- style->very_very_thick_math_space_value,
- style->math_size_value);
+ 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_compute (&attribute->space.length,
- style_value->length.value,
- style->math_size_value);
+ attribute->value = lsm_mathml_length_normalize (&attribute->space.length,
+ style_value->length.value,
+ style->math_size);
}
}
@@ -960,39 +855,25 @@ lsm_mathml_space_list_attribute_parse (LsmMathmlSpaceListAttribute *attribute,
for (i = 0; i < attribute->space_list->n_spaces; i++) {
switch (attribute->space_list->spaces[i].name) {
case LSM_MATHML_SPACE_NAME_VERY_VERY_THIN:
- attribute->values[i] = lsm_mathml_length_compute (&style->very_very_thin_math_space,
- style->very_very_thin_math_space_value,
- style->math_size_value);
+ attribute->values[i] = style->very_very_thin_math_space;
break;
case LSM_MATHML_SPACE_NAME_VERY_THIN:
- attribute->values[i] = lsm_mathml_length_compute (&style->very_thin_math_space,
- style->very_thin_math_space_value,
- style->math_size_value);
+ attribute->values[i] = style->very_thin_math_space;
break;
case LSM_MATHML_SPACE_NAME_THIN:
- attribute->values[i] = lsm_mathml_length_compute (&style->thin_math_space,
- style->thin_math_space_value,
- style->math_size_value);
+ attribute->values[i] = style->thin_math_space;
break;
case LSM_MATHML_SPACE_NAME_MEDIUM:
- attribute->values[i] = lsm_mathml_length_compute (&style->medium_math_space,
- style->medium_math_space_value,
- style->math_size_value);
+ attribute->values[i] = style->medium_math_space;
break;
case LSM_MATHML_SPACE_NAME_THICK:
- attribute->values[i] = lsm_mathml_length_compute (&style->thick_math_space,
- style->thick_math_space_value,
- style->math_size_value);
+ attribute->values[i] = style->thick_math_space;
break;
case LSM_MATHML_SPACE_NAME_VERY_THICK:
- attribute->values[i] = lsm_mathml_length_compute (&style->very_thick_math_space,
- style->very_thick_math_space_value,
- style->math_size_value);
+ attribute->values[i] = style->very_thick_math_space;
break;
case LSM_MATHML_SPACE_NAME_VERY_VERY_THICK:
- attribute->values[i] = lsm_mathml_length_compute (&style->very_very_thick_math_space,
- style->very_very_thick_math_space_value,
- style->math_size_value);
+ attribute->values[i] = style->very_very_thick_math_space;
break;
case LSM_MATHML_SPACE_NAME_ERROR:
default:
@@ -1001,15 +882,15 @@ lsm_mathml_space_list_attribute_parse (LsmMathmlSpaceListAttribute *attribute,
index = MIN (i, style_value->n_spaces - 1);
- attribute->values[i] = lsm_mathml_length_compute
+ attribute->values[i] = lsm_mathml_length_normalize
(&attribute->space_list->spaces[i].length,
style_value->spaces[index].length.value,
- style->math_size_value);
+ style->math_size);
} else
- attribute->values[i] = lsm_mathml_length_compute
+ attribute->values[i] = lsm_mathml_length_normalize
(&attribute->space_list->spaces[i].length,
0.0,
- style->math_size_value);
+ style->math_size);
}
}
}
diff --git a/src/lsmmathmlattributes.h b/src/lsmmathmlattributes.h
index 02f5352..f181ea7 100644
--- a/src/lsmmathmlattributes.h
+++ b/src/lsmmathmlattributes.h
@@ -55,6 +55,15 @@ gboolean lsm_mathml_boolean_attribute_inherit (LsmMathmlBooleanAttribute *attri
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;
+ LsmMathmlLength length;
+ double value;
+} LsmMathmlLengthAttribute;
+
+double lsm_mathml_length_attribute_normalize (LsmMathmlLengthAttribute *atribute, double default_value,
+ double font_size);
+
/*******************************/
typedef struct {
@@ -164,15 +173,6 @@ GType lsm_mathml_length_get_type (void);
#define LSM_TYPE_MATHML_LENGTH (lsm_mathml_length_get_type())
typedef struct {
- double value;
- LsmMathmlUnit unit;
-} LsmMathmlLength;
-
-GType lsm_mathml_space_get_type (void);
-
-#define LSM_TYPE_MATHML_SPACE (lsm_mathml_space_get_type())
-
-typedef struct {
LsmMathmlSpaceName name;
LsmMathmlLength length;
} LsmMathmlSpace;
@@ -186,8 +186,6 @@ typedef struct {
LsmMathmlSpace *spaces;
} LsmMathmlSpaceList;
-double lsm_mathml_length_compute (const LsmMathmlLength *length, double default_value, double font_size);
-
typedef struct {
LsmMathmlAttribute attr;
int value;
@@ -200,12 +198,6 @@ typedef struct {
typedef struct {
LsmMathmlAttribute attr;
- LsmMathmlLength length;
- double value;
-} LsmMathmlLengthAttribute;
-
-typedef struct {
- LsmMathmlAttribute attr;
LsmMathmlSpace space;
double value;
} LsmMathmlSpaceAttribute;
@@ -249,9 +241,6 @@ 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_length_attribute_parse (LsmMathmlLengthAttribute *attribute,
- LsmMathmlLength *style_value,
- double font_size);
void lsm_mathml_space_attribute_parse (LsmMathmlSpaceAttribute *attribute,
LsmMathmlSpace *style_value,
LsmMathmlStyle *style);
diff --git a/src/lsmmathmlelement.c b/src/lsmmathmlelement.c
index 3bbb967..30b7234 100644
--- a/src/lsmmathmlelement.c
+++ b/src/lsmmathmlelement.c
@@ -131,12 +131,12 @@ lsm_mathml_element_update (LsmMathmlElement *self, const LsmMathmlStyle *parent_
lsm_debug ("[Element::update] update %s (%s-%g)",
lsm_dom_node_get_node_name (LSM_DOM_NODE (self)),
style->math_family != NULL ? style->math_family : "undefined" ,
- style->math_size_value);
+ style->math_size);
g_free (self->style.math_family);
self->style.math_family = g_strdup (style->math_family);
self->style.math_variant = style->math_variant;
- self->style.math_size = style->math_size_value;
+ self->style.math_size = style->math_size;
self->style.math_color = style->math_color;
self->style.math_background = style->math_background;
diff --git a/src/lsmmathmlfractionelement.c b/src/lsmmathmlfractionelement.c
index 5fdc9e3..469fcca 100644
--- a/src/lsmmathmlfractionelement.c
+++ b/src/lsmmathmlfractionelement.c
@@ -48,7 +48,9 @@ lsm_mathml_fraction_element_update (LsmMathmlElement *self, LsmMathmlStyle *styl
{
LsmMathmlFractionElement *fraction = LSM_MATHML_FRACTION_ELEMENT (self);
- lsm_mathml_length_attribute_parse (&fraction->line_thickness, &style->line_thickness, style->math_size_value);
+ style->line_thickness = lsm_mathml_length_attribute_normalize (&fraction->line_thickness,
+ style->line_thickness,
+ style->math_size);
fraction->display = style->display;
}
@@ -190,12 +192,15 @@ lsm_mathml_fraction_element_new (void)
return g_object_new (LSM_TYPE_MATHML_FRACTION_ELEMENT, NULL);
}
+static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+
static void
lsm_mathml_fraction_element_init (LsmMathmlFractionElement *self)
{
self->axis_offset = 0.0;
self->bevelled.value = bevelled_default;
+ self->line_thickness.length = length_default;
}
/* LsmMathmlFractionElement class */
@@ -206,7 +211,13 @@ static const LsmAttributeInfos _attribute_infos[] = {
.attribute_offset = offsetof (LsmMathmlFractionElement, bevelled),
.trait_class = &lsm_mathml_boolean_trait_class,
.trait_default = &bevelled_default
- }
+ },
+ {
+ .name = "linethickness",
+ .attribute_offset = offsetof (LsmMathmlFractionElement, line_thickness),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
};
static void
@@ -232,11 +243,6 @@ lsm_mathml_fraction_element_class_init (LsmMathmlFractionElementClass *fraction_
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, "linethickness",
- offsetof (LsmMathmlFractionElement, line_thickness));
}
G_DEFINE_TYPE (LsmMathmlFractionElement, lsm_mathml_fraction_element, LSM_TYPE_MATHML_ELEMENT)
diff --git a/src/lsmmathmlmathelement.c b/src/lsmmathmlmathelement.c
index f893d26..21e81a0 100644
--- a/src/lsmmathmlmathelement.c
+++ b/src/lsmmathmlmathelement.c
@@ -121,42 +121,24 @@ lsm_mathml_math_element_init (LsmMathmlMathElement *self)
self->default_style = style;
g_return_if_fail (style != NULL);
- style->math_size_value = 12.0;
+ style->math_size = 12.0;
style->display = LSM_MATHML_DISPLAY_INLINE;
style->script_level = 0;
style->script_size_multiplier = 0.71;
- style->script_min_size.value = 8.0;
- style->script_min_size.unit = LSM_MATHML_UNIT_PT;
-
- style->very_very_thin_math_space.value = LSM_MATHML_SPACE_EM_VERY_VERY_THIN;
- style->very_very_thin_math_space.unit = LSM_MATHML_UNIT_EM;
- style->very_thin_math_space.value = LSM_MATHML_SPACE_EM_VERY_THIN;
- style->very_thin_math_space.unit = LSM_MATHML_UNIT_EM;
- style->thin_math_space.value = LSM_MATHML_SPACE_EM_THIN;
- style->thin_math_space.unit = LSM_MATHML_UNIT_EM;
- style->medium_math_space.value = LSM_MATHML_SPACE_EM_MEDIUM;
- style->medium_math_space.unit = LSM_MATHML_UNIT_EM;
- style->thick_math_space.value = LSM_MATHML_SPACE_EM_THICK;
- style->thick_math_space.unit = LSM_MATHML_UNIT_EM;
- style->very_thick_math_space.value = LSM_MATHML_SPACE_EM_VERY_THICK;
- style->very_thick_math_space.unit = LSM_MATHML_UNIT_EM;
- style->very_very_thick_math_space.value = LSM_MATHML_SPACE_EM_VERY_VERY_THICK;
- style->very_very_thick_math_space.unit = LSM_MATHML_UNIT_EM;
-
- style->very_very_thin_math_space_value = LSM_MATHML_SPACE_EM_VERY_VERY_THIN * style->math_size_value;
- style->very_thin_math_space_value = LSM_MATHML_SPACE_EM_VERY_THIN * style->math_size_value;
- style->thin_math_space_value = LSM_MATHML_SPACE_EM_THIN * style->math_size_value;
- style->medium_math_space_value = LSM_MATHML_SPACE_EM_MEDIUM * style->math_size_value;
- style->thick_math_space_value = LSM_MATHML_SPACE_EM_THICK * style->math_size_value;
- style->very_thick_math_space_value = LSM_MATHML_SPACE_EM_VERY_THICK * style->math_size_value;
- style->very_very_thick_math_space_value = LSM_MATHML_SPACE_EM_VERY_VERY_THICK * style->math_size_value;
+ style->script_min_size = 8.0;
+
+ style->very_very_thin_math_space = LSM_MATHML_SPACE_EM_VERY_VERY_THIN * style->math_size;
+ style->very_thin_math_space = LSM_MATHML_SPACE_EM_VERY_THIN * style->math_size;
+ style->thin_math_space = LSM_MATHML_SPACE_EM_THIN * style->math_size;
+ style->medium_math_space = LSM_MATHML_SPACE_EM_MEDIUM * style->math_size;
+ style->thick_math_space = LSM_MATHML_SPACE_EM_THICK * style->math_size;
+ style->very_thick_math_space = LSM_MATHML_SPACE_EM_VERY_THICK * style->math_size;
+ style->very_very_thick_math_space = LSM_MATHML_SPACE_EM_VERY_VERY_THICK * style->math_size;
style->math_family = g_strdup ("Serif");
style->math_variant = LSM_MATHML_VARIANT_NORMAL;
- style->math_size.value = 12.0;
- style->math_size.unit = LSM_MATHML_UNIT_PT;
style->math_color.red = 0;
style->math_color.green = 0;
style->math_color.blue = 0;
@@ -166,13 +148,10 @@ lsm_mathml_math_element_init (LsmMathmlMathElement *self)
style->math_background.blue = 0;
style->math_background.alpha = 0;
- style->subscript_shift.value = 0;
- style->subscript_shift.unit = LSM_MATHML_UNIT_PT;
- style->superscript_shift.value = 0;
- style->superscript_shift.unit = LSM_MATHML_UNIT_PT;
+ style->subscript_shift = 0;
+ style->superscript_shift = 0;
- style->line_thickness.value = 0.1;
- style->line_thickness.unit = LSM_MATHML_UNIT_EM;
+ style->line_thickness = 0.1 * style->math_size;
}
static void
diff --git a/src/lsmmathmlpresentationtoken.c b/src/lsmmathmlpresentationtoken.c
index 93f44f5..0104f67 100644
--- a/src/lsmmathmlpresentationtoken.c
+++ b/src/lsmmathmlpresentationtoken.c
@@ -116,11 +116,10 @@ lsm_mathml_presentation_token_update (LsmMathmlElement *self, LsmMathmlStyle *st
lsm_mathml_string_attribute_inherit (&token->math_family,
style->math_family));
lsm_mathml_variant_attribute_parse (&token->math_variant, &style->math_variant);
- lsm_mathml_length_attribute_parse (&token->math_size, &style->math_size, style->math_size_value);
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_value = token->math_size.value;
+ style->math_size = lsm_mathml_length_attribute_normalize (&token->math_size, style->math_size,
+ style->math_size);
}
static const LsmMathmlBbox *
@@ -198,9 +197,12 @@ lsm_mathml_text_element_new (void)
return node;
}
+static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+
static void
lsm_mathml_presentation_token_init (LsmMathmlPresentationToken *token)
{
+ token->math_size.length = length_default;
}
/* LsmMathmlPresentationToken class */
@@ -211,11 +213,23 @@ static const LsmAttributeInfos _attribute_infos[] = {
.attribute_offset = offsetof (LsmMathmlPresentationToken, math_family),
.trait_class = &lsm_mathml_string_trait_class
},
+ {
+ .name = "mathsize",
+ .attribute_offset = offsetof (LsmMathmlPresentationToken, math_size),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
/* Deprecated attributes */
{
.name = "fontfamily",
.attribute_offset = offsetof (LsmMathmlPresentationToken, math_family),
.trait_class = &lsm_mathml_string_trait_class
+ },
+ {
+ .name = "fontsize",
+ .attribute_offset = offsetof (LsmMathmlPresentationToken, math_size),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
}
};
@@ -248,8 +262,6 @@ lsm_mathml_presentation_token_class_init (LsmMathmlPresentationTokenClass *m_tok
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, "mathsize",
- offsetof (LsmMathmlPresentationToken, math_size));
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",
@@ -257,8 +269,6 @@ lsm_mathml_presentation_token_class_init (LsmMathmlPresentationTokenClass *m_tok
/* Deprecated attributes */
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "fontsize",
- offsetof (LsmMathmlPresentationToken, math_size));
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",
diff --git a/src/lsmmathmlscriptelement.c b/src/lsmmathmlscriptelement.c
index 3a13007..4880529 100644
--- a/src/lsmmathmlscriptelement.c
+++ b/src/lsmmathmlscriptelement.c
@@ -113,8 +113,12 @@ lsm_mathml_script_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
{
LsmMathmlScriptElement *script = LSM_MATHML_SCRIPT_ELEMENT (self);
- lsm_mathml_length_attribute_parse (&script->superscript_shift, &style->superscript_shift, style->math_size_value);
- lsm_mathml_length_attribute_parse (&script->subscript_shift, &style->subscript_shift, style->math_size_value);
+ 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);
script->display = style->display;
}
@@ -149,13 +153,13 @@ lsm_mathml_script_element_measure (LsmMathmlElement *element, LsmMathmlView *vie
LsmMathmlScriptElement *script = LSM_MATHML_SCRIPT_ELEMENT (element);
lsm_mathml_measure_sub_sup (element,view,
- script->base,
- script->subscript,
- script->superscript,
- script->subscript_shift.value,
- script->superscript_shift.value,
- script->display, stretch_bbox, &element->bbox,
- &script->subscript_offset, &script->superscript_offset);
+ script->base,
+ script->subscript,
+ script->superscript,
+ script->subscript_shift.value,
+ script->superscript_shift.value,
+ script->display, stretch_bbox, &element->bbox,
+ &script->subscript_offset, &script->superscript_offset);
return &element->bbox;
}
@@ -220,13 +224,32 @@ lsm_mathml_sub_sup_element_new (void)
return node;
}
+static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+
static void
lsm_mathml_script_element_init (LsmMathmlScriptElement *self)
{
+ self->subscript_shift.length = length_default;
+ self->superscript_shift.length = length_default;
}
/* LsmMathmlScriptElement class */
+static const LsmAttributeInfos _attribute_infos[] = {
+ {
+ .name = "subscriptshift",
+ .attribute_offset = offsetof (LsmMathmlScriptElement, subscript_shift),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "superscriptshift",
+ .attribute_offset = offsetof (LsmMathmlScriptElement, superscript_shift),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ }
+};
+
static void
lsm_mathml_script_element_class_init (LsmMathmlScriptElementClass *script_class)
{
@@ -243,6 +266,11 @@ lsm_mathml_script_element_class_init (LsmMathmlScriptElementClass *script_class)
m_element_class->layout = lsm_mathml_script_element_layout;
m_element_class->get_embellished_core = lsm_mathml_script_element_get_embellished_core;
m_element_class->is_inferred_row = NULL;
+ 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);
}
G_DEFINE_TYPE (LsmMathmlScriptElement, lsm_mathml_script_element, LSM_TYPE_MATHML_ELEMENT)
diff --git a/src/lsmmathmlspaceelement.c b/src/lsmmathmlspaceelement.c
index 4aa6ad0..a4ce289 100644
--- a/src/lsmmathmlspaceelement.c
+++ b/src/lsmmathmlspaceelement.c
@@ -46,8 +46,6 @@ lsm_mathml_space_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
{
LsmMathmlSpaceElement *space_element = LSM_MATHML_SPACE_ELEMENT (self);
LsmMathmlSpace space;
- LsmMathmlLength length;
-
space.length.unit = LSM_MATHML_UNIT_EM;
space.length.value = 0;
@@ -55,15 +53,8 @@ lsm_mathml_space_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
lsm_mathml_space_attribute_parse (&space_element->width, &space, style);
- length.unit = LSM_MATHML_UNIT_EM;
- length.value = 0.0;
-
- lsm_mathml_length_attribute_parse (&space_element->height, &length, style->math_size_value);
-
- length.unit = LSM_MATHML_UNIT_EM;
- length.value = 0.0;
-
- lsm_mathml_length_attribute_parse (&space_element->depth, &length, style->math_size_value);
+ 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);
}
static const LsmMathmlBbox *
@@ -94,13 +85,32 @@ lsm_mathml_space_element_new (void)
return g_object_new (LSM_TYPE_MATHML_SPACE_ELEMENT, NULL);
}
+static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+
static void
lsm_mathml_space_element_init (LsmMathmlSpaceElement *self)
{
+ self->height.length = length_default;
+ self->depth.length = length_default;
}
/* LsmMathmlSpaceElement class */
+static const LsmAttributeInfos _attribute_infos[] = {
+ {
+ .name = "height",
+ .attribute_offset = offsetof (LsmMathmlSpaceElement, height),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "depth",
+ .attribute_offset = offsetof (LsmMathmlSpaceElement, depth),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ }
+};
+
static void
lsm_mathml_space_element_class_init (LsmMathmlSpaceElementClass *space_class)
{
@@ -116,15 +126,16 @@ lsm_mathml_space_element_class_init (LsmMathmlSpaceElementClass *space_class)
m_element_class->measure = lsm_mathml_space_element_measure;
m_element_class->layout = lsm_mathml_space_element_layout;
m_element_class->is_inferred_row = NULL;
+ 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);
lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "width",
offsetof (LsmMathmlSpaceElement, width));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "height",
- offsetof (LsmMathmlSpaceElement, height));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "depth",
- offsetof (LsmMathmlSpaceElement, depth));
}
G_DEFINE_TYPE (LsmMathmlSpaceElement, lsm_mathml_space_element, LSM_TYPE_MATHML_ELEMENT)
diff --git a/src/lsmmathmlstyle.c b/src/lsmmathmlstyle.c
index a71489d..70db090 100644
--- a/src/lsmmathmlstyle.c
+++ b/src/lsmmathmlstyle.c
@@ -75,14 +75,11 @@ lsm_mathml_style_change_script_level (LsmMathmlStyle *style, int increment)
{
g_return_if_fail (style != NULL);
- style->math_size_value = style->math_size_value * pow (style->script_size_multiplier, increment);
+ style->math_size = style->math_size * pow (style->script_size_multiplier, increment);
style->script_level += increment;
- if (style->math_size_value < style->script_min_size.value)
- style->math_size_value = style->script_min_size.value;
-
- style->math_size.value = style->math_size_value;
- style->math_size.unit = LSM_MATHML_UNIT_PT;
+ if (style->math_size < style->script_min_size)
+ style->math_size = style->script_min_size;
}
void
@@ -90,9 +87,7 @@ lsm_mathml_style_set_math_size_pt (LsmMathmlStyle *style, double math_size)
{
g_return_if_fail (style != NULL);
- style->math_size_value = math_size;
- style->math_size.value = math_size;
- style->math_size.unit = LSM_MATHML_UNIT_PT;
+ style->math_size = math_size;
}
void
@@ -100,8 +95,7 @@ lsm_mathml_style_set_script_min_size_pt (LsmMathmlStyle *style, double script_mi
{
g_return_if_fail (style != NULL);
- style->script_min_size.value = script_min_size;
- style->script_min_size.unit = LSM_MATHML_UNIT_PT;
+ style->script_min_size = script_min_size;
}
void
diff --git a/src/lsmmathmlstyle.h b/src/lsmmathmlstyle.h
index 53fb441..f1a83a4 100644
--- a/src/lsmmathmlstyle.h
+++ b/src/lsmmathmlstyle.h
@@ -32,42 +32,33 @@ GType lsm_mathml_style_get_type (void);
#define LSM_TYPE_MATHML_STYLE (lsm_mathml_style_get_type())
struct _LsmMathmlStyle {
- double math_size_value;
/* mstyle */
LsmMathmlDisplay display;
int script_level;
double script_size_multiplier;
- LsmMathmlLength script_min_size;
+ double script_min_size;
- LsmMathmlLength very_very_thin_math_space;
- LsmMathmlLength very_thin_math_space;
- LsmMathmlLength thin_math_space;
- LsmMathmlLength medium_math_space;
- LsmMathmlLength thick_math_space;
- LsmMathmlLength very_thick_math_space;
- LsmMathmlLength very_very_thick_math_space;
-
- double very_very_thin_math_space_value;
- double very_thin_math_space_value;
- double thin_math_space_value;
- double medium_math_space_value;
- double thick_math_space_value;
- double very_thick_math_space_value;
- double very_very_thick_math_space_value;
+ double very_very_thin_math_space;
+ double very_thin_math_space;
+ double thin_math_space;
+ double medium_math_space;
+ double thick_math_space;
+ double very_thick_math_space;
+ double very_very_thick_math_space;
/* tokens */
char *math_family;
LsmMathmlVariant math_variant;
- LsmMathmlLength math_size;
+ double math_size;
LsmMathmlColor math_color;
LsmMathmlColor math_background;
/* mfrac */
gboolean bevelled;
/* msubsup */
- LsmMathmlLength subscript_shift;
- LsmMathmlLength superscript_shift;
+ double subscript_shift;
+ double superscript_shift;
/* mfrac */
- LsmMathmlLength line_thickness;
+ double line_thickness;
};
LsmMathmlStyle * lsm_mathml_style_new (void);
diff --git a/src/lsmmathmlstyleelement.c b/src/lsmmathmlstyleelement.c
index 594ccee..b15fdc0 100644
--- a/src/lsmmathmlstyleelement.c
+++ b/src/lsmmathmlstyleelement.c
@@ -52,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);
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,
- style->math_size_value);
+ style->script_min_size = lsm_mathml_length_attribute_normalize (&style_element->script_min_size,
+ style->script_min_size,
+ style->math_size);
lsm_mathml_script_level_attribute_parse (&style_element->script_level, &style->script_level);
@@ -73,43 +73,42 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
lsm_mathml_style_set_math_family (style,
lsm_mathml_string_attribute_inherit (&style_element->math_family,
style->math_family));
- lsm_mathml_length_attribute_parse (&style_element->math_size, &style->math_size, style->math_size_value);
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_size_value = style_element->math_size.value;
+ style->math_size = lsm_mathml_length_attribute_normalize (&style_element->math_size,
+ style->math_size,
+ style->math_size);
/* mstyle */
- lsm_mathml_length_attribute_parse (&style_element->very_very_thin_math_space,
- &style->very_very_thin_math_space, style->math_size_value);
- lsm_mathml_length_attribute_parse (&style_element->very_thin_math_space,
- &style->very_thin_math_space, style->math_size_value);
- lsm_mathml_length_attribute_parse (&style_element->thin_math_space,
- &style->thin_math_space, style->math_size_value);
- lsm_mathml_length_attribute_parse (&style_element->medium_math_space,
- &style->medium_math_space, style->math_size_value);
- lsm_mathml_length_attribute_parse (&style_element->thick_math_space,
- &style->thick_math_space, style->math_size_value);
- lsm_mathml_length_attribute_parse (&style_element->very_thick_math_space,
- &style->very_thick_math_space, style->math_size_value);
- lsm_mathml_length_attribute_parse (&style_element->very_very_thick_math_space,
- &style->very_very_thick_math_space, style->math_size_value);
-
- style->very_very_thin_math_space_value = style_element->very_very_thin_math_space.value;
- style->very_thin_math_space_value = style_element->very_thin_math_space.value;
- style->thin_math_space_value = style_element->thin_math_space.value;
- style->medium_math_space_value = style_element->medium_math_space.value;
- style->thick_math_space_value = style_element->thick_math_space.value;
- style->very_thick_math_space_value = style_element->very_thick_math_space.value;
- style->very_very_thick_math_space_value = style_element->very_very_thick_math_space.value;
+ 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);
+ style->very_thin_math_space =
+ lsm_mathml_length_attribute_normalize (&style_element->very_thin_math_space,
+ style->very_thin_math_space, style->math_size);
+ style->thin_math_space =
+ lsm_mathml_length_attribute_normalize (&style_element->thin_math_space,
+ style->thin_math_space, style->math_size);
+ style->medium_math_space =
+ lsm_mathml_length_attribute_normalize (&style_element->medium_math_space,
+ style->medium_math_space, style->math_size);
+ style->thick_math_space =
+ lsm_mathml_length_attribute_normalize (&style_element->thick_math_space,
+ style->thick_math_space, style->math_size);
+ style->very_thick_math_space =
+ lsm_mathml_length_attribute_normalize (&style_element->very_thick_math_space,
+ style->very_thick_math_space, style->math_size);
+ 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);
/* mfrac */
- lsm_mathml_length_attribute_parse (&style_element->line_thickness,
- &style->line_thickness,
- style->math_size_value);
+ style->line_thickness = lsm_mathml_length_attribute_normalize (&style_element->line_thickness,
+ style->line_thickness,
+ style->math_size);
}
/* LsmMathmlStyleElement implementation */
@@ -120,9 +119,21 @@ lsm_mathml_style_element_new (void)
return g_object_new (LSM_TYPE_MATHML_STYLE_ELEMENT, NULL);
}
+static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+
static void
lsm_mathml_style_element_init (LsmMathmlStyleElement *self)
{
+ self->script_min_size.length = length_default;
+ self->very_very_thin_math_space.length = length_default;
+ self->very_thin_math_space.length = length_default;
+ self->thin_math_space.length = length_default;
+ self->medium_math_space.length = length_default;
+ self->thick_math_space.length = length_default;
+ self->very_thick_math_space.length = length_default;
+ self->very_very_thick_math_space.length = length_default;
+ self->math_size.length = length_default;
+ self->line_thickness.length = length_default;
}
/* LsmMathmlStyleElement class */
@@ -134,15 +145,75 @@ static const LsmAttributeInfos _attribute_infos[] = {
.trait_class = &lsm_mathml_boolean_trait_class
},
{
+ .name = "scriptminsize",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, script_min_size),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
.name = "scriptsizemultiplier",
.attribute_offset = offsetof (LsmMathmlStyleElement, script_size_multiplier),
.trait_class = &lsm_mathml_double_trait_class
},
{
+ .name = "veryverythinmathspace",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, very_very_thin_math_space),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "verythinmathspace",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, very_thin_math_space),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "thinmathspace",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, thin_math_space),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "mediummathspace",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, medium_math_space),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "thickmathspace",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, thick_math_space),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "verythickmathspace",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, very_thick_math_space),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "veryverythickmathspace",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, very_very_thick_math_space),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
.name = "mathfamily",
.attribute_offset = offsetof (LsmMathmlStyleElement, math_family),
.trait_class = &lsm_mathml_string_trait_class
},
+ {
+ .name = "mathsize",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, math_size),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "linethickness",
+ .attribute_offset = offsetof (LsmMathmlStyleElement, line_thickness),
+ .trait_class = &lsm_mathml_length_trait_class,
+ .trait_default = &length_default
+ },
/* Deprecated attributes */
{
.name = "fontfamily",
@@ -172,41 +243,18 @@ lsm_mathml_style_element_class_init (LsmMathmlStyleElementClass *style_class)
lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "scriptlevel",
offsetof (LsmMathmlStyleElement, script_level));
- 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",
offsetof (LsmMathmlStyleElement, math_background));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "veryverythinmathspace",
- offsetof (LsmMathmlStyleElement, very_very_thin_math_space));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "verythinmathspace",
- offsetof (LsmMathmlStyleElement, very_thin_math_space));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "thinmathspace",
- offsetof (LsmMathmlStyleElement, thin_math_space));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "mediummathspace",
- offsetof (LsmMathmlStyleElement, medium_math_space));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "thickmathspace",
- offsetof (LsmMathmlStyleElement, thick_math_space));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "verythickmathspace",
- offsetof (LsmMathmlStyleElement, very_thick_math_space));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "veryverythickmathspace",
- offsetof (LsmMathmlStyleElement, very_very_thick_math_space));
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, "mathsize",
- offsetof (LsmMathmlStyleElement, math_size));
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",
offsetof (LsmMathmlStyleElement, math_background));
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "linethickness",
- offsetof (LsmMathmlStyleElement, line_thickness));
-
/* Deprecated attributes */
- lsm_mathml_attribute_map_add_attribute (m_element_class->attributes, "fontsize",
- offsetof (LsmMathmlStyleElement, math_size));
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",
diff --git a/src/lsmmathmltraits.c b/src/lsmmathmltraits.c
index afbf09c..05804f3 100644
--- a/src/lsmmathmltraits.c
+++ b/src/lsmmathmltraits.c
@@ -122,3 +122,97 @@ const LsmTraitClass lsm_mathml_string_trait_class = {
.to_string = lsm_mathml_string_trait_to_string,
.finalize = lsm_mathml_string_trait_finalize
};
+
+static LsmMathmlLength *
+lsm_mathml_length_copy (LsmMathmlLength *length)
+{
+ LsmMathmlLength *copy;
+
+ copy = g_new (LsmMathmlLength, 1);
+ memcpy (copy, length, sizeof (LsmMathmlLength));
+
+ return copy;
+}
+
+GType
+lsm_mathml_length_get_type (void)
+{
+ static GType our_type = 0;
+
+ if (our_type == 0)
+ our_type = g_boxed_type_register_static
+ ("LsmMathmlLength",
+ (GBoxedCopyFunc) lsm_mathml_length_copy,
+ (GBoxedFreeFunc) g_free);
+ return our_type;
+}
+
+static void
+lsm_mathml_length_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+ LsmMathmlLength *length = (LsmMathmlLength *) abstract_trait;
+ char *unit_str;
+
+ length->value = g_strtod (string, &unit_str);
+ length->unit = lsm_mathml_unit_from_string (unit_str);
+
+ /* TODO Handle "big", "small", normal" sizes */
+}
+
+static char *
+lsm_mathml_length_trait_to_string (LsmTrait *abstract_trait)
+{
+ LsmMathmlLength *length = (LsmMathmlLength *) abstract_trait;
+
+ return g_strdup_printf ("%g %s", length->value,
+ lsm_mathml_unit_to_string (length->unit));
+}
+
+const LsmTraitClass lsm_mathml_length_trait_class = {
+ .size = sizeof (char *),
+ .from_string = lsm_mathml_length_trait_from_string,
+ .to_string = lsm_mathml_length_trait_to_string
+};
+
+double
+lsm_mathml_length_normalize (const LsmMathmlLength *length, double default_value, double font_size)
+{
+ double value;
+
+ g_return_val_if_fail (length != NULL, 0.0);
+
+ switch (length->unit) {
+ case LSM_MATHML_UNIT_PX:
+ case LSM_MATHML_UNIT_PT:
+ value = length->value;
+ break;
+ case LSM_MATHML_UNIT_PC:
+ value = length->value * 72.0 / 6.0;
+ break;
+ case LSM_MATHML_UNIT_CM:
+ value = length->value * 72.0 / 2.54;
+ break;
+ case LSM_MATHML_UNIT_MM:
+ value = length->value * 72.0 / 25.4;
+ break;
+ case LSM_MATHML_UNIT_IN:
+ value = length->value * 72.0;
+ break;
+ case LSM_MATHML_UNIT_EM:
+ value = length->value * font_size;
+ break;
+ case LSM_MATHML_UNIT_EX:
+ value = length->value * font_size * 0.5;
+ break;
+ case LSM_MATHML_UNIT_PERCENT:
+ value = default_value * length->value / 100.0;
+ break;
+ case LSM_MATHML_UNIT_NONE:
+ value = default_value * length->value;
+ break;
+ default:
+ value = 0;
+ }
+
+ return value;
+}
diff --git a/src/lsmmathmltraits.h b/src/lsmmathmltraits.h
index 9d0f7ff..dd30ebe 100644
--- a/src/lsmmathmltraits.h
+++ b/src/lsmmathmltraits.h
@@ -22,6 +22,7 @@
#ifndef LSM_MATHML_TRAITS_H
#define LSM_MATHML_TRAITS_H
+#include <lsmmathmlenums.h>
#include <lsmtraits.h>
G_BEGIN_DECLS
@@ -31,6 +32,19 @@ extern const LsmTraitClass lsm_mathml_unsigned_trait_class;
extern const LsmTraitClass lsm_mathml_double_trait_class;
extern const LsmTraitClass lsm_mathml_string_trait_class;
+typedef struct {
+ double value;
+ LsmMathmlUnit unit;
+} LsmMathmlLength;
+
+GType lsm_mathml_space_get_type (void);
+
+#define LSM_TYPE_MATHML_SPACE (lsm_mathml_space_get_type())
+
+extern const LsmTraitClass lsm_mathml_length_trait_class;
+
+double lsm_mathml_length_normalize (const LsmMathmlLength *length, double default_value, double font_size);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]