[lasem/mml-attrs] [Mathml] Fix computation of lengths and spaces



commit d3cb35bb8c6fce05d229ef3d47c21923b9679c99
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Wed Jan 6 19:18:35 2010 +0100

    [Mathml] Fix computation of lengths and spaces
    
    We need both the default value and the base value. The base value is
    used when lengths are specified without unit or with the percentage unit.

 src/lsmmathmlattributes.c        |   48 ++++++++++++++++++++++++-------------
 src/lsmmathmlattributes.h        |    4 +++
 src/lsmmathmlfractionelement.c   |    4 ++-
 src/lsmmathmloperatorelement.c   |    8 +++---
 src/lsmmathmlpresentationtoken.c |    4 ++-
 src/lsmmathmlscriptelement.c     |    8 ++++-
 src/lsmmathmlspaceelement.c      |    6 ++--
 src/lsmmathmlstyleelement.c      |   10 ++++++++
 src/lsmmathmltableelement.c      |   18 +++++++-------
 src/lsmmathmltraits.c            |    7 ++---
 src/lsmmathmltraits.h            |    4 +-
 11 files changed, 78 insertions(+), 43 deletions(-)
---
diff --git a/src/lsmmathmlattributes.c b/src/lsmmathmlattributes.c
index 6ad70c2..09a09aa 100644
--- a/src/lsmmathmlattributes.c
+++ b/src/lsmmathmlattributes.c
@@ -88,27 +88,38 @@ lsm_mathml_script_level_attribute_apply	(LsmMathmlScriptLevelAttribute *attribut
 
 double
 lsm_mathml_length_attribute_normalize (LsmMathmlLengthAttribute *attribute,
+				       double base,
 				       const LsmMathmlLength *default_value,
 				       const LsmMathmlStyle *style)
 {
+	const LsmMathmlLength *length;
+
 	g_return_val_if_fail (attribute != NULL, 0.0);
+	g_return_val_if_fail (style != NULL, 0.0);
+
+	length = attribute->base.value != NULL ? &attribute->length : default_value;
 
-	attribute->value = lsm_mathml_length_normalize (&attribute->length, default_value, style->math_size);
+	g_return_val_if_fail (length != NULL, 0.0);
+
+	attribute->value = lsm_mathml_length_normalize (length, base, style->math_size);
 
 	return attribute->value;
 }
 
 double
 lsm_mathml_space_attribute_normalize (LsmMathmlSpaceAttribute *attribute,
+				      double base,
 				      const LsmMathmlSpace *default_value,
 				      const LsmMathmlStyle *style)
 {
+	const LsmMathmlSpace *space;
+
 	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;
+	space = attribute->base.value != NULL ?	&attribute->space : default_value;
+
+	g_return_val_if_fail (space != NULL, 0.0);
 
 	switch (attribute->space.name) {
 		case LSM_MATHML_SPACE_NAME_VERY_VERY_THIN:
@@ -137,8 +148,8 @@ lsm_mathml_space_attribute_normalize (LsmMathmlSpaceAttribute *attribute,
 			break;
 		case LSM_MATHML_SPACE_NAME_ERROR:
 		default:
-			attribute->value = lsm_mathml_length_normalize (&attribute->space.length,
-									&default_value->length,
+			attribute->value = lsm_mathml_length_normalize (&space->length,
+									base,
 									style->math_size);
 	}
 
@@ -147,23 +158,26 @@ lsm_mathml_space_attribute_normalize (LsmMathmlSpaceAttribute *attribute,
 
 void
 lsm_mathml_space_list_attribute_normalize (LsmMathmlSpaceListAttribute *attribute,
+					   double base,
 					   const LsmMathmlSpaceList *default_value,
 					   const LsmMathmlStyle *style)
 {
 	LsmMathmlSpaceAttribute space_attribute;
+	const LsmMathmlSpaceList *space_list;
 	unsigned int i;
 
 	g_return_if_fail (attribute != NULL);
-	g_return_if_fail (default_value != NULL);
 	g_return_if_fail (style != NULL);
 
+	space_list = attribute->base.value != NULL ? &attribute->space_list : default_value;
+
+	g_return_if_fail (space_list != NULL);
+
 	g_free (attribute->values);
 	attribute->values = NULL;
+	attribute->n_values = 0;
 
-	if (attribute->base.value == NULL)
-		lsm_mathml_space_list_init (&attribute->space_list, default_value);
-
-	if (attribute->space_list.n_spaces == 0) {
+	if (space_list->n_spaces == 0) {
 		attribute->values = g_new (double, 1);
 		attribute->values[0] = 0.0;
 		return;
@@ -171,12 +185,12 @@ lsm_mathml_space_list_attribute_normalize (LsmMathmlSpaceListAttribute *attribut
 
 	space_attribute.base.value = "";
 
-	attribute->values = g_new (double, attribute->space_list.n_spaces);
-	for (i = 0; i < attribute->space_list.n_spaces; i++) {
-		space_attribute.space = attribute->space_list.spaces[i];
-		lsm_mathml_space_attribute_normalize (&space_attribute,
-						      &default_value->spaces[MIN(i, default_value->n_spaces - 1)],
-						      style);
+	attribute->values = g_new (double, space_list->n_spaces);
+	attribute->n_values = space_list->n_spaces;
+
+	for (i = 0; i < space_list->n_spaces; i++) {
+		space_attribute.space = space_list->spaces[i];
+		lsm_mathml_space_attribute_normalize (&space_attribute, base, NULL, style);
 		attribute->values[i] = space_attribute.value;
 	}
 }
diff --git a/src/lsmmathmlattributes.h b/src/lsmmathmlattributes.h
index 159d511..4d4a195 100644
--- a/src/lsmmathmlattributes.h
+++ b/src/lsmmathmlattributes.h
@@ -92,6 +92,7 @@ typedef struct {
 } LsmMathmlLengthAttribute;
 
 double 		lsm_mathml_length_attribute_normalize	(LsmMathmlLengthAttribute *atribute,
+							 double base,
 							 const LsmMathmlLength *default_value,
 							 const LsmMathmlStyle *style);
 
@@ -102,16 +103,19 @@ typedef struct {
 } LsmMathmlSpaceAttribute;
 
 double 		lsm_mathml_space_attribute_normalize 	(LsmMathmlSpaceAttribute *attribute,
+							 double base,
 							 const LsmMathmlSpace *default_value,
 							 const LsmMathmlStyle *style);
 
 typedef struct {
 	LsmAttribute base;
 	LsmMathmlSpaceList space_list;
+	unsigned int n_values;
 	double *values;
 } LsmMathmlSpaceListAttribute;
 
 void 		lsm_mathml_space_list_attribute_normalize 	(LsmMathmlSpaceListAttribute *attribute,
+								 double base,
 								 const LsmMathmlSpaceList *default_value,
 								 const LsmMathmlStyle *style);
 
diff --git a/src/lsmmathmlfractionelement.c b/src/lsmmathmlfractionelement.c
index 7afcc34..a678ad4 100644
--- a/src/lsmmathmlfractionelement.c
+++ b/src/lsmmathmlfractionelement.c
@@ -52,7 +52,9 @@ lsm_mathml_fraction_element_update (LsmMathmlElement *self, LsmMathmlStyle *styl
 	length.unit = LSM_MATHML_UNIT_PT;
 
 	length.value = style->line_thickness;
-	style->line_thickness = lsm_mathml_length_attribute_normalize (&fraction->line_thickness, &length, style);
+	style->line_thickness = lsm_mathml_length_attribute_normalize (&fraction->line_thickness,
+								       style->line_thickness,
+								       &length, style);
 
 	fraction->display = style->display;
 }
diff --git a/src/lsmmathmloperatorelement.c b/src/lsmmathmloperatorelement.c
index febcd91..fa2df98 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_normalize (&operator_element->left_space, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->left_space, 0.0, &space, style);
 	space = entry->right_space;
-	lsm_mathml_space_attribute_normalize (&operator_element->right_space, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->right_space, 0.0, &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_normalize (&operator_element->min_size, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->min_size, 0.0, &space, style);
 	space = entry->max_size;
-	lsm_mathml_space_attribute_normalize (&operator_element->max_size, &space, style);
+	lsm_mathml_space_attribute_normalize (&operator_element->max_size, 0.0, &space, style);
 	lsm_mathml_boolean_attribute_inherit (&operator_element->symmetric, entry->symmetric);
 
 	operator_element->is_large_op = operator_element->large_op.value &&
diff --git a/src/lsmmathmlpresentationtoken.c b/src/lsmmathmlpresentationtoken.c
index fd0d6f9..4cac226 100644
--- a/src/lsmmathmlpresentationtoken.c
+++ b/src/lsmmathmlpresentationtoken.c
@@ -115,7 +115,9 @@ lsm_mathml_presentation_token_update (LsmMathmlElement *self, LsmMathmlStyle *st
 
 	length.unit = LSM_MATHML_UNIT_PT;
 	length.value = style->math_size;
-	style->math_size = lsm_mathml_length_attribute_normalize (&token->math_size, &length, style);
+	style->math_size = lsm_mathml_length_attribute_normalize (&token->math_size,
+								  style->math_size,
+								  &length, style);
 }
 
 static const LsmMathmlBbox *
diff --git a/src/lsmmathmlscriptelement.c b/src/lsmmathmlscriptelement.c
index ef13f9c..f4a7e8b 100644
--- a/src/lsmmathmlscriptelement.c
+++ b/src/lsmmathmlscriptelement.c
@@ -117,9 +117,13 @@ lsm_mathml_script_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 	length.unit = LSM_MATHML_UNIT_PT;
 
 	length.value = style->superscript_shift;
-	style->superscript_shift = lsm_mathml_length_attribute_normalize (&script->superscript_shift, &length, style);
+	style->superscript_shift = lsm_mathml_length_attribute_normalize (&script->superscript_shift,
+									  style->superscript_shift,
+									  &length, style);
 	length.value = style->subscript_shift;
-	style->subscript_shift = lsm_mathml_length_attribute_normalize (&script->subscript_shift, &length, style);
+	style->subscript_shift = lsm_mathml_length_attribute_normalize (&script->subscript_shift,
+									style->subscript_shift,
+									&length, style);
 
 	script->display = style->display;
 }
diff --git a/src/lsmmathmlspaceelement.c b/src/lsmmathmlspaceelement.c
index e67d845..58ad79d 100644
--- a/src/lsmmathmlspaceelement.c
+++ b/src/lsmmathmlspaceelement.c
@@ -49,9 +49,9 @@ lsm_mathml_space_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 		{ .unit = LSM_MATHML_UNIT_PX, .value = 0.0}};
 	static LsmMathmlLength length = {.unit = LSM_MATHML_UNIT_PX, .value = 0.0};
 
-	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);
+	lsm_mathml_space_attribute_normalize (&space_element->width, 0.0, &space, style);
+	lsm_mathml_length_attribute_normalize (&space_element->height, 0.0, &length, style);
+	lsm_mathml_length_attribute_normalize (&space_element->depth, 0.0, &length, style);
 }
 
 static const LsmMathmlBbox *
diff --git a/src/lsmmathmlstyleelement.c b/src/lsmmathmlstyleelement.c
index c6f657b..f8bd2c9 100644
--- a/src/lsmmathmlstyleelement.c
+++ b/src/lsmmathmlstyleelement.c
@@ -54,6 +54,7 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 									     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,
 								        &length, style);
 
 	new_script_level = lsm_mathml_script_level_attribute_apply (&style_element->script_level,
@@ -77,6 +78,7 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 	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,
 								  &length, style);
 
 	/* mstyle */
@@ -84,36 +86,44 @@ lsm_mathml_style_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 	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,
 						       &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,
 						       &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,
 						       &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,
 						       &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,
 						       &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,
 						       &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,
 						       &length, style);
 
 	/* mfrac */
 
 	length.value = style->line_thickness;
 	style->line_thickness = lsm_mathml_length_attribute_normalize (&style_element->line_thickness,
+								       style->line_thickness,
 								       &length, style);
 }
 
diff --git a/src/lsmmathmltableelement.c b/src/lsmmathmltableelement.c
index dd56958..1c961c5 100644
--- a/src/lsmmathmltableelement.c
+++ b/src/lsmmathmltableelement.c
@@ -72,9 +72,9 @@ lsm_mathml_table_element_update (LsmMathmlElement *self, LsmMathmlStyle *style)
 {
 	LsmMathmlTableElement *table = LSM_MATHML_TABLE_ELEMENT (self);
 
-	lsm_mathml_space_list_attribute_normalize (&table->row_spacing, &row_spacing_default, style);
-	lsm_mathml_space_list_attribute_normalize (&table->column_spacing, &column_spacing_default, style);
-	lsm_mathml_space_list_attribute_normalize (&table->frame_spacing, &frame_spacing_default, style);
+	lsm_mathml_space_list_attribute_normalize (&table->row_spacing, 0.0, &row_spacing_default, style);
+	lsm_mathml_space_list_attribute_normalize (&table->column_spacing, 0.0, &column_spacing_default, style);
+	lsm_mathml_space_list_attribute_normalize (&table->frame_spacing, 0.0, &frame_spacing_default, style);
 }
 
 static const LsmMathmlBbox *
@@ -186,7 +186,7 @@ lsm_mathml_table_element_measure (LsmMathmlElement *self, LsmMathmlView *view, c
 		for (column = 0; column < table->n_columns; column++)
 			table->widths[column] = max_width;
 
-	max_index = table->column_spacing.space_list.n_spaces -  1;
+	max_index = table->column_spacing.n_values -  1;
 	for (column = 0; column < table->n_columns; column++) {
 		self->bbox.width += table->widths[column];
 		if (column < table->n_columns - 1)
@@ -195,7 +195,7 @@ lsm_mathml_table_element_measure (LsmMathmlElement *self, LsmMathmlView *view, c
 
 	height = 0.0;
 
-	max_index = table->row_spacing.space_list.n_spaces -  1;
+	max_index = table->row_spacing.n_values -  1;
 	for (row = 0; row < table->n_rows; row++) {
 		height += table->heights[row] + table->depths[row];
 		if (row < table->n_rows - 1)
@@ -270,8 +270,8 @@ lsm_mathml_table_element_layout (LsmMathmlElement *self, LsmMathmlView *view,
 	if (table->n_rows < 1 || table->n_columns < 1)
 		return;
 
-	max_column = table->column_spacing.space_list.n_spaces -  1;
-	max_row = table->row_spacing.space_list.n_spaces -  1;
+	max_column = table->column_spacing.n_values -  1;
+	max_row = table->row_spacing.n_values -  1;
 
 	y_offset = -self->bbox.height;
         y_offset += table->frame_spacing.values[1];
@@ -369,7 +369,7 @@ lsm_mathml_table_element_render (LsmMathmlElement *self, LsmMathmlView *view)
 
 	for (i = 0; i < table->n_rows - 1; i++) {
 		position += table->heights[i] + table->depths[i];
-		spacing = table->row_spacing.values[MIN (i, table->row_spacing.space_list.n_spaces - 1)];
+		spacing = table->row_spacing.values[MIN (i, table->row_spacing.n_values - 1)];
 		y = position + (0.5 * spacing) + table->line_width * 0.5;
 		lsm_mathml_view_show_line (view, &self->style,
 					x0, y, x1, y,
@@ -386,7 +386,7 @@ lsm_mathml_table_element_render (LsmMathmlElement *self, LsmMathmlView *view)
 
 	for (i = 0; i < table->n_columns - 1; i++) {
 		position += table->widths[i];
-		spacing = table->column_spacing.values[MIN (i, table->column_spacing.space_list.n_spaces - 1)];
+		spacing = table->column_spacing.values[MIN (i, table->column_spacing.n_values - 1)];
 		x = position + 0.5 * (spacing + table->line_width);
 		lsm_mathml_view_show_line (view, &self->style,
 					x, y0, x, y1,
diff --git a/src/lsmmathmltraits.c b/src/lsmmathmltraits.c
index 69cf4de..3034cf2 100644
--- a/src/lsmmathmltraits.c
+++ b/src/lsmmathmltraits.c
@@ -576,7 +576,7 @@ const LsmTraitClass lsm_mathml_length_trait_class = {
 
 double
 lsm_mathml_length_normalize (const LsmMathmlLength *length,
-			     const LsmMathmlLength *default_length,
+			     double base,
 			     double font_size)
 {
 	double value;
@@ -607,10 +607,10 @@ lsm_mathml_length_normalize (const LsmMathmlLength *length,
 			value = length->value * font_size * 0.5;
 			break;
 		case LSM_MATHML_UNIT_PERCENT:
-			value = length->value * lsm_mathml_length_normalize (default_length, NULL, font_size) / 100.0;
+			value = length->value * base / 100.0;
 			break;
 		case LSM_MATHML_UNIT_NONE:
-			value = length->value * lsm_mathml_length_normalize (default_length, NULL, font_size);
+			value = length->value * base;
 			break;
 		default:
 			value = 0;
@@ -643,7 +643,6 @@ lsm_mathml_space_get_type (void)
 	return our_type;
 }
 
-
 static void
 lsm_mathml_space_trait_from_string (LsmTrait *abstract_trait, char *string)
 {
diff --git a/src/lsmmathmltraits.h b/src/lsmmathmltraits.h
index 3ef3b0e..938c7ef 100644
--- a/src/lsmmathmltraits.h
+++ b/src/lsmmathmltraits.h
@@ -53,9 +53,9 @@ typedef struct {
 	LsmMathmlUnit unit;
 } LsmMathmlLength;
 
-GType lsm_mathml_length_get_type (void);
+GType 	lsm_mathml_length_get_type 	(void);
 double 	lsm_mathml_length_normalize 	(const LsmMathmlLength *length,
-					 const LsmMathmlLength *default_length,
+					 double base,
 					 double font_size);
 
 typedef struct {



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