
    h                     B   S SK Jr  S SKrS SK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JrJrJrJr  S SKJrJrJrJrJr  S SKJrJrJrJrJrJrJrJrJ r   S S	K!J"r"J#r#  S SK$r$\$RJ                  " S
5      r&Sr'  S SK(r)Sr' " S S\5      r+ " S S\5      r,Sr-\R\                  " \-5      r/Sr0Sr1\R\                  " \15      r2Sr3\R\                  " \35      r4Sr5Sr6\2\4-   S\6-  -   r7Sr8Sr9\R\                  " \95      r:Sr;Sr<S r= " S S\5      r> " S S \" S!5      5      r? " S" S#\" S$5      5      r@ " S% S&\" S'5      5      rA " S( S)\5      rBS* rCS+ rDS, rES- rFS. rGS3S/ jrHS0 rIS3S1 jrJ\KS2:X  a  \R                  " \J" 5       5        gg! \* a    S SK)r) GNf = f! \* a     GNf = f)4    )BytesION)OrderedDict)sstruct)calcIntBounds)Tagbytechrbyteord	bytesjoinpad)TTFont
TTLibErrorgetTableModulegetTableClassgetSearchRange)	
SFNTReader
SFNTWriterDirectoryEntryWOFFFlavorDatasfntDirectoryFormatsfntDirectorySizeSFNTDirectoryEntrysfntDirectoryEntrySizecalcChecksum)	ttProgram_g_l_y_fzfontTools.ttLib.woff2FTc                   J    \ rS rSrSrSS jrS rS rSS jrS r	S	 r
S
 rSrg)WOFF2Reader,   woff2c                    [         (       d   [        R                  S5        [        S5      eXl        [        U R                  R                  S5      5      nUS:w  a  [        S5      eU R                  R                  S5        [        U l
        U R                  R                  [        5      n[        U5      [        :w  a  [        S5      e[        R                  " [        XP5        [!        5       U l        Sn[%        U R&                  5       He  nU R                  5       nUR)                  U R                  5        [        UR*                  5      n	XR"                  U	'   Xhl        XhR.                  -  nMg     Un
U R                  R                  U R0                  5      n[2        R4                  " U5      n[        U5      U
:w  a  [        SU
[        U5      4-  5      e[7        U5      U l        U R                  R                  SS	5        U R.                  U R                  R;                  5       :w  a  [        S
5      e[=        U 5      U l        [A        SSS9U l!        g )NzfThe WOFF2 decoder requires the Brotli Python extension, available at: https://github.com/google/brotliNo module named brotli   s   wOF2z Not a WOFF2 font (bad signature)r   z"Not a WOFF2 font (not enough data)zAunexpected size for decompressed font data: expected %d, found %d   z4reported 'length' doesn't match the actual file sizeFrecalcBBoxesrecalcTimestamp)"
haveBrotlilogerrorImportErrorfiler   readr   seekWOFF2DirectoryEntryr   woff2DirectorySizelenr   unpackwoff2DirectoryFormatr   tablesrange	numTablesfromFiletagoffsetlengthtotalCompressedSizebrotli
decompressr   transformBuffertellWOFF2FlavorData
flavorDatar   ttFont)selfr+   checkChecksums
fontNumber	signaturedatar8   ientryr7   totalUncompressedSizecompressedDatadecompressedDatas                G/var/www/html/env/lib/python3.13/site-packages/fontTools/ttLib/woff2.py__init__WOFF2Reader.__init__/   s   zII3 677			q)*	?@@		q1yy~~01t9**ABB+T8!mt~~&A'')ENN499%eii.C$KK!Lll"F ' !'(@(@A!,,^< $99S(#.>*?@A   ''78		q!;;$))..**STT)$/ %G    c                    U R                   [        U5         n[        US5      (       dS  UR                  (       a"  U R	                  U5      Ul        UR
                  $ UR                  U R                  5      Ul        UR
                  $ )z9Fetch the raw table data. Reconstruct transformed tables.rF   )r3   r   hasattrtransformedreconstructTablerF   loadDatar=   )rB   r7   rH   s      rL   __getitem__WOFF2Reader.__getitem__a   sj    CH%uf%%  !2237
 zz #^^D,@,@A
zzrO   c                 V   U R                   [        U5         nUR                  U R                  5      nUS:X  a2  [	        U S5      (       a  U R
                  OSnU R                  X45      nU$ US:X  a  U R                  5       nU$ US:X  a  U R                  U5      nU$ [        SU-  5      e)z4Reconstruct table named 'tag' from transformed data.glyfpaddingNlocahmtxz#transform for table '%s' is unknown)
r3   r   rT   r=   rQ   rY   _reconstructGlyf_reconstructLoca_reconstructHmtxr   )rB   r7   rH   rawDatarY   rF   s         rL   rS   WOFF2Reader.reconstructTablek   s    CH%..!5!56&=&-dI&>&>dllDG((:D  F]((*D
 	 F]((1D  BSHIIrO   Nc                     [        5       U R                  S'   [        5       =o0R                  S'   UR                  XR                  5        U(       a  X#l        UR                  U R                  5      nU$ )zReturn recostructed glyf table data, and set the corresponding loca's
locations. Optionally pad glyph offsets to the specified number of bytes.
rZ   rX   )WOFF2LocaTablerA   WOFF2GlyfTablereconstructrY   compile)rB   rF   rY   	glyfTables       rL   r\   WOFF2Reader._reconstructGlyf{   s]     -.F*8*::	KK'dKK0 '  -rO   c                 l   SU R                   ;  a#  U R                  S5      U R                  S   l        U R                   S   nUR	                  U R                   5      n[        U5      U R                  S   R                  :w  a0  [        SU R                  S   R                  [        U5      4-  5      eU$ )z%Return reconstructed loca table data.rZ   rX   zMreconstructed 'loca' table doesn't match original size: expected %d, found %d)rA   rS   r3   rF   re   r0   
origLengthr   )rB   	locaTablerF   s      rL   r]   WOFF2Reader._reconstructLoca   s    $'+'<'<V'DDKK$KK'	  -t9F+666(+/;;v+>+I+I3t9*UV  rO   c                    SU R                   R                  ;   a  SnOSnU H  nU R                  U5        M     [        5       =o@R                  S'   UR                  XR                  5        UR                  U R                  5      nU$ )z%Return reconstructed hmtx table data.rX   )maxphhearX   )rm   headrn   rZ   rX   r[   )r@   transformedTables_decompileTableWOFF2HmtxTablerA   rd   re   )rB   rF   tableDependenciesr7   	hmtxTables        rL   r^   WOFF2Reader._reconstructHmtx   s|    
 T__666 8 !I$C  % %*8*::	KK'dKK0  -rO   c                     X   nU R                   R                  U5      (       a  U R                   U   $ [        U5      nU" U5      nX@R                   R                  U'   UR	                  X R                   5        g)z5Decompile table data and store it inside self.ttFont.N)rA   isLoadedr   r3   	decompilerB   r7   rF   
tableClasstables        rL   rq   WOFF2Reader._decompileTable   sb    y;;$$;;s##"3'
3"'3kk*rO   )r   r+   r@   r3   r=   rA   )r   N)__name__
__module____qualname____firstlineno__flavorrM   rU   rS   r\   r]   r^   rq   __static_attributes__ rO   rL   r   r   ,   s,    F0Hd 
$+rO   r   c                       \ rS rSrSr   SS jrS rS rSS j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g)WOFF2Writer   r   Nc                 x   [         (       d   [        R                  S5        [        S5      eXl        X l        [        U5      U l        [        US9U l	        [        U l        [        U l        [        U l        [        S5      U l        SU l        [%        5       U l        [)        5       U l        [-        SSS9U l        g )NzfThe WOFF2 encoder requires the Brotli Python extension, available at: https://github.com/google/brotlir!   )rF   wOF2r   Fr$   )r'   r(   r)   r*   r+   r5   r   sfntVersionr?   r@   r2   directoryFormatr/   directorySizer.   r   rE   nextTableOffsetr   r=   r   r3   r   rA   )rB   r+   r5   r   r   r@   s         rL   rM   WOFF2Writer.__init__   s     zII3 677	"{+)z:3/1V &y!m %GrO   c                    XR                   ;   a  [        SU-  5      eUS:X  a  U =R                  S-  sl        gU R                  5       n[	        U5      Ul        [        UR
                  5      Ul        X#l        X0R                   U'   g)z4Associate new entry named 'tag' with raw table data.zcannot rewrite '%s' tableDSIG   N)	r3   r   r5   r   r   r7   getKnownTagIndexflagsrF   )rB   r7   rF   rH   s       rL   __setitem__WOFF2Writer.__setitem__   sq    ++83>??&=NNaN##%H	&uyy1 
 CrO   c                    [        U R                  5      U R                  :w  a-  [        SU R                  [        U R                  5      4-  5      eU R                  S;   a  SnOU R                  S:X  a  SnO[        S5      eU(       a9  SU R
                  R                  ;   a  SU R                  ;   a  U R                  SS	9  U R                  5         [        [        U R                  R                  5       5      5      U l        U R                  5       U l        U R                  5       n[        R                   " U[        R"                  S
9n[        U5      U l        U R'                  5       U l        U R+                  5       u  U l        U l        SU l        U R3                  5       nU R4                  R7                  S5        U R4                  R9                  [;        XC-   SS95        U R=                  5         g)zJAll tags must have been specified. Now write the table data and directory.z-wrong number of tables; expected %d, found %d)   trueTOTTOFz1Not a TrueType or OpenType font (bad sfntVersion)rX   r"   )rY   moder   sizeN)r0   r3   r5   r   r   r@   rp   _normaliseGlyfAndLoca_setHeadTransformFlagr   sorteditems#_calcSFNTChecksumsLengthsAndOffsetstotalSfntSize_transformTablesr;   compress	MODE_FONTr:   _calcTotalSizer9   _getVersionmajorVersionminorVersionreserved_packTableDirectoryr+   r-   writer   _writeFlavorData)rB   
isTrueTypefontDatacompressedFont	directorys        rL   closeWOFF2Writer.close   s   t{{t~~-?>>3t{{#345 
 ;;J'JPQQ $//;;;$++%&&q&1""$ "&):):)<"=>!EEG((*8H8HI#&~#6 ))+/3/?/?/A,4,,,.			q		I6Q?@rO   c                     U R                   S:X  a  gS H%  nX R                  ;   d  M  U R                  U5        M'     XR                  S   l        S H  nU R                  U5        M     g)zRecompile glyf and loca tables, aligning glyph offsets to multiples of
'padding' size. Update the head table's 'indexToLocFormat' accordingly while
compiling loca.
r   N)rm   ro   rZ   rX   fvarrX   rX   rZ   )r   r3   rq   rA   rY   _compileTable)rB   rY   r7   s      rL   r   !WOFF2Writer._normaliseGlyfAndLoca  s`    
 v%;Ckk!$$S) < '.F##Cs# $rO   c                     U R                  S5        U R                  S   =R                  S-  sl        U R                  S5        g)zSet bit 11 of 'head' table flags to indicate that the font has undergone
a lossless modifying transform. Re-compile head table data.ro   i   N)rq   rA   r   r   rB   s    rL   r   !WOFF2Writer._setHeadTransformFlag.  s:     	V$F!!W,!6"rO   c                    [        U5      nXR                  ;  a  [        SU-  5      eU R                  R	                  U5      (       a  gU R                  U   R
                  nUS:X  a  [        nO%US:X  a  [        nOUS:X  a  [        nO[        U5      nU" U5      nX@R                  R                  U'   UR                  X R                  5        g)z@Fetch table data, decompile it, and store it inside self.ttFont.zmissing required table: %sNrZ   rX   r[   )r   r3   r   rA   rw   rF   rb   rc   rr   r   rx   ry   s        rL   rq   WOFF2Writer._decompileTable5  s    #hkk!9C?@@;;$${{3$$&='JF]'JF]'J&s+J3"'3kk*rO   c                 x    U R                   U   R                  U R                   5      U R                  U   l        g)z3Compile table and store it in its 'data' attribute.N)rA   re   r3   rF   rB   r7   s     rL   r   WOFF2Writer._compileTableI  s+     $C 0 8 8 ECrO   c                 d   [         [        [        U R                  5      -  -   nU R                  R	                  5        Hn  u  p#UR
                  nXl        [        U5      Ul        US:X  a  [        USS S-   USS -   5      Ul	        O[        U5      Ul	        XR                  S-   S-  -  nMp     U$ )zCompute the 'original' SFNT checksums, lengths and offsets for checksum
adjustment calculation. Return the total size of the uncompressed font.
ro   N   s             )
r   r   r0   r3   r   rF   
origOffsetri   r   checkSum)rB   r8   r7   rH   rF   s        rL   r   /WOFF2Writer._calcSFNTChecksumsLengthsAndOffsetsM  s     #%;c$++>N%NN++++-JC::D%"4yEf}!-d2Ah.DtBCy.P!Q!-d!3''!+r11F . rO   c                    U R                   R                  nU R                  R                  5        H  u  p#SnX!;   a  U R	                  U5      nUb  SUl        Uc*  US:X  a  UR                  S5        UR                  nSUl        U R                  Ul	        UR                  U R                  U5        U =R                  UR                  -  sl        M     U R                  5         U R                  R                  5       nU$ )zReturn transformed font data.NTrX   rZ   F)r@   rp   r3   r   transformTablerR   discardrF   r   r8   saveDatar=   r9   writeMasterChecksumgetvalue)rB   rp   r7   rH   rF   r   s         rL   r   WOFF2Writer._transformTables]  s     OO==++++-JCD'**3/#(,E%|&= &--f5zz$)!//ELNN4//6  ELL0 ! ." 	  "''002rO   c                    US:X  a  SnU$ US:X  aF  S H  nU R                  U5        M     U R                  S   nUR                  U R                  5      nU$ US:X  aW  SU R                  ;  a  gS H  nU R                  U5        M     U R                  S   nUR                  U R                  5      nU$ [	        SU-  5      e)	zReturn transformed table data, or None if some pre-conditions aren't
met -- in which case, the non-transformed table data will be used.
rZ   rO   rX   )rm   ro   rZ   rX   r[   N)rm   ro   rn   rZ   rX   r[   z#Transform for table '%s' is unknown)rq   rA   	transformr3   r   )rB   r7   rF   rf   rt   s        rL   r   WOFF2Writer.transformTableu  s     &=D  F]7$$S) 8F+I&&t{{3D  F]T[[(G$$S) HF+I&&t{{3D  BSHIIrO   c                 F   [        U R                  R                  5       5      n/ n[        [	        U5      5       H-  nUR                  U R                  X      R                  5        M/     [        U R                  S5      u  U l	        U l
        U l        [        R                  " [        U 5      n[        U R                  R!                  5       5      nU He  u  pg[#        5       nUR$                  Ul        UR                  Ul        UR&                  Ul        UR*                  Ul        XHR/                  5       -   nMg     [0        [	        U R                  5      [2        -  -   n	U	[	        U5      :X  d   eUR                  [5        U5      5        [7        U5      S-  n
SU
-
  S-  nU$ )zCalculate checkSumAdjustment.   l    l   /ac )listr3   keysr4   r0   appendr   r   r5   searchRangeentrySelector
rangeShiftr   packr   r   r   r   r7   r   r8   ri   r9   toStringr   r   r   sum)rB   tags	checksumsrG   r   r3   r7   rH   	sfntEntrydirectory_endchecksumchecksumadjustments               rL   _calcMasterChecksumWOFF2Writer._calcMasterChecksum  s]   DKK$$&'	s4y!AT[[1::; " AONNBA
=$,do LL!4d;	))+, JC*,I!IIIM!&I$//I$//I!$6$6$88I ! *C,<?U,UUI...i01y>J.(83zA!!rO   c                     U R                  5       nU R                  R                  U R                  S   R                  S-   5        U R                  R                  [        R                  " SU5      5        g)z0Write checkSumAdjustment to the transformBuffer.ro   r   z>LN)r   r=   r-   r3   r8   r   structr   )rB   r   s     rL   r   WOFF2Writer.writeMasterChecksum  sY    !557!!$++f"5"<"<q"@A""6;;t5G#HIrO   c                     U R                   nU R                  R                  5        H  nU[        UR	                  5       5      -  nM!     XR
                  -  nUS-   S-  nU R                  U5      nU$ )zLCalculate total size of WOFF2 font, including any meta- and/or private data.r   r   )r   r3   valuesr0   r   r:   _calcFlavorDataOffsetsAndSize)rB   r8   rH   s      rL   r   WOFF2Writer._calcTotalSize  sk    ##[['')Ec%..*++F ****1*"33F;rO   c                     UnU R                   nUR                  (       a{  [        UR                  5      U l        X l        [
        R                  " UR                  [
        R                  S9U l        [        U R                  5      U l	        X R                  -  nOS=U l        =U l	        U l        SU l        UR                  (       a8  US-   S-  nX l        [        UR                  5      U l        X R                  -  nU$ S=U l        U l        U$ )z@Calculate offsets and lengths for any meta- and/or private data.r   r   rO   r   r   )r@   metaDatar0   metaOrigLength
metaOffsetr;   r   	MODE_TEXTcompressedMetaData
metaLengthprivData
privOffset
privLength)rB   startr8   rF   s       rL   r   )WOFF2Writer._calcFlavorDataOffsetsAndSize  s    =="%dmm"4D$O&,ooF$4$4'D# "$"9"9:DOoo%FFGGDOGdo0C&)D#==qjB&F$O!$--0DOoo%F  121DOdorO   c                    U R                   nUR                  b%  UR                  b  UR                  UR                  4$ SU R                  ;   a1  [        R
                  " SU R                  S   R                  SS 5      $ g)z;Return the WOFF2 font's (majorVersion, minorVersion) tuple.ro   z>HHr"   r   )r   r   )r@   r   r   r3   r   r1   rF   rB   rF   s     rL   r   WOFF2Writer._getVersion  sq    (T->->-J$$d&7&777 $}}UDKK,?,D,DQq,IJJrO   c                     [         R                  " U R                  U 5      nU R                  R	                  5        H  nXR                  5       -   nM     U$ )z"Return WOFF2 table directory data.)r   r   r   r3   r   r   )rB   r   rH   s      rL   r   WOFF2Writer._packTableDirectory  sD    LL!5!5t<	[['')E!NN$44I *rO   c                 >   U R                   nU R                  R                  nU(       a  U(       a
  [        USS9nU(       aj  U R                  R                  U R                  5        U R                  R                  5       U R                  :X  d   eU R                  R                  U5        U(       ak  U R                  R                  U R                  5        U R                  R                  5       U R                  :X  d   eU R                  R                  U5        gg)z<Write metadata and/or private data using appropiate padding.r"   r   N)
r   r@   r   r   r+   r-   r   r>   r   r   )rB   r   r   s      rL   r   WOFF2Writer._writeFlavorData  s    !44??++(!$%7a!@IINN4??+99>>#t666IIOO./IINN4??+99>>#t666IIOOH% rO   c                     g)NTr   r   s    rL   reordersTablesWOFF2Writer.reordersTables  s    rO   )r   r   r   r   r   r+   r@   r9   r   r   r   r   r   r   r5   r   r   r   r   r   r   rE   r3   r:   r   r=   rA   )r   NN)r"   )r   r   r   r   r   rM   r   r   r   r   rq   r   r   r   r   r   r   r   r   r   r   r   r  r   r   rO   rL   r   r      sq    F ' HD!$4 l$#+(F 0,"<J2
&rO   r   a  
		> # big endian
		signature:           4s   # "wOF2"
		sfntVersion:         4s
		length:              L    # total woff2 file size
		numTables:           H    # number of tables
		reserved:            H    # set to 0
		totalSfntSize:       L    # uncompressed size
		totalCompressedSize: L    # compressed size
		majorVersion:        H    # major version of WOFF file
		minorVersion:        H    # minor version of WOFF file
		metaOffset:          L    # offset to metadata block
		metaLength:          L    # length of compressed metadata
		metaOrigLength:      L    # length of uncompressed metadata
		privOffset:          L    # offset to private data block
		privLength:          L    # length of private data block
)?cmapro   rn   r[   rm   namezOS/2postzcvt fpgmrX   rZ   prepzCFF VORGEBDTEBLCgasphdmxkernLTSHPCLTVDMXvheavmtxBASEGDEFGPOSGSUBEBSCJSTFMATHCBDTCBLCCOLRCPALzSVG sbixacntavarbdatblocbslncvarfdscfeatfmtxr   gvarhstyjustlcarmortmorxopbdproptrakZapfSilfGlatGlocFeatSillz5
		> # big endian
		flags: B  # table type and flags
z5
		> # big endian
		tag: 4s  # 4-byte tag (optional)
?      r#   r   a  
		> # big endian
		version:                  H  # = 0x0000
		optionFlags:              H  # Bit 0: we have overlapSimpleBitmap[], Bits 1-15: reserved
		numGlyphs:                H  # Number of glyphs
		indexFormat:              H  # Offset format for loca table
		nContourStreamSize:       L  # Size of nContour stream
		nPointsStreamSize:        L  # Size of nPoints stream
		flagStreamSize:           L  # Size of flag stream
		glyphStreamSize:          L  # Size of glyph stream
		compositeStreamSize:      L  # Size of composite stream
		bboxStreamSize:           L  # Comnined size of bboxBitmap and bboxStream
		instructionStreamSize:    L  # Size of instruction stream
zF
		>	# big endian
		xMin:				h
		yMin:				h
		xMax:				h
		yMax:				h
r   c                 n    [        [        [        5      5       H  nU [        U   :X  d  M  Us  $    [        $ )zEReturn index of 'tag' in woff2KnownTags list. Return 63 if not found.)r4   r0   woff2KnownTagswoff2UnknownTagIndex)r7   rG   s     rL   r   r     s0    3~&'.##H (  rO   c                       \ rS rSrS rS rS r\S 5       r\R                  S 5       r\S 5       r
\
R                  S 5       r
S	rg
)r.   i  c                     UR                  5       nUR                  [        5      nU R                  U5      n[	        U5      [	        U5      -
  nUR                  X%-   5        g r~   )r>   r,   woff2DirectoryEntryMaxSize
fromStringr0   r-   )rB   r+   posrF   leftconsumeds         rL   r6   WOFF2DirectoryEntry.fromFile  sJ    iikyy34t$t9s4y(		#.!rO   c                 b   [        U5      S:  a  [        S5      e[        R                  " [        X5      u  p!U R
                  S-  S:X  a<  [        U5      [        :  a  [        S5      e[        R                  " [        X5      u  p!O[        U R
                  S-     U l	        [        U R                  5      U l	        [        U5      u  U l        nU R                  U l        U R                  (       a>  [        U5      u  U l        nU R                  S:X  a  U R                  S:w  a  [        S5      eU$ )Nr   z)can't read table 'flags': not enough datar9  z'can't read table 'tag': not enough datarZ   r   z1the transformLength of the 'loca' table must be 0)r0   r   r   unpack2woff2FlagsFormatr   woff2UnknownTagSizewoff2UnknownTagFormatr<  r7   r   unpackBase128ri   r9   rR   )rB   rF   dummys      rL   rA  WOFF2DirectoryEntry.fromString  s    t9q=HIIoo&6C::$4y.. !JKK!//*?LKE4 &djj4&78DHtxx= -d 3oo -d 3DKxx6!dkkQ&6 !TUUrO   c                 <   [        U R                  5      nU R                  S-  S:X  a2  U[        R                  " SU R                  R                  5       5      -  nU[        U R                  5      -  nU R                  (       a  U[        U R                  5      -  nU$ )Nr9  z>4s)
r   r   r   r   r7   tobytespackBase128ri   rR   r9   r   s     rL   r   WOFF2DirectoryEntry.toString  sw    tzz"JJ$&FKKtxx'7'7'9::DDOO,,K,,DrO   c                      U R                   S-	  $ )zzReturn bits 6-7 of table entry's flags, which indicate the preprocessing
transformation version number (between 0 and 3).
   r   r   s    rL   transformVersion$WOFF2DirectoryEntry.transformVersion  s    
 zzQrO   c                 X    SUs=::  a  S::  d   e   eU =R                   US-  -  sl         g )Nr   r   rS  rT  )rB   values     rL   rU  rV    s)    EQ

eqj 
rO   c                 ^    U R                   S;   a  U R                  S:g  $ U R                  S:g  $ )zCReturn True if the table has any transformation, else return False.>   rX   rZ   r   r   )r7   rU  r   s    rL   rR   WOFF2DirectoryEntry.transformed  s3     88''((A--((A--rO   c                 f    U R                   S;   a  U(       d  SOSU l        g [        U5      U l        g )N>   rX   rZ   r   r   )r7   rU  int)rB   booleanValues     rL   rR   rZ    s*    
 88''-9AqD!$'$5D!rO   )r9   ri   r7   rU  N)r   r   r   r   r6   rA  r   propertyrU  setterrR   r   r   rO   rL   r.   r.     sm    ",   ! ! 	. 	. 6 6rO   r.   c                   6   ^  \ rS rSrSrSS jrU 4S jrSrU =r$ )rb   i  zSame as parent class. The only difference is that it attempts to preserve
the 'indexFormat' as encoded in the WOFF2 glyf table.
c                 6    [        U=(       d    S5      U l        g )NrZ   r   tableTagr   s     rL   rM   WOFF2LocaTable.__init__      CM6*rO   c                   >  [        U R                  5      nSU;   Ga  [	        US   S5      (       Ga  US   R
                  nUS:X  a  US:  a  [        S5      e[        S U R                   5       5      (       d  [        S5      e[        R                  " S5      n[        [        U R                  5      5       H$  nUR                  U R                  U   S	-  5        M&     O![        R                  " S
U R                  5      n[        R                  S:w  a  UR                  5         UR                  5       nU$ [         ["        U ]K  U5      nU$ ! [         a    U R                  / 5        Sn GNWf = f)Nr   rX   indexFormati   z,indexFormat is 0 but local offsets > 0x20000c              3   0   #    U  H  oS -  S:H  v   M     g7f)r#   r   Nr   ).0ls     rL   	<genexpr>)WOFF2LocaTable.compile.<locals>.<genexpr>  s     >~!q5A:~s   z5indexFormat is 0 but local offsets not multiples of 2Hr#   Ibig)max	locationsAttributeErrorsetrQ   rg  r   allarrayr4   r0   r   sys	byteorderbyteswaprO  superrb   re   )rB   rA   max_locationrg  rq  rG   rF   	__class__s          rL   re   WOFF2LocaTable.compile  s@   	t~~.L Vv F F .44Ka7*$%STT>t~~>>>$O  "KK,	s4>>23A$$T^^A%6!%;< 4 "KKT^^<	}}%""$$$&D  6v>D1  	HHRLL	s   E E0/E0)rc  r~   )	r   r   r   r   __doc__rM   re   r   __classcell__r{  s   @rL   rb   rb     s    + rO   rb   rZ   c                       \ rS rSrSrSrSS j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g)rc   i  z1Decoder/Encoder for WOFF2 'glyf' table transform.)nContourStreamnPointsStream
flagStreamglyphStreamcompositeStream
bboxStreaminstructionStreamNc                 6    [        U=(       d    S5      U l        g )NrX   rb  r   s     rL   rM   WOFF2GlyfTable.__init__  re  rO   c                    [        U5      nU[        :  a  [        S5      e[        R                  " [
        X5      u  pA[        nU R                   H(  n[        XS-   5      n[        XUSU 5        XS nXW-  nM*     U R                  [        -  nSU l        U(       a5  U R                  S-   S-	  n	[        R                  " SUSU	 5      U l        XY-  nXS:w  a  [        SXS4-  5      eU R                  S-   S	-	  S
-  n
U R                  SU
 n[        R                  " SU5      U l        U R                  U
S U l        [        R                  " SU R                   5      U l        ["        R$                  S:w  a  U R                   R'                  5         [        U R                   5      U R                  :X  d   eSU;   a  U R(                  US   l         UR-                  5       U l        U R.                  cL  S/U l        U R.                  R1                  [3        SU R                  5       Vs/ s H  nSU-  PM
     sn5        OP[        U R.                  5      U R                  :w  a-  [        S[        U R.                  5      U R                  4-  5      e0 =ol        [7        U R.                  5       H  u  pU R9                  U5      nUX'   M     g!   SU l         N= fs  snf )z"Decompile transformed 'glyf' data.znot enough 'glyf' dataSizeN   r   BzJincorrect size of transformed 'glyf' table: expected %d, received %d bytes   r:  r#   hro  ro   z.notdefr   z	glyph%.5dz2incorrect glyphOrder: expected %d glyphs, found %d)r0   woff2GlyfTableFormatSizer   r   rG  woff2GlyfTableFormat
subStreamsgetattrsetattroptionFlagswoff2OverlapSimpleBitmapFlagoverlapSimpleBitmap	numGlyphsru  r  
bboxBitmapr  rv  rw  rx  rg  indexToLocFormatgetGlyphOrder
glyphOrderextendr4   glyphs	enumerate_decodeGlyph)rB   rF   rA   inputDataSizerL  r8   streamr   hasOverlapSimpleBitmapoverlapSimpleBitmapSizebboxBitmapSizer  rG   r  glyphID	glyphNameglyphs                    rL   rd   WOFF2GlyfTable.reconstruct  s   D	33566oo&:DG)ooF4&1DD$u+.;DNF	 & "&!1!14P!P#' !'+~~'9a&?#',{{3=U>U8V'WD$-F"\)* 
  >>B.14:___n5
++c:6//./:#kk#t/B/BC==E!((*4&&'4>>999V.2.>.>F6N+	#$224DO ??"(kDOOO""U1dnn=U#V=UK!O=U#VW4??#t~~5 H4??+T^^<= 
  "!"+DOO"<G%%g.E %F #=	#"DO $Ws   K %K	Kc                    [        U R                  5      U l        [        U R                  5      U R                  :X  d   eSU;   a  U R                  US   l        US   R                  U l        U R                   H  n[        XS5        M     U R                  S-   S-	  S-  n[        R                  " SS/U-  5      U l	        [        R                  " SS/U R                  S	-   S
-	  -  5      U l
        [        U R                  5       H  n U R                  U5        M     [        U R                  5      nU R                  R                  5       U R                   -   U l        U R                   H$  n[        XS-   [        [#        X5      5      5        M&     SU l        SU l        U(       a  U =R&                  [(        -  sl        [*        R,                  " [.        U 5      nU[1        U R                   Vs/ s H  n[#        X5      PM     sn5      -  nU(       a  X`R                  R                  5       -  nU$ ! [         a       gf = fs  snf )zReturn transformed 'glyf' datarm   ro   rO   r  r:  r#   r  r   r  r   Nr  )r0   r  r  r  r  rg  r  r  ru  r  r  r4   _encodeGlyphNotImplementedErroranyrO  r  r  versionr  r  r   r   r  r
   )rB   rA   r  r  r  r  rF   ss           rL   r   WOFF2GlyfTable.transformF  s   T[[)4??#t~~555V'+~~F6N$!&>::ooFD#& &>>B.14:++cA3+?@#(;;sQCDNNQ<NST;T4U#V T^^,G!!'* -
 "%T%=%=!>//113dooEooFD6/3wt/D+EF &! <<||0$7	T__E_74+_EFF!,,4466D '  Fs   H52I
5
IIc                 8   [        S5      R                  5       nU R                  U   Ul        UR                  S:X  a  U$ UR	                  5       (       a  U R                  U5        O"U R                  U5        U R                  X!5        U R                  X5        U$ )NrX   r   )	r   Glyphr  numberOfContoursisComposite_decodeComponents_decodeCoordinates_decodeOverlapSimpleFlag_decodeBBox)rB   r  r  s      rL   r  WOFF2GlyfTable._decodeGlyphh  s    v&,,.!%!4!4W!=!!Q&L  ""5)##E*))%9(rO   c                 (   U R                   n/ Ul        SnSnU(       aU  [        S5      R                  5       nUR	                  X 5      u  p6nXF-  nUR                  R                  U5        U(       a  MU  X l         U(       a  U R                  U5        g g )Nr   r   rX   )r  
componentsr   GlyphComponentrx   r   _decodeInstructions)rB   r  rF   morehaveInstructions	component	haveInstrs          rL   r   WOFF2GlyfTable._decodeComponentsu  s    ##&v.==?I$-$7$7$C!DT/;##I.	 d
  $$$U+ rO   c                     U R                   n/ nSn[        UR                  5       H%  n[        U5      u  pbXF-  nUR	                  U5        M'     X1l        X l         U R                  U5        U R                  U5        g Nr}   )r  r4   r  unpack255UShortr   endPtsOfContours_decodeTripletsr  )rB   r  rF   r  endPointrG   ptsOfContours          rL   r  !WOFF2GlyfTable._decodeCoordinates  sz    !!u--.A!0!6L$H##H- / "2!U#  'rO   c                     U R                   b  UR                  S::  a  g US-	  nUS-  nU R                   U   SU-	  -  (       a&  UR                  S==   [        R                  -  ss'   g g Nr   r   r     )r  r  r   r   flagOverlapSimplerB   r  r  bytebits        rL   r  'WOFF2GlyfTable._decodeOverlapSimpleFlag  sd    ##+u/E/E/J!|k##D)TS[9KKNh888N :rO   c                     U R                   nU R                  n[        U5      u  pB[        R                  " 5       Ul        UR
                  R                  US U 5        X l         X4S  U l        g r~   )r  r  r  r   ProgramprogramfromBytecode)rB   r  r  r  instructionLengths        rL   r  "WOFF2GlyfTable._decodeInstructions  sg    && 22)8)E&!))+""#45G6G#HI&!23E!FrO   c                 ,   [        U R                  US-	     SUS-  -	  -  5      nUR                  5       (       a  U(       d  [        SU-  5      eU(       a.  [        R
                  " [        U R                  U5      u  o@l        g UR                  U 5        g )Nr   r  r  z%no bbox values for composite glyph %d)	boolr  r  r   r   rG  
bboxFormatr  recalcBounds)rB   r  r  haveBBoxrL  s        rL   r  WOFF2GlyfTable._decodeBBox  sv    15'A+9NOPxDwNOO%,__ZRW%X"E?t$rO   c                    S nUR                   S   S-   nUnU[        U R                  5      :  a  [        S5      eU R                  S U nU R                  US  U l        [        R                  " SU5      n[        R                  " SU R
                  5      n[        U5      nX8::  d   eSn	Sn
[        S5      R                  R                  U5      Ul	        [        R                  " S5      Ul
        Sn[        U5       GH  nXl   n[        US-	  5      (       + nUS	-  nUS
:  a  SnOUS:  a  SnOUS:  a  SnOSnX-   U::  d   eUS:  a  SnU" XS-  S-  X{   -   5      nGOUS:  a  U" XS-
  S-  S-  X{   -   5      nSnOUS
:  a:  US-
  nX{   nU" USUS-  -   US-	  -   5      nU" US-	  SUS-  S-  -   US-  -   5      nOUS:  a=  US
-
  nU" USUS-  S-  -   X{   -   5      nU" US-	  SUS-  S-	  S-  -   X{S-      -   5      nOnUS:  a6  X{S-      nU" XU   S-  US-	  -   5      nU" US-	  US-  S-  X{S-      -   5      nO2U" XU   S-  X{S-      -   5      nU" US-	  X{S-      S-  X{S-      -   5      nX-  nU	U-  n	U
U-  n
X4UR                  U'   UR                  R                  [        U5      5        GM     UnU R
                  US  U l        g )Nc                 F    SU::  a  US:  d   S5       eU S-  (       a  U$ U* $ )Nr   i   zinteger overflowr   r   )flagbasevals     rL   withSign0WOFF2GlyfTable._decodeTriplets.<locals>.withSign  s.    <GeOG5GG3"Qh74WH4rO   r}   r   znot enough 'flagStream' datar  r   rX   r     T   x   r#   |   r   r"   
         0   r      r   )r  r0   r  r   ru  r  r   GlyphCoordinateszeroscoordinatesr   r4   r  r   r\  )rB   r  r  nPointsflagSize	flagsDatar   triplets	nTripletsxytripletIndexrG   r  onCurvenBytesdxdyb0b1b2bytesConsumeds                         rL   r  WOFF2GlyfTable._decodeTriplets  sk   	5 ((,q0c$//**;<<OOIX.	//()4C+;;sD$4$45M	###*62CCII'Rkk#&wA8Dtqy/)GDLDby )i777bydRiA%59O$OPdbyB&61%<@V$VWBY+dAdOrQw$?@dairDyQ.>)?29)MNBYdA"(q$9H<R$RSAIqb2g!^$9:XUVFV=WW Q./dl%;q%@R1W$MNAIdq 0HA=M4NN L1Q6(RSCS:TT AIQ./14PQAQ8RR "LGAGA$%6Ea KKs7|,a  b %++MN;rO   c                 l   U R                  U5      nX   nU =R                  [        R                  " SUR                  5      -  sl        UR                  S:X  a  g UR                  5       (       a  U R                  U5        O"U R                  U5        U R                  X15        U R                  X5        g )Nz>hr   )
getGlyphNamer  r   r   r  r  _encodeComponents_encodeCoordinates_encodeOverlapSimpleFlag_encodeBBox)rB   r  r  r  s       rL   r  WOFF2GlyfTable._encodeGlyph  s    %%g.	v{{41G1GHH!!Q&  ""5)##E*))%9(rO   c                 F   [        UR                  5      S-
  nSnSn[        [        UR                  5      5       HJ  nXR:X  a  [        US5      nSnUR                  U   nU =R                  UR                  X4U 5      -  sl        ML     U(       a  U R                  U5        g g )Nr   r   r  )r0   r  r4   rQ   r  re   _encodeInstructions)rB   r  lastcomponentr  r  rG   r  s          rL   r   WOFF2GlyfTable._encodeComponents  s    E,,-1s5++,-A!#*5)#< ((+I  I$5$5dd$SS  . $$U+ rO   c                    Sn[         R                  UR                  ;   a  [        eUR                   H'  nX2-
  nU =R
                  [        U5      -  sl        UnM)     U R                  U5        U R                  U5        g r  )	r   	flagCubicr   r  r  r  pack255UShort_encodeTripletsr
  )rB   r  lastEndPointr  r  s        rL   r  !WOFF2GlyfTable._encodeCoordinates  sp    ,%%..H#2L-"==#L / 	U#  'rO   c                     UR                   S::  a  g UR                  S   [        R                  -  (       a%  US-	  nUS-  nU R                  U==   SU-	  -  ss'   g g r  )r  r   r   r  r  r  s        rL   r  'WOFF2GlyfTable._encodeOverlapSimpleFlag  sZ    !!Q&;;q>H666a<DA+C$$T*dck9* 7rO   c                     UR                   R                  5       nU =R                  [        [	        U5      5      -  sl        U =R
                  U-  sl        g r~   )r  getBytecoder  r  r0   r  )rB   r  instructionss      rL   r
  "WOFF2GlyfTable._encodeInstructions!  s@    }}002M#l*;<<,.rO   c                    UR                   S:w  d   S5       eUR                  5       (       dI  UR                  UR                  UR                  UR
                  4n[        UR                  5      nX4:X  a  g U R                  US-	  ==   SUS-  -	  -  ss'   U =R                  [        R                  " [        U5      -  sl	        g )Nr   zempty glyph has no bboxr   r  r  )r  r  xMinyMinxMaxyMaxr   r  r  r  r   r   r  )rB   r  r  currentBBoxcalculatedBBoxs        rL   r  WOFF2GlyfTable._encodeBBox&  s    %%*E,EE*  ""  **ejj%**ejjHK*5+<+<=N,1%'A+)>>%7<<
E::rO   c                    [        UR                  5      [        UR                  5      :X  d   eUR                  R                  5       nUR	                  5         [
        R
                  " S5      n[
        R
                  " S5      n[        [        U5      5       GH  nUR                  U   [        R                  -  nX%   u  px[        U5      n	[        U5      n
U(       a  SOSnUS:  a  SOSnUS:  a  SOSnUSU-  -   nUS:X  a8  U
S:  a2  UR                  XS-  S-	  -   U-   5        UR                  U
S	-  5        M  US:X  a<  U	S:  a6  UR                  US
-   U	S-  S-	  -   U-   5        UR                  U	S	-  5        M  U	S:  aX  U
S:  aR  UR                  US-   U	S-
  S-  -   U
S-
  S-  S-	  -   U-   5        UR                  U	S-
  S-  S-  U
S-
  S-  -  5        GME  U	S:  ai  U
S:  ac  UR                  US-   SU	S-
  S-  S-	  -  -   U
S-
  S-  S-	  -   U-   5        UR                  U	S-
  S	-  5        UR                  U
S-
  S	-  5        GM  U	S:  ae  U
S:  a_  UR                  US-   U-   5        UR                  U	S-	  5        UR                  U	S-  S-  U
S-	  -  5        UR                  U
S	-  5        GM  UR                  US-   U-   5        UR                  U	S-	  5        UR                  U	S	-  5        UR                  U
S-	  5        UR                  U
S	-  5        GM     U =R                  UR                  5       -  sl        U =R                  UR                  5       -  sl        g )Nr  r   r  r   r#   i   i   r     r  A   r  r  r  r"   i  r  r   i   r   rS  i   r  r  )r0   r  r   copyabsoluteToRelativeru  r4   r   flagOnCurveabsr   r  rO  r  )rB   r  r  r   r  rG   r  r  r  absXabsY
onCurveBitxSignBitySignBit
xySignBitss                  rL   r  WOFF2GlyfTable._encodeTriplets2  sI   5$$%U[[)9999'',,.&&(C ;;s#s;'(Akk!nx';';;G>DAq6Dq6D%3JUqHUqH!AL0JAv$+Z5LQ+>?(JKt,aD4KZ"_!0CDxOPt,tbyqD(* T)a/1 !	! 4!8s"2q!8dQh#=M NOs
dQh%/A567 U*q02 !	! T 12T 12Z#-
:;	*$*!2tqy ABt,Z#-
:;	*t,	*t,[ )^ 	5==?*H,,..rO   )r  r  r  r  r  r  r  rg  r  r  r  r  r  r  rc  r  r~   )r   r   r   r   r}  r  rM   rd   r   r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r   r   rO   rL   rc   rc     sf    ;J+9&v D,(9G%H<T),	(:/

;7/rO   rc   rX   c                   *    \ rS rSrSS jrS rS rSrg)rr   il  Nc                 6    [        U=(       d    S5      U l        g Nr[   rb  r   s     rL   rM   WOFF2HmtxTable.__init__m  re  rO   c                 $   [         R                  " SUS S 5      u  nUSS  nUS-  S:w  a  [        SU R                  -  5      eUS-  S:H  nUS-  S:H  nU(       a  U(       a  [        SU R                  -  5      eUS   nUS	   nUR                  n[        U5      n	[        [        UR                  5      U	5      n
[        U5      SU
-  :  d   e[        R                  " S
US SU
-   5      n[        R                  S:w  a  UR                  5         USU
-  S  nU(       a^  [        U5      SU
-  :  d   e[        R                  " SUS SU
-   5      n[        R                  S:w  a  UR                  5         USU
-  S  nOS[        R                  " S5      n[        U5       H.  u  pX:  a    O&Xn   n[        USS5      nUR                  U5        M0     X-
  nU(       a^  [        U5      SU-  :  d   e[        R                  " SUS SU-   5      n[        R                  S:w  a  UR                  5         USU-  S  nOS[        R                  " S5      n[        U5       H.  u  pX:  a  M  Xn   n[        USS5      nUR                  U5        M0     U(       a  [        SU R                  -  5      e0 U l        [#        U
5       H   nX   nX   X   nnUU4U R                   U'   M"     US   n[#        U5       H  nXU
-      nUUU   4U R                   U'   M      g )N>Br      r   z#Bits 2-7 of '%s' flags are reservedr#   z?either bits 0 or 1 (or both) must set in transformed '%s' flagsrX   rn   rm  ro  r  r  ztoo much '%s' table datar}   )r   r1   r   rc  r  r0   minr\  numberOfHMetricsru  rv  rw  rx  r  r  r   metricsr4   )rB   rF   rA   r   hasLsbArrayhasLeftSideBearingArrayrf   headerTabler  r  r7  advanceWidthArraylsbArrayrG   r  r  r  numberOfSideBearingsleftSideBearingArrayadvanceWidthlsblastAdvances                         rL   rd   WOFF2HmtxTable.reconstructp  s3   ==tBQx0ABx:"BT]]RSS ai1n"'!)q.2Q--  
 6N	Vn))

O	s;#?#?@)L4yA 00000!KKT2HA8H4H-IJ==E!&&(A((*+t9$4 4444{{3-Cq3C/C(DEH}}%!!#,,./D {{3'H )* 5(!,ufa0% !6  );"t9$8 8888#(;;sD9S1?S;S4T#U }}%$--/0023D $);;s#3  )* 5'!,ufa0$++D1 !6 7$--GHH'(A"I 1 4hk#L'3S&9DLL# ) (++,A"'7#78I'24H4K&LDLL# -rO   c           	      6   UR                  5       nUS   nUS   nUR                  nSn[        U5       H0  nX'   nU R                  U   S   n	U	[	        X8   SS5      :w  d  M.  Sn  O   Sn
[        U[        U5      5       H0  nX'   nU R                  U   S   n	U	[	        X8   SS5      :w  d  M.  Sn
  O   U(       a  U
(       a  g SnU(       d  US-  nU
(       d  US-  n[        R                  " S	U5      n[        R                  " S
[        U5       VVs/ s H  u  pxXu:  d  M  U R                  U   S   PM      snn5      n[        R                  S:w  a  UR                  5         XR                  5       -  nU(       a  [        R                  " S[        U5       VVs/ s H  u  pxXu:  d  M  U R                  U   S   PM      snn5      n[        R                  S:w  a  UR                  5         XR                  5       -  nU
(       a  [        R                  " S[        U[        U5      5       Vs/ s H  nU R                  X'      S   PM     sn5      n[        R                  S:w  a  UR                  5         XR                  5       -  nU$ s  snnf s  snnf s  snf )NrX   rn   Fr   r  r   Tr#   r4  rm  ro  r  )r  r7  r4   r8  r  r0   r   r   ru  r  rv  rw  rx  rO  )rB   rA   r  rX   rn   r7  r9  rG   r  rA  r:  r   rF   r<  r=  r?  s                   rL   r   WOFF2HmtxTable.transform  s   ))+
f~f~00 '(A"I,,y)!,Cgdovq99" ) #('Z9A"I,,y)!,Cgdovq99*.' : 2 VOE&VOE{{4'!KK %.j$9$9LA' +Y'*$9
 ==E!&&())++{{ )2*(=(=+ /DLL+A.(=H }}%!!#$$&&D"#(;; ##3S_EE LL/2E$  }}%$--/0022DGs   J
!J
J*J-J
)r8  rc  r~   )r   r   r   r   rM   rd   r   r   r   rO   rL   rr   rr   l  s    +HMTLrO   rr   r[   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r?   i	  r   c                   > [         (       d  [        S5      eUb  Ub  [        S5      eUb  [        S5      eUb#  SU;   a  SU;  d  SU;   a  SU;  a  [        S5      e[        [
        U ]  US9  U(       aB  UR                  R                  5        VVs/ s H  u  pEUR                  (       d  M  UPM     nnnOkU(       ad  UR                  U l
        UR                  U l
        UR                  U l        UR                  U l        Uc  [        US	5      (       a  UR                  nUc  [         n[#        U5      U l        gs  snnf )
a  Data class that holds the WOFF2 header major/minor version, any
metadata or private data (as bytes strings), and the set of
table tags that have transformations applied (if reader is not None),
or will have once the WOFF2 font is compiled.

Args:
        reader: an SFNTReader (or subclass) object to read flavor data from.
        data: another WOFFFlavorData object to initialise data from.
        transformedTables: set of strings containing table tags to be transformed.

Raises:
        ImportError if the brotli module is not installed.

NOTE: The 'reader' argument, on the one hand, and the 'data' and
'transformedTables' arguments, on the other hand, are mutually exclusive.
r!   Nz4'reader' and 'data' arguments are mutually exclusivezA'reader' and 'transformedTables' arguments are mutually exclusiverX   rZ   z7'glyf' and 'loca' must be transformed (or not) together)readerrp   )r'   r*   	TypeError
ValueErrorry  r?   rM   r3   r   rR   r   r   r   r   rQ   rp   woff2TransformedTableTagsrs  )rB   rH  rF   rp   r7   rH   r{  s         rL   rM   WOFF2FlavorData.__init__  s=   " z677 VWW ,W  (''//**//VWWot-V-<&,mm&9&9&;!&;
u?P?P&;  !  $ 1 1D $ 1 1D MMDM MMDM (WT;N-O-O$($:$:!$ 9!$%6!7!s   D<-D<c                 .    [         R                  " U5      $ r~   )r;   r<   )rB   r_   s     rL   _decompressWOFF2FlavorData._decompressA  s      ))rO   )r   r   r   rp   )NNN)	r   r   r   r   FlavorrM   rN  r   r~  r  s   @rL   r?   r?   	  s    F38j* *rO   r?   c                 l   [        U 5      S:X  a  [        S5      eSn[        U S   5      S:X  a  [        S5      e[        [        5       H^  n[        U 5      S:X  a  [        S5      e[        U S   5      nU SS n US-  (       a  [        S5      eUS	-  US
-  -  nUS-  S:X  d  M[  X4s  $    [        S5      e)am  Read one to five bytes from UIntBase128-encoded input string, and return
a tuple containing the decoded integer plus any leftover data.

>>> unpackBase128(b'\x3f\x00\x00') == (63, b"\x00\x00")
True
>>> unpackBase128(b'\x8f\xff\xff\xff\x7f')[0] == 4294967295
True
>>> unpackBase128(b'\x80\x80\x3f')  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TTLibError: UIntBase128 value must not start with leading zeros
>>> unpackBase128(b'\x8f\xff\xff\xff\xff\x7f')[0]  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TTLibError: UIntBase128-encoded sequence is longer than 5 bytes
>>> unpackBase128(b'\x90\x80\x80\x80\x00')[0]  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TTLibError: UIntBase128 value exceeds 2**32-1
r   z%not enough data to unpack UIntBase128r  z3UIntBase128 value must not start with leading zerosr   Nl      | z!UIntBase128 value exceeds 2**32-1r  r  z3UIntBase128-encoded sequence is longer than 5 bytes)r0   r   r	   r4   woff2Base128MaxSize)rF   resultrG   codes       rL   rK  rK  E  s    * 4yA~@AAFtAw4NOO&'t9>DEEtAwABxJ@AAA+$+.4KA< ( J
KKrO   c                 J    U S:  d   eSnU S:  a  US-  nU S-  n U S:  a  M  U$ )zReturn the length in bytes of a UIntBase128-encoded sequence with value n.

>>> base128Size(0)
1
>>> base128Size(24567)
3
>>> base128Size(2**32-1)
5
r   r   r  r  r   )nr   s     rL   base128SizerW  r  s=     6M6D
s(		a s( KrO   c                     U S:  d  U S:  a  [        S5      eSn[        U 5      n[        U5       H:  nU SX#-
  S-
  -  -	  S-  nX2S-
  :  a  US-  nU[        R                  " S	U5      -  nM<     U$ )
a  Encode unsigned integer in range 0 to 2**32-1 (inclusive) to a string of
bytes using UIntBase128 variable-length encoding. Produce the shortest possible
encoding.

>>> packBase128(63) == b"\x3f"
True
>>> packBase128(2**32-1) == b'\x8f\xff\xff\xff\x7f'
True
r   l        z3UIntBase128 format requires 0 <= integer <= 2**32-1rO   r  r   r  r  r  )r   rW  r4   r   r   )rV  rF   r   rG   bs        rL   rP  rP    s     	1uU
NOODq>D4[11%&$.ax<IAC##	 
 KrO   c                    [        U SS 5      nU SS n US:X  a>  [        U 5      S:  a  [        S5      e[        R                  " SU SS 5      u  nU SS n X 4$ US:X  a5  [        U 5      S:X  a  [        S5      e[        U SS 5      nUS	-  nU SS n X 4$ US
:X  a5  [        U 5      S:X  a  [        S5      e[        U SS 5      nUS-  nU SS n X 4$ UnX 4$ )a  Read one to three bytes from 255UInt16-encoded input string, and return a
tuple containing the decoded integer plus any leftover data.

>>> unpack255UShort(bytechr(252))[0]
252

Note that some numbers (e.g. 506) can have multiple encodings:
>>> unpack255UShort(struct.pack("BB", 254, 0))[0]
506
>>> unpack255UShort(struct.pack("BB", 255, 253))[0]
506
>>> unpack255UShort(struct.pack("BBB", 253, 1, 250))[0]
506
Nr      r#   z#not enough data to unpack 255UInt16z>H   r     r"  )r	   r0   r   r   r1   )rF   rT  rS  s      rL   r  r    s    48D8Ds{t9q=BCCMM$Ra1	ABx& <% 
t9>BCCbq"#ABx < 
t9>BCCbq"#ABx
 < <rO   c                    U S:  d  U S:  a  [        S5      eU S:  a  [        R                  " SU 5      $ U S:  a  [        R                  " SSU S-
  5      $ U S	:  a  [        R                  " SS
U S-
  5      $ [        R                  " SSU 5      $ )zEncode unsigned integer in range 0 to 65535 (inclusive) to a bytestring
using 255UInt16 variable-length encoding.

>>> pack255UShort(252) == b'\xfc'
True
>>> pack255UShort(506) == b'\xfe\x00'
True
>>> pack255UShort(762) == b'\xfd\x02\xfa'
True
r   i  z/255UInt16 format requires 0 <= integer <= 65535r[  r4  r]  z>BBr"  i  r\  z>BH)r   r   r   )rX  s    rL   r  r    s     qyEFNJKKs{{{4''	{{5#us{33	{{5#us{33{{5#u--rO   c                     [         R                  SU < SU< 35        [        U SSS9nSUl        Ub  [	        UR
                  US9Ul        UR                  USS9  g)	aQ  Compress OpenType font to WOFF2.

Args:
        input_file: a file path, file or file-like object (open in binary mode)
                containing an OpenType font (either CFF- or TrueType-flavored).
        output_file: a file path, file or file-like object where to save the
                compressed WOFF2 font.
        transform_tables: Optional[Iterable[str]]: a set of table tags for which
                to enable preprocessing transformations. By default, only 'glyf'
                and 'loca' tables are transformed. An empty set means disable all
                transformations.
Processing  => Fr$   r   N)rF   rp   reorderTables)r(   infor   r   r?   r@   save)
input_fileoutput_filetransform_tablesfonts       rL   r   r     sX     HHj+>?*5%HDDK#)4D
 	IIkI/rO   c                     [         R                  SU < SU< 35        [        U SSS9nSUl        SUl        UR                  USS9  g)a,  Decompress WOFF2 font to OpenType font.

Args:
        input_file: a file path, file or file-like object (open in binary mode)
                containing a compressed WOFF2 font.
        output_file: a file path, file or file-like object where to save the
                decompressed OpenType font.
r`  ra  Fr$   NTrb  )r(   rd  r   r   r@   re  )rf  rg  ri  s      rL   r<   r<     sA     HHj+>?*5%HDDKDOIIkI.rO   c                   ^ SSK mSSKJn  SSKJn   " U4S jSTR
                  5      n " S STR                  5      n " S	 S
TR                  5      nTR                  S[        R                  SS9nUR                  SSUSS9  UR                  SS9nUR                  SSS9nUR                  SSS9n	X4 H6  n
U
R                  SS9nUR                  SSSSS9  UR                  SSSS S9  M8     UR                  S!S"S#S$9  U	R                  S!S"S%S$9  UR                  S&S'S(S)S$9  U	R                  S&S'S(S*S$9  UR                  5       nUR                  S+S,SUS-S.9  UR                  S/S,SUS0S.9  UR                  [         S1S21S39  U	R                  ["        S49  [%        UR'                  U 5      5      nUR)                  S5S5      nU(       d  UR+                  5         gUR)                  S65      nUR)                  S75      nU" U(       a  S8O
U(       a  S9OS:S;9  US<   (       d  U[         L a  S=nOoU["        L a[  [-        US!   S>5       nUR/                  S?5        UR1                  S?5      nSSS5        [3        W5      S?:X  d   S@5       eUSA:X  a  SBOSCnO[5        U5      eU" US!   SUSD9US<'    U" SE0 UD6  g! , (       d  f       NR= f! [6         a  nUR9                  U5         SnAgSnAff = f)Fz#Compress and decompress WOFF2 fontsr   N)configLogger)makeOutputFileNamec                   &   > \ rS rSrSU 4S jjrSrg)main.<locals>._HelpActioni  Nc                 ,  > UR                    Vs/ s H"  n[        UT
R                  5      (       d  M   UPM$     nnU H?  nUR                  R	                  5        H  u  p[        U	R                  5       5        M      MA     UR                  5         g s  snf r~   )_actions
isinstance_SubParsersActionchoicesr   printformat_helpexit)rB   parser	namespacer   option_stringactionsubparsers_actionssubparsers_actionchoice	subparserargparses             rL   __call__"main.<locals>._HelpAction.__call__  s     %oo"-Ffh&@&@A -  "
 &8!):)B)B)H)H)J%F)//12 *K &8 KKM"s
   BBr   r~   r   r   r   r   r  r   )r  s   rL   _HelpActionro    s    		 		rO   r  c                       \ rS rSrSS jrSrg)$main.<locals>._NoGlyfTransformActioni  Nc                 >    UR                   R                  SS15        g )NrX   rZ   )rh  difference_updaterB   rx  ry  r   rz  s        rL   r  -main.<locals>._NoGlyfTransformAction.__call__  s    &&88&&9IJrO   r   r~   r  r   rO   rL   _NoGlyfTransformActionr    s    	KrO   r  c                       \ rS rSrSS jrSrg)"main.<locals>._HmtxTransformActioni  Nc                 :    UR                   R                  S5        g r1  )rh  addr  s        rL   r  +main.<locals>._HmtxTransformAction.__call__  s    &&**62rO   r   r~   r  r   rO   rL   _HmtxTransformActionr    s    	3rO   r  zfonttools ttLib.woff2F)progdescriptionadd_helpz-hz--helpzshow this help message and exit)r{  helpzsub-commands)titler   z#Compress a TTF or OTF font to WOFF2)r  r<   zDecompress a WOFF2 font to OTF)requiredz-vz	--verbose
store_truezprint more messages to consolez-qz--quietz do not print messages to consolerf  INPUTz&the input OpenType font (.ttf or .otf))metavarr  zthe input WOFF2 fontz-oz--output-fileOUTPUTzthe output WOFF2 fontzthe output OpenType fontz--no-glyf-transformrh  z'Do not transform glyf (and loca) tables)destnargsr{  r  z--hmtx-transformz/Enable optional transformation for 'hmtx' tablerX   rZ   )
subcommandrh  )r  r  quietverboseERRORDEBUGINFO)levelrg  z.woff2rbr"   znot enough datas   OTTOz.otfz.ttf)	outputDir	extensionr   )r  	fontToolsrl  fontTools.ttxrm  r  ActionArgumentParsermainr}  add_argumentadd_subparsers
add_parseradd_mutually_exclusive_groupadd_argument_groupset_defaultsr   r<   vars
parse_argspop
print_helpopenr-   r,   r0   AssertionErrorr   r)   )argsrl  rm  r  r  r  rx  parser_groupparser_compressparser_decompressr  grouptransform_groupoptionsr  r  r  r  fr   er  s                        @rL   r  r    sq   &0
h** 
K K3x 3 $$$$,, % F h{1R   ((~(>L"-- E . O %//"B 0  &9	666F1	 	 	
 	3	 	 	
 :   5 ! 
 ""# #    $	 !  ""'	 #  &88:O  %6 !    #> !     &) !  ""j"96$$T*+G\40JKK Ekk)$GwWV =!! I:%gl+T2aq	ffQi 3 {#q(;*;;("-"8fI ,,!3L!TY"
W 32  Qs$   #J1(K 1
J?
K'K""K'__main__r~   )Mior   rv  ru  r   collectionsr   fontTools.miscr   fontTools.misc.arrayToolsr   fontTools.misc.textToolsr   r   r	   r
   r   fontTools.ttLibr   r   r   r   r   fontTools.ttLib.sfntr   r   r   r   r   r   r   r   r   fontTools.ttLib.tablesr   r   logging	getLoggerr(   r'   
brotlicffir;   r*   r   r   r2   calcsizer/   r<  rH  woff2FlagsSizerJ  rI  r=  rR  r@  rK  r  r  r  r  r   r.   rb   rc   rr   r?   rK  rW  rP  r  r  r   r<   r  r   rw  r   rO   rL   <module>r     s    
   # " 3 J J 
 
 
 7  /0
	# J
C+* C+LC* CP
 $ %%&:; @D 
 !!"23 
 &&'<=   ((1/B+BB  -   #++,@A 
  &  G6. G6T#]6* #Ln/]6* n/bZ]6* Zz9*n 9*x*LZ$,)X..04/"GT zHHTV [3    		s0   9F =F 
FF FF FF