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/dpiswitcher.pyo
�
��Yc
@sQdZddlZddlZddlZddlZddlmZddlZddlZddl	Z	dddddd	d
gZ
ddd
gZddddddddddg
Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Zd!�Zd"ejfd#��YZed$krMe�Zej�ndS(%sw
This extension scales a document to fit different SVG DPI -90/96-

Copyright (C) 2012 Jabiertxo Arraiza, jabier.arraiza@marker.es
Copyright (C) 2016 su_v, <suv-sf@users.sf.net>

Version 0.6 - DPI Switcher

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


Changes since v0.5:
    - transform all top-level containers and graphics elements
    - support scientific notation in SVG lengths
    - fix scaling with existing matrix() (use functions from simpletransform.py)
    - support different units for document width, height attributes
    - improve viewBox support (syntax, offset)
    - support common cases of text-put-on-path in SVG root
    - support common cases of <use> references in SVG root
    - examples from http://tavmjong.free.fr/INKSCAPE/UNITS/ tested

TODO:
    - check grids/guides created with 0.91:
      http://tavmjong.free.fr/INKSCAPE/UNITS/units_mm_nv_90dpi.svg
    - check <symbol> instances
    - check more <use> and text-on-path cases (reverse scaling needed?)
    - scale perspective of 3dboxes

