
    Ogz0                    Z   d dl mZ d dlmZ d dlZd dlmZmZmZ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 d d	lmZ d d
lmZ d dlmZ g dZeeef   ZdZdej:                  d df	 	 	 	 	 	 	 	 	 	 	 ddZdej:                  d df	 	 	 	 	 	 	 	 	 	 	 ddZd dZ d!d"dZ!	 	 	 	 	 	 	 	 	 	 d#dZ"	 	 	 	 	 	 	 	 	 	 d$dZ#dej:                  d ddf	 	 	 	 	 	 	 	 	 	 	 d%dZ$d Z%d&dZ&d'dZ'd(dZ(ejR                   G d dejT                               Z+e+jX                  fd)dZ-e+jX                  dfd)dZ.y)*    )annotations)UnionN)TextAttribHatch
DXFGraphic)const)TextEntityAlignmentMAP_TEXT_ENUM_TO_ALIGN_FLAGS)Matrix44BoundingBox)path)Path)fonts)EntityQuery)	make_path_from_strmake_paths_from_strmake_hatches_from_strmake_path_from_entitymake_paths_from_entitymake_hatches_from_entityvirtual_entitiesexplodeKind)TEXTATTRIB      ?c                   t        |       dk(  r
t               S t        |      }t        | ||      }t	        j
                  |gd      }|j                  j                  |      }	t        |	|||      }
||
|z  }
|j                  |
      S )a  Convert a single line string `s` into a :term:`Multi-Path` object.
    The text `size` is the height of the uppercase letter "X" (cap height).
    The paths are aligned about the insertion point at (0, 0).
    BASELINE means the bottom of the letter "X".

    Args:
         s: text to convert
         font: font face definition as :class:`~ezdxf.tools.fonts.FontFace` object
         size: text size (cap height) in drawing units
         align: alignment as :class:`ezdxf.enums.TextEntityAlignment`,
            default is :attr:`LEFT`
         length: target length for the :attr:`ALIGNED` and :attr:`FIT` alignments
         m: transformation :class:`~ezdxf.math.Matrix44`

    r   T)fast)
lenr   get_font_str_to_pathr   bboxmeasurementsscale_from_baselinealignment_transformation	transform)sfontsizealignlengthmabstract_fontpr#   draw_units_fmmatrixs              [/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/text2path.pyr   r       s    . 1v{vTNMQt,A99aSt$D "..BB4HM%mT5&IF}!;;v    c                t    t        |       dk(  rg S t        | |||||      }t        |j                               S )a  Convert a single line string `s` into a list of
    :class:`~ezdxf.path.Path` objects. All paths are returned as a list of
    :term:`Single-Path` objects.
    The text `size` is the height of the uppercase letter "X" (cap height).
    The paths are aligned about the insertion point at (0, 0).
    BASELINE means the bottom of the letter "X".

    Args:
         s: text to convert
         font: font face definition as :class:`~ezdxf.tools.fonts.FontFace` object
         size: text size (cap height) in drawing units
         align: alignment as :class:`ezdxf.enums.TextEntityAlignment`,
            default is :attr:`LEFT`
         length: target length for the :attr:`ALIGNED` and :attr:`FIT` alignments
         m: transformation :class:`~ezdxf.math.Matrix44`

    r   )r    r   list	sub_paths)r(   r)   r*   r+   r,   r-   r/   s          r2   r   r   G   s9    2 1v{	1dD%;Ar3   c                n    t         j                  j                  |       }t        j                  |d      S )Nr   
