HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/share/inkscape/extensions/pixelsnap.pyo
�
��Yc@ s1dZddlmZddlZddlmZddlZddlZddlZyddl	Z	Wn!e
k
r�e
de��nXdZddZ
d	efd
��YZd�Zd�Zed
�Zeeed�Zd�Zd�Zde	jfd��YZedkr-e�Zej�ndS(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����(tdivisionN(tmatrixsXNo module named inkex.
Please edit the file %s and see the section titled 'INKEX MODULE'iii�tTransformErrorcB seZRS((t__name__t
__module__(((s+/usr/share/inkscape/extensions/pixelsnap.pyRWscC sUt|ttf�s!|g}nx-|D]%}|jtj|d�kr(tSq(WtS(Ntsvg(t
isinstancetlistttuplettagtinkextaddNStTruetFalse(telemtmatchestm((s+/usr/share/inkscape/extensions/pixelsnap.pytelemtypeYs
cC s@|}|dddgg7}t|�jj�}|j�|S(Nii(RtIttolisttpop(t	transformtinverse((s+/usr/share/inkscape/extensions/pixelsnap.pytinvert_transform_s

cC s�|rt|�}n|dd|d|dd|d|dd}|dd|d|dd|d|dd}||fS(s� Better than simpletransform.applyTransformToPoint,
        a) coz it's a simpler name
        b) coz it returns the new xy, rather than modifying the input
    iii(R(RtptRtxty((s+/usr/share/inkscape/extensions/pixelsnap.pyttransform_pointfs
66cC s�|rt|�}n|dk	r6||dd9}n|dk	rW||dd9}n|dk	ry|dk	ry||fS|dk	r�|S|dk	r�|SdS(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.
    iiN(RtNone(RtwidththeightR((s+/usr/share/inkscape/extensions/pixelsnap.pyttransform_dimensionsrs
cC sjt|d|d�}t|d|d�}|dkrL|dkrLtS|dkr\tS||tkS(Nii(tabsRR
tMaxGradient(tpt1tpt2thlentvlen((s+/usr/share/inkscape/extensions/pixelsnap.pytvertical�scC s|tt|d|d�t�}tt|d|d�t�}|dkr^|dkr^tS|dkrntS||tkS(Nii(troundR t	PrecisionRR
R!(R"R#R$R%((s+/usr/share/inkscape/extensions/pixelsnap.pyt
horizontal�s!!tPixelSnapEffectcB s�eZdd�Zdd�Zdd�Zddd�Zd�Zd�Zdd�Z	dd�Z
dd�Zdd	�Zdd
�Z
dd�Zdd�Zdd
�Zd�ZRS(cC s�|j|�}|dkrdS|j|d|�}tt|dd�t|dd��dtkrztd��nt|d|�}|dS(s� Returns a value which is the amount the
            bounding-box is offset due to the stroke-width.
            Transform is taken into account.
        itparent_transformii
s'Selection contains non-symetric scalingRi(tstroke_widthRR R(RR(tselfRR+R,R((s+/usr/share/inkscape/extensions/pixelsnap.pytelem_offset�s7cC s�tj|jjdd��}|jdd�}|dkrEd}nd}|r�|dkr�|j|jdd�j��}n|r�t|�|d<tj|�|jd<n|SdS(s6 Return stroke-width in pixels, untransformed
        tstylettstroketnoneisstroke-widthN(	tsimplestylet
parseStyletattribtgetRtunittouutstriptstrtformatStyle(R-RtsetvalR/R1R,((s+/usr/share/inkscape/extensions/pixelsnap.pyR,�s	$cC s�|j|d|�}|j|�}|dkr4dStt|dd�t|dd��dtkrztd��n|r�t|d|�}t|�}t|d|dt�}|j||�ndS(NR+iii
s@Selection contains non-symetric scaling, can't snap stroke widthRR(RR,R R(RRR'R(R-RR+RR,((s+/usr/share/inkscape/extensions/pixelsnap.pytsnap_stroke�s7cC s�|jjdd�j�}|r3tj|�}n*dddgdddgdddgg}|rxtj||�}n|r�tj|�|jd<n|SdS(s� Gets this element's transform. Use setval=matrix to
            set this element's transform.
            You can only specify parent_transform when getting.
        RR0iiN(R5R6R8tsimpletransformtparseTransformtcomposeTransformtformatTransform(R-RR;R+R((s+/usr/share/inkscape/extensions/pixelsnap.pyR�s*cC s{|j|�}|dds+|ddr/dSt|dd�|dd<t|dd�|dd<|j||�dS(Niii(RR'(R-RR((s+/usr/share/inkscape/extensions/pixelsnap.pytsnap_transform�sc	C sZ||dj�}|dkr$dS|dkrdt|||dddg�d||dd<n�|dkr�t|d||ddg�d||dd<n�d}|dkr�d}nx�t|t||d�d	�D]r}||d|||d|d}}t|||f�\}}|||d|<|||d|d<q�WdS(
sR Modifies a segment so that every point is transformed, including handles
        itzNthitvtaii(tlowerRtrangetlen(	R-Rtpathtitsegtypetfirst_coordinatetjRR((s+/usr/share/inkscape/extensions/pixelsnap.pyttransform_path_node�s44	')cC s2||dj�}d}}|dkr3d}n|dkrs|r^|d||dd<q||dd}n�|dkr�|r�|d||dd<q||dd}ne|r�|dkr�|d||dd<|d||dd<n$||dd}||dd}|dkr.||gSdS(	s� Return the endpoint of the given path segment.
            Inspects the segment type to know which elements are the endpoints.
        iRBRCiRDi����i����N(RFR(R-RIRJR;RKRR((s+/usr/share/inkscape/extensions/pixelsnap.pytpathxy�s&
	cC sDdtjd}tj|jj||jd��}|j|d|�}|j||�}d}}}	}
x�tt	|��D]�}|j
||�\}}
t|||
f�\}}
|dkr�|}}	|
}}
q�t||�}t|
|�}t
||	�}	t
|
|
�}
q�W||||f|	||
|ffS(s Returns [min_x, min_y], [max_x, max_y] of the transformed
            element. (It doesn't make any sense to return the untransformed
            bounding box, with the intent of transforming it later, because
            the min/max points will be completely different points)
            
            The returned bounding box includes stroke-width offset.
            
            This function uses a simplistic algorithm & doesn't take curves
            or arcs into account, just node positions.
        s{%s}original-dtinkscapetdR+i(R
tNSSt
simplepatht	parsePathR5R6RR.RGRHRORtmintmax(R-RR+t
original_dRIRtoffsettmin_xtmin_ytmax_xtmax_yRJRR((s+/usr/share/inkscape/extensions/pixelsnap.pytpath_bounding_boxs 
%

cC s�dtjd}tj|jj||jd��}|j|d|�}|j||�\}}|d|d}|d|d}	|dks�|	dkr�dSt|�|t|	�|	f}
t	||dt
�}t	||dt
�}x�tt|��D]�}|j
dd|dgdd|dgg||�|j
|
dddgd|
ddgg||�|j
dd|d
gdd|d
gg||�qWtj|�}||jkr�||j|<n
||jd<dS(Ns{%s}original-dRPRQR+iiR(R
RRRSRTR5R6RR]R'RRRGRHRNt
formatPath(R-RR+RWRIRtmin_xytmax_xyRRtrescaleRJ((s+/usr/share/inkscape/extensions/pixelsnap.pytsnap_path_scale5s*% 5
9c
C sKdtjd}tj|jj||jd��}|j|d|�}|j||�\}}|dt|d�|dt|d�|j	f}t
||d|ddt�}xOtt
|��D];}	|jdd|dgdd|dgg||	�q�Wtj|�}||jkr:||j|<n
||jd<dS(Ns{%s}original-dRPRQR+iiR(R
RRRSRTR5R6RR]R'tdocument_offsetRRRGRHRNR^(
R-RR+RWRIRR_R`tfractional_offsetRJ((s+/usr/share/inkscape/extensions/pixelsnap.pyt
snap_path_posUs%7 cC s�dtjd}tj|jj||jd��}|j|d|�}|ddsg|ddrvtd��n|j||�d}|j	|d�}|j	|d�}x�t
t|��D]�}	||	dj�}
|j	||	�}|
d	kr|}n|	t|�dksJ|	t|�d
krS|ddj�d	krS|}n|j	||	d�}|ox|ox|s�|}q�nt
|�}
tt||��}t||�}t||�}t}}t||�rt|�d
ks�|	dkr|d|d<nt}nt||�r/t}nt||�rvt|�d
ks\|	dkrm|d|d<nt}nt||�r�t}nt
|
�}ddg}|r�|dt|d|�||d<n|r|dt|d|�||j|d<nt||d|ddt�}|jdd|dgdd|dgg||	�q�Wtj|�}||jkr�||j|<n
||jd<dS(Ns{%s}original-dRPRQR+iis5Selection contains transformations with skew/rotationi����RBiR(R
RRRSRTR5R6RRR.RORGRHRFRRRR
R)RR&R'RcRRNR^(R-RR+RWRIRRXtprev_xytfirst_xyRJRKtxytnext_xytxy_untransformedton_verticalt
on_horizontalRd((s+/usr/share/inkscape/extensions/pixelsnap.pyt	snap_pathisf%	0	
				'. c	C s�|j|d|�}|dds1|ddr@td��n|j||�d}|j|jd�}|j|jd�}|j|jd�}|j|jd�}t|||�\}}t|||g�\}}t|�}t|�}t||�|}t||�|}t|||d	t�\}}t|||gd	t�\}}||j	|dd7}t
|�|jd<t
|�|jd<t
|�|jd<t
|�|jd<dS(
NR+iis5Selection contains transformations with skew/rotationRRRRR(RRR.R7R5RRR'RRcR9(	R-RR+RRXRRRR((s+/usr/share/inkscape/extensions/pixelsnap.pyt	snap_rect�s*!cC s|j||�dS(N(Rn(R-RR+((s+/usr/share/inkscape/extensions/pixelsnap.pyt
snap_image�scC s^t|d�r}|j|�|j|d|�}xE|D]=}y|j||�Wq8tk
rt}tj|IJq8Xq8WdSt|d�s�dS|j|�y|j||�Wn tk
r�}tj|IJnXt|d�r|j||�|j	||�|j
||�nDt|d�r8|j||�n"t|d�rZ|j||�ndS(NtgR+RItrecttimage(spathRqRr(
RRARt
pixel_snapRtsyststderrR<RbReRmRnRo(R-RR+Rte((s+/usr/share/inkscape/extensions/pixelsnap.pyRs�s0


cC s�|jj�}|j|jd�d|_xQ|jj�D]@\}}y|j|�Wq<tk
r{}t	j
|IJq<Xq<WdS(NRi(tdocumenttgetrootR7R5Rctselectedt	iteritemsRsRRtRu(R-RtidRRv((s+/usr/share/inkscape/extensions/pixelsnap.pyteffect�sN(RRRR.R,R<RRARNROR]RbReRmRnRoRsR|(((s+/usr/share/inkscape/extensions/pixelsnap.pyR*�s	
	$ E!t__main__(t__doc__t
__future__RRttnumpyRR3R=RSR
tImportErrort__file__R(R!t	ExceptionRRRR
RRRR&R)tEffectR*RR|taffect(((s+/usr/share/inkscape/extensions/pixelsnap.pyt<module>;s,$


						�h