From 08f61b05720c3fbd5e44c8723a171f08495683d1 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 7 Jan 2003 07:05:55 +0000 Subject: [PATCH] Added text box support. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@242 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/label-object.c | 62 ++++++++++++++++++++++++++++++------- glabels2/src/label-text.c | 21 ++++++++++++- glabels2/src/label-text.h | 3 ++ glabels2/src/view-text.c | 2 +- glabels2/src/xml-label.c | 24 +++++++++++--- 5 files changed, 94 insertions(+), 18 deletions(-) diff --git a/glabels2/src/label-object.c b/glabels2/src/label-object.c index dd825e71..f7d529e6 100644 --- a/glabels2/src/label-object.c +++ b/glabels2/src/label-object.c @@ -70,6 +70,14 @@ static void gl_label_object_finalize (GObject *object); static void merge_changed_cb (glLabel *label, glLabelObject *object); +static void set_size (glLabelObject *object, + gdouble w, + gdouble h); + +static void get_size (glLabelObject *object, + gdouble *w, + gdouble *h); + /*****************************************************************************/ /* Boilerplate object stuff. */ @@ -102,17 +110,21 @@ gl_label_object_get_type (void) static void gl_label_object_class_init (glLabelObjectClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *gobject_class = (GObjectClass *) klass; + glLabelObjectClass *object_class = (glLabelObjectClass *) klass; gl_debug (DEBUG_LABEL, "START"); parent_class = g_type_class_peek_parent (klass); - object_class->finalize = gl_label_object_finalize; + gobject_class->finalize = gl_label_object_finalize; + + object_class->set_size = set_size; + object_class->get_size = get_size; signals[CHANGED] = g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (object_class), + G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (glLabelObjectClass, changed), NULL, NULL, @@ -122,7 +134,7 @@ gl_label_object_class_init (glLabelObjectClass *klass) signals[MOVED] = g_signal_new ("moved", - G_OBJECT_CLASS_TYPE (object_class), + G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (glLabelObjectClass, moved), NULL, NULL, @@ -131,7 +143,7 @@ gl_label_object_class_init (glLabelObjectClass *klass) 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE); signals[FLIP_ROTATE] = g_signal_new ("flip_rotate", - G_OBJECT_CLASS_TYPE (object_class), + G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (glLabelObjectClass, flip_rotate), NULL, NULL, @@ -140,7 +152,7 @@ gl_label_object_class_init (glLabelObjectClass *klass) 0); signals[TOP] = g_signal_new ("top", - G_OBJECT_CLASS_TYPE (object_class), + G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (glLabelObjectClass, top), NULL, NULL, @@ -150,7 +162,7 @@ gl_label_object_class_init (glLabelObjectClass *klass) signals[BOTTOM] = g_signal_new ("bottom", - G_OBJECT_CLASS_TYPE (object_class), + G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (glLabelObjectClass, bottom), NULL, NULL, @@ -415,6 +427,20 @@ gl_label_object_get_position (glLabelObject *object, gl_debug (DEBUG_LABEL, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Default set size method. */ +/*---------------------------------------------------------------------------*/ +static void +set_size (glLabelObject *object, + gdouble w, + gdouble h) +{ + g_return_if_fail (object && GL_IS_LABEL_OBJECT (object)); + + object->private->w = w; + object->private->h = h; +} + /*****************************************************************************/ /* Set size of object. */ /*****************************************************************************/ @@ -434,8 +460,8 @@ gl_label_object_set_size (glLabelObject *object, } else { - object->private->w = w; - object->private->h = h; + set_size (object, w, h); + } g_signal_emit (G_OBJECT(object), signals[CHANGED], 0); @@ -443,6 +469,20 @@ gl_label_object_set_size (glLabelObject *object, gl_debug (DEBUG_LABEL, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Default get size method. */ +/*---------------------------------------------------------------------------*/ +static void +get_size (glLabelObject *object, + gdouble *w, + gdouble *h) +{ + g_return_if_fail (object && GL_IS_LABEL_OBJECT (object)); + + *w = object->private->w; + *h = object->private->h; +} + /*****************************************************************************/ /* Get size of object. */ /*****************************************************************************/ @@ -462,8 +502,8 @@ gl_label_object_get_size (glLabelObject *object, } else { - *w = object->private->w; - *h = object->private->h; + get_size (object, w, h); + } gl_debug (DEBUG_LABEL, "END"); diff --git a/glabels2/src/label-text.c b/glabels2/src/label-text.c index 0be52cb3..d60c2295 100644 --- a/glabels2/src/label-text.c +++ b/glabels2/src/label-text.c @@ -60,7 +60,7 @@ struct _glLabelTextPrivate { /* Private globals. */ /*========================================================*/ -static GObjectClass *parent_class = NULL; +static glLabelObjectClass *parent_class = NULL; static guint instance = 0; @@ -332,6 +332,17 @@ gl_label_text_get_props (glLabelText *ltext, gl_debug (DEBUG_LABEL, "just = %d", *just); } +void +gl_label_text_get_box (glLabelText *ltext, + gdouble *w, + gdouble *h) +{ + g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext)); + + /* peek at the parent size. */ + (* parent_class->get_size) (GL_LABEL_OBJECT(ltext), w, h); +} + /*---------------------------------------------------------------------------*/ /* PRIVATE. text buffer "changed" callback. */ /*---------------------------------------------------------------------------*/ @@ -358,11 +369,14 @@ get_size (glLabelObject *object, GnomeGlyphList *glyphlist; ArtDRect bbox; gdouble affine[6]; + gdouble w_parent, h_parent; gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext)); + (* parent_class->get_size) (object, &w_parent, &h_parent); + font = gnome_font_find_closest_from_weight_slant ( ltext->private->font_family, ltext->private->font_weight, @@ -393,6 +407,11 @@ get_size (glLabelObject *object, } + if ( *h == 0.0 ) *h = ltext->private->font_size; + + if ( *w < w_parent ) *w = w_parent; + if ( *h < h_parent ) *h = h_parent; + g_strfreev (line); gl_debug (DEBUG_LABEL, "END"); diff --git a/glabels2/src/label-text.h b/glabels2/src/label-text.h index 2b5b36b5..f26acce9 100644 --- a/glabels2/src/label-text.h +++ b/glabels2/src/label-text.h @@ -75,6 +75,9 @@ void gl_label_text_get_props (glLabelText *ltext, gboolean *font_italic_flag, guint *color, GtkJustification *just); +void gl_label_text_get_box (glLabelText *ltext, + gdouble *w, + gdouble *h); G_END_DECLS diff --git a/glabels2/src/view-text.c b/glabels2/src/view-text.c index 58d04873..a9d17c1f 100644 --- a/glabels2/src/view-text.c +++ b/glabels2/src/view-text.c @@ -217,7 +217,7 @@ gl_view_text_new (glLabelText *object, gl_view_object_set_view (GL_VIEW_OBJECT(view_text), view); gl_view_object_set_object (GL_VIEW_OBJECT(view_text), GL_LABEL_OBJECT(object), - GL_VIEW_HIGHLIGHT_SIMPLE); + GL_VIEW_HIGHLIGHT_BOX_RESIZABLE); group = gl_view_object_get_group (GL_VIEW_OBJECT(view_text)); diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index e7cb46a0..5f1edce7 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -421,6 +421,7 @@ xml_parse_text_props (xmlNodePtr object_node, { GObject *object; GList *lines; + gdouble w, h; gchar *font_family; gdouble font_size; GnomeFontWeight font_weight; @@ -436,6 +437,9 @@ xml_parse_text_props (xmlNodePtr object_node, object = gl_label_text_new (label); + w = gl_xml_get_prop_double (object_node, "w", 0); + h = gl_xml_get_prop_double (object_node, "h", 0); + font_family = xmlGetProp (object_node, "font_family"); font_size = gl_xml_get_prop_double (object_node, "font_size", 0.0); @@ -490,11 +494,12 @@ xml_parse_text_props (xmlNodePtr object_node, } - gl_label_text_set_lines (GL_LABEL_TEXT(object), lines); - gl_label_text_set_props (GL_LABEL_TEXT(object), - font_family, font_size, font_weight, - font_italic_flag, - color, just); + gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); + gl_label_text_set_lines (GL_LABEL_TEXT(object), lines); + gl_label_text_set_props (GL_LABEL_TEXT(object), + font_family, font_size, font_weight, + font_italic_flag, + color, just); gl_text_node_lines_free (&lines); g_free (font_family); @@ -994,6 +999,7 @@ xml_create_text_props (xmlNodePtr object_node, { xmlNodePtr line_node, field_node, literal_node; GList *lines; + gdouble w, h; gchar *font_family; gdouble font_size; GnomeFontWeight font_weight; @@ -1008,12 +1014,20 @@ xml_create_text_props (xmlNodePtr object_node, xmlSetProp (object_node, "type", "Text"); + gl_label_text_get_box ( GL_LABEL_TEXT(object), &w, &h); lines = gl_label_text_get_lines (GL_LABEL_TEXT(object)); gl_label_text_get_props (GL_LABEL_TEXT(object), &font_family, &font_size, &font_weight, &font_italic_flag, &color, &just); + string = g_strdup_printf ("%g", w); + xmlSetProp (object_node, "w", string); + g_free (string); + string = g_strdup_printf ("%g", h); + xmlSetProp (object_node, "h", string); + g_free (string); + xmlSetProp (object_node, "font_family", font_family); string = g_strdup_printf ("%g", font_size); xmlSetProp (object_node, "font_size", string); -- 2.39.5