B
    JdY\                 @   s  d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
Z
d dlZeeZdZG dd deZd	Zd
Zed Zed ZdZee Zee Zee Zee Zee Zee ZG dd de	j	ZdZg ZdgZdd ZdddZedkrd dl Z d dl!Z!e!"e # j$ dS )    )sstruct)otRound)safeEval
num2binary
binary2num)DefaultTableNz
	bFamilyType:        B
	bSerifStyle:        B
	bWeight:            B
	bProportion:        B
	bContrast:          B
	bStrokeVariation:   B
	bArmStyle:          B
	bLetterForm:        B
	bMidline:           B
	bXHeight:           B
c               @   s   e Zd Zdd Zdd ZdS )Panosec             C   s>   t t\}}}x(|D ] }|j|t| |d |  qW d S )N)value)r   	getformatpanoseFormat	simpletaggetattrnewline)selfwriterttFontformatstringnamesfixesname r   Q/var/www/html/venv/lib/python3.7/site-packages/fontTools/ttLib/tables/O_S_2f_2.pytoXML   s    
zPanose.toXMLc             C   s   t | |t|d  d S )Nr	   )setattrr   )r   r   attrscontentr   r   r   r   fromXML"   s    zPanose.fromXMLN)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   a  
	>   # big endian
	version:                H       # version
	xAvgCharWidth:          h       # average character width
	usWeightClass:          H       # degree of thickness of strokes
	usWidthClass:           H       # aspect ratio
	fsType:                 H       # type flags
	ySubscriptXSize:        h       # subscript horizontal font size
	ySubscriptYSize:        h       # subscript vertical font size
	ySubscriptXOffset:      h       # subscript x offset
	ySubscriptYOffset:      h       # subscript y offset
	ySuperscriptXSize:      h       # superscript horizontal font size
	ySuperscriptYSize:      h       # superscript vertical font size
	ySuperscriptXOffset:    h       # superscript x offset
	ySuperscriptYOffset:    h       # superscript y offset
	yStrikeoutSize:         h       # strikeout size
	yStrikeoutPosition:     h       # strikeout position
	sFamilyClass:           h       # font family class and subclass
	panose:                 10s     # panose classification number
	ulUnicodeRange1:        L       # character range
	ulUnicodeRange2:        L       # character range
	ulUnicodeRange3:        L       # character range
	ulUnicodeRange4:        L       # character range
	achVendID:              4s      # font vendor identification
	fsSelection:            H       # font selection flags
	usFirstCharIndex:       H       # first unicode character index
	usLastCharIndex:        H       # last unicode character index
	sTypoAscender:          h       # typographic ascender
	sTypoDescender:         h       # typographic descender
	sTypoLineGap:           h       # typographic line gap
	usWinAscent:            H       # Windows ascender
	usWinDescent:           H       # Windows descender
z/
	ulCodePageRange1:   L
	ulCodePageRange2:   L
zt
	sxHeight:           h
	sCapHeight:         h
	usDefaultChar:      H
	usBreakChar:        H
	usMaxContext:       H
z?
	usLowerOpticalPointSize:    H
	usUpperOpticalPointSize:    H
z	>	# big endian
c               @   s   e Zd ZdZdgZdd Zdd Zdd Zd	d
 Zdd Z	e