i����N(tetreetdefstglyphtmarkertmasks
missing-glyphtpatterntsymboltatgtswitchtcircletellipsetimagetlinetpathtpolygontpolylinetrectttexttusecCs|jtjdd��dkS(s0Check whether element is an Inkscape 3dbox type.ttypetsodipodisinkscape:box3d(tgettinkextaddNS(telement((s-/usr/share/inkscape/extensions/dpiswitcher.pytis_3dboxSscCs|jtjdd�kS(s(Check whether element is of type <text>.Rtsvg(ttagRR(R((s-/usr/share/inkscape/extensions/dpiswitcher.pytis_useXscCs|jtjdd�kS(s(Check whether element is of type <text>.RR(RRR(R((s-/usr/share/inkscape/extensions/dpiswitcher.pytis_text]scCsJt|�rF|jtjdd��}|dk	rFt|�rFtSntS(s,Check whether text element is put on a path.ttextPathRN(RtfindRRtNonetlentTruetFalse(Rt	text_path((s-/usr/share/inkscape/extensions/dpiswitcher.pytis_text_on_pathbs
cCs||j�kS(s@Check whether element1 and element2 are siblings of same parent.(t	getparent(telement1telement2((s-/usr/share/inkscape/extensions/dpiswitcher.pyt
is_siblingkscCsG|dk	rC|jddtj�}|dk	rCt|j�kSntS(s!Check whether element is in defs.Rt
namespacesN(R!R RtNSStlinked_nodetiterdescendantsR$(tdocRR((s-/usr/share/inkscape/extensions/dpiswitcher.pyt
is_in_defsps
cCs�|dk	r-|jtjdd�d�}n|dk	r�||jd�d}d|}|j|dtj�}t|t�r�t	|�r�|dSdSndS(	sReturn linked element or None.threftxlinkt#is
//*[@id="%s"]R+iN(
R!RRRR txpathR,t
isinstancetlistR"(R/RR1t	linked_idRtel_list((s-/usr/share/inkscape/extensions/dpiswitcher.pyt
get_linkedys!
cCst}|rn|S(s'Check transformation for 3dbox element.(R$(RRtscale_xtscale_ytskip((s-/usr/share/inkscape/extensions/dpiswitcher.pytcheck_3dbox�scCst}t||jtjdd���}t||�st||�rt}d|jkr�t	j
|jd��}|ddc|9<|ddc|9<|jdt	j
|��nt	j
dj||��}t|dd|dd|dd|dd�}tjt|��}d}	tj|jd	��}
|	|
krt|
|	�||
|	<|jd	tj|
��nx�|j�D]|}|jtjd
d�kr�tj|jd	��}
|	|
krt|
|	�||
|	<|jd	tj|
��qq�q�Wqn|S(s3Check whether to skip scaling a text put on a path.RRt	transformiiisscale({},{})s	font-sizetstylettspan(R$R9R RRR0R*R#tattribtsimpletransformtparseTransformRtsettformatTransformtformattabstmathtsqrttsimplestylet
parseStyletfloattformatStyleR.R(RRR:R;R<Rtmattdettdescrimtproptsdicttchild((s-/usr/share/inkscape/extensions/dpiswitcher.pytcheck_text_on_path�s4$8)cCs�t}t||�}t||�s�t||�r�t}d|jkr�tj|jd��}|ddc|9<|ddc|9<|j	dtj
|��q�q�n|S(s>Check whether to skip scaling an instanciated element (<use>).R>iii(R$R9R0R*R#RARBRCRRDRE(RRR:R;R<RRN((s-/usr/share/inkscape/extensions/dpiswitcher.pyt	check_use�s"tDPISwitchercBs�eZd�Zi
dd6dd6dd6dd6d	d
6dd6d
d6dd6dd6dd6Zi
dd6dd6dd6dd6dd
6dd6dd6dd6dd6dd6Zed�Zd�Zd �Zd!�Z	d"�Z
d#�Zd$�Zd%�Z
d&�ZRS('cCs�tjj|�|jjddddddddd	d
d�|jjdddddddddd
d
�dd|_dd|_d|_d|_	dS(Ns
--switchertactiontstoreRtstringtdesttswitchertdefaultt0thelpsSelect the DPI switch you wants--actiontg�V@gX@tpxg�?(
RtEffectt__init__tOptionParsert
add_optionR!tfactor_atfactor_btunitstunitExponent(tself((s-/usr/share/inkscape/extensions/dpiswitcher.pyRb�s


	g�V@ting�?tptg�?R`gk�b�X@tmmg)��n�A@tcmgpt:���@tmgt���KAtkmg.@tpcgP�@tydg�@tftgX@g�UUUU�?g:Z��x<@gd�/���B@g�:��@gd�����LAg0@g�@g�@c
Cs|jjdkr$|jj�}n|jj�}|r_tjddj|dg��}ntjddj|��}tjd�}|j|�}|j	|�}d}d}	|r�t
|j|j�|j
�!�}n|r|j|j�|j
�!}	n||	fS(sParse SVG length.R]s(%s)$t|t%s:(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)idR`(toptionsR[t_DPISwitcher__uuconvLegacytkeyst_DPISwitcher__uuconvtretcompiletjointmatchtsearchRLRYtstarttend(
Ritlengthtpercenttknown_unitst	unitmatchtparamtptutvaltunit((s-/usr/share/inkscape/extensions/dpiswitcher.pytparse_length�s &%cCs�|jpd}||kr�|jjdkrc||j|}||j||jd}|}q�||j|}||j||jd}|}n||fS(s-Convert length to self.units if unit differs.R`R](RgRuR[RvRx(RiR�R�tdoc_unittval_px((s-/usr/share/inkscape/extensions/dpiswitcher.pytconvert_lengths		cCs?||jkr;|j|j|�dt�d}||kSdS(s=Check unit of attribute value, match to units in *unit_list*.R�iN(RAR�RR#(RiRtattrt	unit_listR�((s-/usr/share/inkscape/extensions/dpiswitcher.pytcheck_attr_units"cCsi||jkre|j|j|�dt�\}}||kre|j|dj|||��qendS(s9Scale attribute value if unit matches one in *unit_list*.R�s{}{}N(RAR�RR#RDRF(RiRR�R�tfactorR�R�((s-/usr/share/inkscape/extensions/dpiswitcher.pytscale_attr_vals$c	Cs|j|jd��d}|j|j|jd���d}||j|j}||j|j}|jd�r�|jdt|��n|jd�r�|jdt|��n|jd�rMtjdd|jd��}g|j	�j
dd�D]}t|�^q�}|jddjg|D]}	|	|j^q-��n|j
jd	kr||j|�|j|�nx|D]w}
tj|
�j}|j}|j}
|tks�|tkr�t|
�r�t||
||
�r�q�q�nt|
�rt||
||
�rq�qnt|
�rCt||
||
�rCq�qCnx4ddgD]&}|j|
|d
gd|j�qPWx4dd
gD]&}|j|
|d
gd|j�q�W|dkr�|
dkr�tjdj||
��}tj||
�q�q�q�WdS(s)Scale all top-level elements in SVG root.twidthitheighttviewBoxs +|, +|,t is{} {} {} {}t1Rtg�?txtysscale({},{})N( R�RR�ReRhRDtstrRytsubtstriptsplitRLRFRuR[tscaleGuidest	scaleGridRtQNamet	localnametGRAPHICS_ELEMENTStCONTAINER_ELEMENTSRR=R&RTRRUR�RBRCtapplyTransformToNode(RiRtwidthNumbertheightNumbertwidthDoct	heightDoct
viewboxstringtitviewboxlistR�RRtwidth_scaletheight_scaleR�RN((s-/usr/share/inkscape/extensions/dpiswitcher.pyt	scaleRootsJ%16

					$$cCsdS(N((RiRn((s-/usr/share/inkscape/extensions/dpiswitcher.pytscaleElementWscCs�d}|j|dtj�}x{|D]s}tj|jd�d�}|jdtt|dj	��|j
�dtt|dj	��|j
��q%WdS(Ns//sodipodi:guideR+tpositiont,ii(R4RR,RYR�RRDR�RLR�Re(RiRtxpathStrtguidestguidetpoint((s-/usr/share/inkscape/extensions/dpiswitcher.pyR�Zs

c	Cs�d}|j|dtj�}x�|D]�}|jdd�|jd�r�tttjdd|jd���|j	�d}|jdt|��n|jd�r�tttjdd|jd���|j	�d}|jdt|��n|jd	�rRtttjdd|jd	���|j	�d}|jd	t|��n|jd
�r%tttjdd|jd
���|j	�d}|jd
t|��q%q%WdS(Ns//inkscape:gridR+RgR`tspacingxs[a-zA-Z]R_tspacingytoriginxtoriginy(
R4RR,RDRR�RLRyR�Re(	RiRR�tgridstgridR�R�R�R�((s-/usr/share/inkscape/extensions/dpiswitcher.pyR�as 
5555cCs�tj}tjt_|jj�}|jjdkr�dGHdt|jt	j
dd���GH|jd�}|r�d|GHn|jd�}|r�d	|GHn|jd
�}|r�d|GHn|jt	j
dd
��}|jt	j
dd��}|r
d|GHn|jd�}|r+d|GHnd}	|j|	dt	j
�}
d}	|
rwt|
�}dt|�dGHn|j|	dt	j
�}d}
xW|D]0}dt|
�d|jd�GH|
d}
q�Wn|jjdkrdd|_dd|_n|jt	j
dd
��}|jt	j
dd�d�|j|jd��d|_|jr�|jdkr�|jdkr�|jd kr�|jjdkr�d!|j|j|j|_q�d!|j|j|j|_n|j|�|t_dS("Ns"page_info"s:::SVG document related info:::s	version: tversionuinkscapeR�swidth: R�sheight: R�s	viewBox: t	namedviewRsdocument-unitstinkscapesdocument-units: Rgsunits: s//sodipodi:guideR+s//inkscape:grids
Document has s guidesisGrid number s	: Units: R]gX@g�V@R`R_Rtg�?(tsyststdouttstderrtdocumenttgetrootRuRWR�RRRR R4R,R"R[ReRfRDR�RgRxRhRvR�(RitsaveoutRR�R�R�R�tdocunitsRgR�R�tnumberGuidesR�R�R�((s-/usr/share/inkscape/extensions/dpiswitcher.pyteffectssZ	$
 
6!!
(t__name__t
__module__RbRvRxR$R�R�R�R�R�R�R�R�R�(((s-/usr/share/inkscape/extensions/dpiswitcher.pyRV�s@	

				:			t__main__(t__doc__R�RyRYRHtlxmlRRRBRJtSKIP_CONTAINERSR�R�RRRR&R*R0R9R=RTRURaRVR�R�taffect(((s-/usr/share/inkscape/extensions/dpiswitcher.pyt<module>*sT													
	#	