o
    h:                      @   s   d dl mZ d dlZ d dlmZmZmZ d dlmZm	Z	 d dl
mZ d dlZ d dlmZ d dlmZ d dlZd dlZedZeeed	 ejd
ZG dd deZg dZeddddZedkrlee  dS dS )    )ttLibN)computeMegaGlyphOrdercomputeMegaCmaprenameCFFCharStrings)layoutPreMergelayoutPostMerge)Options)Timer)reducezfontTools.mergez.timer)loggerlevelc                   @   sB   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dS )Mergera  Font merger.

    This class merges multiple files into a single OpenType font, taking into
    account complexities such as OpenType layout (``GSUB``/``GPOS``) tables and
    cross-font metrics (for example ``hhea.ascent`` is set to the maximum value
    across all the fonts).

    If multiple glyphs map to the same Unicode value, and the glyphs are considered
    sufficiently different (that is, they differ in any of paths, widths, or
    height), then subsequent glyphs are renamed and a lookup in the ``locl``
    feature will be created to disambiguate them. For example, if the arguments
    are an Arabic font and a Latin font and both contain a set of parentheses,
    the Latin glyphs will be renamed to ``parenleft.1`` and ``parenright.1``,
    and a lookup will be inserted into the to ``locl`` feature (creating it if
    necessary) under the ``latn`` script to substitute ``parenleft`` with
    ``parenleft.1`` etc.

    Restrictions:

    - All fonts must have the same units per em.
    - If duplicate glyph disambiguation takes place as described above then the
      fonts must have a ``GSUB`` table.

    Attributes:
            options: Currently unused.
    Nc                 C   s   |st  }|| _d S N)r   options)selfr    r   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fontTools/merge/__init__.py__init__5   s   
zMerger.__init__c                 C   s<   dd |D }t ||D ]\}}||_|d d|_q|S )Nc                 S   s   g | ]}t |qS r   )r   TTFont).0fontfiler   r   r   
<listcomp><   s    z%Merger._openFonts.<locals>.<listcomp>name   )zip_merger__fontfilegetDebugName_merger__name)r   	fontfilesfontsfontr   r   r   r   
_openFonts;   s
   zMerger._openFontsc              	      s  |  |}dd |D }t| | |d j}|  |}t||D ]\}}|| d|v r5t| ||d  q dd |D }dd |D | _t| | tj	|d}|| j
 |D ]}| | qX|| _ttjdd	 |D t }	|	d
 t|	D ]T  | jjv rqytd  =  fdd|D }
td  t }| | |
}|tur|dur|| < td  ntd  W d   n1 sw   Y  qy| `| `| | |S )a  Merges fonts together.

        Args:
                fontfiles: A list of file names to be merged

        Returns:
                A :class:`fontTools.ttLib.TTFont` object. Call the ``save`` method on
                this to write it out to an OTF file.
        c                 S   s   g | ]}t | qS r   )listgetGlyphOrderr   r    r   r   r   r   P       z Merger.merge.<locals>.<listcomp>r   zCFF c                 S   s   g | ]}|d  qS )cmapr   r$   r   r   r   r   ]   s    c                 S   s   g | ]}i qS r   r   )r   _r   r   r   r   ^   s    )sfntVersionc                 s   s    | ]	}t | V  qd S r   )r"   keysr$   r   r   r   	<genexpr>i       zMerger.merge.<locals>.<genexpr>
GlyphOrderz
merge '%s'c                    s   g | ]}|  tqS r   )getNotImplementedr$   tagr   r   r   q   r%   zMerging '%s'.FzMerged '%s'.zDropped '%s'.N)r!   r   r(   r   setGlyphOrderr   duplicateGlyphsPerFontr   r   r   
glyphOrder	_preMerger   r
   setunionremovesortedr   drop_tablestimerloginfogetTableClassmerger.   
_postMerge)r   r   r   glyphOrdersr(   r    r3   cmapsmegaallTagstablesclazztabler   r/   r   r>   B   sN   








zMerger.mergec                    s   t jt  gdd |D R  }|D ]J td  z|  }W n! ty@   z|d }W n ty=   td |jjf w Y nw |tu rFq| fdd|D }|tur[t	| | q|S )Nc                 s   s$    | ]}|t urt| V  qd S r   )r.   varsr)   r   rF   r   r   r   r*      s   " z&Merger.mergeObjects.<locals>.<genexpr>z %s*z*Don't know how to merge key %s of class %sc                 3   s    | ]	}t | tV  qd S r   )getattrr.   rH   keyr   r   r*      r+   )
r5   r6   r;   r<   KeyError	Exception	__class____name__r.   setattr)r   returnTablelogicrD   allKeys
mergeLogicvaluer   rK   r   mergeObjects   s8   
zMerger.mergeObjectsc                 C   s   t | d S r   )r   r   r    r   r   r   r4      s   zMerger._preMergec                 C   s&   t | d|v r|d | d S d S )NzOS/2)r   recalcAvgCharWidthrX   r   r   r   r?      s   zMerger._postMerger   )
rP   
__module____qualname____doc__r   r!   r>   rW   r4   r?   r   r   r   r   r      s    
Cr   )r   r   mainz%make one with everything (TOTAL TIME)c                 C   s  ddl m} | du rtjdd } t }|| } g }|jr<t|j}dd | D }W d   n1 s7w   Y  | D ]}|	| q>t
|dk rtdtjd td	tjd td
tjd tdtjd tdtjd tdtjd tdtjd tdtjd tdtjd tdtjd dS ||jrtjntjd |jrtjtj ndtj_t|d}||}|jr||j td ||j W d   dS 1 sw   Y  dS )zMerge multiple fonts into oner   )configLoggerN   c                 S   s"   g | ]}|  d s| qS )#)lstrip
startswithstrip)r   liner   r   r   r      s    zmain.<locals>.<listcomp>ztusage: pyftmerge [font1 ... fontN] [--input-file=filelist.txt] [--output-file=merged.ttf] [--import-file=tables.ttx])filezN                                   [--drop-tables=tags] [--verbose] [--timing] z- font1 ... fontN              Files to merge.zp --input-file=<filename>      Read files to merge from a text file, each path new line. # Comment lines allowed.zM --output-file=<filename>     Specify output file name (default: merged.ttf).za --import-file=<filename>     TTX file to import after merging. This can be used to set metadata.zY --drop-tables=<table tags>   Comma separated list of table tags to skip, case sensitive.z: --verbose                    Output progress information.z5 --timing                     Output progress timing.)r   T)r   zcompile and save font)	fontToolsr^   sysargvr   
parse_opts
input_fileopen	readlinesappendlenprintstderrverboseloggingINFOWARNINGtimingr:   r   setLevelDEBUGdisabledr   r>   import_file	importXMLsaveoutput_file)argsr^   r   r   	inputfilegmergerr    r   r   r   r]      st   



"r]   __main__r   )rg   r   fontTools.merge.basefontTools.merge.cmapr   r   r   fontTools.merge.layoutr   r   fontTools.merge.optionsr   fontTools.merge.tablesfontTools.misc.loggingToolsr	   	functoolsr
   rh   rs   	getLoggerr;   rP   rt   r:   objectr   __all__r]   exitr   r   r   r   <module>   s(   
 F