[goffice] Add val to sub- and superscript attributes



commit 99f65ea80e8b92ef70100f5aa4c49243037c6f86
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Oct 27 19:09:56 2011 -0600

    Add val to sub- and superscript attributes
    
    2011-10-27  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* goffice/utils/go-format.c (go_format_execute): add arg to call of
    	go_pango_attr_superscript_new
    	(cb_attrs_as_string): write value of sub- and superscript attributes
    	* goffice/utils/go-pango-extras.h: publish GOPangoAttr* struct
    	(go_pango_attr_*_new): add argument
    	* goffice/utils/go-pango-extras.c (go_pango_translate_here): check
    	attribute values
    	(go_pango_attr_subscript_copy): copy attribute value
    	(go_pango_attr_superscript_copy): copy attribute value
    	(go_pango_attr_compare): replace with go_pango_attr_*_compare
    	(go_pango_attr_*_new): add argument

 ChangeLog                       |   14 ++++++++
 goffice/utils/go-format.c       |   14 +++++---
 goffice/utils/go-pango-extras.c |   64 ++++++++++++++++++++++-----------------
 goffice/utils/go-pango-extras.h |   16 +++++++--
 4 files changed, 71 insertions(+), 37 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fa811dc..4198463 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2011-10-27  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* goffice/utils/go-format.c (go_format_execute): add arg to call of
+	go_pango_attr_superscript_new
+	(cb_attrs_as_string): write value of sub- and superscript attributes
+	* goffice/utils/go-pango-extras.h: publish GOPangoAttr* struct
+	(go_pango_attr_*_new): add argument
+	* goffice/utils/go-pango-extras.c (go_pango_translate_here): check
+	attribute values
+	(go_pango_attr_subscript_copy): copy attribute value
+	(go_pango_attr_superscript_copy): copy attribute value
+	(go_pango_attr_compare): replace with go_pango_attr_*_compare
+	(go_pango_attr_*_new): add argument
+
+2011-10-27  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* goffice/utils/go-format.c (cb_attrs_as_string): handle super and
 	subscripts
 	(go_format_parse_markup): ditto
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 1428ea1..b06a8b6 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -3476,7 +3476,7 @@ SUFFIX(go_format_execute) (PangoLayout *layout, GString *dst,
 					markup_stack = g_slist_delete_link (markup_stack, markup_stack);
 				}
 				
-				attr = go_pango_attr_superscript_new ();
+				attr = go_pango_attr_superscript_new (TRUE);
 				attr->start_index = start;
 				attr->end_index = end;
 				pango_attr_list_insert (attrs, attr);
@@ -4853,10 +4853,14 @@ cb_attrs_as_string (PangoAttribute *a, GString *accum)
 		break;
 	default :
 		if (a->klass->type == go_pango_attr_subscript_get_type ()) {
-			g_string_append (accum, "[subscript=1");
+			g_string_append_printf (accum, "[subscript=%d", 
+						((GOPangoAttrSubscript *)a)->val ?
+						1:0);
 			break;
 		} else if (a->klass->type == go_pango_attr_superscript_get_type ()) {
-			g_string_append (accum, "[superscript=1");
+			g_string_append_printf (accum, "[superscript=%d",
+						((GOPangoAttrSuperscript *)a)->val ?
+						1:0);
 			break;
 		} else return FALSE; /* ignored */
 	}
@@ -4934,12 +4938,12 @@ go_format_parse_markup (char *str)
 				else if (0 == strcmp (val, "error"))
 					a = pango_attr_underline_new (PANGO_UNDERLINE_ERROR);
 			} else if (0 == strncmp (str, "subscript", 9))
-				a = go_pango_attr_subscript_new ();
+				a = go_pango_attr_subscript_new (atoi (val));
 			break;
 
 		case 11:
 			if (0 == strncmp (str, "superscript", 11))
-				a = go_pango_attr_superscript_new ();
+				a = go_pango_attr_superscript_new (atoi (val));
 			break;
 
 		case 13:
