U
    :vh8                     @   s  d Z ddlZddlZddlZddl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 zdd	lmZ W n* ek
r   ed
 dd	lmZ Y nX ddlmZ ddlmZmZmZmZmZmZmZ ddlm Z m!Z! ddl"m#Z# e$e%Z&ddiZ'dd Z(dddZ)e*dZ+e*dZ,e(G dd de-Z.e*dZ/ddddddd d!d"d#d$d%d&d'd(hZ0d)d*d+dd,d-d.d/Z1ej2d0 ej2d1 dej2d2Z3e(dod4d5Z4e(dpd7d8Z5e(d9d: Z6e(d;d< Z7e(d=d> Z8e7d?d@dAdBdCdDdEZ9e(dFdG Z:e(dHdI Z;e(dJdK Z<e(dLdM Z=e(dNdO fdPdQZ>e(dRdO fdSdTZ?dUdO dVdO dWdO dXdO dYdO dZdO d[dO d\dO d]dO d^dO d_dO d`Z@e(dadb ZAe(G dcdd ddZBe(dedf ZCG dgdh dheZDe(didj ZEG dkdl dlZFG dmdn dneZGdS )qz
Utilities to parse SVG graphics into fpdf.drawing objects.

The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.
    N)Number)
NamedTuple)
parse_path)BasePen   )PathPaintRule)
fromstringzYdefusedxml could not be imported - fpdf2 will not be able to sanitize SVG images provided)html)color_from_hex_stringcolor_from_rgb_stringGraphicsContextGraphicsStylePaintedPathClippingPath	Transform)
ImageCacheVectorImageInfo)stream_content_for_raster_imageforce_nodocumentFc                 C   s   dt | j< | S )zQA decorator that forces pdoc not to document the decorated item (class or method)F)__pdoc____qualname__)item r   ,/tmp/pip-unpacked-wheel-dvf6lv8i/fpdf/svg.pyr   -   s    
zhttp://www.w3.org/2000/svgzhttp://www.w3.org/1999/xlink)svgxlinkz(?:\s+,\s+|\s+,|,\s+|\s+|,)zx(matrix|rotate|scale|scaleX|scaleY|skew|skewX|skewY|translate|translateX|translateY)\(((?:\s*(?:[-+]?[\d\.]+,?)+\s*)+)\)c                   @   s   e Zd ZdZdS )Percentz$class to represent percentage valuesN)__name__
__module__r   __doc__r   r   r   r   r   A   s   r   z2\s*(?P<value>[-+]?[\d\.]+)\s*(?P<unit>%|[a-zA-Z]*)%emexchremvwvhZvminZvmaxcapZicZlhZrlhviZvbH   gbX<@gjZ@   g      ?gjZ?)incmmmptZpcZpxQih  i  )degZgradZradZturnr.   c                 C   s   t | }|dkr$td|  dd| \}}|s8|}zt|t|  W S  tk
r   |tkrvt|  d| dt|  d| dY nX dS )z7Convert a length unit to our canonical length unit, pt.NzUnable to parse 'z' as a lengthz" uses unsupported relative length z contains unrecognized unit )unit_splittermatch
ValueErrorgroupsfloatabsolute_length_unitsKeyErrorrelative_length_units)Z
length_strdefault_unitr2   valueunitr   r   r   resolve_lengthv   s     
r<   r0   c                 C   s\   t |  \}}|s|}zt|t|  W S  tk
rV   td|  d| dY nX dS )z;Convert an angle value to our canonical angle unit, radianszangle z has unknown unit N)r1   r2   r4   r5   angle_unitsr7   r3   )Z	angle_strr9   r:   r;   r   r   r   resolve_angle   s    r>   c                 C   s:   zdt |   d} W n tk
r,   d} Y nX |  | S )zECreate an XML namespace string representation for the given tag name.{} )_HANDY_NAMESPACESr7   )spacenamer   r   r   xmlns   s
    
