コード例 #1
0
ファイル: sp-ctrlline.cpp プロジェクト: loveq369/DoonSketch
static void
sp_ctrlline_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
{
    SPCtrlLine *cl = SP_CTRLLINE (item);

    item->canvas->request_redraw ((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);

    if (parent_class->update)
        (* parent_class->update) (item, affine, flags);

    sp_canvas_item_reset_bounds (item);

    cl->affine = affine;

    if (cl->s == cl->e) {
        item->x1 = item->x2 = item->y1 = item->y2 = 0;
    } else {

        Geom::Point s = cl->s * affine;
        Geom::Point e = cl->e * affine;

        item->x1 = round(MIN(s[Geom::X], e[Geom::X]) - 1);
        item->y1 = round(MIN(s[Geom::Y], e[Geom::Y]) - 1);
        item->x2 = round(MAX(s[Geom::X], e[Geom::X]) + 1);
        item->y2 = round(MAX(s[Geom::Y], e[Geom::Y]) + 1);

        item->canvas->request_redraw ((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);

    }
}
コード例 #2
0
ファイル: sp-ctrlquadr.cpp プロジェクト: AakashDabas/inkscape
static void sp_ctrlquadr_update(SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags)
{
    SPCtrlQuadr *cq = SP_CTRLQUADR(item);

    item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);

    if (SP_CANVAS_ITEM_CLASS(sp_ctrlquadr_parent_class)->update) {
        SP_CANVAS_ITEM_CLASS(sp_ctrlquadr_parent_class)->update(item, affine, flags);
    }

    sp_canvas_item_reset_bounds (item);

    cq->affine = affine;

    Geom::Point p1(cq->p1 * affine);
    Geom::Point p2(cq->p2 * affine);
    Geom::Point p3(cq->p3 * affine);
    Geom::Point p4(cq->p4 * affine);
        
    item->x1 = (int)(MIN4(p1[Geom::X], p2[Geom::X], p3[Geom::X], p4[Geom::X]));
    item->y1 = (int)(MIN4(p1[Geom::Y], p2[Geom::Y], p3[Geom::Y], p4[Geom::Y]));
    item->x2 = (int)(MAX4(p1[Geom::X], p2[Geom::X], p3[Geom::X], p4[Geom::X]));
    item->y2 = (int)(MAX4(p1[Geom::Y], p2[Geom::Y], p3[Geom::Y], p4[Geom::Y]));

    item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
}
コード例 #3
0
ファイル: canvas-bpath.cpp プロジェクト: AakashDabas/inkscape
static void sp_canvas_bpath_update(SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags)
{
    SPCanvasBPath *cbp = SP_CANVAS_BPATH(item);

    item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);

    if (reinterpret_cast<SPCanvasItemClass *>(sp_canvas_bpath_parent_class)->update) {
        reinterpret_cast<SPCanvasItemClass *>(sp_canvas_bpath_parent_class)->update(item, affine, flags);
    }

    sp_canvas_item_reset_bounds (item);

    if (!cbp->curve) return;

    cbp->affine = affine;

    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;
    }
    item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
}
コード例 #4
0
void CtrlRect::update(Geom::Matrix const &affine, unsigned int flags)
{
    if (((SPCanvasItemClass *) parent_class)->update) {
        ((SPCanvasItemClass *) parent_class)->update(this, affine, flags);
    }

    sp_canvas_item_reset_bounds(this);

    if (_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) {
        /* Request redraw old */
        if (!_has_fill) {
            /* Top */
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y0 - 1,
                                     _area.x1 + 1, _area.y0 + 1);
            /* Left */
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y0 - 1,
                                     _area.x0 + 1, _area.y1 + 1);
            /* Right */
            sp_canvas_request_redraw(canvas,
                                     _area.x1 - 1, _area.y0 - 1,
                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
            /* Bottom */
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y1 - 1,
                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
        } else {
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y0 - 1,
                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
        }
    }

    Geom::Rect bbox(_rect.min() * affine, _rect.max() * affine);

    _area.x0 = (int) floor(bbox.min()[Geom::X] + 0.5);
    _area.y0 = (int) floor(bbox.min()[Geom::Y] + 0.5);
    _area.x1 = (int) floor(bbox.max()[Geom::X] + 0.5);
    _area.y1 = (int) floor(bbox.max()[Geom::Y] + 0.5);

    _shadow_size = _shadow;

    if (_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) {
        /* Request redraw new */
        if (!_has_fill) {
            /* Top */
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y0 - 1,
                                     _area.x1 + 1, _area.y0 + 1);
            /* Left */
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y0 - 1,
                                     _area.x0 + 1, _area.y1 + 1);
            /* Right */
            sp_canvas_request_redraw(canvas,
                                     _area.x1 - 1, _area.y0 - 1,
                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
            /* Bottom */
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y1 - 1,
                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
        } else {
            sp_canvas_request_redraw(canvas,
                                     _area.x0 - 1, _area.y0 - 1,
                                     _area.x1 + _shadow_size + 1, _area.y1 + _shadow_size + 1);
        }

        x1 = _area.x0 - 1;
        y1 = _area.y0 - 1;
        x2 = _area.x1 + _shadow_size + 1;
        y2 = _area.y1 + _shadow_size + 1;
    }
}
static void
sp_canvastext_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags)
{
    SPCanvasText *cl = SP_CANVASTEXT (item);

    item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);

    if (SP_CANVAS_ITEM_CLASS(sp_canvastext_parent_class)->update)
        SP_CANVAS_ITEM_CLASS(sp_canvastext_parent_class)->update(item, affine, flags);

    sp_canvas_item_reset_bounds (item);

    cl->affine = affine;

    Geom::Point s = cl->s * affine;
    // 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)
    // 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
    cairo_surface_t *tmp_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
    cairo_t* tmp_buf = cairo_create(tmp_surface);

    cairo_set_font_size(tmp_buf, cl->fontsize);
    cairo_text_extents_t extents;
    cairo_text_extents(tmp_buf, cl->text, &extents);
    double border = cl->border;

    item->x1 = s[Geom::X] + extents.x_bearing - border;
    item->y1 = s[Geom::Y] + extents.y_bearing - border;
    item->x2 = item->x1 + extents.width + 2*border;
    item->y2 = item->y1 + extents.height + 2*border;

    /* FROM: http://lists.cairographics.org/archives/cairo-bugs/2009-March/003014.html
      - Glyph surfaces: In most font rendering systems, glyph surfaces
        have an origin at (0,0) and a bounding box that is typically
        represented as (x_bearing,y_bearing,width,height).  Depending on
        which way y progresses in the system, y_bearing may typically be
        negative (for systems similar to cairo, with origin at top left),
        or be positive (in systems like PDF with origin at bottom left).
        No matter which is the case, it is important to note that
        (x_bearing,y_bearing) is the coordinates of top-left of the glyph
        relative to the glyph origin.  That is, for example:

        Scaled-glyph space:

          (x_bearing,y_bearing) <-- negative numbers
             +----------------+
             |      .         |
             |      .         |
             |......(0,0) <---|-- glyph origin
             |                |
             |                |
             +----------------+
                      (width+x_bearing,height+y_bearing)

        Note the similarity of the origin to the device space.  That is
        exactly how we use the device_offset to represent scaled glyphs:
        to use the device-space origin as the glyph origin.
    */

    // adjust update region according to anchor shift


    switch (cl->anchor_position) {
    case TEXT_ANCHOR_LEFT:
        cl->anchor_offset_x = 0;
        cl->anchor_offset_y = -extents.height/2;
        break;
    case TEXT_ANCHOR_RIGHT:
        cl->anchor_offset_x = extents.width;
        cl->anchor_offset_y = -extents.height/2;
        break;
    case TEXT_ANCHOR_BOTTOM:
        cl->anchor_offset_x = extents.width/2;
        cl->anchor_offset_y = 0;
        break;
    case TEXT_ANCHOR_TOP:
        cl->anchor_offset_x = extents.width/2;
        cl->anchor_offset_y = -extents.height;
        break;
    case TEXT_ANCHOR_ZERO:
        cl->anchor_offset_x = 0;
        cl->anchor_offset_y = 0;
        break;
    case TEXT_ANCHOR_MANUAL:
        cl->anchor_offset_x = (1 + cl->anchor_pos_x_manual) * extents.width/2;
        cl->anchor_offset_y = -(1 + cl->anchor_pos_y_manual) * extents.height/2;
        break;
    case TEXT_ANCHOR_CENTER:
    default:
        cl->anchor_offset_x = extents.width/2;
        cl->anchor_offset_y = -extents.height/2;
        break;
    }

    cl->anchor_offset_x += extents.x_bearing;
    cl->anchor_offset_y += extents.height + extents.y_bearing;

    item->x1 -= cl->anchor_offset_x;
    item->x2 -= cl->anchor_offset_x;
    item->y1 -= cl->anchor_offset_y;
    item->y2 -= cl->anchor_offset_y;

    item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
}