
    ,hd2                         d Z ddlZddlZddlmZmZ ddlmZ  G d de      Z	 G d d	e      Z
 G d
 de      Z G d de      Z G d de      Z G d de      Zd Zy)z+Objects related to system font file lookup.    N)calcsizeunpack_from   )lazypropertyc                   t    e Zd ZdZdZed        Zed        Zed        Zed        Z	ed        Z
ed        Zy)		FontFileszR
    A class-based singleton serving as a lazy cache for system font details.
    Nc                 h    | j                   | j                         | _         | j                   |||f   S )z
        Return the absolute path to the installed OpenType font having
        *family_name* and the styles *is_bold* and *is_italic*.
        )_font_files_installed_fonts)clsfamily_nameis_bold	is_italics       Q/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pptx/text/fonts.pyfindzFontFiles.find   s4     ??"!224COWi@AA    c                 p    i }| j                         D ]   }| j                  |      D ]
  \  }}|||<    " |S )z
        Return a dict mapping a font descriptor to its font file path,
        containing all the font files resident on the current machine. The
        font descriptor is a (family_name, is_bold, is_italic) 3-tuple.
        )_font_directories_iter_font_files_in)r   fontsdkeypaths        r   r   zFontFiles._installed_fonts   sO     &&( 	"A 44Q7 "	T!c
"	" r   c                     t         j                  j                  d      r| j                         S t         j                  j                  d      r| j	                         S t        d      )zo
        Return a sequence of directory paths likely to contain fonts on the
        current platform.
        darwinwin32zunsupported operating system)sysplatform
startswith_os_x_font_directories_windows_font_directoriesOSErrorr   s    r   r   zFontFiles._font_directories+   sR     <<""8,--//<<""7+0022455r   c              #     K   t        j                  |      D ]  \  }}}|D ]  }t         j                  j                  |      d   }|j	                         dvr8t         j                  j                  t         j                  j                  ||            }t        j                  |      5 }|j                  |j                  |j                  f|f ddd         y# 1 sw Y   xY ww)a  
        Generate the OpenType font files found in and under *directory*. Each
        item is a key/value pair. The key is a (family_name, is_bold,
        is_italic) 3-tuple, like ('Arial', True, False), and the value is the
        absolute path to the font file.
           )z.otfz.ttfN)oswalkr   splitextlowerabspathjoin_Fontopenr   r   r   )	r   	directoryrootdirsfilesfilenamefile_extr   fs	            r   r   zFontFiles._iter_font_files_in7   s      "$!3 	JD$! J77++H5a8>>#+;;wwrww||D('CDZZ% JMM199akkBDIIJ JJ	JJ Js   B)C,+(C C, C)%C,c                     g d}t         j                  j                  d      }|P|j                  t         j                  j                  |dd      t         j                  j                  |d      g       |S )zp
        Return a sequence of directory paths on a Mac in which fonts are
        likely to be located.
        )z/Library/Fontsz/Network/Library/Fontsz/System/Library/FontsHOMELibraryFontsz.fonts)r&   environgetextendr   r+   )r   os_x_font_dirshomes      r   r    z FontFiles._os_x_font_directoriesH   sa    

 zz~~f%!!dIw7dH9UV r   c                     dgS )zr
        Return a sequence of directory paths on Windows in which fonts are
        likely to be located.
        zC:\Windows\Fonts r#   s    r   r!   z#FontFiles._windows_font_directoriesZ   s     $$$r   )__name__
__module____qualname____doc__r
   classmethodr   r   r   r   r    r!   r?   r   r   r   r      s     KB B 
 
 	6 	6 J J   " % %r   r   c                       e Zd ZdZd Zd Zd Zed        Zed        Z	e
d        Zed        Zed	        Zd
 Zed        Zed        Zy)r,   z
    A wrapper around an OTF/TTF font file stream that knows how to parse it
    for its name and style characteristics, e.g. bold and italic.
    c                     || _         y N)_stream)selfstreams     r   __init__z_Font.__init__i   s	    r   c                     | S rG   r?   rI   s    r   	__enter__z_Font.__enter__l   s    r   c                 8    | j                   j                          y rG   )rH   close)rI   exception_typeexception_valueexception_tbs       r   __exit__z_Font.__exit__o   s    r   c                 T    	 | j                   d   j                  S # t        $ r Y yw xY w)zS
        |True| if this font is marked as a bold style of its font family.
        headF)_tablesr   KeyErrorrM   s    r   r   z_Font.is_boldr   s.    
	<<'/// 		    	''c                 T    	 | j                   d   j                  S # t        $ r Y yw xY w)zV
        |True| if this font is marked as an italic style of its font family.
        rV   F)rW   r   rX   rM   s    r   r   z_Font.is_italic}   s.    
	<<'111 		rY   c                 8     | t         j                  |            S )zI
        Return a |_Font| instance loaded from *font_file_path*.
        )_Streamr-   )r   font_file_paths     r   r-   z
