[gnumeric] Fix zoom of text superscripts and subscripts. [#425685]



commit 69f8f2ba0be0a726232a484e0fb0e8ecfbb1ff6c
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sat Oct 22 22:13:00 2011 -0600

    Fix zoom of text superscripts and subscripts. [#425685]
    
    2011-10-22 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/mstyle.c (gnm_style_get_pango_attrs): adjust the pango
    	attributes for subscript/superscripts in the case of zoom
    	* src/rendered-value.c (rv_adjust_filter): new
    	(rv_adjust_attributes): new
    	(gnm_rendered_value_new): adjust the pango attributes before
    	rendering to account for font size and zoom

 ChangeLog            |    9 ++++++
 NEWS                 |    1 +
 src/mstyle.c         |   12 ++++----
 src/rendered-value.c |   77 ++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 90 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9b6563f..8ee303c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2011-10-22 Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/mstyle.c (gnm_style_get_pango_attrs): adjust the pango
+	attributes for subscript/superscripts in the case of zoom
+	* src/rendered-value.c (rv_adjust_filter): new
+	(rv_adjust_attributes): new
+	(gnm_rendered_value_new): adjust the pango attributes before
+	rendering to account for font size and zoom
+
+2011-10-22 Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/mstyle.c (gnm_style_get_pango_attrs): use new goffice
 	defines for super/subscripts
 	* src/wbc-gtk-actions.c (toggle_font_attr): ditto
diff --git a/NEWS b/NEWS
index 9ea37e0..6df3b62 100644
--- a/NEWS
+++ b/NEWS
@@ -36,6 +36,7 @@ Andreas:
 	* Fix centering of spanned cell content. [#662361]
 	* Add optional markers to indicate that cell content has been
 	truncated. [#662149]
+	* Fix zoom of text superscripts and subscripts. [#425685]
 
 Jean:
 	* Make things build against gtk+-3.0.
diff --git a/src/mstyle.c b/src/mstyle.c
index 9b79987..61d98c5 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -1649,6 +1649,7 @@ gnm_style_get_pango_attrs (GnmStyle const *style,
 {
 	PangoAttrList *l;
 	GnmUnderline ul;
+	GnmFont *font = gnm_style_get_font (style, context);
 
 	if (style->pango_attrs) {
 		if (zoom == style->pango_attrs_zoom) {
@@ -1685,18 +1686,17 @@ gnm_style_get_pango_attrs (GnmStyle const *style,
 	case GO_FONT_SCRIPT_STANDARD :
 		break;
 	case GO_FONT_SCRIPT_SUB :
-		add_attr (l, pango_attr_rise_new (GO_SUBSCRIPT_RISE));
+		add_attr (l, pango_attr_rise_new
+			  (GO_SUBSCRIPT_RISE * font->size_pts/10. * zoom));
 		zoom *= GO_SUBSCRIPT_SCALE;
 		break;
 	case GO_FONT_SCRIPT_SUPER :
-		add_attr (l, pango_attr_rise_new (GO_SUPERSCRIPT_RISE));
+		add_attr (l, pango_attr_rise_new
+			  (GO_SUPERSCRIPT_RISE* font->size_pts/10. * zoom));
 		zoom *= GO_SUPERSCRIPT_SCALE;
 	}
 
-	{
-		GnmFont *font = gnm_style_get_font (style, context);
-		add_attr (l, pango_attr_font_desc_new (font->go.font->desc));
-	}
+	add_attr (l, pango_attr_font_desc_new (font->go.font->desc));
 
 	if (zoom != 1)
 		add_attr (l, pango_attr_scale_new (zoom));
diff --git a/src/rendered-value.c b/src/rendered-value.c
index 9eb45b7..8ba03c2 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -162,6 +162,38 @@ gnm_rendered_value_remeasure (GnmRenderedValue *rv)
 				       &rv->layout_natural_height);
 }
 
+typedef struct {
+	double scale;
+	int rise;
+} rv_adjust_attributes_t;
+
+static gboolean
+rv_adjust_filter (PangoAttribute *attribute, rv_adjust_attributes_t *raat)
+{
+	if (attribute->klass->type == PANGO_ATTR_RISE) {
+		PangoAttrInt *pa_rise = (PangoAttrInt *)attribute;
+		pa_rise->value = raat->scale * pa_rise->value + raat->rise;
+	}
+	if (attribute->klass->type == PANGO_ATTR_SCALE && raat->scale != 1.) {
+		PangoAttrFloat *pa_scale = (PangoAttrFloat *)attribute;
+		pa_scale->value = pa_scale->value * raat->scale;
+	}
+	return FALSE;
+}
+
+static void
+rv_adjust_attributes (PangoAttrList *markup, double scale, int rise)
+{
+	rv_adjust_attributes_t raat = {scale, rise};
+
+	g_print ("rv_adjust_attributes pal:%p scale:%f rise:%d\n",
+		 markup, scale, rise);
+
+	pango_attr_list_filter (markup, (PangoAttrFilterFunc) rv_adjust_filter,
+				&raat);
+}
+
+
 /**
  * gnm_rendered_value_new:
  * @cell:   The cell
@@ -275,11 +307,50 @@ gnm_rendered_value_new (GnmCell const *cell,
 		if (fmt != NULL && go_format_is_markup (fmt)) {
 			PangoAttrList *orig = attrs;
 			const PangoAttrList *markup = go_format_get_markup (fmt);
+			PangoAttrList *c_markup = NULL;
+			PangoAttrIterator *iter;
+			GSList *extra_attrs = NULL, *l;
+			PangoFontDescription *desc = pango_font_description_new ();
+			double font_size, scale = 1., tscale;
+			int rise = 0;
+
 			attrs = pango_attr_list_copy (attrs);
-			pango_attr_list_splice (attrs,
-						(PangoAttrList *)markup,
-						0, 0);
+
+			iter = pango_attr_list_get_iterator (attrs);
+			pango_attr_iterator_get_font (iter,
+						      desc,
+						      NULL,
+						      &extra_attrs);
+			font_size = pango_font_description_get_size (desc)/
+				(double)PANGO_SCALE;
+			
+			for (l = extra_attrs; l != NULL; l = l->next) {
+				PangoAttribute *pa = l->data;
+				if (pa->klass->type == PANGO_ATTR_RISE) {
+					PangoAttrInt *pa_rise = l->data;
+					rise = pa_rise->value;
+					
+				}
+				if (pa->klass->type == PANGO_ATTR_SCALE) {
+					PangoAttrFloat *pa_scale = l->data;
+					scale = pa_scale->value;
+				}
+			}
+			go_slist_free_custom (extra_attrs, 
+					      (GFreeFunc) pango_attribute_destroy);
+			pango_font_description_free (desc);
+			pango_attr_iterator_destroy (iter);
+
+			tscale = font_size/10. * scale;
+			if (tscale != 1|| rise != 0) {
+				markup = c_markup = pango_attr_list_copy 
+					((PangoAttrList *)markup);
+				rv_adjust_attributes (c_markup, tscale, rise);
+			}
+
+			pango_attr_list_splice (attrs, (PangoAttrList *)markup, 0, 0);
 			pango_attr_list_unref (orig);
+			pango_attr_list_unref (c_markup);
 		}
 	}
 



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