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/svg_and_media_zip_output.pyc
�
��Yc@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZe
j
e
jd�ej�dejfd��YZedkr�e�Zej�ndS(s�
svg_and_media_zip_output.py
An extention which collects all images to the documents directory and
creates a zip archive containing all images and the document

Copyright (C) 2005 Pim Snel, pim@lingewoud.com
Copyright (C) 2008 Aaron Spike, aaron@ekips.org
Copyright (C) 2011 Nicolas Dufour, nicoduf@yahoo.fr
    * Fix for a bug related to special caracters in the path (LP #456248).
    * Fix for Windows support (LP #391307 ).
    * Font list and image directory features.

this is  the first Python script  ever created
its based on embedimage.py

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.

TODOs
- fix bug: not saving existing .zip after a Collect for Output is run
     this bug occurs because after running an effect extention the inkscape:output_extension is reset to svg.inkscape
     the file name is still xxx.zip. after saving again the file xxx.zip is written with a plain .svg which
     looks like a corrupt zip
- maybe add better extention
- consider switching to lzma in order to allow cross platform compression with no encoding problem...
i����NttCompressedMediaOutputcBsPeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	RS(cCs�tjj|�tjdkr+d|_n	d|_dddddg|_|jjd	d
ddd
dddddd�|jjdd
ddddddt	dd�|jjdd
ddd
dddd�dS(Ntnttcp437slatin-1s!{http://www.w3.org/2000/svg}tspans {http://www.w3.org/2000/svg}texts${http://www.w3.org/2000/svg}flowRoots${http://www.w3.org/2000/svg}flowParas${http://www.w3.org/2000/svg}flowSpans--image_dirtactiontstorettypetstringtdestt	image_dirtdefaultRthelpsImage directorys--font_listtinkboolt	font_lists
Add font lists--tabttabs'The selected UI-tab when OK was pressed(
tinkextEffectt__init__tostnametencodingt	text_tagstOptionParsert
add_optiontFalse(tself((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pyR9s*	cCs�t|jd�}tjdkrQy#ddl}|jdtj�WqQqQXntjj	|j
��|j�tj
|j�dS(sv
        Writes the temporary compressed file to its destination
        and removes the temporary directory.
        trbRi����Ni(topentzip_fileRRtmsvcrttsetmodetO_BINARYtsyststdouttwritetreadtclosetshutiltrmtreettmp_dir(RtoutR((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pytoutputQs
cCstj�rtj�}nd}t|jj|�}x�|jjddtj�D]�}|j	tj
dd��}|d dkrR|j	tj
dd	��}tj|�}tj
|j�}	|	dkr�tjj|	�r�tjj|	�}nt|d
�}tjj|tjj|��}
tjj|�rftj||j�|j||
j|j��n�tjjtjj|j|��r�tjtjj|j|�|j�|jtjj|j|�|
j|j��ntjtd�|�|jtj
dd�|
�qRqRWdS(
sg
        Collects all images in the document
        and copy them to the temporary directory.
        sUTF-8s//svg:imaget
namespacesthrefuxlinkitdatatabsrefusodipodisutf-8sCould not locate file: %sN(tlocaletgetpreferredencodingtunicodetoptionsR	tdocumenttxpathRtNSStgettaddNSturlparseturllibturl2pathnametpathtNoneRtisfiletrealpathtjointbasenameR%tcopyR'R"tencodeRterrormsgt_tset(Rtdocnametzt
dir_localetdirtnodetxlinkR-turlR+t
image_path((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pytcollect_imagesas,"!$%1cCsetjj|j|�}t|d�}|jj|�|j�|j||j|j	�d�dS(sr
        Copy SVG document to the temporary directory
        and add it to the temporary compressed file
        tws.svgN(
RR:R>R'RR2R"R$RAR(RtdocstrippedRFtdst_filetstream((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pytcollect_SVG�s

cCs|j|jkS(s_
        Returns true if the tag in question is an element that
        can hold text.
        (ttagR(RRI((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pytis_text�scCs�g}d}d|jkr4tj|jd�}n|s>|S|jd�r�|jd�r||j|dd|d�q�|j|d�n#|jd�r�|j|d�n|S(sg
        Given a node, returns a list containing all the fonts that
        the node is using.
        Rtstylesfont-familysfont-weightt s-inkscape-font-specification(tattribtsimplestylet
parseStylethas_keytappend(RRItfontsts((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pyt	get_fonts�s cCsVg}g}|jj�j�}|jt|j|��g}xD|D]<}x3|j|�D]"}||kr]|j|�q]q]WqGWt|�}d}t	j
j|j|�}	t
|	d�}
t|�dkr�|
jtd��nPt|�dkr|
jtd�|d�n |
jtd�dj|��|
j�|j|	|�d	S(
s�
        Walks through nodes, building a list of all fonts found, then
        reports to the user with that list.
        Based on Craig Marshall's replace_font.py
        sfontlist.txtRNis1Didn't find any fonts in this document/selection.is!Found the following font only: %ssFound the following fonts:
%ss
N(R2tgetroottgetiteratortextendtfilterRTR^R[tsortedRR:R>R'RtlenR"RCR$(RRFtitemstnodestfonts_foundRItftfindingstfilenameRPRQ((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pyt
list_fonts�s(
 
cCs|jj�}|jtjdd��}|dkrF|jd}ntjj	|j
dd��}|j
dd�}|j
dd�}tj�|_
tjj|j
|�d|_tj|jd�}|j||�|j||�|jjtkr
|j|�n|j�dS(	NREusodipodii����s.zipRs.svgs.svgzRN(R2R_R5RR6R;targsRR:R?treplacettempfiletmkdtempR'R>RtzipfiletZipFileRMRRR1R
tTrueRkR$(RtdocrootRERORF((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pyteffect�s(
t__name__t
__module__RR)RMRRRTR^RkRt(((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pyR8s			$				t__main__(t__doc__R7R8Rtos.pathRRpR%R RnR.RRXt	setlocaletLC_ALLtlocalizeRRRutetaffect(((s:/usr/share/inkscape/extensions/svg_and_media_zip_output.pyt<module>&s"
