return ret;
}
+/**
+ * rpt_common_strellipsize_to_enum:
+ * @ellipsize:
+ *
+ * Returns: the enum value that match the string @ellipsize.
+ */
+eRptEllipsize
+rpt_common_strellipsize_to_enum (const gchar *ellipsize)
+{
+ eRptEllipsize ret;
+
+ gchar *real_ellipsize;
+
+ ret = RPT_ELLIPSIZE_NONE;
+
+ if (ellipsize != NULL)
+ {
+ real_ellipsize = g_strstrip (g_strdup (ellipsize));
+ if (g_ascii_strcasecmp (real_ellipsize, "none") == 0)
+ {
+ /* already setted */
+ }
+ else if (g_ascii_strcasecmp (real_ellipsize, "start") == 0)
+ {
+ ret = RPT_ELLIPSIZE_START;
+ }
+ else if (g_ascii_strcasecmp (real_ellipsize, "middle") == 0)
+ {
+ ret = RPT_ELLIPSIZE_MIDDLE;
+ }
+ else if (g_ascii_strcasecmp (real_ellipsize, "end") == 0)
+ {
+ ret = RPT_ELLIPSIZE_END;
+ }
+ else
+ {
+ g_warning ("Ellipsize type «%s» not available.", real_ellipsize);
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * rpt_common_enum_to_strellipsize:
+ * @unit:
+ *
+ * Returns: the string value that represents then enum value @unit.
+ */
+const gchar
+*rpt_common_enum_to_strellipsize (eRptEllipsize ellipsize)
+{
+ gchar *ret;
+
+ switch (ellipsize)
+ {
+ case RPT_ELLIPSIZE_NONE:
+ ret = g_strdup ("none");
+ break;
+
+ case RPT_ELLIPSIZE_START:
+ ret = g_strdup ("start");
+ break;
+
+ case RPT_ELLIPSIZE_MIDDLE:
+ ret = g_strdup ("middle");
+ break;
+
+ case RPT_ELLIPSIZE_END:
+ ret = g_strdup ("end");
+ break;
+
+ default:
+ g_warning ("Ellipsize type «%d» not available.", ellipsize);
+ ret = g_strdup ("none");
+ break;
+ }
+
+ return ret;
+}
+
/**
* rpt_common_stroutputtype_to_enum:
* @output_type:
/*
- * Copyright (C) 2006-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2006-2011 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
PROP_PADDING_TOP,
PROP_PADDING_RIGHT,
PROP_PADDING_BOTTOM,
- PROP_PADDING_LEFT
+ PROP_PADDING_LEFT,
+ PROP_ELLIPSIZE
};
static void rpt_obj_text_class_init (RptObjTextClass *klass);
gdouble padding_right;
gdouble padding_bottom;
gdouble padding_left;
+ eRptEllipsize ellipsize;
};
-GType
-rpt_obj_text_get_type (void)
-{
- static GType rpt_obj_text_type = 0;
-
- if (!rpt_obj_text_type)
- {
- static const GTypeInfo rpt_obj_text_info =
- {
- sizeof (RptObjTextClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) rpt_obj_text_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (RptObjText),
- 0, /* n_preallocs */
- (GInstanceInitFunc) rpt_obj_text_init,
- NULL
- };
-
- rpt_obj_text_type = g_type_register_static (TYPE_RPT_OBJECT, "RptObjText",
- &rpt_obj_text_info, 0);
- }
-
- return rpt_obj_text_type;
-}
+G_DEFINE_TYPE (RptObjText, rpt_obj_text, TYPE_RPT_OBJECT)
static void
rpt_obj_text_class_init (RptObjTextClass *klass)
"Padding Left",
0, G_MAXDOUBLE, 0,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class, PROP_ELLIPSIZE,
+ g_param_spec_uint ("ellipsize",
+ "Ellipsize",
+ "Ellipsize",
+ RPT_ELLIPSIZE_NONE, RPT_ELLIPSIZE_END, RPT_ELLIPSIZE_NONE,
+ G_PARAM_READWRITE));
}
static void
priv->font = font;
priv->align = NULL;
priv->background_color = NULL;
+
+ priv->ellipsize = RPT_ELLIPSIZE_NONE;
}
/**
prop = (gchar *)xmlGetProp (xnode, "source");
g_object_set (rpt_obj_text, "source", prop, NULL);
+ if (prop != NULL) xmlFree (prop);
prop = (gchar *)xmlGetProp (xnode, "background-color");
if (prop != NULL)
color = rpt_common_parse_color (g_strstrip (prop));
g_object_set (rpt_obj_text, "background-color", color, NULL);
+
+ xmlFree (prop);
}
prop = (gchar *)xmlGetProp (xnode, "padding-top");
if (prop != NULL)
{
g_object_set (rpt_obj_text, "padding-top", 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);
+ xmlFree (prop);
}
prop = (gchar *)xmlGetProp (xnode, "padding-bottom");
if (prop != NULL)
{
g_object_set (rpt_obj_text, "padding-bottom", 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);
+ xmlFree (prop);
+ }
+ prop = (gchar *)xmlGetProp (xnode, "ellipsize");
+ if (prop != NULL)
+ {
+ g_object_set (rpt_obj_text, "ellipsize", rpt_common_strellipsize_to_enum (prop), NULL);
+ xmlFree (prop);
}
}
}
{
xmlSetProp (xnode, "padding-left", g_strdup_printf ("%f", priv->padding_left));
}
+ if (priv->ellipsize > RPT_ELLIPSIZE_NONE)
+ {
+ xmlSetProp (xnode, "ellipsize", rpt_common_enum_to_strellipsize (priv->ellipsize));
+ }
}
static void
rpt_obj_text_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
RptObjText *rpt_obj_text = RPT_OBJ_TEXT (object);
-
RptObjTextPrivate *priv = RPT_OBJ_TEXT_GET_PRIVATE (rpt_obj_text);
switch (property_id)
priv->padding_left = g_value_get_double (value);
break;
+ case PROP_ELLIPSIZE:
+ priv->ellipsize = g_value_get_uint (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
rpt_obj_text_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
RptObjText *rpt_obj_text = RPT_OBJ_TEXT (object);
-
RptObjTextPrivate *priv = RPT_OBJ_TEXT_GET_PRIVATE (rpt_obj_text);
switch (property_id)
g_value_set_double (value, priv->padding_left);
break;
+ case PROP_ELLIPSIZE:
+ g_value_set_uint (value, priv->ellipsize);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
else
{
- pango_font_description_set_size (pfdesc, 12);
+ pango_font_description_set_size (pfdesc, 12 * PANGO_SCALE);
}
pango_layout_set_font_description (playout, pfdesc);
cairo_set_source_rgba (priv->cr, color->r, color->g, color->b, color->a);
cairo_fill_preserve (priv->cr);
}
+ if (prop != NULL) xmlFree (prop);
/* drawing border */
rpt_print_border (rpt_print, position, size, border, rotation);
cairo_clip (priv->cr);
}
+ /* ellipsize */
+ prop = xmlGetProp (xnode, (const xmlChar *)"ellipsize");
+ if (prop != NULL)
+ {
+ eRptEllipsize ellipsize = rpt_common_strellipsize_to_enum (prop);
+ if (ellipsize > RPT_ELLIPSIZE_NONE)
+ {
+ switch (ellipsize)
+ {
+ case RPT_ELLIPSIZE_START:
+ pango_layout_set_ellipsize (playout, PANGO_ELLIPSIZE_START);
+ break;
+
+ case RPT_ELLIPSIZE_MIDDLE:
+ pango_layout_set_ellipsize (playout, PANGO_ELLIPSIZE_MIDDLE);
+ break;
+
+ case RPT_ELLIPSIZE_END:
+ pango_layout_set_ellipsize (playout, PANGO_ELLIPSIZE_END);
+ break;
+
+ default:
+ break;
+ }
+ }
+ xmlFree (prop);
+ }
+
/* drawing text */
if (font != NULL)
{