rE   c                 G   s(   i }|D ]}||t | |< |||< q|S )z>Create a lookup for the given name in the given XML namespace.)rE   )rC   namesresultrD   r   r   r   xmlns_lookup   s
    
rH   c                 C   s&   |  d}|dkr"| |d d S | S )z8Remove the xmlns namespace from a qualified XML tag namer@   r   r   N)index)Zqualified_tagir   r   r   
without_ns   s    
rK   r   rectcircleellipselinepolylinepolygonc                 C   sZ   zt j|  } W n tk
r"   Y nX | dr6t| S | drHt| S td|  d S )N#Zrgbz unsupported color specification )r	   Z
COLOR_DICTr7   
startswithr
   r   r3   Zcolorstrr   r   r   svgcolor   s    

rU   c                 C   s0   t | }|dk r td|  d|dkr,d S |S )Nr   zstroke width z cannot be negative)r<   r3   incomingvalr   r   r   convert_stroke_width   s    rY   c                 C   s$   t | }|dk r td|  d|S )N      ?zmiter limit z cannot be less than 1)r5   r3   rV   r   r   r   convert_miterlimit   s    r[   c                    s    fdd}|S )Nc                    s$   t | }|k rS | kr  S |S Nr5   )r:   rX   max_valmin_valr   r   	converter   s    zclamp_float.<locals>.converterr   )r`   r_   ra   r   r^   r   clamp_float   s    rb   c                 C   s   | S r\   r   )r:   r   r   r   <lambda>       rc   c                 C   s   | dkrt jS || S )NZinherit)r   ZINHERITr:   ra   r   r   r   inheritable   s    rf   c                 C   s   | S r\   r   )Znoopr   r   r   rc      rd   c                 C   s   | dkrd S t | |S )Nnonerf   re   r   r   r   optional   s    ri   c                 C   s   dt | tfS )NZ
fill_colorri   rU   rT   r   r   r   rc     rd   c                 C   s   dt | fS )NZintersection_rulerh   )Zfillrulestrr   r   r   rc     rd   c                 C   s   dt | tddfS )Nfill_opacity        rZ   rf   rb   )Zfilopstrr   r   r   rc     s    c                 C   s   dt | tfS )NZstroke_colorrj   rT   r   r   r   rc     rd   c                 C   s   dt | tfS )Nstroke_width)rf   rY   )valuestrr   r   r   rc     s    c                 C   s   dt | dd fS )NZstroke_dash_patternc                 S   s   dd t | D S )Nc                 S   s   g | ]}t |qS r   r]   ).0r   r   r   r   
<listcomp>  s     z.<lambda>.<locals>.<lambda>.<locals>.<listcomp>)NUMBER_SPLITsplit)dar   r   r   rc     rd   z<lambda>.<locals>.<lambda>)ri   )Z	dasharrayr   r   r   rc     s     c                 C   s   dt | tfS )NZstroke_dash_phase)rf   r5   )Zdashoffr   r   r   rc     s    c                 C   s   dt | fS )Nstroke_cap_stylerh   )Zcapstrr   r   r   rc     rd   c                 C   s   dt | fS )NZstroke_join_stylerh   )Zjoinstrr   r   r   rc   !  rd   c                 C   s   dt | tfS )NZstroke_miter_limit)rf   r[   )Zlimstrr   r   r   rc   #  s    c                 C   s   dt | tddfS )Nstroke_opacityrl   rZ   rm   )Zstropstrr   r   r   rc   (  s    )fillz	fill-rulezfill-opacityZstrokezstroke-widthzstroke-dasharrayzstroke-dashoffsetzstroke-linecapzstroke-linejoinzstroke-miterlimitzstroke-opacityc                 C   s   t |jdd}d| j_t D ]4\}}|||j|}|r$t| jf||  q$|d|jd}|rt	|}|| j_
|| j_|jd}|rt|| _dS )zKApply the known styles from `svg_element` to the pdf path/group `stylable`.stylerA   Fopacity	transformN)r	   Zparse_css_styleattribgetrx   
auto_closesvg_attr_mapitemssetattrr5   rk   rv   convert_transformsrz   )stylablesvg_elementrx   	attr_namera   r:   ry   tfstrr   r   r   apply_styles/  s    r   c                   @   s   e Zd ZdZededddZededddZededdd	Z	ededd
dZ
edd Zedd ZededddZdS )ShapeBuilderzNA namespace within which methods for converting basic shapes can be looked up.F)clipping_pathc                 C   s   t  }|rt }t||  |S )z.Create a new path with the appropriate styles.)r   r   r   )tagr   pathr   r   r   new_pathK  s
    
zShapeBuilder.new_pathc           
      C   s  t |jdd}t |jdd}|jdd}|drNt|dd }nt |}|jdd}|drt|dd }nt |}|jd	d
}|jdd
}|dkrd}|dkrd}||  krd
krn n
d }}n>|d
krt| }}n(|d
krt| }}nt|}t|}|dk sD|dk sD|dk sD|dk rRtd| |dksf|dkrlt S ||d kr|d }||d kr|d }| ||}	|		|||||| |	S )z&Convert an SVG <rect> into a PDF path.x0ywidthr    Nheightrxautoryrg   r   z	bad rect    )
r<   r{   r|   endswithr   r5   r3   r   r   Z	rectangle)
clsr   r   r   r   r   r   r   r   r   r   r   r   rL   T  sF    



(zShapeBuilder.rectc                 C   sP   t |jdd}t |jdd}t |jd }| ||}|||| |S )z(Convert an SVG <circle> into a PDF path.cxr   cyr)r5   r{   r|   r   rM   )r   r   r   r   r   r   r   r   r   r   rM     s    zShapeBuilder.circlec                 C   s   t |jdd}t |jdd}|jdd}|jdd}| ||}||  kr`dksrn |dksr|dkrv|S |dkrt | }}n&|dkrt | }}nt |}t |}||||| |S )z)Convert an SVG <ellipse> into a PDF path.r   r   r   r   r   r   )r5   r{   r|   r   rN   )r   r   r   r   r   r   r   r   r   r   r   rN     s    &zShapeBuilder.ellipsec                 C   s^   t |jd }t |jd }t |jd }t |jd }| |}||| ||| |S )z&Convert an SVG <line> into a PDF path.x1y1x2y2)r5   r{   r   move_toline_to)r   r   r   r   r   r   r   r   r   r   rO     s    
zShapeBuilder.linec                 C   s&   |  |}d|jd  }t|| |S )z*Convert an SVG <polyline> into a PDF path.Mpointsr   r{   svg_path_converter)r   r   r   r   r   r   r   rP     s    

