canvas-text.cpp revision 4d9e17d0548ca7858aa258ae757c2d3a278f8ae4
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Canvas text
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Lauris Kaplinski <lauris@kaplinski.com>
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Maximilian Albert <maximilian.albert@gmail.com>
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Jon A. Cruz <jon@joncruz.org>
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Copyright (C) 2000-2002 Lauris Kaplinski
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Copyright (C) 2008 Maximilian Albert
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Released under GNU GPL, read the file 'COPYING' for more information
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic void sp_canvastext_class_init (SPCanvasTextClass *klass);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic void sp_canvastext_init (SPCanvasText *canvastext);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic void sp_canvastext_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic void sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi type = g_type_register_static (SP_TYPE_CANVAS_ITEM, "SPCanvasText", &info, (GTypeFlags)0);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim GtkObjectClass *object_class = (GtkObjectClass *) klass;
13faa91230bde46da937bf33010b9accc5bdeb59sd SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi parent_class_ct = (SPCanvasItemClass*)g_type_class_peek_parent (klass);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim canvastext->s[Geom::X] = canvastext->s[Geom::Y] = 0.0;
14ea4bb737263733ad80a36b4f73f681c30a6b45sd canvastext->border = 3; // must be a constant, and not proportional to any width, height, or fontsize to allow alignment with other text boxes
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (* GTK_OBJECT_CLASS (parent_class_ct)->destroy) (object);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindisp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf)
aed5247ff899ec457005d93dfbdb4ffd74574695Joshua M. Clulow cairo_set_font_size(buf->ct, cl->fontsize);
44ed9dbbfa620821ecf59a131462082f628dd0f3Stephen Hanson cairo_text_extents(buf->ct, cl->text, &extents);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim cairo_rectangle(buf->ct, item->x1 - buf->rect.left(),
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim ink_cairo_set_source_rgba32(buf->ct, cl->rgba_background);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim double offsetx = s[Geom::X] - cl->anchor_offset_x - buf->rect.left();
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim double offsety = s[Geom::Y] - cl->anchor_offset_y - buf->rect.top();
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim cairo_move_to(buf->ct, round(offsetx), round(offsety));
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson ink_cairo_set_source_rgba32(buf->ct, cl->rgba_stroke);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson ink_cairo_set_source_rgba32(buf->ct, cl->rgba);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hansonsp_canvastext_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags)
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson (* parent_class_ct->update) (item, affine, flags);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi // Point s specifies the position of the anchor, which is at the bounding box of the text itself (i.e. not at the border of the filled background rectangle)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi // The relative position of the anchor can be set using e.g. anchor_position = TEXT_ANCHOR_LEFT
// Set up a temporary cairo_t to measure the text extents; it would be better to compute this in the render()
// method but update() seems to be called before so we don't have the information available when we need it
case TEXT_ANCHOR_LEFT:
case TEXT_ANCHOR_RIGHT:
case TEXT_ANCHOR_BOTTOM:
case TEXT_ANCHOR_TOP:
case TEXT_ANCHOR_ZERO:
case TEXT_ANCHOR_MANUAL:
case TEXT_ANCHOR_CENTER:
SPCanvasText *sp_canvastext_new(SPCanvasGroup *parent, SPDesktop *desktop, Geom::Point pos, gchar const *new_text)
// Pos specifies the position of the anchor, which is at the bounding box of the text itself (i.e. not at the border of the filled background rectangle)
return ct;