static double goc_polyline_distance (GocItem *item, double x, double y, GocItem **near_item) { GocPolyline *polyline = GOC_POLYLINE (item); GOStyle *style = go_style_dup (go_styled_object_get_style (GO_STYLED_OBJECT (item))); double tmp_width = 0; double res = 20; double ppu = goc_canvas_get_pixels_per_unit (item->canvas); cairo_surface_t *surface; cairo_t *cr; if (polyline->nb_points == 0) return res; *near_item = item; tmp_width = style->line.width; if (style->line.width * ppu < 5) style->line.width = 5. / (ppu * ppu); else style->line.width /= ppu; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); cr = cairo_create (surface); if (goc_polyline_prepare_draw (item, cr, 0)) { if (cairo_in_stroke (cr, x, y)) res = 0; } g_object_unref (style); cairo_destroy (cr); cairo_surface_destroy (surface); style->line.width = tmp_width; return res; }
/* Somewhat magic. * We do not honour all of the anchor flags. All that is used is the far corner. */ static void vcombo_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible) { GocGroup *view = GOC_GROUP (sov); if (visible) { double scale = goc_canvas_get_pixels_per_unit (GOC_ITEM (view)->canvas); double h = (coords[3] - coords[1]) + 1.; if (h > 20.) /* clip vertically */ h = 20.; h /= scale; goc_item_set (GOC_ITEM (view->children->data), /* put it outside the cell */ "x", ((coords[2] >= 0.)? coords[2] / scale: (coords[0] / scale - h + 1.)), "y", coords [3] / scale - h + 1., "width", h, /* force a square, use h for width too */ "height", h, NULL); goc_item_show (GOC_ITEM (view)); } else goc_item_hide (GOC_ITEM (view)); }
static void so_image_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible) { GocItem *view = GOC_ITEM (GOC_GROUP (sov)->children->data); double scale = goc_canvas_get_pixels_per_unit (view->canvas); if (visible) { double x, y, width, height; double old_x1, old_y1, old_x2, old_y2, old_width, old_height; GdkPixbuf *placeholder = g_object_get_data (G_OBJECT (view), "tile"); x = MIN (coords [0], coords [2]) / scale; y = MIN (coords [1], coords [3]) / scale; width = fabs (coords [2] - coords [0]) / scale; height = fabs (coords [3] - coords [1]) / scale; goc_item_get_bounds (view, &old_x1, &old_y1, &old_x2, &old_y2); goc_item_set (view, "x", x, "y", y, "width", width, "height", height, NULL); /* regenerate the image if necessary */ old_width = fabs (old_x1 - old_x2); old_height = fabs (old_y1 - old_y2); if (placeholder != NULL && (fabs (width - old_width) > 0.5 || fabs (height - old_height) > 0.5)) { GdkPixbuf *newimage = go_pixbuf_tile (placeholder, (guint)width, (guint)height); goc_item_set (view, "pixbuf", newimage, NULL); g_object_unref (newimage); } goc_item_show (view); } else goc_item_hide (view); }
static void so_path_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible) { GnmSOPathView *spv = (GnmSOPathView *) sov; if (visible) { SheetObject *so = sheet_object_view_get_so (sov); GnmSOPath const *sop = GNM_SO_PATH (so); GOPath *path; double scale, x_scale, y_scale, x, y; if ((sop->path == NULL && sop->paths == NULL) || sop->width <=0. || sop->height <=0.) return; scale = goc_canvas_get_pixels_per_unit (GOC_ITEM (sov)->canvas); x_scale = fabs (coords[2] - coords[0]) / sop->width / scale; y_scale = fabs (coords[3] - coords[1]) / sop->height / scale; x = MIN (coords[0], coords[2]) / scale - sop->x_offset * x_scale; y = MIN (coords[1], coords[3]) / scale - sop->y_offset * y_scale; if (sop->path != NULL) { path = go_path_scale (sop->path, x_scale, y_scale); goc_item_set (spv->path, "x", x, "y", y, "path", path, NULL); go_path_free (path); } else { unsigned i; for (i = 0; i < sop->paths->len; i++) { path = go_path_scale ((GOPath *) g_ptr_array_index (sop->paths, i), x_scale, y_scale); goc_item_set (GOC_ITEM (g_ptr_array_index (spv->paths, i)), "x", x, "y", y, "path", path, NULL); go_path_free (path); } } if (spv->text != NULL && GOC_ITEM (spv->text)) { double x0, y0, x1, y1; if (spv->path) goc_item_get_bounds (spv->path, &x0, &y0, &x1, &y1); else { unsigned i; double mx, my, Mx, My; x0 = y0 = G_MAXDOUBLE; x1 = y1 = -G_MAXDOUBLE; for (i = 0; i < spv->paths->len; i++) { goc_item_get_bounds (GOC_ITEM (g_ptr_array_index (spv->paths, i)), &mx, &my, &Mx, &My); if (mx < x0) x0 = mx; if (my < y0) y0 = my; if (Mx > x1) x1 = Mx; if (My > y1) y1 = My; } } x1 -= x0 + sop->margin_pts.left + sop->margin_pts.right; y1 -= y0 + sop->margin_pts.top + sop->margin_pts.bottom; x0 += x1 / 2. + sop->margin_pts.left; y0 += y1 / 2. + sop->margin_pts.top; x1 = MAX (x1, DBL_MIN); y1 = MAX (y1, DBL_MIN); goc_item_set (GOC_ITEM (spv->text), "x", x0, "y", y0, "clip-height", y1, "clip-width", x1, "wrap-width", x1, NULL); } } else goc_item_hide (GOC_ITEM (sov)); }