
    h             	       @   S SK JrJ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  S SKJrJrJrJrJr  S SKJr  S S	KJr  S S
KJrJr  S SKJr  S SKJr  S SKrS SKr\R@                  " \!5      r"S r#Sr$Sr%Sr&Sr'Sr(SnS jr) " S S\*5      r+ " S S\+5      r, " S S\" S/ SQ5      5      r- " S S5      r. " S S\+5      r/ " S S \/5      r0 " S! S"\/5      r1 " S# S$\+5      r2 " S% S&\+5      r3 " S' S(\+5      r4 " S) S*\+5      r5 " S+ S,\+5      r6 " S- S.\+5      r7 " S/ S0\+5      r8 " S1 S2\+5      r9 " S3 S4\*5      r: " S5 S6\+5      r; " S7 S8\+5      r<S9 r=S: r>S; r?S< r@SoS= jrAS> rBS? rCS@ rDSA rESB rFSC rGSD rHSE rISF rJSG rKSH rLSI rMSJ rNSK rOSL rPSpSM jrQSN rRSpSO jrSSP rTSQ rUSR rVSS rW\" STSU5      rXSV rYSW rZSX r[SY r\SZ r]S[ r^S\ r_S] r`S^ raS_ rb " S` Sa\*5      rc\" SbS5      rd\" ScS5      re SqSd jrfSrSe jrgSrSf jrhSsSg jri          StSh jrjSi rkSj rlSk rmSl rnSm rog)u    )
namedtupleOrderedDictN)fixedToFloat)otRound)ttLib)otTables)ValueRecordvalueRecordFormatDictOTLOffsetOverflowErrorOTTableWriterCountReference)otBase)STATNameStatement)_compression_level_from_envcompact_lookup)OpenTypeLibError)reducec                     U (       d  g[         R                  " 5       n [        [        U 5      UR                  S9Ul        U$ ! [         a  n[        SU S35      UeSnAff = f)a  Builds a coverage table.

Coverage tables (as defined in the `OpenType spec <https://docs.microsoft.com/en-gb/typography/opentype/spec/chapter2#coverage-table>`__)
are used in all OpenType Layout lookups apart from the Extension type, and
define the glyphs involved in a layout subtable. This allows shaping engines
to compare the glyph stream with the coverage table and quickly determine
whether a subtable should be involved in a shaping operation.

This function takes a list of glyphs and a glyphname-to-ID map, and
returns a ``Coverage`` object representing the coverage table.

Example::

    glyphMap = font.getReverseGlyphMap()
    glyphs = [ "A", "B", "C" ]
    coverage = buildCoverage(glyphs, glyphMap)

Args:
    glyphs: a sequence of glyph names.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    An ``otTables.Coverage`` object or ``None`` if there are no glyphs
    supplied.
NkeyzCould not find glyph z in font)otCoveragesortedset__getitem__glyphsKeyError
ValueError)r   glyphMapselfes       J/var/www/html/env/lib/python3.13/site-packages/fontTools/otlLib/builder.pybuildCoverager#      se    8 ;;=DES[h.B.BC K  E08<=1DEs   "A 
A"AA"               c                 R  ^  T c  gT  Vs/ s H	  o3c  M  UPM     snm T (       d  g[        U 4S jT  5       5      (       d-   S[        T  Vs/ s H  oDR                  PM     sn5      -  5       e[        R                  " 5       nT S   R                  Ul        Xl        T Ul        [        UR                  5      Ul        Ub=  U=R
                  [        -  sl        [        U[        5      (       d   U5       eX%l        U$ UR
                  [        -  S:X  d
   SU-  5       eU$ s  snf s  snf )a  Turns a collection of rules into a lookup.

A Lookup (as defined in the `OpenType Spec <https://docs.microsoft.com/en-gb/typography/opentype/spec/chapter2#lookupTbl>`__)
wraps the individual rules in a layout operation (substitution or
positioning) in a data structure expressing their overall lookup type -
for example, single substitution, mark-to-base attachment, and so on -
as well as the lookup flags and any mark filtering sets. You may import
the following constants to express lookup flags:

- ``LOOKUP_FLAG_RIGHT_TO_LEFT``
- ``LOOKUP_FLAG_IGNORE_BASE_GLYPHS``
- ``LOOKUP_FLAG_IGNORE_LIGATURES``
- ``LOOKUP_FLAG_IGNORE_MARKS``
- ``LOOKUP_FLAG_USE_MARK_FILTERING_SET``

Args:
    subtables: A list of layout subtable objects (e.g.
        ``MultipleSubst``, ``PairPos``, etc.) or ``None``.
    flags (int): This lookup's flags.
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.

Returns:
    An ``otTables.Lookup`` object or ``None`` if there are no subtables
    supplied.
Nc              3   Z   >#    U  H   oR                   TS    R                   :H  v   M"     g7fr   N)
LookupType).0t	subtabless     r"   	<genexpr>buildLookup.<locals>.<genexpr>o   s%      9BA	!///s   (+z3all subtables must have the same LookupType; got %sr   z]if markFilterSet is None, flags must not set LOOKUP_FLAG_USE_MARK_FILTERING_SET; flags=0x%04x)allreprr,   r   Lookup
LookupFlagSubTablelenSubTableCount"LOOKUP_FLAG_USE_MARK_FILTERING_SET
isinstanceintMarkFilteringSet)r/   flagsmarkFilterSetstr.   r    s   `     r"   buildLookupr@   L   s*   < ':ii:I 9B   <t()y!y)@  
 99;Dl--DOODMT]]+D ==---<}<- - K	 "DDJ 	
?AFG	
J K- ; 	*s   DD
D$c                   `    \ 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)LookupBuilder   SUBTABLE_BREAKc                     Xl         UR                  5       U l        X l        X4sU l        U l        SU l        S U l        S U l        US;   d   eg )Nr   )GPOSGSUB)	fontgetReverseGlyphMapr   locationtablelookup_type
lookupflagr>   lookup_index)r    rH   rJ   rK   rL   s        r"   __init__LookupBuilder.__init__   sQ    	//1 ',$
D$! ((((    c                     [        XR                  5      =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ N)r:   	__class__rK   rM   r>   r    others     r"   equalsLookupBuilder.equals   sZ    unn- :

ekk):5#3#33: ""e&9&99		
rQ   c                     0 $ )z?Infers glyph glasses for the GDEF table, such as {"cedilla":3}. r    s    r"   inferGlyphClassesLookupBuilder.inferGlyphClasses       	rQ   c                     0 $ )z$Helper for building 'aalt' features.rZ   r[   s    r"   getAlternateGlyphs LookupBuilder.getAlternateGlyphs   r^   rQ   c                 B    [        XR                  U R                  5      $ rS   )r@   rM   r>   r    r/   s     r"   buildLookup_LookupBuilder.buildLookup_   s    9oot7I7IJJrQ   c                     0 n[        UR                  5       U R                  R                  S9 H  nX   u  pEXB;  d  M  [	        U5      X$'   M     U$ )z{"cedilla": ("BOTTOM", ast.Anchor), ...} --> {"BOTTOM":0, "TOP":1}

Helper for MarkBasePostBuilder, MarkLigPosBuilder, and
MarkMarkPosBuilder. Seems to return the same numeric IDs
for mark classes as the AFDKO makeotf tool.
r   )r   keysrH   
getGlyphIDr7   )r    marksidsmarkmarkClassName_markAnchors         r"   buildMarkClasses_LookupBuilder.buildMarkClasses_   sN     5::<TYY-A-ABD).&M'%(X" C 
rQ   c                     [        U5      Ul        / Ul        [        U5       H3  n[	        X0R
                  5      nUR                  R                  U5        M5     g rS   )r7   BacktrackGlyphCountBacktrackCoveragereversedr#   r   append)r    prefixsubtablepcoverages        r"   setBacktrackCoverage_#LookupBuilder.setBacktrackCoverage_   sG    '*6{$%'"&!A$Q6H&&--h7 "rQ   c                     [        U5      Ul        / Ul        U H3  n[        X0R                  5      nUR                  R                  U5        M5     g rS   )r7   LookAheadGlyphCountLookAheadCoverager#   r   rt   )r    suffixrv   srx   s        r"   setLookAheadCoverage_#LookupBuilder.setLookAheadCoverage_   sB    '*6{$%'"A$Q6H&&--h7 rQ   c                     [        U5      Ul        / Ul        U H3  n[        X0R                  5      nUR                  R                  U5        M5     g rS   )r7   InputGlyphCountInputCoverager#   r   rt   r    r   rv   grx   s        r"   setInputCoverage_LookupBuilder.setInputCoverage_   sB    #&v; !#A$Q6H""))(3 rQ   c                     [        U5      Ul        / Ul        U H3  n[        X0R                  5      nUR                  R                  U5        M5     g rS   )r7   
GlyphCountr   r#   r   rt   r   s        r"   setCoverage_LookupBuilder.setCoverage_   sB    !&kA$Q6H$$X. rQ   c                     0 /nU H3  nUS   U R                   :X  a  UR                  0 5        M)  X   US   U'   M5     U Vs/ s H
  oR" U5      PM     nnU$ s  snf )Nr   )SUBTABLE_BREAK_rt   )r    mappingklasssubstitutionsr   r   r/   s          r"   build_subst_subtables#LookupBuilder.build_subst_subtables   si    C1v---$$R()0b!#&	 
 (55}!U1X}	5 6s   Ac                 B    [         R                  [        SU5      5        g)zAdd an explicit subtable break.

Args:
    location: A string or tuple representing the location in the
        original source which produced this break, or ``None`` if
        no location is provided.
z0unsupported "subtable" statement for lookup typeN)logwarningr   r    rJ   s     r"   add_subtable_break LookupBuilder.add_subtable_break   s     	BH	
rQ   )rH   r   rJ   rN   rL   rM   r>   rK   N)__name__
__module____qualname____firstlineno__r   rO   rW   r\   r`   rd   rn   ry   r   r   r   r   r   __static_attributes__rZ   rQ   r"   rB   rB      sD    &O)
K884/
rQ   rB   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
AlternateSubstBuilder   ac  Builds an Alternate Substitution (GSUB3) lookup.

Users are expected to manually add alternate glyph substitutions to
the ``alternates`` attribute after the object has been initialized,
e.g.::

    builder.alternates["A"] = ["A.alt1", "A.alt2"]

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    alternates: An ordered dictionary of alternates, mapping glyph names
        to a list of names of alternates.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 R    [         R                  XUSS5        [        5       U l        g )NrG      )rB   rO   r   
alternatesr    rH   rJ   s      r"   rO   AlternateSubstBuilder.__init__   s    t8VQ?%-rQ   c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   )rB   rW   r   rU   s     r"   rW   AlternateSubstBuilder.equals  s'    ##D0XT__HXHX5XXrQ   c                 d    U R                  U R                  [        5      nU R                  U5      $ )zrBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the alternate
    substitution lookup.
)r   r   buildAlternateSubstSubtablerd   rc   s     r"   buildAlternateSubstBuilder.build  s1     ..OO8
	   ++rQ   c                     U R                   $ rS   r   r[   s    r"   r`   (AlternateSubstBuilder.getAlternateGlyphs  s    rQ   c                 N    U R                   U R                  U R                   U4'   g rS   )r   r   r   s     r"   r   (AlternateSubstBuilder.add_subtable_break  s!    <@<P<P--x89rQ   r   Nr   r   r   r   __doc__rO   rW   r   r`   r   r   rZ   rQ   r"   r   r      s"    ,(Y
,QrQ   r   c                   $    \ rS rSr\S 5       rSrg)ChainContextualRulei  c                 <    U R                   [        R                  :H  $ rS   )ru   rB   r   r[   s    r"   is_subtable_break%ChainContextualRule.is_subtable_break  s    {{m;;;;rQ   rZ   N)r   r   r   r   propertyr   r   rZ   rQ   r"   r   r     s     < <rQ   r   )ru   r   r~   lookupsc                   L    \ rS rSrS rS r\S 5       r\S 5       rS r	S r
Srg	)
ChainContextualRuleseti!  c                     / U l         g rS   rulesr[   s    r"   rO   ChainContextualRuleset.__init__"  s	    
rQ   c                 :    U R                   R                  U5        g rS   )r   rt   r    rules     r"   addRuleChainContextualRuleset.addRule%  s    

