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/synfig_prepare.pyo
�
��Yc@s�dZddlZddlZddlZddlmZmZmZmZddlZddl	Z	ddl
Z
defd��YZy ddl
mZmZeZWn
eZnXdefd��YZd	efd
��YZd�Zd�Zid
ddgdd
dggd�Zdd�Zdejfd��YZedkr�ye�Zej�Wq�ek
r�Zee�q�XndS(s
synfig_prepare.py
Simplifies SVG files in preparation for sif export.

Copyright (C) 2011 Nikita Kitaev

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
i����N(tNSStaddNStetreeterrormsgtMalformedSVGErrorcBs eZdZd�Zd�ZRS(sHRaised when the SVG document is invalid or contains unsupported featurescCs
||_dS(N(tvalue(tselfR((s0/usr/share/inkscape/extensions/synfig_prepare.pyt__init__!scCsdt|j�S(NsSVG document is invalid or contains unsupported features

Error message: %s

The SVG to Synfig converter is designed to handle SVG files that were created using Inkscape. Unsupported features are most likely to occur in SVG files written by other programs.
(treprR(R((s0/usr/share/inkscape/extensions/synfig_prepare.pyt__str__#s(t__name__t
__module__t__doc__RR	(((s0/usr/share/inkscape/extensions/synfig_prepare.pyRs	(tPopentPIPEtInkscapeActionGroupcBs�eZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zed	�Z
d
�Zd�Zd�ZRS(s@A class for calling Inkscape to perform operations on a documentcCs1d|_d|_t|_t|_||_dS(Nt(tcommandt	init_argstFalset
has_selectiont
has_actiontsvg_document(RR((s0/usr/share/inkscape/extensions/synfig_prepare.pyR3s
				cCs
||_dS(s2Set the SVG document that Inkscape will operate onN(R(RR((s0/usr/share/inkscape/extensions/synfig_prepare.pytset_svg_document:scCs
||_dS(s�Set the initial arguments to Inkscape subprocess

        Can be used to pass additional arguments to Inkscape, or an initializer
        command (e.g. unlock all objects before proceeding).
        N(R(Rtcmd((s0/usr/share/inkscape/extensions/synfig_prepare.pyt
set_init_args>scCsd|_t|_t|_dS(sClear all actionsRN(RRRR(R((s0/usr/share/inkscape/extensions/synfig_prepare.pytclearFs		cCs8|jr4|jd|7_|js4t|_q4ndS(sVRun an Inkscape verb

        For a list of verbs, run `inkscape --verb-list`
        s
--verb=%s N(RRRtTrue(Rtverb((s0/usr/share/inkscape/extensions/synfig_prepare.pyRLs		cCs,|jd|7_|js(t|_ndS(sSelect object with given ids--select=%s N(RRR(Rt	object_id((s0/usr/share/inkscape/extensions/synfig_prepare.pyt	select_idWs	cCs;|jdd�}|dkr*td�n|j|�dS(soSelect the object represented by the SVG node

        Selection will fail if node has no id attribute
        tidsNode has no idN(tgettNoneRR(Rtnodetnode_id((s0/usr/share/inkscape/extensions/synfig_prepare.pytselect_node]scCs"x|D]}|j|�qWdS(smSelect objects represented by SVG nodes

        Selection will fail if any node has no id attribute
        N(R$(RtnodesR"((s0/usr/share/inkscape/extensions/synfig_prepare.pytselect_nodesgs
cCs)|jj|d|�}|j|�dS(sSelect objects matching a given XPath expression

        Selection will fail if any matching node has no id attribute
        t
namespacesN(RtxpathR&(RR(R'R%((s0/usr/share/inkscape/extensions/synfig_prepare.pytselect_xpathoscCs&|jr"|jd�t|_ndS(sDeselect all objectstEditDeselectN(RRR(R((s0/usr/share/inkscape/extensions/synfig_prepare.pytdeselectxs	
cCs�|js
dS|jd|jd}trttd||fdtdtdt�}|j�}|j}|j	}n"t
jd||f�\}}}|j�|j�dS(	s"Run the actions on a specific fileNt s--verb=FileSave --verb=FileQuitsinkscape "%s" %stshelltstdouttstderrsinkscape %s %s(
RRRtbsubprocessR
RRtwaitR.R/tostpopen3tclose(RtfilenameRtptrctfterrt_((s0/usr/share/inkscape/extensions/synfig_prepare.pytrun_file~s	(	"
cCs�|js|jStjd�}|jj|�|j|�t|d�}tj|�}|j	�yt
j|�Wntk
r�nX||_|S(s#Run the actions on the svg xml trees.svgtr(
RRttempfiletmktemptwriteR;topenRtparseR4R2tremovet	Exception(Rtsvgfiletstreamtnew_svg_doc((s0/usr/share/inkscape/extensions/synfig_prepare.pytrun_document�s	


	N(R
RRR!RRRRRRR$R&RR)R+R;RG(((s0/usr/share/inkscape/extensions/synfig_prepare.pyR1s						
				tSynfigExportActionGroupcBs,eZdZdd�Zd�Zd�ZRS(sAAn action group with stock commands designed for Synfig exportingcCs5tj||�|jd�|j�|j�dS(Ns--verb=UnlockAllInAllLayers(RRRtobjects_to_pathst
unlink_clones(RR((s0/usr/share/inkscape/extensions/synfig_prepare.pyR�s

cCs�|jddt�|jd�|j�dddddd	d
g}djg|D]}d|^qR�}|j|dt�|jd�|j�d
S(s$Convert unsupported objects to pathss//svg:flowRootR'tObjectToPathssvg:rects
svg:circlessvg:ellipsessvg:linessvg:polylinessvg:polygonssvg:texts | s//N(R)RRR+tjoin(Rt	non_pathstnpt	xpath_cmd((s0/usr/share/inkscape/extensions/synfig_prepare.pyRI�s

	&
cCs.|jddt�|jd�|j�dS(s)Unlink clones (remove <svg:use> elements)s	//svg:useR'tEditUnlinkCloneN(R)RRR+(R((s0/usr/share/inkscape/extensions/synfig_prepare.pyRJ�s
N(R
RRR!RRIRJ(((s0/usr/share/inkscape/extensions/synfig_prepare.pyRH�s	cCs�|jdd�}tj|�}t|�dkr7dSd}||dd||ddg}g}x|t|�kr�||ddkr�|jdgg�qjn|dks�||ddkr�|d7}qjnd	||d<||ddd|dks'||ddd|dkrJ|j|d	|g�|d7}n||ddd||dddg}|j|�qjWx<|gkr�d	|j�g}|j||�|d7}q�Wtj	|�}|j
d|�dS(
s?Fuse subpaths of a path. Should only be used on unstroked pathstdiNii����i����tZtMtL(R R!t
simplepatht	parsePathtlenRBtinserttappendtpopt
formatPathtset(t	path_nodetpath_dtpathtit
initial_pointtreturn_stacktel((s0/usr/share/inkscape/extensions/synfig_prepare.pyt
fuse_subpaths�s4$ 
@
,cCsCtj|jdd��}d|j�krv|ddkrvd|j�ks_|ddkriddgSd|gSnd|j�ks�|ddkr�|dgS|jtdd��}tj|tdd��}tj|tdd��}|j	}d	|j�kr|d	}|d	=n	t
d
�tdd�|j�kri|tdd�}|tdd�=nd}d
|j�kr�|d
}|d
=ntt|��}d|j�kr�|d=nd|j�kr�|d}	|d=nd}	x(|j�D]}
|j
|
||
�q�W|j
d
|�i}idd6dd6}idd6dd6}
x�|j�D]�}|jd�r�||||<qe|jd�r�|||
|<qe|jd�r�|||
|<qe|jd�r�||||<qe||||<|||
|<qeWt|�dkr9|j
dtj|��n|j
dtj|��|j
dtj|
��|j
d	|�|j
d	|�|dk	r�|j
tdd�|�|j
tdd�|�n|j
d
|d�|j
d
|d�|	dk	r#|j
d|	�|j
d|	�n|j�j||�||gS(s�Split a path into two paths, one filled and one stroked

    Returns a the list [fill, stroke], where each is the XML element of the
    fill or stroke, or None.
    tstyleRtfilltnonetstroketgtsvgR_RQs0Cannot split stroke and fill of non-path elementt	nodetypestsodipodiRt	transforms#000000tmarkertfilteris-fills-strokeN(tsimplestylet
parseStyleR tkeysR!tmakeelementRRt
SubElementtattribtAssertionErrortstrRR\t
startswithRWtformatStylet	getparenttreplace(R]RetgroupRfRhtattribsRQRktpath_idRmtattrib_nametstyle_groupt
style_filltstyle_stroketkey((s0/usr/share/inkscape/extensions/synfig_prepare.pytsplit_fill_and_stroke
s|""

"
	

	




g�?gcCss|jtdd�ks`|jtdd�ks`|jtdd�ks`|jtdd�krddS|jtdd�krO|jd�rOg|jd�j�D]}t|�^q�\}}}}t|jd	|��}t|jd
|��}	d|||||	|f}
tj|
|�}tj|jd�|�}|jd=ntj|jd�|�}tj	|jd
d��}i}
dg}x8|D]0}||j
�kr�|||
|<||=q�q�W|j�}|j|�|}ddg}x=|D]5}|j|�r|j|�||<|j|=qqW|jtdd�ks�|jtdd�ks�|jtdd�ks�|jtdd�kr0t
|
�dkr�d
|j
�kr�|jd
=q�n|jd
tj|
��d|j
�kr|jd=nxf|j�D]}t|||�qWn?|j|
�|jd
tj|��|jdtj|��dS(s3Propagate style and transform to remove inheritancet	namedviewRltdefsRjtmetadatat
foreignObjectNtviewBoxtwidththeightstranslate(%f, %f) scale(%f, %f)RmReRRoRfRhRitatswitchi(ttagRR tsplitt
get_dimensiontsimpletransformtparseTransformRuRpRqRrtcopytupdateRWR\Rytiterchildrentpropagate_attribstformatTransform(R"tparent_styletparent_transformtxtvxtvytvwtvhtdwtdhtttthis_transformt
this_styletremaining_styletnon_propagatedR�tparent_style_copyt
style_attribsRutc((s0/usr/share/inkscape/extensions/synfig_prepare.pyR�qsX': 
	




t1024cCsV|dkrdSyt|d�}Wn
d}nXt|�tkrPt|�S|ddkrddS|ddkr�t|d �S|ddkr�t|d �d	S|dd
kr�t|d �dS|ddkr�t|d �d
S|ddkr
t|d �dS|ddkr,t|d �dS|ddkrNt|d �dSdSdS(s;Convert an SVG length string from arbitrary units to pixelsRii����t%ii����tpxtptg���S�?temitmmg�Zd;@tpctcmg��Q��B@tini`N(tintR!ttypetfloat(tstlast((s0/usr/share/inkscape/extensions/synfig_prepare.pyR��s2

t
SynfigPrepcBseZd�ZRS(cCs�t|j�}|j�|_t|jj��xs|jjddt�D]Y}|jdd�j�j	d�dkrJt
|�d}|dk	r�t|�q�qJqJWdS(	sITransform document in preparation for exporting it into the Synfig formats
//svg:pathR'RQRtmiiN(
RHtdocumentRGR�tgetrootR(RR tlowertcountR�R!Rd(RR�R"Rf((s0/usr/share/inkscape/extensions/synfig_prepare.pyteffect�s'(R
RR�(((s0/usr/share/inkscape/extensions/synfig_prepare.pyR��st__main__(RR2R=tinkexRRRRRURpR�RCRt
subprocessR
RRR0RtobjectRRHRdR�R�R�tEffectR�R
tetaffect(((s0/usr/share/inkscape/extensions/synfig_prepare.pyt<module>s."$

{/	2	d'K