dd Zejdd Ze
dd Zejdd Ze
dd Zejdd Zdd Zdd Zd ddZdd ZdS )!table_O_S_2f_2zthe OS/2 tableheadc             C   s   t t|| \}}| jdkr0t t|| \}}n~| jdkrNt t|| \}}n`| jdkrt t|| \}}|  jd  _|  jd  _n&| jdkrddl	m
} |d| j t|rtd t t| jt | _d S )	N   )               r   )ttLibz)unknown format for OS/2 table: version %sztoo much 'OS/2' table data)r   Zunpack2OS2_format_0versionOS2_format_1_additionOS2_format_2_additionOS2_format_5_additionusLowerOpticalPointSizeusUpperOpticalPointSize	fontToolsr(   
TTLibErrorlenlogwarningunpackr   panoser   )r   datar   dummyr(   r   r   r   	decompilel   s    




ztable_O_S_2f_2.decompilec             C   sZ  |  | | j}|d }| jd@ r6|jd@ s6td | jd@ rT|jd@ sTtd | jd@ rr| jd@ rrtd	 | jd
k r| jd@ rtd| j tt	| j| _| jdkrtt
| }n| jdkrtt| }n|| jdkrtt| }nd| jdkr4| j }t| jd |d< t| jd |d< tt|}nddlm} |d| j || _|S )Nr!   r"   r#   zNfsSelection bit 0 (italic) and head table macStyle bit 1 (italic) should match    zJfsSelection bit 5 (bold) and head table macStyle bit 0 (bold) should match@   !   zNfsSelection bit 6 (regular) is set, bits 0 (italic) and 5 (bold) must be clearr%   i  zWfsSelection bits 7, 8 and 9 are only defined in OS/2 table version 4 and up: version %sr   )r#   r$   r%   r&   r'   r.   r/   )r(   z)unknown format for OS/2 table: version %s)updateFirstAndLastCharIndexr6   fsSelectionZmacStyler3   r4   r*   r   packr   r)   OS2_format_1OS2_format_2__dict__copyroundr.   r/   OS2_format_5r0   r(   r1   )r   r   r6   r!   r7   dr(   r   r   r   compile   s8    







ztable_O_S_2f_2.compilec       	      C   s  | d |  | jdkr"t}n$| jdkr2t}n| jdkrBt}nt}t|\}}}x|D ]}t	| |}|dkr|
d |  ||| |d nl|dkr|j|t|d nP|dkr|j|t|d	d n2|d
kr|j|t|dd d n|j||d |  q\W d S )NzXThe fields 'usFirstCharIndex' and 'usLastCharIndex'
will be recalculated by the compilerr"   )r#   r$   r%   r&   r6   )ulUnicodeRange1ulUnicodeRange2ulUnicodeRange3ulUnicodeRange4ulCodePageRange1ulCodePageRange2)r	   )fsTyper>      	achVendID)commentr   r*   r@   rA   rE   r)   r   r
   r   Zbegintagr   Zendtagr   r   repr)	r   r   r   formatr   r   r   r   r	   r   r   r   r      s4    





ztable_O_S_2f_2.toXMLc             C   s   |dkrHt   | _}x|D ](}t|tr|\}}}||||| qW nX|dkrft| |t|d  n:|dkrt| |td|d  d  nt| |t|d  d S )Nr6   )rH   rI   rJ   rK   rL   rM   rN   r>   r	   rP   z''')r   r6   
isinstancetupler   r   r   r   )r   r   r   r   r   r6   elementr   r   r   r      s    


ztable_O_S_2f_2.fromXMLc             C   st   d|krd S t  }x0t|d dg D ]}| r$||j  q$W |rpt|}t|}td|| _td|| _	d S )Ncmaptablesi  )
setr   	isUnicodeupdaterX   keysminmaxusFirstCharIndexusLastCharIndex)r   r   codestableZminCodeZmaxCoder   r   r   r=      s    z*table_O_S_2f_2.updateFirstAndLastCharIndexc             C   s   | j S )N)usMaxContext)r   r   r   r   usMaxContex   s    ztable_O_S_2f_2.usMaxContexc             C   s
   || _ d S )N)rd   )r   r	   r   r   r   re      s    c             C   s   | j S )N)r`   )r   r   r   r   fsFirstCharIndex   s    ztable_O_S_2f_2.fsFirstCharIndexc             C   s
   || _ d S )N)r`   )r   r	   r   r   r   rf      s    c             C   s   | j S )N)ra   )r   r   r   r   fsLastCharIndex   s    ztable_O_S_2f_2.fsLastCharIndexc             C   s
   || _ d S )N)ra   )r   r	   r   r   r   rg      s    c             C   s   t  }| j| j }}| j| j }}xttdD ]h}|d|> @ rF|| |d|> @ r`||d  |d|> @ rz||d  |d|> @ r,||d  q,W |S )z= Return the set of 'ulUnicodeRange*' bits currently enabled. r:   r"   r;   `   )rZ   rH   rI   rJ   rK   rangeadd)r   bitsul1ul2ul3ul4ir   r   r   getUnicodeRanges   s    
