
    he                       S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
r
S SKJr  S SKJr  S SKJr  S SKJr  S SKrS rSrS	rS
rSrS rSrS	rS
rSrSrSrSrSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'S	r(Sr)S r*S r+Sr,Sr-Sr.Sr// SQr0Sr1Sr2Sr3Sr4S7S  jr5S8S! jr6 " S" S#5      r7 " S$ S%5      r8 " S& S'\85      r9 " S( S)\85      r:S9S* jr;S:S+ jr<    S;S, jr=S<S- jr>S=S. jr?S>S/ jr@S?S0 jrA " S1 S25      rBS@S3 jrCSAS4 jrD\34SBS5 jjrESCS6 jrFg)D    )annotations)UnionOptionalBinaryIOTextIOIterableIteratorAnyN)abstractmethod)StringIO)array)pack               @   A   B   C   D   E   F   G   H   I      i   )        g?g
ףp=
?g?gp=
ף?g333333?g
ףp=
?g?g      ?g333333?gffffff?g?g?      ?g(\?g333333?g?gffffff?g?g?      ?g(\?g333333?gffffff?gHzG?g       @gzG @            c                    SU S-   -  $ )NzColor_%dr    indexs    F/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/acadctb.py
color_namer-   f   s    ##    c                    [        U [        5      (       a;  U R                  5       nUS:X  a  Sn U $ US:X  a  Sn U $ [        S[        U 5      -  5      eU $ )NTRUETFALSEFzUnknown bool value '%s'.)
isinstancestrupper
ValueError)valueupperstrs     r,   get_boolr8   j   s`    %;;=vE
 L	  E L 7#e*DEELr.   c                     \ rS rSr  S     SS jjr\SS j5       r\R                  SS j5       r\S 5       r\R                  SS j5       rSS jr	SS	 jr
SS
 jrSS jr\SS j5       r\SS j5       r\R                  SS j5       r\SS j5       r\R                  SS j5       r\SS j5       r\R                  SS j5       rS S jrSrg)!	PlotStylev   Nc                   U=(       d    0 nX0l         [        U5      U l        [        UR	                  S[        U5      5      5      U l        [        UR	                  S[        U5      5      5      U l        [        UR	                  SS5      5      U l        [        UR	                  S[        5      5      U l
        [        U l        U R                  [        :w  a*  [        UR	                  SU R                  5      5      U l        [        UR	                  S[        5      5      U l        [        UR	                  S[         5      5      U l        [        UR	                  S	[         5      5      U l        [        UR	                  S
S5      5      U l        [)        UR	                  SS5      5      U l        [        UR	                  S[,        5      5      U l        [1        UR	                  SS5      5      U l        [        UR	                  S[4        5      5      U l        [        UR	                  S[8        5      5      U l        [        UR	                  S[<        5      5      U l        [        UR	                  S[@        5      5      U l!        g )Nnamelocalized_namedescription color
mode_colorcolor_policyphysical_pen_numbervirtual_pen_numberscreend   linepattern_sizer"   linetypeadaptive_linetypeT
lineweight	end_style
join_style
fill_style)"parentintr+   r3   getr-   r=   r>   r?   OBJECT_COLOR_color	COLOR_RGB_color_type_mode_colorDITHERING_ON_color_policy	AUTOMATICrD   rE   rF   floatrH   OBJECT_LINETYPErI   r8   rJ   OBJECT_LINEWEIGHTrK   END_STYLE_OBJECTrL   JOIN_STYLE_OBJECTrM   FILL_STYLE_OBJECTrN   )selfr+   datarO   s       r,   __init__PlotStyle.__init__w   s    zrZ
E):;<	!$((+;Z=N"OPtxxr:; $((7L9:$;;,&"488L$++#FGD .,!GH#&txx0Ey'Q#R "%dhh/CY&O"P$((8S12 %dhh/A3&G HDHHZAB!)$((3F*M!N dhh|5FGHTXXk3CDEdhh|5FGHdhh|5FGHr.   c                ^    U R                  5       (       a  g[        U R                  5      SS $ )zOGet style color as ``(r, g, b)`` tuple or ``None``, if style has
object color.
Nr   )has_object_color	int2colorrV   r`   s    r,   rA   PlotStyle.color   s.    
   ""T--.r22r.   c                b    Uu  p#n[        X#X@R                  S9U l        U R                  U l        g)zSet color as RGB values.)