zShapeBuilder.polylinec                 C   s,   |  ||}d|jd  d }t|| |S )z)Convert an SVG <polygon> into a PDF path.r   r   Zr   )r   r   r   r   r   r   r   r   rQ     s    
zShapeBuilder.polygonN)F)F)F)F)F)r   r   r   r   staticmethodboolr   classmethodrL   rM   rN   rO   rP   rQ   r   r   r   r   r   G  s   0


r   c                 C   s<  t | }t }|D ]\}}|dkrdtdd t|D \}}}}}	}
t|||||	|
| }q|dkrt|^}}t|}tj|d}|rt	|dkr|
t|d t|d }ntd	| d
| d|| }q|dkrZt|}t	|dkrt|d }t|d }n.t	|dkr8t|d  }}ntd|  tj||d| }q|dkr|tjt|dd| }q|dkrtjdt|d| }q|dkr(t|}t	|dkrt|d }t|d }n.t	|dkrt|d }d}ntd|  tjt|t|d| }q|dkrPtjtt|dd| }q|dkrxtjdtt|d| }q|dkrt|}t	|dkrt|d }t|d }n.t	|dkrt|d }d}ntd|  tj||d| }q|dkrtjt|dd| }q|dkrtjdt|d| }q|S )z8Convert SVG/CSS transform functions into PDF transforms.Zmatrixc                 s   s   | ]}t |V  qd S r\   r]   )rp   nr   r   r   	<genexpr>  s     z%convert_transforms.<locals>.<genexpr>rotate)thetar   r   r   zrotation transform (z) is malformedscalezbad scale transform r   r   ZscaleXZscaleYZskewzbad skew transform ZskewXZskewY	translatezbad translation transform Z
translateXZ
translateY)TRANSFORM_GETTERfindallr   identitytuplerr   rs   r>   rotationlenaboutr5   r3   scalingZshearingmathtanr<   translation)r   parsedrz   Ztf_typeargsabcdefr   r   r   ZsxZsyr   r   r   r   r   r     sz    	
$






 




