403Webshell
Server IP : 93.86.61.54  /  Your IP : 216.73.216.60
Web Server : Apache/2.4.62 (Ubuntu)
System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64
User : www-data ( 33)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/inkscape/extensions/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/inkscape/extensions/__pycache__/hershey.cpython-310.pyc
o

0�a�:�@s�dZddlZddlZddlmZddlZddlmZmZmZm	Z	ddlm
Z
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZGdd�dej�ZedkrVe���dSdS)	aT
Hershey Text 3.0.5, 2021-05-17

Copyright 2021, Windell H. Oskay, www.evilmadscientist.com

Major revisions in Hershey Text 3.0:

1. Migrate font format to use SVG fonts.
    - SVG fonts support unicode, meaning that we can use a full range of
        characters. We are no longer limited to the ASCII range that the
        historical Hershey font formats used.
    - Arbitrary curves are supported within glyphs; we are no longer limited to
        the straight line segments used in the historical Hershey format.
    - The set of fonts can now be expanded.

2. Add a mechanism for adding your own SVG fonts, either within the
    folder containing the default fonts, or from an external file or directory.
    This is particularly important for installations where one does not
    have access to edit the contents of the Inkscape extensions directory.

3. Support font mapping: If a given font face is used for a given block of
    text, check first to see if a matching SVG font is present. If not,
    substitute with the default (selected) stroke font from the list of
    included fonts.

4. Instead of entering text (one line at a time) in the extension,
    this script now converts text (either all text, or all selected text)
    in the document, replacing it in place. While not every possible
    method of formatting text is supported, many are.

�N)�deepcopy)�	Transform�Style�units�AbortExtension)�load_svg�Group�TextElement�FlowPara�SVGfont�FontFace�FlowSpan�Glyph�MissingGlyph�Tspan�FlowRoot�	Rectangle�Use�PathElement�Defscs�eZdZdZ�fdd�ZdZdZdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zgd&�gd'�gd(fd)d*�Zd+d,�Z�ZS)-�Hersheyz0
    An extension for use with Inkscape 1.0
    cs
tt|���|jjddddd�|jjdddd	d�|jjd
ddd
d�|jjdtjdddd�|jjddddd�|jjddddd�t�|_d|_	d|_
d|_d|_d|_
d|_t�|_g|_d|_d|_g|_g|_g|_g|_g|_g|_d|_d|_d|_dS)Nz--tab�mode�renderz-The active tab or mode when Apply was pressed)�dest�default�helpz
--fontface�fontface�HersheySans1z-The selected font face when Apply was pressedz--otherfont�	otherfont�z'Optional other font name or path to usez
--preserve�
preserve_textFzPreserve original text)�typerrrz--action�	util_mode�samplezThe utility option selectedz--text�sample_textzText to use for font tablegY�
SUU�?rT�)�superr�__init__�
arg_parser�add_argument�inkex�Boolean�dict�font_file_list�font_load_fail�
svg_height�	svg_width�output_generated�warn_unflow�
warn_textpath�	font_dict�nodes_to_delete�vb_scale_factor�text_string�
text_families�text_heights�
text_spacings�text_aligns�text_x�text_y�line_number�new_line�render_width)�self��	__class__��)/usr/share/inkscape/extensions/hershey.pyr'FsZ������
zHershey.__init__gX@a�====== Hershey Text Help ======

The Hershey Text extension is designed to replace text in your document (either
selected text or all text) with specialized "stroke" or "engraving" fonts
designed for plotters.

Whereas regular "outline" fonts (e.g., TrueType) work by filling in the region
inside an invisible outline, stroke fonts are composed only of individual lines
or strokes with finite width; much like human handwriting when using a physical
pen.

Stroke fonts are most often used for creating text-like paths that computer
controlled drawing and cutting machines (from pen plotters to CNC routers) can
efficiently follow.

A full user guide for Hershey Text is available to download from
    http://wiki.evilmadscientist.com/hershey


   ==== Basic operation ====

To use Hershey Text, start with a document that contains text objects. Select
the "Render" tab of Hershey Text, and choose a font face from the pop-up menu.