diff --git a/goffice/utils/go-pango-extras.c b/goffice/utils/go-pango-extras.c
index b3dc7f4..8cd82a9 100644
--- a/goffice/utils/go-pango-extras.c
+++ b/goffice/utils/go-pango-extras.c
@@ -12,13 +12,6 @@
 #include "go-glib-extras.h"
 #include <string.h>
 
-struct _GOPangoAttrSuperscript {
-	PangoAttribute attr;
-};
-struct _GOPangoAttrSubscript {
-	PangoAttribute attr;
-};
-
 struct cb_splice {
 	guint pos, len;
 	PangoAttrList *result;
@@ -538,34 +531,34 @@ go_pango_translate_here (PangoAttrIterator *state_iter,
 	for (l = the_attrs; l != NULL; l = l->next) {
 		PangoAttribute *attribute = l->data;
 		PangoAttrType type = attribute->klass->type;
-		/* If we haven't used a sub or superscript then */
-		/* go_pango_attr_*_type may still be PANGO_ATTR_INVALID */
-		if (type != PANGO_ATTR_INVALID) {
-			if (type == go_pango_attr_superscript_get_type ()) {
+		if (type == go_pango_attr_superscript_get_type ()) {
+			GOPangoAttrSuperscript *attr = (GOPangoAttrSuperscript *)attribute;
+			if (attr->val) {
 				scale *= GO_SUPERSCRIPT_SCALE;
 				rise += GO_SUPERSCRIPT_RISE * font_scale;
 				font_scale *= GO_SUPERSCRIPT_SCALE;
-			} else { /* go_pango_attr_subscript_type */
+			}
+		} else { /* go_pango_attr_subscript_type */
+			GOPangoAttrSubscript *attr = (GOPangoAttrSubscript *)attribute;
+			if (attr->val) {
 				scale *= GO_SUBSCRIPT_SCALE;
 				rise += GO_SUBSCRIPT_RISE * font_scale;
 				font_scale *= GO_SUBSCRIPT_SCALE;
 			}
-		}	
+		}
 	}
-	go_slist_free_custom (the_attrs, (GFreeFunc)pango_attribute_destroy);
 
-	if (scale != 1.) {
+	if (the_attrs != NULL) {
 		PangoAttribute *attr = pango_attr_scale_new (scale);
 		attr->start_index = range_start;
 		attr->end_index = range_end;
 		pango_attr_list_insert (attrs, attr);
-	}
-	if (rise != 0) {
-		PangoAttribute *attr = pango_attr_rise_new (rise);
+		attr = pango_attr_rise_new (rise);
 		attr->start_index = range_start;
 		attr->end_index = range_end;
 		pango_attr_list_insert (attrs, attr);
 	}
+	go_slist_free_custom (the_attrs, (GFreeFunc)pango_attribute_destroy);
 }
 
 
@@ -653,15 +646,17 @@ go_pango_attr_superscript_get_type (void)
 
 
 static PangoAttribute *
-go_pango_attr_subscript_copy (G_GNUC_UNUSED PangoAttribute const *attr)
+go_pango_attr_subscript_copy (PangoAttribute const *attr)
 {
-	return go_pango_attr_subscript_new ();
+	GOPangoAttrSubscript *at = (GOPangoAttrSubscript *)attr;
+	return go_pango_attr_subscript_new (at->val);
 }
 
 static PangoAttribute *
 go_pango_attr_superscript_copy (G_GNUC_UNUSED PangoAttribute const *attr)
 {
-	return go_pango_attr_superscript_new ();
+	GOPangoAttrSuperscript *at = (GOPangoAttrSuperscript *)attr;
+	return go_pango_attr_superscript_new (at->val);
 }
 
 static void
@@ -671,14 +666,25 @@ go_pango_attr_destroy (PangoAttribute *attr)
 }
 
 static gboolean
-go_pango_attr_compare (G_GNUC_UNUSED PangoAttribute const *attr1,
-		       G_GNUC_UNUSED PangoAttribute const *attr2)
+go_pango_attr_superscript_compare (PangoAttribute const *attr1,
+				   PangoAttribute const *attr2)
 {
-	return FALSE;
+	GOPangoAttrSuperscript *at1 = (GOPangoAttrSuperscript *)attr1;
+	GOPangoAttrSuperscript *at2 = (GOPangoAttrSuperscript *)attr2;
+	return (at1->val == at2->val);
+}
+
+static gboolean
+go_pango_attr_subscript_compare (PangoAttribute const *attr1,
+				 PangoAttribute const *attr2)
+{
+	GOPangoAttrSubscript *at1 = (GOPangoAttrSubscript *)attr1;
+	GOPangoAttrSubscript *at2 = (GOPangoAttrSubscript *)attr2;
+	return (at1->val == at2->val);
 }
 
 PangoAttribute *
-go_pango_attr_subscript_new (void)
+go_pango_attr_subscript_new (gboolean val)
 {
 	GOPangoAttrSubscript *result;
 
@@ -686,7 +692,7 @@ go_pango_attr_subscript_new (void)
 		0,
 		go_pango_attr_subscript_copy,
 		go_pango_attr_destroy,
-		go_pango_attr_compare
+		go_pango_attr_subscript_compare
 	};
 
 	if (!klass.type)
@@ -694,12 +700,13 @@ go_pango_attr_subscript_new (void)
 
 	result = g_new (GOPangoAttrSubscript, 1);
 	result->attr.klass = &klass;
+	result->val = val;
 
 	return (PangoAttribute *) result;
 }
 
 PangoAttribute *
-go_pango_attr_superscript_new (void)
+go_pango_attr_superscript_new (gboolean val)
 {
 	GOPangoAttrSuperscript *result;
 
@@ -707,7 +714,7 @@ go_pango_attr_superscript_new (void)
 		0,
 		go_pango_attr_superscript_copy,
 		go_pango_attr_destroy,
-		go_pango_attr_compare
+		go_pango_attr_superscript_compare
 	};
 
 	if (!klass.type)
@@ -715,6 +722,7 @@ go_pango_attr_superscript_new (void)
 
 	result = g_new (GOPangoAttrSuperscript, 1);
 	result->attr.klass = &klass;
+	result->val = val;
 
 	return (PangoAttribute *) result;
 }