r   c                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )PathPenc                    s$   || _ d| _d | _t j|| d S )NF)pdf_pathlast_was_line_tofirst_is_movesuper__init__)selfr   r   kwargs	__class__r   r   r   +  s    zPathPen.__init__c                 C   s&   | j j|  d| _| jd kr"d| _d S )NFT)r   r   r   r   r   r.   r   r   r   _moveTo1  s    
zPathPen._moveToc                 C   s&   | j j|  d| _| jd kr"d| _d S )NTF)r   r   r   r   r   r   r   r   _lineTo7  s    
zPathPen._lineToc                 C   sJ   | j j|d |d |d |d |d |d d d| _| jd krFd| _d S )Nr   r   )r   r   r   r   Zx3Zy3F)r   Zcurve_tor   r   )r   pt1pt2Zpt3r   r   r   _curveToOne=  s         
zPathPen._curveToOnec                 C   s>   | j j|d |d |d |d d d| _| jd kr:d| _d S )Nr   r   )r   r   r   r   F)r   Zquadratic_curve_tor   r   )r   r   r   r   r   r   _qCurveToOneE  s    $
zPathPen._qCurveToOnec              	   C   s<   | j j||||||d |d d d| _| jd kr8d| _d S )Nr   r   )r   r   r   Z	large_arcZpositive_sweepr   r   F)r   Zarc_tor   r   )r   r   r   r   ZarcZsweependr   r   r   arcToK  s    	
zPathPen.arcToc                 C   s   | j r| j  | j  d S r\   )r   r   Zremove_last_path_elementclose)r   r   r   r   
_closePathY  s    
zPathPen._closePath)r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r   r   r   *  s   r   c                 C   s$   t | }t|| |js tdd S )Nz"Path does not start with move item)r   r   r   r3   )r   svg_pathZpenr   r   r   r   a  s    
r   c                   @   s   e Zd ZdZeddddZd(eddd	Zed
d Z	edd Z
edd Zd)ddZd*ddZd+ddZedd Zedd Zed,ddZedd Zed d! Zed"d# Zed$d% Zed&d' ZdS )-	SVGObjectzU
    A representation of an SVG that has been converted to a PDF representation.
    zutf-8encodingc             
   O   s:   t |d|d"}| | f||W  5 Q R  S Q R X dS )a  
        Create an `SVGObject` from the contents of the file at `filename`.

        Args:
            filename (path-like): the path to a file containing SVG data.
            *args: forwarded directly to the SVGObject initializer. For subclass use.
            encoding (str): optional charset encoding to use when reading the file.
            **kwargs: forwarded directly to the SVGObject initializer. For subclass use.

        Returns:
            A converted `SVGObject`.
        r   r   N)openread)r   filenamer   r   r   Zsvgfiler   r   r   	from_filen  s    zSVGObject.from_fileN)image_cachec                 C   sL   || _ i | _t|}|jtddkr4td|j | | | | d S )Nr   zroot tag must be svg, not )r   cross_referencesparse_xml_strr   rH   r3   extract_shape_infoconvert_graphics)r   Zsvg_textr   Zsvg_treer   r   r   r     s    