When you click Apply, it will render all text elements on your page with the
selected stroke-based typeface. If you would like to convert only certain text
elements, click Apply with just those elements selected.

If the "Preserve original text" box is checked, then the original text elements
on the page will be preserved even when you click Apply. If it is unchecked,
then the original font elements will be removed once rendered.

You can generate a list of available SVG fonts or a list of all glyphs available
in a given font by using the tools available on the "Utilities" tab.


   ==== How Hershey Text works ====

Hershey Text works by performing font substitution, starting with the text in
your document and replacing it with paths generated from the characters in the
selected SVG font.

Hershey Text uses fonts in the SVG font format. While SVG fonts are one of the
few types that support stroke-based characters, it is important to note that
converting an outline font to SVG format does not convert it to a stroke based
font. Indeed, most SVG fonts are actually outline fonts.

This extension *does not* convert outline fonts into stroke fonts, nor does it
convert other fonts into SVG format. Its sole function is to replace the text
in your document with paths from the selected SVG font.


   ==== Using an external SVG font ====

To use an external SVG font -- one not included with the distribution -- select
"Other" for the name of the font in the pop-up menu on the "Render" tab. Then,
do one of the following:

(1) Add your SVG font file (perhaps "example.svg") to the "svg_fonts" directory
within your Inkscape extensions directory, and enter the name of the font
("example") in the "Other SVG font name or path" box on the "Render" tab.

or

(2) Place your SVG font file anywhere on your computer, and enter the full path
to the file  in the "Other SVG font name or path" box on the "Render" tab.
A full path might, for example, look like:
    /Users/Robin/Documents/AxiDraw/fonts/path_handwriting.svg


   ==== Using SVG fonts: Advanced methods ====

In addition to using a single SVG font for substitution, you can also use
font name mapping to automatically use particular stroke fonts in place of
specific font faces, to support various automated workflows and to support
the rapid use of multiple stroke font faces within the same document.

Several SVG fonts are included with this distribution, including both
single-stroke and multi-stroke fonts. These fonts are included within the
"svg_fonts" directory within your Inkscape extensions directory.

You can select the font that you would like to use from the pop-up menu on the
"Render" Tab. You can also make use of your own SVG fonts.

Order of preference for SVG fonts:

(1) If there is an SVG font with name matching that of the font for a given
piece of text, that font will be used. For example, if the original text is in
font "FancyScript" and there is a file in svg_fonts with name FancyScript.svg,
then FancyScript.svg will be used to render the text.

(2) Otherwise (if there is no SVG font available matching the name of the font
for a given block of text), the face selected from the "Font face" pop-up menu
will be used as the default font when rendering text with Hershey Text.

(3) You can also enter text in the "Name/Path" box, which can represent one of
the following: (i) a font name (for a font located in the svg_fonts directory),
(ii) the path to a font file elsewhere on your computer, or (iii) the path to a
directory containing (one or more) font files.

(3a) Using a font name:
If you move a custom SVG font file into your svg_fonts directory, then you can
enter the name of the SVG font in the "Name/Path" text box and select "Other"
from the pop-up menu. Then, the named font will be used as the default.

(3b) Using a file path:
If you enter the path to an SVG font file in the "Name/Path" text box and
select "Other" from the pop-up menu. Then, that font will be used as the
default. All SVG fonts located in the same directory as that font file will
also be available for name-based font substitution. If there are multiple
font-name matches, files in an external directory take precedence over ones in
the svg_fonts directory.

(3c) Using a directory path:
If you enter the path to a directory containing SVG font files in the
"Name/Path" text box, then all SVG font files files in that directory will be
available for name-based font substitution. If there are multiple font-name
matches, files in an external directory take precedence over ones in the
svg_fonts directory.



Tips about using these methods with your own custom fonts:

(A) These methods can be used to render different text elements with different
SVG font faces. You can even rename a font -- either your own custom one or one
of the bundled ones -- to match the name of a font that you're using. For
example, if you rename a script font you name a font to "Helvetica.svg",
then all text in Helvetica will be replaced with that SVG font.

