]> git.sur5r.net Git - glabels/commitdiff
2004-07-11 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Mon, 12 Jul 2004 01:09:00 +0000 (01:09 +0000)
committerJim Evins <evins@snaught.com>
Mon, 12 Jul 2004 01:09:00 +0000 (01:09 +0000)
* data/glabels-2.0.dtd:
* src/label-text.c: (gl_label_text_instance_init), (copy),
(gl_label_text_set_auto_shrink), (gl_label_text_get_auto_shrink):
* src/label-text.h:
* src/object-editor-private.h:
* src/object-editor-text-page.c:
(gl_object_editor_prepare_text_page),
(gl_object_editor_set_text_auto_shrink),
(gl_object_editor_get_text_auto_shrink):
* src/object-editor.c: (gl_object_editor_set_key_names):
* src/object-editor.glade:
* src/object-editor.h:
* src/print.c: (draw_text_object):
* src/view-text.c: (update_object_from_editor_cb),
(update_editor_from_object_cb):
* src/xml-label.c: (xml_parse_object_text),
(xml_create_object_text):
Added option to allow document merge to auto shrink text size to fit
within the text box.  The code in print.c that actually shrinks the
text is loosely based on a patch submitted by Mark Harrison
<mark.harrison@velocitynet.com.au>.  This addresses feature request
#661421.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@432 f5e0f49d-192f-0410-a22d-a8d8700d0965

12 files changed:
glabels2/ChangeLog
glabels2/data/glabels-2.0.dtd
glabels2/src/label-text.c
glabels2/src/label-text.h
glabels2/src/object-editor-private.h
glabels2/src/object-editor-text-page.c
glabels2/src/object-editor.c
glabels2/src/object-editor.glade
glabels2/src/object-editor.h
glabels2/src/print.c
glabels2/src/view-text.c
glabels2/src/xml-label.c

index 70e981692bc8f6d98a4bb6a662cb2deb2e9f529c..fd29e957f2a19515fa2b76b133b3bcbc2e7585d3 100644 (file)
@@ -1,3 +1,28 @@
+2004-07-11  Jim Evins  <evins@snaught.com>
+
+       * data/glabels-2.0.dtd:
+       * src/label-text.c: (gl_label_text_instance_init), (copy),
+       (gl_label_text_set_auto_shrink), (gl_label_text_get_auto_shrink):
+       * src/label-text.h:
+       * src/object-editor-private.h:
+       * src/object-editor-text-page.c:
+       (gl_object_editor_prepare_text_page),
+       (gl_object_editor_set_text_auto_shrink),
+       (gl_object_editor_get_text_auto_shrink):
+       * src/object-editor.c: (gl_object_editor_set_key_names):
+       * src/object-editor.glade:
+       * src/object-editor.h:
+       * src/print.c: (draw_text_object):
+       * src/view-text.c: (update_object_from_editor_cb),
+       (update_editor_from_object_cb):
+       * src/xml-label.c: (xml_parse_object_text),
+       (xml_create_object_text):
+               Added option to allow document merge to auto shrink text size to fit
+               within the text box.  The code in print.c that actually shrinks the
+               text is loosely based on a patch submitted by Mark Harrison
+               <mark.harrison@velocitynet.com.au>.  This addresses feature request
+               #661421.
+       
 2004-07-11  Jim Evins  <evins@snaught.com>
 
        * data/glabels-2.0.dtd:
index dcd0b35d2b7f80960505483e2acb87e3c195aa56..556fb35e5dee3ed2e816c0482a573ef4197f9d8f 100644 (file)
                  %position_attrs;
                  %size_attrs;
                  justify         %JUSTIFY_TYPE;          #REQUIRED
+                 auto_shrink     %BOOLEAN_TYPE;          #IMPLIED
                  %affine_attrs;
                  %shadow_attrs;
 >
index 70ae32a72255fb9e964841f7df08604c540c9f75..82e3c1eb403563948715bf3023c0b9e6e1b746a2 100644 (file)
 /* Private macros and constants.                          */
 /*========================================================*/
 
