
    BPcC                       d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZ d	d
lmZmZ d	dlmZ  G d d          Z G d de          Z G d dee          Z G d de          Z G d de          Z G d de          Z G d dee          Z G d dee          Z G d dee          Z G d de          Z G d  d!e          Z G d" d#e          Z G d$ d%e          Z d&S )'z
Provide text based element classes interface.

Because text is not rendered at all, no information about a text's path
size or actual location can be generated yet.
    )annotations)TemporaryDirectory   )BaseElementProtocolPath)	TransformBoundingBox)inkscape	write_svg   )BaseElementShapeElement)PathElementBasec                      e Zd ZdZddZdS )	TextBBMixinzHMixin to query the bounding box from Inkscape

    .. versionadded:: 1.2selfr   returnr
   c           
        t          d          5 }t          | j        |d          }t          |dddd|                                           }t          t          | j        j        |                                                    }t          |          d	k    rt          d
          t          j        | cddd           S # 1 swxY w Y   dS )zsQuery the bbbox of a single object. This calls the Inkscape command,
        so it is rather slow to use in a loop.zinkscape-command)prefixz	input.svgz-Xz-Yz-Wz-H)query_id   z&Error: Bounding box computation failedN)r   r   rootr   get_idlistmapviewport_to_unit
splitlineslen
ValueErrorr
   new_xywh)r   tmpdirsvg_fileouts       6/usr/share/inkscape/extensions/inkex/elements/_text.pyget_inkscape_bboxzTextBBMixin.get_inkscape_bbox,   s      '9::: 	.f FK@@H8T4tdkkmmTTTCs495s~~7G7GHHIIC3xx1}} !IJJJ'-	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   B&CCCN)r   r   r   r
   )__name__
