Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3 2øªjc£ã @s�ddlmZmZddlZddlmZddlmZddlm Z ddl m Z m Z mZmZddlmZddlmZdd lmZmZmZdd lmZdd lmZddlZddlZejeƒZd d „Z dZ!dZ"dZ#dZ$dZ%d—dd„Z&Gdd„de'ƒZ(Gdd„de(ƒZ)Gdd„dedddddgƒƒZ*Gdd „d ƒZ+Gd!d"„d"e(ƒZ,Gd#d$„d$e,ƒZ-Gd%d&„d&e,ƒZ.Gd'd(„d(e(ƒZ/Gd)d*„d*e(ƒZ0Gd+d,„d,e(ƒZ1Gd-d.„d.e(ƒZ2Gd/d0„d0e(ƒZ3Gd1d2„d2e(ƒZ4Gd3d4„d4e(ƒZ5Gd5d6„d6e(ƒZ6Gd7d8„d8e'ƒZ7Gd9d:„d:e(ƒZ8Gd;d<„d„Z:d?d@„Z;dAdB„Zd˜dGdH„Z?dIdJ„Z@dKdL„ZAdMdN„ZBdOdP„ZCdQdR„ZDdSdT„ZEdUdV„ZFdWdX„ZGdYdZ„ZHd[d\„ZId]d^„ZJd_d`„ZKdadb„ZLdcdd„ZMdedf„ZNd™dgdh„ZOdidj„ZPdšdkdl„ZQdmdn„ZRdodp„ZSdqdr„ZTdsdt„ZUedudvƒZVdwdx„ZWdydz„ZXd{d|„ZYd}d~„ZZdd€„Z[d�d‚„Z\dƒd„„Z]d…d†„Z^d‡dˆ„Z_d‰dŠ„Z`Gd‹dŒ„dŒe'ƒZaed›dƒZbedŽdƒZcdœd�d�„Zdd‘d’„Zed“d”„Zfd�d•d–„ZgdS)žé)Ú namedtupleÚ OrderedDictN)Ú fixedToFloat)ÚttLib)ÚotTables)Ú ValueRecordÚvalueRecordFormatDictÚ OTTableWriterÚCountReference)ÚotBase)ÚSTATNameStatement)ÚGPOS_COMPACT_MODE_DEFAULTÚGPOS_COMPACT_MODE_ENV_KEYÚcompact_lookup)ÚOpenTypeLibError)ÚreducecCs$|sdStjƒ}t||jd�|_|S)aBuilds a coverage table. Coverage tables (as defined in the `OpenType spec `_) 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)Úkey)ÚotÚCoverageÚsortedÚ __getitem__Úglyphs)rÚglyphMapÚself©rú=/tmp/pip-build-_d5lkt3n/fonttools/fontTools/otlLib/builder.pyÚ buildCoverages rééééécs̈dkr dSdd„ˆDƒ‰ˆs"dSt‡fdd„ˆDƒƒsRtdtdd„ˆDƒƒƒ‚tjƒ}ˆdj|_||_ˆ|_t|jƒ|_ |dk r®|jt O_t |t ƒs¦t|ƒ‚||_ n|jt @dksÈtd |ƒ‚|S) aTurns a collection of rules into a lookup. A Lookup (as defined in the `OpenType Spec `_) 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. NcSsg|]}|dk r|‘qS)Nr)Ú.0Ústrrrú bszbuildLookup..c3s|]}|jˆdjkVqdS)rN)Ú LookupType)r"Út)Ú subtablesrrú fszbuildLookup..z3all subtables must have the same LookupType; got %scSsg|] }|j‘qSr)r%)r"r&rrrr$hsrz]if markFilterSet is None, flags must not set LOOKUP_FLAG_USE_MARK_FILTERING_SET; flags=0x%04x)ÚallÚAssertionErrorÚreprrZLookupr%Z LookupFlagZSubTableÚlenZ SubTableCountÚ"LOOKUP_FLAG_USE_MARK_FILTERING_SETÚ isinstanceÚintZMarkFilteringSet)r'ÚflagsÚ markFilterSetrr)r'rÚ buildLookupBs,  r2c@speZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„ZdS)Ú LookupBuilderZSUBTABLE_BREAKcCsF||_|jƒ|_||_|||_|_d|_d|_d|_|dksBt ‚dS)NrÚGPOSÚGSUB)r4r5) ÚfontZgetReverseGlyphMaprÚlocationÚtableÚ lookup_typeÚ lookupflagr1Ú lookup_indexr*)rr6r7r8r9rrrÚ__init__~s zLookupBuilder.__init__cCs0t||jƒo.|j|jko.|j|jko.|j|jkS)N)r.Ú __class__r8r:r1)rÚotherrrrÚequalsˆs   zLookupBuilder.equalscCsiS)z?Infers glyph glasses for the GDEF table, such as {"cedilla":3}.r)rrrrÚinferGlyphClasses�szLookupBuilder.inferGlyphClassescCsiS)z$Helper for building 'aalt' features.r)rrrrÚgetAlternateGlyphs”sz LookupBuilder.getAlternateGlyphscCst||j|jƒS)N)r2r:r1)rr'rrrÚ buildLookup_˜szLookupBuilder.buildLookup_cCsFi}x {"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Úkeysr6Z getGlyphIDr,)rÚmarksÚidsÚmarkZ markClassNameZ _markAnchorrrrÚbuildMarkClasses_›s  zLookupBuilder.buildMarkClasses_cCs>t|ƒ|_g|_x(t|ƒD]}t||jƒ}|jj|ƒqWdS)N)r,ÚBacktrackGlyphCountZBacktrackCoverageÚreversedrrÚappend)rÚprefixÚsubtableÚpÚcoveragerrrÚsetBacktrackCoverage_©s   z#LookupBuilder.setBacktrackCoverage_cCs:t|ƒ|_g|_x$|D]}t||jƒ}|jj|ƒqWdS)N)r,ÚLookAheadGlyphCountZLookAheadCoveragerrrJ)rÚsuffixrLÚsrNrrrÚsetLookAheadCoverage_°s    z#LookupBuilder.setLookAheadCoverage_cCs:t|ƒ|_g|_x$|D]}t||jƒ}|jj|ƒqWdS)N)r,ÚInputGlyphCountZ InputCoveragerrrJ)rrrLÚgrNrrrÚsetInputCoverage_·s    zLookupBuilder.setInputCoverage_cCs:t|ƒ|_g|_x$|D]}t||jƒ}|jj|ƒqWdS)N)r,Ú GlyphCountrrrrJ)rrrLrUrNrrrÚ setCoverage_¾s    zLookupBuilder.setCoverage_csTig}x6|D].}|d|jkr*|jiƒq |||d|<q W‡fdd„|Dƒ}|S)Nrrcsg|] }ˆ|ƒ‘qSrr)r"rR)Úklassrrr$Ìsz7LookupBuilder.build_subst_subtables..éÿÿÿÿ)ÚSUBTABLE_BREAK_rJ)rÚmappingrYZ substitutionsrr'r)rYrÚbuild_subst_subtablesÅs  z#LookupBuilder.build_subst_subtablescCstjtd|ƒƒdS)zóAdd 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)rr7rrrÚadd_subtable_breakÏsz LookupBuilder.add_subtable_breakN)Ú__name__Ú __module__Ú __qualname__r[r<r?r@rArBrGrOrSrVrXr]r`rrrrr3{s  r3c@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) ÚAlternateSubstBuildera§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. cCstj|||ddƒtƒ|_dS)Nr5é)r3r<rÚ alternates)rr6r7rrrr<õszAlternateSubstBuilder.__init__cCstj||ƒo|j|jkS)N)r3r?rf)rr>rrrr?ùszAlternateSubstBuilder.equalscCs|j|jtƒ}|j|ƒS)z’Build the lookup. Returns: An ``otTables.Lookup`` object representing the alternate substitution lookup. )r]rfÚbuildAlternateSubstSubtablerB)rr'rrrÚbuildüs zAlternateSubstBuilder.buildcCs|jS)N)rf)rrrrrAsz(AlternateSubstBuilder.getAlternateGlyphscCs|j|j|j|f<dS)N)r[rf)rr7rrrr` sz(AlternateSubstBuilder.add_subtable_breakN) rarbrcÚ__doc__r<r?rhrAr`rrrrrdÞs  rdc@seZdZedd„ƒZdS)ÚChainContextualRulecCs |jtjkS)N)rKr3r[)rrrrÚis_subtable_breaksz%ChainContextualRule.is_subtable_breakN)rarbrcÚpropertyrkrrrrrjsrjrKrrQÚlookupsc@sDeZdZdd„Zdd„Zedd„ƒZedd„ƒZd d „Zd d „Z d S)ÚChainContextualRulesetcCs g|_dS)N)Úrules)rrrrr<szChainContextualRuleset.__init__cCs|jj|ƒdS)N)rorJ)rÚrulerrrÚaddRuleszChainContextualRuleset.addRulecCs4x.|jD]$}t|jƒdks(t|jƒdkrdSqWdS)NrTF)ror,rKrQ)rrprrrÚhasPrefixOrSuffixs z(ChainContextualRuleset.hasPrefixOrSuffixcCsDx>|jD]4}x.|j|j|jfD]}tdd„|DƒƒrdSqWqWdS)Ncss|]}t|ƒdkVqdS)rN)r,)r"Úxrrrr(-sz.TF)rorKrrQÚany)rrprNrrrÚhasAnyGlyphClasses's   z)ChainContextualRuleset.hasAnyGlyphClassesc Csdd\}}}g}xP|||gD]B}g}x|jD]}|j||ƒq*W|j|ƒ}|sRdS|j|ƒqW|S)Nrrr)rrr)rorJÚ_classBuilderForContext) rÚPREFIXZGLYPHSZSUFFIXZclassDefBuildersÚixÚcontextÚrÚclassesrrrÚformat2ClassDefs1s   z'ChainContextualRuleset.format2ClassDefscCsJtdd�}x:|D]2}x,|D]$}t|ƒ}|j|ƒs4dS|j|ƒqWqW|S)NF)Ú useClass0)ÚClassDefBuilderÚsetÚcanAddÚadd)rryZclassdefbuilderÚpositionZglyphsetrrrrrv>s    z.ChainContextualRuleset._classBuilderForContextN) rarbrcr<rqrlrrrur|rvrrrrrns   rnc@sžeZdZdd„Zdd„Zdd„Zdd„Zd%d d „Zd&d d „Zd'dd„Z dd„Z dd„Z d(dd„Z d)dd„Z d*dd„Zd+dd„Zd,dd„Zd-d!d"„Zd#d$„ZdS).ÚChainContextualBuildercCstj||ƒo|j|jkS)N)r3r?ro)rr>rrrr?JszChainContextualBuilder.equalscCsHtƒg}x0|jD]&}|jr(|jtƒƒq|dj|ƒqWdd„|DƒS)NrcSsg|]}t|jƒdkr|‘qS)r)r,ro)r"rsrrrr$Wsz3ChainContextualBuilder.rulesets..rZ)rnrorkrJrq)rÚrulesetrprrrÚrulesetsMs  zChainContextualBuilder.rulesetscCsTd}xJ|D]B}tƒ}td|jidƒ|d<tj|ƒj||jƒ|t|jƒƒ7}q W|S)Nrr%) r r r%ÚcopyÚdeepcopyÚcompiler6r,Z getAllData)rr'Úsizer#ÚwrrrÚgetCompiledSize_Ys z'ChainContextualBuilder.getCompiledSize_c CsPg}d}|jƒ}tdd„|Dƒƒ}�x |D�]}dddgg}x$|jD]}|dj|j||ƒƒqDW|jƒ}|r‚|j|||ƒg|d<|jsš|j||ƒg|d<xnd D]f}||r y|j ||ƒWq t k �r} z(t j d|t |jƒ| fƒd||<WYdd} ~ Xq Xq Wd d „|Dƒ}|�s*td |jƒ‚t||j d �} |j| ƒq*W|j|ƒS)zšBuild the lookup. Returns: An ``otTables.Lookup`` object representing the chained contextual positioning lookup. Fcss|] }|jVqdS)N)rr)r"r„rrrr(psz/ChainContextualBuilder.build..Nrerrz*Contextual format %i at %s overflowed (%s)cSsg|]}|dk r|‘qS)Nr)r"rsrrrr$’sz0ChainContextualBuilder.build..zAll candidates overflowed)r)rrre)r…rtrorJÚbuildFormat3Subtabler|ÚbuildFormat2SubtableruÚbuildFormat1Subtabler‹Ú Exceptionr^r_Ústrr7rÚminÚextendrB) rr'Úchainingr…r„Ú candidatesrpÚ classdefsÚiÚeÚwinnerrrrrhfs8    zChainContextualBuilder.buildTc Cs®|j|d�}d|_|jƒtƒ}i}|jd|d�}xÚ|jD]Ð}|jd|d�}|ržt|jƒ|_ t|j ƒ|_ dd„t |jƒDƒ|_ dd„|j Dƒ|_t|jƒ|_n t|jƒ|_dd„|jdd…Dƒ|_|j||ƒt|jdƒd} | |krü|j| ƒg|| <|| j|ƒq:Wt||jƒ|_g} xT|jjD]H} |jd|d�} t| ||| ƒt| |›d �t|| ƒƒ| j| ƒ�q*Wt||jd|d�| ƒt||jd|d�d t| ƒƒ|S) N)r“r)Úformatr“cSsg|]}t|ƒd‘qS)r)Úlist)r"rsrrrr$«sz?ChainContextualBuilder.buildFormat1Subtable..cSsg|]}t|ƒd‘qS)r)rš)r"rsrrrr$¬scSsg|]}t|ƒd‘qS)r)rš)r"rsrrrr$²srÚCount)Ú newSubtable_ÚFormatÚpopulateDefaultsrÚ ruleAttr_roÚnewRule_r,rKrHrQrPrIÚ BacktrackÚ LookAheadrrTrWÚInputÚbuildLookupListršr�rJrrrÚ newRuleSet_ÚsetattrÚ ruleSetAttr_) rr„r“r#rNZrulesetsByFirstGlyphZruleAttrrpÚruleAsSubtableÚ firstGlyphZruleSetsrUZruleSetrrrrŽ�sB       z+ChainContextualBuilder.buildFormat1Subtablec s*|j|d�‰dˆ_ˆjƒ|r:dd„|Dƒ\ˆ_ˆ_ˆ_n|djƒˆ_|djƒ}g}x$|D]}|j d|d�}|j |ƒq^Wt ƒ}|j d|d�} �xN|j D�]B} |jd|d�} |�rHt| jƒ| _t| jƒ| _‡fdd„t| jƒDƒ| _‡fdd„| jDƒ| _t| jƒ| _‡fd d„| jdd…Dƒ| _|ˆjjt| jd ƒd } nHt| jƒ| _‡fd d„| jdd…Dƒ| _|ˆjjt| jd ƒd } |j| | ƒ|t | jd ƒO}t| | ƒj | ƒt | | ›d �t| | ›d �ƒdƒqœWt ˆ|j!d|d�|ƒt ˆ|j!d|d�d t|ƒƒt"||j#ƒˆ_$ˆS) N)r“rcSsg|] }|jƒ‘qSr)rh)r"Úcrrrr$Õsz?ChainContextualBuilder.buildFormat2Subtable..r)r™r“cs g|]}ˆjjt|ƒd‘qS)r)ÚBacktrackClassDefÚ classDefsrš)r"rs)r#rrr$ìscs g|]}ˆjjt|ƒd‘qS)r)ÚLookAheadClassDefr¬rš)r"rs)r#rrr$ðscs g|]}ˆjjt|ƒd‘qS)r)Ú InputClassDefr¬rš)r"rs)r#rrr$õsrcs g|]}ˆjjt|ƒd‘qS)r)ÚClassDefr¬rš)r"rs)r#rrr$ýsr›)%rœr�ržr«r®r­rhr¯r{r¥rJrrŸror r,rKrHrQrPrIr¡r¢rrTr£r¬ršrWÚClassr¤Úgetattrr¦r§rrr) rr„r•r“Z inClassesZ classSetsÚ_ZclassSetrNZ classRuleAttrrpr¨ZsetForThisRuler)r#rr�ËsR         z+ChainContextualBuilder.buildFormat2SubtablecCs`|j|d�}d|_|rB|j|j|ƒ|j|j|ƒ|j|j|ƒn|j|j|ƒ|j ||ƒ|S)N)r“re) rœr�rOrKrSrQrVrrXr¤)rrpr“r#rrrrŒs  z+ChainContextualBuilder.buildFormat3SubtablecCsŒx†t|jƒD]x\}}|dk r t|tƒs,|g}xV|D]N}|jdkrht|tƒrPd}nd}td|›d�|jƒ‚|j|ƒ}||_ |j|_ q2Wq WdS)NZ substitutionZ positioningz2Missing index of the specified lookup, might be a z lookup) Ú enumeratermr.ršr;ÚChainContextPosBuilderrr7ÚnewLookupRecord_Z SequenceIndexZLookupListIndex)rrpr#Z sequenceIndexZ lookupListÚlr>Úrecrrrr¤s      z&ChainContextualBuilder.buildLookupListcCs$|jjt|j|j|j|jgƒƒdS)N)rorJrjr[)rr7rrrr`4s z)ChainContextualBuilder.add_subtable_breakcCsPd|j›�}|rd|}tt|ƒƒ}t||j›d�dƒt||j›d�gƒ|S)NÚContextÚChainr›rÚ LookupRecord)Ú subtable_typer±rr¦)rr“Ú subtablenamer#rrrrœ>s  z#ChainContextualBuilder.newSubtable_rcCsL|dkrd}n|dkrd}nt|ƒ‚|jdd…›|›d�}|rHd|}|S) NrÚRulerr°rreÚSetr¹)r*r»)rr™r“Ú formatTyper¼rrrr§Qsz#ChainContextualBuilder.ruleSetAttr_cCsL|dkrd}n|dkrd}nt|ƒ‚|jdd…›|›d�}|rHd|}|S) NrÚrr°rrer½r¹)r*r»)rr™r“r¿r¼rrrrŸ]sz ChainContextualBuilder.ruleAttr_cCs tt|j||ƒƒƒ}|jƒ|S)N)r±rr§rž)rr™r“r#rrrr¥isz"ChainContextualBuilder.newRuleSet_cCs tt|j||ƒƒƒ}|jƒ|S)N)r±rrŸrž)rr™r“r#rrrr pszChainContextualBuilder.newRule_NFcCsŽ|rd|}d|}t||ƒs6t||dƒt||gƒ|r@|}n tt|ƒƒ}t||t||ƒdƒ|rzt||ƒj||ƒnt||ƒj|ƒ|S)Nr¹rr)Úhasattrr¦r±rÚinsertrJ)rr#Z subtable_nameZ count_nameÚexistingÚindexr“Z new_subtablerrrÚattachSubtableWithCount_ws    z/ChainContextualBuilder.attachSubtableWithCount_cCs"|j||j›d�|j›d�dd�S)Nrºr›F)r“)rÅr»)rr#rrrrµ‘s   z'ChainContextualBuilder.newLookupRecord_)T)T)T)T)rT)rT)rT)rT)NNF)rarbrcr?r…r‹rhrŽr�rŒr¤r`rœr§rŸr¥r rÅrµrrrrrƒIs   7 . H     rƒc@s eZdZdZdd„Zdd„ZdS)r´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. cCs"tj|||ddƒg|_d|_dS)Nr4r ZPos)r3r<ror»)rr6r7rrrr<µszChainContextPosBuilder.__init__csTd}xJ|ddd…D]8‰ˆ|jkr&|Stˆtƒrt‡‡fdd„|Dƒƒrˆ}qW|S)z$Helper for add_single_pos_chained_()Nrc3s|]}ˆj|ˆƒVqdS)N)Úcan_add)r"Úglyph)ÚlookupÚvaluerrr(ÁszCChainContextPosBuilder.find_chainable_single_pos..rZ)r[r.ÚSinglePosBuilderr))rrmrrÉÚresr)rÈrÉrÚfind_chainable_single_posºs  z0ChainContextPosBuilder.find_chainable_single_posN)rarbrcrir<rÌrrrrr´šsr´c@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚChainContextSubstBuildera?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. cCs"tj|||ddƒg|_d|_dS)Nr5éZSubst)r3r<ror»)rr6r7rrrr<âsz!ChainContextSubstBuilder.__init__cCsˆi}x~|jD]t}|jrq xf|jD]\}t|tƒs4|g}xF|D]>}|dk r:|jƒ}x(|jƒD]\}}|j|tƒƒj |ƒqXWq:Wq Wq W|S)N) rorkrmr.ršrAÚitemsÚ setdefaultrÚupdate)rÚresultrprmrÈZaltsrÇÚ replacementsrrrrAçs    $z+ChainContextSubstBuilder.getAlternateGlyphscshd}x^|jddd…D]J}|jr$|Sx:|jD]0}t|tƒr,t‡fdd„|jjƒDƒƒ r,|}q,WqW|S)z&Helper for add_single_subst_chained_()Nrc3s|]}|ˆkVqdS)Nr)r"rU)rrrr(þszGChainContextSubstBuilder.find_chainable_single_subst..rZ)rorkrmr.ÚSingleSubstBuilderrtr\rC)rrrËrpÚsubr)rrÚfind_chainable_single_substös   z4ChainContextSubstBuilder.find_chainable_single_substN)rarbrcrir<rArÖrrrrrÍÇsrÍc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚLigatureSubstBuildera–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. cCstj|||ddƒtƒ|_dS)Nr5r)r3r<rÚ ligatures)rr6r7rrrr<szLigatureSubstBuilder.__init__cCstj||ƒo|j|jkS)N)r3r?rØ)rr>rrrr?szLigatureSubstBuilder.equalscCs|j|jtƒ}|j|ƒS)z‘Build the lookup. Returns: An ``otTables.Lookup`` object representing the ligature substitution lookup. )r]rØÚbuildLigatureSubstSubtablerB)rr'rrrrh"s zLigatureSubstBuilder.buildcCs|j|j|j|f<dS)N)r[rØ)rr7rrrr`.sz'LigatureSubstBuilder.add_subtable_breakN)rarbrcrir<r?rhr`rrrrr×s  r×c@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚMultipleSubstBuilderaÃ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. cCstj|||ddƒtƒ|_dS)Nr5r)r3r<rr\)rr6r7rrrr<IszMultipleSubstBuilder.__init__cCstj||ƒo|j|jkS)N)r3r?r\)rr>rrrr?MszMultipleSubstBuilder.equalscCs|j|jtƒ}|j|ƒS)N)r]r\ÚbuildMultipleSubstSubtablerB)rr'rrrrhPszMultipleSubstBuilder.buildcCs|j|j|j|f<dS)N)r[r\)rr7rrrr`Tsz'MultipleSubstBuilder.add_subtable_breakN)rarbrcrir<r?rhr`rrrrrÚ2s rÚc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚCursivePosBuildera×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. cCstj|||ddƒi|_dS)Nr4re)r3r<Ú attachments)rr6r7rrrr<iszCursivePosBuilder.__init__cCstj||ƒo|j|jkS)N)r3r?rÝ)rr>rrrr?mszCursivePosBuilder.equalscCs x|D]}||f|j|<qWdS)akAdds 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Ý)rr7rÚ entryAnchorÚ exitAnchorrÇrrrÚadd_attachmentrs z CursivePosBuilder.add_attachmentcCst|j|jƒ}|j|gƒS)z�Build the lookup. Returns: An ``otTables.Lookup`` object representing the cursive positioning lookup. )ÚbuildCursivePosSubtablerÝrrB)rr#rrrrh‚szCursivePosBuilder.buildN)rarbrcrir<r?ràrhrrrrrÜXs rÜc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚMarkBasePosBuildera×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. cCs"tj|||ddƒi|_i|_dS)Nr4r)r3r<rDÚbases)rr6r7rrrr<©szMarkBasePosBuilder.__init__cCs$tj||ƒo"|j|jko"|j|jkS)N)r3r?rDrã)rr>rrrr?®s  zMarkBasePosBuilder.equalscCs*dd„|jDƒ}|jdd„|jDƒƒ|S)NcSsi|] }d|“qS)rr)r"rÇrrrú ¶sz8MarkBasePosBuilder.inferGlyphClasses..cSsi|] }d|“qS)rer)r"rÇrrrrä·s)rãrÑrD)rrÒrrrr@µsz$MarkBasePosBuilder.inferGlyphClassescsr|j|jƒ‰‡fdd„|jjƒDƒ}i}x0|jjƒD]"\}}‡fdd„|jƒDƒ||<q4Wt|||jƒ}|j|ƒS)z”Build the lookup. Returns: An ``otTables.Lookup`` object representing the mark-to-base positioning lookup. cs"i|]\}\}}ˆ||f|“qSrr)r"rFÚmcÚanchor)Ú markClassesrrräÂsz,MarkBasePosBuilder.build..csi|]\}}|ˆ|“qSrr)r"råræ)rçrrräÇs)rGrDrÏrãÚbuildMarkBasePosrrB)rrDrãrÇÚanchorsr'r)rçrrhºs  zMarkBasePosBuilder.buildN)rarbrcrir<r?r@rhrrrrrâ�s râc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚMarkLigPosBuilderacBuilds 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. cCs"tj|||ddƒi|_i|_dS)Nr4é)r3r<rDrØ)rr6r7rrrr<ëszMarkLigPosBuilder.__init__cCs$tj||ƒo"|j|jko"|j|jkS)N)r3r?rDrØ)rr>rrrr?ðs  zMarkLigPosBuilder.equalscCs*dd„|jDƒ}|jdd„|jDƒƒ|S)NcSsi|] }d|“qS)rr)r"rÇrrrräøsz7MarkLigPosBuilder.inferGlyphClasses..cSsi|] }d|“qS)rer)r"rÇrrrräùs)rØrÑrD)rrÒrrrr@÷sz#MarkLigPosBuilder.inferGlyphClassescsŽ|j|jƒ‰‡fdd„|jjƒDƒ}i}xL|jjƒD]>\}}g||<x,|D]$}||j‡fdd„|jƒDƒƒqJWq4Wt|||jƒ}|j|ƒS)z˜Build the lookup. Returns: An ``otTables.Lookup`` object representing the mark-to-ligature positioning lookup. cs"i|]\}\}}ˆ||f|“qSrr)r"rFråræ)rçrrräsz+MarkLigPosBuilder.build..csi|]\}}|ˆ|“qSrr)r"råÚa)rçrrrä s)rGrDrÏrØrJÚbuildMarkLigPosrrB)rrDÚligsÚligÚ componentsrªr'r)rçrrhüs   (zMarkLigPosBuilder.buildN)rarbrcrir<r?r@rhrrrrrêÌs rêc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚMarkMarkPosBuilderaÏ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. cCs"tj|||ddƒi|_i|_dS)Nr4rÎ)r3r<rDÚ baseMarks)rr6r7rrrr<+szMarkMarkPosBuilder.__init__cCs$tj||ƒo"|j|jko"|j|jkS)N)r3r?rDrò)rr>rrrr?0s  zMarkMarkPosBuilder.equalscCs*dd„|jDƒ}|jdd„|jDƒƒ|S)NcSsi|] }d|“qS)rer)r"rÇrrrrä8sz8MarkMarkPosBuilder.inferGlyphClasses..cSsi|] }d|“qS)rer)r"rÇrrrrä9s)ròrÑrD)rrÒrrrr@7sz$MarkMarkPosBuilder.inferGlyphClassescsàˆjˆjƒ‰tˆjƒˆjd�}‡fdd„ˆjjƒDƒ}tjƒ}d|_t ˆƒ|_ t |ˆj ƒ|_ t ˆjˆj ƒ|_t|ˆj ƒ|_tjƒ|_t |jjƒ|j_g|j_x6|jjD]*‰‡‡fdd„|Dƒ}|jjjt|ƒƒq¦Wˆj|gƒS)z”Build the lookup. Returns: An ``otTables.Lookup`` object representing the mark-to-mark positioning lookup. )rcs"i|]\}\}}ˆ||f|“qSrr)r"rFråræ)rçrrräEsz,MarkMarkPosBuilder.build..rcsg|]}ˆjˆj|ƒ‘qSr)ròÚget)r"rå)Úbaserrrr$Ssz,MarkMarkPosBuilder.build..)rGrDrrCrórÏrZ MarkMarkPosr�r,Ú ClassCountrrZ Mark1CoverageròZ Mark2CoverageÚbuildMarkArrayZ Mark1ArrayZ Mark2ArrayrZ Mark2CountÚ Mark2RecordrJÚbuildMark2RecordrB)rZ markClassListrDr#rér)rôrçrrrh<s"    zMarkMarkPosBuilder.buildN)rarbrcrir<r?r@rhrrrrrñs rñc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚReverseChainSingleSubstBuildera[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. cCstj|||ddƒg|_dS)Nr5r )r3r<ro)rr6r7rrrr<rsz'ReverseChainSingleSubstBuilder.__init__cCstj||ƒo|j|jkS)N)r3r?ro)rr>rrrr?vsz%ReverseChainSingleSubstBuilder.equalscsˆg}xx|jD]n\}}‰tjƒ}d|_|j||ƒ|j||ƒtˆjƒ|jƒ|_ t ˆƒ|_ ‡fdd„|j j Dƒ|_ |j|ƒq W|j|ƒS)z›Build the lookup. Returns: An ``otTables.Lookup`` object representing the chained contextual substitution lookup. rcsg|] }ˆ|‘qSrr)r"rU)r\rrr$ˆsz8ReverseChainSingleSubstBuilder.build..)rorZReverseChainSingleSubstr�rOrSrrCrrr,rWrZ SubstituterJrB)rr'rKrQr#r)r\rrhys   z$ReverseChainSingleSubstBuilder.buildcCsdS)Nr)rr7rrrr`Œsz1ReverseChainSingleSubstBuilder.add_subtable_breakN)rarbrcrir<r?rhr`rrrrrùXs rùc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) rÔadBuilds 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. cCstj|||ddƒtƒ|_dS)Nr5r)r3r<rr\)rr6r7rrrr<§szSingleSubstBuilder.__init__cCstj||ƒo|j|jkS)N)r3r?r\)rr>rrrr?«szSingleSubstBuilder.equalscCs|j|jtƒ}|j|ƒS)z‘Build the lookup. Returns: An ``otTables.Lookup`` object representing the multiple substitution lookup. )r]r\ÚbuildSingleSubstSubtablerB)rr'rrrrh®szSingleSubstBuilder.buildcCsdd„|jjƒDƒS)NcSsi|]\}}t|gƒ|“qSr)r)r"rÇÚreplrrrrä¹sz9SingleSubstBuilder.getAlternateGlyphs..)r\rÏ)rrrrrA¸sz%SingleSubstBuilder.getAlternateGlyphscCs|j|j|j|f<dS)N)r[r\)rr7rrrr`»sz%SingleSubstBuilder.add_subtable_breakN) rarbrcrir<r?rhrAr`rrrrrÔ‘s  rÔc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) ÚClassPairPosSubtableBuilderaSBuilds 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. cCs(||_d\|_|_i|_d|_g|_dS)NF)NN)Úbuilder_Ú classDef1_Ú classDef2_Úvalues_ÚforceSubtableBreak_Ú subtables_)rÚbuilderrrrr<Ês  z$ClassPairPosSubtableBuilder.__init__cCsŒ|j o2|jdk o2|jj|ƒo2|jdk o2|jj|ƒ}|s^|jƒtdd�|_tdd�|_i|_|jj|ƒ|jj|ƒ||f|j||f<dS)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. NT)r}F)rrþr€rÿÚflush_r~rr�)rÚgc1Úvalue1Úgc2Úvalue2Z mergeablerrrÚaddPairÑs         z#ClassPairPosSubtableBuilder.addPaircCs d|_dS)z-Add an explicit subtable break at this point.TN)r)rrrrÚaddSubtableBreakìsz,ClassPairPosSubtableBuilder.addSubtableBreakcCs|jƒ|jS)z>Return the list of ``otTables.PairPos`` subtables constructed.)rr)rrrrr'ðsz%ClassPairPosSubtableBuilder.subtablescCsL|jdks|jdkrdSt|j|jjƒ}|jdkr6dS|jj|ƒd|_ dS)NF) rþrÿÚbuildPairPosClassesSubtablerrýrrrrJr)rr#rrrrõs  z"ClassPairPosSubtableBuilder.flush_N) rarbrcrir<r r r'rrrrrrü¿s  rüc@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)ÚPairPosBuildera¥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. cCs(tj|||ddƒg|_i|_i|_dS)Nr4r)r3r<ÚpairsÚ glyphPairsÚ locations)rr6r7rrrr<szPairPosBuilder.__init__cCs|jj||||fƒdS)aAdd 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)r rJ)rr7Ú glyphclass1rÚ glyphclass2rrrrÚ addClassPairs zPairPosBuilder.addClassPairc CsV||f}|jj|dƒ}|dk r:|j|}tjd|||ƒn||f|j|<||j|<dS)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)rrórr^Údebug) rr7Zglyph1rÚglyph2rrZoldValueÚotherLocrrrÚ addGlyphPair&s  zPairPosBuilder.addGlyphPaircCs |jj|j|j|j|jfƒdS)N)r rJr[)rr7rrrr`Bs z!PairPosBuilder.add_subtable_breakcCs$tj||ƒo"|j|jko"|j|jkS)N)r3r?rr )rr>rrrr?Ls  zPairPosBuilder.equalsc Cs i}d}xŒ|jD]‚\}}}}||jkr8|dk r|jƒqd\}}|rL|jƒ}|rX|jƒ}|j||fƒ}|dkr‚t|ƒ}||||f<|j||||ƒqWg} |jr´| jt |j|j ƒƒx&t |j ƒƒD]} | j|| j ƒƒqÂW|j| ƒ} tjjttƒ} | �r| dk�rtjdƒt|j| | ƒ| S)zŒBuild the lookup. Returns: An ``otTables.Lookup`` object representing the pair positioning lookup. NrÚ0zCompacting GPOS...)rr)r r[r Ú getFormatrórür rr’ÚbuildPairPosGlyphsrrrCr'rBÚosÚenvironrr r^Úinforr6) rZbuildersrrrrrZ valFormat1Z valFormat2r'rrÈÚmoderrrrhSs8    zPairPosBuilder.buildN) rarbrcrir<rrr`r?rhrrrrr ÿs  r c@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) rÊ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. cCs"tj|||ddƒi|_i|_dS)Nr4r)r3r<rr\)rr6r7rrrr<ŽszSinglePosBuilder.__init__cCsD|j||ƒs(|j|}td||f|ƒ‚|r6||j|<||j|<dS)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. z7Already defined different position for glyph "%s" at %sN)rÆrrr\)rr7rÇZ otValueRecordrrrrÚadd_pos“s   zSinglePosBuilder.add_poscCs*t|tƒst‚|jj|ƒ}|dkp(||kS)N)r.rr*r\ró)rrÇrÉZcurValuerrrrƨs zSinglePosBuilder.can_addcCstj||ƒo|j|jkS)N)r3r?r\)rr>rrrr?­szSinglePosBuilder.equalscCst|j|jƒ}|j|ƒS)zŽBuild the lookup. Returns: An ``otTables.Lookup`` object representing the single positioning lookup. )ÚbuildSinglePosr\rrB)rr'rrrrh°szSinglePosBuilder.buildN) rarbrcrir<rrÆr?rhrrrrrÊ}s rÊcCs|sdStjƒ}t|ƒ|_|S)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)rZ SingleSubstÚdictr\)r\rrrrrú¾s  rúcCs|sdStjƒ}t|ƒ|_|S)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)rZ MultipleSubstr r\)r\rrrrrÛÓs  rÛcCs|sdStjƒ}t|ƒ|_|S)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)rZAlternateSubstr rf)r\rrrrrgós  rgcCst|ƒ |fS)N)r,)rðrrrÚ_getLigatureKey s r!cCs€|sdStjƒ}i|_xdt|jƒtd�D]P}tjƒ}|dd…|_t|jƒd|_ |||_ |d}|jj |gƒj |ƒq(W|S)aŒ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. N)rrr) rZ LigatureSubstrØrrCr!ZLigatureZ Componentr,Z CompCountÚLigGlyphrÐrJ)r\rrðZligaturer©rrrrÙs rÙcCshtjƒ}|||_|_d|_|dk r0||_d|_|dk s@|dk rd|jdksRtdƒ‚||_||_d|_|S)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. rNrz7Either point, or both of deviceX/deviceY, must be None.re) rÚAnchorZ XCoordinateZ YCoordinater�Z AnchorPointr*Z XDeviceTableZ YDeviceTable)rsÚyÚpointZdeviceXZdeviceYrrrrÚ buildAnchorDs r&csdtjƒ}g|_xDt||jd�D]2}||‰‡fdd„t|ƒDƒ}|jjt|ƒƒqWt|jƒ|_ |S)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. )rcsg|]}ˆj|ƒ‘qSr)ró)r"Ú markClass)Úbrrr$�sz"buildBaseArray..) rÚ BaseArrayÚ BaseRecordrrÚrangerJÚbuildBaseRecordr,Z BaseCount)rãÚnumMarkClassesrrrôrér)r(rÚbuildBaseArraycs r.cCstjƒ}||_|S)N)rr*Z BaseAnchor)rérrrrr,‡sr,cCs|sdStjƒ}||_|S)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ÚComponentRecordZLigatureAnchor)rérrrrÚbuildComponentRecordŽs r0cCsz|sdStjƒ}d|_t|jƒ|ƒ|_g|_x<|jjD]0}||\}}tjƒ}||_||_ |jj |ƒq6Wt |jƒ|_ |S)ayBuilds 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) rZ CursivePosr�rrCrZEntryExitRecordrZ EntryAnchorZ ExitAnchorrJr,ZEntryExitCount)ÚattachrrrÇrÞrßr·rrrrá¤s  rácsЈsdStjƒ}ˆjƒ}t|ƒ|_}t|ƒ|_}d|koF|knsPt‚‡fdd„t||dƒDƒ|_ }t|ƒ}t|ƒ}|d kr’|dks–t‚|d kr®|d kr®d|_ n|dkrÆ|d krÆd |_ nd|_ |S)a‡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. Nrcsg|]}ˆj|dƒ‘qS)r)ró)r"r‰)Údeltasrrr$æszbuildDevice..ré�é€reré r iÿÿÿéýÿÿÿi÷ÿÿÿ) rÚDevicerCr‘Ú StartSizeÚmaxÚEndSizer*r+Ú DeltaValueÚ DeltaFormat)r2rrCZ startSizeZendSizeZ deltaValuesZmaxDeltaZminDeltar)r2rÚ buildDeviceÍs""r=csxtjƒ}g|_xXt||jd�D]F}g}x,||D] ‰|j‡fdd„t|ƒDƒƒq0W|jjt|ƒƒqWt|jƒ|_ |S)a6Builds 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. )rcsg|]}ˆj|ƒ‘qSr)ró)r"rå)Ú componentrrr$sz&buildLigatureArray..) rÚ LigatureArrayÚLigatureAttachrrrJr+ÚbuildLigatureAttachr,Z LigatureCount)rîr-rrrïrér)r>rÚbuildLigatureArrayôs  rBcCs(tjƒ}dd„|Dƒ|_t|jƒ|_|S)NcSsg|] }t|ƒ‘qSr)r0)r"rªrrrr$!sz'buildLigatureAttach..)rr@r/r,ZComponentCount)rðrrrrrAs rAcCs\tjƒ}g|_x.) rZ MarkBasePosr�rÚ MarkCoveragerörCr9ÚvaluesrõZ BaseCoverager.r))rDrãrrrrrrF|s   rFcCst|||ƒgS)aç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)rDrîrrrrrí›s2rícCsbtjƒ}d|_t||ƒ|_t||ƒ|_tdd„|jƒDƒƒd|_ t||ƒ|_ t ||j |ƒ|_ |S)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. rcSsg|] \}}|‘qSrr)r"rår²rrrr$èsz+buildMarkLigPosSubtable..) rZ MarkLigPosr�rrGrörCr9rHrõZLigatureCoveragerBr?)rDrîrrrrrrIÐs   rIcCs6t|tƒst‚t|tjƒst‚tjƒ}||_||_|S)N)r.r/r*rr#rDr°Z MarkAnchor)ÚclassIDrærrrrrEîs rEcCstjƒ}||_|S)N)rr÷Z Mark2Anchor)rérrrrrø÷srøcCsF|dk r |Sd}x0|D](}|dk r||dk r|||jƒO}qW|S)Nr)r)ÚfrHr–ÚmaskrÉrrrÚ_getValueFormatþs rMcCsftƒ}tdd�}tdd�}x2t|ƒD]&\}}|j|ƒ|j|ƒ|j|ƒq$Wtjƒ} d| _t||j ƒdƒ}| _ t||j ƒdƒ}| _ t ||ƒ| _ |jƒ| _|jƒ| _|jƒ} |jƒ} g| _xŒ| D]„} tjƒ} g| _| jj| ƒxd| D]\}tjƒ}|j| |fd ƒ\}}|�rt||d�nd|_|�r2t||d�nd|_| jj|ƒqèWqÄWt| jƒ| _t| ƒ| _| S) a¦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. T)r}FrrrN)ÚsrcÚ valueFormat)NN)rr~rrÑr�rÚPairPosr�rMrHÚ ValueFormat1Ú ValueFormat2rrrhZ ClassDef1Z ClassDef2r{Z Class1RecordZ Class2RecordrJrórÚValue1ÚValue2r,Z Class1CountZ Class2Count)r rÚ valueFormat1Ú valueFormat2rNZ classDef1Z classDef2rrrZclasses1Zclasses2Úc1Zrec1Úc2Zrec2Úval1Úval2rrrr  s<'            r c s„i}xd|jƒD]X\\}}\}}|dk r.|jƒnd}|dk rB|jƒnd}|j||fiƒ} ||f| ||f<qW‡fdd„t|jƒƒDƒS)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. Nrcs"g|]\\}}}t|ˆ||ƒ‘qSr)ÚbuildPairPosGlyphsSubtable)r"ÚformatAÚformatBÚpos)rrrr$wsz&buildPairPosGlyphs..)rÏrrÐr) r rrMÚglyphAÚglyphBÚvalAÚvalBr\r]r^r)rrrPs  rcsLtjƒ}d|_t||jƒdƒ}|_t||jƒdƒ}|_i}x4|jƒD](\\}}\}} |j|gƒj ||| fƒqHWt dd„|j ƒDƒˆƒ|_ g|_ x¦|j jD]š} tj ƒ} g| _|j j | ƒxnt|| ‡fdd„d�D]R\} } }tjƒ}| |_|rþt| |d�nd |_|�rt||d�nd |_| jj |ƒqÖWt| jƒ| _qžWt|j ƒ|_|S) a¢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. rrcSsh|] \}}|’qSrr)r"rUr²rrrú £sz-buildPairPosGlyphsSubtable..cs ˆ|dS)Nrr)rs)rrrÚ©sz,buildPairPosGlyphsSubtable..)r)rNrON)rrPr�rMrHrQrRrÏrÐrJrrCrZPairSetrZPairValueRecordrZ SecondGlyphrrSrTr,ZPairValueCountZ PairSetCount)r rrUrVrrMr_r`rarbrÇZpsrrYrZZpvrr)rrr[|s,  $ r[cs¨gtƒ}‰iii}}‰xL|jƒD]@\}}t|ƒ‰|jˆgƒj|ƒ|jˆdgƒjˆƒ|ˆˆ<q&WxV|jƒD]J\‰}t|ƒtˆƒdkrt‡‡fdd„|Dƒ}|jt|ˆƒƒˆjˆƒqtWx~|jƒD]r\} } ‡fdd„| Dƒ} t| ƒdkrÌi} x,| D]$‰| j ‡‡fdd „|ˆDƒƒ�qüW|jt| ˆƒƒˆj | ƒqÌWxL|jƒD]@\‰}ˆˆk�rLx |D]} t| ˆˆiˆƒ}�qdW|j|ƒ�qLW|j ‡fd d „d �|S) aÂ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. rrëcsi|]}ˆˆ|“qSrr)r"rU)rrHrrräâsz"buildSinglePos..csg|]}|ˆkr|‘qSrr)r"Úk)Úhandledrrr$êsz"buildSinglePos..rc3s|]}|ˆˆfVqdS)Nr)r"rU)rerHrrr(îsz!buildSinglePos..cs t|ˆƒS)N)Ú_getSinglePosTableKey)r&)rrrrd sz buildSinglePos..)r) rrÏÚ_getSinglePosValueKeyrÐrJr,Ú_getSinglePosValueSizeÚbuildSinglePosSubtabler�rÑÚsort)r\rrÒZ coveragesÚmasksrÇrÉrZformat1MappingrOrCÚf2Zformat2MappingrUr#r)rrfrerrHrr´s6    $   rcs¨tjƒ}tˆjƒ|ƒ|_ttjdd„ˆjƒDƒdƒ‰|_ ‡‡fdd„|jj Dƒ‰t ‡fdd„ˆDƒƒrŒd|_ |j dkr„ˆd|_ q¤d|_ nd |_ ˆ|_ t|j ƒ|_|S) a˜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. cSsg|] }|jƒ‘qSr)r)r"Úvrrrr$& sz*buildSinglePosSubtable..rcsg|]}tˆ|ˆd�‘qS))rNrO)r)r"rU)rOrHrrr$' sc3s|]}|ˆdkVqdS)rNr)r"rn)Ú valueRecordsrrr(( sz)buildSinglePosSubtable..rNr)rÚ SinglePosrrCrrr/Ú__or__rHZ ValueFormatrr)r�ÚValuer,Z ValueCount)rHrrr)rOrorHrrj s"   rjcCs2t|tjƒst|ƒ‚|jj}t|ƒ ||dfS)Nr)r.rrpr*rrr,)rLrrrrrrg5 srgcCsŽt|tƒst|ƒ‚dg}}xT|jjƒD]F\}}t|tjƒrP|j|t|ƒfƒn|j||fƒ|t |dO}q(W|j ƒ|j d|ƒt |ƒS)Nr) r.rr*Ú__dict__rÏrr7rJÚ_makeDeviceTuplerrkrÂÚtuple)Z valueRecordrOrÒÚnamerÉrrrrh; s   rhÚ _DeviceTuplez(DeltaFormat StartSize EndSize DeltaValuecCs(t|j|j|j|jd@rfnt|jƒƒS)Ni€)rwr<r8r:rur;)ZdevicerrrrtM s rtcCsHd}x>|dd…D].\}}t|tƒr8|t|jƒd7}q|d7}qW|S)Nrrre)r.rwr,r;)ZvalueKeyÚcountr²rnrrrriW s   ricCs,tƒ}x |jƒD]\}}t|||ƒqW|S)a­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. )rrÏr¦)rÉrrernrrrÚ buildValueb srycsHˆsdStjƒ}tˆjƒ|ƒ|_‡fdd„|jjDƒ|_t|jƒ|_|S)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. Ncsg|]}tˆ|ƒ‘qSr)ÚbuildAttachPoint)r"rU)Ú attachPointsrrr$” sz#buildAttachList..) rZ AttachListrrCrrÚ AttachPointr,rW)r{rrr)r{rÚbuildAttachList� s r}cCs.|sdStjƒ}tt|ƒƒ|_t|jƒ|_|S)N)rr|rrZ PointIndexr,Z PointCount)Úpointsrrrrrz™ s  rzcCstjƒ}d|_||_|S)Nr)rÚ CaretValuer�Z Coordinate)ZcoordrrrrÚbuildCaretValueForCoord¤ sr€cCstjƒ}d|_||_|S)Nr)rrr�ZCaretValuePoint)r%rrrrÚbuildCaretValueForPoint¬ sr�cs–ˆrtˆjƒƒntƒ}ˆr(|jˆjƒƒ‡‡fdd„|Dƒ‰dd„ˆjƒDƒ‰ˆsVdStjƒ}tˆjƒ|ƒ|_‡fdd„|jjDƒ|_ t |j ƒ|_ |S)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.cs$i|]}tˆj|ƒˆj|ƒƒ|“qSr)Ú buildLigGlyphró)r"rU)Úcoordsr~rrrä× sz%buildLigCaretList..cSsi|]\}}|dk r||“qS)Nr)r"rUrªrrrräØ sNcsg|] }ˆ|‘qSrr)r"rU)Úcaretsrrr$Ý sz%buildLigCaretList..) rrCrÑrÏrZ LigCaretListrrrr"r,Z LigGlyphCount)rƒr~rrrr)r„rƒr~rÚbuildLigCaretList´ s  r…cCsbg}|r |jdd„t|ƒDƒƒ|r<|jdd„t|ƒDƒƒ|sDdStjƒ}||_t|jƒ|_|S)NcSsg|] }t|ƒ‘qSr)r€)r"rªrrrr$æ sz!buildLigGlyph..cSsg|] }t|ƒ‘qSr)r�)r"rMrrrr$è s)r’rrr"rr,Z CaretCount)rƒr~r„rrrrr‚â s r‚cs:|sdStjƒ}d|_‡fdd„|Dƒ|_t|jƒ|_|S)aBuilds 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. Nrcsg|]}t|ˆƒ‘qSr)r)r"Úm)rrrr$ sz)buildMarkGlyphSetsDef..)rZMarkGlyphSetsDefZMarkSetTableFormatrr,Z MarkSetCount)ZmarkSetsrrr)rrÚbuildMarkGlyphSetsDefñ s r‡c@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) r~z$Helper for building ClassDef tables.cCstƒ|_i|_||_dS)N)rÚclasses_Úglyphs_Ú useClass0_)rr}rrrr< szClassDefBuilder.__init__cCsLt|ttfƒrt|ƒ}t|ƒ}||jkr,dSx|D]}||jkr2dSq2WdS)NTF)r.rÚ frozensetrrurˆr‰)rrrÇrrrr€ s   zClassDefBuilder.canAddcCspt|ttfƒrt|ƒ}t|ƒ}||jkr,dS|jj|ƒx2|D]*}||jkr^td|›d�dƒ‚||j|<q>WdS)NzGlyph z is already present in class.) r.rr‹rrurˆr�r‰r)rrrÇrrrr�& s    zClassDefBuilder.addcCs,t|jdd„dd�}|js(|jdtƒƒ|S)NcSs t|ƒ|fS)N)r,)rRrrrrdA sz)ClassDefBuilder.classes..T)rÚreverser)rrˆrŠrÂr‹)rrÒrrrr{4 s zClassDefBuilder.classescCsPi}x8t|jƒƒD](\}}|dkr$qx|D] }|||<q*WqWtjƒ}||_|S)Nr)r³r{rr¯r¬)rZ glyphClassesrJrrÇZclassDefrrrrhF s zClassDefBuilder.buildN) rarbrcrir<r€r�r{rhrrrrr~ s  r~liÿÿÿc Cs²tjdƒ|d<tjƒ}|d_|d}t||ƒ|_t||ƒ\}}|sNd|_nd|_t |||ƒ}||}tj ƒ} || _ d|_ | |_ t|ƒ|_|r®tjƒ} || _| |_t|ƒ|_dS)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. ÚSTATrviir N)rZnewTablerr�r8Ú_addNameZElidedFallbackNameIDÚ_buildAxisRecordsÚVersionÚ_buildAxisValuesFormat4ZAxisRecordArrayZAxisZDesignAxisRecordSizeZDesignAxisRecordr,ZDesignAxisCountZAxisValueArrayÚ AxisValueZAxisValueCount) ZttFontÚaxesrZelidedFallbackNameZ statTableÚ nameTableÚ axisRecordsÚ axisValuesZmultiAxisValuesZaxisRecordArrayZaxisValueArrayrrrÚbuildStatTableV s(R   r—c Cs&g}g}�xt|ƒD�]\}}tjƒ}|d|_t||ddƒ|_|jd|ƒ|_|j|ƒx¾|jdfƒD]®}tj ƒ}||_ |jddƒ|_ t||dƒ|_ d|krÌ|d|_ d |krÄd |_|d |_nd |_n@d |k�rd |_|d |_|jdtƒ|_|jdtƒ|_ntdƒ‚|j|ƒqhWqW||fS)NÚtagrvéZorderingrHr0rrÉZ linkedValuererZ nominalValuerZ rangeMinValueZ rangeMaxValuez$Can't determine format for AxisValue)r³rZ AxisRecordZAxisTagrŽZ AxisNameIDróZ AxisOrderingrJr’Ú AxisIndexÚFlagsÚ ValueNameIDrrr�Z LinkedValueZ NominalValueÚAXIS_VALUE_NEGATIVE_INFINITYZ RangeMinValueÚAXIS_VALUE_POSITIVE_INFINITYZ RangeMaxValueÚ ValueError) r“r”r•r–ÚaxisRecordIndexÚaxisDictZaxisZaxisValÚ axisValRecrrrr�È s:        r�c CsÒi}x t|ƒD]\}}|||d<qWg}x¢|D]š}tjƒ}d|_t||dƒ|_|jddƒ|_g} x:|djƒD]*\} } tj ƒ} || | _ | | _ | j | ƒqrW| j dd„d �t| ƒ|_| |_ |j |ƒq0W|S) Nr˜rrvr0rr7cSs|jS)N)rš)Úavrrrrrd sz)_buildAxisValuesFormat4..)r)r³rr’r�rŽrœrór›rÏZAxisValueRecordršrrrJrkr,Z AxisCount) rr“r”ZaxisTagToIndexr r¡r–ZaxisLocationDictr¢ZaxisValueRecordsr˜rÉr£rrrr‘ï s(   r‘cCsœt|tƒr|St|tƒr$t|d�}njt|tƒr4|}nZt|tƒr†|jƒ}x:|D]2}t|tƒrv|j|j||j |j |j ƒqLt dƒ‚qLW|St dƒ‚|j ||d�S)N)Úenz*value must be a list of STATNameStatementsz$value must be int, str, dict or list)Ú minNameID)r.r/r�r ršZ_findUnusedNameIDr ÚsetNameÚstringZ platformIDZ platEncIDZlangIDÚ TypeErrorZaddMultilingualName)r”rÉr¥ÚnamesZnameIDZ nameRecordrrrrŽ s(         rŽ)rN)NNN)NN)NNi€)Nr)r)hÚ collectionsrrrZfontTools.misc.fixedToolsrZ fontToolsrZfontTools.ttLib.tablesrrZfontTools.ttLib.tables.otBaserrr r r ZfontTools.feaLib.astr ZfontTools.otlLib.optimize.gposr rrZfontTools.otlLib.errorrÚ functoolsrÚloggingr†Ú getLoggerrar^rZLOOKUP_FLAG_RIGHT_TO_LEFTZLOOKUP_FLAG_IGNORE_BASE_GLYPHSZLOOKUP_FLAG_IGNORE_LIGATURESZLOOKUP_FLAG_IGNORE_MARKSr-r2Úobjectr3rdrjrnrƒr´rÍr×rÚrÜrârêrñrùrÔrür rÊrúrÛrgr!rÙr&r.r,r0rár=rBrArörèrFrírIrErørMr rr[rrjrgrhrwrtriryr}rzr€r�r…r‚r‡r~r�ržr—r�r‘rŽrrrrÚs®        # 9c1 2S-=.&5?DH9.@~A  . $)'*$25  G, 8R/    ."?   r'