-#define DEFAULT_FONT_FAMILY      "Sans"
-#define DEFAULT_FONT_SIZE        14.0
-#define DEFAULT_FONT_WEIGHT      GNOME_FONT_BOOK
-#define DEFAULT_FONT_ITALIC_FLAG FALSE
-#define DEFAULT_JUST             GTK_JUSTIFY_LEFT
-#define DEFAULT_COLOR            GNOME_CANVAS_COLOR (0,0,0)
+#define DEFAULT_FONT_FAMILY       "Sans"
+#define DEFAULT_FONT_SIZE         14.0
+#define DEFAULT_FONT_WEIGHT       GNOME_FONT_BOOK
+#define DEFAULT_FONT_ITALIC_FLAG  FALSE
+#define DEFAULT_JUST              GTK_JUSTIFY_LEFT
+#define DEFAULT_COLOR             GNOME_CANVAS_COLOR (0,0,0)
 #define DEFAULT_TEXT_LINE_SPACING 1.0
+#define DEFAULT_AUTO_SHRINK       FALSE
 
 /*========================================================*/
 /* Private types.                                         */
@@ -56,6 +57,7 @@ struct _glLabelTextPrivate {
        GtkJustification just;
        guint            color;
        gdouble          line_spacing;
+       gboolean         auto_shrink;
 };
 
 /*========================================================*/
@@ -194,6 +196,7 @@ gl_label_text_instance_init (glLabelText *ltext)
        ltext->private->just             = DEFAULT_JUST;
        ltext->private->color            = DEFAULT_COLOR;
        ltext->private->line_spacing     = DEFAULT_TEXT_LINE_SPACING;
+       ltext->private->auto_shrink      = DEFAULT_AUTO_SHRINK;
 
        g_signal_connect (G_OBJECT(ltext->private->buffer), "changed",
                          G_CALLBACK(buffer_changed_cb), ltext);
@@ -256,6 +259,7 @@ copy (glLabelObject *dst_object,
        new_ltext->private->color            = ltext->private->color;
        new_ltext->private->just             = ltext->private->just;
        new_ltext->private->line_spacing     = ltext->private->line_spacing;
+       new_ltext->private->auto_shrink      = ltext->private->auto_shrink;
 
        gl_text_node_lines_free (&lines);
 
@@ -696,3 +700,37 @@ get_text_color (glLabelObject *object)
        return ltext->private->color;
 }
 
+/*****************************************************************************/
+/* Set auto shrink flag.                                                     */
+/*****************************************************************************/
+void
+gl_label_text_set_auto_shrink (glLabelText      *ltext,
+                              gboolean          auto_shrink)
+{
+       gl_debug (DEBUG_LABEL, "BEGIN");
+
+       g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext));
+
+       if (ltext->private->auto_shrink != auto_shrink) {
+
+               ltext->private->auto_shrink = auto_shrink;
+               gl_label_object_emit_changed (GL_LABEL_OBJECT(ltext));
+
+       }
+
+       gl_debug (DEBUG_LABEL, "END");
+}
+
+/*****************************************************************************/
+/* Query auto shrink flag.
+/*****************************************************************************/
+gboolean
+gl_label_text_get_auto_shrink (glLabelText      *ltext)
+{
+       gl_debug (DEBUG_LABEL, "");
+
+       g_return_val_if_fail (ltext && GL_IS_LABEL_TEXT (ltext), 0);
+
+       return ltext->private->auto_shrink;
+}
+
index 99c6072825e1cef27c5376bb6fbba4511124d868..abf6fdbae97b5a00db132deb12a8af4df977caa1 100644 (file)
@@ -66,6 +66,11 @@ void           gl_label_text_get_box      (glLabelText      *ltext,
                                           gdouble          *w,
                                           gdouble          *h);
 
+void           gl_label_text_set_auto_shrink (glLabelText      *ltext,
+                                             gboolean          auto_shrink);
+gboolean       gl_label_text_get_auto_shrink (glLabelText      *ltext);
+
+
 G_END_DECLS
 
 #endif /* __LABEL_TEXT_H__ */
index 2bc8c3e21888a27dcc0d19a671b20ca3f1ee699e..77d01bfaeeae771c534bd7e42ef82c661231bc35 100644 (file)
@@ -97,6 +97,7 @@ struct _glObjectEditorPrivate {
        GtkWidget  *text_center_toggle;
        GtkWidget  *text_right_toggle;
        GtkWidget  *text_line_spacing_spin;
+       GtkWidget  *text_auto_shrink_check;
 
        GtkWidget  *edit_page_vbox;
        GtkWidget  *edit_text_view;
index f22b1cd64e8c9e4a4b24afa6d7fd8431af5eadd5..db6428844e4c32c1bbe1aecfaacc0f40b53828c5 100644 (file)
@@ -88,6 +88,8 @@ gl_object_editor_prepare_text_page (glObjectEditor       *editor)
                glade_xml_get_widget (editor->priv->gui, "text_right_toggle");
        editor->priv->text_line_spacing_spin =
                glade_xml_get_widget (editor->priv->gui, "text_line_spacing_spin");
+       editor->priv->text_auto_shrink_check =
+               glade_xml_get_widget (editor->priv->gui, "text_auto_shrink_check");
 
        /* Load family names */
        family_names = gnome_font_family_list ();
@@ -153,6 +155,11 @@ gl_object_editor_prepare_text_page (glObjectEditor       *editor)
                                  G_CALLBACK (gl_object_editor_changed_cb),
                                  G_OBJECT (editor));
 