diff --git a/goffice/utils/go-pango-extras.h b/goffice/utils/go-pango-extras.h
index 359ca9f..c660fd2 100644
--- a/goffice/utils/go-pango-extras.h
+++ b/goffice/utils/go-pango-extras.h
@@ -7,8 +7,16 @@
 
 G_BEGIN_DECLS
 
-typedef struct _GOPangoAttrSuperscript GOPangoAttrSuperscript;
-typedef struct _GOPangoAttrSubscript GOPangoAttrSubscript;
+typedef struct {
+	PangoAttribute attr;
+	gboolean val;
+} GOPangoAttrSuperscript;
+
+typedef struct {
+	PangoAttribute attr;
+	gboolean val;
+} GOPangoAttrSubscript;
+
 
 void go_pango_attr_list_open_hole (PangoAttrList *tape, guint pos, guint len);
 void go_pango_attr_list_erase (PangoAttrList *attrs, guint pos, guint len);
@@ -24,8 +32,8 @@ void go_create_std_tags_for_buffer (GtkTextBuffer *buffer);
 
 PangoAttrList *go_pango_translate_attributes (PangoAttrList *attrs);
 void go_pango_translate_layout (PangoLayout *layout);
-PangoAttribute *go_pango_attr_subscript_new (void);
-PangoAttribute *go_pango_attr_superscript_new (void);
+PangoAttribute *go_pango_attr_subscript_new (gboolean val);
+PangoAttribute *go_pango_attr_superscript_new (gboolean val);
 PangoAttrType go_pango_attr_subscript_get_type (void);
 PangoAttrType go_pango_attr_superscript_get_type (void);
 



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