ztable_O_S_2f_2.getUnicodeRangesc             C   s   d\}}}}x|D ]}d|  kr*dk r<n n|d|> O }qd|  krPdk rfn n|d|d > O }qd|  krzdk rn n|d|d > O }qd|  krdk rn n|d|d > O }qt d| qW || | _| _|| | _| _d	S )
z; Set the 'ulUnicodeRange*' fields to the specified 'bits'. )r   r   r   r   r   r:   r"   r;   rh   {   z#expected 0 <= int <= 122, found: %rN)
ValueErrorrH   rI   rJ   rK   )r   rk   rl   rm   rn   ro   bitr   r   r   setUnicodeRanges  s    
ztable_O_S_2f_2.setUnicodeRangesFc             C   sf   t  }x*|d jD ]}| r||j  qW |rPt|dd}|  | }nt|}| | |S )a/   Intersect the codepoints in the font's Unicode cmap subtables with
		the Unicode block ranges defined in the OpenType specification (v1.7),
		and set the respective 'ulUnicodeRange*' bits if there is at least ONE
		intersection.
		If 'pruneOnly' is True, only clear unused bits with NO intersection.
		rX   T)inverse)	rZ   rY   r[   r\   rX   r]   intersectUnicodeRangesrq   ru   )r   r   Z	pruneOnlyunicodesrc   emptyrk   r   r   r   recalcUnicodeRanges  s    
z"table_O_S_2f_2.recalcUnicodeRangesc             C   sD   d}| d}|r:dd |j D }tt|t| }|| _|S )zRecalculate xAvgCharWidth using metrics from ttFont's 'hmtx' table.

		Set it to 0 if the unlikely event 'hmtx' table is not found.
		r   hmtxc             S   s    g | ]}|d  d kr|d  qS )r   r   ).0mr   r   r   
