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øªj´Iã@sdZddlmZddlmZddlmZddlmZ ddl m Z m Z ddl mZdd lmZmZd-d d „Zd d„Zdd„Zdd„Zd.dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Z d)d*„Z!e"d+k�rdd,l#Z#dd,l$Z$e$j%e#j&ƒj'ƒd,S)/zºModule to build FeatureVariation tables: https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#featurevariations-table NOTE: The API is experimental and subject to change. é)Úhashdict)ÚpopCount)ÚnewTable)ÚotTables)Ú buildLookupÚbuildSingleSubstSubtable)Ú OrderedDicté)Ú VarLibErrorÚVarLibValidationErrorÚrvrncCst|t|ƒ|ƒdS)a³Add conditional substitutions to a Variable Font. The `conditionalSubstitutions` argument is a list of (Region, Substitutions) tuples. A Region is a list of Boxes. A Box is a dict mapping axisTags to (minValue, maxValue) tuples. Irrelevant axes may be omitted and they are interpretted as extending to end of axis in each direction. A Box represents an orthogonal 'rectangular' subset of an N-dimensional design space. A Region represents a more complex subset of an N-dimensional design space, ie. the union of all the Boxes in the Region. For efficiency, Boxes within a Region should ideally not overlap, but functionality is not compromised if they do. The minimum and maximum values are expressed in normalized coordinates. A Substitution is a dict mapping source glyph names to substitute glyph names. Example: # >>> f = TTFont(srcPath) # >>> condSubst = [ # ... # A list of (Region, Substitution) tuples. # ... ([{"wdth": (0.5, 1.0)}], {"cent": "cent.rvrn"}), # ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}), # ... ] # >>> addFeatureVariations(f, condSubst) # >>> f.save(dstPath) N)ÚaddFeatureVariationsRawÚoverlayFeatureVariations)ÚfontÚconditionalSubstitutionsÚ featureTag©rúA/tmp/pip-build-_d5lkt3n/fonttools/fontTools/varLib/featureVars.pyÚaddFeatureVariationssrcCstƒ}x8|D]0\}}t|ƒ}||kr4||j|ƒq |||<q Wdd„|jƒDƒ}~tƒ}xVt|ƒD]J\}}ttdd„|Dƒdd„d�ƒ}||kr¢||j|ƒqdt|ƒ||<qdWt t|jƒƒƒ}~tƒdff}t|ƒ}x²t |ƒD]¦\}\}}t|ƒ} d |>} x„|jƒD]x\} } xl|D]d} t | | ƒ\}}|d k �rRt|ƒ}| j |dƒ| B| B| |<|d k �rt|ƒ}| j |dƒ| B| |<�qW�qW| }qâWg}x„t|jƒd d„d�D]l\} } | dk�r¼�q¦g}d}x8| �rü| d @�rè|j ||d ƒ| d L} |d 7}�qÆW|j t| ƒ|fƒ�q¦W|S) apCompute overlaps between all conditional substitutions. The `conditionalSubstitutions` argument is a list of (Region, Substitutions) tuples. A Region is a list of Boxes. A Box is a dict mapping axisTags to (minValue, maxValue) tuples. Irrelevant axes may be omitted and they are interpretted as extending to end of axis in each direction. A Box represents an orthogonal 'rectangular' subset of an N-dimensional design space. A Region represents a more complex subset of an N-dimensional design space, ie. the union of all the Boxes in the Region. For efficiency, Boxes within a Region should ideally not overlap, but functionality is not compromised if they do. The minimum and maximum values are expressed in normalized coordinates. A Substitution is a dict mapping source glyph names to substitute glyph names. Returns data is in similar but different format. Overlaps of distinct substitution Boxes (*not* Regions) are explicitly listed as distinct rules, and rules with the same Box merged. The more specific rules appear earlier in the resulting list. Moreover, instead of just a dictionary of substitutions, a list of dictionaries is returned for substitutions corresponding to each unique space, with each dictionary being identical to one of the input substitution dictionaries. These dictionaries are not merged to allow data sharing when they are converted into font tables. Example: >>> condSubst = [ ... # A list of (Region, Substitution) tuples. ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}), ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}), ... ([{"wdth": (0.5, 1.0)}], {"cent": "cent.rvrn"}), ... ([{"wght": (0.5, 1.0), "wdth": (-1, 1.0)}], {"dollar": "dollar.rvrn"}), ... ] >>> from pprint import pprint >>> pprint(overlayFeatureVariations(condSubst)) [({'wdth': (0.5, 1.0), 'wght': (0.5, 1.0)}, [{'dollar': 'dollar.rvrn'}, {'cent': 'cent.rvrn'}]), ({'wdth': (0.5, 1.0)}, [{'cent': 'cent.rvrn'}]), ({'wght': (0.5, 1.0)}, [{'dollar': 'dollar.rvrn'}])] cSsg|]\}}|t|ƒf‘qSr)Údict)Ú.0ÚkÚvrrrú gsz,overlayFeatureVariations..css|]}tt|ƒƒVqdS)N)rÚ cleanupBox)rrrrrú qsz+overlayFeatureVariations..cSstt|jƒƒƒS)N)ÚtupleÚsortedÚitems)ÚdrrrÚrsz*overlayFeatureVariations..)Úkeyrr NcSst|dƒ S)Nr )r)Z BoxAndRankrrrr �s)rrÚextendrÚreversedrrÚupdaterÚlistÚ enumerateÚ overlayBoxÚgetÚappend)rZmergedÚvaluer!Z initMapInitZboxMapÚiZ currRegionÚ_ZnewMapZcurrRankÚboxZrankZcurrBoxÚ intersectionÚ remainderrZ substsListrrrr3s\-         rc Cs@i}|j|ƒ|j|ƒx`t|ƒt|ƒ@D]L}||\}}||\}}t||ƒ}t||ƒ} || ksjd|fS|| f||<q*Wt|ƒ} d} d} xž|D]–}||kr¢d} q�||\}}||\}}||krÌ||krÌq�| rØ||fSd} d} ||krøt||ƒ}|} n"||k�r|}t||ƒ} n||fS|| f| |<q�W| �r8|dfS|| fS)a>Overlays `top` box on top of `bot` box. Returns two items: - Box for intersection of `top` and `bot`, or None if they don't intersect. - Box for remainder of `bot`. Remainder box might not be exact (since the remainder might not be a simple box), but is inclusive of the exact remainder. NFT)r$ÚsetÚmaxÚminr) ÚtopZbotr.ÚaxisTagZmin1Zmax1Zmin2Zmax2ZminimumÚmaximumr/Z exactlyOneZ fullyInsiderrrr'¨sJ              r'cCsdd„|jƒDƒS)zòReturn a sparse copy of `box`, without redundant (default) values. >>> cleanupBox({}) {} >>> cleanupBox({'wdth': (0.0, 1.0)}) {'wdth': (0.0, 1.0)} >>> cleanupBox({'wdth': (-1.0, 1.0)}) {} cSsi|]\}}|dkr||“qS)çð?çð¿)r7r6r)rÚtagÚlimitrrrú szcleanupBox..)r)r-rrrrös rcsd|krtƒ|d<|dj}|jdkr,d|_d|_g}x,t|jjƒD]\}}|j|krD|j|ƒqDW|�st |gƒ}|jjj|ƒt |jjƒ|j_ t |ƒ|jjj |ƒ}xd|jjD]X} | jjdkrÔtd| j›d�ƒ‚dd„| jjDƒ} x"| jjg| D]} | jj|ƒqöWq²W|g}t|ƒ\}} t|| ƒ‰dd „t|d jƒDƒ} g}x¼|D]´\}}g}xJt|jƒƒD]:\}\}}||k�r„td ƒ‚t| |||ƒ}|j|ƒ�qfW‡fd d„|Dƒ}g}x2|D]*}|jj|jj}|jt|||ƒƒ�qÀW|jt ||ƒƒ�qLWt!|ƒ|_dS) z{Low level implementation of addFeatureVariations that directly models the possibilities of the FeatureVariations table.ÚGSUBiNz,Feature variations require that the script 'z$' defines a default language system.cSsg|] }|j‘qSr)ÚLangSys)rZlsrrrrr2sz+addFeatureVariationsRaw..cSsi|]\}}||j“qSr)r4)rÚ axisIndexZaxisrrrr:?sz+addFeatureVariationsRaw..ZfvarzrrrrRzs  rRc Cs�t|jjƒ}i}x t|ƒD]\}}||||<qWxH|D]@}t|ƒ}tt|ƒgƒ}|jjj|ƒ|jj|||ks8t‚q8Wt|jjƒ|j_ |S)zlBuild the lookups for the glyph substitutions, return a dict mapping the substitution to lookup indices.) rHrerfr&rrrr)ÚAssertionErrorZ LookupCount) rZr]Z firstIndexr?r+rir>ZsubstMapÚlookuprrrrSŠs  rScCstjƒ}d|_||_|S)z%Build the FeatureVariations subtable.i)rdrCrBÚFeatureVariationRecord)r^ZfvrrrrY›srYcCs.tjƒ}||_tjƒ|_||j_|jjƒ|S)zBuild a FeatureRecord.)rdrErFrUrVZpopulateDefaults)rÚlookupListIndicesÚfrrrrrG£s   rGcCs8tjƒ}tjƒ|_||j_tjƒ|_d|j_||j_|S)zBuild a FeatureVariationRecord.i)rdrlZ ConditionSetÚConditionTableÚFeatureTableSubstitutionrBÚSubstitutionRecord)raZsubstitutionRecordsÚfvrrrrrX­s  rXcCs$tjƒ}||_tjƒ|_||j_|S)z'Build a FeatureTableSubstitutionRecord.)rdZFeatureTableSubstitutionRecordrQrUrV)Z featureIndexrmÚftsrrrrrW¸s  rWcCs$tjƒ}d|_||_||_||_|S)zBuild a ConditionTable.r )rdroZFormatZ AxisIndexZFilterRangeMinValueZFilterRangeMaxValue)r=ZfilterRangeMinValueZfilterRangeMaxValuerbrrrrTÁs rTcCs^dd„t|jjƒDƒ}|jƒdd„|Dƒ|j_ttdd„|Dƒtt|ƒƒƒƒ}t||ƒdS)z�Sort the feature list by feature tag, and remap the feature indices elsewhere. This is needed after the feature list has been modified. cSsg|]\}}|j||f‘qSr)rF)rrJÚfearrrrÐsz#sortFeatureList..cSsg|]\}}}|‘qSrr)rr8rJrtrrrrÒscSsg|]\}}}|‘qSrr)rr8rJrtrrrrÓsN) r&rDrEÚsortrÚzipÚrangerHÚ remapFeatures)rAZ tagIndexFeaÚ featureRemaprrrrIËs  rIc Cs¦x\t|jjƒD]L\}}|jj}|dk r0t||ƒx(t|jjƒD]\}}|j}t||ƒq>WqWt|dƒr¢|j dk r¢x.|j j D]"}x|j j D]} || j | _ qŠWq|WdS)z7Go through the scripts list, and remap feature indices.NrC)r&rKrLrMrNÚ _remapLangSysrPr<ÚhasattrrCrlrprqrQ) rAryZ scriptIndexÚscriptZdefaultLangSysZlangSysRecordIndexZ langSysRecr\rrrsrrrrxÙs rxcs0|jdkrˆ|j|_‡fdd„|jDƒ|_dS)Niÿÿcsg|] }ˆ|‘qSrr)rrJ)ryrrrìsz!_remapLangSys..)rgrQ)r\ryr)ryrrzés  rzÚ__main__N)r )r )(Ú__doc__ZfontTools.misc.dictToolsrZfontTools.misc.intToolsrZfontTools.ttLibrZfontTools.ttLib.tablesrrdZfontTools.otlLib.builderrrÚ collectionsrÚerrorsr r rrr'rr r@rRrSrYrGrXrWrTrIrxrzÚ__name__ÚdoctestÚsysÚexitÚtestmodÚfailedrrrrÚs4      #uN R