zSVGObject.__init__c                 C   s(   |r$| dsd| n|}|| j|< d S )NrR   )rS   r   )r   keyZ
referencedr   r   r   update_xref  s    zSVGObject.update_xrefc           
      C   s$  | d}| d}| d}| dd}|dkr:d| _nd| _d| _|dk	r~|  |drtt|dd	 | _n
t|| _d| _|dk	r|  |drt|dd	 | _n
t|| _|dkrd| _nT|  d
d t	
|D \}}}}	|dk s|	dk rtd| ||||	g| _dS )z&Collect shape info from the given SVG.r   r   viewBoxpreserveAspectRatioTrg   Nr    r   c                 S   s   g | ]}t |qS r   r]   )rp   numr   r   r   rq     s     z0SVGObject.extract_shape_info.<locals>.<listcomp>r   z)invalid negative width/height in viewbox )r|   preserve_arr   stripr   r   r<   r   viewboxrr   rs   r3   )
r   root_tagr   r   r   r   vxvyr%   r&   r   r   r   r     s4    






zSVGObject.extract_shape_infoc                 C   s4   t  }d|j_d|j_d|j_| || || _dS )zFConvert the graphics contained in the SVG into the PDF representation.NFZbutt)r   rx   rn   r}   ru   build_group
base_group)r   r   r   r   r   r   r     s    zSVGObject.convert_graphicsTc                 C   s   |  |j|j|j|S )a  
        Size the converted SVG paths to the page viewport.

        The SVG document size can be specified relative to the rendering viewport
        (e.g. width=50%). If the converted SVG sizes are relative units, then this
        computes the appropriate scale transform to size the SVG to the correct
        dimensions for a page in the current PDF document.

        If the SVG document size is specified in absolute units, then it is not scaled.

        Args:
            pdf (fpdf.FPDF): the pdf to use the page size of.
            align_viewbox (bool): if True, mimic some of the SVG alignment rules if the
                viewbox aspect ratio does not match that of the viewport.

        Returns:
            The same thing as `SVGObject.transform_to_rect_viewport`.
        )transform_to_rect_viewportkZepwZeph)r   pdfalign_viewboxr   r   r   transform_to_page_viewport  s    z$SVGObject.transform_to_page_viewportFc                 C   sr  |r
|}n2t | jtr2|s"td| j| d }n
| jp:|}|rF|}n2t | jtrn|s^td| j| d }n
| jpv|}|dkrt }ntd| }| jrV| j\}	}
}}|dks|dkrddt	 fS || }|| }|s| j
r||krt|| }}|tj|	 |
 d tj||d }|rV|tj|d |d |  |d |d |  d }|| j_|| || | jfS )a  
        Size the converted SVG paths to an arbitrarily sized viewport.

        The SVG document size can be specified relative to the rendering viewport
        (e.g. width=50%). If the converted SVG sizes are relative units, then this
        computes the appropriate scale transform to size the SVG to the correct
        dimensions for a page in the current PDF document.

        Args:
            scale (Number): the scale factor from document units to PDF points.
            width (Number): the width of the viewport to scale to in document units.
            height (Number): the height of the viewport to scale to in document units.
            align_viewbox (bool): if True, mimic some of the SVG alignment rules if the
                viewbox aspect ratio does not match that of the viewport.
            ignore_svg_top_attrs (bool): ignore <svg> top attributes like "width", "height"
                or "preserveAspectRatio" when figuring the image dimensions.
                Require width & height to be provided as parameters.

        Returns:
            A tuple of (width, height, `fpdf.drawing.GraphicsContext`), where width and
            height are the resolved width and height (they may be 0. If 0, the returned
            `fpdf.drawing.GraphicsContext` will be empty). The
            `fpdf.drawing.GraphicsContext` contains all of the paths that were
            converted from the SVG, scaled to the given viewport size.
        z?SVG "width" is a percentage, hence a viewport width is requiredd   zASVG "height" is a percentage, hence a viewport height is requiredr   r   r   r   )
