
    Ogq                       U d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ d dl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 d d
lmZmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z5 d dl6m7Z7 d dl8m9Z9m:Z: erd dl;m<Z< d dl=m>Z> d dl?m@Z@ g dZAe5ZBdZCdZDdZEdZF ej                  d      ZHej                  ZJdeKd<   d4d5dZL G d  d!      ZM G d" d#      ZN G d$ d%e
      ZO G d& d'eN      ZP eP       ZQ G d( d)      ZReeeP   gdf   ZS G d* d+      ZT ej                  d,      ZVd6d-ZWd7d.ZXd8d/ZYd9d0ZZd:d1Z[d;d2Z\	 d<	 	 	 d=d3Z]y)>    )annotations)TYPE_CHECKINGOptionalUnioncastSequenceCallableIterable
NamedTuple)	TypeAliasN)options)RGB)acadctb)Configuration)Color)DXF_DEFAULT_COLORSint2rgb)	AttribInsertFace3dLinetypeViewportLayerLayerOverrides	Textstyle
DXFGraphic)CONTINUOUS_PATTERN)
DXFPolygon)InsertUnitsMeasurement)find_support_file)const)make_table_key)fonts)scale_patternHatchPatternType)Drawing)Table)Layout)
PropertiesBackendPropertiesLayerPropertiesLayoutPropertiesRenderContext	layer_keyis_valid_color
rgb_to_hex
hex_to_rgbMODEL_SPACE_BG_COLORPAPER_SPACE_BG_COLORVIEWPORT_COLOROLE2FRAME_COLORset_color_alphaFillingz#212830#ffffffz#aaaaaaz#89adbaezdxfr   CTBc                F    t        j                  |       j                  |k  S N)r   from_hex	luminance)colordarks     d/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/drawing/properties.pyis_dark_colorrC   P   s    <<((D00    c                       e Zd ZdZdZdZddZy)r8   r         c                    t         j                  | _        d| _        d| _        d | _        d | _        d| _        d| _        g | _	        y )NSOLID              ?)
r8   rI   typenameanglegradient_color1gradient_color2gradient_centeredpattern_scalepatternselfs    rB   __init__zFilling.__init__Y   sB    MM	 	
0404(+$')+rD   NreturnNone)__name__
__module____qualname__rI   PATTERNGRADIENTrV    rD   rB   r8   r8   T   s    EGH,rD   r8   c                  B    e Zd ZdZddZd Zedd       Zed	d       Zy)
r*   zAn implementation agnostic representation of DXF entity properties like
    color and linetype. These properties represent the actual values after
    resolving all DXF specific rules like "by layer", "by block" and so on.
    c                    d| _         d| _        d| _        t        | _        d| _        d| _        d| _        d| _        d | _	        d | _
        t        j                  | _        y )Nr9      
CONTINUOUSrK         ?T0)r@   penlinetype_namer   linetype_patternlinetype_scale
lineweight
is_visiblelayerfontfillingr   UnitlessunitsrT   s    rB   rV   zProperties.__init__m   se     $
 #/  2D%(!% 

 /3	 +/ ))
rD   c           	     p    d| j                    d| j                   d| j                   d| j                   d	S )N(z, z, "z"))r@   rg   rj   rl   rT   s    rB   __str__zProperties.__str__   s@    

|2d001DOO3D E