__module____qualname____doc__r&        r%   r   r   '   s2         	. 	. 	. 	. 	. 	.r,   r   c                      e Zd ZdZdZd ZdS )
FlowRegionzSVG Flow Region (SVG 2.0)
flowRegionc                N    t          d | D             t                                S )Nc                    g | ]	}|j         
S r+   )path).0childs     r%   
<listcomp>z'FlowRegion.get_path.<locals>.<listcomp>?   s    1115EJ111r,   )sumr   r   s    r%   get_pathzFlowRegion.get_path=   s%    11D111466:::r,   Nr'   r(   r)   r*   tag_namer8   r+   r,   r%   r.   r.   8   s.        ##H; ; ; ; ;r,   r.   c                  2    e Zd ZdZdZed             Zd ZdS )FlowRootzSVG Flow Root (SVG 2.0)flowRootc                ,    |                      d          S )z,Return the first flowRegion in this flowRootzsvg:flowRegion)findoner7   s    r%   regionzFlowRoot.regionG   s     ||,---r,   c                X    | j         }||                                nt                      S N)r@   r8   r   )r   r@   s     r%   r8   zFlowRoot.get_pathL   s'    $*$6v   DFFBr,   N)r'   r(   r)   r*   r:   propertyr@   r8   r+   r,   r%   r<   r<   B   sL        !!H. . X.C C C C Cr,   r<   c                      e Zd ZdZdZd ZdS )FlowParazSVG Flow Paragraph (SVG 2.0)flowParac                    t                      S rB   r   r7   s    r%   r8   zFlowPara.get_pathV       vvr,   Nr9   r+   r,   r%   rE   rE   Q   s.        &&H    r,   rE   c                      e Zd ZdZdZd ZdS )FlowDivzSVG Flow Div (SVG 2.0)flowDivc                    t                      S rB   r   r7   s    r%   r8   zFlowDiv.get_path`   rH   r,   Nr9   r+   r,   r%   rJ   rJ   [   s.          H    r,   rJ   c                      e Zd ZdZdZd ZdS )FlowSpanzSVG Flow Span (SVG 2.0)flowSpanc                    t                      S rB   r   r7   s    r%   r8   zFlowSpan.get_pathj   rH   r,   Nr9   r+   r,   r%   rN   rN   e   s.        !!H    r,   rN   c                  b    e Zd ZdZdZ ed           Z ed           Zd Zd Z	ddZ
dd
Zd	S )TextElementzA Text elementtextc                T    |                      |                     dd                    S Nxr   to_dimensionlessgetr7   s    r%   <lambda>zTextElement.<lambda>s   "    d33DHHS!4D4DEE r,   c                T    |                      |                     dd                    S Nyr   rW   r7   s    r%   rZ   zTextElement.<lambda>t   r[   r,   c                    t                      S rB   r   r7   s    r%   r8   zTextElement.get_pathv       vvr,   c                ,    |                      d          S )z,Returns all children that are tspan elementsz	svg:tspan)findallr7   s    r%   tspanszTextElement.tspansy   s    ||K(((r,   
c                    | gt          |                                           z   }|                    d |D                       S )z(Return the text content including tspansc                *    g | ]}|j         	|j         S rB   )rS   )r3   elems     r%   r5   z(TextElement.get_text.<locals>.<listcomp>   s!    NNNt	8M8M8M8Mr,   )r   rc   join)r   sepnodess      r%   get_textzTextElement.get_text}   s?    dkkmm,,,xxNNuNNNOOOr,   Nc                    t          |          | j        z  }|                    | j        | j        f          \  }}t          ||          }|                                 D ]}||                    |          z  }|S )
        Returns a horrible bounding box that just contains the coord points
        of the text without width or height (which is impossible to calculate)
        )r	   	transformapply_to_pointrV   r^   r
   rc   bounding_box)r   rn   effective_transformrV   r^   bboxtspans          r%   	shape_boxzTextElement.shape_box   s    
 (	22T^C"1146462BCC11a  [[]] 	< 	<EE&&':;;;DDr,   )rd   rB   )r'   r(   r)   r*   r:   rC   rV   r^   r8   rc   rk   rt   r+   r,   r%   rR   rR   o   s        HEEFFAEEFFA  ) ) )P P P P

 
 
 
 
 
r,   rR   c                      e Zd ZdZdZd ZdS )TextPathzA textPath elementtextPathc                    t                      S rB   r   r7   s    r%   r8   zTextPath.get_path   r`   r,   Nr9   r+   r,   r%   rv   rv      s.        H    r,   rv   c                  j    e Zd ZdZdZ ed           Z ed           Zed             Z	d Z
d	dZdS )
TspanzA tspan text elementrs   c                T    |                      |                     dd                    S rU   rW   r7   s    r%   rZ   zTspan.<lambda>   r[   r,   c                T    |                      |                     dd                    S r]   rW   r7   s    r%   rZ   zTspan.<lambda>   r[   r,   c                     | |d          S )z Adds a superscript tspan elementz"font-size:65%;baseline-shift:super)styler+   )clsrS   s     r%   superscriptzTspan.superscript   s     s4CDDDDr,   c                    t                      S rB   r   r7   s    r%   r8   zTspan.get_path   r`   r,   Nc                r   t          |          | j        z  }|                    | j        | j        f          \  }}|                     | j                            dd                    }| j        dz   }| j        t          |          z   }|                    ||f          \  }}t          ||f||f          S )rm   z	font-size12pxr   )
r	   rn   ro   rV   r^   rX   r~   rY   floatr
   )r   rn   rq   x1y1fontsizex2y2s           r%   rt   zTspan.shape_box   s    
 (	22T^C$33TVTV4DEEB((V)L)LMMVaZVeHoo%$33RH==BB8b"X...r,   rB   )r'   r(   r)   r*   r:   rC   rV   r^   classmethodr   r8   rt   r+   r,   r%   rz   rz      s        HEEFFAEEFFAE E [E  / / / / / /r,   rz   c                      e Zd ZdZdZdS )SVGfontzAn svg font elementfontNr'   r(   r)   r*   r:   r+   r,   r%   r   r      s        HHHr,   r   c                      e Zd ZdZdZdS )FontFacezAn svg font font-face elementz	font-faceNr   r+   r,   r%   r   r      s        ''HHHr,   r   c                      e Zd ZdZdZdS )GlyphzAn svg font glyph elementglyphNr   r+   r,   r%   r   r      s        ##HHHr,   r   c                      e Zd ZdZdZdS )MissingGlyphz!An svg font missing-glyph elementzmissing-glyphNr   r+   r,   r%   r   r      s        ++HHHr,   r   N)!r*   
__future__r   tempfiler   interfaces.IElementr   pathsr   
transformsr	   r
   commandr   r   _baser   r   	_polygonsr   r   r.   r<   rE   rJ   rN   rR   rv   rz   r   r   r   r   r+   r,   r%   <module>r      s  *  # " " " " " ' ' ' ' ' ' 5 5 5 5 5 5       / / / / / / / / ) ) ) ) ) ) ) ) , , , , , , , , & & & & & &. . . . . . . ."; ; ; ; ; ; ; ;C C C C C|[ C C C    |       l       |       ,   @    |[   / / / / /L+ / / /:    k       {       O       ;     r,   