color_typeN)mode_color2intrU   rV   rS   )r`   rgbrgbs        r,   rA   rh      s1     a *!>N>NO&&r.   c                F    U R                  5       (       a  g U R                  $ N)re   rU   rg   s    r,   rj   PlotStyle.color_type   s       ""###r.   c                    Xl         g rq   )rU   )r`   r6   s     r,   rj   rr      s     r.   c                0    [         U l        [         U l        g)zSet color to object color.N)rR   rS   rV   rg   s    r,   set_object_colorPlotStyle.set_object_color   s    "'r.   c                b    U R                   c   eU R                   R                  U5      U l        g)zJSet `lineweight` in millimeters. Use ``0.0`` to set lineweight by
object.
N)rO   get_lineweight_indexrK   r`   rK   s     r,   set_lineweightPlotStyle.set_lineweight   s*     {{&&&++:::Fr.   c                f    U R                   c   eU R                   R                  U R                     $ )zJReturns the lineweight in millimeters or `0.0` for use entity
lineweight.
)rO   lineweightsrK   rg   s    r,   get_lineweightPlotStyle.get_lineweight   s-     {{&&&{{&&t77r.   c                4    U R                   [        [        4;   $ )z#``True`` if style has object color.)rS   rR   OBJECT_COLOR2rg   s    r,   re   PlotStyle.has_object_color   s    {{|];;;r.   c                     U R                   S-   $ )zW:ref:`ACI` in range from ``1`` to ``255``. Has no meaning for named
plot styles. (int)
r   r*   rg   s    r,   aciPlotStyle.aci   s    
 zzA~r.   c                :    [        U R                  [        -  5      $ )uI  Depending on the capabilities of your plotter, dithering approximates
the colors with dot patterns. When this option is ``False``, the colors
are mapped to the nearest color, resulting in a smaller range of
colors when plotting.

Dithering is available only whether you select the object’s color or
assign a plot style color.

)boolrX   rW   rg   s    r,   	ditheringPlotStyle.dithering   s     D&&566r.   c                z    U(       a  U =R                   [        -  sl         g U =R                   [        ) -  sl         g rq   )rX   rW   r`   statuss     r,   r   r      )    ,.<-/r.   c                :    [        U R                  [        -  5      $ )z Plot colors in grayscale. (bool))r   rX   GRAYSCALE_ONrg   s    r,   	grayscalePlotStyle.grayscale   s     D&&566r.   c                z    U(       a  U =R                   [        -  sl         g U =R                   [        ) -  sl         g rq   )rX   r   r   s     r,   r   r      r   r.   c                :    [        U R                  [        -  5      $ rq   )r   rX   NAMED_COLORrg   s    r,   named_colorPlotStyle.named_color   s    D&&455r.   c                z    U(       a  U =R                   [        -  sl         g U =R                   [        ) -  sl         g rq   )rX   r   r   s     r,   r   r      s)    +-;,.r.   c                   U R                   nUR                  SU-  5        UR                  SU R                  -  5        UR                  SU R                  -  5        UR                  SU R                  -  5        UR                  SU R
                  -  5        U R
                  [        :w  a  UR                  SU R                  -  5        UR                  SU R                  -  5        UR                  SU R                  -  5        UR                  S	U R                  -  5        UR                  S
U R                  -  5        UR                  S[        U R                  5      -  5        UR                  SU R                  -  5        UR                  S[        [        U R                   5      5      R#                  5       -  5        UR                  S[        U R$                  5      -  5        UR                  SU R&                  -  5        UR                  SU R(                  -  5        UR                  SU R*                  -  5        UR                  S5        g)z.Write style data to file-like object `stream`.z %d{
z  name="%s
z  localized_name="%s
z  description="%s
z  color=%d
z  mode_color=%d
z  color_policy=%d
z  physical_pen_number=%d
z  virtual_pen_number=%d
z  screen=%d
z  linepattern_size=%s
z  linetype=%d
z  adaptive_linetype=%s
z  lineweight=%s
z  fill_style=%d
z  end_style=%d
z  join_style=%d
z }
N)r+   writer=   r>   r?   rS   rR   rV   rX   rD   rE   rF   r3   rH   rI   r   rJ   r4   rK   rN   rL   rM   )r`   streamr+   s      r,   r   PlotStyle.write  s   

X%&^dii/0-0C0CCD*T-=-==>^dkk12;;,&LL,t/?/??@*T-?-??@1D4L4LLM043J3JJK_t{{23.T5J5J1KKL&67&T$2H2H-I)J)P)P)RR	
 	(3t+??@(4??:;'$..89(4??:;Vr.   )rS   rX   rU   rV   rJ   r?   rL   rN   r+   rM   rH   rI   rK   r>   r=   rO   rD   rF   rE   NN)r+   rP   ra   Optional[dict]rO   zOptional[PlotStyleTable])returnzOptional[tuple[int, int, int]])rl   ztuple[int, int, int]r   None)r6   rP   )r   r   )rK   rZ   r   r   )r   rZ   )r   r   )r   rP   )r   r   r   r   r   r   r   r   )__name__
__module____qualname____firstlineno__rb   propertyrA   setterrj   ru   rz   r~   re   r   r   r   r   r   __static_attributes__r)   r.   r,   r:   r:   v   sB     $+/	II I )	I@ 3 3 \\
' 
' $ $ ! !(
G8<   
7 
7 0 0 7 7 0 0 6 6 / /r.   r:   c                      \ rS rSrSr   S     SS jjrSS jrSS jrSS jrSS jr	SS jr
\SS	 j5       rSS
 jrSS jr\S 5       rSrg)PlotStyleTablei  zPlotStyle containerc                `    Xl         X l        X0l        SU l        [	        S[
        5      U l        g )Nr   f)r?   scale_factorapply_factorcustom_lineweight_display_unitsr   DEFAULT_LINE_WEIGHTSr}   )r`   r?   r   r   s       r,   rb   PlotStyleTable.__init__  s0     '(( 01, &:;r.   c                     U R                   R                  U5      $ ! [         a6    U R                   R                  U5        [	        U R                   5      S-
  s $ f = f)z^Get index of `lineweight` in the lineweight table or append
`lineweight` to lineweight table.
r   )r}   r+   r5   appendlenry   s     r,   rx   #PlotStyleTable.get_lineweight_index.  sW    	-##))*55 	-##J/t''(1,,	-s    =AAc                     X R                   U'   U$ ! [         a6    U R                   R                  U5        [        U R                   5      S-
  s $ f = f)zArgument `index` is the lineweight table index, not the :ref:`ACI`.

Args:
    index: lineweight table index = :attr:`PlotStyle.lineweight`
    lineweight: in millimeters

r   )r}   
IndexErrorr   r   )r`   r+   rK   s      r,   set_table_lineweight#PlotStyleTable.set_table_lineweight8  sS    	-&0U#L 	-##J/t''(1,,	-s    =AAc                     U R                   U   $ )zReturns lineweight in millimeters of lineweight table entry `index`.

Args:
    index: lineweight table index = :attr:`PlotStyle.lineweight`

Returns:
    lineweight in mm or ``0.0`` for use entity lineweight

)r}   )r`   r+   s     r,   get_table_lineweight#PlotStyleTable.get_table_lineweightG  s     &&r.   c                r    [        US5       nU R                  U5        SSS5        g! , (       d  f       g= f)z6Save CTB or STB file as `filename` to the file system.wbN)openr   )r`   filenamer   s      r,   savePlotStyleTable.saveS  s&    (D!VJJv "!!s   (
6c                    [        5       nU R                  U5        UR                  [        S5      5        UR	                  5       nUR                  5         [        X5        g)z:Compress and write the CTB or STB file to binary `stream`.r   N)r   write_contentr   chrgetvalueclose	_compress)r`   r   memfilebodys       r,   r   PlotStyleTable.writeX  sF    *7#c!f!&r.   c                    g rq   r)   r`   r   s     r,   r   PlotStyleTable.write_contenta      r.   c                    UR                  S5        [        U R                  5       H  u  p#UR                  SX#4-  5        M     UR                  S5        g)z/Write custom lineweight table to text `stream`.zcustom_lineweight_table{
z	 %d=%.2f
}
N)r   	enumerater}   )r`   r   r+   weights       r,   _write_lineweights!PlotStyleTable._write_lineweightse  sE    12&t'7'78MELL78 9Ur.   c                  ^  U 4S jn[        U5      nUR                  SS5      T l        [        UR                  SS5      5      T l        [        UR                  SS5      5      T l        [        UR                  SS	5      5      T l        U" UR                  S
S5      5        T R                  UR                  S0 5      5        g)z)Parse plot styles from CTB string `text`.c                   > U c  g [        SS/[        U 5      -  5      Tl        U R                  5        H&  u  p[	        U5      TR                  [        U5      '   M(     g )Nr   r!   )r   r   r}   itemsrZ   rP   )r}   keyr6   r`   s      r,   set_lineweights-PlotStyleTable.parse.<locals>.set_lineweightso  sT    "$S3%#k2B*BCD)//1
-25\  S* 2r.   r?   r@   r   r#   r   Tr   r   custom_lineweight_tableN
plot_style)
PlotStyleFileParserrQ   r?   rZ   r   r8   r   rP   r   load_styles)r`   textr   parsers   `   r,   parsePlotStyleTable.parsel  s    	: %T*!::mR8!&**^S"AB$VZZ%EF/2JJ8!<0
, 	

