
    Ph                     \    d dl mZ ddlmZ  G d dej                        Z G d de      Zy)	    )safeEval   )DefaultTablec                   P    e Zd ZdZed        Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zy)table_C_O_L_R_a  Color table

    The ``COLR`` table defines color presentation of outline glyphs. It must
    be used in concert with the ``CPAL`` table, which contains the color
    descriptors used.

    This table is structured so that you can treat it like a dictionary keyed by glyph name.

    ``ttFont['COLR'][<glyphName>]`` will return the color layers for any glyph.

    ``ttFont['COLR'][<glyphName>] = <value>`` will set the color layers for any glyph.

    See also https://learn.microsoft.com/en-us/typography/opentype/spec/colr
    c                    | j                   si S i }| j                   j                  }t        |      }| j                  j                  D ]  }|j
                  }|j                  }|j                  }||z   |k  sJ g }t        |||z         D ]6  }	||	   }
|j                  t        |
j                  |
j                               8 |||<    |S N)LayerRecordArrayLayerRecordlenBaseGlyphRecordArrayBaseGlyphRecord	BaseGlyphFirstLayerIndex	NumLayersrangeappend
LayerGlyphPaletteIndex)tablecolorLayerListslayerRecordsnumLayerRecordsbaseRec	baseGlyphfirstLayerIndex	numLayerslayersilayerRecs              jC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\fontTools/ttLib/tables/C_O_L_R_.py_decompileColorLayersV0z&table_C_O_L_R_._decompileColorLayersV0   s    %%I--99l+11AAG))I%55O))I"Y./AAAF?Oi,GH'?k(*=*=x?T?TUV I *0OI& B     c                 l   ddl m} ddlm} t	        || j
                        } |       }| j                  |_         ||| j                  j                         D ci c],  \  }}||D cg c]  }|j                  |j                  f c}. c}}}|j                  d             |S c c}w c c}}}w )Nr   otTablesr   )populateCOLRv0T)rebuild)glyphMap) r&   fontTools.colorLib.builderr'   getattrtableTagversionVersionColorLayersitemsnamecolorIDgetReverseGlyphMap)	selfttFontr&   r'   
tableClassr   r   r   layers	            r!   
_toOTTableztable_C_O_L_R_._toOTTable,   s    =Xt}}5
 *.)9)9)?)?)A)A%Iv VLVEUZZ7VLL)A ..t.<	
  Ms   B/)B*B/*B/c                    ddl m} ddlm}  ||| j                        }t        || j                        } |       }|j                  ||       |j                  | _        | j                  dk(  r| j                  |      | _
        y || _        y )Nr   )OTTableReaderr%   r-   r   )otBaser;   r*   r&   r-   r,   	decompiler/   r.   r"   r0   r   )r5   datar6   r;   r&   readerr7   r   s           r!   r>   ztable_C_O_L_R_.decompile>   sr    ) tdmm<Xt}}5
'}}<<1#;;EBD DJr#   c                     ddl m} t        | d      r| j                  }n| j	                  |      } || j
                        }|j                  ||       |j                         S )Nr   )OTTableWriterr   r<   )r=   rB   hasattrr   r9   r-   compile
getAllData)r5   r6   rB   r   writers        r!   rD   ztable_C_O_L_R_.compileP   sQ    )4!JJEOOF+E6ff%  ""r#   c                    t        | d      r| j                  j                  ||       y |j                  d| j                         |j                          t        | j                  j                         |j                        D ]l  }|j                  d|       |j                          | j                  |   D ]  }|j                  ||        |j                  d       |j                          n y )Nr   r.   )value)key
ColorGlyph)r2   )rC   r   toXML2	simpletagr.   newlinesortedr0   keys
getGlyphIDbegintagtoXMLendtag)r5   rF   r6   r   r8   s        r!   rR   ztable_C_O_L_R_.toXML\   s    4!JJff-Ydll;NN#D$4$4$9$9$;ARARS	9= !--i8EKK/ 9l+  Tr#   c                 ~   |dk(  rt        | |t        |d                y |dk(  rt        | d      si | _        |d   }|D ]  }t	        |t
              s g }|D ]K  }t	        |t
              rt               }|j                  |d   |d   |d   |       |j                  |       M || j                  |<   y dd	l	m
}	 t        | d
      s"t        |	| j                        }
 |
       | _        | j                  j                  ||||       | j                  j                          | j                  j                  | _        y )Nr.   rH   rJ   r0   r2   r   r      r%   r   )setattrr   rC   r0   
isinstancestrr   fromXMLr   r*   r&   r,   r-   r   populateDefaultsr/   r.   )r5   r2   attrscontentr6   	glyphNameelementr   r8   r&   r7   s              r!   rY   ztable_C_O_L_R_.fromXMLj   s   9D$w 89\!4/#% fI"gs+ # F"gs+#gaj'!*gaj&Ie$ # +1DY'"4)$Xt}}=
'\
JJtUGV<JJ'')::--DLr#   c                     t        |t              s!t        dt        |      j                         | j
                  |   S Nzexpected str, found rW   rX   	TypeErrortype__name__r0   r5   r]   s     r!   __getitem__ztable_C_O_L_R_.__getitem__   s;    )S)24	?3K3K2LMNN	**r#   c                     t        |t              s!t        dt        |      j                         ||| j
                  |<   y || j
                  v r| j
                  |= y y r`   ra   )r5   r]   rH   s      r!   __setitem__ztable_C_O_L_R_.__setitem__   sa    )S)24	?3K3K2LMNN*/DY'$***  + +r#   c                     | j                   |= y r	   )r0   re   s     r!   __delitem__ztable_C_O_L_R_.__delitem__   s    Y'r#   N)rd   
__module____qualname____doc__staticmethodr"   r9   r>   rD   rR   rY   rf   rh   rj    r#   r!   r   r   	   sC      $$$
#!.8+
,(r#   r   c                        e Zd ZddZd Zd Zy)r   Nc                      || _         || _        y r	   r2   r3   )r5   r2   r3   s      r!   __init__zLayerRecord.__init__   s    	r#   c                 t    |j                  d| j                  | j                         |j                          y )Nr8   rr   )rL   r2   r3   rM   )r5   rF   r6   s      r!   rR   zLayerRecord.toXML   s)    tyy$,,Gr#   c                     |j                         D ].  \  }}|dk(  rt        | ||       t        | |t        |             0 y )Nr2   )r1   rV   r   )r5   eltnamer[   r\   r6   r2   rH   s          r!   rY   zLayerRecord.fromXML   s9     ;;=KD%v~dE*dHUO4	 )r#   )NN)rd   rk   rl   rs   rR   rY   ro   r#   r!   r   r      s    5r#   r   N)fontTools.misc.textToolsr   r*   r   r   objectr   ro   r#   r!   <module>ry      s.   
 . K(\.. K(\5& 5r#   