(B) Using a directory path (3c) is a particularly helpful method if you do
not have access to modify the svg_fonts directory.



   ==== Limitations ====

This extension renders text into non-editable paths, generated from the
character geometry of SVG fonts. Once you have rendered the text, the resulting
paths can be edited with path editing tools, but not text editing tools.

Since this extension works by a process of font substitution, text spanning a
single line will generally stay that way, whereas text flowed in a box (that
may span multiple lines) will be re-flowed from scratch. Style information such
as text size and line spacing can be lost in some cases.

We recommend that you use the live preview option to achieve best results with
this extension.


(c) 2021 Windell H. Oskay
Evil Mad Scientist Laboratories
cCsR|j���|�}|r't�|�\}}|durdShd�}||vr!dSt�|d�SdS)a]
        Get the <svg> attribute with name "name", and parse it as a length,
        into a value and associated units. Return value in inches.

        This may cause scaling issues in some circumstances. Note, for
        example, that Adobe Illustrator uses 72 px per inch, and Inkscape
        used 90 px per inch prior to version 0.92.
        N>�em�ex�%�in)�document�getroot�getr�
parse_unit�convert_unit)rA�name�string_to_parse�value�unit�	bad_unitsrDrDrE�getlength_inchs	zHershey.getlength_inchcCs&t�|�\}}|dur
dSt�|d�S)z�
        Custom replacement for the old "unittouu" routine

        Parse the attribute into a value and associated units.
        Return value in user units (typically "px").
        Importantly, return None for malformed inputs.
        Nr)rrMrN)rA�input_stringrQ�_rDrDrE�units_to_userunits.s	zHershey.units_to_userunitscCs\|durdS|���dd���}t|�dkrdSt|d�}t|d�}t|d�}t|d	�}	|dks8|	dkr:dS|dusB|durFtd
��t|�}
t|�}|
dksV|dkrXdS||
}|	|}
d}d}|dur�|���dd�����}t|�dkr�|d}|d
kr�t|�dkr�|d}t|�dkr�|d}n|}t|�dkr�|d}|dkr�|
|}||	}|}|}||||fS	||
kr�|dks�||
kr�|dkr�|
|}|}|}||}||	}|dvr�|}n|dvr�||}n||d}||||fS||	}|}|}|	|}||}|dv�r|}n|dv�r!||}n||d}||||fS)a�"
        Parse SVG viewbox and generate scaling parameters.
        Reference documentation: https://www.w3.org/TR/SVG11/coords.html

        Inputs:
            viewbox:         Contents of SVG viewbox attribute
            p_a_r:      Contents of SVG preserveAspectRatio attribute
            doc_width:  Width of SVG document
            doc_height: Height of SVG document

        Output: s_x, s_y, o_x, o_y
            Scale parameters (s_x, s_y) and offset parameters (o_x, o_y)

        N)r%r%rrz, � �rr%��z7Width or height attribute missing on toplevel <svg> tag�xmidymid�meet�defer�none�slice>�xmaxymin�xmidymin�xminymin>�xmaxymax�xmidymax�xminymax>rf�xminymidrc>rd�xmaxymidra)�strip�replace�split�len�floatr�lower)rA�viewbox�p_a_r�	doc_width�
doc_height�vb_array�min_x�min_y�width�height�d_width�d_height�ar_doc�ar_vb�	par_align�par_mos�	par_array�par0�s_x�s_y�o_x�o_y�scaled_vb_height�
excess_height�scaled_vb_width�excess_widthrDrDrE�vb_scale>s��

zHershey.vb_scalecCsD|�d�r|�d�r|dd�S|�d�r |�d�r |dd�S|S)z�
        A multi-word font name may have a leading and trailing
        single or double quotes, depending on the source.
        If so, remove those quotes.
        �'r%����")�
startswith�endswith�rA�fontnamerDrDrE�strip_quotes�s
zHershey.strip_quotescCsd}|durdS|D]�}t|t�r|�|�St|t��r	t�}t�}t�}t�}|�d�|d<|�d�}|durAt|�|d<|D]�}t|t�r�z|�d�}	WnYqC|	dur\qC|	|vraqCt�}
|�d�|
d<|�d�}|dur{t|�|
d<n|d|
d<|�d	�|
d	<|
||	<qCt|t�r�|�d
�|d<|�d�}|dur�d
|d<nt|�|d<|�d�}|dur�t|�|d<|�d�}
|
dur�t|
�|d<qCt|t	�r�|�d�}|dur�t|�|d<n|d|d<|�d	�|d	<||d<qCd|d|d<||d<||d<|Sq
dS)a�
        Parse an input svg, searching for an SVG font. If an
        SVG font is found, parse it and return a "digest" containing
        structured information from the font. See below for more
        about the digest format.

        If the font is not found cannot be parsed, return none.

        Notable limitations:

       (1) This function only parses the first font face found within the
        tree. We may, in the future, support discovering multiple fonts
        within an SVG file.

       (2) We are only processing left-to-right and horizontal text,
        not vertical text nor RTL.

       (3) This function currently performs only certain recursive searches,
        within the <defs> element. It will not discover fonts nested within
        groups or other elements. So far as we know, that is not a limitation
        in practice. (If you have a counterexample please contact Evil Mad
        Scientist tech support and let us know!)

       (4) Kerning details are not implemented yet.
        N�id�font_idzhoriz-adv-x�horiz_adv_x�unicodez
glyph-name�
glyph_name�d�font-family�font_familyzunits-per-emg@�@�units_per_em�ascent�descent�
missing_glyph��?�scale�glyphs�geometry)
�
isinstancer�parse_svg_fontrr,rLrmrrr)rA�	node_list�digest�noder�r�r�r��element�uni_text�
glyph_dictr�r�r�rDrDrEr��s~
0










���zHershey.parse_svg_fontcCs�|durdS||jvr
dS||jvr|j|}nd|j|<dSz	t|�}|�|���|j|<WdSty@d|j|<YdSt�dt|��d|j|<YdS)z�
        Attempt to load an SVG font from a file in our list
        of (likely) SVG font files.
        If we can, add the contents to the font library.
        Otherwise, add a "None" entry to the font library.
        NzError parsing SVG font at )	r4r-rr�rK�IOErrorr*�errormsg�str)rAr��the_path�font_svgrDrDrE�	load_font�s"


zHershey.load_fontc
	CsLd|j_|j���t��}|jD]}|�|�qd}t||j	�d}tt
d|dddd���}||j	}d	|}|}t|j�D]]}|j|d
urIq?dt|�dd
�}	|�t
di|	���}
||
_||
_t|�t|�d�}	d|d|dd�}|�t
di|	���}z
|jj�d�|_Wnty�|jj|_Ynw||_||7}q?|�||j�d
S)zC
        Generate display table of all available SVG fonts
        Fg�������?�pxr_�black�
sans-serif�end��stroke�	font-size�fillr��text-anchor��?N�0�true)�x�y�hershey-ignore�r�r��startzutf-8rD)�optionsr �svg�get_current_layer�addrr-r�r�r6r�sortedr4r	�text�styler$�decode�AttributeError�recursively_traverse_svg�
doc_transform)
rA�groupr��	font_size�font_size_text�labeltext_style�x_offset�y_offsetr��text_attribs�textline�sampletext_style�
samplelinerDrDrE�
font_table�sF

�
��
zHershey.font_tablecCsxd|j_|�d�}|jrt�d�dS|j���t	��}d}|j
|dD]}|j
|d|ddur8|d7}q%tt�
t�|���}d	}t||j�d
}ttd|d|d
d���}d||j}	|	}
|	}|
}d}
t|j
|d�D]@}|j
|d|ddur�qrt|
|�\}}|	|d}|
|d}t|�t|�d�}|�tdi|���}||_||_|
d}
qr|�||j�dS)z�
        Generate display table of glyphs within the current SVG font. Sorted display of
        all printable characters in the font _except_ missing glyph.
        F�not_a_font_namez/Font not found; Unable to generate glyph table.Nrr�r�r%g�������?r�r_r�r�r�r�r�rD)r�r �font_load_wrapperr.r*r�r�r�r�rr4�int�math�floor�sqrtr�r6rr��divmodr	r�r�r�r�)rAr�r��glyph_count�glyph�columnsr�r��glyph_styler�r�r�r��
draw_position�y_pos�x_posr�r�rDrDrE�glyph_table�sF

�
�
zHershey.glyph_tablecCs�t�|_d}tj�tj�t��|��}t�|�D]!}|�d�r9tj�||�}tj�	|�r9tj�
|�\}}||j|<qtj�
|jj�\}}||jvrU|jj
dkrS||j_
dStj�|jj�}tj�	|�r�tj�|�\}}	tj�
|	�\}}
||j|<|jj
dkr�||j_
t�|�D]!}|�d�r�tj�||�}tj�	|�r�tj�
|�\}}||j|<q�dStj�|�r�t�|�D]#}|�d�r�tj�||�}tj�	|�r�tj�
|�\}}||j|<q�dSdS)a�
        Create list of "plausible" SVG font files

        List items in primary svg_fonts directory, typically located in the
        directory where this script is being executed from.

        If there is text given in the "Other name/path" input, that text may
        represent one of the following:

       (A) The name of a font file, located in the svg_fonts directory.
            - This may be given with or without the .svg suffix.
            - If it is a font file, and the font face selected is "other",
                then use this as the default font face.

       (B) The path to a font file, located elsewhere.
            - If it is a font file, and the font face selected is "other",
                then use this as the default font face.
            - ALSO: Search the directory where that file is located for
                any other SVG fonts.

       (C) The path to a directory
            - It may or may not have a trailing separator
            - Search that directory for SVG fonts.

        This function will create a list of available files that
        appear to be SVG(SVG font) files. It does not parse the files.
        We will format it as a dictionary, that maps each file name
        (without extension) to a path.
        �	svg_fonts)z.svgz.SVG�otherN)r,r-�os�path�realpath�join�getcwd�listdirr��isfile�splitextr�rrrk�isdir)rA�font_directory_name�font_dir�dir_item�	file_path�rootrV�	test_path�	directory�	file_name�extrDrDrE�find_font_files#sT�

�



�

��zHershey.find_font_filescCsV|�|�	|j|dur|jj}||jvr|�|�n	|j|dur)d|_dS|S)a�

        This implements the following logic:

        * Check to see if the font name is in our lookup table of fonts,
            self.font_dict

        * If the font is not listed in font_dict[]:
            * Check to see if there is a corresponding SVG font file that
            can be opened and parsed.

            * If the font can be opened and parsed:
                * Add that font to font_dict.
            * Otherwise
                * Add the font name to font_dict as None.

        * If the font has value None in font_dict:
            * Try to load fallback font.

        * Fallback font:
            * If an SVG font matching that in the SVG is not available,
            check to see if the default font is available. That font
            is given by self.options.fontface

        * If a font is loaded and available, return the font name.
            Otherwise, return none.

        NT)r�r4r�rr.r�rDrDrEr�}s

zHershey.font_load_wrappercCs�|�|�}|durdSz	|j|d}Wnd}Yz9||j|dvr;|j|dd}|j|dd||fWS|j|d|d}|j|d|d||fWSYdS)z�
        Given a font face name and a character(unicode point),
            return an SVG path, horizontal advance value,
            and scaling factor.

        If the font is not available by name, use the default font.
        Nr�g����MbP?r�r�r�r�)r�r4)rAr��char�scale_factor�x_advrDrDrE�
get_font_char�s&
	��zHershey.get_font_charcCs�|�d�|_|�d�|_|j��|_|j�d�}|r/|j�d�}|�|||j|j�\}}}}n
dt|j	�}|}d}d}t
||f||fd�|_||d|_d	S)
zE
        Wrapper function for processing viewbox information
        rwrv�viewBox�preserveAspectRatior��)r��	translate�@N)