cap_height)r   font_managerfind_font_name	make_font)r)   	font_names     r2   r!   r!   f   s)    ""11$7I??955r3   c                D    |j                  | |      j                         S )Nr8   )text_path_exto_path)r(   render_enginer*   s      r2   r"   r"   k   s!    %%aD%9AACCr3   c                6   t         |   \  }}t        | |||      }d}d}|t        j                  k(  r||j                  j
                  z  }|}n,|t        j                  k(  r||j                  j
                  z  }|dk7  r|t        j                  ||d      z  }|S )a  Returns the alignment transformation matrix to transform a basic
    text path at location (0, 0) and alignment :attr:`LEFT` into the final text
    path of the given alignment.
    For the alignments :attr:`FIT` and :attr:`ALIGNED` defines the argument
    `length` the  total length of the final text path. The given bounding box
    defines the rendering borders of the basic text path.

    r   )	r   basic_alignment_transformationr
   ALIGNEDr*   xFITr   scale)	fmr#   r+   r,   halignvalignr1   	stretch_x	stretch_ys	            r2   r&   r&   o   s     2%8NFF+BffEFII#+++TYY[[(			%))	)TYY[[(	C(..Is;;Mr3   c                   |t         j                  k(  rd}n|t         j                  k(  r+|j                  J d       |j                  j                   }nQ|t         j
                  k(  s|dkD  r+|j                  J d       |j                  j                   }nt        d|       | j                  }| j                  }|t         j                  k(  rd}nU|t         j                  k(  r| }n>|t         j                  k(  r| dz  }n$|t         j                  k(  r|}nt        d|       |dk(  r| | j                  dz  z   }t        j                   ||d      S )	Ng        zinvalid empty bounding box   zinvalid halign argument: zinvalid valign argument:    g       @r   )r	   LEFTRIGHTextmaxrE   CENTERcenter
ValueErrorr9   descender_heightBASELINETOPMIDDLEBOTTOMtotal_heightr   	translate)rH   r#   rI   rJ   shift_xr9   rV   shift_ys           r2   rC   rC      s5    	5;;	{{&D(DD&;;==.	5<<	6A:{{&D(DD&;;==.4VH=>>J**	599	+	5<<	+/	5<<	"4VH=>>{+# 55gw22r3   c                   t        |      }|j                  t        j                  j                  u rg S t        | ||||      }t        |xs i       }|j                  dd       |j                  dd       |j                  dt        j                         t        j                  |d|      }	||	D 
cg c]  }
|
j                  |       c}
S t        |	      S c c}
w )a  Convert a single line string `s` into a list of virtual
    :class:`~ezdxf.entities.Hatch` entities.
    The text `size` is the height of the uppercase letter "X" (cap height).
    The paths are aligned about the insertion point at (0, 0).
    The HATCH entities are aligned to this insertion point. BASELINE means the
    bottom of the letter "X".

    .. important::

        Returns an empty list for .shx, .shp and .lff fonts a.k.a. stroke fonts.

    Args:
         s: text to convert
         font: font face definition as :class:`~ezdxf.tools.fonts.FontFace` object
         size: text size (cap height) in drawing units
         align: alignment as :class:`ezdxf.enums.TextEntityAlignment`,
            default is :attr:`LEFT`
         length: target length for the :attr:`ALIGNED` and :attr:`FIT` alignments
         dxfattribs: additional DXF attributes
         m: transformation :class:`~ezdxf.math.Matrix44`

    
solid_fill   pattern_nameSOLIDcolorT)	edge_path
dxfattribs)r!   font_render_typer   FontRenderTypeSTROKEr   dict
setdefaultr	   BYLAYERr   
to_hatchesr'   r5   )r(   r)   r*   r+   r,   rf   r-   font_pathshatcheshatchs              r2   r   r      s    > TNE!5!5!<!<<	  4uf=Ej&B'J,*.'2'5==1ooet
KG}078u"88G} 9s   4Cc                    | t        d      | j                         t        vrt        d| j                                y )Nzentity is Nonezunsupported entity type: )	TypeErrordxftypeVALID_TYPESentitys    r2   check_entity_typerx      sB    ~())^^,3FNN4D3EFGG -r3   c                <   t        |        | j                         }t        |t        j                  | j                               | j                  j                  | j                         | j                               }| j                         }|j                  |      S )zConvert text content from DXF entities TEXT and ATTRIB into a
    :term:`Multi-Path` object.
    The paths are located at the location of the source entity.
    )r*   r+   r,   )rx   
plain_textr   r   get_font_facer=   dxfheightget_align_enum
fit_lengthwcs_transformation_matrixr'   )rw   textr/   r-   s       r2   r   r      s     fDF,,./ZZ##%  "	A 	((*A;;q>r3   c                F    t        t        |       j                               S )zConvert text content from DXF entities TEXT and ATTRIB into a
    list of :class:`~ezdxf.path.Path` objects. All paths are returned as a
    list of :term:`Single-Path` objects.
    The paths are located at the location of the source entity.

    )r5   r   r6   rv   s    r2   r   r      s     %f-779::r3   c                    t        |        | j                  j                  }| j                         }t	        |       }t        t        j                  |d||            S )a   Convert text content from DXF entities TEXT and ATTRIB into a
    list of virtual :class:`~ezdxf.entities.Hatch` entities.
    The hatches are placed at the same location as the source entity and have
    the same DXF attributes as the source entity.

    T)re   	extrusionrf   )rx   r|   r   graphic_propertiesr   r5   r   rm   )rw   r   attribsro   s       r2   r   r      sX     f

