index 0daf6e69a2248216488022fe7388083ca7b94c6a..c47806615d1f98f7c13ab4407fd1eb637262f12a 100644 (file)
#include "display/display-forward.h"
#include "display/curve.h"
#include "display/inkscape-cairo.h"
-#include "libnr/nr-matrix-fns.h"
#include <libnr/nr-pixops.h>
-#include <libnr/nr-convert2geom.h>
-#include <libnr/nr-path.h>
#include "helper/geom.h"
-/*
- * FIXME: The following #includes and some other content in this file (see below) should actually
- * be in a separate file called display/canvas-text.cpp. It temporarily had to be moved here
- * because of linker errors.
- */
-
-/**
-#include "display-forward.h"
-#include "sp-canvas-util.h"
-#include "canvas-text.h"
-#include "display/inkscape-cairo.h"
-**/
#include <sstream>
#include <string.h>
#include <desktop.h>
#endif
#include <color.h>
-#include <libnr/nr-matrix-fns.h>
#include <libnr/nr-pixops.h>
**/
static void sp_canvas_bpath_init (SPCanvasBPath *path);
static void sp_canvas_bpath_destroy (GtkObject *object);
-static void sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
+static void sp_canvas_bpath_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
static void sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf);
-static double sp_canvas_bpath_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
+static double sp_canvas_bpath_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item);
static SPCanvasItemClass *parent_class;
}
static void
-sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
+sp_canvas_bpath_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
{
SPCanvasBPath *cbp = SP_CANVAS_BPATH (item);
@@ -144,13 +128,19 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
cbp->affine = affine;
- Geom::Rect bbox = bounds_exact_transformed(cbp->curve->get_pathvector(), affine);
-
- item->x1 = (int)bbox.min()[Geom::X] - 1;
- item->y1 = (int)bbox.min()[Geom::Y] - 1;
- item->x2 = (int)bbox.max()[Geom::X] + 1;
- item->y2 = (int)bbox.max()[Geom::Y] + 1;
-
+ Geom::OptRect bbox = bounds_exact_transformed(cbp->curve->get_pathvector(), affine);
+
+ if (bbox) {
+ item->x1 = (int)bbox->min()[Geom::X] - 1;
+ item->y1 = (int)bbox->min()[Geom::Y] - 1;
+ item->x2 = (int)bbox->max()[Geom::X] + 1;
+ item->y2 = (int)bbox->max()[Geom::Y] + 1;
+ } else {
+ item->x1 = 0;
+ item->y1 = 0;
+ item->x2 = 0;
+ item->y2 = 0;
+ }
sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
}
sp_canvas_prepare_buffer(buf);
- NR::Rect area (NR::Point(buf->rect.x0, buf->rect.y0), NR::Point(buf->rect.x1, buf->rect.y1));
+ Geom::Rect area (Geom::Point(buf->rect.x0, buf->rect.y0), Geom::Point(buf->rect.x1, buf->rect.y1));
if ( !cbp->curve ||
((cbp->stroke_rgba & 0xff) == 0 && (cbp->fill_rgba & 0xff) == 0 ) ||
}
static double
-sp_canvas_bpath_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item)
+sp_canvas_bpath_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item)
{
SPCanvasBPath *cbp = SP_CANVAS_BPATH (item);
@@ -215,7 +205,7 @@ sp_canvas_bpath_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_it
return NR_HUGE;
double width = 0.5;
- Geom::Rect viewbox = to_2geom(item->canvas->getViewbox());
+ Geom::Rect viewbox = item->canvas->getViewbox();
viewbox.expandBy (width);
double dist = NR_HUGE;
pathv_matrix_point_bbox_wind_distance(cbp->curve->get_pathvector(), cbp->affine, p, NULL, NULL, &dist, 0.5, &viewbox);
@@ -285,241 +275,6 @@ sp_canvas_bpath_set_stroke (SPCanvasBPath *cbp, guint32 rgba, gdouble width, SPS
sp_canvas_item_request_update (SP_CANVAS_ITEM (cbp));
}
-
-
-/*
- * FIXME: The following code should actually be in a separate file called
- * display/canvas-text.cpp. It temporarily had to be moved here because of linker errors.
- */
-
-static void sp_canvastext_class_init (SPCanvasTextClass *klass);
-static void sp_canvastext_init (SPCanvasText *canvastext);
-static void sp_canvastext_destroy (GtkObject *object);
-
-static void sp_canvastext_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
-static void sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf);
-
-static SPCanvasItemClass *parent_class_ct;
-
-GtkType
-sp_canvastext_get_type (void)
-{
- static GtkType type = 0;
-
- if (!type) {
- GtkTypeInfo info = {
- (gchar *)"SPCanvasText",
- sizeof (SPCanvasText),
- sizeof (SPCanvasTextClass),
- (GtkClassInitFunc) sp_canvastext_class_init,
- (GtkObjectInitFunc) sp_canvastext_init,
- NULL, NULL, NULL
- };
- type = gtk_type_unique (SP_TYPE_CANVAS_ITEM, &info);
- }
- return type;
-}
-
-static void
-sp_canvastext_class_init (SPCanvasTextClass *klass)
-{
- GtkObjectClass *object_class = (GtkObjectClass *) klass;
- SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass;
-
- parent_class_ct = (SPCanvasItemClass*)gtk_type_class (SP_TYPE_CANVAS_ITEM);
-
- object_class->destroy = sp_canvastext_destroy;
-
- item_class->update = sp_canvastext_update;
- item_class->render = sp_canvastext_render;
-}
-
-static void
-sp_canvastext_init (SPCanvasText *canvastext)
-{
- canvastext->rgba = 0x0000ff7f;
- canvastext->s[NR::X] = canvastext->s[NR::Y] = 0.0;
- canvastext->affine = NR::identity();
- canvastext->fontsize = 10.0;
- canvastext->item = NULL;
- canvastext->desktop = NULL;
- canvastext->text = NULL;
-}
-
-static void
-sp_canvastext_destroy (GtkObject *object)
-{
- g_return_if_fail (object != NULL);
- g_return_if_fail (SP_IS_CANVASTEXT (object));
-
- SPCanvasText *canvastext = SP_CANVASTEXT (object);
-
- canvastext->item=NULL;
-
- if (GTK_OBJECT_CLASS (parent_class_ct)->destroy)
- (* GTK_OBJECT_CLASS (parent_class_ct)->destroy) (object);
-}
-
-// FIXME: remove this as soon as we know how to correctly determine the text extent
-static const double arbitrary_factor = 0.7;
-
-// these are set in sp_canvastext_update() and then re-used in sp_canvastext_render(), which is called afterwards
-static double anchor_offset_x = 0;
-static double anchor_offset_y = 0;
-
-static void
-sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf)
-{
- SPCanvasText *cl = SP_CANVASTEXT (item);
-
- if (!buf->ct)
- return;
-
- guint32 rgba = cl->rgba;
- cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
-
- NR::Point s = cl->s * cl->affine;
- double offsetx = s[NR::X] - buf->rect.x0;
- double offsety = s[NR::Y] - buf->rect.y0;
- offsetx -= anchor_offset_x;
- offsety += anchor_offset_y;
-
- cairo_move_to(buf->ct, offsetx, offsety);
- cairo_set_font_size(buf->ct, cl->fontsize);
- cairo_show_text(buf->ct, cl->text);
- cairo_stroke(buf->ct);
-
- cairo_new_path(buf->ct);
-}
-
-static void
-sp_canvastext_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
-{
- SPCanvasText *cl = SP_CANVASTEXT (item);
-
- sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
-
- if (parent_class_ct->update)
- (* parent_class_ct->update) (item, affine, flags);
-
- sp_canvas_item_reset_bounds (item);
-
- cl->affine = affine;
-
- NR::Point s = cl->s * affine;
-
- // 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
- /**
- cairo_t tmp_buf;
- cairo_text_extents_t bbox;
- cairo_text_extents(&tmp_buf, cl->text, &bbox);
- **/
- item->x1 = s[NR::X] + 0;
- item->y1 = s[NR::Y] - cl->fontsize;
- item->x2 = s[NR::X] + cl->fontsize * strlen(cl->text);
- item->y2 = s[NR::Y] + cl->fontsize * 0.5; // for letters below the baseline
-
- // adjust update region according to anchor shift
- // FIXME: use the correct text extent
- anchor_offset_x = arbitrary_factor * cl->fontsize * strlen(cl->text) * (cl->anchor_x + 1.0) / 2.0;
- anchor_offset_y = cl->fontsize * (cl->anchor_y + 1.0) / 2.0;
- item->x1 -= anchor_offset_x;
- item->x2 -= anchor_offset_x;
- item->y1 += anchor_offset_y;
- item->y2 += anchor_offset_y;
-
- sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
-}
-
-SPCanvasItem *
-sp_canvastext_new(SPCanvasGroup *parent, SPDesktop *desktop, Geom::Point pos, gchar const *new_text)
-{
- SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_CANVASTEXT, NULL);
-
- SPCanvasText *ct = SP_CANVASTEXT(item);
-
- ct->desktop = desktop;
-
- ct->s = pos;
- g_free(ct->text);
- ct->text = g_strdup(new_text);
-
- // TODO: anything else to do?
-
- return item;
-}
-
-
-void
-sp_canvastext_set_rgba32 (SPCanvasText *ct, guint32 rgba)
-{
- g_return_if_fail (ct != NULL);
- g_return_if_fail (SP_IS_CANVASTEXT (ct));
-
- if (rgba != ct->rgba) {
- SPCanvasItem *item;
- ct->rgba = rgba;
- item = SP_CANVAS_ITEM (ct);
- sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
- }
- sp_canvas_item_request_update (SP_CANVAS_ITEM (ct));
-}
-
-#define EPSILON 1e-6
-#define DIFFER(a,b) (fabs ((a) - (b)) > EPSILON)
-
-void
-sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0)
-{
- sp_canvastext_set_coords(ct, NR::Point(x0, y0));
-}
-
-void
-sp_canvastext_set_coords (SPCanvasText *ct, const NR::Point start)
-{
- NR::Point pos = ct->desktop->doc2dt(start);
-
- g_return_if_fail (ct != NULL);
- g_return_if_fail (SP_IS_CANVASTEXT (ct));
-
- if (DIFFER (pos[0], ct->s[NR::X]) || DIFFER (pos[1], ct->s[NR::Y])) {
- ct->s[NR::X] = pos[0];
- ct->s[NR::Y] = pos[1];
- sp_canvas_item_request_update (SP_CANVAS_ITEM (ct));
- }
- sp_canvas_item_request_update (SP_CANVAS_ITEM (ct));
-}
-
-void
-sp_canvastext_set_text (SPCanvasText *ct, gchar const * new_text)
-{
- g_free (ct->text);
- ct->text = g_strdup(new_text);
- sp_canvas_item_request_update (SP_CANVAS_ITEM (ct));
-}
-
-void
-sp_canvastext_set_number_as_text (SPCanvasText *ct, int num)
-{
- std::ostringstream number;
- number << num;
- sp_canvastext_set_text(ct, number.str().c_str());
-}
-
-void
-sp_canvastext_set_fontsize (SPCanvasText *ct, double size)
-{
- ct->fontsize = size;
-}
-
-void
-sp_canvastext_set_anchor (SPCanvasText *ct, double anchor_x, double anchor_y)
-{
- ct->anchor_x = anchor_x;
- ct->anchor_y = anchor_y;
-}
-
/*
Local Variables:
mode:c++