|2	
rD   c                @    t        j                  | j                        S zReturns color as RGB tuple.r   r>   r@   rT   s    rB   rgbzProperties.rgb        ||DJJ''rD   c                .    | j                   j                  S zEReturns perceived color luminance in range [0, 1] from dark to light.rw   r?   rT   s    rB   r?   zProperties.luminance        xx!!!rD   NrW   rX   r   rX   float)	rZ   r[   r\   __doc__rV   rs   propertyrw   r?   r_   rD   rB   r*   r*   g   s:    
/*b
 ( ( " "rD   r*   c                  |    e Zd ZU dZdZded<   dZded<   dZd	ed
<   dZded<   dZ	d	ed<   e
dd       Ze
dd       Zy)r+   zBThe backend receives a condensed version of the entity properties.#000000r   r@   rd   r   rj   re   strrl   rF   intrf    handlec                @    t        j                  | j                        S ru   rv   rT   s    rB   rw   zBackendProperties.rgb   rx   rD   c                .    | j                   j                  S rz   r{   rT   s    rB   r?   zBackendProperties.luminance   r|   rD   Nr}   r~   )rZ   r[   r\   r   r@   __annotations__rj   rl   rf   r   r   rw   r?   r_   rD   rB   r+   r+      s\    LE5JE3CLFC( ( " "rD   r+   c                  *     e Zd ZdZ fdZddZ xZS )r,   zModified attribute meaning:

    is_visible: Whether entities belonging to this layer should be drawn
    layer: Stores real layer name (mixed case)

    c                0    t         |           d| _        y NF)superrV   has_aci_color_7)rU   	__class__s    rB   rV   zLayerProperties.__init__   s    $rD   c                6    | j                   r|S | j                  S )zyReturns the layer color or if layer color is ACI color 7 the
        given layout default foreground color `fg`.
        )r   r@   )rU   fgs     rB   get_entity_color_from_layerz+LayerProperties.get_entity_color_from_layer   s     I::rD   )r   r   rX   r   )rZ   r[   r\   r   rV   r   __classcell__)r   s   @rB   r,   r,      s    %rD   r,   c                      e Zd Zdej                  df	 	 	 	 	 	 	 d	dZed
d       Zed
d       Zedd       Z	e
ej                  fdd       Ze
ddd       ZdddZy)r-   Nc                    || _         || _        d| _        d| _        d| _        | j                  ||       ||| _        yy)zs
        Args:
            name: tab/display name
            units: enum :class:`ezdxf.enums.InsertUnits`
        r   FN)rM   rp   _background_color_default_color_has_dark_background
set_colors)rU   rM   background_colorforeground_colorrp   dark_backgrounds         rB   rV   zLayoutProperties.__init__   sM     	"'
!# $)!(*:;&(7D% 'rD   c                    | j                   S )z,Returns the default layout background color.)r   rT   s    rB   r   z!LayoutProperties.background_color   s     %%%rD   c                    | j                   S )z,Returns the default layout foreground color.)r   rT   s    rB   default_colorzLayoutProperties.default_color   s     """rD   c                    | j                   S )z:Returns ``True`` if the actual background-color is "dark".)r   rT   s    rB   has_dark_backgroundz$LayoutProperties.has_dark_background  s     (((rD   c                &    t        dt        |       S )NModelrp   )r-   r3   r   s    rB   
modelspacezLayoutProperties.modelspace  s     
 	
rD   c                    | j                   dk(  rt        }nt        }|| j                  }t	        | j                   ||      S )z Setup default layout properties.r   r   )rM   r3   r4   rp   r-   )layoutrp   bgs      rB   from_layoutzLayoutProperties.from_layout  s;     ;;'!%B%B=LLERu==rD   c                    t        |      st        d|       || _        t        |      dk(  r|dd }t	        |      | _        |!t        |      st        d|       || _        y| j
                  rdnd| _        y)zSetup default layout colors.

        Required color format "#RRGGBB" or including alpha transparency
        "#RRGGBBAA".
        zInvalid background color: 	   Nrb   zInvalid foreground color: r9   r   )r0   
ValueErrorr   lenrC   r   r   )rU   r   r   s      rB   r   zLayoutProperties.set_colors  s     b!9">??!#r7a<BQB$1"$5!>!"% #=bT!BCC"$D/3/H/H)iDrD   )rM   r   r   r   r   Optional[Color]r   zOptional[bool])rX   r   rX   bool)rX   r-   r=   )r   r)   rp   Optional[int]rX   r-   )r   r   r   r   rX   rY   )rZ   r[   r\   r   ro   rV   r   r   r   r   staticmethodr   r   r   r_   rD   rB   r-   r-      s     -1""*.88  8 *	8 (80 & & # # ) ) $-- 
 
 > >XrD   r-   c                     e Zd ZdZ	 d*ddd	 	 	 	 	 d+dZd*d,dZd-dZd.d/d	Zd
 Zd0dZ	d1dZ
d2dZd3dZe	 	 	 	 	 	 	 	 d4d       Zd5dZd6dZd7dZd8dZd9dZed:d       Zed;d       Zd<dZd=dZd>dZd?dZd@dZdd	 	 	 	 	 dAdZdBdZdd	 	 	 	 	 dCdZdd	 	 	 	 	 dDd Z	 	 	 	 	 	 dEd!Z dFd"Z!	 	 	 	 	 	 dGd#Z"dHd$Z#dd	 	 	 	 	 dId%Z$dd	 	 	 	 	 dJd&Z%d' Z&dKd(Z'dLd)Z(y)Mr.   a'  The render context for the given DXF document. The :class:`RenderContext`
    resolves the properties of DXF entities from the context they reside in to actual
    values like RGB colors, transparency, linewidth and so on.

    A given `ctb` file (plot style file) overrides the default properties for all
    layouts, which means the plot style table stored in the layout is always ignored.

    Args:
        doc: DXF document
        ctb: path to a plot style table or a :class:`~ezdxf.addons.acadctb.ColorDependentPlotStyles`
            instance
        export_mode: Whether to render the document as it would look when
            exported (plotted) by a CAD application to a file such as pdf,
            or whether to render the document as it would appear inside a
            CAD application.
    Nr   F)ctbexport_modec                  g | _         t               | _        d | _        || _        || _        t               | _        t               | _        t        j                  | _
        d| _        t        j                  | _        d| _        d| _        d | _        t               | _        t&        j)                         | _        | j-                  | j
                        | _        t1        j2                  ddd      | _        d | _        |r| j9                  |j)                                t;        |j<                        | _        |j>                  j3                  dd      | _        |j>                  j3                  dd      | _        |j>                  j3                  dd      | _        |j@                  x|j@                  }tC        |tD              r*|jG                  d	tH        jJ                  jL                        }tO        jP                  |      jR                  jU                         | _        | jW                  |       	 t        |j>                  j3                  d
d            | _
        	 t        |j>                  j3                  dd            | _        | j                  t        j                  k(  rH| j                  t        jZ                  k(  rt        j\                  | _
        nt        j^                  | _
        | j                  | j*                  _
        y # tX        $ r t        j                  | _
        Y w xY w# tX        $ r t        j                  | _        Y w xY w)NrK   r   zdrawing-addonshx_resolve_ordertslz$LTSCALEz$PDSIZEz$PDMODE\z	$INSUNITSz$MEASUREMENT)0_saved_statesdictline_pattern"current_block_reference_propertiesr   override_ctblayersr$   r   ro   rp   ri   r    Imperialmeasurementpdsizepdmodedocument_dir_hatch_pattern_cacher-   r   current_layout_properties_load_plot_style_tableplot_stylesr   getr   _layer_properties_overrideset_current_layout_load_line_pattern	linetypesheaderfilename
isinstancer   replaceospathseppathlibPathparentresolve_setup_text_stylesr   MetricMetersInches)rU   docr   r   r   s        rB   rV   zRenderContext.__init__B  st    028<HL/&26&04
 ))
%(&//48AE!)9)D)D)F&66t7H7HI!(0%"
 IM'##CNN$45 23== AD"%**..S"AD**..C8DK**..A6DK||'<<h,'//bggkkBH$+LL$:$A$A$I$I$K!##C(2(Q)GH
8#.szz~~na/P#Q  zz[111##{'9'99!,!3!3DJ!,!3!3DJ/3zz&&,  2(11
2  8#.#7#7 8s$   0*L *L* L'&L'*M
Mc                    || _         y)zThe function `func` is called with the current layer properties as
        argument after resetting them, so the function can override the layer
        properties.
        Nr   )rU   funcs     rB   set_layer_properties_overridez+RenderContext.set_layer_properties_override{  s    
 +/'rD   c                @    | j                   r| j                  |       y y r=   r   )rU   r   s     rB   _override_layer_propertiesz(RenderContext._override_layer_properties  s    **++F3 +rD   c                   t        |t              r'|dk(  r| j                  }|dk(  rI|j                         }n8t        |t              s(t        dt        j                   dt        |             t        j                  |      | _
        | j                  |      | _        t               | _        |j                  rS| j!                  |j                        | _        | j#                  t%        | j                  j'                                      yy)a  Set the current layout and update layout specific properties.

        Args:
            layout: modelspace or a paperspace layout
            ctb: path to a plot style table or a :class:`~ezdxf.addons.acadctb.ColorDependentPlotStyles`
                instance

        r   z%expected argument ctb of type str or z, got N)r   r   r   get_plot_style_filenamer;   	TypeErrorrZ   rL   r-   r   r   r   r   r   r   r   _setup_layersr   listvalues)rU   r   r   s      rB   r   z RenderContext.set_current_layout  s     c3by''by446C%7~VDQTI;W  *:)E)Ef)M&66s;f::,,VZZ8DK++D1C1C1E,FG rD   c                ,    t        j                   |       S )zReturns a shallow copy.)copyrT   s    rB   r   zRenderContext.copy  s    yyrD   c                    i }|j                   | j                   |d<   |j                  | j                  |d<   |j                  | j                  |d<    |j                  di |S )zwWhere the user has not specified a value, populate configuration
        fields based on the dxf header values
        r   r   r   r_   )r   r   r   with_changes)rU   configchangess      rB   update_configurationz"RenderContext.update_configuration  sk     ==  $GH==  $GH%%)%5%5GM""v""-W--rD   c                    t               }|j                  D ]9  }| j                  t        t        |            }||t        |j                        <   ; |S r=   )r   r   resolve_layer_propertiesr   r   r/   rl   )rU   r   r   rl   layer_propertiess        rB   r   zRenderContext._setup_layers  sS    -1VZZ 	IE#<<T%=OP8HF9-3345	I rD   c                \    |j                   D ]  }| j                  t        d|              y )Nr   )stylesadd_text_styler   )rU   r   
text_styles      rB   r   z RenderContext._setup_text_styles  s*    ** 	?J[* =>	?rD   c                   |j                   }|J |j                  D ch c]  }t        |       }}|j                  j                  }t               }|j                  D ]  }t        t        |      }|j                         }|j                  |      r#|j                         }| j                  |||       | j                  |      }	t        |	j                        }
|	||
<   |
|v sd|	_         |S c c}w r   )r   frozen_layersr/   dxfr   r   r   r   r   get_vp_overrideshas_overridesr   _apply_layer_overridesr   rl   rk   )rU   vpr   rM   frozen_layer_names	vp_handler   rl   	overridesr   keys              rB   _setup_vp_layerszRenderContext._setup_vp_layers  s    ff:<:J:JK$ioKKFFMM	-1VZZ 
	4E&E..0I&&y1

++IuiH#<<UC,223C*F3K((.3 +
	4  Ls   C1c                   |j                  |       |_        |j                  |       }|||_        |j	                  |       |_        |j                  |       |j                  _        |j                  |       |j                  _
        y r=   )	get_colorr@   get_rgbrw   get_transparencytransparencyget_linetyper   linetypeget_lineweightrj   )r  rl   r  	rgb_colors       rB   r   z$RenderContext._apply_layer_overrides  st      )))4%%i0	 !EI&77	B&33I>		(77	B		rD   c                J   |j                   | S | j                         }|j                  }|dk(  r|j                  j	                  d      }|r|j                  |      |_        |j                  |      }||_        |j                  t        |j                                      |S )Nr   plot_style_name)r   r   r   r   r   r   r   r  r   r   r   r   )rU   r   vp_ctxr   r   s        rB   from_viewportzRenderContext.from_viewport  s    66>K!!"9&&**./C!'!>!>s!CF((,))$v}}*?@rD   c                \   t               }|j                  j                  |_        |j                  j                  |_        | j                  |      |_        t        |j                        }|dk  rt        |j                  |      |_        |j                  d      s|j                  j                  dk(  |_        t        |j                  j                        j                         |_        | j                   j#                  |j                  t$              |_        | j)                  |j                  j*                        |_        |j-                         xr |j/                          |_        | j2                  r2|xj0                  t5        |j                  j6                        z  c_        |S )zResolve layer properties.   
true_colorrb   )r,   r   rM   rl   r@   rf   _true_layer_colortransparency_to_alphar	  r7   has_dxf_attribr   r   r  upperrg   r   r   r   rh   _true_layer_lineweightrj   is_on	is_frozenrk   r   r   plot)rU   rl   
propertiesalphas       rB   r   z&RenderContext.resolve_layer_properties  s?   $&
 99>>

11%8
 &e&8&893;.z/?/?GJ
 ##L1).A)=J& $'uyy'9'9#:#@#@#B
 &*&7&7&;&;$$&8'

# !% ; ;EII<P<P Q
 % Geoo6G2G
!!T%))..%99!rD   c                   t        |j                  j                        }|j                  j                  }d}|dk(  r3|j	                         \  }}}|r?t        j                  ||rdnd|      }n"	 t        j                  || j                        }|t        j                         }|| j
                  |<   y# t
        j                  $ r t        j                  d       Y Pw xY w)zSetup text style properties.Nr   i  i  )familyweightitalic)orderz+no fonts available, not even fallback fonts)	table_keyr   rM   rm   get_extended_font_datar$   find_best_matchresolve_font_facer   FontNotFoundErrorloggerwarningFontFace)rU   r   rM   	font_file	font_facer   r"  bolds           rB   r   zRenderContext.add_text_style  s    ,,-NN''		?#-#D#D#F FFD!11!#3v	N!33T%;%;	 (I$

4 ** NLMNs   1!B8 8(C#"C#c                    |j                   j                  d      rt        |j                        S |j                  }|dk  s|dkD  rd}| j                  |      S )Nr  rF   r  rb   )r   hasattrr1   rw   r@   _aci_to_true_color)rU   rl   acis      rB   r  zRenderContext._true_layer_color"  sQ    99\*eii(( ++CQw#)**3//rD   c                H    |dk  r| j                         S t        |      dz  S )Nr         Y@)default_lineweightr   )rU   rj   s     rB   r  z$RenderContext._true_layer_lineweight-  s(    >**,,$u,,rD   c                N   t        | t              r1t        | t        j                        } 	 t        j                  |       }n| }t        dd      D ]/  }||   }|j                         st        t        |         |_        1 |S # t        $ r t        j                         }Y _w xY w)NrF      )r   r   r!   r   support_dirsr   loadIOErrornew_ctbrangehas_object_colorr   r   r@   )r   r   r2  entrys       rB   r   z$RenderContext._load_plot_style_table3  s    
 h$(73G3GHH(ll8, C
 C= 	?CHE%%'%&8&=>		?
 
  (oo'(s   B B$#B$c                ,    t        | j                        S )zfReturns ``True`` if current processing state is inside of a block
        reference (INSERT).
        )r   r   rT   s    rB   inside_block_referencez$RenderContext.inside_block_referenceK  s    
 D;;<<rD   c                \    | j                   j                  | j                         || _        y r=   )r   appendr   )rU   block_references     rB   
push_statezRenderContext.push_stateR  s$    !!$"I"IJ2A/rD   c                B    | j                   j                         | _        y r=   )r   popr   rT   s    rB   	pop_statezRenderContext.pop_stateV  s    262D2D2H2H2J/rD   c                `   t               }| j                  |      |_        t        |j                        }| j	                         |_        | j                  ||      |_        | j                  ||      |_	        | j                  ||      \  |_        |_        | j                  ||      |_        | j                  |      |_        | j#                  ||      |_        |j'                  d      r| j)                  |      |_        t-        |t.              r| j1                  |      |_        |S )z#Resolve all properties of `entity`.resolved_layerstyle)r*   resolve_layerrl   r/   resolve_unitsrp   resolve_colorr@   resolve_penrf   resolve_linetyperg   rh   resolve_lineweightrj   resolve_linetype_scaleri   resolve_visiblerk   is_supported_dxf_attribresolve_fontrm   r   r   resolve_fillingrn   )rU   entityprJ  s       rB   resolve_allzRenderContext.resolve_allY  s   L$$V,"177+$$&$$VN$K   G.2.C.C> /D /
++ ..vn.U66v>++F>+R))'2&&v.AFfj),,V4AIrD   c                .    | j                   j                  S r=   )r   rp   rT   s    rB   rM  zRenderContext.resolve_unitsm  s    --333rD   c                H    |j                   j                  | j                  z  S r=   )r   ltscaleri   )rU   rW  s     rB   rR  z$RenderContext.resolve_linetype_scalep  s    zz!!D$7$777rD   rI  c               :   t        |t              r t        |j                  j                         S t        |t
              rt        |j                               S t        |t              r|j                  S |xs t        | j                  |            }| j                  j                  |      }|r|j                  syt        |t              r/t        |j                  j                         xr |j                   S t        |j                  j                         S )zcResolve the visibility state of `entity`. Returns ``True`` if
        `entity` is visible.
        F)r   r   r   r   	invisibler   anyget_edges_visibilityr   rk   r/   rL  r   r   r   is_invisible)rU   rW  rJ  entity_layerr   s        rB   rS  zRenderContext.resolve_visibles  s     ff%FJJ00111'v22455) $$$%N43E3Ef3M)N;;??<8$4$?$?'FJJ0011M&:M:M6MMFJJ00111rD   c                    |j                   j                  }|dk(  r"| j                  r| j                  j                  }|S )znResolve the layer of `entity`, this is only relevant for entities
        inside of block references.
        re   )r   rl   r@  r   )rU   rW  rl   s      rB   rL  zRenderContext.resolve_layer  s8     

  C<D77;;AAErD   c                  |j                   j                  d      rd}n|j                   j                  }|xs t        | j	                  |            }| j
                  j                  |t              }|t        j                  k(  r&|j                  | j                  j                        }ni|t        j                  k(  r:| j                  s| j                  j                  }n3| j                  j                  }n| j!                  |j"                  |      }| j%                  |j                   j                  d      |j                        }|dd |z   S )zaResolve the rgb-color of `entity` as hex color string:
        "#RRGGBB" or "#RRGGBBAA".
        r  rb   r	  N)r   r0  r@   r/   rL  r   r   DEFAULT_LAYER_PROPERTIESr"   BYLAYERr   r   r   BYBLOCKr@  r   _true_entity_colorrw   _entity_alpha_str)rU   rW  rJ  r2  rb  r   r@   r  s           rB   rN  zRenderContext.resolve_color  s    ::l+ C**""C%N43E3Ef3M)N;;??<9QR%--$@@..<<E EMM!..66DD??EE++FJJ<E&&JJNN>*,<,B,B
 Ray5  rD   c                  |j                   j                  }|xs t        | j                  |            }| j                  j                  |t              }|t        j                  k(  r|j                  }|S |t        j                  k(  r(| j                  sd}|S | j                  j                  }|S |t        j                  k(  rd}|S )zIResolve the aci-color of `entity` as pen number in the range of [1..255].rb   )r   r@   r/   rL  r   r   re  r"   rf  rf   rg  r@  r   BYOBJECT)rU   rW  rJ  rf   rb  r   s         rB   rO  zRenderContext.resolve_pen  s     jj%N43E3Ef3M)N;;??<9QR%--"&&C 
 EMM!..
 
 ==AA 
 ENN"C
rD   c                    |t         j                  k(  r&| j                  r| j                  j                  dd S y||dd S |dz  }|dk  r|dS y)zEReturns the alpha value as hex string "xx" or empty string if opaque.rb   Nr   r  02x)r"   TRANSPARENCY_BYBLOCKr@  r   r@   )rU   raw_transparencylayer_colorr  s       rB   ri  zRenderContext._entity_alpha_str  si     u999**>>DDQRHH %qr?" 4'3;C[!rD   c                   |t         j                  k(  rP| j                  j                  t	        |      t
              }|j                  | j                  j                        }|S |t         j                  k(  r<| j                  s| j                  j                  }|S | j                  j                  }|S | j                  d|      }|S )z7Resolve the `aci` color as hex color string: "#RRGGBB" N)r"   rf  r   r   r/   re  r   r   r   rg  r@  r   r@   rh  )rU   r2  rJ  rl   r@   s        rB   resolve_aci_colorzRenderContext.resolve_aci_color  s    %--KKOOIn$=?WXE55..<<E  EMM!..66DD
  ??EE  ++D#6ErD   c                    |t        |      S d|cxk  rdk  r)n | j                  j                  S | j                  |      S | j                  j                  S )zjReturns rgb color in hex format: "#RRGGBB".

        `true_color` has higher priority than `aci`.
        r   r7  )r1   r1  r   r   )rU   r  r2  s      rB   rh  z RenderContext._true_entity_color  sY     !j))]s] 11??? **3//11???rD   c                |    |dk(  r| j                   j                  S t        | j                  |   j                        S )zeReturns the `aci` value (AutoCAD Color Index) as rgb value in
        hex format: "#RRGGBB".
        rb   )r   r   r1   r   r@   )rU   r2  s     rB   r1  z RenderContext._aci_to_true_color  s9     !811???d..s399::rD   c                  |j                   j                  }d|cxk  rdk  r.n n+| j                  |   j                  t        j
                  k7  r	 |j                   j                  j                         }|dk(  rZ|xs t        | j                  |            }| j                  j                  |t              }|j                  }|j                  }||fS |dk(  rH| j                  r0| j                  j                  }| j                  j                  }||fS d}t         }||fS | j"                  j                  |t               }||fS )zResolve the linetype of `entity`. Returns a tuple of the linetype
        name as upper-case string and the simplified linetype pattern as tuple
        of floats.
        r   r7  rf  rg  STANDARD)r   r@   r   r  r   OBJECT_LINETYPEr  r/   rL  r   r   re  rg   rh   r@  r   r   r   )rU   rW  rJ  r2  rM   rb  rl   rS   s           rB   rP  zRenderContext.resolve_linetype  s7    jjMcMt// 

(g-- .
 zz""((*9)RYt7I7I&7Q-RLKKOOL2JKE&&D,,G W} Y**>>LL;;LL  W}	 ", W} ''++D2DEGW}rD   c               8      fd}t        d |             S )a  Resolve the lineweight of `entity` in mm.

        DXF stores the lineweight in mm times 100 (e.g. 0.13mm = 13).
        The smallest line weight is 0 and the biggest line weight is 211.
        The DXF/DWG format is limited to a fixed value table,
        see: :attr:`ezdxf.lldxf.const.VALID_DXF_LINEWEIGHTS`

        CAD applications draw lineweight 0mm as an undefined small value, to
        prevent backends to draw nothing for lineweight 0mm the smallest
        return value is 0.01mm.

        c                    j                   j                  } d| cxk  rdk  rHn nEj                  |    j                  t        j
                  k7  rj                  j                  |       S j                   j                  }|t        j                  k(  rHxs t        j                              }j                  j                  |t              j                  S |t        j                  k(  r2j                  rj                   j                  S j#                         S |t        j$                  k(  rj#                         S t'        |      dz  S )Nr   r7  r4  )r   r@   r   rj   r   OBJECT_LINEWEIGHTr  r"   LINEWEIGHT_BYLAYERr/   rL  r   r   re  LINEWEIGHT_BYBLOCKr@  r   r5  LINEWEIGHT_DEFAULTr   )r2  rj   rb  rW  rJ  rU   s      rB   rj   z4RenderContext.resolve_lineweight.<locals>.lineweight<  s   **""CC#4#3#3$jG55$6 ''66s;;..JU555-V4;M;Mf;U1V{{ ":* u777..BBMMM  2244u777..00Z(500rD   g{Gz?)max)rU   rW  rJ  rj   s   ``` rB   rQ  z RenderContext.resolve_lineweight,  s     	14 4&&rD   c                     y)z/Returns the default lineweight of the document.rd   r_   rT   s    rB   r5  z RenderContext.default_lineweightX  s     rD   c                    |j                   j                  dd      }| j                  j                  t        |            S )zjResolve the text style of `entity` to a font name.
        Returns ``None`` for the default font.
        rK  Standard)r   r   r$   r$  )rU   rW  rK  s      rB   rU  zRenderContext.resolve_font]  s0    
 

w
3zz~~i.//rD   c                    fd} fd}t        |t              syt        t        |      t               j                  j
                  rnj                  t        j                  _        S j                  dk(  r1t        j                  _        t        j                        _        S  |        S  |        S )zBResolve filling properties (SOLID, GRADIENT, PATTERN) of `entity`.c                    t         j                  _        j                  j	                         _        t        j                        _        j                  r,t        j                  dz        } t        | | | f      _        nt        j                        _        j                  _        j                  _        y )Nr  )r8   r^   rL   rM   r  r1   color1rO   	one_colorroundtintrP   color2rotationrN   centeredrQ   )crn   gradients    rB   setup_gradientz5RenderContext.resolve_filling.<locals>.setup_gradienth  s    "++GL#==..0GL&0&AG#!!(--#-.*4aAY*?'*4X__*E'$--GM(0(9(9G%rD   c                    t         j                  _        j                  j                  j                         _        j                  j                  _        j                  j                  _	        j                  j                  rxj                  dz  c_        j                  j                  j                        _        j                  ry j                  } | sy t        | j                         dj                  z  j                         _        j                  j                  j                  <   y )NrG   rK   )r8   r]   rL   r   pattern_namer  rM   rR   pattern_anglerN   pattern_doubler   r   rS   r%   as_list)rS   rn   polygonrU   s    rB   setup_patternz4RenderContext.resolve_filling.<locals>.setup_patternv  s    "??GL";;3399;GL$+KK$=$=G!#KK55GM{{))%%*%"77;;GLLIGOooG ,!3)>)>#>GO 7>ooD%%gll3rD   Nr   )r   r   r   r8   r   
solid_fillr  rI   rL   kindr1   r  rO   )rU   rW  r  r  rn   r  r  s   `   @@@rB   rV  zRenderContext.resolve_fillinge  s    	:	F@ &*-z6*);;!!''H&}}  ==A%#*==GL.8.IG+
  #$  OrD   r=   )r   zOptional[Drawing]r   	str | CTBr   r   )r   zOptional[LayerPropsOverride])r   Sequence[LayerProperties])r   )r   r)   r   r  )r   r   rX   r   )r   r'   rX   dict[str, LayerProperties])r   r'   )r   r   rX   r  )r  r   rl   r   r  r   rX   rY   )r   r   rX   r.   )rl   r   rX   r,   )r   r   )rl   r   rX   r   )rj   r   rX   r   )r   r  r   )rC  r*   rX   rY   rW   )rW  r   rX   r*   )rX   r   )rW  r   rX   r   )rW  r   rJ  Optional[str]rX   r   )rW  r   rX   r   )rW  r   rJ  r  rX   r   )rW  r   rJ  r  rX   r   )ro  r   rp  r   rX   r   )r2  r   rJ  r   rX   r   )r  zOptional[tuple[int, int, int]]r2  r   rX   r   )r2  r   rX   r   )rW  r   rJ  r  rX   ztuple[str, Sequence[float]])rW  r   rJ  r  rX   r   )rW  r   rX   zOptional[fonts.FontFace])rW  r   rX   zOptional[Filling]))rZ   r[   r\   r   rV   r   r   r   r   r   r   r   r  r   r   r  r   r   r  r  r   r   r@  rD  rG  rY  rM  rR  rS  rL  rN  rO  ri  rr  rh  r1  rP  rQ  r5  rU  rV  r_   rD   rB   r.   r.   0  s   & "&7: !7:7: 	7:
 7:r/4H8.?& CCC "C 
	C C<%.	0-  . = =BK(48 FJ2 25B2	24 FJ! !5B!	!B FJ 5B	& -<A	0 @8@?B@	@; FJ" "5B"	$"J FJ*' *'5B*'	*'X
0BrD   r.   z#[0-9A-Fa-f]{6,8}c                    t        |       t        urt        dt        |        d      t        |       dv rt	        t
        j                  |             S y)NzInvalid argument type: .rb   r   F)rL   r   r   r   r   COLOR_PATTERN	fullmatch)r@   s    rB   r0   r0     sL    E{%1$u+a@AA
5zVM++E233rD   c                ^    t        d | D              s
J d|         | \  }}}d|d|d|dS )z'Returns color in hex format: "#RRGGBB".c              3  <   K   | ]  }d |cxk  xr dk  nc   yw)r   r  Nr_   ).0xs     rB   	<genexpr>zrgb_to_hex.<locals>.<genexpr>  s     *qA}}}*s   zinvalid RGB color: #rm  )all)rw   rgbs       rB   r1   r1     sI    *c**G.A#,GG*GAq!qgaWQsG$$rD   c                    | j                  d      } t        |       dk(  sJ t        | dd d      }t        | dd d      }t        | dd d      }t        |||      S )z,Returns hex string color as (r, g, b) tuple.r     r   rG         )lstripr   r   r   )
hex_stringr  r  r  s       rB   r2   r2     sh    ""3'Jz?aJqOR AJqOR AJqOR Aq!Q<rD   c                    | j                  d      rt        |       dv sJ d|  d       d|cxk  rdk  sn J d|        | dd	  |d
S )zReturns `color` including the new `alpha` channel in hex format:
    "#RRGGBBAA".

    Args:
        color: may be an RGB or RGBA hex color string
        alpha: the new alpha value (0-255)
    r  r  zinvalid RGB color: ""r   r7  zalpha out of range: Nrb   rm  )
startswithr   )r@   r  s     rB   r7   r7     sx     C SZ 4 & ' 
eWA&'  ;3E7;;BQi[s$$rD   c                b    t        t        d|       d      } t        t        d| z
  dz              S )NrJ   rK   r  )minr~  r   r  )values    rB   r  r    s-    C%EucEkS()**rD   c                    t               }| D ]K  }t        |t              sJ |j                  j                  j                         }|j                         ||<   M |S )zLoad linetypes defined in a DXF document into  as dictionary,
    key is the upper case linetype name, value is the simplified line pattern,
    see :func:`compile_line_pattern`.
    )r   r   r   r   rM   r  simplified_line_pattern)r   rS   r  rM   s       rB   r   r     s[    
 +/&G ;(H---||  &&( 88:; NrD   c                    |D ch c]  }t        |       }}| D ])  }t        |j                        |v r||_        "| |_        + yc c}w )zSet layer state of `layers` to on/off.

    Args:
        layers: layer properties
        layer_names: iterable of layer names
        state: `True` turn this `layers` on and others off,
            `False` turn this `layers` off and others on
    N)r/   rl   rk   )r   layer_namesstaterM   unique_layer_namesrl   s         rB   set_layers_stater    sV     7BBd)D/BB )U[[!%77$E#(yE	) Cs   A)g?)r@   r   rA   r   rX   r   )r@   r   rX   r   )rw   z7Union[tuple[int, int, int], tuple[float, float, float]]rX   r   )r  r   rX   r   )r@   r   r  r   rX   r   )r  r   rX   r   )r   r(   rX   zdict[str, Sequence[float]])T)r   r  r  zIterable[str])^
__future__r   typingr   r   r   r   r   r	   r
   r   typing_extensionsr   r   r   rer   loggingr:   r   ezdxf.colorsr   ezdxf.addonsr   ezdxf.addons.drawing.configr   ezdxf.addons.drawing.type_hintsr   r   r   ezdxf.entitiesr   r   r   r   r   r   r   r   r   ezdxf.entities.ltyper   ezdxf.entities.polygonr   ezdxf.enumsr   r    ezdxf.filemanagementr!   ezdxf.lldxfr"   ezdxf.lldxf.validatorr#   r/   ezdxf.fontsr$   ezdxf.tools.patternr%   r&   ezdxf.documentr'   ezdxf.sections.tabler(   ezdxf.layoutsr)   __all__r$  r3   r4   r5   r6   	getLoggerr)  ColorDependentPlotStylesr;   r   rC   r8   r*   r+   r,   re  r-   LayerPropsOverrider.   compiler  r0   r1   r2   r7   r  r   r  r_   rD   rB   <module>r     s|   #	 	 	 ( 	  	       5 1 4
 
 
 4 - 0 2  =  ?&*$$ 	    			7	#11Y 11, ,&E" E"P"
 "(j , +, NX NXb x894?@ w	 w	t 

./%% +
 JN)%)4A)rD   