L iRdgZ ddlmZmZddlmZddlmZddlm Z ddl m Z ddl Z dd l mZedid d d d d dddddddddddddddddddddddddddddZed dddddddddddddd!Zed"d#Zed$dddddddd% Zedid d d&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4dd5dZedid d d&dd'dd(dd6dd7dd8dd9dd-dd.dd0dd1dd2dd3dd:dd4dd;dZediddd?dd@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdiZe ZedidBddjddkdldmdCdndAdoddpddqddrddsddtdduddvddwddxddyddzed{dd|dd}dd~dddddddddddddddddddddddddddddddddddddZGddeZdZdZy) FontBuilder)TTFontnewTable) cmap_classes flagCubic)Panose) timestampNowN) OrderedDict tableVersiong? fontRevisioncheckSumAdjustment magicNumberi<_flags unitsPerEmicreatedmodifiedxMinyMinxMaxyMaxmacStyle lowestRecPPEMfontDirectionHintindexToLocFormatglyphDataFormat)r numGlyphs maxPoints maxContoursmaxCompositePointsmaxCompositeContoursmaxZonesmaxTwilightPoints maxStoragemaxFunctionDefsmaxInstructionDefsmaxStackElementsmaxSizeOfInstructionsmaxComponentElementsmaxComponentDepthiP)r r!@) formatType italicAngleunderlinePositionunderlineThickness isFixedPitch minMemType42 maxMemType42 minMemType1 maxMemType1ascentdescentlineGapadvanceWidthMaxminLeftSideBearingminRightSideBearing xMaxExtentcaretSlopeRise caretSlopeRun caretOffset reserved0 reserved1 reserved2 reserved3metricDataFormatnumberOfHMetricsadvanceHeightMaxminTopSideBearingminBottomSideBearing yMaxExtent reserved4numberOfVMetrics copyright familyName styleNameuniqueFontIdentifierfullNameversionpsName trademark manufacturerdesigner description vendorURL designerURL licenseDescription licenseInfoURLtypographicFamilytypographicSubfamilycompatibleFullName sampleTextpostScriptCIDFindfontName wwsFamilyNamewwsSubfamilyNamelightBackgroundPalettedarkBackgroundPalettevariationsPostScriptNamePrefix xAvgCharWidth usWeightClassi usWidthClassfsTypeySubscriptXSizeySubscriptYSizeySubscriptXOffsetySubscriptYOffsetySuperscriptXSizeySuperscriptYSizeySuperscriptXOffsetySuperscriptYOffsetyStrikeoutSizeyStrikeoutPosition sFamilyClasspanoseulUnicodeRange1ulUnicodeRange2ulUnicodeRange3ulUnicodeRange4 achVendIDz???? fsSelectionusFirstCharIndexusLastCharIndex sTypoAscendersTypoDescender sTypoLineGap usWinAscent usWinDescentulCodePageRange1ulCodePageRange2sxHeight sCapHeight usDefaultChar usBreakChar usMaxContextusLowerOpticalPointSizeusUpperOpticalPointSizeceZdZd#dZdZdZdZdZdZdZ d$d Z d%d Z d Z d Z d&d ZdZd%dZdZd'dZdZdZdZdZdZdZdZdZd'dZd(dZdZdZd)dZd*dZ d+d Z! d,d!Z"d-d"Z#y).rNc|Ltd|_||_t}|J|j |||||j y|J||_d|v|_y)aInitialize a FontBuilder instance. If the `font` argument is not given, a new `TTFont` will be constructed, and `unitsPerEm` must be given. If `isTTF` is True, the font will be a glyf-based TTF; if `isTTF` is False it will be a CFF-based OTF. The `glyphDataFormat` argument corresponds to the `head` table field that defines the format of the TrueType `glyf` table (default=0). TrueType glyphs historically can only contain quadratic splines and static components, but there's a proposal to add support for cubic Bezier curves as well as variable composites/components at https://github.com/harfbuzz/boring-expansion-spec/blob/main/glyf1.md You can experiment with the new features by setting `glyphDataFormat` to 1. A ValueError is raised if `glyphDataFormat` is left at 0 but glyphs are added that contain cubic splines or varcomposites. This is to prevent accidentally creating fonts that are incompatible with existing TrueType implementations. If `font` is given, it must be a `TTFont` instance and `unitsPerEm` must _not_ be given. The `isTTF` and `glyphDataFormat` arguments will be ignored. NF)recalcTimestamp)rrrrglyf)rfontisTTFr setupHead setupMaxp)selfrrrrnows [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/fontBuilder.py__init__zFontBuilder.__init__9sv, <u5DIDJ.C) )) NN% /   NN % %%DI4DJc:|jj|y)zgSave the font. The 'file' argument can be either a pathname or a writable file object. N)rsave)rfiles rrzFontBuilder.save`s trct|x}|j|<|jD]\}}t||||jD]\}}t||||SN)rritemssetattr)rtableTagdefaultsvaluestablekvs r_initTableWithValuesz FontBuilder._initTableWithValuesfsj&.x&88 (#NN$ !DAq E1a  !LLN !DAq E1a  ! rcl|j|}|jD]\}}t|||yr)rrr)rrrrrrs r_updateTableWithValuesz"FontBuilder._updateTableWithValuesns5 (#LLN !DAq E1a  !rc 2|jdt|y)zCreate a new `head` table and initialize it with default values, which can be overridden by keyword arguments. headN)r _headDefaultsrrs rrzFontBuilder.setupHeads !!&-@rc (|jd|y)z^Update the head table with the fields and values passed as keyword arguments. rN)rrs r updateHeadzFontBuilder.updateHeadys ##FF3rc:|jj|y)z!Set the glyph order for the font.N)r setGlyphOrder)r glyphOrders rsetupGlyphOrderzFontBuilder.setupGlyphOrders  +rc.g}|r t|nd}|dkDr@td|jD}t|ddd}|j |n|}d}t||dd} | j |j |j | t||dd} |j | |hi} |D];\} } }|j| |k(rd }| | vrg| | <| | j | |f=tid dd }| |_ |j |td |j d <d|j d _ ||j d _y #tj$r!|s td d}t||dd} YwxYw)aBuild the `cmap` table for the font. The `cmapping` argument should be a dict mapping unicode code points as integers to glyph names. The `uvs` argument, when passed, must be a list of tuples, describing Unicode Variation Sequences. These tuples have three elements: (unicodeValue, variationSelector, glyphName) `unicodeValue` and `variationSelector` are integer code points. `glyphName` may be None, to indicate this is the default variation. Text processors will then use the cmap to find the glyph name. Each Unicode Variation Sequence should be an officially supported sequence, but this is not policed. r ic36K|]\}}|dks ||fyw)r N).0rrs r z0FontBuilder.setupCharacterMap..sS41aq7{ASs  rdrr`rTrzFcmap format 4 subtable overflowed; sort glyph order by unicode to fix.NrhrVcmap)maxdictrbuildCmapSubTableappendcompilerstructerror ValueErrorgetuvsDictrr tables)rcmappinguvs allowFallback subTableshighestUnicode cmapping_3_1 subTable_3_10format subTable_3_1 subTable_0_3r unicodeValuevariationSelector glyphName uvsSubTables rsetupCharacterMapzFontBuilder.setupCharacterMaps *2X F "S8>>3CSSL-hArBM   ] +#L(vq!D  I   + &(vq!D & ?G>A M: /<< -: $I$G313G-.)*11<2KL  M,BAq9K")K    [ )$V, &)* &&#, & 7|| I  \F,\61aHL Is*E 0FFc&tdx}|jd<g|_|jD]]\}}t |t r|}n t |}t |tr t|}|j||j|||_y)aCreate the `name` table for the font. The `nameStrings` argument must be a dict, mapping nameIDs or descriptive names for the nameIDs to name record values. A value is either a string, or a dict, mapping language codes to strings, to allow localized name table entries. By default, both Windows (platformID=3) and Macintosh (platformID=1) name records are added, unless any of `windows` or `mac` arguments is False. The following descriptive names are available for nameIDs: copyright (nameID 0) familyName (nameID 1) styleName (nameID 2) uniqueFontIdentifier (nameID 3) fullName (nameID 4) version (nameID 5) psName (nameID 6) trademark (nameID 7) manufacturer (nameID 8) designer (nameID 9) description (nameID 10) vendorURL (nameID 11) designerURL (nameID 12) licenseDescription (nameID 13) licenseInfoURL (nameID 14) typographicFamily (nameID 16) typographicSubfamily (nameID 17) compatibleFullName (nameID 18) sampleText (nameID 19) postScriptCIDFindfontName (nameID 20) wwsFamilyName (nameID 21) wwsSubfamilyName (nameID 22) lightBackgroundPalette (nameID 23) darkBackgroundPalette (nameID 24) variationsPostScriptNamePrefix (nameID 25) nameen)ttFontnameIDwindowsmacN) rrnamesr isinstanceint_nameIDsstrraddMultilingualName)r nameStringsrr nameTablenameName nameValuers rsetupNameTablezFontBuilder.setupNameTablesJ)1(88 DIIf% #.#4#4#6  Hi(C(!!(+)S) I.  ) )$))FGQT *  rc V|jdt|d|vr=d|jvsJd|jdj|jd|vsMd|vsHd|vsCd|vs>d|jvsJd |jdj |jy y y y y ) zCreate a new `OS/2` table and initialize it with default values, which can be overridden by keyword arguments. zOS/2r}hmtxz6the 'hmtx' table must be setup before the 'OS/2' tablerrrrz6the 'cmap' table must be setup before the 'OS/2' tableN)r _OS2DefaultsrrecalcAvgCharWidthrecalcUnicodeRangesrs rsetupOS2zFontBuilder.setupOS2s !!&,? & ($))# HG H# IIf  0 0 ;  ' F* F* F*$))# HG H# IIf  1 1$)) < +++ (rcddlm}m}m}m}m} m} |jrJd|j_ |} d| _ d| _ |j| _ |g| _ || _| } | | _| } |j!D]\}}t#| ||d}d}|}|jj%|_| |_| j|_|j!D]\}}t#|||d|vr)d|jdj*z }|dd|ddg|_|d|j&| | ||}|j!D]\}}| |_| |_|||<||_| jj3|t5d|jd<| |jd_y)Nr) CFFFontSet TopDictIndexTopDict CharStringsGlobalSubrsIndex PrivateDictOTTOr FontMatrixrzCFF )cffLibrrrr r r rr sfntVersionmajorminorotFont fontNames topDictIndex GlobalSubrsrr getGlyphOrdercharsetPrivaterr private globalSubrsrrcff)rrWfontInfocharStringsDict privateDictrrrr r r fontSetrrkeyvaluefdSelectfdArraytopDictscale charStringsr charStrings rsetupCFFzFontBuilder.setupCFFs  ::~ & ,  #H+~&( )-%++- )JC GS% ( ))))113!%11"..* )JC GS% ( ) x ' &)444E"'Aua!;G ! '//;7 &5%:%:%< 0 !Iz!(J %0J "%/K " 0*##G,$V, & ' &rcddlm}m}m}m}m}m} m} m} |jrJd|j_ |} d| _ d| _ |jj} |d| d| _|}|| _|ig}d}| }d|_||_|D]^}| }|j%d| }|j'D]\}}t)|||||_|j-|`|}| |_||_d|jdj2z }|dd|ddg|_|dj*}|dd||||}|j'D]\}}||_||_|||<||_| jj-|t;d|jd<| |jd_|r|j?|yy) Nr)rrrr r r  FDArrayIndexFontDictr rr TrCFF2) rrrrr r r r*r+rrrrrrrrstringssetCFF2rrrrcff2GetGlyphOrderFDArrayrr rrrrsetupCFF2Regions)rr fdArrayListregionsrrrr r r r*r+rr/rr"r#rfontDictrr r!r$r%r&rr's r setupCFF2zFontBuilder.setupCFF24s ::~ & ,   II33+D2CTJ&( )  $K.)& %KzH   T "!mG)//1 - Ue, -&H  NN8 $ %)$5!!DIIf%000#Q5!Q7!*$$!$k7HgV %4%:%:%< 0 !Iz!(J %0J "%/K " 0*##G,$V, & ' &   ! !' * rc ddlm}m}m}ddlm}d|j vsJdd|j vsJd|j djDcgc]}|j}}|||}|ttt|dd } ||| g} || } |j djjd } | | _| jD]} | | j _ycc}w) Nr)buildVarRegionList buildVarData buildVarStore) VarStoreDatafvarzfvar must to be set up firstr,zCFF2 must to be set up firstF)optimize) otVarStorer )varLib.builderr7r8r9rr:raxesaxisTaglistrangelenrrVarStorer0rvstore)rr3r7r8r9r:aaxisTags varRegionListvarDatavarStorerEr$r4s rr1zFontBuilder.setupCFF2RegionsqsSS("B$BB""B$BB"'+yy'8'='=>!AII>>*7H= tE#g,$78$O  :2))F#''44Q7! -H&,H   # -?sC=c,|jsJ|ro|jdjdk(rS|jD]@\}}|jdkDst d|j Ds3td|dtd|jd<td|jd<||jd_ t|jdr(|jj|jd_ |r|jy y ) aCreate the `glyf` table from a dict, that maps glyph names to `fontTools.ttLib.tables._g_l_y_f.Glyph` objects, for example as made by `fontTools.pens.ttGlyphPen.TTGlyphPen`. If `calcGlyphBounds` is True, the bounds of all glyphs will be calculated. Only pass False if your glyph objects already have their bounding box values set. If `validateGlyphFormat` is True, raise ValueError if any of the glyphs contains cubic curves or is a variable composite but head.glyphDataFormat=0. Set it to False to skip the check if you know in advance all the glyphs are compatible with the specified glyphDataFormat. rr c3.K|] }|tzywrr)rfs rrz(FontBuilder.setupGlyf..s1QA!i-1QszGlyph zt has cubic Bezier outlines, but glyphDataFormat=0; either convert to quadratics with cu2qu or set glyphDataFormat=1.locarrN) rrrrnumberOfContoursanyrrrglyphshasattrrcalcGlyphBounds)rrQrSvalidateGlyphFormatrgs r setupGlyfzFontBuilder.setupGlyfszzz 499V#4#D#D#I!<<> a%%)c1Q1Q.Q$ )\\ %V, &$V, &#) & 499l ++/99+?+?DIIf  (   " rc2t|j||y)aAdds an font variations table to the font. Args: axes (list): See below. instances (list): See below. ``axes`` should be a list of axes, with each axis either supplied as a py:class:`.designspaceLib.AxisDescriptor` object, or a tuple in the format ```tupletag, minValue, defaultValue, maxValue, name``. The ``name`` is either a string, or a dict, mapping language codes to strings, to allow localized name table entries. ```instances`` should be a list of instances, with each instance either supplied as a py:class:`.designspaceLib.InstanceDescriptor` object, or a dict with keys ``location`` (mapping of axis tags to float values), ``stylename`` and (optionally) ``postscriptfontname``. The ``stylename`` is either a string, or a dict, mapping language codes to strings, to allow localized name table entries. N)addFvarr)rr? instancess r setupFvarzFontBuilder.setupFvars*  4+rcddlm}d|jvr td|jdjDcgc]}|j }}t t|}||j|||ycc}w)zAdds an axis variations table to the font. Args: axes (list): A list of py:class:`.designspaceLib.AxisDescriptor` objects. r) _add_avarr;z*'fvar' table is missing; can't add 'avar'.N)varLibr\rKeyErrorr?r@r enumerate)rr?mappingsr\axisrGs r setupAvarzFontBuilder.setupAvarsk &  "GH H-1YYv->-C-CDTDLLDD9T?+$))T8X6EsA:cbtdx}|jd<d|_d|_||_y)Ngvarrr rrrUreserved variationsrrgrds r setupGvarzFontBuilder.setupGvar/#+F#33tyy   $rcbtdx}|jd<d|_d|_||_y)NGVARrr rerhs r setupGVARzFontBuilder.setupGVARrjrc|jd}|jjD]}|j|y)zCalculate the bounding boxes of all glyphs in the `glyf` table. This is usually not called explicitly by client code. rN)rrQr recalcBounds)r glyphTableglyphs rrSzFontBuilder.calcGlyphBoundss>YYv& &&--/ +E   z * +rc(|jd|y)zCreate a new `hmtx` table, for horizontal metrics. The `metrics` argument must be a dict, mapping glyph names to `(width, leftSidebearing)` tuples. rN setupMetricsrmetricss rsetupHorizontalMetricsz"FontBuilder.setupHorizontalMetrics &'*rc(|jd|y)zCreate a new `vmtx` table, for horizontal metrics. The `metrics` argument must be a dict, mapping glyph names to `(height, topSidebearing)` tuples. vmtxNrsrus rsetupVerticalMetricsz FontBuilder.setupVerticalMetricsrxrc|dvsJt|x}|j|<i}|D]5}||\}}tt|tt|f||<7||_y)zz2FontBuilder.setupVerticalOrigins..s c$irT)r reverser VORG)VOriginRecordsdefaultVertOriginY)sortedrrr majorVersion minorVersion)rverticalOriginsdefaultVerticalOriginrr vorgTablers @rsetupVerticalOriginsz FontBuilder.setupVerticalOriginss ! (C% #&r*s? !CIINI  # %+/%% ! !!   7L M IIf% !" !" ! 0B+B/IbM 0rc d|jv}|jdt|}|js|r|rd|_g|_i|_yd|_y)zCreate a new `post` table and initialize it with default values, which can be overridden by keyword arguments. r,postg@r/N)rr _postDefaultsrr0 extraNamesmapping)rkeepGlyphNamesrisCFF2 postTables r setupPostzFontBuilder.setupPost sQ499$--fmVL JJ&n#&I #%I "I #&I rc\|jrt}nt}|jd|iy)zCreate a new `maxp` table. This is called implicitly by FontBuilder itself and is usually not called by client code. maxpN)r_maxpDefaultsTTF_maxpDefaultsOTFr)rrs rrzFontBuilder.setupMaxp-s' ::'H'H !!&(B7rcHtdddg}|jdi|y)zThis adds an empty DSIG table to the font to make some MS applications happy. This does not properly sign the font. rr ) ulVersionusFlag usNumSigssignatureRecordsDSIGN)rrrs rsetupDummyDSIGzFontBuilder.setupDummyDSIG7s.   !!&"f5rc>ddlm}||j||||y)aAdd OpenType features to the font from a string containing Feature File syntax. The `filename` argument is used in error messages and to determine where to look for "include" files. The optional `tables` argument can be a list of OTL tables tags to build, allowing the caller to only build selected OTL tables. See `fontTools.feaLib` for details. The optional `debug` argument controls whether to add source debugging information to the font in the `Debg` table. r)addOpenTypeFeaturesFromString)filenamerdebugN)feaLib.builderrr)rfeaturesrrrrs raddOpenTypeFeatureszFontBuilder.addOpenTypeFeaturesCs B% IIx(6 rc~ddlm}d|jvr td|j |j||y)z|Add conditional substitutions to a Variable Font. See `fontTools.varLib.featureVars.addFeatureVariations`. r) featureVarsr;z5'fvar' table is missing; can't add FeatureVariations.) featureTagN)r]rrr^addFeatureVariations)rconditionalSubstitutionsrrs rrz FontBuilder.addFeatureVariationsWs> (  "RS S(( II/J ) rc |ddlm}|jj}|||||||||jd<y)zqBuild new COLR table using color layers dictionary. Cf. `fontTools.colorLib.builder.buildCOLR`. r ) buildCOLR)rUglyphMaprJ varIndexMap clipBoxesallowLayerReuseCOLRN)fontTools.colorLib.builderrrgetReverseGlyphMap) r colorLayersrUrJrrrrrs r setupCOLRzFontBuilder.setupCOLResA 999//1% #+  &rc vddlm}||||||jjd|jd<y)zBuild new CPAL table using list of palettes. Optionally build CPAL v1 table using paletteTypes, paletteLabels and paletteEntryLabels. Cf. `fontTools.colorLib.builder.buildCPAL`. r ) buildCPALr) paletteTypes paletteLabelspaletteEntryLabelsrCPALN)rrrr)rpalettesrrrrs r setupCPALzFontBuilder.setupCPALs6 9% %'1iimmF+   &rc ddlm}d|jvsJd||j|||td|jdjDy)zBuild a new 'STAT' table. See `fontTools.otlLib.builder.buildStatTable` for details about the arguments. r)buildStatTablerzname must to be set up firstc3:K|]}|jdk(ywrN platformIDrnrs rrz(FontBuilder.setupStat..sN!+N)macNamesN)otlLib.builderrrrPr)rr? locationselidedFallbackNamers r setupStatzFontBuilder.setupStatsT 3"B$BB" II   Ndii6G6M6MNN  r)NNTr )NF)TT)NNr)T)NNF)rvrn)NNNNT)NNN)Nr)$__name__ __module__ __qualname__rrrrrrrrrrr(r5r1rVrZrbrirmrSrwr{rtrrrrrrrrrrrrrrrr8s%(N ! A 4 ,4-l1f=*1(f;+z- #@,. 7% % +++*A A 0> '8 6 (  " :  0 rcZt||}||_||_||_d|_|S)Nr )rrr platEncIDlanguage)rrrrsubTables rrrs5F#F+HHM$H"HH Orc.ddlm}m}|sJtd}|d}t dt |ddD}d}|rd |z}|D]} |} t | tr| \| _| _ | _ | _ } nf| j| j| j| j| j f\| _| _ | _ | _ } | j"rd| _t | t&r t)| } |j+| || | _|j.j1| |D]} t | t(r| d } | d } | j3d}n2| j4} | j6xs | j8} | j:}t | t&r t)| } |}|j+| || |_||j?|||_ | |_!|jDj1|||d<y)Nr)Axis NamedInstancer;rc3:K|]}|jdk(ywrrrs rrzaddFvar..sP"2==A%Prrr))rri ))rr r r)rrlocation stylenamepostscriptfontname) platforms)#ttLib.tables._f_v_a_rrrrrPgetattrrtupler@minValue defaultValuemaxValuetagminimumdefaultmaximumrhiddenrrrr axisNameIDr?rrrlocalisedStyleNamerQpostScriptFontNamesubfamilyNameIDaddNamepostscriptNameID coordinatesrY)rr?rYrrr;rrraxis_defrarinstancerpsnameinsts rrXrXs : K4 F DV IP 7B0OPPH!I 9, v h &    !         U QT\4=$*;T]D# dC 4=D#77Tx7X 58$ h %":.KK(D\\"67F"++K..D(2D2DD00F dC 4=D(<< 8 =   $-$5$5f $5$RD !& d#)$,DLrr)__all__ttLibrrttLib.tables._c_m_a_prttLib.tables._g_l_y_frttLib.tables.O_S_2f_2r misc.timeToolsr r collectionsr rrrrrrrr_panoseDefaultsrobjectrrrXrrrr sw /B$/,)( #           !"# ( "            !"# (         !"# (                       "# $% &' () *!+ ,- ./ 01 23 4$&5 @(( ((( (  (  (((((((((( !(" #($%(&'(()(*+(,-(./(01(23(45(67(89(:;(<=(>?(@A(BC(DE(FG(HI(JK(LM(NO( Vo  &o  dCr