File: //usr/share/inkscape/extensions/pixelsnap.pyo
�
��Yc @ s1 d Z d d l m Z d d l Z d d l m Z d d l Z d d l Z d d l Z y d d l Z Wn! e
k
r� e
d e � � n Xd Z d d Z
d e f d
� � YZ d � Z d � Z e d
� Z e e e d � Z d � Z d � Z d e j f d � � YZ e d k r-e � Z e j � n d S( s�
TODO: This only snaps selected elements, and if those elements are part of a
group or layer that has it's own transform, that won't be taken into
account, unless you snap the group or layer as a whole. This can account
for unexpected results in some cases (eg where you've got a non-integer
translation on the layer you're working in, the elements in that layer
won't snap properly). The workaround for now is to snap the whole
group/layer, or remove the transform on the group/layer.
I could fix it in the code by traversing the parent elements up to the
document root & calculating the cumulative parent_transform. This could
be done at the top of the pixel_snap method if parent_transform==None,
or before calling it for the first time.
TODO: Transforming points isn't quite perfect, to say the least. In particular,
when translating a point bezier curve, we translate the handles by the same amount.
BUT, some handles that are attached to a particular point are conceptually
handles of the prev/next node.
Best way to fix it would be to keep a list of the fractional_offsets[] of
each point, without transforming anything. Then go thru each point and
transform the appropriate handle according to the relevant fraction_offset
in the list.
i.e. calculate first, then modify.
In fact, that might be a simpler algorithm anyway -- it avoids having
to keep track of all the first_xy/next_xy guff.
TODO: make elem_offset return [x_offset, y_offset] so we can handle non-symetric scaling
------------
Note: This doesn't work very well on paths which have both straight segments
and curved segments.
The biggest three problems are:
a) we don't take handles into account (segments where the nodes are
aligned are always treated as straight segments, even where the
handles make it curve)
b) when we snap a straight segment right before/after a curve, it
doesn't make any attempt to keep the transition from the straight
segment to the curve smooth.
c) no attempt is made to keep equal widths equal. (or nearly-equal
widths nearly-equal). For example, font strokes.
I guess that amounts to the problyem that font hinting solves for fonts.
I wonder if I could find an automatic font-hinting algorithm and munge
it to my purposes?
Some good autohinting concepts that may help:
http://freetype.sourceforge.net/autohinting/archive/10Mar2000/hinter.html
Note: Paths that have curves & arcs on some sides of the bounding box won't
be snapped correctly on that side of the bounding box, and nor will they
be translated/resized correctly before the path is modified. Doesn't affect
most applications of this extension, but it highlights the fact that we
take a geometrically simplistic approach to inspecting & modifying the path.
i����( t divisionN( t matrixsX No module named inkex.
Please edit the file %s and see the section titled 'INKEX MODULE'i i i� t TransformErrorc B s e Z RS( ( t __name__t
__module__( ( ( s+ /usr/share/inkscape/extensions/pixelsnap.pyR W s c C sU t | t t f � s! | g } n x- | D]% } | j t j | d � k r( t Sq( Wt S( Nt svg( t
isinstancet listt tuplet tagt inkext addNSt Truet False( t elemt matchest m( ( s+ /usr/share/inkscape/extensions/pixelsnap.pyt elemtypeY s
c C s@ | } | d d d g g 7} t | � j j � } | j � | S( Ni i ( R t It tolistt pop( t transformt inverse( ( s+ /usr/share/inkscape/extensions/pixelsnap.pyt invert_transform_ s
c C s� | r t | � } n | d d | d | d d | d | d d } | d d | d | d d | d | d d } | | f S( s� Better than simpletransform.applyTransformToPoint,
a) coz it's a simpler name
b) coz it returns the new xy, rather than modifying the input
i i i ( R ( R t ptR t xt y( ( s+ /usr/share/inkscape/extensions/pixelsnap.pyt transform_pointf s
66c C s� | r t | � } n | d k r6 | | d d 9} n | d k rW | | d d 9} n | d k ry | d k ry | | f S| d k r� | S| d k r� | Sd S( s� Dimensions don't get translated. I'm not sure how much diff rotate/skew
makes in this context, but we currently ignore anything besides scale.
i i N( R t None( R t widtht heightR ( ( s+ /usr/share/inkscape/extensions/pixelsnap.pyt transform_dimensionsr s
c C sj t | d | d � } t | d | d � } | d k rL | d k rL t S| d k r\ t S| | t k S( Ni i ( t absR R
t MaxGradient( t pt1t pt2t hlent vlen( ( s+ /usr/share/inkscape/extensions/pixelsnap.pyt vertical� s c C s| t t | d | d � t � } t t | d | d � t � } | d k r^ | d k r^ t S| d k rn t S| | t k S( Ni i ( t roundR t PrecisionR R
R! ( R"