diff options
Diffstat (limited to 'src/model/textbox.c')
-rw-r--r-- | src/model/textbox.c | 186 |
1 files changed, 73 insertions, 113 deletions
diff --git a/src/model/textbox.c b/src/model/textbox.c index 8e7a46c..ba41b67 100644 --- a/src/model/textbox.c +++ b/src/model/textbox.c @@ -8,7 +8,7 @@ * Andres de Barbara <adebarbara@fi.uba.ar> * Marc Lorber <lorber.marc@wanadoo.fr> * - * Web page: https://github.com/marc-lorber/oregano + * Web page: https://ahoi.io/project/oregano * * Copyright (C) 1999-2001 Richard Hult * Copyright (C) 2003,2006 Ricardo Markiewicz @@ -26,8 +26,8 @@ * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ #include <math.h> @@ -46,34 +46,27 @@ static void textbox_class_init (TextboxClass *klass); static void textbox_init (Textbox *textbox); static void textbox_copy (ItemData *dest, ItemData *src); static ItemData *textbox_clone (ItemData *src); -static void textbox_rotate (ItemData *data, int angle, SheetPos *center); +static void textbox_rotate (ItemData *data, int angle, Coords *center); static void textbox_print (ItemData *data, cairo_t *cr, SchematicPrintContext *ctx); static int textbox_register (ItemData *data); static void textbox_unregister (ItemData *data); static gboolean textbox_has_properties (ItemData *data); -static void textbox_flip (ItemData *data, gboolean horizontal, - SheetPos *center); +static void textbox_flip (ItemData *data, IDFlip direction, Coords *center); +enum { TEXT_CHANGED, FONT_CHANGED, LAST_SIGNAL }; -enum { - TEXT_CHANGED, - FONT_CHANGED, - LAST_SIGNAL -}; - -struct _TextboxPriv { +struct _TextboxPriv +{ char *text; char *font; }; G_DEFINE_TYPE (Textbox, textbox, TYPE_ITEM_DATA) -static guint textbox_signals[LAST_SIGNAL] = { 0 }; - +static guint textbox_signals[LAST_SIGNAL] = {0}; -static void -textbox_finalize (GObject *object) +static void textbox_finalize (GObject *object) { Textbox *textbox = TEXTBOX (object); TextboxPriv *priv = textbox->priv; @@ -83,14 +76,12 @@ textbox_finalize (GObject *object) G_OBJECT_CLASS (textbox_parent_class)->finalize (object); } -static void -textbox_dispose (GObject *object) +static void textbox_dispose (GObject *object) { G_OBJECT_CLASS (textbox_parent_class)->dispose (object); } -static void -textbox_class_init (TextboxClass *klass) +static void textbox_class_init (TextboxClass *klass) { GObjectClass *object_class; ItemDataClass *item_data_class; @@ -100,26 +91,14 @@ textbox_class_init (TextboxClass *klass) object_class = G_OBJECT_CLASS (klass); textbox_signals[TEXT_CHANGED] = - g_signal_new ("text_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + g_signal_new ("text_changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, + NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); textbox_signals[FONT_CHANGED] = - g_signal_new ("font_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - - object_class->finalize= textbox_finalize; + g_signal_new ("font_changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, + NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); + + object_class->finalize = textbox_finalize; object_class->dispose = textbox_dispose; item_data_class->clone = textbox_clone; @@ -132,15 +111,13 @@ textbox_class_init (TextboxClass *klass) item_data_class->print = textbox_print; } -static void -textbox_init (Textbox *textbox) +static void textbox_init (Textbox *textbox) { TextboxPriv *priv = g_new0 (TextboxPriv, 1); textbox->priv = priv; } -Textbox * -textbox_new (char *font) +Textbox *textbox_new (char *font) { Textbox *textbox; @@ -154,8 +131,7 @@ textbox_new (char *font) return textbox; } -static ItemData * -textbox_clone (ItemData *src) +static ItemData *textbox_clone (ItemData *src) { Textbox *new_textbox; ItemDataClass *id_class; @@ -163,7 +139,7 @@ textbox_clone (ItemData *src) g_return_val_if_fail (src != NULL, NULL); g_return_val_if_fail (IS_TEXTBOX (src), NULL); - id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS(src)); + id_class = ITEM_DATA_CLASS (G_OBJECT_GET_CLASS (src)); if (id_class->copy == NULL) return NULL; @@ -173,8 +149,7 @@ textbox_clone (ItemData *src) return ITEM_DATA (new_textbox); } -static void -textbox_copy (ItemData *dest, ItemData *src) +static void textbox_copy (ItemData *dest, ItemData *src) { Textbox *dest_textbox, *src_textbox; @@ -193,14 +168,13 @@ textbox_copy (ItemData *dest, ItemData *src) dest_textbox->priv->font = src_textbox->priv->font; } -static void -textbox_rotate (ItemData *data, int angle, SheetPos *center) +static void textbox_rotate (ItemData *data, int angle, Coords *center) { cairo_matrix_t affine; double x, y; Textbox *textbox; - SheetPos b1, b2; - SheetPos textbox_center, delta; + Coords b1, b2; + Coords textbox_center, delta; g_return_if_fail (data != NULL); g_return_if_fail (IS_TEXTBOX (data)); @@ -216,13 +190,13 @@ textbox_rotate (ItemData *data, int angle, SheetPos *center) textbox_center.y = b1.y + (b2.y - b1.y) / 2; } - cairo_matrix_init_rotate (&affine, (double) angle * M_PI / 180); + cairo_matrix_init_rotate (&affine, (double)angle * M_PI / 180); // Let the views (canvas items) know about the rotation. g_signal_emit_by_name (G_OBJECT (textbox), "rotated", angle); if (center) { - SheetPos textbox_pos; + Coords textbox_pos; item_data_get_pos (ITEM_DATA (textbox), &textbox_pos); @@ -237,14 +211,13 @@ textbox_rotate (ItemData *data, int angle, SheetPos *center) } } -static void -textbox_flip (ItemData *data, gboolean horizontal, SheetPos *center) +static void textbox_flip (ItemData *data, IDFlip direction, Coords *center) { cairo_matrix_t affine; double x, y; Textbox *textbox; - SheetPos b1, b2; - SheetPos textbox_center = {0.0, 0.0}, delta; + Coords b1, b2; + Coords textbox_center = {0.0, 0.0}, delta; g_return_if_fail (data != NULL); g_return_if_fail (IS_TEXTBOX (data)); @@ -257,16 +230,16 @@ textbox_flip (ItemData *data, gboolean horizontal, SheetPos *center) textbox_center.y = b1.y + (b2.y - b1.y) / 2; } - if (horizontal) + if (direction == ID_FLIP_HORIZ) cairo_matrix_init_scale (&affine, -1, 1); else cairo_matrix_init_scale (&affine, 1, -1); // Let the views (canvas items) know about the rotation. - g_signal_emit_by_name (G_OBJECT (textbox), "flipped", horizontal); + g_signal_emit_by_name (G_OBJECT (textbox), "flipped", direction); if (center) { - SheetPos textbox_pos; + Coords textbox_pos; item_data_get_pos (ITEM_DATA (textbox), &textbox_pos); @@ -281,26 +254,20 @@ textbox_flip (ItemData *data, gboolean horizontal, SheetPos *center) } } -void -textbox_update_bbox (Textbox *textbox) +void textbox_update_bbox (Textbox *textbox) { - SheetPos b1, b2; + Coords b1, b2; b1.x = 0.0; - b1.y = 0.0-5; // - font->ascent; - b2.x = 0.0+5; // + rbearing; - b2.y = 0.0+5; // + font->descent; + b1.y = 0.0 - 5; // - font->ascent; + b2.x = 0.0 + 5; // + rbearing; + b2.y = 0.0 + 5; // + font->descent; item_data_set_relative_bbox (ITEM_DATA (textbox), &b1, &b2); } -static gboolean -textbox_has_properties (ItemData *data) -{ - return TRUE; -} +static gboolean textbox_has_properties (ItemData *data) { return TRUE; } -void -textbox_set_text (Textbox *textbox, const char *text) +void textbox_set_text (Textbox *textbox, const char *text) { g_return_if_fail (textbox != NULL); g_return_if_fail (IS_TEXTBOX (textbox)); @@ -312,8 +279,7 @@ textbox_set_text (Textbox *textbox, const char *text) g_signal_emit_by_name (G_OBJECT (textbox), "text_changed", text); } -char * -textbox_get_text (Textbox *textbox) +char *textbox_get_text (Textbox *textbox) { g_return_val_if_fail (textbox != NULL, NULL); g_return_val_if_fail (IS_TEXTBOX (textbox), NULL); @@ -321,8 +287,7 @@ textbox_get_text (Textbox *textbox) return textbox->priv->text; } -void -textbox_set_font (Textbox *textbox, char *font) +void textbox_set_font (Textbox *textbox, char *font) { g_return_if_fail (textbox != NULL); g_return_if_fail (IS_TEXTBOX (textbox)); @@ -335,12 +300,10 @@ textbox_set_font (Textbox *textbox, char *font) textbox_update_bbox (textbox); - g_signal_emit_by_name(G_OBJECT (textbox), - "font_changed", textbox->priv->font); + g_signal_emit_by_name (G_OBJECT (textbox), "font_changed", textbox->priv->font); } -char * -textbox_get_font (Textbox *textbox) +char *textbox_get_font (Textbox *textbox) { g_return_val_if_fail (textbox != NULL, NULL); g_return_val_if_fail (IS_TEXTBOX (textbox), NULL); @@ -348,38 +311,36 @@ textbox_get_font (Textbox *textbox) return textbox->priv->font; } -static void -textbox_print (ItemData *data, cairo_t *cr, SchematicPrintContext *ctx) +static void textbox_print (ItemData *data, cairo_t *cr, SchematicPrintContext *ctx) { -/* GnomeCanvasPoints *line; - double x0, y0; - ArtPoint dst, src; - double affine[6]; - int i; - Textbox *textbox; - TextboxPriv *priv; - SheetPos pos; - - g_return_if_fail (data != NULL); - g_return_if_fail (IS_TEXTBOX (data)); - - textbox = TEXTBOX (data); - priv = textbox->priv; - - item_data_get_pos (ITEM_DATA (textbox), &pos); - src.x = pos.x; - src.y = pos.y; - - art_affine_identity (affine); - - gnome_print_setfont (opc->ctx, - gnome_font_face_get_font_default (opc->label_font, 6)); - print_draw_text (opc->ctx, priv->text, &src); - */ + /* GnomeCanvasPoints *line; + double x0, y0; + ArtPoint dst, src; + double affine[6]; + int i; + Textbox *textbox; + TextboxPriv *priv; + Coords pos; + + g_return_if_fail (data != NULL); + g_return_if_fail (IS_TEXTBOX (data)); + + textbox = TEXTBOX (data); + priv = textbox->priv; + + item_data_get_pos (ITEM_DATA (textbox), &pos); + src.x = pos.x; + src.y = pos.y; + + art_affine_identity (affine); + + gnome_print_setfont (opc->ctx, + gnome_font_face_get_font_default (opc->label_font, 6)); + print_draw_text (opc->ctx, priv->text, &src); + */ } -static void -textbox_unregister (ItemData *data) +static void textbox_unregister (ItemData *data) { NodeStore *store; @@ -389,8 +350,7 @@ textbox_unregister (ItemData *data) node_store_remove_textbox (store, TEXTBOX (data)); } -static int -textbox_register (ItemData *data) +static int textbox_register (ItemData *data) { NodeStore *store; |