rTr/r0rJrKr�rLr�rm�PX_PER_INCHrr�r6)rArorpr�r�r�r�rDrDrE�handle_viewbox�szHershey.handle_viewboxcCsV|d}|d}|d}|d}|d}d}|d|j}	z|�||�\}
}}Wn
d}d	}
d}Y|jr8dS|||9}d}
d}t||fd
�}||	}|dkrTd}|j|}t�|�}|dkrhd�|�}ntt�	|�d
�}d�||�}d|i}t||
||fd�}||9}|
d	ur�|�
t��}|�|
�||_
||_d|_|t|�|S)z0
        Render an individual svg glyph
        r�r��offset�
vertoffset�font_heightr��stroke_scalerN)r�r%z	{0:.3f}inr[z{0:.{1}f}inzstroke-width�rT)r6r�r.rr@r��log10�formatr��ceilr�r�set_pathr��	transformr1rm)rA�chardata�parentr�r�rrr�
font_scaler�path_string�adv_xr��h_offset�v_offset�scale_transform�_scale�stroke_width�log_ten�width_string�prec�p_style�
the_transform�path_elementrDrDrE�
draw_svg_text�sL


zHershey.draw_svg_textcCs^|��}|dur,|�|�}|�dd�}|dur|St|�j}|dur$|St|�t|�S|jS)zm
        Determine the cumulative transform which node inherits from
        its chain of ancestors.
        Nr)�	getparent�recursive_get_encl_transformrLr�matrixr�)rAr��parent_transform�node_transform�transrDrDrEr!-s