#<dCDL"56r.   c                    g rq   r)   )r`   styless     r,   r   PlotStyleTable.load_styles  r   r.   )r   r   r?   r}   r   Nr@   r#   Fr?   r3   r   rZ   r   r   )rK   rZ   r   rP   )r+   rP   rK   rZ   r   rP   )r+   rP   r   rZ   )r   str | os.PathLiker   r   )r   r   r   r   r   )r   r3   r   r   )r   r   r   r   __doc__rb   rx   r   r   r   r   r   r   r   r   r   r   r)   r.   r,   r   r     s|     !"	<< < 	<--
'
   7(  r.   r   c                     ^  \ rS rSr   S     SU 4S jjjrSS jrSS jrS rSSS jjrSS jr	SS jr
SS	 jrSS
 jrSS jrS rSrU =r$ )ColorDependentPlotStylesi  c                   > [         TU ]  XU5        [        [        5       Vs/ s H  n[	        X@S9PM     snU l        U R
                  R                  S[	        S5      5        g s  snf )N)rO   r      )superrb   rangeSTYLE_COUNTr:   _stylesinsert)r`   r?   r   r   r+   	__class__s        r,   rb   !ColorDependentPlotStyles.__init__  s\     	LA7<[7I)
7IeIe)7I)
 	y~	
)
s   A$c                V    SUs=:  a  S:  a  O  OU R                   U   $ [        U5      e)z0Returns :class:`PlotStyle` for :ref:`ACI` `aci`.r   r   )r   r   )r`   r   s     r,   __getitem__$ColorDependentPlotStyles.__getitem__  s&    s=S=<<$$S/!r.   c                b    SUs=:  a  S:  a  O  OXl         X R                  U'   g[        U5      e)zSet plot `style` for `aci`.r   r   N)rO   r   r   )r`   r   styles      r,   __setitem__$ColorDependentPlotStyles.__setitem__  s(    s=S=L %LLS/!r.   c                2    [        U R                  SS 5      $ )zIterable of all plot styles.r   N)iterr   rg   s    r,   __iter__!ColorDependentPlotStyles.__iter__  s    DLL$%%r.   c                >    [        US-
  US9n[        Ul        X0U'   U$ )a?  Set `aci` to new attributes defined by `data` dict.

Args:
    aci: :ref:`ACI`
    data: ``dict`` of :class:`PlotStyle` attributes: description, color,
        physical_pen_number, virtual_pen_number, screen,
        linepattern_size, linetype, adaptive_linetype,
        lineweight, end_style, join_style, fill_style

r   )r+   ra   )r:   rT   rj   )r`   r   ra   r   s       r,   	new_style"ColorDependentPlotStyles.new_style  s(     ad3$S	r.   c                <    X   nUR                  5       nUS:X  a  gU$ )zLReturns the assigned lineweight for :class:`PlotStyle` `aci` in
millimeter.
r!   Nr~   )r`   r   r   rK   s       r,   r~   'ColorDependentPlotStyles.get_lineweight  s*     	))+
r.   c                    U R                  U5        U R                  U5        U R                  U5        U R                  U5        g)z$Write the CTB-file to text `stream`.N)_write_header_write_aci_table_write_plot_stylesr   r   s     r,   r   &ColorDependentPlotStyles.write_content  s:    6"f%''r.   c                V   UR                  SU R                  -  5        UR                  S5        UR                  SU R                  -  5        UR                  S[        U R                  5      R                  5       -  5        UR                  S[        U R                  5      -  5        g)1Write header values of CTB-file to text `stream`.description="%s
zaci_table_available=TRUE
scale_factor=%.1f
apply_factor=%s
#custom_lineweight_display_units=%s
Nr   r?   r   r3   r   r4   r   r   s     r,   r  &ColorDependentPlotStyles._write_header  s    (4+;+;;<12*T->->>?(3t/@/@+A+G+G+IIJ2$6678	
r.   c                    UR                  S5        U  H.  nUR                  nUR                  SU[        U5      4-  5        M0     UR                  S5        g)z1Write AutoCAD Color Index table to text `stream`.zaci_table{
z %d="%s
r   N)r   r+   r-   )r`   r   r   r+   s       r,   r  )ColorDependentPlotStyles._write_aci_table  sJ    ^$EKKELLz%/@'AAB  	Ur.   c                |    UR                  S5        U  H  nUR                  U5        M     UR                  S5        gz#Write user styles to text `stream`.zplot_style{
r   N)r   )r`   r   r   s      r,   r	  +ColorDependentPlotStyles._write_plot_styles  s0    _%EKK Ur.   c                    UR                  5        H/  u  p#[        U5      n[        X#5      n[        Ul        US-   nX0U'   M1     g )Nr   )r   rP   r:   rT   rj   )r`   r   r+   r   r   s        r,   r   $ColorDependentPlotStyles.load_styles  s?    "LLNLEJEe+E(E!)CI +r.   r   r   r   )r   rP   r   r:   )r   rP   r   r:   rq   )r   rP   ra   r   r   r:   )r   rP   r   )r   r   r   r   rb   r   r   r   r  r~   r   r  r  r	  r   r   __classcell__r   s   @r,   r   r     sk     !"	

 
 	
 
""&$	(	
 r.   r   c                     ^  \ rS rSr   S     SU 4S jjjrSS jrSS jrSS jrSS jrSS jr	SS jr
  S       SS	 jjrSS
 jrSS jrSS jrSS jrS rSrU =r$ )NamedPlotStylesi  c                R   > [         TU ]  XU5        [        SSSS.S9nSU0U l        g )Nr   Normal)r=   r>   ra   )r   rb   r:   r   )r`   r?   r   r   normalr   s        r,   rb   NamedPlotStyles.__init__  s:     	LA "*
 /7-?r.   c                "    U R                  5       $ )!Iterable of all plot style names.)keysrg   s    r,   r   NamedPlotStyles.__iter__  s    yy{r.   c                     U R                   U   $ )z%Returns :class:`PlotStyle` by `name`.r  r`   r=   s     r,   r   NamedPlotStyles.__getitem__  s    ||D!!r.   c                @    US:w  a  U R                   U	 g[        S5      e)zCDelete plot style `name`. Plot style ``'Normal'`` is not deletable.r   z"Can't delete plot style 'Normal'. N)r   r5   r)  s     r,   __delitem__NamedPlotStyles.__delitem__  s"    8T"ABBr.   c                    [        U R                  R                  5       5      nUR                  S5        S/nUR	                  [        U5      5        [        U5      $ )r%  r   )setr   r&  discardextendsortedr   )r`   r&  results      r,   r&  NamedPlotStyles.keys  sF    4<<$$&'XfTl#F|r.   c              #  ^   #    U R                  5        H  nXR                  U   4v   M     g7f)zDIterable of all plot styles as (``name``, class:`PlotStyle`) tuples.N)r&  r   )r`   r   s     r,   r   NamedPlotStyles.items  s'     99;C||C((( s   +-c              #  F   #    U R                  5        H	  u  pUv   M     g7f)z*Iterable of all class:`PlotStyle` objects.N)r   )r`   r   r6   s      r,   valuesNamedPlotStyles.values  s     **,JCK 's   !c                    UR                  5       S:X  a  [        S5      eU=(       d    0 nXS'   U=(       d    UUS'   [        U R                  5      n[	        XBU S9n[
        Ul        SUl        XPR                  U'   U$ )a  Create new class:`PlotStyle` `name` by attribute dict `data`, replaces
