Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-offset.cpp File Reference

Implementation of <path sodipodi:type="inkscape:offset">. More...

Go to the source code of this file.

Functions

static void refresh_offset_source (SPOffset *offset)
 
static void sp_offset_quit_listening (SPOffset *offset)
 
static void sp_offset_href_changed (SPObject *old_ref, SPObject *ref, SPOffset *offset)
 
static void sp_offset_move_compensate (Geom::Affine const *mp, SPItem *original, SPOffset *self)
 
static void sp_offset_delete_self (SPObject *deleted, SPOffset *self)
 
static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *item)
 
static bool vectors_are_clockwise (Geom::Point A, Geom::Point B, Geom::Point C)
 
double sp_offset_distance_to_original (SPOffset *offset, Geom::Point px)
 Distance to the original path; that function is called from shape-editor-knotholders to set the radius when the control knot moves.
 
void sp_offset_top_point (SPOffset const *offset, Geom::Point *px)
 Computes a point on the offset; used to set a "seed" position for the control knot.
 
static void sp_offset_start_listening (SPOffset *offset, SPItem *to)
 
SPItemsp_offset_get_source (SPOffset *offset)
 

Variables

static bool use_slow_but_correct_offset_method = false
 

Detailed Description

Implementation of <path sodipodi:type="inkscape:offset">.

Definition in file sp-offset.cpp.

Function Documentation

◆ refresh_offset_source()

static void refresh_offset_source ( SPOffset offset)
static
Note
SPOffset is a derivative of SPShape, much like the SPSpiral or SPRect. The goal is to have a source shape (= originalPath), an offset (= radius) and compute the offset of the source by the radius. To get it to work, one needs to know what the source is and what the radius is, and how it's stored in the xml representation. The object itself is a "path" element, to get lots of shape functionality for free. The source is the easy part: it's stored in a "inkscape:original" attribute in the path. In case of "linked" offset, as they've been dubbed, there is an additional "inkscape:href" that contains the id of an element of the svg. When built, the object will attach a listener vector to that object and rebuild the "inkscape:original" whenever the href'd object changes. This is of course grossly inefficient, and also does not react to changes to the href'd during context stuff (like changing the shape of a star by dragging control points) unless the path of that object is changed during the context (seems to be the case for SPEllipse). The computation of the offset is done in sp_offset_set_shape(), a function that is called whenever a change occurs to the offset (change of source or change of radius). just like the sp-star and other, this path derivative can make control points, or more precisely one control point, that's enough to define the radius (look in shape-editor-knotholders).

Definition at line 1061 of file sp-offset.cpp.

References Inkscape::XML::Node::attribute(), Shape::ConvertToForme(), Shape::ConvertToShape(), css, fill_nonZero, fill_oddEven, SPObject::getRepr(), Geom::Affine::isIdentity(), item, offset, orig, sp_repr_css_attr(), sp_repr_css_property(), sp_svg_transform_read(), Path::svg_dump_path(), and SPItem::transform.

Referenced by SPOffset::set(), and SPOffset::update().

◆ sp_offset_delete_self()

static void sp_offset_delete_self ( SPObject deleted,
SPOffset self 
)
static

◆ sp_offset_distance_to_original()

double sp_offset_distance_to_original ( SPOffset offset,
Geom::Point  px 
)

Distance to the original path; that function is called from shape-editor-knotholders to set the radius when the control knot moves.

The sign of the result is the radius we're going to offset the shape with, so result > 0 ==outset and result < 0 ==inset. thus result<0 means 'px inside source'.

Todo:
Awfully damn stupid method: uncross the source path EACH TIME you need to compute the distance. The good way to do this would be to store the uncrossed source path somewhere, and delete it when the context is finished. Hopefully this part is much faster than actually computing the offset (which happen just after), so the time spent in this function should end up being negligible with respect to the delay of one context.

Definition at line 736 of file sp-offset.cpp.

References Shape::ConvertToShape(), dot(), Shape::dg_arete::dx, Shape::dg_arete::en, fill_oddEven, FIRST, Shape::getEdge(), Shape::getPoint(), Shape::dg_point::incidentEdge, LAST, len, Shape::NextAt(), Shape::numberOfEdges(), Shape::numberOfPoints(), offset, Shape::dg_arete::st, Shape::dg_point::totalDegree(), vectors_are_clockwise(), and Shape::dg_point::x.

◆ sp_offset_get_source()

SPItem * sp_offset_get_source ( SPOffset offset)

◆ sp_offset_href_changed()

static void sp_offset_href_changed ( SPObject old_ref,
SPObject ref,
SPOffset offset 
)
static

Definition at line 974 of file sp-offset.cpp.

References offset, sp_offset_quit_listening(), and sp_offset_start_listening().

Referenced by SPOffset::SPOffset().

◆ sp_offset_move_compensate()

◆ sp_offset_quit_listening()

static void sp_offset_quit_listening ( SPOffset offset)
static

Definition at line 959 of file sp-offset.cpp.

References offset.

Referenced by SPOffset::release(), SPOffset::set(), sp_offset_delete_self(), and sp_offset_href_changed().

◆ sp_offset_source_modified()

static void sp_offset_source_modified ( SPObject iSource,
guint  flags,
SPItem item 
)
static

Definition at line 1050 of file sp-offset.cpp.

References item, and offset.

Referenced by sp_offset_start_listening().

◆ sp_offset_start_listening()

◆ sp_offset_top_point()

void sp_offset_top_point ( SPOffset const *  offset,
Geom::Point px 
)

Computes a point on the offset; used to set a "seed" position for the control knot.

Returns
the topmost point on the offset.

Definition at line 896 of file sp-offset.cpp.

References Path::Convert(), Path::Fill(), Shape::getPoint(), Shape::hasPoints(), Path::LoadPathVector(), offset, Shape::SortPoints(), and Shape::dg_point::x.

◆ vectors_are_clockwise()

static bool vectors_are_clockwise ( Geom::Point  A,
Geom::Point  B,
Geom::Point  C 
)
static
Todo:
FIXME: This can be done using linear operations, more stably and faster. method: transform A and C into B's space, A should be negative and B should be positive in the orthogonal component. I think this is equivalent to dot(A, rot90(B))*dot(C, rot90(B)) == -1. – njh

Definition at line 682 of file sp-offset.cpp.

References dot(), and Geom::rot90().

Referenced by sp_offset_distance_to_original().

Variable Documentation

◆ use_slow_but_correct_offset_method

bool use_slow_but_correct_offset_method = false
static

Definition at line 82 of file sp-offset.cpp.

Referenced by SPOffset::set_shape().