_Font.open   s    
 7<</00r   c                 4    | j                   d   j                  S )a  
        The name of the typeface family for this font, e.g. 'Arial'. The full
        typeface name includes optional style names, such as 'Regular' or
        'Bold Italic'. This attribute is only the common base name shared by
        all fonts in the family.
        name)rW   r   rM   s    r   r   z_Font.family_name   s     ||F#///r   c                 :    | j                   j                  dd      S )zo5-tuple containing the fields read from the font file header.

        Also known as the offset table.
        z>4sHHHHr   )rH   read_fieldsrM   s    r   _fieldsz_Font._fields   s     ||''	155r   c              #      K   | j                   }| j                  j                  d|dz        }d}t        |      D ]/  }|dz  }t	        |||      \  }}}}	|j                  d      ||	f 1 yw)zl
        Generate a (tag, offset, length) 3-tuple for each of the tables in
        this font file.
              )offsetlengthz>4sLLLzutf-8N)_table_countrH   readranger   decode)
rI   countbufrtmplirf   tagchecksumofflen_s
             r   _iter_table_recordsz_Font._iter_table_records   s~     
 !!||  52: >u 	1AVF'24v'F$C3**W%sD00	1s   A-A/c                 H     t         fd j                         D              S )z
        A mapping of OpenType table tag, e.g. 'name', to a table object
        providing access to the contents of that table.
        c              3   Z   K   | ]"  \  }}}|t        |j                  ||      f $ y wrG   )_TableFactoryrH   ).0rp   rr   rs   rI   s       r   	<genexpr>z _Font._tables.<locals>.<genexpr>   s3      
S$ -T\\3=>
s   (+)dictrt   rM   s   `r   rW   z_Font._tables   s(      
"&":":"<
 
 	
r   c                      | j                   d   S )zB
        The number of tables in this OpenType font file.
        r%   rb   rM   s    r   rh   z_Font._table_count   s    
 ||Ar   N)r@   rA   rB   rC   rK   rN   rT   propertyr   r   rD   r-   r   r   rb   rt   rW   rh   r?   r   r   r,   r,   c   s    
     1 1 0 0 6 61 
 
  r   r,   c                   :    e Zd ZdZd Zed        Zd Zd ZddZ	y)	r\   zMA thin wrapper around a binary file that facilitates reading C-struct values.c                     || _         y rG   )_file)rI   files     r   rK   z_Stream.__init__   s	    
r   c                 &     | t        |d            S )zGReturn |_Stream| providing binary access to contents of file at `path`.rb)r-   )r   r   s     r   r-   z_Stream.open   s     4d#$$r   c                 8    | j                   j                          y)ze
        Close the wrapped file. Using the stream after closing raises an
        exception.
        N)r   rP   rM   s    r   rP   z_Stream.close   s    
 	

r   c                 n    | j                   j                  |       | j                   j                  |      S )zN
        Return *length* bytes from this stream starting at *offset*.
        )r   seekri   )rI   rf   rg   s      r   ri   z_Stream.read   s'     	

zzv&&r   c                     | j                   j                  |       | j                   j                  t        |            }t	        ||      S )z
        Return a tuple containing the C-struct fields in this stream
        specified by *template* and starting at *offset*.
        )r   r   ri   r   r   )rI   templaterf   rm   s       r   ra   z_Stream.read_fields   s8    
 	

zzx128T**r   N)r   )
r@   rA   rB   rC   rK   rD   r-   rP   ri   ra   r?   r   r   r\   r\      s-    W % %'+r   r\   c                       e Zd ZdZd Zy)
_BaseTablez:
    Base class for OpenType font file table objects.
    c                 <    || _         || _        || _        || _        y rG   )_tagrH   _offset_length)rI   rp   rJ   rf   rg   s        r   rK   z_BaseTable.__init__   s    	r   N)r@   rA   rB   rC   rK   r?   r   r   r   r      s    r   r   c                   b     e Zd ZdZ fdZed        Zed        Zed        Z	ed        Z
 xZS )
_HeadTablez
    OpenType font table having the tag 'head' and containing certain header
    information for the font, including its bold and/or italic style.
    c                 2    t         t        |   ||||       y rG   )superr   rK   rI   rp   rJ   rf   rg   	__class__s        r   rK   z_HeadTable.__init__       j$(fffEr   c                 2    t        | j                  dz        S )zP
        |True| if this font is marked as having emboldened characters.
        r%   bool	_macStylerM   s    r   r   z_HeadTable.is_bold       
 DNNQ&''r   c                 2    t        | j                  dz        S )zP
        |True| if this font is marked as having italicized characters.
        r   r   rM   s    r   r   z_HeadTable.is_italic  r   r   c                 N    | j                   j                  d| j                        S )zA
        A 17-tuple containing the fields in this table.
        z>4s4sLLHHqqhhhhHHHHH)rH   ra   r   rM   s    r   rb   z_HeadTable._fields  s     
 ||''(>MMr   c                      | j                   d   S )zV
        The unsigned short value of the 'macStyle' field in this head table.
        rd   r|   rM   s    r   r   z_HeadTable._macStyle  s    
 ||Br   )r@   rA   rB   rC   rK   r}   r   r   r   rb   r   __classcell__r   s   @r   r   r      s`    