existing class:`PlotStyle` objects.

Args:
    name: plot style name
    localized_name: name shown in plot style editor, uses `name` if ``None``
    data: ``dict`` of :class:`PlotStyle` attributes: description, color,
        physical_pen_number, virtual_pen_number, screen,
        linepattern_size, linetype, adaptive_linetype, lineweight,
        end_style, join_style, fill_style

r   z-Can't replace or modify plot style 'Normal'. r=   r>   )r+   ra   rO   T)lowerr5   r   r   r:   	COLOR_ACIrj   r   )r`   r=   ra   r>   r+   r   s         r,   r  NamedPlotStyles.new_style   sy    $ ::<8#LMMzrV!/!74DLL!>$ "Tr.   c                <    X   nUR                  5       nUS:X  a  gU$ )zMReturns the assigned lineweight for :class:`PlotStyle` `name` in
millimeter.
r!   Nr  )r`   r=   r   rK   s       r,   r~   NamedPlotStyles.get_lineweight>  s*     
))+
r.   c                j    U R                  U5        U R                  U5        U R                  U5        g)z$Write the STB-file to text `stream`.N)r  r	  r   r   s     r,   r   NamedPlotStyles.write_contentI  s,    6"''r.   c                V   UR                  SU R                  -  5        UR                  S5        UR                  SU R                  -  5        UR                  S[        U R                  5      R                  5       -  5        UR                  S[        U R                  5      -  5        g)r  r  zaci_table_available=FALSE
r  r  r  Nr  r   s     r,   r  NamedPlotStyles._write_headerO  s    (4+;+;;<23*T->->>?(3t/@/@+A+G+G+IIJ2$6678	
r.   c                    UR                  S5        [        U R                  5       5       H  u  p#X#l        UR                  U5        M     UR                  S5        gr  )r   r   r8  r+   )r`   r   r+   r   s       r,   r	  "NamedPlotStyles._write_plot_stylesZ  sD    _%%dkkm4LEKKK 5 	Ur.   c                    UR                  5        H>  u  p#[        U5      n[        X#5      n[        Ul        X0R
                  UR                  '   M@     g rq   )r   rP   r:   r<  rj   r   r=   )r`   r   r+   r   s       r,   r   NamedPlotStyles.load_stylesb  s?    "LLNLEJEe+E(E',LL$	 +r.   r  r   r   )r   zIterable[str])r=   r3   r   r:   )r=   r3   r   r   )r   zIterator[tuple[str, PlotStyle]])r   zIterable[PlotStyle]r   )r=   r3   ra   r   r>   zOptional[str]r   r:   )r=   r3   r   )r   r   r   r   rb   r   r   r,  r&  r   r8  r  r~   r   r  r	  r   r   r  r  s   @r,   r  r    s     !"	@@ @ 	@ @ "C)
  $(,	  &	
 
<	(	
- -r.   r  c                n    [        U 5      n[        5       nUR                  UR                  5       5        U$ )z%Read a CTB-file from binary `stream`.)_decompressr   r   decoder   contentr   s      r,   	_read_ctbrM  j  s,     (G%'F
LL!"Mr.   c                n    [        U 5      n[        5       nUR                  UR                  5       5        U$ )z%Read a STB-file from binary `stream`.)rI  r  r   rJ  rK  s      r,   	_read_stbrO  r  s,     (GF
LL!"Mr.   c                h   [        U 5      n [        U S5       nU R                  5       R                  S5      (       a  [	        U5      sSSS5        $ U R                  5       R                  S5      (       a  [        U5      sSSS5        $ [        SR                  U 5      5      e! , (       d  f       g= f)z5Load the CTB or STB file `filename` from file system.rbz.ctbNz.stbzInvalid file type: "{}")r3   r   r;  endswithrM  rO  r5   format)r   r   s     r,   loadrT  z  s     8}H	h	>>$$V,,V$ 
	 ^^&&v..V$	 
	 6==hGHH 
	s   /B#.B#	B##
B1c                     [        5       $ )zCreate a new CTB file.)r   r)   r.   r,   new_ctbrV    s    #%%r.   c                     [        5       $ )zCreate a new STB file.)r  r)   r.   r,   new_stbrX    s    r.   c                ^    U R                  5       n[        R                  " USS 5      nUSS $ )z:Read and decompress the file content from binray `stream`.<   Nr   )readzlib
decompress)r   rL  ra   s      r,   rI  rI    s-    kkmG??723<(D9r.   c           
        [         R                  " UR                  5       5      n[         R                  " U5      nU R	                  S5        U R	                  [        SU[        U5      [        U5      5      5        U R	                  U5        g)z0Compress `content` and write to binary `stream`.s0   PIAFILEVERSION_2.0,CTBVER1,compress
pmzlibcodecLLLN)r\  compressencodeadler32r   r   r   )r   rL  	comp_bodyadler_chksums       r,   r   r     s]    gnn./I<<	*L
LLFG
LLe\3w<YHI
LLr.   c                  @    \ rS rSrSrSS jr\SS j5       rS	S jrSr	g)
r   i  zA very simple CTB/STB file parser. CTB/STB files are created by
applications, so the file structure should be correct in the most cases.
c                j    0 U l         [        R                  U5       H  u  p#X0R                   U'   M     g rq   )ra   r   	iteritems)r`   r   elementr6   s       r,   rb   PlotStyleFileParser.__init__  s-    	1;;DANG!&IIg Br.   c              #     ^^^^^#    SmSUU4S jjmS	UUUU4S jjmS
UUU4S jjmUU4S jnU R                  S5      mT[        T5      :  a,  T" 5       nT" 5       nX#4v   U" 5         T[        T5      :  a  M+  gg7f)z7Iterate over all first level (start at col 0) elements.r   c                    > TT   n U R                  S5      (       a  U SS nUR                  5       $ U R                  SS5      S   nUR                  5       $ )z&Get element name of line <line_index>.{Nr   =r   r   )rR  splitstrip)liner=   
line_indexliness     r,   get_name/PlotStyleFileParser.iteritems.<locals>.get_name  sX    $D}}S!!CRy ::< zz#q)!,::<r.   c                    > UU4S jn [        5       nU " 5       (       d   T" 5       nT" 5       nX1U'   U " 5       (       d  M   TS-  mU$ )zUGet mapping of elements enclosed by { }.