<listcomp>7  s    z5table_O_S_2f_2.recalcAvgCharWidth.<locals>.<listcomp>)getZmetricsvaluesr   sumr2   ZxAvgCharWidth)r   r   Z	avg_widthr{   widthsr   r   r   recalcAvgCharWidth/  s    
z!table_O_S_2f_2.recalcAvgCharWidthN)F)r   r   r   __doc__dependenciesr9   rG   r   r   r=   propertyre   setterrf   rg   rq   ru   rz   r   r   r   r   r   r    f   s"   "!
r    ){))zBasic Latin)r      ))zLatin-1 Supplement)      ))zLatin Extended-A)   i  ))zLatin Extended-B)i  iO  ))zIPA Extensions)iP  i  )zPhonetic Extensions)i   i  )zPhonetic Extensions Supplement)i  i  ))zSpacing Modifier Letters)i  i  )zModifier Tone Letters)i   i  ))zCombining Diacritical Marks)i   io  )z&Combining Diacritical Marks Supplement)i  i  ))zGreek and Coptic)ip  i  ))ZCoptic)i,  i,  ))Cyrillic)i   i  )zCyrillic Supplement)i   i/  )zCyrillic Extended-A)i-  i-  )zCyrillic Extended-B)i@  i  ))ZArmenian)i0  i  ))Hebrew)i  i  ))ZVai)i   i?  ))Arabic)i   i  )zArabic Supplement)iP  i  ))ZNKo)i  i  ))
Devanagari)i 	  i	  ))ZBengali)i	  i	  ))ZGurmukhi)i 
  i
  ))ZGujarati)i
  i
  ))ZOriya)i   i  ))ZTamil)i  i  ))ZTelugu)i   i  ))ZKannada)i  i  ))Z	Malayalam)i   i  ))Thai)i   i  ))ZLao)i  i  ))ZGeorgian)i  i  )zGeorgian Supplement)i -  i/-  ))ZBalinese)i   i  ))zHangul Jamo)i   i  ))zLatin Extended Additional)i   i  )zLatin Extended-C)i`,  i,  )zLatin Extended-D)i   i  ))zGreek Extended)i   i  ))zGeneral Punctuation)i    io   )zSupplemental Punctuation)i .  i.  ))zSuperscripts And Subscripts)ip   i   ))zCurrency Symbols)i   i   ))z'Combining Diacritical Marks For Symbols)i   i   ))zLetterlike Symbols)i !  iO!  ))zNumber Forms)iP!  i!  ))ZArrows)i!  i!  )zSupplemental Arrows-A)i'  i'  )zSupplemental Arrows-B)i )  i)  )z Miscellaneous Symbols and Arrows)i +  i+  ))zMathematical Operators)i "  i"  )z#Supplemental Mathematical Operators)i *  i*  )z$Miscellaneous Mathematical Symbols-A)i'  i'  )z$Miscellaneous Mathematical Symbols-B)i)  i)  ))zMiscellaneous Technical)i #  i#  ))zControl Pictures)i $  i?$  ))zOptical Character Recognition)i@$  i_$  ))zEnclosed Alphanumerics)i`$  i$  ))zBox Drawing)i %  i%  ))zBlock Elements)i%  i%  ))zGeometric Shapes)i%  i%  ))zMiscellaneous Symbols)i &  i&  ))ZDingbats)i '  i'  ))zCJK Symbols And Punctuation)i 0  i?0  ))Hiragana)i@0  i0  ))Katakana)i0  i0  )zKatakana Phonetic Extensions)i1  i1  ))ZBopomofo)i 1  i/1  )zBopomofo Extended)i1  i1  ))zHangul Compatibility Jamo)i01  i1  ))zPhags-pa)i@  i  ))zEnclosed CJK Letters And Months)i 2  i2  ))zCJK Compatibility)i 3  i3  ))zHangul Syllables)i   i  ))zNon-Plane 0 *)i   i  ))Z
Phoenician)i 	 i	 ))zCJK Unified Ideographs)i N  i  )zCJK Radicals Supplement)i.  i.  )zKangxi Radicals)i /  i/  )z"Ideographic Description Characters)i/  i/  )z"CJK Unified Ideographs Extension A)i 4  iM  )z"CJK Unified Ideographs Extension B)i   iߦ )ZKanbun)i1  i1  ))zPrivate Use Area (plane 0))i   i  ))zCJK Strokes)i1  i1  )zCJK Compatibility Ideographs)i   i  )z'CJK Compatibility Ideographs Supplement)i  i ))zAlphabetic Presentation Forms)i   iO  ))zArabic Presentation Forms-A)iP  i  ))zCombining Half Marks)i   i/  ))zVertical Forms)i  i  )zCJK Compatibility Forms)i0  iO  ))zSmall Form Variants)iP  io  ))zArabic Presentation Forms-B)ip  i  ))zHalfwidth And Fullwidth Forms)i   i  ))ZSpecials)i  i  ))ZTibetan)i   i  ))ZSyriac)i   iO  ))ZThaana)i  i  ))ZSinhala)i  i  ))ZMyanmar)i   i  ))ZEthiopic)i   i  )zEthiopic Supplement)i  i  )zEthiopic Extended)i-  i-  ))ZCherokee)i  i  ))z%Unified Canadian Aboriginal Syllabics)i   i  ))ZOgham)i  i  ))ZRunic)i  i  ))ZKhmer)i  i  )zKhmer Symbols)i  i  ))Z	Mongolian)i   i  ))zBraille Patterns)i (  i(  ))zYi Syllables)i   i  )zYi Radicals)i  iϤ  ))ZTagalog)i   i  )ZHanunoo)i   i?  )ZBuhid)i@  i_  )ZTagbanwa)i`  i  ))z
Old Italic)i  i/ ))ZGothic)i0 iO ))ZDeseret)i  iO ))zByzantine Musical Symbols)i  i )zMusical Symbols)i  i )zAncient Greek Musical Notation)i  iO ))z!Mathematical Alphanumeric Symbols)i  i ))zPrivate Use (plane 15))i   i )zPrivate Use (plane 16))i   i ))zVariation Selectors)i   i  )zVariation Selectors Supplement)i  i ))ZTags)i   i  ))ZLimbu)i   iO  ))zTai Le)iP  i  ))zNew Tai Lue)i  i  ))ZBuginese)i   i  ))Z
Glagolitic)i ,  i_,  ))ZTifinagh)i0-  i-  ))zYijing Hexagram Symbols)iM  iM  ))zSyloti Nagri)i   i/  ))zLinear B Syllabary)i   i  )zLinear B Ideograms)i  i  )zAegean Numbers)i  i? ))zAncient Greek Numbers)i@ i ))ZUgaritic)i i ))zOld Persian)i i ))ZShavian)iP i ))ZOsmanya)i i ))zCypriot Syllabary)i  i? ))Z
Kharoshthi)i 
 i_
 ))zTai Xuan Jing Symbols)i  i_ ))Z	Cuneiform)i   i# )z!Cuneiform Numbers and Punctuation)i $ i$ ))zCounting Rod Numerals)i` i ))Z	Sundanese)i  i  ))ZLepcha)i   iO  ))zOl Chiki)iP  i  ))Z