+       g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
+                                 "toggled",
+                                 G_CALLBACK (gl_object_editor_changed_cb),
+                                 G_OBJECT (editor));
+
        gl_debug (DEBUG_EDITOR, "END");
 }
 
@@ -546,3 +553,43 @@ gl_object_editor_get_text_line_spacing (glObjectEditor      *editor)
        return text_line_spacing;
 }
 
+/*****************************************************************************/
+/* Set auto shrink checkbox.                                                 */
+/*****************************************************************************/
+void
+gl_object_editor_set_text_auto_shrink (glObjectEditor      *editor,
+                                      gboolean             auto_shrink)
+{
+       gl_debug (DEBUG_EDITOR, "START");
+
+       g_signal_handlers_block_by_func (G_OBJECT(editor->priv->text_auto_shrink_check),
+                                        gl_object_editor_changed_cb,
+                                        editor);
+
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
+                                      auto_shrink);
+
+       g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->text_auto_shrink_check),
+                                          gl_object_editor_changed_cb,
+                                          editor);
+
+       gl_debug (DEBUG_EDITOR, "END");
+}
+
+/*****************************************************************************/
+/* Query auto shrink checkbox.                                               */
+/*****************************************************************************/
+gboolean    gl_object_editor_get_text_auto_shrink (glObjectEditor      *editor)
+{
+       gboolean auto_shrink;
+
+       gl_debug (DEBUG_EDITOR, "START");
+
+       auto_shrink = 
+               gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
+
+       gl_debug (DEBUG_EDITOR, "END");
+
+       return auto_shrink;
+}
+
index 27412729c7747a74b7989472bc86c23b1d8d9dda..0de6051ae50eb080dc45b0cdec3512071f473810 100644 (file)
@@ -377,6 +377,11 @@ gl_object_editor_set_key_names (glObjectEditor      *editor,
                gtk_widget_set_sensitive (editor->priv->edit_key_combo, merge != NULL);
        }
  