e. g. lineweights, plot_styles, aci_table

c                 ,   > TT    R                  S5      $ )N})rR  rq  rr  s   r,   end_of_listGPlotStyleFileParser.iteritems.<locals>.get_mapping.<locals>.end_of_list  s    Z(11#66r.   r   )dict)ry  ra   r=   r6   rs  	get_valuerq  rr  s       r,   get_mapping2PlotStyleFileParser.iteritems.<locals>.get_mapping  sF    7 6D!mmz!"T
 "mm !OJKr.   c                    > TT   n U R                  S5      (       a  TS-  mT" 5       $ U R                  SS5      S   n[        U5      nTS-  mU$ )zMGet value of line <line_index> or the list that starts in line
<line_index>.
rl  r   rm  )rR  rn  sanitized_value)rp  r6   r}  rq  rr  s     r,   r|  0PlotStyleFileParser.iteritems.<locals>.get_value  s\    
 $D}}S!!a
"}$!ZZQ/2'.a
Lr.   c                    > T [        T5      :  a=  [        TT    5      S:X  a*  T S-  m T [        T5      :  a  [        TT    5      S:X  a  M(  g g g g )Nr   r   )r   rx  s   r,   skip_empty_lines7PlotStyleFileParser.iteritems.<locals>.skip_empty_lines  sQ    s5z)c%
2C.D.Ia
 s5z)c%
2C.D.I).I)r.   
N)r   r3   )r   r{  )r   zUnion[str, dict])rn  r   )	r   r  r=   r6   r}  rs  r|  rq  rr  s	       @@@@@r,   rg  PlotStyleFileParser.iteritems  sv      
	  	 	 	&	 		 
 