$$I'')G"6*E		
 r3   c                      e Zd ZdZdZdZdZy)r   a  The :class:`Kind` enum defines the DXF types to create as bit flags,
    e.g. 1+2 to get HATCHES as filling and SPLINES and POLYLINES as outline:

    === =========== ==============================
    Int Enum        Description
    === =========== ==============================
    1   HATCHES     :class:`~ezdxf.entities.Hatch` entities as filling
    2   SPLINES     :class:`~ezdxf.entities.Spline` and 3D :class:`~ezdxf.entities.Polyline`
                    entities as outline
    4   LWPOLYLINES :class:`~ezdxf.entities.LWPolyline` entities as approximated
                    (flattened) outline
    === =========== ==============================

    ra   rN   rO   N)__name__
__module____qualname____doc__HATCHESSPLINESLWPOLYLINES r3   r2   r   r     s     GGKr3   r   c                   t        |        | j                  j                  }| j                         }g }|t        j
                  z  r|j                  t        |              |t        j                  t        j                  z   z  r~t        |       }|t        j                  z  r&|j                  t        j                  ||             |t        j                  z  r'|j                  t        j                  |||             t        |      S )a  Convert the text content of DXF entities TEXT and ATTRIB into virtual
    SPLINE and 3D POLYLINE entities or approximated LWPOLYLINE entities
    as outlines, or as HATCH entities as fillings.

    Returns the virtual DXF entities as an :class:`~ezdxf.query.EntityQuery`
    object.

    Args:
        entity: TEXT or ATTRIB entity
        kind: kind of entities to create as bit flags, see enum :class:`Kind`

    )rf   )r   rf   )rx   r|   r   r   r   r   extendr   r   r   r   r   to_splines_and_polylinesto_lwpolylinesr   )rw   kindr   r   entitiesro   s         r2   r   r   +  s     f

$$I'')G!#Hdll089t||d.../&v.$,,OOD99%GTU$"""OO##EY7S x  r3   c                    t        | |      }|| j                         }| j                          ||D ]  }|j                  |        t	        |      S )an  Explode the text `entity` into virtual entities,
    see :func:`virtual_entities`. The source entity will be destroyed.

    The target layout is given by the `target` argument, if `target` is ``None``,
    the target layout is the source layout of the text entity.

    Returns the created DXF entities as an :class:`~ezdxf.query.EntityQuery`
    object.

    Args:
        entity: TEXT or ATTRIB entity to explode
        kind: kind of entities to create as bit flags, see enum :class:`Kind`
        target: target layout for new created DXF entities, ``None`` for the
            same layout as the source entity.

    )r   
get_layoutdestroy
add_entityr   )rw   r   targetr   es        r2   r   r   K  s]    "  -H ~""$
NN 	!Aa 	!x  r3   )r(   strr)   fonts.FontFacer*   floatr,   r   r-   r   returnr   )r(   r   r)   r   r*   r   r,   r   r-   r   r   
list[Path])r)   r   r   fonts.AbstractFont)r   )r(   r   rA   r   r*   r   r   r   )
rH   fonts.FontMeasurementsr#   r   r+   r
   r,   r   r   r   )
rH   r   r#   r   rI   intrJ   r   r   r   )r(   r   r)   r   r*   r   r,   r   r-   r   r   list[Hatch])rw   AnyTextr   r   )rw   r   r   r   )rw   r   r   r   )rw   r   r   r   r   r   )/
__future__r   typingr   enumezdxf.entitiesr   r   r   r   ezdxf.lldxfr	   ezdxf.enumsr
   r   
ezdxf.mathr   r   ezdxfr   
ezdxf.pathr   ezdxf.fontsr   ezdxf.queryr   __all__r   ru   rP   r   r   r!   r"   r&   rC   r   rx   r   r   r   uniqueIntEnumr   r   r   r   r   r3   r2   <module>r      s   #   : :  I ,    #
 f
  

"
"$
$
$ $
 $ $ 
$T 

"
"

 
   >6
D
  	
 :33&13;>3HK33B 

"
"/
/
/ /
 / / /dH&;* 4<<  * 37,, !@ *.d !r3   