+       if (editor->priv->text_auto_shrink_check) {
+               gtk_widget_set_sensitive (editor->priv->text_auto_shrink_check,
+                                         merge != NULL);
+       }
        if (editor->priv->edit_insert_field_button) {
                gtk_widget_set_sensitive (editor->priv->edit_insert_field_button,
                                          merge != NULL);
index c85236c1852db6100a4c218998f8343fee394450..f9e019d7a2b63790d079e7c9f31bc1d83702bc98 100644 (file)
                  <child>
                    <widget class="GtkTable" id="table1">
                      <property name="visible">True</property>
-                     <property name="n_rows">6</property>
+                     <property name="n_rows">7</property>
                      <property name="n_columns">2</property>
                      <property name="homogeneous">False</property>
                      <property name="row_spacing">12</property>
                          <property name="y_options">fill</property>
                        </packing>
                      </child>
+
+                     <child>
+                       <widget class="GtkCheckButton" id="text_auto_shrink_check">
+                         <property name="visible">True</property>
+                         <property name="can_focus">True</property>
+                         <property name="label" translatable="yes">Allow merge to automatically shrink text</property>
+                         <property name="use_underline">True</property>
+                         <property name="relief">GTK_RELIEF_NORMAL</property>
+                         <property name="active">False</property>
+                         <property name="inconsistent">False</property>
+                         <property name="draw_indicator">True</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">0</property>
+                         <property name="right_attach">2</property>
+                         <property name="top_attach">6</property>
+                         <property name="bottom_attach">7</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
                    </widget>
                    <packing>
                      <property name="padding">0</property>
index ff47e423dde6b07e528250315d527f85faf7daec..f450c1556df47412af6584c7000231906e12700f 100644 (file)
@@ -210,6 +210,11 @@ void        gl_object_editor_set_text_color       (glObjectEditor      *editor,
 
 guint       gl_object_editor_get_text_color       (glObjectEditor      *editor);
 
+void        gl_object_editor_set_text_auto_shrink (glObjectEditor      *editor,
+                                                  gboolean             auto_shrink);
+
+gboolean    gl_object_editor_get_text_auto_shrink (glObjectEditor      *editor);
+
 
 /*
  * Edit Text Page
index 73bf40349c98a00dda53cbb06b40e981ae3b8357..83b9971178feb460504a0d73434cfb829d70b617 100644 (file)
@@ -721,22 +721,23 @@ draw_text_object (PrintInfo     *pi,
                  glLabelText   *object,
                  glMergeRecord *record)
 {
-       GnomeFont *font;
-       gchar **line;
-       gint i;
-       gdouble x_offset, y_offset, w, object_w, object_h;
-       gchar *text;
-       GList *lines;
-       gchar *font_family;
-       gdouble font_size;
-       GnomeFontWeight font_weight;
-       gboolean font_italic_flag;
-       guint color;
+       GnomeFont       *font;
+       gchar          **line;
+       gint             i;
+       gdouble          x_offset, y_offset, w, object_w, object_h;
+       gchar           *text;
+       GList           *lines;
+       gchar           *font_family;
+       gdouble          font_size;
+       GnomeFontWeight  font_weight;
+       gboolean         font_italic_flag;
+       guint            color;
        GtkJustification just;
-       GnomeGlyphList *glyphlist;
-       ArtDRect bbox;
-       gdouble affine[6];
-       gdouble text_line_spacing;
+       gboolean         auto_shrink;
+       GnomeGlyphList  *glyphlist;
+       ArtDRect         bbox;
+       gdouble          affine[6];
+       gdouble          text_line_spacing;
 
 
        gl_debug (DEBUG_PRINT, "START");
@@ -749,7 +750,53 @@ draw_text_object (PrintInfo     *pi,
        font_italic_flag = gl_label_object_get_font_italic_flag (GL_LABEL_OBJECT(object));
        color = gl_label_object_get_text_color (GL_LABEL_OBJECT(object));
        just = gl_label_object_get_text_alignment (GL_LABEL_OBJECT(object));
-       text_line_spacing = gl_label_object_get_text_line_spacing (GL_LABEL_OBJECT(object));
+       text_line_spacing =
+               gl_label_object_get_text_line_spacing (GL_LABEL_OBJECT(object));
+       auto_shrink = gl_label_text_get_auto_shrink (object);
+
+       text = gl_text_node_lines_expand (lines, record);
+       line = g_strsplit (text, "\n", -1);
+       g_free (text);
+
+       art_affine_identity (affine);
+
+       if (record && auto_shrink) {
+               /* auto shrink text size to keep within text box limits. */
+               for (i = 0; line[i] != NULL; i++) {
+
+                       font = gnome_font_find_closest_from_weight_slant (font_family,
+                                                                         font_weight,
+                                                                         font_italic_flag,
+                                                                         font_size);
+                       glyphlist = gnome_glyphlist_from_text_dumb (font,
+                                                                   color,
+                                                                   0.0, 0.0,
+                                                                   line[i]);
+                       gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
+                       w = bbox.x1;
+
+                       /* If width is too large, iteratively shrink font_size until this
+                          line fits the width, or until the font size is ridiculously
+                          small. */
+                       while ( (w > object_w) && (font_size >= 1.0) ) {
+
+                               font_size -= 0.5;
+
+                               font = gnome_font_find_closest_from_weight_slant (
+                                       font_family,
+                                       font_weight,
+                                       font_italic_flag,
+                                       font_size);
+                               glyphlist = gnome_glyphlist_from_text_dumb (font,
+                                                                           color,
+                                                                           0.0, 0.0,
+                                                                           line[i]);
+                               gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
+                               w = bbox.x1;
+                       }
+               }
+
+       }
 
        font = gnome_font_find_closest_from_weight_slant (
                                        font_family,
@@ -764,12 +811,6 @@ draw_text_object (PrintInfo     *pi,
                                 GL_COLOR_F_BLUE (color));
        gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (color));
 
-       text = gl_text_node_lines_expand (lines, record);
-       line = g_strsplit (text, "\n", -1);
-       g_free (text);
-
-       art_affine_identity (affine);
-
        for (i = 0; line[i] != NULL; i++) {
 
                glyphlist = gnome_glyphlist_from_text_dumb (font, color,
index a4e492577871663fc42350df66502ea5012e1e24..f129033eb20e9d402fbcc77aa982e23cc7a86c48 100644 (file)
@@ -312,6 +312,7 @@ update_object_from_editor_cb (glObjectEditor *editor,
        guint              color;
        GtkJustification   just;
        gdouble            text_line_spacing;
+       gboolean           auto_shrink;
 
        gl_debug (DEBUG_VIEW, "START");
 
@@ -330,6 +331,7 @@ update_object_from_editor_cb (glObjectEditor *editor,
        color = gl_object_editor_get_text_color (editor);
        just = gl_object_editor_get_text_alignment (editor);
        text_line_spacing = (gdouble) gl_object_editor_get_text_line_spacing (editor);
+       auto_shrink = gl_object_editor_get_text_auto_shrink (editor);
 
        gl_label_object_set_position (object, x, y);
        gl_label_object_set_font_family (object, font_family);
@@ -339,6 +341,7 @@ update_object_from_editor_cb (glObjectEditor *editor,
        gl_label_object_set_text_color (object, color);
        gl_label_object_set_text_alignment (object, just);
        gl_label_object_set_text_line_spacing (object, text_line_spacing);
+       gl_label_text_set_auto_shrink (GL_LABEL_TEXT (object), auto_shrink);
 
        g_free (font_family);
 
@@ -399,6 +402,7 @@ update_editor_from_object_cb (glLabelObject  *object,
        guint              color;
        GtkJustification   just;
        gdouble            text_line_spacing;
+       gboolean           auto_shrink;
 
        gl_debug (DEBUG_VIEW, "START");
 
@@ -412,6 +416,7 @@ update_editor_from_object_cb (glLabelObject  *object,
        color            = gl_label_object_get_text_color (object);
        just             = gl_label_object_get_text_alignment (object);
        text_line_spacing = gl_label_object_get_text_line_spacing (object);
+       auto_shrink      = gl_label_text_get_auto_shrink (GL_LABEL_TEXT (object));
 
        gl_object_editor_set_font_family (editor, font_family);
        gl_object_editor_set_font_size (editor, font_size);
@@ -420,6 +425,7 @@ update_editor_from_object_cb (glLabelObject  *object,
        gl_object_editor_set_text_color (editor, color);
        gl_object_editor_set_text_alignment (editor, just);
        gl_object_editor_set_text_line_spacing (editor, text_line_spacing);
+       gl_object_editor_set_text_auto_shrink (editor, auto_shrink);
 
        g_free (font_family);
 
index 067fe41ee30caf2a0cb664283ad50754fce1ef29..e18a4295d1d2fb11a9001d4541449cb28cfb10a7 100644 (file)
@@ -411,6 +411,7 @@ xml_parse_object_text (xmlNodePtr  node,
        gdouble           w, h;
        gchar            *string;
        GtkJustification  just;
+       gboolean          auto_shrink;
        gdouble           affine[6];
        xmlNodePtr        child;
 
@@ -434,6 +435,10 @@ xml_parse_object_text (xmlNodePtr  node,
        g_free (string);
        gl_label_object_set_text_alignment (GL_LABEL_OBJECT(object), just);
 
+       /* auto_shrink attr */
+       auto_shrink = gl_xml_get_prop_boolean (node, "auto_shrink", FALSE);
+       gl_label_text_set_auto_shrink (GL_LABEL_TEXT(object), auto_shrink);
+
        /* affine attrs */
        affine[0] = gl_xml_get_prop_double (node, "a0", 0.0);
        affine[1] = gl_xml_get_prop_double (node, "a1", 0.0);
@@ -1099,6 +1104,7 @@ xml_create_object_text (xmlNodePtr     root,
        gdouble           x, y;
        gdouble           w, h;
        GtkJustification  just;
+       gboolean          auto_shrink;
        gdouble           affine[6];
 
        gl_debug (DEBUG_XML, "START");
@@ -1119,6 +1125,10 @@ xml_create_object_text (xmlNodePtr     root,
        just = gl_label_object_get_text_alignment (object);
        xmlSetProp (node, "justify", gl_util_just_to_string (just));
 
+       /* auto_shrink attr */
+       auto_shrink = gl_label_text_get_auto_shrink (GL_LABEL_TEXT (object));
+       gl_xml_set_prop_boolean (node, "auto_shrink", auto_shrink);
+
        /* affine attrs */
        gl_label_object_get_affine (object, affine);
        gl_xml_set_prop_double (node, "a0", affine[0]);