]> saetta.ns0.it Git - reptool/libreptool.bug/commitdiff
Added, managed and tested property ellipsize to text objects (closes #64).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Tue, 18 Oct 2011 09:45:08 +0000 (11:45 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Tue, 18 Oct 2011 09:45:08 +0000 (11:45 +0200)
data/reptool.dtd
data/reptool_report.dtd
src/rptcommon.c
src/rptcommon.h
src/rptobjecttext.c
src/rptprint.c
src/rptreport.c

index c809b7c1237bf2684288e587ee845af472fddcfe..ba0534a3e4e0a359a59f7fd77b91c48141c22772 100644 (file)
@@ -71,6 +71,7 @@
   padding-right      CDATA #IMPLIED
   padding-bottom     CDATA #IMPLIED
   padding-left       CDATA #IMPLIED
+  ellipsize          (none | start | middle | end)
 >
 
 <!ELEMENT line EMPTY>
index 90842c711116cbf142f30460f0c7c7033fb72234..6a3f6339927f451bcd7176306c523a25929c6ee0 100644 (file)
@@ -65,6 +65,7 @@
   padding-right      CDATA #IMPLIED
   padding-bottom     CDATA #IMPLIED
   padding-left       CDATA #IMPLIED
+  ellipsize          (none | start | middle | end)
 >
 
 <!ELEMENT line EMPTY>
index af2ecaf8a1712d221f5fc5bb30526ca5bd9f95c3..db73db03bbd0ab201afccd7c8139b0741af5bcc7 100644 (file)
@@ -184,6 +184,87 @@ const gchar
        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:
index 0622d2a5c56271cf7f8effcaf7a737c0dabc2d12..523987827e8b16c6d4285e8836fb06350c500107 100644 (file)
@@ -183,6 +183,14 @@ struct _RptStroke
 };
 typedef struct _RptStroke RptStroke;
 
+typedef enum
+{
+       RPT_ELLIPSIZE_NONE,
+       RPT_ELLIPSIZE_START,
+       RPT_ELLIPSIZE_MIDDLE,
+       RPT_ELLIPSIZE_END
+} eRptEllipsize;
+
 
 gdouble rpt_common_value_to_points (eRptUnitLength unit, gdouble value);
 gdouble rpt_common_points_to_value (eRptUnitLength unit, gdouble value);
@@ -193,6 +201,9 @@ const gchar *rpt_common_enum_to_strunit (eRptUnitLength unit);
 eRptOutputType rpt_common_stroutputtype_to_enum (const gchar *output_type);
 const gchar *rpt_common_enum_to_stroutputtype (eRptOutputType output_type);
 
+eRptEllipsize rpt_common_strellipsize_to_enum (const gchar *ellipsize);
+const gchar *rpt_common_enum_to_strellipsize (eRptEllipsize ellipsize);
+
 RptPoint *rpt_common_rptpoint_new (void);
 RptPoint *rpt_common_rptpoint_new_with_values (gdouble x, gdouble y);
 RptPoint *rpt_common_get_position (xmlNode *xnode);
index 30152b25137a1c0f77589e9a89b91b70fd129901..d1eaf57d509ce37f6df124c9d9c42dcd905175bd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -32,7 +32,8 @@ enum
        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);
@@ -64,35 +65,10 @@ struct _RptObjTextPrivate
                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)
@@ -167,6 +143,12 @@ 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
@@ -194,6 +176,8 @@ rpt_obj_text_init (RptObjText *rpt_obj_text)
        priv->font = font;
        priv->align = NULL;
        priv->background_color = NULL;
+
+       priv->ellipsize = RPT_ELLIPSIZE_NONE;
 }
 
 /**
@@ -261,6 +245,7 @@ RptObject
 
                                        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)
@@ -269,27 +254,39 @@ RptObject
 
                                                        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);
                                                }
                                }
                }
@@ -339,13 +336,16 @@ rpt_obj_text_get_xml (RptObject *rpt_objtext, xmlNode *xnode)
                {
                        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)
@@ -394,6 +394,10 @@ rpt_obj_text_set_property (GObject *object, guint property_id, const GValue *val
                                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;
@@ -404,7 +408,6 @@ static void
 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)
@@ -453,6 +456,10 @@ rpt_obj_text_get_property (GObject *object, guint property_id, GValue *value, GP
                                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;
index dab0b9e5187083a4a87e0a83478aa0a95bdfb05f..e0fbac7ff8c9eb40df0d97a6068332587557eb16 100644 (file)
@@ -851,7 +851,7 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
                }
        else
                {
-                       pango_font_description_set_size (pfdesc, 12);
+                       pango_font_description_set_size (pfdesc, 12 * PANGO_SCALE);
                }
 
        pango_layout_set_font_description (playout, pfdesc);
@@ -910,6 +910,7 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
                        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);
@@ -958,6 +959,34 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
                        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)
                {
index caf144d54fc18a4c9df9a346d60309adc177c725..577b372fcf66a972ed4ef7be2c22745f2b9c6897 100644 (file)
@@ -655,6 +655,7 @@ RptReport
                                      "source", g_strdup_printf ("[%s]", field_name),
                                      "size", size,
                                      "font", font,
+                                     "ellipsize", RPT_ELLIPSIZE_END,
                                      NULL);
 
                        rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_BODY);