4 3u:%:DKE+	 3u:%s   A1A<:A<c                8    U R                   R                  X5      $ rq   )ra   rQ   )r`   r=   defaults      r,   rQ   PlotStyleFileParser.get  s    yy}}T++r.   r!  N)r   r3   )r=   r3   r  r
   r   r
   )
r   r   r   r   r   rb   staticmethodrg  rQ   r   r)   r.   r,   r   r     s&    '
 9 9v,r.   r   c                    U R                  5       n U R                  S5      (       a  U SS  $ U R                  S5      (       a  U R                  S5      S   $ U $ )N"r   ) r   )ro  
startswithrR  rn  )r6   s    r,   r  r    sT    KKMEQRy ~~c{{3""Lr.   c                D    U S-  S-	  nU S-  S-	  nU S-  S-	  nU S-  nX#XA4$ )zLConvert color integer value from CTB-file to ``(r, g, b, color_type)
tuple.
l      ~    i      i      r    r)   )rA   rj   redgreenblues        r,   rf   rf     sD    
 *$+J8
"CV^!E4<Dt''r.   c                    [        XX#5      * $ )z:Convert mode_color (r, g, b, color_type) tuple to integer.)	color2intr  r  r  rj   s       r,   rk   rk     s    c$333r.   c                2    US-  U S-  -   US-  -   U-   * S-  $ )z/Convert color (r, g, b, color_type) to integer.r  r  r  l    r)   r  s       r,   r  r  	  s,    B3"9-!<tCDzQQr.   )r+   rP   r   r3   )r6   zUnion[str, bool]r   r   )r   r   r   r   )r   r   r   r  )r   r   r   z0Union[ColorDependentPlotStyles, NamedPlotStyles])r   r   )r   r  )r   r   r   bytes)r   r   rL  r3   )r6   r3   r   r3   )rA   rP   r   ztuple[int, int, int, int])r  rP   r  rP   r  rP   r   rP   )
r  rP   r  rP   r  rP   rj   rP   r   rP   )G
__future__r   typingr   r   r   r   r   r	   r
   osabcr   ior   r   structr   r\  END_STYLE_BUTTEND_STYLE_SQUAREEND_STYLE_ROUNDEND_STYLE_DIAMONDr]   JOIN_STYLE_MITERJOIN_STYLE_BEVELJOIN_STYLE_ROUNDJOIN_STYLE_DIAMONDr^   FILL_STYLE_SOLIDFILL_STYLE_CHECKERBOARDFILL_STYLE_CROSSHATCHFILL_STYLE_DIAMONDSFILL_STYLE_HORIZONTAL_BARSFILL_STYLE_SLANT_LEFTFILL_STYLE_SLANT_RIGHTFILL_STYLE_SQUARE_DOTSFILL_STYLE_VERICAL_BARSr_   rW   r   r   rY   r\   r[   rR   r   r   r   COLOR_BY_LAYERCOLOR_BY_BLOCKrT   r<  r-   r8   r:   r   r   r  rM  rO  rT  rV  rX  rI  r   r   r  rf   rk   r  r)   r.   r,   <module>r     s  
 #   
                       	  B   	 	$	c cLf fRf~ fRy-n y-xII5I&

G, G,T		( @I 4
Rr.   