$rQ   c                     U R                    H7  n[        UR                  5      S:  d  [        UR                  5      S:  d  M7    g   g)Nr   TF)r   r7   ru   r~   r   s     r"   hasPrefixOrSuffix(ChainContextualRuleset.hasPrefixOrSuffix(  s;     JJD4;;!#s4;;'7!';  rQ   c                     U R                    HG  nUR                  UR                  UR                  4 H  n[	        S U 5       5      (       d  M      g   MI     g)Nc              3   >   #    U  H  n[        U5      S :  v   M     g7f)r$   Nr7   )r-   xs     r"   r0   <ChainContextualRuleset.hasAnyGlyphClasses.<locals>.<genexpr>7  s     48as1vz8s   TF)r   ru   r   r~   any)r    r   rx   s      r"   hasAnyGlyphClasses)ChainContextualRuleset.hasAnyGlyphClasses1  sI     JJD![[$++t{{C48444 D  rQ   c                     Su  pn/ nXU4 HV  n/ nU R                    H  nUR                  Xu   5        M     U R                  U5      nU(       d    g UR                  U5        MX     U$ )N)r   r$   r%   )r   rt   _classBuilderForContext)	r    PREFIXGLYPHSSUFFIXclassDefBuildersixcontextrclassess	            r"   format2ClassDefs'ChainContextualRuleset.format2ClassDefs;  sn    !(6*BGZZqu%  227;G##G, +  rQ   c                     [        SS9nU HA  nU H8  n[        U5      nUR                  U5      (       d      g UR                  U5        M:     MC     U$ )NF	useClass0)ClassDefBuilderr   canAddadd)r    r   classdefbuilderpositionglyphsetr   s         r"   r   .ChainContextualRuleset._classBuilderForContextH  sS    )E:H$X&--f55##F+	 %   rQ   r   N)r   r   r   r   rO   r   r   r   r   r   r   r   rZ   rQ   r"   r   r   !  s>          rQ   r   c                       \ rS rSrS rS rS rS rSS jrSS jr	SS jr
S	 rS
 rSS jrSS jrSS jrSS jrSS jr SS jrS rSrg)ChainContextualBuilderiS  c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   rB   rW   r   rU   s     r"   rW   ChainContextualBuilder.equalsT  %    ##D0NTZZ5;;5NNrQ   c                 $   [        5       /nU R                   HC  nUR                  (       a  UR                  [        5       5        M/  US   R	                  U5        ME     U Vs/ s H   n[        UR                  5      S:  d  M  UPM"     sn$ s  snf )Nr   r   )r   r   r   rt   r   r7   )r    rulesetr   r   s       r"   rulesetsChainContextualBuilder.rulesetsW  st     *+,JJD%%578BK%	  #77ac!''lQ&67777s   #BBc                     U(       d  gU R                  [        R                  " U5      5      n[        5       nUR	                  X0R
                  5        [        UR                  5       5      nU$ Nr   )rd   copydeepcopyr   compilerH   r7   
getAllData)r    r/   rK   wsizes        r"   getCompiledSize_'ChainContextualBuilder.getCompiledSize_c  sO     !!$--	":;Oa#1<<>"rQ   c           
         / nU R                  5       n[        S U 5       5      nU R                  R                  R	                  S5      nU(       d  U R
                  S:X  a  SnU GH  nSSS/ /nUR                   H&  nUS   R                  U R                  Xs5      5        M(     UR                  5       nU(       a  U R                  XXU5      /US'   UR                  (       d  U R                  XS5      /US'   / n	S	 H7  n
Xj   (       d  M   U R                  Xj   5      nU	R                  XU
   45        M9     U	(       d  ['        SU R$                  5      e[)        U	S S9u  pUR+                  U5        GM     U R-                  U5      $ ! [         a9  n[        R!                  S
U
[#        U R$                  5      U4-  5         SnAM  SnAff = f)zzBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the chained
    contextual positioning lookup.
c              3   8   #    U  H  oR                   v   M     g 7frS   )r   )r-   r   s     r"   r0   /ChainContextualBuilder.build.<locals>.<genexpr>x  s     IW00s   z$fontTools.otlLib.builder:WRITE_GPOS7PosTNr   r%   r$   )r$   r%   r   z*Contextual format %i at %s overflowed (%s)zAll candidates overflowedc                     U S   $ r   rZ   )r   s    r"   <lambda>.ChainContextualBuilder.build.<locals>.<lambda>  s    adrQ   r   )r   r   rH   cfggetsubtable_typer   rt   buildFormat3Subtabler   buildFormat2Subtabler   buildFormat1Subtabler   r   r   r   strrJ   r   minextendrd   )r    r/   r   chainingwrite_gpos7r   
candidatesr   	classdefscandidates_by_sizeir   r!   	_min_sizewinners                  r"   r   ChainContextualBuilder.buildn  s    	==?III iimm''(NOt11U:HG dB/J1$$T%>%>t%NO &  002I--g(K!
1 --!%!:!:7!M N
1!#==I#44Z]C +114A2GH  &&'BDMMRR #$6N KIV$O  V   ++! 2 H #dmm"4a89 s   F
G.GGc           	      4   U R                  US9nSUl        UR                  5         [        5       n0 nU R	                  SUS9nUR
                   GHs  nU R                  SUS9nU(       a  [        UR                  5      Ul	        [        UR                  5      Ul        [        UR                  5       V	s/ s H  n	[        U	5      S   PM     sn	Ul        UR                   V	s/ s H  n	[        U	5      S   PM     sn	Ul        [        UR                   5      Ul        O[        UR                   5      Ul        UR                   SS   V	s/ s H  n	[        U	5      S   PM     sn	Ul        U R)                  Xx5        [        UR                   S   5      S   n
X;  a  UR+                  U
5        / XZ'   XZ   R-                  U5        GMv     [/        X@R0                  5      Ul        / nUR2                  R                    HL  nU R5                  SUS9n[7        XX\   5        [7        X S3[        X\   5      5        UR-                  U5        MN     [7        X0R9                  SUS9U5        [7        X0R9                  SUS9S-   [        U5      5        U$ s  sn	f s  sn	f s  sn	f )Nr  r$   formatr  r   Count)newSubtable_FormatpopulateDefaultsr   	ruleAttr_r   newRule_r7   ru   rq   r~   r|   rs   list	Backtrack	LookAheadr   r   r   InputbuildLookupListr   rt   r#   r   r   newRuleSet_setattrruleSetAttr_)r    r   r  r?   rx   rulesetsByFirstGlyphruleAttrr   ruleAsSubtabler   
firstGlyphruleSetsr   ruleSets                 r"   r  +ChainContextualBuilder.buildFormat1Subtable  sA   1	
5!>>X>>MMD!]]!h]GN585E2585E2@H@U+V@U1DGAJ@U+V(@D+L1DGAJ+L(14T[[1A.,/,<)8<AB#H1DGAJ#HN   6dkk!n-a0J5Z(35$0 ,33NC+ ". $Hmm<##A&&a(&CGG';'>?Gz/5I5L1MNOOG$	 $ 	%%Q%BHM!!X!>H#h-	
 	= ,W+L $Is   5J#J	Jc           
         U R                  US9nSUl        UR                  5         U(       a4  U Vs/ s H  oUR                  5       PM     snu  Ul        Ul        Ul        OUS   R                  5       Ul        US   R                  5       n/ nU H$  nU R                  SUS9n	UR                  U	5        M&     [        5       n
U R                  SUS9nUR                   GHt  nU R                  SUS9nU(       Ga]  [        UR                   5      Ul        [        UR$                  5      Ul        [)        UR                   5       Vs/ s H(  nUR                  R*                  [-        U5      S      PM*     snUl        UR$                   Vs/ s H'  oR                  R*                  [-        U5      S      PM)     snUl        [        UR2                  5      Ul        UR2                  SS   Vs/ s H'  oR
                  R*                  [-        U5      S      PM)     snUl        UUR
                  R*                  [-        UR2                  S   5      S         nO[        UR2                  5      Ul        UR2                  SS   Vs/ s H'  oR                  R*                  [-        U5      S      PM)     snUl        UUR                  R*                  [-        UR2                  S   5      S         nU R=                  X5        U
[        UR2                  S   5      -  n
[?        X5      R                  U5        [A        UU S3[?        X S35      S-   5        GMw     [C        U5       H  u  nn	[?        X5      (       a  M  S UU'   M     [A        X@RE                  SUS9U5        [A        X@RE                  SUS9S-   [        U5      5        [G        XRH                  5      Ul%        U$ s  snf s  snf s  snf s  snf s  snf )Nr  r%   r$   r  r   r  )&r  r  r  r   BacktrackClassDefInputClassDefLookAheadClassDefClassDefr   r$  rt   r   r  r   r  r7   ru   rq   r~   r|   rs   	classDefsr  r   r!  r   r   r"  r   Classr#  getattrr%  	enumerater&  r#   r   r   )r    r   r  r  r?   c	inClasses	classSets_classSetrx   classRuleAttrr   r)  r   setForThisRuler  s                    r"   r  +ChainContextualBuilder.buildFormat2Subtable  s   1	

 %..IqI.	$ $ $A,,,.BKaL((*		A''q8'DHX&  5a(CMMD!]]!h]GN585E2585E2 &dkk2,2 ((22471:>2,(
 IM,HS1((22471:>,( 25T[[1A.DHKKPQPRO(DSq$$..tAwqz:O($ "+$$..tDKKN/CA/FG" -0,<)?C{{12(?N!KK))$q'!*5($ "+KK))$t{{1~*>q*AB"   6DKKN++HN299.I /'/(?@1DI "R %Y/KAx833#	! 0 	%%Q%BIN!!X!>H#i.	
 $Hmm<	A /,,,
((s   O /O%.O*,.O/.O4c                 D   U R                  US9nSUl        U(       aU  U R                  UR                  U5        U R	                  UR
                  U5        U R                  UR                  U5        OU R                  UR                  U5        U R                  X5        U$ )Nr  r   )
r  r  ry   ru   r   r~   r   r   r   r#  )r    r   r  r?   s       r"   r  +ChainContextualBuilder.buildFormat3Subtable/  s    1	&&t{{B7&&t{{B7""4;;3dkk2.T&	rQ   c                 ^   [        UR                  5       H  u  p4Uc  M
  [        U[        5      (       d  U/nU Hl  nUR                  c4  [        U [
        5      (       a  SnOSn[        SU S3U R                  5      eU R                  U5      nX7l	        UR                  Ul
        Mn     M     g )Nsubstitutionpositioningz2Missing index of the specified lookup, might be a z lookup)r6  r   r:   r  rN   ChainContextPosBuilderr   rJ   newLookupRecord_SequenceIndexLookupListIndex)r    r   r?   sequenceIndex
lookupListlrV   recs           r"   r#  &ChainContextualBuilder.buildLookupList;  s    )24<<)@%M%!*d33",J#A~~-%d,BCC$2E$1E.227A MM 
 //3C(5%*+..C' $ *ArQ   c                     U R                   R                  [        U R                  U R                  U R                  U R                  /5      5        g rS   )r   rt   r   r   r   s     r"   r   )ChainContextualBuilder.add_subtable_breakP  sC    

$$$$$$%%&		
rQ   c                     SU R                    3nU(       a  SU-   n[        [        U5      " 5       n[        X0R                    S3S5        [        X0R                    S3/ 5        U$ )NContextChainr  r   LookupRecord)r  r5  r   r%  )r    r  subtablenamer?   s       r"   r  #ChainContextualBuilder.newSubtable_Z  sf     !3!3 45"\1LR&())*%0!4))*,7<	rQ   c                     US:X  a  SnOUS:X  a  SnO[        W5      eU R                  SS  U S3nU(       a  SU-   nU$ )	Nr$   Ruler%   r4  r   r   SetrQ  AssertionErrorr  r    r  r  
formatTyperS  s        r"   r&  #ChainContextualBuilder.ruleSetAttr_m  sV    Q;Jq[ J ,,,,Qq12:,cB"\1LrQ   c                     US:X  a  SnOUS:X  a  SnO[        W5      eU R                  SS  U S3nU(       a  SU-   nU$ )	Nr$    r%   r4  r   r   rV  rQ  rX  rZ  s        r"   r   ChainContextualBuilder.ruleAttr_y  sV    Q;Jq[ J ,,,,Qq12:,dC"\1LrQ   c                 n    [        [        U R                  X5      5      " 5       nUR                  5         U$ rS   )r5  r   r&  r  r    r  r  r?   s       r"   r$  "ChainContextualBuilder.newRuleSet_  s4    !!&3
  		rQ   c                 n    [        [        U R                  X5      5      " 5       nUR                  5         U$ rS   )r5  r   r  r  ra  s       r"   r  ChainContextualBuilder.newRule_  s2    v0
  		rQ   Nc                 `   U(       a
  SU-   nSU-   n[        X5      (       d  [        XS5        [        X/ 5        U(       a  UnO[        [        U5      " 5       n[        X[        X5      S-   5        U(       a  [        X5      R	                  XW5        U$ [        X5      R                  U5        U$ )NrQ  r   r$   )hasattrr%  r5  r   insertrt   )r    r?   subtable_name
count_nameexistingindexr  new_subtables           r"   attachSubtableWithCount_/ChainContextualBuilder.attachSubtableWithCount_  s     #m3M :-Jr&&BA&Br*#L #2}57L 7! ;<B&--eB  B&--l;rQ   c                 Z    U R                  UU R                   S3U R                   S3SS9$ )NrR  r  Fr  )rm  r  r    r?   s     r"   rE  'ChainContextualBuilder.newLookupRecord_  sB    ,,!!",/!!"%(	 - 
 	
rQ   rZ   )T)r$   T)NNF)r   r   r   r   rW   r   r   r   r  r  r  r#  r   r  r&  r  r$  r  rm  rE  r   rZ   rQ   r"   r   r   S  s_    O
8	E,N,\JX
9*
&

 RW4
rQ   r   c                   $    \ rS rSrSrS rS rSrg)rD  i  a  Builds a Chained Contextual Positioning (GPOS8) lookup.

Users are expected to manually add rules to the ``rules`` attribute after
the object has been initialized, e.g.::

    # pos [A B] [C D] x' lookup lu1 y' z' lookup lu2 E;

    prefix  = [ ["A", "B"], ["C", "D"] ]
    suffix  = [ ["E"] ]
    glyphs  = [ ["x"], ["y"], ["z"] ]
    lookups = [ [lu1], None,  [lu2] ]
    builder.rules.append( (prefix, glyphs, suffix, lookups) )

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    rules: A list of tuples representing the rules in this lookup.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 P    [         R                  XUSS5        / U l        SU l        g )NrF   r'   r   rB   rO   r   r  r   s      r"   rO   ChainContextPosBuilder.__init__  s%    t8VQ?
"rQ   c                    ^^ SnUSSS2    HM  mTU R                   :X  a  Us  $ [        T[        5      (       d  M.  [        UU4S jU 5       5      (       d  MK  TnMO     U$ )z$Helper for add_single_pos_chained_()Nr   c              3   H   >#    U  H  nTR                  UT5      v   M     g 7frS   )can_add)r-   glyphlookupvalues     r"   r0   CChainContextPosBuilder.find_chainable_single_pos.<locals>.<genexpr>  s"      <:@ue,,&s   ")r   r:   SinglePosBuilderr2   )r    r   r   r{  resrz  s      ` @r"   find_chainable_single_pos0ChainContextPosBuilder.find_chainable_single_pos  sb    ddmF---
&"233 <:@< 9 9  $ 
rQ   r   r  N)r   r   r   r   r   rO   r  r   rZ   rQ   r"   rD  rD    s    4#

rQ   rD  c                   0    \ rS rSrSrS rS rS rS rSr	g)	ChainContextSubstBuilderi  a  Builds a Chained Contextual Substitution (GSUB6) lookup.

Users are expected to manually add rules to the ``rules`` attribute after
the object has been initialized, e.g.::

    # sub [A B] [C D] x' lookup lu1 y' z' lookup lu2 E;

    prefix  = [ ["A", "B"], ["C", "D"] ]
    suffix  = [ ["E"] ]
    glyphs  = [ ["x"], ["y"], ["z"] ]
    lookups = [ [lu1], None,  [lu2] ]
    builder.rules.append( (prefix, glyphs, suffix, lookups) )

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    rules: A list of tuples representing the rules in this lookup.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 P    [         R                  XUSS5        / U l        SU l        g )NrG      Substrt  r   s      r"   rO   !ChainContextSubstBuilder.__init__  s%    t8VQ?
$rQ   c                 v  ^ 0 nU R                    H  nUR                  (       a  M  UR                   H  n[        U[        5      (       d  U/nU H^  nUc  M  UR                  5       nUR                  5        H2  u  pgUR                  U/ 5      mTR                  U4S jU 5       5        M4     M`     M     M     U$ )Nc              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7frS   rZ   )r-   r   alts_for_glyphs     r"   r0   >ChainContextSubstBuilder.getAlternateGlyphs.<locals>.<genexpr>  s      2+7aN;R<s   		)	r   r   r   r:   r  r`   items
setdefaultr  )	r    resultr   r   rz  altsry  replacementsr  s	           @r"   r`   +ChainContextSubstBuilder.getAlternateGlyphs  s    JJD%%<<!'400&iG%F)%88:37::</E-3->->ub-IN*11 2+72  4@ & (  rQ   c                   ^^ SnU R                   SSS2    Hg  nUR                  (       a  Us  $ UR                   H?  m[        TU5      (       d  M  [	        UU4S jTR
                   5       5      (       a  M=  TnMA     Mi     U$ )z.Helper for add_{single,multi}_subst_chained_()Nr   c              3   d   >#    U  H%  oT;   =(       a    TU   TR                   U   :g  v   M'     g 7frS   r   )r-   r   r   subs     r"   r0   @ChainContextSubstBuilder.find_chainable_subst.<locals>.<genexpr>  s/      >KVaLAWQZ3;;q>%AA;s   -0)r   r   r   r:   r   r   )r    r   builder_classr~  r   r  s    `   @r"   find_chainable_subst-ChainContextSubstBuilder.find_chainable_subst  ss    JJtt$D%%
||c=11# >KN;;> ; ; C	 $ % 
rQ   c                   ^^ SnU R                   SSS2    Hr  nUR                  (       a  Us  $ UR                   HJ  m[        T[        5      (       d  M  [        UU4S j[        R                  " U6  5       5      (       d  MH  TnML     Mt     U$ )z(Helper for add_ligature_subst_chained_()Nr   c              3   b   >#    U  H$  nTR                   R                  UT5      T:H  v   M&     g 7frS   )	ligaturesr  )r-   seqreplacementr  s     r"   r0   IChainContextSubstBuilder.find_chainable_ligature_subst.<locals>.<genexpr>+  s.      9 MM%%c;7;F9s   ,/)r   r   r   r:   LigatureSubstBuilderr2   	itertoolsproduct)r    r   r  r~  r   r  s     `  @r"   find_chainable_ligature_subst6ChainContextSubstBuilder.find_chainable_ligature_subst"  s    JJtt$D%%
||!#';<< (00&9   C $ % 
rQ   r  N)
r   r   r   r   r   rO   r`   r  r  r   rZ   rQ   r"   r  r    s    4%
$rQ   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	r  i3  aR  Builds a Ligature Substitution (GSUB4) lookup.

Users are expected to manually add ligatures to the ``ligatures``
attribute after the object has been initialized, e.g.::

    # sub f i by f_i;
    builder.ligatures[("f","f","i")] = "f_f_i"

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    ligatures: An ordered dictionary mapping a tuple of glyph names to the
        ligature glyphname.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 R    [         R                  XUSS5        [        5       U l        g )NrG   r&   )rB   rO   r   r  r   s      r"   rO   LigatureSubstBuilder.__init__J  s    t8VQ?$rQ   c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   )rB   rW   r  rU   s     r"   rW   LigatureSubstBuilder.equalsN  s%    ##D0VT^^u5VVrQ   c                 d    U R                  U R                  [        5      nU R                  U5      $ )zqBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the ligature
    substitution lookup.
)r   r  buildLigatureSubstSubtablerd   rc   s     r"   r   LigatureSubstBuilder.buildQ  s1     ..NN6
	   ++rQ   c                 N    U R                   U R                  U R                   U4'   g rS   )r   r  r   s     r"   r   'LigatureSubstBuilder.add_subtable_break]  s!    ;?;O;O,,h78rQ   )r  N
r   r   r   r   r   rO   rW   r   r   r   rZ   rQ   r"   r  r  3  s    ,'W
,PrQ   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	MultipleSubstBuilderia  a  Builds a Multiple Substitution (GSUB2) lookup.

Users are expected to manually add substitutions to the ``mapping``
attribute after the object has been initialized, e.g.::

    # sub uni06C0 by uni06D5.fina hamza.above;
    builder.mapping["uni06C0"] = [ "uni06D5.fina", "hamza.above"]

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    mapping: An ordered dictionary mapping a glyph name to a list of
        substituted glyph names.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 R    [         R                  XUSS5        [        5       U l        g )NrG   r%   rB   rO   r   r   r   s      r"   rO   MultipleSubstBuilder.__init__x      t8VQ?"}rQ   c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   rB   rW   r   rU   s     r"   rW   MultipleSubstBuilder.equals|  %    ##D0RT\\U]]5RRrQ   c                 d    U R                  U R                  [        5      nU R                  U5      $ rS   )r   r   buildMultipleSubstSubtablerd   rc   s     r"   r   MultipleSubstBuilder.build  s*    ..t||=WX	  ++rQ   c                 N    U R                   U R                  U R                   U4'   g rS   r   r   r   s     r"   r   'MultipleSubstBuilder.add_subtable_break  !    9=9M9Md**H56rQ   r  Nr  rZ   rQ   r"   r  r  a  s    ,%S,NrQ   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	CursivePosBuilderi  a  Builds a Cursive Positioning (GPOS3) lookup.

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    attachments: An ordered dictionary mapping a glyph name to a two-element
        tuple of ``otTables.Anchor`` objects.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 B    [         R                  XUSS5        0 U l        g )NrF   r   )rB   rO   attachmentsr   s      r"   rO   CursivePosBuilder.__init__  s    t8VQ?rQ   c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   )rB   rW   r  rU   s     r"   rW   CursivePosBuilder.equals  s+      -W$2B2BeFWFW2W	
rQ   c                 6    U H  nX44U R                   U'   M     g)a  Adds attachment information to the cursive positioning lookup.

Args:
    location: A string or tuple representing the location in the
        original source which produced this lookup. (Unused.)
    glyphs: A list of glyph names sharing these entry and exit
        anchor locations.
    entryAnchor: A ``otTables.Anchor`` object representing the
        entry anchor, or ``None`` if no entry anchor is present.
    exitAnchor: A ``otTables.Anchor`` object representing the
        exit anchor, or ``None`` if no exit anchor is present.
Nr  )r    rJ   r   entryAnchor
exitAnchorry  s         r"   add_attachment CursivePosBuilder.add_attachment  s!     E'2&?DU# rQ   c                 f    [        U R                  U R                  5      nU R                  U/5      $ )zoBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the cursive
    positioning lookup.
)buildCursivePosSubtabler  r   rd   rp  s     r"   r   CursivePosBuilder.build  s-     %T%5%5t}}E  "&&rQ   r  N)
r   r   r   r   r   rO   rW   r  r   r   rZ   rQ   r"   r  r    s     

@ 'rQ   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	MarkBasePosBuilderi  a  Builds a Mark-To-Base Positioning (GPOS4) lookup.

Users are expected to manually add marks and bases to the ``marks``
and ``bases`` attributes after the object has been initialized, e.g.::

    builder.marks["acute"]   = (0, a1)
    builder.marks["grave"]   = (0, a1)
    builder.marks["cedilla"] = (1, a2)
    builder.bases["a"] = {0: a3, 1: a5}
    builder.bases["b"] = {0: a4, 1: a5}

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    marks: An dictionary mapping a glyph name to a two-element
        tuple containing a mark class ID and ``otTables.Anchor`` object.
    bases: An dictionary mapping a glyph name to a dictionary of
        mark class IDs and ``otTables.Anchor`` object.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 P    [         R                  XUSS5        0 U l        0 U l        g )NrF   r&   )rB   rO   ri   basesr   s      r"   rO   MarkBasePosBuilder.__init__  s$    t8VQ?

rQ   c                     [         R                  X5      =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ rS   )rB   rW   ri   r  rU   s     r"   rW   MarkBasePosBuilder.equals  s?      - *

ekk)*

ekk)	
rQ   c                     U R                    Vs0 s H  oS_M     nnUR                  U R                   Vs0 s H  oS_M     sn5        U$ s  snf s  snf )Nr$   r   )r  updateri   r    ry  r  s      r"   r\   $MarkBasePosBuilder.inferGlyphClasses  sJ    (,

3
u(
3TZZ8ZEaxZ89 48
   AAc                    U R                  U R                  5      n0 nU R                  R                  5        H(  u  nu  pEXA;  a  [        SU< SU< 35      eX   U4X#'   M*     0 nU R                  R                  5        HC  u  px0 Xg'   UR                  5        H&  u  pEXA;  a  [        SU< SU< 35      eXVU   X   '   M(     ME     [        X&U R                  5      n	U R                  U	5      $ )ztBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the mark-to-base
    positioning lookup.
zMark class z not found for mark glyph z not found for base glyph )rn   ri   r  r   r  buildMarkBasePosr   rd   )
r    markClassesri   rk   mcanchorr  ry  anchorsr/   s
             r"   r   MarkBasePosBuilder.build  s     ,,TZZ8"&**"2"2"4D,2$ CEtL  '?F3EK #5 "jj..0NEEL%mmo
($GI5Q  17e[_- . 1 %U4==A	  ++rQ   )r  ri   N
r   r   r   r   r   rO   rW   r\   r   r   rZ   rQ   r"   r  r    s    6


,rQ   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	MarkLigPosBuilderi  a  Builds a Mark-To-Ligature Positioning (GPOS5) lookup.

Users are expected to manually add marks and bases to the ``marks``
and ``ligatures`` attributes after the object has been initialized, e.g.::

    builder.marks["acute"]   = (0, a1)
    builder.marks["grave"]   = (0, a1)
    builder.marks["cedilla"] = (1, a2)
    builder.ligatures["f_i"] = [
        { 0: a3, 1: a5 }, # f
        { 0: a4, 1: a5 }  # i
    ]

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    marks: An dictionary mapping a glyph name to a two-element
        tuple containing a mark class ID and ``otTables.Anchor`` object.
    ligatures: An dictionary mapping a glyph name to an array with one
        element for each ligature component. Each array element should be
        a dictionary mapping mark class IDs to ``otTables.Anchor`` objects.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 P    [         R                  XUSS5        0 U l        0 U l        g )NrF      )rB   rO   ri   r  r   s      r"   rO   MarkLigPosBuilder.__init__$  $    t8VQ?
rQ   c                     [         R                  X5      =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ rS   )rB   rW   ri   r  rU   s     r"   rW   MarkLigPosBuilder.equals)  ?      - 2

ekk)2%//1	
rQ   c                     U R                    Vs0 s H  oS_M     nnUR                  U R                   Vs0 s H  oS_M     sn5        U$ s  snf s  snf )Nr%   r   )r  r  ri   r  s      r"   r\   #MarkLigPosBuilder.inferGlyphClasses0  J    (,7u(7TZZ8ZEaxZ89 88r  c           
         U R                  U R                  5      nU R                  R                  5        VVVs0 s H  u  nu  p4X!U   U4_M     nnnn0 nU R                  R                  5        HK  u  px/ Xg'   U H<  n	Xg   R	                  U	R                  5        VV
s0 s H
  u  p:X   U
_M     sn
n5        M>     MM     [        XVU R                  5      nU R                  U5      $ s  snnnf s  sn
nf )zxBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the mark-to-ligature
    positioning lookup.
)rn   ri   r  r  rt   buildMarkLigPosr   rd   )r    r  rk   r  r  ri   ligslig
componentsr7  ar/   s               r"   r   MarkLigPosBuilder.build5  s     ,,TZZ8FJjjFVFVFX
FX0BlrDr?F++FX 	 
 #~~335OCDI	  !'')!L)+/1"4)!LM    6 $E?	  ++
 "Ms   C&C-)r  ri   Nr  rZ   rQ   r"   r  r    s    <


,rQ   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	MarkMarkPosBuilderiI  a{  Builds a Mark-To-Mark Positioning (GPOS6) lookup.

Users are expected to manually add marks and bases to the ``marks``
and ``baseMarks`` attributes after the object has been initialized, e.g.::

    builder.marks["acute"]     = (0, a1)
    builder.marks["grave"]     = (0, a1)
    builder.marks["cedilla"]   = (1, a2)
    builder.baseMarks["acute"] = {0: a3}

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    marks: An dictionary mapping a glyph name to a two-element
        tuple containing a mark class ID and ``otTables.Anchor`` object.
    baseMarks: An dictionary mapping a glyph name to a dictionary
        containing one item: a mark class ID and a ``otTables.Anchor`` object.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 P    [         R                  XUSS5        0 U l        0 U l        g )NrF   r  )rB   rO   ri   	baseMarksr   s      r"   rO   MarkMarkPosBuilder.__init__d  r  rQ   c                     [         R                  X5      =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ rS   )rB   rW   ri   r  rU   s     r"   rW   MarkMarkPosBuilder.equalsi  r  rQ   c                     U R                    Vs0 s H  oS_M     nnUR                  U R                   Vs0 s H  oS_M     sn5        U$ s  snf s  snf )Nr   )r  r  ri   r  s      r"   r\   $MarkMarkPosBuilder.inferGlyphClassesp  r  r  c                    U R                  U R                  5      n[        UR                  5       UR                  S9nU R                  R                  5        VVVs0 s H  u  nu  pEX1U   U4_M     nnnn[        R                  " 5       nSUl        [        U5      Ul
        [        X`R                  5      Ul        [        U R                  U R                  5      Ul        [!        X`R                  5      Ul        [        R$                  " 5       Ul        [        UR                  R&                  5      UR$                  l        / UR$                  l        UR                  R&                   H^  nU Vs/ s H   o@R                  U   R	                  U5      PM"     n	nUR$                  R*                  R-                  [/        U	5      5        M`     U R1                  U/5      $ s  snnnf s  snf )ztBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the mark-to-mark
    positioning lookup.
r   r$   )rn   ri   r   rg   r  r  r   MarkMarkPosr  r7   
ClassCountr#   r   Mark1Coverager  Mark2CoveragebuildMarkArray
Mark1Array
Mark2Arrayr   
Mark2CountMark2Recordrt   buildMark2Recordrd   )
r    r  markClassListrk   r  r  ri   r?   baser  s
             r"   r   MarkMarkPosBuilder.buildu  sw    ,,TZZ8{//1{GFJjjFVFVFX
FX0BlrDr?F++FX 	 
 ^^	K((>(G&umm<#&r'7'7'>'>#? $&!$$++D>KLm~~d+//3mGLMM%%,,-=g-FG ,   "&&!
 Ms   G1'G%)r  ri   Nr  rZ   rQ   r"   r  r  I  s    4


'rQ   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	ReverseChainSingleSubstBuilderi  a  Builds a Reverse Chaining Contextual Single Substitution (GSUB8) lookup.

Users are expected to manually add substitutions to the ``substitutions``
attribute after the object has been initialized, e.g.::

    # reversesub [a e n] d' by d.alt;
    prefix = [ ["a", "e", "n"] ]
    suffix = []
    mapping = { "d": "d.alt" }
    builder.substitutions.append( (prefix, suffix, mapping) )

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    substitutions: A three-element tuple consisting of a prefix sequence,
        a suffix sequence, and a dictionary of single substitutions.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 B    [         R                  XUSS5        / U l        g )NrG   r'   )rB   rO   r   r   s      r"   rO   'ReverseChainSingleSubstBuilder.__init__  s    t8VQ?
rQ   c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   r   rU   s     r"   rW   %ReverseChainSingleSubstBuilder.equals  r   rQ   c                    / nU R                    H  u  p#n[        R                  " 5       nSUl        U R	                  X%5        U R                  X55        [        UR                  5       U R                  5      Ul	        [        U5      Ul        UR                  R                   Vs/ s H  odU   PM	     snUl        UR                  U5        M     U R                  U5      $ s  snf )z{Build the lookup.

Returns:
    An ``otTables.Lookup`` object representing the chained
    contextual substitution lookup.
r$   )r   r   ReverseChainSingleSubstr  ry   r   r#   rg   r   r   r7   r   r   
Substitutert   rd   )r    r/   ru   r~   r   r?   r   s          r"   r   $ReverseChainSingleSubstBuilder.build  s     	'+zz#FG++-BBI&&v2&&v2'FBKLBM131C1CD1CAQZ1CDBMR  (2   ++ Es   $C c                     g rS   rZ   r   s     r"   r   1ReverseChainSingleSubstBuilder.add_subtable_break  s    rQ   r   Nr  rZ   rQ   r"   r  r    s    2O,&rQ   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
SingleSubstBuilderi  a$  Builds a Single Substitution (GSUB1) lookup.

Users are expected to manually add substitutions to the ``mapping``
attribute after the object has been initialized, e.g.::

    # sub x by y;
    builder.mapping["x"] = "y"

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    mapping: A dictionary mapping a single glyph name to another glyph name.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 R    [         R                  XUSS5        [        5       U l        g )NrG   r$   r  r   s      r"   rO   SingleSubstBuilder.__init__  r  rQ   c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   r  rU   s     r"   rW   SingleSubstBuilder.equals  r  rQ   c                 d    U R                  U R                  [        5      nU R                  U5      $ )zqBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the multiple
    substitution lookup.
)r   r   buildSingleSubstSubtablerd   rc   s     r"   r   SingleSubstBuilder.build  s,     ..t||=UV	  ++rQ   c                 n    U R                   R                  5        VVs0 s H  u  pX/_M
     snn$ s  snnf rS   )r   r  )r    ry  repls      r"   r`   %SingleSubstBuilder.getAlternateGlyphs  s/    151C1C1EF1E+%v1EFFFs   1c                 N    U R                   U R                  U R                   U4'   g rS   r  r   s     r"   r   %SingleSubstBuilder.add_subtable_break  r  rQ   r  Nr   rZ   rQ   r"   r  r    s#    *%S,GNrQ   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
ClassPairPosSubtableBuilderi  a;  Builds class-based Pair Positioning (GPOS2 format 2) subtables.

Note that this does *not* build a GPOS2 ``otTables.Lookup`` directly,
but builds a list of ``otTables.PairPos`` subtables. It is used by the
:class:`PairPosBuilder` below.

Attributes:
    builder (PairPosBuilder): A pair positioning lookup builder.
c                 X    Xl         Su  U l        U l        0 U l        SU l        / U l        g )NNNF)builder_
classDef1_
classDef2_values_forceSubtableBreak_
subtables_)r    builders     r"   rO   $ClassPairPosSubtableBuilder.__init__  s+    +5(#( rQ   c                    U R                   (       + =(       ag    U R                  SL=(       aR    U R                  R                  U5      =(       a0    U R                  SL=(       a    U R                  R                  U5      nU(       d3  U R	                  5         [        SS9U l        [        SS9U l        0 U l        U R                  R                  U5        U R                  R                  U5        X$4U R                  X4'   g)a>  Add a pair positioning rule.

Args:
    gc1: A set of glyph names for the "left" glyph
    value1: An ``otTables.ValueRecord`` object for the left glyph's
        positioning.
    gc2: A set of glyph names for the "right" glyph
    value2: An ``otTables.ValueRecord`` object for the right glyph's
        positioning.
NTr   F)r1  r.  r   r/  flush_r   r0  r   )r    gc1value1gc2value2	mergeables         r"   addPair#ClassPairPosSubtableBuilder.addPair
  s     ((( ,t+,&&s+, t+, &&s+ 	 KKM-=DO->DODLC C $*#3cZ rQ   c                     SU l         g)z-Add an explicit subtable break at this point.TN)r1  r[   s    r"   addSubtableBreak,ClassPairPosSubtableBuilder.addSubtableBreak%  s
    #' rQ   c                 :    U R                  5         U R                  $ )z>Return the list of ``otTables.PairPos`` subtables constructed.)r6  r2  r[   s    r"   r/   %ClassPairPosSubtableBuilder.subtables)  s    rQ   c                     U R                   b  U R                  c  g [        U R                  U R                  R
                  5      nUR                  c  g U R                  R                  U5        SU l	        g )NF)
r.  r/  buildPairPosClassesSubtabler0  r-  r   r   r2  rt   r1  rp  s     r"   r6  "ClassPairPosSubtableBuilder.flush_.  sY    ??"doo&=(t}}7M7MN;;r"#( rQ   )r-  r.  r/  r1  r2  r0  N)r   r   r   r   r   rO   r<  r?  r/   r6  r   rZ   rQ   r"   r*  r*    s     46(
)rQ   r*  c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)PairPosBuilderi8  ae  Builds a Pair Positioning (GPOS2) lookup.

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    pairs: An array of class-based pair positioning tuples. Usually
        manipulated with the :meth:`addClassPair` method below.
    glyphPairs: A dictionary mapping a tuple of glyph names to a tuple
        of ``otTables.ValueRecord`` objects. Usually manipulated with the
        :meth:`addGlyphPair` method below.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 ^    [         R                  XUSS5        / U l        0 U l        0 U l        g )NrF   r%   )rB   rO   pairs
glyphPairs	locationsr   s      r"   rO   PairPosBuilder.__init__L  s+    t8VQ?
rQ   c                 >    U R                   R                  X#XE45        g)a  Add a class pair positioning rule to the current lookup.

Args:
    location: A string or tuple representing the location in the
        original source which produced this rule. Unused.
    glyphclass1: A set of glyph names for the "left" glyph in the pair.
    value1: A ``otTables.ValueRecord`` for positioning the left glyph.
    glyphclass2: A set of glyph names for the "right" glyph in the pair.
    value2: A ``otTables.ValueRecord`` for positioning the right glyph.
N)rI  rt   )r    rJ   glyphclass1r8  glyphclass2r:  s         r"   addClassPairPairPosBuilder.addClassPairR  s     	

;DErQ   c                     X$4nU R                   R                  US5      nUb(  U R                  U   n[        R	                  SUUU5        gX54U R                   U'   XR                  U'   g)a  Add a glyph pair positioning rule to the current lookup.

Args:
    location: A string or tuple representing the location in the
        original source which produced this rule.
    glyph1: A glyph name for the "left" glyph in the pair.
    value1: A ``otTables.ValueRecord`` for positioning the left glyph.
    glyph2: A glyph name for the "right" glyph in the pair.
    value2: A ``otTables.ValueRecord`` for positioning the right glyph.
NzGAlready defined position for pair %s %s at %s; choosing the first value)rJ  r  rK  r   debug)	r    rJ   glyph1r8  glyph2r:  r   oldValueotherLocs	            r"   addGlyphPairPairPosBuilder.addGlyphPair_  sq     ??&&sD1 ~~c*HII+ %+#3DOOC "*NN3rQ   c                     U R                   R                  U R                  U R                  U R                  U R                  45        g rS   )rI  rt   r   r   s     r"   r   !PairPosBuilder.add_subtable_break{  s=    

$$$$$$$$		
rQ   c                     [         R                  X5      =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ rS   )rB   rW   rJ  rI  rU   s     r"   rW   PairPosBuilder.equals  sA      - *5#3#33*

ekk)	
rQ   c                 N   0 n[        U 5      nU R                   H8  u  p4pVX0R                  L a  UR                  5         M&  UR	                  X4XV5        M:     / nU R
                  (       a/  UR                  [        U R
                  U R                  5      5        UR                  UR                  5       5        U R                  U5      nU R                  R                  R                  S[        5       S9n	U	S:w  a+  [        R!                  S5        [#        U R                  X5        U$ )zlBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the pair positioning
    lookup.
z0fontTools.otlLib.optimize.gpos:COMPRESSION_LEVEL)defaultr   zCompacting GPOS...)r*  rI  r   r?  r<  rJ  r  buildPairPosGlyphsr   r/   rd   rH   r  r  r   r   infor   )
r    buildersr3  rN  r8  rO  r:  r/   rz  levels
             r"   r   PairPosBuilder.build  s     -d38<

4K222((*OOKE	 9C
 	??/OP**,-""9- 		!!>/1 " 
 A:HH)*499e4rQ   )rJ  rK  rI  N)r   r   r   r   r   rO   rP  rX  r   rW   r   r   rZ   rQ   r"   rG  rG  8  s&    &F+8

 rQ   rG  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r}  i  a  Builds a Single Positioning (GPOS1) lookup.

Attributes:
    font (``fontTools.TTLib.TTFont``): A font object.
    location: A string or tuple representing the location in the original
        source which produced this lookup.
    mapping: A dictionary mapping a glyph name to a ``otTables.ValueRecord``
        objects. Usually manipulated with the :meth:`add_pos` method below.
    lookupflag (int): The lookup's flag
    markFilterSet: Either ``None`` if no mark filtering set is used, or
        an integer representing the filtering set to be used for this
        lookup. If a mark filtering set is provided,
        `LOOKUP_FLAG_USE_MARK_FILTERING_SET` will be set on the lookup's
        flags.
c                 P    [         R                  XUSS5        0 U l        0 U l        g )NrF   r$   )rB   rO   rK  r   r   s      r"   rO   SinglePosBuilder.__init__  s$    t8VQ?rQ   c                     U R                  X#5      (       d#  U R                  U   n[        SU< SU< 3U5      eU(       a  X0R                  U'   XR                  U'   g)a  Add a single positioning rule.

Args:
    location: A string or tuple representing the location in the
        original source which produced this lookup.
    glyph: A glyph name.
    otValueRection: A ``otTables.ValueRecord`` used to position the
        glyph.
z.Already defined different position for glyph "z" at N)rx  rK  r   r   )r    rJ   ry  otValueRecordrW  s        r"   add_posSinglePosBuilder.add_pos  sX     ||E11~~e,H"($ 
 "/LL (urQ   c                     [        U[        5      (       d   eU R                  R                  U5      nUS L =(       d    X2:H  $ rS   )r:   r	   r   r  )r    ry  r{  curValues       r"   rx  SinglePosBuilder.can_add  s<    %----<<##E*448#44rQ   c                 l    [         R                  X5      =(       a    U R                  UR                  :H  $ rS   r  rU   s     r"   rW   SinglePosBuilder.equals  r  rQ   c                 d    [        U R                  U R                  5      nU R                  U5      $ )znBuild the lookup.

Returns:
    An ``otTables.Lookup`` object representing the single positioning
    lookup.
)buildSinglePosr   r   rd   rc   s     r"   r   SinglePosBuilder.build  s)     #4<<?	  ++rQ   )rK  r   N)r   r   r   r   r   rO   rj  rx  rW   r   r   rZ   rQ   r"   r}  r}    s!     
)*5
S,rQ   r}  c                 `    U (       d  g[         R                  " 5       n[        U 5      Ul        U$ )a  Builds a single substitution (GSUB1) subtable.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.SingleSubstBuilder` instead.

Args:
    mapping: A dictionary mapping input glyph names to output glyph names.

Returns:
    An ``otTables.SingleSubst`` object, or ``None`` if the mapping dictionary
    is empty.
N)r   SingleSubstdictr   r   r    s     r"   r"  r"    s&     >>D=DLKrQ   c                 `    U (       d  g[         R                  " 5       n[        U 5      Ul        U$ )a  Builds a multiple substitution (GSUB2) subtable.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.MultipleSubstBuilder` instead.

Example::

    # sub uni06C0 by uni06D5.fina hamza.above
    # sub uni06C2 by uni06C1.fina hamza.above;

    subtable = buildMultipleSubstSubtable({
        "uni06C0": [ "uni06D5.fina", "hamza.above"],
        "uni06C2": [ "uni06D1.fina", "hamza.above"]
    })

Args:
    mapping: A dictionary mapping input glyph names to a list of output
        glyph names.

Returns:
    An ``otTables.MultipleSubst`` object or ``None`` if the mapping dictionary
    is empty.
N)r   MultipleSubstrv  r   rw  s     r"   r  r    s(    2 D=DLKrQ   c                 `    U (       d  g[         R                  " 5       n[        U 5      Ul        U$ )a  Builds an alternate substitution (GSUB3) subtable.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.AlternateSubstBuilder` instead.

Args:
    mapping: A dictionary mapping input glyph names to a list of output
        glyph names.

Returns:
    An ``otTables.AlternateSubst`` object or ``None`` if the mapping dictionary
    is empty.
N)r   AlternateSubstrv  r   rw  s     r"   r   r   %  s(     D7mDOKrQ   c                    U (       d  g[         R                  " 5       n0 Ul        [        U R	                  5       UR
                  S9 Hx  n[         R                  " 5       nUSS Ul        [        UR                  5      S-   Ul	        X   Ul
        US   nUR                  R                  U/ 5      R                  U5        Mz     U$ )aH  Builds a ligature substitution (GSUB4) subtable.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.LigatureSubstBuilder` instead.

Example::

    # sub f f i by f_f_i;
    # sub f i by f_i;

    subtable = buildLigatureSubstSubtable({
        ("f", "f", "i"): "f_f_i",
        ("f", "i"): "f_i",
    })

Args:
    mapping: A dictionary mapping tuples of glyph names to output
        glyph names.

Returns:
    An ``otTables.LigatureSubst`` object or ``None`` if the mapping dictionary
    is empty.
Nr   r$   r   )r   LigatureSubstr  r   rg   _getLigatureSortKeyLigature	Componentr7   	CompCountLigGlyphr  rt   )r   r    r  ligaturer*  s        r"   r  r  ;  s    4 D DNW\\^1I1IJ
;;='^ !3!34q8#/]
!!*b188B K KrQ   c                     [         R                  " 5       nXsUl        Ul        SUl        Ub  X%l        SUl        Uc  Ub*  UR                  S:X  d   S5       eX5l        XEl        SUl        U$ )a  Builds an Anchor table.

This determines the appropriate anchor format based on the passed parameters.

Args:
    x (int): X coordinate.
    y (int): Y coordinate.
    point (int): Index of glyph contour point, if provided.
    deviceX (``otTables.Device``): X coordinate device table, if provided.
    deviceY (``otTables.Device``): Y coordinate device table, if provided.

Returns:
    An ``otTables.Anchor`` object.
r$   r%   z7Either point, or both of deviceX/deviceY, must be None.r   )r   AnchorXCoordinateYCoordinater  AnchorPointXDeviceTableYDeviceTable)r   ypointdeviceXdeviceYr    s         r"   buildAnchorr  i  sz     99;D)*&Dd&DK g1KK1	ED	E##KrQ   c                 R   [         R                  " 5       n/ Ul        [        XR                  S9 HT  nX   n[        U5       Vs/ s H  oeR                  U5      PM     nnUR                  R                  [        U5      5        MV     [        UR                  5      Ul
        U$ s  snf )a  Builds a base array record.

As part of building mark-to-base positioning rules, you will need to define
a ``BaseArray`` record, which "defines for each base glyph an array of
anchors, one for each mark class." This function builds the base array
subtable.

Example::

    bases = {"a": {0: a3, 1: a5}, "b": {0: a4, 1: a5}}
    basearray = buildBaseArray(bases, 2, font.getReverseGlyphMap())

Args:
    bases (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being dictionaries mapping mark class ID
        to the appropriate ``otTables.Anchor`` object used for attaching marks
        of that class.
    numMarkClasses (int): The total number of mark classes for which anchors
        are defined.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    An ``otTables.BaseArray`` object.
r   )r   	BaseArray
BaseRecordr   r   ranger  rt   buildBaseRecordr7   	BaseCount)r  numMarkClassesr   r    r  b	markClassr  s           r"   buildBaseArrayr    s    4 <<>DDOu"6"67K5:>5JK5J	55#5JKw78 8 )DNK Ls   B$c                 <    [         R                  " 5       nXl        U$ rS   )r   r  
BaseAnchorr  r    s     r"   r  r    s    ==?DOKrQ   c                 L    U (       d  g[         R                  " 5       nXl        U$ )a  Builds a component record.

As part of building mark-to-ligature positioning rules, you will need to
define ``ComponentRecord`` objects, which contain "an array of offsets...
to the Anchor tables that define all the attachment points used to attach
marks to the component." This function builds the component record.

Args:
    anchors: A list of ``otTables.Anchor`` objects or ``None``.

Returns:
    A ``otTables.ComponentRecord`` object or ``None`` if no anchors are
    supplied.
N)r   ComponentRecordLigatureAnchorr  s     r"   buildComponentRecordr    s#     D!KrQ   c                    U (       d  g[         R                  " 5       nSUl        [        U R	                  5       U5      Ul        / Ul        UR
                  R                   HE  nX   u  pE[         R                  " 5       nXFl        XVl	        UR                  R                  U5        MG     [        UR                  5      Ul        U$ )a1  Builds a cursive positioning (GPOS3) subtable.

Cursive positioning lookups are made up of a coverage table of glyphs,
and a set of ``EntryExitRecord`` records containing the anchors for
each glyph. This function builds the cursive positioning subtable.

Example::

    subtable = buildCursivePosSubtable({
        "AlifIni": (None, buildAnchor(0, 50)),
        "BehMed": (buildAnchor(500,250), buildAnchor(0,50)),
        # ...
    }, font.getReverseGlyphMap())

Args:
    attach (dict): A mapping between glyph names and a tuple of two
        ``otTables.Anchor`` objects representing entry and exit anchors.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    An ``otTables.CursivePos`` object, or ``None`` if the attachment
    dictionary was empty.
Nr$   )r   
CursivePosr  r#   rg   r   EntryExitRecordr   EntryAnchor
ExitAnchorrt   r7   EntryExitCount)attachr   r    ry  r  r  rK  s          r"   r  r    s    2 ==?DDK!&++-:DMD%%"(-  "%###C( & d223DKrQ   c                    U (       d  g[         R                  " 5       nU R                  5       n[        U5      =Ul        n[        U5      =Ul        nSUs=::  a  U::  d   e   e[        X4S-   5       Vs/ s H  oPR                  US5      PM     sn=Ul	        n[        U5      n[        U5      nUS:  a  US:  d   eUS:  a  US:  a	  SUl
        U$ US:  a  US	:  a	  SUl
        U$ S
Ul
        U$ s  snf )aW  Builds a Device record as part of a ValueRecord or Anchor.

Device tables specify size-specific adjustments to value records
and anchors to reflect changes based on the resolution of the output.
For example, one could specify that an anchor's Y position should be
increased by 1 pixel when displayed at 8 pixels per em. This routine
builds device records.

Args:
    deltas: A dictionary mapping pixels-per-em sizes to the delta
        adjustment in pixels when the font is displayed at that size.

Returns:
    An ``otTables.Device`` object if any deltas were supplied, or
    ``None`` otherwise.
Nr   r$   i   r%   ir'   r   )r   Devicerg   r
  	StartSizemaxEndSizer  r  
DeltaValueDeltaFormat)	deltasr    rg   	startSizeendSizer   deltaValuesmaxDeltaminDeltas	            r"   buildDevicer    s   " 99;D;;=D!$T*DNY Y&DL7	$W$$$$$(-i1(E%(E

4(E% DOk ;H;Hd?x#~--"}A
 K	 
B8a< K K%s   4C0c           
         [         R                  " 5       n/ Ul        [        XR                  S9 Hm  n/ nX    H<  nUR                  [        U5       Vs/ s H  ovR                  U5      PM     sn5        M>     UR                  R                  [        U5      5        Mo     [        UR                  5      Ul
        U$ s  snf )a  Builds a LigatureArray subtable.

As part of building a mark-to-ligature lookup, you will need to define
the set of anchors (for each mark class) on each component of the ligature
where marks can be attached. For example, for an Arabic divine name ligature
(lam lam heh), you may want to specify mark attachment positioning for
superior marks (fatha, etc.) and inferior marks (kasra, etc.) on each glyph
of the ligature. This routine builds the ligature array record.

Example::

    buildLigatureArray({
        "lam-lam-heh": [
            { 0: superiorAnchor1, 1: inferiorAnchor1 }, # attach points for lam1
            { 0: superiorAnchor2, 1: inferiorAnchor2 }, # attach points for lam2
            { 0: superiorAnchor3, 1: inferiorAnchor3 }, # attach points for heh
        ]
    }, 2, font.getReverseGlyphMap())

Args:
    ligs (dict): A mapping of ligature names to an array of dictionaries:
        for each component glyph in the ligature, an dictionary mapping
        mark class IDs to anchors.
    numMarkClasses (int): The number of mark classes.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    An ``otTables.LigatureArray`` object if deltas were supplied.
r   )r   LigatureArrayLigatureAttachr   r   rt   r  r  buildLigatureAttachr7   LigatureCount)r  r  r   r    r  r  	componentr  s           r"   buildLigatureArrayr    s    > DDd 4 45INNn8MN8M"MM"-8MNO #""#6w#?@	 6
 T001DK Os   B=c                     [         R                  " 5       nU  Vs/ s H  n[        U5      PM     snUl        [	        UR                  5      Ul        U$ s  snf rS   )r   r  r  r  r7   ComponentCount)r  r    r7  s      r"   r  r  C  sK    D=GHZ03ZHDd223DK Is   Ac                    [         R                  " 5       n/ Ul        [        U R	                  5       UR
                  S9 H/  nX   u  pE[        XE5      nUR                  R                  U5        M1     [        UR                  5      Ul	        U$ )a  Builds a mark array subtable.

As part of building mark-to-* positioning rules, you will need to define
a MarkArray subtable, which "defines the class and the anchor point
for a mark glyph." This function builds the mark array subtable.

Example::

    mark = {
        "acute": (0, buildAnchor(300,712)),
        # ...
    }
    markarray = buildMarkArray(marks, font.getReverseGlyphMap())

Args:
    marks (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being a tuple of mark class number and
        an ``otTables.Anchor`` object representing the mark's attachment
        point.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    An ``otTables.MarkArray`` object.
r   )
r   	MarkArray
MarkRecordr   rg   r   buildMarkRecordrt   r7   	MarkCount)ri   r   r    rk   r  r  markrecs          r"   r  r  K  sp    4 <<>DDOuzz|)=)=>!K	!)4w' ? )DNKrQ   c                     [        XU5      /$ )a	  Build a list of MarkBasePos (GPOS4) subtables.

This routine turns a set of marks and bases into a list of mark-to-base
positioning subtables. Currently the list will contain a single subtable
containing all marks and bases, although at a later date it may return the
optimal list of subtables subsetting the marks and bases into groups which
save space. See :func:`buildMarkBasePosSubtable` below.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.MarkBasePosBuilder` instead.

Example::

    # a1, a2, a3, a4, a5 = buildAnchor(500, 100), ...

    marks = {"acute": (0, a1), "grave": (0, a1), "cedilla": (1, a2)}
    bases = {"a": {0: a3, 1: a5}, "b": {0: a4, 1: a5}}
    markbaseposes = buildMarkBasePos(marks, bases, font.getReverseGlyphMap())

Args:
    marks (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being a tuple of mark class number and
        an ``otTables.Anchor`` object representing the mark's attachment
        point. (See :func:`buildMarkArray`.)
    bases (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being dictionaries mapping mark class ID
        to the appropriate ``otTables.Anchor`` object used for attaching marks
        of that class. (See :func:`buildBaseArray`.)
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A list of ``otTables.MarkBasePos`` objects.
)buildMarkBasePosSubtable)ri   r  r   s      r"   r  r  o  s    ^ %U8<==rQ   c                 L   [         R                  " 5       nSUl        [        X5      Ul        [        X5      Ul        [        U R                  5        VVs/ s H  u  pEUPM	     snn5      S-   Ul	        [        X5      Ul
        [        XR                  U5      Ul        U$ s  snnf )aj  Build a single MarkBasePos (GPOS4) subtable.

This builds a mark-to-base lookup subtable containing all of the referenced
marks and bases. See :func:`buildMarkBasePos`.

Args:
    marks (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being a tuple of mark class number and
        an ``otTables.Anchor`` object representing the mark's attachment
        point. (See :func:`buildMarkArray`.)
    bases (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being dictionaries mapping mark class ID
        to the appropriate ``otTables.Anchor`` object used for attaching marks
        of that class. (See :func:`buildBaseArray`.)
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A ``otTables.MarkBasePos`` object.
r$   )r   MarkBasePosr  r#   MarkCoverager  r  r  valuesr  BaseCoverager  r  )ri   r  r   r    r  r:  s         r"   r  r    s    * >>DDK%e6D#E4DN5<<>:>%"2>:;a?DO%e6D#E??HEDNK ;   B 
c                     [        XU5      /$ )aS  Build a list of MarkLigPos (GPOS5) subtables.

This routine turns a set of marks and ligatures into a list of mark-to-ligature
positioning subtables. Currently the list will contain a single subtable
containing all marks and ligatures, although at a later date it may return
the optimal list of subtables subsetting the marks and ligatures into groups
which save space. See :func:`buildMarkLigPosSubtable` below.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.MarkLigPosBuilder` instead.

Example::

    # a1, a2, a3, a4, a5 = buildAnchor(500, 100), ...
    marks = {
        "acute": (0, a1),
        "grave": (0, a1),
        "cedilla": (1, a2)
    }
    ligs = {
        "f_i": [
            { 0: a3, 1: a5 }, # f
            { 0: a4, 1: a5 }  # i
            ],
    #   "c_t": [{...}, {...}]
    }
    markligposes = buildMarkLigPos(marks, ligs,
        font.getReverseGlyphMap())

Args:
    marks (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being a tuple of mark class number and
        an ``otTables.Anchor`` object representing the mark's attachment
        point. (See :func:`buildMarkArray`.)
    ligs (dict): A mapping of ligature names to an array of dictionaries:
        for each component glyph in the ligature, an dictionary mapping
        mark class IDs to anchors. (See :func:`buildLigatureArray`.)
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A list of ``otTables.MarkLigPos`` objects.

)buildMarkLigPosSubtable)ri   r  r   s      r"   r  r    s    d $E:;;rQ   c                 L   [         R                  " 5       nSUl        [        X5      Ul        [        X5      Ul        [        U R                  5        VVs/ s H  u  pEUPM	     snn5      S-   Ul	        [        X5      Ul
        [        XR                  U5      Ul        U$ s  snnf )a$  Build a single MarkLigPos (GPOS5) subtable.

This builds a mark-to-base lookup subtable containing all of the referenced
marks and bases. See :func:`buildMarkLigPos`.

Args:
    marks (dict): A dictionary mapping anchors to glyphs; the keys being
        glyph names, and the values being a tuple of mark class number and
        an ``otTables.Anchor`` object representing the mark's attachment
        point. (See :func:`buildMarkArray`.)
    ligs (dict): A mapping of ligature names to an array of dictionaries:
        for each component glyph in the ligature, an dictionary mapping
        mark class IDs to anchors. (See :func:`buildLigatureArray`.)
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A ``otTables.MarkLigPos`` object.
r$   )r   
MarkLigPosr  r#   r  r  r  r  r  r  LigatureCoverager  r  )ri   r  r   r    r  r:  s         r"   r  r    s    ( ==?DDK%e6D#E4DN5<<>:>%"2>:;a?DO)$9D+D//8LDK ;r  c                     [        U [        5      (       d   e[        U[        R                  5      (       d   e[        R                  " 5       nXl        Xl        U$ rS   )r:   r;   r   r  r  r4  
MarkAnchor)classIDr  r    s      r"   r  r    sF    gs####fbii((((==?DJOKrQ   c                 <    [         R                  " 5       nXl        U$ rS   )r   r
  Mark2Anchorr  s     r"   r  r    s    >>DKrQ   c                 h    U b  U $ SnU H$  nUc  M  XB   c  M  X4U   R                  5       -  nM&     U$ r   )	getFormat)fr  r  maskr{  s        r"   _getValueFormatr  #  sD    }D!5!H&&((D  KrQ   c                    [        5       n[        SS9n[        SS9n[        U 5       H8  u  pxUR                  U5        UR	                  U5        UR	                  U5        M:     [
        R                  " 5       n	SU	l        [        X R                  5       S5      =o)l
        [        X0R                  5       S5      =o9l        [        XA5      U	l        UR                  5       U	l        UR                  5       U	l        UR#                  5       n
UR#                  5       n/ U	l        U
 H  n[
        R$                  " 5       n/ Ul        U	R$                  R)                  U5        U Hy  n[
        R&                  " 5       nU R+                  X4S5      u  nnU(       a
  [-        UUS9OS	Ul        U(       a
  [-        UUS9OS	Ul        UR&                  R)                  U5        M{     M     [3        U	R$                  5      U	l        [3        U5      U	l        U	$ )
a2  Builds a class pair adjustment (GPOS2 format 2) subtable.

Kerning tables are generally expressed as pair positioning tables using
class-based pair adjustments. This routine builds format 2 PairPos
subtables.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.ClassPairPosSubtableBuilder`
instead, as this takes care of ensuring that the supplied pairs can be
formed into non-overlapping classes and emitting individual subtables
whenever the non-overlapping requirement means that a new subtable is
required.

Example::

    pairs = {}

    pairs[(
        [ "K", "X" ],
        [ "W", "V" ]
    )] = ( buildValue(xAdvance=+5), buildValue() )
    # pairs[(... , ...)] = (..., ...)

    pairpos = buildPairPosClassesSubtable(pairs, font.getReverseGlyphMap())

Args:
    pairs (dict): Pair positioning data; the keys being a two-element
        tuple of lists of glyphnames, and the values being a two-element
        tuple of ``otTables.ValueRecord`` objects.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.
    valueFormat1: Force the "left" value records to the given format.
    valueFormat2: Force the "right" value records to the given format.

Returns:
    A ``otTables.PairPos`` object.
Tr   Fr%   r   r$   r,  srcvalueFormatN)r   r   r   r  r   r   PairPosr  r  r  ValueFormat1ValueFormat2r#   r   r   	ClassDef1	ClassDef2r   Class1RecordClass2Recordrt   r  r	   Value1Value2r7   Class1CountClass2Count)rI  r   valueFormat1valueFormat2rx   	classDef1	classDef2r7  r9  r    classes1classes2c1rec1c2rec2val1val2s                     r"   rD  rD  .  s   N uH$/I%0I5Mcc " ::<DDK'6|\\^UV'WWL$'6|\\^UV'WWL$!(5DM__&DN__&DN  "H  "HD   &B??$DB8\:JD$   ,? K   ,? K
 $$T* 	 $ 4,,-D8}DKrQ   c                 R   0 nU R                  5        HN  u  u  p4u  pVUb  UR                  5       OSnUb  UR                  5       OSnUR                  Xx40 5      n	XV4XU4'   MP     [        UR                  5       5       VVV	s/ s H  u  u  pxn	[	        XXx5      PM     sn	nn$ s  sn	nnf )a  Builds a list of glyph-based pair adjustment (GPOS2 format 1) subtables.

This organises a list of pair positioning adjustments into subtables based
on common value record formats.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.PairPosBuilder`
instead.

Example::

    pairs = {
        ("K", "W"): ( buildValue(xAdvance=+5), buildValue() ),
        ("K", "V"): ( buildValue(xAdvance=+5), buildValue() ),
        # ...
    }

    subtables = buildPairPosGlyphs(pairs, font.getReverseGlyphMap())

Args:
    pairs (dict): Pair positioning data; the keys being a two-element
        tuple of glyphnames, and the values being a two-element
        tuple of ``otTables.ValueRecord`` objects.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A list of ``otTables.PairPos`` objects.
r   )r  r  r  r   buildPairPosGlyphsSubtable)
rI  r   rw   glyphAglyphBvalAvalBformatAformatBposs
             r"   r`  r`  }  s    @ 	A*/++-&,4&*&6$.."A&*&6$.."AllG-r2!%V	 +8 *0	):):%g 	#3'C):  s   B"c                   ^ [         R                  " 5       nSUl        [        X R	                  5       S5      =o$l        [        X0R	                  5       S5      =o4l        0 nU R                  5        H-  u  u  pgu  pUR                  U/ 5      R                  XxU	45        M/     [        U R                  5        V
Vs1 s H  u  pU
iM	     snn
T5      Ul        / Ul        UR                  R                   H  n[         R                  " 5       n/ Ul        UR                  R                  U5        [!        X\   U4S jS9 Hl  u  pn[         R                  " 5       nUUl        U(       a	  [%        XS9OSUl        U(       a
  [%        UUS9OSUl        UR                  R                  U5        Mn     [+        UR                  5      Ul        M     [+        UR                  5      Ul        U$ s  snn
f )aF  Builds a single glyph-based pair adjustment (GPOS2 format 1) subtable.

This builds a PairPos subtable from a dictionary of glyph pairs and
their positioning adjustments. See also :func:`buildPairPosGlyphs`.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.PairPosBuilder` instead.

Example::

    pairs = {
        ("K", "W"): ( buildValue(xAdvance=+5), buildValue() ),
        ("K", "V"): ( buildValue(xAdvance=+5), buildValue() ),
        # ...
    }

    pairpos = buildPairPosGlyphsSubtable(pairs, font.getReverseGlyphMap())

Args:
    pairs (dict): Pair positioning data; the keys being a two-element
        tuple of glyphnames, and the values being a two-element
        tuple of ``otTables.ValueRecord`` objects.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.
    valueFormat1: Force the "left" value records to the given format.
    valueFormat2: Force the "right" value records to the given format.

Returns:
    A ``otTables.PairPos`` object.
r$   r   c                    > TU S      $ r   rZ   )r   r   s    r"   r  ,buildPairPosGlyphsSubtable.<locals>.<lambda>  s    !A$rQ   r   r  N)r   r  r  r  r  r  r  r  r  rt   r#   rg   r   PairSetr   PairValueRecordr   SecondGlyphr	   r  r  r7   PairValueCountPairSetCount)rI  r   r  r  r    rw   r  r  r  r  r   r:  ry  psrU  r  r  pvrs    `                r"   r  r    s   @ ::<DDK'6|\\^UV'WWL$'6|\\^UV'WWL$
A*/++-&,4	VR ''t(<= +8!">1">IDMDL%%ZZ\B"(7O"PF$$$&C$CO   ? J   ,? J
 %%c* #Q   2 23% && DLL)DK- #?s   9G&
c                   ^^^ / [        5       p20 0 0 spEmU R                  5        HZ  u  pg[        U5      nUR                  U/ 5      R	                  U5        UR                  US   / 5      R	                  U5        UTU'   M\     UR                  5        Hc  u  p[        U	5      [        U5      -  S:  d  M"  U	 V
s0 s H  oTU   _M
     nn
UR	                  [        UT5      5        UR                  U5        Me     UR                  5        H  u  pU Vs/ s H  oU;  d  M
  UPM     nn[        U5      S:  d  M/  0 nU H"  mUR                  UU4S jUT    5       5        M$     UR	                  [        UT5      5        UR                  U5        M     UR                  5        H7  u  pX;  d  M  U	 H  n
[        U
TU   0T5      nM     UR	                  W5        M9     UR                  U4S jS9  U$ s  sn
f s  snf )an  Builds a list of single adjustment (GPOS1) subtables.

This builds a list of SinglePos subtables from a dictionary of glyph
names and their positioning adjustments. The format of the subtables are
determined to optimize the size of the resulting subtables.
See also :func:`buildSinglePosSubtable`.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.SinglePosBuilder` instead.

Example::

    mapping = {
        "V": buildValue({ "xAdvance" : +5 }),
        # ...
    }

    subtables = buildSinglePos(pairs, font.getReverseGlyphMap())

Args:
    mapping (dict): A mapping between glyphnames and
        ``otTables.ValueRecord`` objects.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A list of ``otTables.SinglePos`` objects.
r   r  r$   c              3   0   >#    U  H  oTT   4v   M     g 7frS   rZ   )r-   r   kr  s     r"   r0   !buildSinglePos.<locals>.<genexpr>#	  s     %Kl&)nls   c                    > [        U T5      $ rS   )_getSinglePosTableKey)r.   r   s    r"   r   buildSinglePos.<locals>.<lambda>7	  s    3Ax@rQ   r   )r   r  _getSinglePosValueKeyr  rt   r7   _getSinglePosValueSizebuildSinglePosSubtabler   r  sort)r   r   r  handled	coveragesmasksry  r{  r   r   r   format1Mappingr  rg   r  f2format2Mappingr?   r  s    `            `   @r"   rr  rr    s   < #%G  "2rIf#E*S"%,,U3Q$++C0s	 ( !(v;/44q86<=fnfN=MM0JKKK ) #[[]2A'!1a2r7Q;N%%%Kil%KK MM0JKNN2 + !(+Qs,<hG MM"	 ) KK@KAMC > 3s   9G3	G8 G8c                 ^  ^ [         R                  " 5       n[        U R                  5       U5      Ul        [        [        R                  U R                  5        Vs/ s H  o3R                  5       PM     snS5      =oBl
        UR                  R                   Vs/ s H  n[        X   US9PM     snm[        U4S jT 5       5      (       a-  SUl        UR                  S:w  a  TS   Ul        U$ SUl         U$ SUl        TUl        [!        UR                  5      Ul        U$ s  snf s  snf )aD  Builds a single adjustment (GPOS1) subtable.

This builds a list of SinglePos subtables from a dictionary of glyph
names and their positioning adjustments. The format of the subtable is
determined to optimize the size of the output.
See also :func:`buildSinglePos`.

Note that if you are implementing a layout compiler, you may find it more
flexible to use
:py:class:`fontTools.otlLib.lookupBuilders.SinglePosBuilder` instead.

Example::

    mapping = {
        "V": buildValue({ "xAdvance" : +5 }),
        # ...
    }

    subtable = buildSinglePos(pairs, font.getReverseGlyphMap())

Args:
    mapping (dict): A mapping between glyphnames and
        ``otTables.ValueRecord`` objects.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A ``otTables.SinglePos`` object.
r   r  c              3   2   >#    U  H  oTS    :H  v   M     g7fr+   rZ   )r-   vvalueRecordss     r"   r0   )buildSinglePosSubtable.<locals>.<genexpr>b	  s     
6AQs   r$   Nr%   )r   	SinglePosr#   rg   r   r   r;   __or__r  r  ValueFormatr   r	   r2   r  Valuer7   
ValueCount)r  r   r    r  r  r   r   s         @r"   r  r  ;	  s   < <<>D!&++-:DM%+

FMMO<Oq[[]O<a& K"
 %%%A 		{;%L 
6
666q %aDJ K DJ
 K !
djj/K! =s   D%
D*c                     [        U [        R                  5      (       d   U 5       eU R                  R                  n[        U5      * XS      4$ r   )r:   r   r"  r   r   r7   )rv   r   r   s      r"   r  r  o	  sG    h--7x7-%%F[L(!9-..rQ   c                    [        U [        5      (       d   U 5       eS/ p!U R                  R                  5        Hb  u  p4[        U[        R
                  5      (       a  UR                  U[        U5      45        OUR                  X445        U[        U   S   -  nMd     UR                  5         UR                  SU5        [        U5      $ r   )r:   r	   __dict__r  r   r  rt   _makeDeviceTupler
   r  rg  tuple)valueRecordr  r  namer{  s        r"   r  r  u	  s    k;//<</R"++113eRYY''MM4!1%!89:MM4-(,T2155 4 KKM
MM![!=rQ   _DeviceTuplez(DeltaFormat StartSize EndSize DeltaValuec                     [        U R                  U R                  U R                  U R                  S-  (       a  S5      $ [	        U R
                  5      5      $ )Ni   rZ   )r.  r  r  r  r+  r  )devices    r"   r*  r*  	  sR      6)	  05V5F5F/G	 rQ   c                     SnU SS   H<  u  p#[        U[        5      (       a  U[        UR                  5      S-   -  nM7  US-  nM>     U$ )Nr   r$   r   )r:   r.  r7   r  )valueKeycountr:  r  s       r"   r  r  	  sN    Ea&&S&**EQJE	 
 LrQ   c                 d    [        5       nU R                  5        H  u  p#[        XU5        M     U$ )ai  Builds a positioning value record.

Value records are used to specify coordinates and adjustments for
positioning and attaching glyphs. Many of the positioning functions
in this library take ``otTables.ValueRecord`` objects as arguments.
This function builds value records from dictionaries.

Args:
    value (dict): A dictionary with zero or more of the following keys:
        - ``xPlacement``
        - ``yPlacement``
        - ``xAdvance``
        - ``yAdvance``
        - ``xPlaDevice``
        - ``yPlaDevice``
        - ``xAdvDevice``
        - ``yAdvDevice``

Returns:
    An ``otTables.ValueRecord`` object.
)r	   r  r%  )r{  r    r  r  s       r"   
buildValuer5  	  s,    , =D KrQ   c                 *   U (       d  g[         R                  " 5       n[        U R                  5       U5      Ul        UR                  R
                   Vs/ s H  n[        X   5      PM     snUl        [        UR                  5      Ul	        U$ s  snf )a  Builds an AttachList subtable.

A GDEF table may contain an Attachment Point List table (AttachList)
which stores the contour indices of attachment points for glyphs with
attachment points. This routine builds AttachList subtables.

Args:
    attachPoints (dict): A mapping between glyph names and a list of
        contour indices.

Returns:
    An ``otTables.AttachList`` object if attachment points are supplied,
        or ``None`` otherwise.
N)
r   
AttachListr#   rg   r   r   buildAttachPointAttachPointr7   r   )attachPointsr   r    r   s       r"   buildAttachListr;  	  st     ==?D!,"3"3"5x@DMCG==CWCWXCWa(9CWXD$**+DOK Ys   Bc                     U (       d  g [         R                  " 5       n[        [        U 5      5      Ul        [        UR                  5      Ul        U$ rS   )r   r9  r   r   
PointIndexr7   
PointCount)pointsr    s     r"   r8  r8  	  s;     >>DS[)DO$//*DOKrQ   c                     [         R                  " 5       n[        U [        5      (       a  SUl        U u  Ul        Ul        U$ SUl        Xl        U$ )Nr   r$   )r   
CaretValuer:   r+  r  
CoordinateDeviceTable)coordr    s     r"   buildCaretValueForCoordrE  	  sL     ==?D%,1)) K KrQ   c                 J    [         R                  " 5       nSUl        Xl        U$ )Nr%   )r   rA  r  CaretValuePoint)r  r    s     r"   buildCaretValueForPointrH  	  s    ==?DDK KrQ   c           
         U (       a  [        U R                  5       5      O	[        5       nU(       a  UR                  UR                  5       5        U Vs0 s H-  oD[        U R	                  U5      UR	                  U5      5      _M/     nnUR                  5        VVs0 s H  u  pFUc  M
  XF_M     nnnU(       d  g[        R                  " 5       n[        UR                  5       U5      Ul	        UR                  R                   Vs/ s H  oEU   PM	     snUl        [        UR                  5      Ul        U$ s  snf s  snnf s  snf )a@  Builds a ligature caret list table.

Ligatures appear as a single glyph representing multiple characters; however
when, for example, editing text containing a ``f_i`` ligature, the user may
want to place the cursor between the ``f`` and the ``i``. The ligature caret
list in the GDEF table specifies the position to display the "caret" (the
character insertion indicator, typically a flashing vertical bar) "inside"
the ligature to represent an insertion point. The insertion positions may
be specified either by coordinate or by contour point.

Example::

    coords = {
        "f_f_i": [300, 600] # f|fi cursor at 300 units, ff|i cursor at 600.
    }
    points = {
        "c_t": [28] # c|t cursor appears at coordinate of contour point 28.
    }
    ligcaretlist = buildLigCaretList(coords, points, font.getReverseGlyphMap())

Args:
    coords: A mapping between glyph names and a list of coordinates for
        the insertion point of each ligature component after the first one.
    points: A mapping between glyph names and a list of contour points for
        the insertion point of each ligature component after the first one.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns:
    A ``otTables.LigCaretList`` object if any carets are present, or
        ``None`` otherwise.N)r   rg   r  buildLigGlyphr  r  r   LigCaretListr#   r   r   r  r7   LigGlyphCount)coordsr?  r   r   r   caretsr7  r    s           r"   buildLigCaretListrO  	  s    @ $*SsuFfkkm$FLMfvzz!}fjjm<<fFM%||~?~tqdad~F???D!&++-:DM(,(<(<=(<1AY(<=DMT]]+DK N?
 >s   4D:	D?+D?Ec                    / nU (       a6  [        U S S9n UR                  U  Vs/ s H  n[        U5      PM     sn5        U(       a4  UR                  [        U5       Vs/ s H  n[        U5      PM     sn5        U(       d  g [        R
                  " 5       nX%l        [        UR                  5      Ul        U$ s  snf s  snf )Nc                 :    [        U [        5      (       a  U S   $ U $ r   )r:   r+  )r7  s    r"   r  buildLigGlyph.<locals>.<lambda>%
  s    jE6J6Jad.QPQ.QrQ   r   )	r   r  rE  rH  r   r  rA  r7   
CaretCount)rM  r?  rN  r7  rw   r    s         r"   rJ  rJ  !
  s    F$QR6B6a.q16BC6&>J>a.q1>JK;;=DO$//*DOK CJs   B:B?c                     U (       d  g[         R                  " 5       nSUl        U  Vs/ s H  n[        X15      PM     snUl        [        UR                  5      Ul        U$ s  snf )a  Builds a mark glyph sets definition table.

OpenType Layout lookups may choose to use mark filtering sets to consider
or ignore particular combinations of marks. These sets are specified by
setting a flag on the lookup, but the mark filtering sets are defined in
the ``GDEF`` table. This routine builds the subtable containing the mark
glyph set definitions.

Example::

    set0 = set("acute", "grave")
    set1 = set("caron", "grave")

    markglyphsets = buildMarkGlyphSetsDef([set0, set1], font.getReverseGlyphMap())

Args:

    markSets: A list of sets of glyphnames.
    glyphMap: a glyph name to ID map, typically returned from
        ``font.getReverseGlyphMap()``.

Returns
    An ``otTables.MarkGlyphSetsDef`` object.
Nr$   )r   MarkGlyphSetsDefMarkSetTableFormatr#   r   r7   MarkSetCount)markSetsr   r    ms       r"   buildMarkGlyphSetsDefrZ  1
  sW    2  DD9ABA]1/BDMDMM*DK Cs   A"c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r   iS
  z$Helper for building ClassDef tables.c                 <    [        5       U l        0 U l        Xl        g rS   )r   classes_glyphs_
useClass0_)r    r   s     r"   rO   ClassDefBuilder.__init__V
  s    #rQ   c                     [        U[        [        45      (       a  [        U5      n[	        U5      nXR
                  ;   a  gU H  nX R                  ;   d  M    g   g)NTF)r:   r   	frozensetr   r+  r]  r^  r    r   ry  s      r"   r   ClassDefBuilder.canAdd[
  sO    fsI.//F^Fv]]"E$  rQ   c                 (   [        U[        [        45      (       a  [        U5      n[	        U5      nXR
                  ;   a  g U R
                  R                  U5        U H0  nX R                  ;   a  [        SU S3S 5      eXR                  U'   M2     g )NzGlyph z is already present in class.)	r:   r   rb  r   r+  r]  r   r^  r   rc  s      r"   r   ClassDefBuilder.addf
  s    fsI.//F^Fv]]"&!E$&UG#@A4  #)LL rQ   c                     [        U R                  S S9nU R                  (       d  UR                  S[	        5       5        U$ )Nc                     [        U 5      * U 4$ rS   r   )r   s    r"   r  )ClassDefBuilder.classes.<locals>.<lambda>
  s    s1vgq\rQ   r   r   )r   r]  r_  rg  rb  )r    r  s     r"   r   ClassDefBuilder.classest
  s1     +ABMM!Y[)rQ   c                     0 n[        U R                  5       5       H  u  p#US:X  a  M  U H  nX!U'   M	     M     [        R                  " 5       nXl        U$ r   )r6  r   r   r2  r3  )r    glyphClassesr  r   ry  classDefs         r"   r   ClassDefBuilder.build
  sR    (8OG!|&-U#    9
 ;;=)rQ   )r]  r^  r_  N)r   r   r   r   r   rO   r   r   r   r   r   rZ   rQ   r"   r   r   S
  s    .$
	)$	rQ   r   i   ic                 *   [         R                  " S5      U S'   [        R                  " 5       =o`S   l        [        XXES9Ul        [        XXES9u  pxU(       d  SUl        OSUl        [        X!XUS9n	X-   nU S   R                  R                  5         [        R                  " 5       n
Xzl        SUl        Xl        [!        U5      Ul        SUl        S	Ul        U(       a2  [        R&                  " 5       nXl        Xl        [!        U5      Ul        g	g	)
a  Add a 'STAT' table to 'ttFont'.

'axes' is a list of dictionaries describing axes and their
values.

Example::

    axes = [
        dict(
            tag="wght",
            name="Weight",
            ordering=0,  # optional
            values=[
                dict(value=100, name='Thin'),
                dict(value=300, name='Light'),
                dict(value=400, name='Regular', flags=0x2),
                dict(value=900, name='Black'),
            ],
        )
    ]

Each axis dict must have 'tag' and 'name' items. 'tag' maps
to the 'AxisTag' field. 'name' can be a name ID (int), a string,
or a dictionary containing multilingual names (see the
addMultilingualName() name table method), and will translate to
the AxisNameID field.

An axis dict may contain an 'ordering' item that maps to the
AxisOrdering field. If omitted, the order of the axes list is
used to calculate AxisOrdering fields.

The axis dict may contain a 'values' item, which is a list of
dictionaries describing AxisValue records belonging to this axis.

Each value dict must have a 'name' item, which can be a name ID
(int), a string, or a dictionary containing multilingual names,
like the axis name. It translates to the ValueNameID field.

Optionally the value dict can contain a 'flags' item. It maps to
the AxisValue Flags field, and will be 0 when omitted.

The format of the AxisValue is determined by the remaining contents
of the value dictionary:

If the value dict contains a 'value' item, an AxisValue record
Format 1 is created. If in addition to the 'value' item it contains
a 'linkedValue' item, an AxisValue record Format 3 is built.

If the value dict contains a 'nominalValue' item, an AxisValue
record Format 2 is built. Optionally it may contain 'rangeMinValue'
and 'rangeMaxValue' items. These map to -Infinity and +Infinity
respectively if omitted.

You cannot specify Format 4 AxisValue tables this way, as they are
not tied to a single axis, and specify a name for a location that
is defined by multiple axes values. Instead, you need to supply the
'locations' argument.

The optional 'locations' argument specifies AxisValue Format 4
tables. It should be a list of dicts, where each dict has a 'name'
item, which works just like the value dicts above, an optional
'flags' item (defaulting to 0x0), and a 'location' dict. A
location dict key is an axis tag, and the associated value is the
location on the specified axis. They map to the AxisIndex and Value
fields of the AxisValueRecord.

Example::

    locations = [
        dict(name='Regular ABCD', location=dict(wght=300, ABCD=100)),
        dict(name='Bold ABCD XYZ', location=dict(wght=600, ABCD=200)),
    ]

The optional 'elidedFallbackName' argument can be a name ID (int),
a string, a dictionary containing multilingual names, or a list of
STATNameStatements. It translates to the ElidedFallbackNameID field.

The 'ttFont' argument must be a TTFont instance that already has a
'name' table. If a 'STAT' table already exists, it will be
overwritten by the newly created one.
STATwindowsmac)windowsNamesmacNamesi  i  r-  r'   r   N)r   newTabler   rp  rK   _addNameElidedFallbackNameID_buildAxisRecordsVersion_buildAxisValuesFormat4namesr  AxisRecordArrayAxisDesignAxisRecordSizeDesignAxisRecordr7   DesignAxisCountAxisValueCountAxisValueArray	AxisValue)ttFontaxesrK  elidedFallbackNamert  ru  	statTableaxisRecords
axisValuesmultiAxisValuesaxisRecordArrayaxisValueArrays               r"   buildStatTabler  
  s	   h ^^F+F6N')wwy0Iv$%-L&I"
 0<K &	 '	1V
 %1

6N ((*O&%&I"!0 #K 0I I#I**,#- #1 #&z?	  rQ   c           	         / n/ n[        U 5       GHW  u  pg[        R                  " 5       nUS   Ul        [	        XS   SX#S9Ul        UR                  SU5      Ul        UR                  U5        UR                  SS5       H  n	[        R                  " 5       n
Xjl
        U	R                  SS	5      U
l        [	        XS   X#S9U
l        S
U	;   a*  U	S
   U
l        SU	;   a  SU
l        U	S   U
l        OaSU
l        OYSU	;   aH  SU
l        U	S   U
l        U	R                  S["        5      U
l        U	R                  S[&        5      U
l        O[+        S5      eUR                  U
5        M     GMZ     XE4$ )Ntagr-     rq  orderingr  rZ   r=   r   r{  linkedValuer   r$   nominalValuer%   rangeMinValuerangeMaxValuez$Can't determine format for AxisValue)r6  r   
AxisRecordAxisTagrw  
AxisNameIDr  AxisOrderingrt   r  	AxisIndexFlagsValueNameIDr%  r  LinkedValueNominalValueAXIS_VALUE_NEGATIVE_INFINITYRangeMinValueAXIS_VALUE_POSITIVE_INFINITYRangeMaxValuer   )r  r  rt  ru  r  r  axisRecordIndexaxisDictaxisaxisVal
axisValRecs              r"   ry  ry    sn   KJ%.t_!}}"V$c<
 %LL_E4 ||Hb1GJ#2 &{{7A6J%-&J" '!#*7#3
  G+()J%-4]-CJ*()J%7*$%
!*1.*A
'+2;;#%A,
( ,3;;#%A,
( !!GHHj)7 2 &5J ""rQ   c                    0 n[        U5       H  u  pgXeUS   '   M     / nU  H  n	[        R                  " 5       n
SU
l        [	        X)S   X4S9U
l        U	R                  SS5      U
l        / nU	S   R                  5        H:  u  p[        R                  " 5       nX\   Ul
        Xl        UR                  U5        M<     UR                  S S	9  [        U5      U
l        Xl	        UR                  U
5        M     U$ )
Nr  r&   r-  rq  r=   r   rJ   c                     U R                   $ rS   )r  )avrs    r"   r  )_buildAxisValuesFormat4.<locals>.<lambda>P  s    cmmrQ   r   )r6  r   r  r  rw  r  r  r  r  AxisValueRecordr  r%  rt   r  r7   	AxisCount)rK  r  r  rt  ru  axisTagToIndexr  r  r  axisLocationDictr  axisValueRecordsr  r{  r  s                  r"   r{  r{  =  s    N%.t_!*9x' &5 J%\\^

!)V,l"

 ,//;
*:6<<>JC$$&C*/CMI##C(	 ?
 	";<"#34
%5"*%! &" rQ   c                    U S   n[        U[        5      (       a  U$ [        U[        5      (       a
  [        US9nO[        U[        5      (       a  UnO[        U[        5      (       ax  UR                  5       nU H`  n[        U[        5      (       a?  UR                  UR                  UUR                  UR                  UR                  5        MW  [        S5      e   U$ [        S5      eUR                  X`X4US9$ )Nr-  )enz*value must be a list of STATNameStatementsz$value must be int, str, dict or list)r  rr  rs  	minNameID)r:   r;   r	  rv  r  _findUnusedNameIDr   setNamestring
platformID	platEncIDlangID	TypeErroraddMultilingualName)	r  r{  r  rr  rs  	nameTabler|  nameID
nameRecords	            r"   rw  rw  W  s    vI%%	E4	 	 	E4	 	 ,,.J*&788!!%%))((%%   LMM   >??((g) )  rQ   c                 2   U R                  5       n[        R                  " S5      =U S'   n[        R                  " 5       =Ul        nSUl        UR                  5         [        U5      Ul	        [        UUUUU5      Ul        [        UUUUU	U
5      Ul        g)a  
Add a 'MATH' table to 'ttFont'.

'constants' is a dictionary of math constants. The keys are the constant
names from the MATH table specification (with capital first letter), and the
values are the constant values as numbers.

'italicsCorrections' is a dictionary of italic corrections. The keys are the
glyph names, and the values are the italic corrections as numbers.

'topAccentAttachments' is a dictionary of top accent attachments. The keys
are the glyph names, and the values are the top accent horizontal positions
as numbers.

'extendedShapes' is a set of extended shape glyphs.

'mathKerns' is a dictionary of math kerns. The keys are the glyph names, and
the values are dictionaries. The keys of these dictionaries are the side
names ('TopRight', 'TopLeft', 'BottomRight', 'BottomLeft'), and the values
are tuples of two lists. The first list contains the correction heights as
numbers, and the second list contains the kern values as numbers.

'minConnectorOverlap' is the minimum connector overlap as a number.

'vertGlyphVariants' is a dictionary of vertical glyph variants. The keys are
the glyph names, and the values are tuples of glyph name and full advance height.

'horizGlyphVariants' is a dictionary of horizontal glyph variants. The keys
are the glyph names, and the values are tuples of glyph name and full
advance width.

'vertGlyphAssembly' is a dictionary of vertical glyph assemblies. The keys
are the glyph names, and the values are tuples of assembly parts and italics
correction. The assembly parts are tuples of glyph name, flags, start
connector length, end connector length, and full advance height.

'horizGlyphAssembly' is a dictionary of horizontal glyph assemblies. The
keys are the glyph names, and the values are tuples of assembly parts
and italics correction. The assembly parts are tuples of glyph name, flags,
start connector length, end connector length, and full advance width.

Where a number is expected, an integer or a float can be used. The floats
will be rounded.

Example::

    constants = {
        "ScriptPercentScaleDown": 70,
        "ScriptScriptPercentScaleDown": 50,
        "DelimitedSubFormulaMinHeight": 24,
        "DisplayOperatorMinHeight": 60,
        ...
    }
    italicsCorrections = {
        "fitalic-math": 100,
        "fbolditalic-math": 120,
        ...
    }
    topAccentAttachments = {
        "circumflexcomb": 500,
        "acutecomb": 400,
        "A": 300,
        "B": 340,
        ...
    }
    extendedShapes = {"parenleft", "parenright", ...}
    mathKerns = {
        "A": {
            "TopRight": ([-50, -100], [10, 20, 30]),
            "TopLeft": ([50, 100], [10, 20, 30]),
            ...
        },
        ...
    }
    vertGlyphVariants = {
        "parenleft": [("parenleft", 700), ("parenleft.size1", 1000), ...],
        "parenright": [("parenright", 700), ("parenright.size1", 1000), ...],
        ...
    }
    vertGlyphAssembly = {
        "braceleft": [
            (
                ("braceleft.bottom", 0, 0, 200, 500),
                ("braceleft.extender", 1, 200, 200, 200)),
                ("braceleft.middle", 0, 100, 100, 700),
                ("braceleft.extender", 1, 200, 200, 200),
                ("braceleft.top", 0, 200, 0, 500),
            ),
            100,
        ],
        ...
    }
MATHi   N)rI   r   rv  r   r  rK   rz  r  _buildMathConstantsMathConstants_buildMathGlyphInfoMathGlyphInfo_buildMathVariantsMathVariants)r  	constantsitalicsCorrectionstopAccentAttachmentsextendedShapes	mathKernsminConnectorOverlapvertGlyphVariantshorizGlyphVariantsvertGlyphAssemblyhorizGlyphAssemblyr   mathrK   s                 r"   buildMathTabler  u  s    T ((*H!NN622F6NT"DJEM	-i8E-E ,ErQ   c                 r   U (       d  g [         R                  " 5       nUR                  5        H  n[        U R	                  UR
                  S5      5      nUR                  (       a6  [        UR                  [         R                  5      (       d   e[        U5      n[        XR
                  U5        M     U$ r   )r   r  getConvertersr   r  r-  
tableClass
issubclassMathValueRecord_mathValueRecordr%  )r  mathConstantsconvr{  s       r"   r  r    s    $$&M++-	dii34??door/A/ABBBB$U+Eyy%0 . rQ   c                 ^   [        X1X$/5      (       d  g [        R                  " 5       nUR                  5         U(       a  [	        UR                  5       U 5      n[        R                  " 5       Ul        XeR                  l        [        UR                  5      UR                  l
        UR                   Vs/ s H  n[        X   5      PM     snUR                  l        U(       a  [	        UR                  5       U 5      n[        R                  " 5       Ul        XeR                  l        [        UR                  5      UR                  l        UR                   Vs/ s H  n[        X'   5      PM     snUR                  l        U(       a  [	        X05      Ul        U(       Gau  [	        UR                  5       U 5      n[        R$                  " 5       Ul        XeR$                  l        [        UR                  5      UR$                  l        / UR$                  l        UR                   H  n[        R,                  " 5       n	S H  n
XU   ;   d  M  XH   U
   u  p[        U5      [        U5      S-
  :X  d   e[        R.                  " 5       n[        U5      Ul        U Vs/ s H  n[        U5      PM     snUl        U Vs/ s H  n[        U5      PM     snUl        [7        X S3U5        M     UR$                  R*                  R9                  U	5        M     U$ s  snf s  snf s  snf s  snf )N>   TopLeftTopRight
BottomLeftBottomRightr$   MathKern)r   r   r  r  r#   rg   MathItalicsCorrectionInfor   r7   r   ItalicsCorrectionCountr  ItalicsCorrectionMathTopAccentAttachmentTopAccentCoverageTopAccentAttachmentCountTopAccentAttachmentExtendedShapeCoverageMathKernInfoMathKernCoverageMathKernCountMathKernInfoRecordsMathKernInfoRecordr  HeightCountCorrectionHeight	KernValuer%  rt   )r   r  r  r  r  ra  rx   nry  recordsidecorrectionHeights
kernValueskernhr  s                   r"   r  r    s    4HTUUD !3!8!8!:HE)+)E)E)G&2:&&/@CHOO@T&&==E__<
=L/23_<
&&8  !5!:!:!<hG')'A'A'C$9A$$6@CHOO@T$$=?G<
?N!145<
$$8 %2>%L" !18<OO--5**-hoo*>'02-__E**,FLU++4=4DT4J1%01S_q5HHHH;;=D'*+<'=D$5F-5F(+5F-D) DN%N:a&6q&9:%NDNFfH$5t< M 1188@ % KK<
<
*- &Os   6LL L% L*c                 "   [        X#XE/5      (       d  g [        R                  " 5       nUR                  5         Xl        U(       d  U(       a  [        U UU5      u  Ul        Ul        U(       d  U(       a  [        U UU5      u  Ul        Ul	        U$ rS   )
r   r   r  r  MinConnectorOverlap_buildMathGlyphConstructionVertGlyphCoverageVertGlyphConstructionHorizGlyphCoverageHorizGlyphConstruction)r   r  r  r  r  r  variantss          r"   r  r  @  s     	0AV   H#6 -'!! 	C"H$B /'"" 	E#X%D OrQ   c                 V   [        5       nU(       a  UR                  UR                  5       5        U(       a  UR                  UR                  5       5        [        X05      n/ nUR                   GH  n[
        R                  " 5       nUR                  5         U(       aq  Xa;   al  [        X   5      Ul	        / Ul
        X    HK  u  p[
        R                  " 5       n
Xl        [        U	5      U
l        UR                  R                  U
5        MM     U(       a  Xb;   a  X&   u  p[
        R                  " 5       Ul        [!        U5      UR                  l        [        U5      UR                  l        / UR                  l        U H  nUu  pnnn	[
        R(                  " 5       n
Xl        [-        U5      U
l        [        U5      U
l        [        U5      U
l        [        U	5      U
l        UR                  R&                  R                  U
5        M     UR                  U5        GM     XE4$ rS   )r   r  rg   r#   r   r   MathGlyphConstructionr  r7   VariantCountMathGlyphVariantRecordVariantGlyphr   AdvanceMeasurementrt   GlyphAssemblyr  r  	PartCountPartRecordsGlyphPartRecordry  r;   	PartFlagsStartConnectorLengthEndConnectorLengthFullAdvance)r   r   
assembliesr   rx   constructions	glyphNameconstructionvariantNameadvancer  partsicpart	part_namer=   startends                     r"   r  r  g  s   UFhmmo&joo'(V.HM__	//1%%'	-(+H,?(@L%24L/(0(;$224&1#,3G,<)33::6B	 )< )1"-IE)+)9)9);L&;KB;OL&&836u:L&&057L&&28<5	%g++-(#&u: .5en+,3CL)%,W%5"**66==fE  	\*; %> ""rQ   c                 P    [         R                  " 5       n[        U 5      Ul        U$ rS   )r   r  r   r%  )r{  value_records     r"   r  r    s"    %%'L LrQ   r+   )NNNr,  )Nr%   TT)TT)r   TT)
NNNNNr   NNNN)pcollectionsr   r   r  osfontTools.misc.fixedToolsr   fontTools.misc.roundToolsr   	fontToolsr   fontTools.ttLib.tablesr   r   fontTools.ttLib.tables.otBaser	   r
   r   r   r   r   fontTools.feaLib.astr   fontTools.otlLib.optimize.gposr   r   fontTools.otlLib.errorr   	functoolsr   loggingr   	getLoggerr   r   r#   LOOKUP_FLAG_RIGHT_TO_LEFTLOOKUP_FLAG_IGNORE_BASE_GLYPHSLOOKUP_FLAG_IGNORE_LIGATURESLOOKUP_FLAG_IGNORE_MARKSr9   r@   objectrB   r   r   r   r   rD  r  r  r  r  r  r  r  r  r  r*  rG  r}  r"  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rD  r`  r  rr  r  r  r  r.  r*  r  r5  r;  r8  rE  rH  rO  rJ  rZ  r   r  r  r  ry  r{  rw  r  r  r  r  r  r  rZ   rQ   r"   <module>r/     s   /  	 2 -  1  * 2 4    !$N # !' % ! %+ "6r`
F `
F.QM .Qb<$&OP</ /d`
] `
F*3 *ZM5 M`+P= +P\#N= #NL2' 2'jF, F,RA, A,HE' E'P6] 6r+N +N\=)& =)@t] tn;,} ;,B*@,(\>!H,&R$N'T!H/>d>2<j<L^)X=@Od1h/ .*TU>0
+\ D<f <~  ,K< +J;  UYy3x(#V4@ @F7t$N(#VrQ   