Saurashtra)i  iߨ  ))zKayah Li)i   i/  ))ZRejang)i0  i_  ))ZCham)i   i_  ))zAncient Symbols)i i ))zPhaistos Disc)i i ))ZCarian)i i )ZLycian)i i )ZLydian)i 	 i?	 ))zDomino Tiles)i0 i )zMahjong Tiles)i  i/ c              C   sP   t sHdd ttD } x0t| D ]$\}\}}t | t||f q W t tfS )Nc             S   s.   g | ]&\}}|D ]\}\}}|||ffqqS r   r   )r|   rt   blocks_startstopr   r   r   r~     s    z%_getUnicodeRanges.<locals>.<listcomp>)_unicodeStarts	enumerateOS2_UNICODE_RANGESsortedappend_unicodeValues)ZunicodeRangesr   r   rt   r   r   r   _getUnicodeRanges  s    
r   Fc             C   s   t | } t \}}t  }x2| D ]*}|t|| \}}||kr|| qW tdd | D rh|d |rt ttt| S |S )a'   Intersect a sequence of (int) Unicode codepoints with the Unicode block
	ranges defined in the OpenType specification v1.7, and return the set of
	'ulUnicodeRanges' bits for which there is at least ONE intersection.
	If 'inverse' is True, return the the bits for which there is NO intersection.

	>>> intersectUnicodeRanges([0x0410]) == {9}
	True
	>>> intersectUnicodeRanges([0x0410, 0x1F000]) == {9, 57, 122}
	True
	>>> intersectUnicodeRanges([0x0410, 0x1F000], inverse=True) == (
	...     set(range(len(OS2_UNICODE_RANGES))) - {9, 57, 122})
	True
	c             s   s&   | ]}d |  kodk n  V  qdS )i   i   Nr   )r|   coder   r   r   	<genexpr>  s    z)intersectUnicodeRanges.<locals>.<genexpr>9   )rZ   r   bisectrj   anyri   r2   r   )rx   rv   ZunicodestartsZunicodevaluesrk   r   r   rt   r   r   r   rw     s    


rw   __main__)F)%ZfontTools.miscr   ZfontTools.misc.roundToolsr   ZfontTools.misc.textToolsr   r   r   ZfontTools.ttLib.tablesr   r   logging	getLoggerr   r3   r   objectr   r)   r+   r,   r-   Z	bigendianr@   rA   rE   r    r   r   r   r   rw   doctestsysexittestmodfailedr   r   r   r   <module>   s@   
. [ -