isinstancer   r   r3   r   r   r   r   r   r   r   minr   r   rz   )r   r   r   r   r   Zignore_svg_top_attrsZvp_widthZ	vp_heightrz   r   r   r%   r&   Zw_ratioZh_ratior   r   r   r     sT    


z$SVGObject.transform_to_rect_viewportc           	   
   C   sz   |j | _ | |\}}}|j|j }}z@|dk	rX|dk	rX|dd |jt|| |_||| W 5 ||| X dS )a  
        Directly draw the converted SVG to the given PDF's current page.

        The page viewport is used for sizing the SVG.

        Args:
            pdf (fpdf.FPDF): the document to which the converted SVG is rendered.
            x (Number): abscissa of the converted SVG's top-left corner.
            y (Number): ordinate of the converted SVG's top-left corner.
            debug_stream (io.TextIO): the stream to which rendering debug info will be
                written.
        Nr   )	r   r   r   r   Zset_xyrz   r   r   Z	draw_path)	r   r   r   r   debug_stream_r   Zold_xZold_yr   r   r   draw_to_page0  s    zSVGObject.draw_to_pagec              	   C   s   |D ]}|j tddkr$| | q|j tddkr@| | q|j tddkr\| | q|j tkrr| | q|j tddkrz|jd }W n tk
r   d}Y nX |D ]}| 	|| qqt
dt|j  qdS )	z:Produce lookups for groups and paths inside the <defs> tagr   gr   imageclipPathidNTIgnoring unsupported SVG tag: <%s> (contributions are welcome to add support for it))r   rH   r   
build_pathbuild_image
shape_tagsbuild_shaper{   r7   build_clipping_pathLOGGERwarningrK   )r   defschildclip_idZchild_r   r   r   handle_defsM  s(    

zSVGObject.handle_defsc              	   C   s   t  }t|| tdddD ].}z|j| }W  q\W q tk
rH   Y qX qtd| dz|| j|  W n* tk
r   td| d| dY nX d|jksd	|jkrt|j	dd
t|j	d	d
 }}t
j||d|_|S )z?Resolve a cross-reference to an already-seen SVG element by ID.r   hrefr  zuse z% doesn't contain known xref attributez references nonexistent ref id Nr   r   r   r   )r   r   rH   r{   r7   r3   add_itemr   r5   r|   r   r   rz   )r   Zxref	pdf_group	candidaterefr   r   r   r   r   
build_xrefh  s*    


&zSVGObject.build_xrefc                 C   s6  |dkrt  }t|| dd |D D ]}| | q&|D ]}|jtddkrZ| | q:|jtddkr~|| |d q:|jtddkr|| |d q:|jtkr|| 	|d q:|jtdd	kr|| 
|d q:|jtdd
kr
|| |d q:tdt|j q:| |jd| |S )z+Handle nested items within a group <g> tag.Nc                 S   s    g | ]}|j td dkr|qS )r   r  )r   rH   )rp   r  r   r   r   rq     s     z)SVGObject.build_group.<locals>.<listcomp>r   r  r   Fr   Zuser   r  r  )r   r   r  r   rH   r  r   r  r  r  r  r  r	  r
  rK   r   r{   r|   )r   groupr  r  r   r   r   r     s4    


zSVGObject.build_groupc                 C   sR   t  }t|| | || |jd}|dk	r:t|| | |jd| |S )z1Convert an SVG <path> tag into a PDF path object.r   Nr  )r   r   apply_clipping_pathr{   r|   r   r   )r   r   r   r   r   r   r   r    s    

zSVGObject.build_pathc                 C   s<   t tt|j }||}| || | |jd| |S )zConvert an SVG shape tag into a PDF path object. Necessary to make xref (because ShapeBuilder doesn't have access to this object.)r  )getattrr   r  r   r  r   r{   r|   )r   shapeshape_builderZ
shape_pathr   r   r   r    s
    zSVGObject.build_shapec                 C   s   |j tkr&ttt|j  }||d}n^|j tddkrnt }t|| tj|_	|j
