
    Og(#                    8   U d dl mZ d dlmZmZmZ d dlmZmZ d dl	Z
d dlmZ d dlZd dlmZ d dlmZ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mZ eZded<   eZ ded<   g dZ!ejD                   G d d             Z# G d de      Z$ G d de$e      Z%ddZ&y)    )annotations)ABCabstractmethodABCMeta)OptionalIterableN)	TypeAlias)Configuration)
PropertiesBackendProperties)Color)
DXFGraphic)Vec2Matrix44)NumpyPath2dNumpyPoints2dsingle_pathsr	   BkPath2d
BkPoints2d)      ?        r   r   r   g      r   r   r   r   r   r   r   i  r   r   c                  \    e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZd	ed<   ddZddZy)	ImageDataa  Image data.

    Attributes:
        image: an array of RGBA pixels
        transform: the transformation to apply to the image when drawing
            (the transform from pixel coordinates to wcs)
        pixel_boundary_path: boundary path vertices in pixel coordinates, the image
            coordinate system has an inverted y-axis and the top-left corner is (0, 0)
        remove_outside: remove image outside the clipping boundary if ``True`` otherwise
            remove image inside the clipping boundary

    z
np.ndarrayimager   	transformr   pixel_boundary_pathFbooluse_clipping_boundaryTremove_outsidec                <    | j                   j                  ^}}}||fS )z0Returns the image size as tuple (width, height).)r   shape)selfimage_heightimage_width_s       a/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/drawing/backend.py
image_sizezImageData.image_size4   s#    (,

(8(8%kAL((    c                X    | j                         \  }}|t        d<   t        t              S )zeReturns the transformation matrix to align the image coordinate system with
        the WCS.
           )r'   _IMAGE_FLIP_MATRIXr   )r"   r%   r#   s      r&   flip_matrixzImageData.flip_matrix9   s+     //+<!-2*++r(   N)returnztuple[int, int])r-   r   )	__name__
__module____qualname____doc____annotations__r   r   r'   r,    r(   r&   r   r      s:     &&"'4'ND)
,r(   r   c                     e Zd ZdZedd       Zedd       Zedd       Zedd       Zedd       Z	edd       Z
e	 	 	 	 	 	 dd       Zedd	       Ze	 	 	 	 	 	 dd
       Ze	 	 	 	 	 	 dd       Zedd       Zedd       Zedd       Zy)BackendInterfacez+Public interface for 2D rendering backends.c                    t         NNotImplementedErrorr"   configs     r&   	configurezBackendInterface.configureE       !!r(   c                    t         r7   r8   r"   entity
