[goffice] read and write the subscript/superscript attributes



commit 23065b6094c0d3ee352cf680f9ac29b238b81aef
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Oct 27 09:54:17 2011 -0600

    read and write the subscript/superscript attributes
    
    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
    	* goffice/utils/go-pango-extras.h (go_pango_attr_subscript_get_type):
    	new
    	(go_pango_attr_superscript_get_type): new
    	* goffice/utils/go-pango-extras.c (go_pango_attr_subscript_get_type):
    	new
    	(go_pango_attr_superscript_get_type): new
    	(filter_func): use the above
    	(go_pango_attr_subscript_new): ditto
    	(go_pango_attr_superscript_new): ditto

 ChangeLog                       |   15 ++++++++++++++
 goffice/utils/go-format.c       |   20 +++++++++++++++---
 goffice/utils/go-pango-extras.c |   41 ++++++++++++++++++++++++++++----------
 goffice/utils/go-pango-extras.h |    4 +++
 4 files changed, 65 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e318501..45f1028 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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
+	* goffice/utils/go-pango-extras.h (go_pango_attr_subscript_get_type):
+	new
+	(go_pango_attr_superscript_get_type): new
+	* goffice/utils/go-pango-extras.c (go_pango_attr_subscript_get_type):
+	new
+	(go_pango_attr_superscript_get_type): new
+	(filter_func): use the above
+	(go_pango_attr_subscript_new): ditto
+	(go_pango_attr_superscript_new): ditto
+
 2011-10-27  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/canvas/goc-canvas.c: new helper functions.
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 78fb4e3..1428ea1 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -4206,7 +4206,7 @@ _go_number_format_init (void)
 
 #ifdef DEFINE_COMMON
 static void
-cb_format_leak (gpointer key, gpointer value, gpointer user_data)
+cb_format_leak (G_GNUC_UNUSED gpointer key, gpointer value, G_GNUC_UNUSED gpointer user_data)
 {
 	GOFormat const *gf = value;
 	if (gf->ref_count != 1)
@@ -4852,7 +4852,13 @@ cb_attrs_as_string (PangoAttribute *a, GString *accum)
 			((c->blue & 0xff00) >> 8));
 		break;
 	default :
-		return FALSE; /* ignored */
+		if (a->klass->type == go_pango_attr_subscript_get_type ()) {
+			g_string_append (accum, "[subscript=1");
+			break;
+		} else if (a->klass->type == go_pango_attr_superscript_get_type ()) {
+			g_string_append (accum, "[superscript=1");
+			break;
+		} else return FALSE; /* ignored */
 	}
 	g_string_append_printf (accum, ":%u:%u]", a->start_index, a->end_index);
 	return FALSE;
@@ -4927,7 +4933,13 @@ go_format_parse_markup (char *str)
 					a = pango_attr_underline_new (PANGO_UNDERLINE_LOW);
 				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 ();
+			break;
+
+		case 11:
+			if (0 == strncmp (str, "superscript", 11))
+				a = go_pango_attr_superscript_new ();
 			break;
 
 		case 13:
@@ -7240,7 +7252,7 @@ go_format_output_number_to_odf (GsfXMLOut *xout, GOFormat const *fmt,
 
 static void
 go_format_output_text_to_odf (GsfXMLOut *xout, GOFormat const *fmt,
-				char const *name, int cond_part)
+				char const *name, G_GNUC_UNUSED int cond_part)
 {
 	char const *xl = go_format_as_XL (fmt);
 	GString *accum = g_string_new (NULL);
diff --git a/goffice/utils/go-pango-extras.c b/goffice/utils/go-pango-extras.c
index dff4378..b3dc7f4 100644
--- a/goffice/utils/go-pango-extras.c
+++ b/goffice/utils/go-pango-extras.c
@@ -12,9 +12,6 @@
 #include "go-glib-extras.h"
 #include <string.h>
 
-static PangoAttrType go_pango_attr_subscript_type = PANGO_ATTR_INVALID;
-static PangoAttrType go_pango_attr_superscript_type = PANGO_ATTR_INVALID;
-
 struct _GOPangoAttrSuperscript {
 	PangoAttribute attr;
 };
@@ -496,9 +493,8 @@ static gboolean
 filter_func (PangoAttribute *attribute, G_GNUC_UNUSED gpointer data)
 {
 	PangoAttrType type = attribute->klass->type;
-	return (type != PANGO_ATTR_INVALID &&
-		(type == go_pango_attr_superscript_type ||
-		 type == go_pango_attr_subscript_type));
+	return (type == go_pango_attr_superscript_get_type () ||
+		type == go_pango_attr_subscript_get_type ());
 }
 
 static void
@@ -545,7 +541,7 @@ go_pango_translate_here (PangoAttrIterator *state_iter,
 		/* 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_type) {
+			if (type == go_pango_attr_superscript_get_type ()) {
 				scale *= GO_SUPERSCRIPT_SCALE;
 				rise += GO_SUPERSCRIPT_RISE * font_scale;
 				font_scale *= GO_SUPERSCRIPT_SCALE;
@@ -631,6 +627,31 @@ go_pango_translate_layout (PangoLayout *layout)
 	
 }
 
+PangoAttrType 
+go_pango_attr_subscript_get_type (void)
+{
+	static PangoAttrType go_pango_attr_subscript_type = PANGO_ATTR_INVALID;
+
+	if(go_pango_attr_subscript_type == PANGO_ATTR_INVALID)
+		go_pango_attr_subscript_type =
+			pango_attr_type_register ("GOSubscript");
+
+	return go_pango_attr_subscript_type;
+}
+
+PangoAttrType 
+go_pango_attr_superscript_get_type (void)
+{
+	static PangoAttrType go_pango_attr_superscript_type = PANGO_ATTR_INVALID;
+
+	if(go_pango_attr_superscript_type == PANGO_ATTR_INVALID)
+		go_pango_attr_superscript_type =
+			pango_attr_type_register ("GOSuperscript");
+
+	return go_pango_attr_superscript_type;
+}
+
+
 static PangoAttribute *
 go_pango_attr_subscript_copy (G_GNUC_UNUSED PangoAttribute const *attr)
 {
@@ -669,8 +690,7 @@ go_pango_attr_subscript_new (void)
 	};
 
 	if (!klass.type)
-		klass.type = go_pango_attr_subscript_type =
-			pango_attr_type_register ("GOSubscript");
+		klass.type = go_pango_attr_subscript_get_type ();
 
 	result = g_new (GOPangoAttrSubscript, 1);
 	result->attr.klass = &klass;
@@ -691,8 +711,7 @@ go_pango_attr_superscript_new (void)
 	};
 
 	if (!klass.type)
-		klass.type = go_pango_attr_superscript_type =
-			pango_attr_type_register ("GOSuperscript");
+		klass.type = go_pango_attr_superscript_get_type ();
 
 	result = g_new (GOPangoAttrSuperscript, 1);
 	result->attr.klass = &klass;
diff --git a/goffice/utils/go-pango-extras.h b/goffice/utils/go-pango-extras.h
index 0d666f1..359ca9f 100644
--- a/goffice/utils/go-pango-extras.h
+++ b/goffice/utils/go-pango-extras.h
@@ -26,6 +26,10 @@ 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);
+PangoAttrType go_pango_attr_subscript_get_type (void);
+PangoAttrType go_pango_attr_superscript_get_type (void);
+
+
 
 G_END_DECLS
 



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