d}|d k	rt|| ntdt|j  d S | || d S )NTr   r   r   zaIgnoring unsupported <clipPath> child tag: <%s> (contributions are welcome to add support for it))r   r  r  r   rH   r   r   r   Z
DONT_PAINTZ
paint_ruler{   r|   r   r	  r
  rK   r   )r   r  r  r  Zclipping_path_shaper   r   r   r   r    s     

zSVGObject.build_clipping_pathc                 C   s0   |j d}|r,td|}| j|d  |_d S )Nz	clip-pathzurl\((\#\w+)\)r   )r{   r|   researchr   r   )r   r   r   r   Zclipping_path_idr   r   r   r    s    zSVGObject.apply_clipping_pathc                 C   s   d }t ddD ]}||jkr|j| } q,q|s8tdt|jdd}t|jdd}d|jkrptd d	|jkrtd
 d|jkrtd t|t|jddt|jdd||| d}| |jd| |S )Nr   r  z#<image> is missing a href attributer   r   r   r   zu"preserveAspectRatio" defined on <image> is currently not supported (contributions are welcome to add support for it)rx   zg"style" defined on <image> is currently not supported (contributions are welcome to add support for it)rz   zk"transform" defined on <image> is currently not supported (contributions are welcome to add support for it)r   r   r   r  r   r   r   r   svg_objr  )	rH   r{   r3   r5   r|   r	  r
  SVGImager   )r   r   r  r   r   r   Z	svg_imager   r   r   r    s>    




zSVGObject.build_image)N)T)TF)NNN)N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r  r  r  r  r   r   r   r   r   i  s>   

'

   
T


#



r   c                   @   s^   e Zd ZU eed< eed< eed< eed< eed< eed< dd Zed	d
 Z	edd Z
dS )r  r  r   r   r   r   r  c                 C   s    t | j| j| j| j| j| jdS )Nr  )r  r  r   r   r   r   r  )r   Z_memor   r   r   __deepcopy__  s    zSVGImage.__deepcopy__c                 C   s   | j o| j j}|stdddlm} ||| j\}}}t|trVt	d d||fS |
| j| j\}	}
t|| j| j|	|
dd}|||fS )NzHfpdf2 bug - Cannot render a raster image without a SVGObject.image_cacher   )preload_imagez{Inserting .svg vector graphics in <image> tags is currently not supported (contributions are welcome to add support for it)rA   T)infor   r   whZkeep_aspect_ratio)r  r   AssertionErrorZimage_parsingr   r  r   r   r	  r
  Zsize_in_document_unitsr   r   r   r   r   )r   Z_gsd_registry_style	last_iteminitial_pointr   r   r   r!  r"  r#  stream_contentr   r   r   render  s,    

zSVGImage.renderc                 C   s8   |  ||||\}}}|| j d| d |||fS )Nz rendered as: 
)r)  writer  )r   Zgsd_registryrx   r&  r'  r   Z_pfxr(  r   r   r   render_debug/  s       
zSVGImage.render_debugN)r   r   r   str__annotations__r   r   r  r   r)  r,  r   r   r   r   r    s   

r  )r.   )r0   )Hr   loggingr   r  warningsZnumbersr   typingr   ZfontTools.svgLib.pathr   ZfontTools.pens.basePenr   enumsr   Zdefusedxml.ElementTreer   r   ImportErrorwarnxml.etree.ElementTreerA   r	   Zdrawingr
   r   r   r   r   r   r   Zimage_datastructuresr   r   outputr   	getLoggerr   r	  r   r   rB   compilerr   r   r5   r   r1   r8   r6   taur=   r<   r>   rE   rH   rK   r  rU   rY   r[   rb   rf   ri   r~   r   r   r   r   r   r   r  r   r   r   r   <module>   s    $	
	





      




/

b7
   