z$Hershey.recursive_get_encl_transformc
	Cs`|d}|d}|d}|d}|D�]}z|j}Wn	ty#Ynwz|d}	|�|	�}Wn	ty8Ynwz	|�|d�}WnYz |d}
d|
vrSd	}nd
|
vrat|
�d
��d}n|�|
�}Wn	typYnwz|d}Wn	ty�Ynw|jd
ur�|j|j7_|jD]}|j	�
|�|j�
|�|j�
|�|j
�
|�q�t|ttf�r�t�}||d<||d<||d<||d<|�||�|jd
u�r|d}|d}|d}|d}|j|j7_|jD]}|j	�
|�|j�
|�|j�
|�|j
�
|�q�t|t��r-|jd7_|j	�
|�|j�
|�|j�
|�|j
�
|�qd
S)z8
        Parse a flowroot node and its children
        rr��line_spacing�alignr�r��line-height�normal��?rH�Y@�
text-alignN�
)r��
ValueErrorrW�KeyErrorr�rm�rstripr�r7r8�appendr9r:r;r�r
r
r,�recursively_parse_flowroot�tail)
rAr��parent_info�font_height_local�font_family_local�line_spacing_local�text_align_localr��
node_stylerr&rV�	the_stylerDrDrEr2As�

��
���


��z"Hershey.recursively_parse_flowrootcCs�|d}|d}|d}|d}|d}|d}z|j}	WnYz|	d}
|�|
�}Wn	ty6Ynwz	|�|	d�}Wn	tyIYnwz|	d	}Wn	tyYYnwz
|�d
�}|durf|}Wn	typYnwz|�d�}|dur~|}n|dur�d
}t|�|j||}Wn	ty�Ynw|jdur�|j	|j7_	|jD] }
|j
�|�|j�|�|j
�|�|j�|�|j�|�q�|D]?}t|t��rt�}||d<||d<||d<||d<||d<||d<d}|�d�}|dkr�d}|�||�|�r|jd|_q�|jdu�r\|j��}|du�r^|d}|d}|d}|d}|d}|j	|7_	|D]%}
|j�|�|j
�|�|j
�|�|j�|�|j�|��q:dSdSdS)z4
        parse a text node and its children
        rr��anchorr�r�r&r�r�r�r�Nr�rFz
sodipodi:role�lineTr%)r�rWr/r�rLr.rmr>r�r7r8r1r9r;r<r=r�rr,�recursively_parse_textr3ri)rAr�r4r5r6�anchor_local�x_local�y_local�parent_line_spacingr9r�x_temp�y_temprV�sub_node�	node_info�adv_line�role�_stripped_tailr8rDrDrEr=�s�
���
��
���


�

�zHershey.recursively_parse_text�r�rr�rr�r�visiblecW	Cs�
|D�]E}|�d|�}|dkr|}|dvrq|j}t|�t|�}t|t�r@d}|�d�}	|	s0n|	dkr6d}|r?|�|||�qt|t�r�|j}
|
durMqt|�}t|�d	d
��}t|�dd
��}
|dksi|
dkrxd
�	||
�}t|�t|�}n|}z|�
t��}Wnty�t�
d�Yqw|�d|�|�t|
��|D]}|j�|�q�|jjs�|j�|�qt|ttf��rHd|_d}d}|�d�}|�d�}|�d	�}|�d�}d}d}d}d}z
|�d�}|dur�WqWn	ty�Ynwz|j}Wn
t�yYnwd}z|d}|�|�}Wn
t�yYnwd}z	|�|d�}Wn
t�y3Ynwz"|d}d|v�rAd}nd|v�rPt|�d��d}n|�|�}Wn
t�y`Ynwz|j}Wn
t�ypYnw|du�r�t|�j}	t�|dd|dd|dd|dd�} t�|dd|dd|dd|dd�}!| |!d }"nd!}"|�d"�}#d|_ g|_!g|_"g|_#g|_$g|_%g|_&|�'�}$|$�
t��}%d|%_(d#d$d%d%d&�}&|&|%_d}'d}(d})d}*d}+	t|t��r�z|d'}Wn
t�y
Ynw|j)�*d(|#�d},t|,t+��r-|,j,}|,j-}|,j.}-|,j/}d}nt|,t��r4	|�s;d|_0q	t1�}.||.d)<||.d*<||.d+<||.d,<|�2||.�|j dk�r\q|j �3��rcqd}/d}0d}1|j �4�}2|j �4d�}3d}4d-}5t5|2�D�]k\}6}7t6|7�}8t6|3|6�}9d}(d}:|8dk�r�|4};t|j"|;�}<t|j#|;�}=|=|<}>|/|>}/�n3|(|8k�r�|(}?|(|8k�r�|7|(}@|4|(};|j"|;}<|j!|;}Az|�7|A|@�\}B}C}DWnd}Cd}DY|*|C|D|<7}*|(d7}(|@�3��r�|@|5k�s�n|(|8k�s�d}E|*|k�r|?|:k�rd}End}E|?}(n|(|8k�rd}E|E�r�|%�
t��}Fd}*d})d|_d}+d}G|:}H|H|(k�rX|4|H};t|j"|;�}<t|j#|;�}=|=|<}>|>|Gk�rO|>}G|Hd}H|H|(k�s2|/|G}/t1�}I|/|Id.<|"|Id/<|:}H|H|(k�r�|4|H}'|j"|'}<|j!|'}A|j$|'}|7|H|Id0<|<|Id)<|A|Id*<|)|Id1<|�8|I|F�})|)}+|Hd}H|'d}'|H|(k�sn|(}:d}J|d2k�r�tt|�|+d3d4�}Jn|d5k�r�tt|�|+d4�}J|Jdu�r�|J|F_|0�r�|Gd6}1d}0|(|8k�s�|4|9}4|4}'�q|t|t|�|1fd4�}J�n	z|d7}Wn
t�yYnw	t1�}K||Kd)<||Kd*<||Kd8<||Kd9<||Kd:<||Kd+<d|_9|�:||K�|j dk�r4q|j �3��r;qd;d<�|j D�}Lt6|L�}M|%�
t��}Fd}(|(|Mk�rt|j%|(�}Nt|j&|(�}O|(|Mk�r|L|(}P|j"|(}Qt1�}I|P|Id0<|j!|(|Id*<|Q|Id)<|)|Id1<d|Id.<|"|Id/<|�8|I|F�})|)}+|)}*d}R|(d}S|S|Mk�r�d}Rnt|j%|S�|Nk�s�t|j&|S�|Ok�r�d}R|R�r�|j$|(}d}T|d=k�r�|N|+d3}Tn|d5k�r�|N|+}Tn|N}T|O}Ut|T|Ufd4�}J|J|F_|%�
t��}Fd|_d})|(d7}(n	|(d7}(|(|Mk�sg|(|Mk�sTt�}Jt6|F�dk�r|F�'�}$|$�;|F�|du�r't|�|J}Vn|J}V|V|%_|j<�s9|%�'�}$|$�;|%�|jj�sH|j<�rH|j�|�qdS)>zw
        recursively parse the full document and its children,
        looking for nodes that may contain text
        �
visibility�inherit)�hidden�collapseTzinkscape:labelzHershey TextFNr�r�r�rztranslate({0:.6E}, {1:.6E})z7Unable to process text. Consider unlinking cloned text.rz1.25�16px�drr�r��r�r�r�r(r)r*rHr+r%rr�r�z#000000r_�round)r�r�zstroke-linecapzstroke-linejoinr,z'/svg:svg//*[@id="%s"]/svg:flowRegion[1]rr�r&r'� rrr�r�centerrZr	r�r[r�r;r�r�cSsg|]}|�qSrDrD)�.0�qrDrDrE�
<listcomp>�sz4Hershey.recursively_traverse_svg.<locals>.<listcomp>�middle)=rLrrr�rr�r�hrefrmrr�r�r*r��setr1rr5r�r r	rr?rWr.r�r/r�r0r"r�r�r7r8r9r:r;r<r=r �labelr��
getElementr�left�toprwrvr2r,r2�isspace�
splitlines�	enumeraterlr�rr>r=�remover1)WrA�
anode_list�mat_current�parent_visibilityr��vis�_matrix�mat_new�
recurse_group�	ink_label�refnode�local_transformr�r��
_trans_string�
ref_transform�	ref_grouprD�start_x�start_yr&r�
bounding_rect�
rect_widthr�
text_align�hershey_ignorer9�font_height_tempr��line_spacing_temp�
transform2�scale_x�scale_y�scale_r�the_idrr�r��str_pos�i�w�w_temp�width_this_line�flowref�rect_heightr:�v�
first_line�y_offs_overall�
text_lines�extd_text_lines�str_pos_eol�nbspr>�	text_line�line_length�extd_line_length�
line_start�str_pos_temp�char_height�charline_spacing�char_v_spacing�
word_start�	character�char_familyrVr�r��render_line�
line_group�line_max_v_spacing�j�	char_datarrE�letter_vals�str_len�x_start_line�y_start_line�q_val�charfont_height�
set_alignment�i_next�x_shift�y_shift�resultrDrDrEr�s�


