From: Andrea Zagli Date: Mon, 31 Oct 2011 17:10:23 +0000 (+0100) Subject: Added letter spacing property to text object (closes #173). X-Git-Tag: 0.5.0~15 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=97b5a219659c93a894b64240178e84d633fedd11;p=reptool%2Flibreptool Added letter spacing property to text object (closes #173). --- diff --git a/data/reptool.dtd b/data/reptool.dtd index 6e454e4..b421db8 100644 --- a/data/reptool.dtd +++ b/data/reptool.dtd @@ -73,6 +73,7 @@ padding-bottom CDATA #IMPLIED padding-left CDATA #IMPLIED ellipsize (none | start | middle | end) + letter-spacing CDATA #IMPLIED > diff --git a/data/reptool_report.dtd b/data/reptool_report.dtd index cca9d2a..481a7e0 100644 --- a/data/reptool_report.dtd +++ b/data/reptool_report.dtd @@ -67,6 +67,7 @@ padding-bottom CDATA #IMPLIED padding-left CDATA #IMPLIED ellipsize (none | start | middle | end) + letter-spacing CDATA #IMPLIED > diff --git a/src/rptobjecttext.c b/src/rptobjecttext.c index 640cc1d..6292215 100644 --- a/src/rptobjecttext.c +++ b/src/rptobjecttext.c @@ -33,7 +33,8 @@ enum PROP_PADDING_RIGHT, PROP_PADDING_BOTTOM, PROP_PADDING_LEFT, - PROP_ELLIPSIZE + PROP_ELLIPSIZE, + PROP_LETTER_SPACING }; static void rpt_obj_text_class_init (RptObjTextClass *klass); @@ -66,6 +67,7 @@ struct _RptObjTextPrivate gdouble padding_bottom; gdouble padding_left; eRptEllipsize ellipsize; + guint letter_spacing; }; G_DEFINE_TYPE (RptObjText, rpt_obj_text, TYPE_RPT_OBJECT) @@ -149,6 +151,12 @@ rpt_obj_text_class_init (RptObjTextClass *klass) "Ellipsize", RPT_ELLIPSIZE_NONE, RPT_ELLIPSIZE_END, RPT_ELLIPSIZE_NONE, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_LETTER_SPACING, + g_param_spec_uint ("letter-spacing", + "Letter spacing", + "Amount of extra space to add between graphemes of the text.", + 0, G_MAXUINT, 0, + G_PARAM_READWRITE)); } static void @@ -178,6 +186,8 @@ rpt_obj_text_init (RptObjText *rpt_obj_text) priv->background_color = NULL; priv->ellipsize = RPT_ELLIPSIZE_NONE; + + priv->letter_spacing = 0; } /** @@ -201,10 +211,11 @@ RptObject rpt_obj_text = RPT_OBJECT (g_object_new (rpt_obj_text_get_type (), NULL)); g_object_set (G_OBJECT (rpt_obj_text), - "name", name_, - "position", &position, - NULL); + "name", name_, + "position", &position, + NULL); } + g_free (name_); return rpt_obj_text; } @@ -263,25 +274,25 @@ RptObject prop = (gchar *)xmlGetProp (xnode, "padding-top"); if (prop != NULL) { - g_object_set (rpt_obj_text, "padding-top", strtod (prop, NULL), NULL); + g_object_set (rpt_obj_text, "padding-top", g_strtod (prop, NULL), NULL); xmlFree (prop); } prop = (gchar *)xmlGetProp (xnode, "padding-right"); if (prop != NULL) { - g_object_set (rpt_obj_text, "padding-right", strtod (prop, NULL), NULL); + g_object_set (rpt_obj_text, "padding-right", g_strtod (prop, NULL), NULL); xmlFree (prop); } prop = (gchar *)xmlGetProp (xnode, "padding-bottom"); if (prop != NULL) { - g_object_set (rpt_obj_text, "padding-bottom", strtod (prop, NULL), NULL); + g_object_set (rpt_obj_text, "padding-bottom", g_strtod (prop, NULL), NULL); xmlFree (prop); } prop = (gchar *)xmlGetProp (xnode, "padding-left"); if (prop != NULL) { - g_object_set (rpt_obj_text, "padding-left", strtod (prop, NULL), NULL); + g_object_set (rpt_obj_text, "padding-left", g_strtod (prop, NULL), NULL); xmlFree (prop); } prop = (gchar *)xmlGetProp (xnode, "ellipsize"); @@ -290,6 +301,12 @@ RptObject g_object_set (rpt_obj_text, "ellipsize", rpt_common_strellipsize_to_enum (prop), NULL); xmlFree (prop); } + prop = (gchar *)xmlGetProp (xnode, "letter-spacing"); + if (prop != NULL) + { + g_object_set (rpt_obj_text, "letter-spacing", strtol (prop, NULL, 10), NULL); + xmlFree (prop); + } } } @@ -342,6 +359,10 @@ rpt_obj_text_get_xml (RptObject *rpt_objtext, xmlNode *xnode) { xmlSetProp (xnode, "ellipsize", rpt_common_enum_to_strellipsize (priv->ellipsize)); } + if (priv->letter_spacing > 0) + { + xmlSetProp (xnode, "letter-spacing", g_strdup_printf ("%d", priv->letter_spacing)); + } } static void @@ -400,6 +421,10 @@ rpt_obj_text_set_property (GObject *object, guint property_id, const GValue *val priv->ellipsize = g_value_get_uint (value); break; + case PROP_LETTER_SPACING: + priv->letter_spacing = g_value_get_uint (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -462,6 +487,10 @@ rpt_obj_text_get_property (GObject *object, guint property_id, GValue *value, GP g_value_set_uint (value, priv->ellipsize); break; + case PROP_LETTER_SPACING: + g_value_set_uint (value, priv->letter_spacing); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; diff --git a/src/rptprint.c b/src/rptprint.c index f7de315..2f1e7d5 100644 --- a/src/rptprint.c +++ b/src/rptprint.c @@ -904,6 +904,32 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode) pango_attr_list_insert (lpattr, pattr); } + /* letter spacing */ + prop = xmlGetProp (xnode, (const xmlChar *)"letter-spacing"); + if (prop != NULL) + { + guint spacing; + + spacing = strtol (prop, NULL, 10); + + if (spacing > 0) + { + PangoAttribute *pattr; + + pattr = pango_attr_letter_spacing_new (spacing * PANGO_SCALE); + pattr->start_index = 0; + pattr->end_index = strlen (text) + 1; + + if (lpattr == NULL) + { + lpattr = pango_attr_list_new (); + } + pango_attr_list_insert (lpattr, pattr); + } + + xmlFree (prop); + } + if (lpattr != NULL) { pango_layout_set_attributes (playout, lpattr);