[gnumeric] move odf_pango_attrs_to_markup to goffice



commit 702f36bebedece2963e16b8f11bf58f28dfed5a0
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sat May 12 21:54:32 2012 -0600

    move odf_pango_attrs_to_markup to goffice
    
    2012-05-12  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (odf_pango_attrs_to_markup): move to goffice
    	(odf_pango_attr_as_markup_string): move to goffice

 plugins/openoffice/ChangeLog         |    5 +
 plugins/openoffice/openoffice-read.c |  262 +---------------------------------
 2 files changed, 6 insertions(+), 261 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index fc064c4..8d0cab4 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,10 @@
 2012-05-12  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-read.c (odf_pango_attrs_to_markup): move to goffice
+	(odf_pango_attr_as_markup_string): move to goffice
+
+2012-05-12  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-read.c (odf_pango_attr_as_markup_string): add some
 	more attribute types
 
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 8d4a45a..be93315 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -463,266 +463,6 @@ static OOFormula odf_get_formula_type (GsfXMLIn *xin, char const **str);
 static char const *odf_strunescape (char const *string, GString *target,
 				    G_GNUC_UNUSED GnmConventions const *convs);
 
-/* Some utilities that should belong elsewhere */
-static int
-odf_pango_attr_as_markup_string (PangoAttribute *a, GString *gstr)
-{
-	int spans = 0;
-
-	switch (a->klass->type) {
-	case PANGO_ATTR_FONT_DESC : 
-		{
-			char *str = pango_font_description_to_string 
-				(((PangoAttrFontDesc *)a)->desc);
-			spans += 1;
-			g_string_append_printf (gstr, "<span font_desc=\"%s\">", str);
-			g_free (str);
-		}
-		break;
-	case PANGO_ATTR_FAMILY :
-		spans += 1;
-		g_string_append_printf (gstr, "<span font_family=\"%s\">", 
-					((PangoAttrString *)a)->value);
-		break;
-	case PANGO_ATTR_ABSOLUTE_SIZE :
-	case PANGO_ATTR_SIZE :
-		spans += 1;
-		g_string_append_printf (gstr, "<span font_size=\"%i\">", 
-					((PangoAttrSize *)a)->size);
-		break;
-	case PANGO_ATTR_RISE:
-		spans += 1;
-		g_string_append_printf (gstr, "<span rise=\"%i\">", 
-					((PangoAttrInt *)a)->value);
-		break;
-	case PANGO_ATTR_STYLE :
-		spans += 1;
-		switch (((PangoAttrInt *)a)->value) {
-		case PANGO_STYLE_ITALIC:
-			g_string_append (gstr, "<span font_style=\"italic\">");
-			break;
-		case PANGO_STYLE_OBLIQUE:
-			g_string_append (gstr, "<span font_style=\"oblique\">");
-			break;
-		case PANGO_STYLE_NORMAL:
-		default:
-			g_string_append (gstr, "<span font_style=\"normal\">");
-			break;
-		}		
-		break;
-	case PANGO_ATTR_WEIGHT :
-		spans += 1;
-		g_string_append_printf (gstr, "<span font_weight=\"%i\">", 
-					((PangoAttrInt *)a)->value);
-	break;
-	case PANGO_ATTR_STRIKETHROUGH :
-		spans += 1;
-		if (((PangoAttrInt *)a)->value)
-			g_string_append (gstr, "<span strikethrough=\"true\">");
-		else
-			g_string_append (gstr, "<span strikethrough=\"false\">");
-		break;
-	case PANGO_ATTR_UNDERLINE :
-		spans += 1;
-		switch (((PangoAttrInt *)a)->value) {
-		case PANGO_UNDERLINE_SINGLE:
-			g_string_append (gstr, "<span underline=\"single\">");
-			break;
-		case PANGO_UNDERLINE_DOUBLE:
-			g_string_append (gstr, "<span underline=\"double\">");
-			break;
-		case PANGO_UNDERLINE_LOW:
-			g_string_append (gstr, "<span underline=\"low\">");
-			break;
-		case PANGO_UNDERLINE_ERROR:
-			g_string_append (gstr, "<span underline=\"error\">");
-			break;
-		case PANGO_UNDERLINE_NONE:
-		default:
-			g_string_append (gstr, "<span underline=\"none\">");
-			break;
-		}		
-		break;
-	case PANGO_ATTR_LANGUAGE :
-		spans += 1;
-		g_string_append_printf (gstr, "<span lang=\"%s\">", 
-					pango_language_to_string (((PangoAttrLanguage *)a)->value));
-		break;
-	case PANGO_ATTR_VARIANT :
-		spans += 1;
-		if (((PangoAttrInt *)a)->value == PANGO_VARIANT_NORMAL)
-			g_string_append (gstr, "<span font_variant=\"normal\">");
-		else
-			g_string_append (gstr, "<span font_variant=\"smallcaps\">");
-		break;
-	case PANGO_ATTR_LETTER_SPACING :
-		spans += 1;
-		g_string_append_printf (gstr, "<span letter_spacing=\"%i\">", 
-					((PangoAttrInt *)a)->value);
-		break;
-	case PANGO_ATTR_FALLBACK :
-		spans += 1;
-		if (((PangoAttrInt *)a)->value)
-			g_string_append (gstr, "<span fallback=\"true\">");
-		else
-			g_string_append (gstr, "<span fallback=\"false\">");
-		break;
-	case PANGO_ATTR_STRETCH :
-		spans += 1;
-		switch (((PangoAttrInt *)a)->value) {
-		case PANGO_STRETCH_ULTRA_CONDENSED:
-			g_string_append (gstr, "<span font_stretch=\"ultracondensed\">");
-			break;
-		case PANGO_STRETCH_EXTRA_CONDENSED:
-			g_string_append (gstr, "<span font_stretch=\"extracondensed\">");
-			break;
-		case PANGO_STRETCH_CONDENSED:
-			g_string_append (gstr, "<span font_stretch=\"condensed\">");
-			break;
-		case PANGO_STRETCH_SEMI_CONDENSED:
-			g_string_append (gstr, "<span font_stretch=\"semicondensed\">");
-			break;
-		case PANGO_STRETCH_SEMI_EXPANDED:
-			g_string_append (gstr, "<span font_stretch=\"semiexpanded\">");
-			break;
-		case PANGO_STRETCH_EXPANDED:
-			g_string_append (gstr, "<span font_stretch=\"expanded\">");
-			break;
-		case PANGO_STRETCH_EXTRA_EXPANDED:
-			g_string_append (gstr, "<span font_stretch=\"extraexpanded\">");
-			break;
-		case PANGO_STRETCH_ULTRA_EXPANDED:
-			g_string_append (gstr, "<span font_stretch=\"ultraexpanded\">");
-			break;
-		case PANGO_STRETCH_NORMAL:
-		default:
-			g_string_append (gstr, "<span font_stretch=\"normal\">");
-			break;
-		}		
-		break;
-	case PANGO_ATTR_GRAVITY :
-		spans += 1;
-		switch (((PangoAttrInt *)a)->value) {
-		case PANGO_GRAVITY_SOUTH:
-			g_string_append (gstr, "<span gravity=\"south\">");
-			break;
-		case PANGO_GRAVITY_EAST:
-			g_string_append (gstr, "<span gravity=\"east\">");
-			break;
-		case PANGO_GRAVITY_NORTH:
-			g_string_append (gstr, "<span gravity=\"north\">");
-			break;
-		case PANGO_GRAVITY_WEST:
-			g_string_append (gstr, "<span gravity=\"west\">");
-			break;
-		case PANGO_GRAVITY_AUTO:
-		default:
-			g_string_append (gstr, "<span gravity=\"auto\">");
-			break;
-		}		
-		break;
-	case PANGO_ATTR_GRAVITY_HINT :
-		spans += 1;
-		switch (((PangoAttrInt *)a)->value) {
-		case PANGO_GRAVITY_HINT_LINE:
-			g_string_append (gstr, "<span gravity_hint=\"line\">");
-			break;
-		case PANGO_GRAVITY_HINT_STRONG:
-			g_string_append (gstr, "<span gravity_hint=\"strong\">");
-			break;
-		case PANGO_GRAVITY_HINT_NATURAL:
-		default:
-			g_string_append (gstr, "<span gravity_hint=\"natural\">");
-			break;
-		}		
-		break;
-		
-	case PANGO_ATTR_FOREGROUND :
-		{
-			PangoColor *color = &((PangoAttrColor *)a)->color;
-			spans += 1;
-			g_string_append_printf (gstr, "<span foreground=\"#%02X%02X%02X\">",
-						color->red, color->green, color->blue);
-		}
-		break;
-	case PANGO_ATTR_BACKGROUND :
-		{
-			PangoColor *color = &((PangoAttrColor *)a)->color;
-			spans += 1;
-			g_string_append_printf (gstr, "<span background=\"#%02X%02X%02X\">",
-						color->red, color->green, color->blue);
-		}
-		break;
-	case PANGO_ATTR_UNDERLINE_COLOR :
-		{
-			PangoColor *color = &((PangoAttrColor *)a)->color;
-			spans += 1;
-			g_string_append_printf (gstr, "<span underline_color=\"#%02X%02X%02X\">",
-						color->red, color->green, color->blue);
-		}
-		break;
-	case PANGO_ATTR_STRIKETHROUGH_COLOR :
-		{
-			PangoColor *color = &((PangoAttrColor *)a)->color;
-			spans += 1;
-			g_string_append_printf (gstr, "<span strikethrough_color=\"#%02X%02X%02X\">",
-						color->red, color->green, color->blue);
-		}
-		break;
-
-	case PANGO_ATTR_SCALE :
-	case PANGO_ATTR_SHAPE :
-	default :
-		break; /* ignored */
-	}
-
-	return spans;
-}
-
-static char *
-odf_pango_attrs_to_markup (PangoAttrList *attrs, char const *text)
-{
-	PangoAttrIterator * iter;
-	int handled = 0;
-	int from, to;
-	int len;
-	GString *gstr;
-
-	if (text == NULL)
-		return NULL;
-	if (attrs == NULL || go_pango_attr_list_is_empty (attrs))
-		return g_strdup (text);
-
-	len = strlen (text);
-	gstr = g_string_sized_new (len + 1);
-
-	iter = pango_attr_list_get_iterator (attrs);
-	do {
-		GSList *list, *l;
-		int spans = 0;
-
-		pango_attr_iterator_range (iter, &from, &to);
-		to = (to > len) ? len : to;       /* Since "to" can be really big! */
-		from = (from > len) ? len : from; /* Since "from" can also be really big! */
-		if (from > handled)
-			g_string_append_len (gstr, text + handled, from - handled);
-		list = pango_attr_iterator_get_attrs (iter);
-		for (l = list; l != NULL; l = l->next)
-			spans += odf_pango_attr_as_markup_string (l->data, gstr);
-		g_slist_free (list);
-		if (to > from)
-			g_string_append_len (gstr, text + from, to - from);
-		while (spans-- > 0)
-			g_string_append (gstr, "</span>");
-		handled = to;
-	} while (pango_attr_iterator_next (iter));
-
-	pango_attr_iterator_destroy (iter);
-
-	return g_string_free (gstr, FALSE);
-}
-
-
 /* Implementations */
 
 static void
@@ -7855,7 +7595,7 @@ oo_chart_title_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 	if (state->chart.title_expr == NULL && ptr->gstr) {
 			state->chart.title_expr = gnm_expr_top_new_constant
 				(value_new_string_nocopy 
-				 (odf_pango_attrs_to_markup (ptr->attrs, ptr->gstr->str)));
+				 (go_pango_attrs_to_markup (ptr->attrs, ptr->gstr->str)));
 			use_markup = (ptr->attrs != NULL && 
 				      !go_pango_attr_list_is_empty (ptr->attrs));
 	}



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