propertiess      r&   enter_entityzBackendInterface.enter_entityI   
     "!r(   c                    t         r7   r8   )r"   r@   s     r&   exit_entityzBackendInterface.exit_entityN   r=   r(   c                    t         r7   r8   r"   colors     r&   set_backgroundzBackendInterface.set_backgroundR   r=   r(   c                    t         r7   r8   r"   posrA   s      r&   
draw_pointzBackendInterface.draw_pointV   r=   r(   c                    t         r7   r8   r"   startendrA   s       r&   	draw_linezBackendInterface.draw_lineZ   r=   r(   c                    t         r7   r8   )r"   linesrA   s      r&   draw_solid_linesz!BackendInterface.draw_solid_lines^   
     "!r(   c                    t         r7   r8   )r"   pathrA   s      r&   	draw_pathzBackendInterface.draw_pathd   r=   r(   c                    t         r7   r8   )r"   pathsrA   s      r&   draw_filled_pathsz"BackendInterface.draw_filled_pathsh   rV   r(   c                    t         r7   r8   r"   pointsrA   s      r&   draw_filled_polygonz$BackendInterface.draw_filled_polygonn   rV   r(   c                    t         r7   r8   r"   
image_datarA   s      r&   
draw_imagezBackendInterface.draw_imaget   r=   r(   c                    t         r7   r8   r"   s    r&   clearzBackendInterface.clearx   r=   r(   c                    t         r7   r8   rf   s    r&   finalizezBackendInterface.finalize|   r=   r(   Nr;   r
   r-   Noner@   r   rA   r   r-   rk   r@   r   r-   rk   rH   r   r-   rk   rL   r   rA   r   r-   rk   rP   r   rQ   r   rA   r   r-   rk   rT   zIterable[tuple[Vec2, Vec2]]rA   r   r-   rk   rX   r   rA   r   r-   rk   r[   Iterable[BkPath2d]rA   r   r-   rk   r_   r   rA   r   r-   rk   rc   r   rA   r   r-   rk   r-   rk   )r.   r/   r0   r1   r   r<   rB   rE   rI   rM   rR   rU   rY   r\   r`   rd   rg   ri   r3   r(   r&   r5   r5   B   sO   5" " " " " " " " " " " " "0">O"	" "
 " " "'"5F"	" "
 " ".?"	" "
 " " " " " "r(   r5   c                      e Zd ZddZddZddZddZedd       Ze	dd       Z
e	dd       Ze	dd       Z	 	 	 	 	 	 dd	Zdd
Z	 	 	 	 	 	 ddZe		 	 	 	 	 	 dd       Ze	dd       Ze	dd       ZddZy)Backendc                0    g | _         t               | _        y r7   )entity_stackr
   r;   rf   s    r&   __init__zBackend.__init__   s    AC%2_r(   c                    || _         y r7   )r;   r:   s     r&   r<   zBackend.configure   s	    r(   c                >    | j                   j                  ||f       y r7   )r{   appendr?   s      r&   rB   zBackend.enter_entity   s      &*!56r(   c                T    | j                   j                         \  }}||u sJ d       y )Nzentity stack mismatch)r{   pop)r"   r@   eps       r&   rE   zBackend.exit_entity   s,      $$&1F{333{r(   c                B    | j                   r| j                   d   d   S dS )z%Obtain the current entity being drawnr   N)r{   rf   s    r&   current_entityzBackend.current_entity   s'     ,0+<+<t  $Q'F$Fr(   c                    t         r7   r8   rG   s     r&   rI   zBackend.set_background   r=   r(   c                    t         )zeDraw a real dimensionless point, because not all backends support
        zero-length lines!
        r8   rK   s      r&   rM   zBackend.draw_point   s
    
 "!r(   c                    t         r7   r8   rO   s       r&   rR   zBackend.draw_line   r=   r(   c                    |D ]<  \  }}|j                  |      r| j                  ||       *| j                  |||       > y)zDFast method to draw a bunch of solid lines with the same properties.N)iscloserM   rR   )r"   rT   rA   sr   s        r&   rU   zBackend.draw_solid_lines   s@      	1DAqyy|:.q!Z0		1r(   c                    t        |      rWt        |j                  | j                  j                              }t        |      }|D ]  }| j                  |||       |} yy)ah  Draw an outline path (connected string of line segments and Bezier
        curves).

        The :meth:`draw_path` implementation is a fall-back implementation
        which approximates Bezier curves by flattening as line segments.
        Backends can override this method if better path drawing functionality
        is available for that backend.

        distanceN)leniter
flatteningr;   max_flattening_distancenextrR   )r"   rX   rA   verticesprevvertexs         r&   rY   zBackend.draw_path   sa     t9)L)LMH >D" tVZ8 r(   c                    |D ]A  }| j                  t        |j                  | j                  j                              |       C y)ar  Draw multiple filled paths (connected string of line segments and
        Bezier curves).

        The current implementation passes these paths to the backend, all backends
        included in ezdxf handle holes by the even-odd method.  If a backend requires
        oriented paths (exterior paths in counter-clockwise and holes in clockwise
        orientation) use the function :func:`oriented_paths` to separate and orient the
        input paths.

        The default implementation draws all paths as filled polygons.

        Args:
            paths: sequence of paths
            properties: HATCH properties

        r   N)r`   r   r   r;   r   )r"   r[   rA   rX   s       r&   r\   zBackend.draw_filled_paths   sF    &  	D$$OOT[[-P-POQ 		r(   c                    t         )zFill a polygon whose outline is defined by the given points.
        Used to draw entities with simple outlines where :meth:`draw_path` may
        be an inefficient way to draw such a polygon.
        r8   r^   s      r&   r`   zBackend.draw_filled_polygon   s
     "!r(   c                    t         )z$Draw an image with the given pixels.r8   rb   s      r&   rd   zBackend.draw_image   rC   r(   c                    t         )zClear the canvas. Does not reset the internal state of the backend.
        Make sure that the previous drawing is finished before clearing.

        r8   rf   s    r&   rg   zBackend.clear   s
     "!r(   c                     y r7   r3   rf   s    r&   ri   zBackend.finalize   s    r(   Nrw   rj   rl   rm   )r-   zOptional[DXFGraphic]rn   ro   rp   rq   rr   rs   ru   rv   )r.   r/   r0   r|   r<   rB   rE   propertyr   r   rI   rM   rR   rU   rY   r\   r`   rd   rg   ri   r3   r(   r&   ry   ry      s    574 G G " " " " " "101>O1	1&'5F	6 " ".?"	" " " " " "r(   ry   )	metaclassc                    ddl m}m}  |t        |             } ||      \  }}|D ]  }|j	                           |D ]  }|j                           ||fS )zSeparate paths into exterior paths and holes. Exterior paths are oriented
    counter-clockwise, holes are oriented clockwise.
    r   )winding_deconstructionmake_polygon_structure)
ezdxf.pathr   r   r   counter_clockwise	clockwise)r[   r   r   polygonsexternal_pathsholesr   s          r&   oriented_pathsr      sf     J%l5&9:H 38<NE 	 	5  r(   )r[   rt   r-   z%tuple[list[BkPath2d], list[BkPath2d]])'
__future__r   abcr   r   r   typingr   r   numpynptyping_extensionsr	   dataclassesezdxf.addons.drawing.configr
   ezdxf.addons.drawing.propertiesr   r   ezdxf.addons.drawing.type_hintsr   ezdxf.entitiesr   
ezdxf.mathr   r   ezdxf.npshapesr   r   r   r   r2   r   r+   	dataclassr   r5   ry   r   r3   r(   r&   <module>r      s    # , , %  '  5 I 1 % % C C!) !%
I %  , , ,D<"s <"~w' wt!r(   