+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:
%position_attrs;
%size_attrs;
justify %JUSTIFY_TYPE; #REQUIRED
+ auto_shrink %BOOLEAN_TYPE; #IMPLIED
%affine_attrs;
%shadow_attrs;
>
/* 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. */
GtkJustification just;
guint color;
gdouble line_spacing;
+ gboolean auto_shrink;
};
/*========================================================*/
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);
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);
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;
+}
+
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__ */
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;
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 ();
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");
}
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;
+}
+
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);
<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>
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
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");
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,
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,
guint color;
GtkJustification just;
gdouble text_line_spacing;
+ gboolean auto_shrink;
gl_debug (DEBUG_VIEW, "START");
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);
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);
guint color;
GtkJustification just;
gdouble text_line_spacing;
+ gboolean auto_shrink;
gl_debug (DEBUG_VIEW, "START");
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);
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);
gdouble w, h;
gchar *string;
GtkJustification just;
+ gboolean auto_shrink;
gdouble affine[6];
xmlNodePtr child;
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);
gdouble x, y;
gdouble w, h;
GtkJustification just;
+ gboolean auto_shrink;
gdouble affine[6];
gl_debug (DEBUG_XML, "START");
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]);