F ( ( ( ( N N    r   r   c                        e Zd ZdZ fdZed        Zed        Zd Z	ed        Z
ed        Zd Zd	 Zed
        Zed        Zed        Z xZS )
_NameTablezp
    An OpenType font table having the tag 'name' and containing the
    name-related strings for the font.
    c                 2    t         t        |   ||||       y rG   )r   r   rK   r   s        r   rK   z_NameTable.__init__  r   r   c                 0    dd} || j                   d      S )zN
        The name of the typeface family for this font, e.g. 'Arial'.
        c                 B    |D ]  }| j                  |      }||c S  |S rG   )r:   )dict_keysdefaultr   values        r   
find_firstz*_NameTable.family_name.<locals>.find_first&  s0     !		#$ L! Nr   ))r   r%   )r%   r%   )   r%   rG   )_names)rI   r   s     r   r   z_NameTable.family_name   s    	 $++'?@@r   c                 f    |dk(  r|dk7  ry| j                  d      S |dv r| j                  d      S y)z
        Return the unicode name decoded from *raw_name* using the encoding
        implied by the combination of *platform_id* and *encoding_id*.
        r%   r   Nz	mac-roman)r   r   z	utf-16-be)rk   )raw_nameplatform_idencoding_ids      r   _decode_namez_NameTable._decode_name0  s@     !a??;//F"??;//r   c              #      K   | j                   \  }}}| j                  }t        |      D ]$  }| j                  |||      \  }}}|||f|f & yw)zGenerate a key/value pair for each name in this table.

        The key is a (platform_id, name_id) 2-tuple and the value is the unicode text
        corresponding to that key.
        N)_table_header_table_bytesrj   
_read_name)	rI   table_formatrl   strings_offsettable_bytesidxr   name_idr_   s	            r   _iter_namesz_NameTable._iter_names@  sn      /3.@.@+e^''< 	1C)-S.*&K$ |)400	1s   AAc                 ,    d|dz  z   }t        d| |      S )z
        The (platform_id, encoding_id, language_id, name_id, length,
        name_str_offset) 6-tuple encoded in each name record C-struct.
           rd   z>HHHHHHr   )rm   r   name_hdr_offsets      r   _name_headerz_NameTable._name_headerQ  s      cBh,9dO<<r   c                 6    ||z   }d|z  }t        || |      d   S )z
        Return the *length* bytes comprising the encoded string in *bufr* at
        *str_offset* in the strings area beginning at *strings_offset*.
        z%dsr   r   )rm   r   
str_offsetrg   rf   rn   s         r   _raw_name_stringz_NameTable._raw_name_stringZ  s+      *,v~4v.q11r   c                 j    | j                  ||      \  }}}}}}	| j                  |||||	|      }
|||
fS )aG  Return a (platform_id, name_id, name) 3-tuple for name at `idx` in `bufr`.

        The triple looks like (0, 1, 'Arial'). `strings_offset` is the for the name at
        `idx` position in `bufr`. `strings_offset` is the index into `bufr` where actual
        name strings begin. The returned name is a unicode string.
        )r   _read_name_text)rI   rm   r   r   r   enc_idlang_idr   rg   r   r_   s              r   r   z_NameTable._read_named  sW     EIDUDU#E
AVWgvz ##+v~z6
 GT))r   c                 P    | j                  ||||      }| j                  |||      S )z
        Return the unicode name string at *name_str_offset* or |None| if
        decoding its format is not supported.
        )r   r   )rI   rm   r   r   r   name_str_offsetrg   r   s           r   r   z_NameTable._read_name_texts  s0     ((~PVW  ;DDr   c                 b    | j                   j                  | j                  | j                        S )z9
        The binary contents of this name table.
        )rH   ri   r   r   rM   s    r   r   z_NameTable._table_bytes}  s#    
 ||  t||<<r   c                 .    t        d| j                        S )zw
        The (table_format, name_count, strings_offset) 3-tuple contained
        in the header of this table.
        z>HHH)r   r   rM   s    r   r   z_NameTable._table_header  s     64#4#455r   c                 4    t        | j                               S )zGA mapping of (platform_id, name_id) keys to string names for this font.)rz   r   rM   s    r   r   z_NameTable._names  s     D$$&''r   )r@   rA   rB   rC   rK   r}   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r     s    
F A A  1" = = 2 2*E = = 6 6 ( (r   r   c                 Z    t         t        dj                  | t              } || |||      S )z
    Return an instance of |Table| appropriate to *tag*, loaded from
    *font_file* with content of *length* starting at *offset*.
    )rV   r_   )r   r   r:   r   )rp   rJ   rf   rg   
TableClasss        r   rw   rw     s,    
 %j9==c:NJc66622r   )rC   r&   r   structr   r   utilr   objectr   r,   r\   r   r   r   rw   r?   r   r   <module>r      sn    2 	 
 ( S% S%l\F \~ +f  +F	 	#  # Lx( x(v3r   