�

��




��
���


��
�

��
���$






�
�





�	




�
�

�

�j�








�
�F


������z Hershey.recursively_traverse_svgcCs�|jj�d�|j_|jj�d�|j_|jj�d�|j_|jj�d�|j_|jj�d�|j_gd�gd�g|_|��|�	�d|j
d}|jdur]|j|jkrW|j||_
n|j||_
|jjdkrjt�|j�n@|jjdkr�|jjd	kr{|��n/|��n*|jjr�|jjD]}|�|jj|�}|�|jj|g|�q�n
|�|j��|j�|jD]}|dur�|��}|dur�|�|�q�|jr�t�d
�|jr�t�d�dSdS)zE
        Main entry point; Execute the extension's function.
        r�rIrJr%g�@Nr�	utilitiesr#z)Warning: unable to load SVG stroke fonts.z�Warning: unable to convert text flowed into a frame.
Please use Text > Unflow to convert it prior to use.
If you are unable to identify the object in question, please contact technical support for help.)r�rrirrr"r$r�r�rrr0r/r@r*r��	help_textr�r��idsr!r��selectedr�rJrKr5r rcr.r2)rA�_rendered_stroke_scale�id_refr�element_to_removerrDrDrE�effect\sH


�

�
�zHershey.effect)�__name__�
__module__�__qualname__�__doc__r'rr�rTrWr�r�r�r�r�r�r�r�r�rrr!r2r=r�r��
__classcell__rDrDrBrEr@s@6
2)17Z5!@Sn
�_r�__main__)r�r�r��copyrr*rrrrrrr	r
rrr
rrrrrrrr�Effectrr��runrDrDrDrE�<module>s2 Dg�

Youez - 2016 - github.com/yon3zu
LinuXploit