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äáã@sRddlmZddlmZmZddlZddlmZmZddl Z ddl Z ddl m Z ddl mZddd d d d d dgZdZedZdd„Zdd„ZGdd„deƒZGdd„deƒZGdd„deƒZGdd „d eƒZGdd „d eƒZdd„Zdd„Zd d!„ZGd"d „d eƒZd#d$„ZGd%d „d eƒZ Gd&d„deƒZ!Gd'd „d eƒZ"Gd(d„deeƒZ#dS))é)ÚLogMixin)ÚtobytesÚtostrN)ÚBytesIOÚStringIO)Úetree)ÚplistlibÚDesignSpaceDocumentErrorÚDesignSpaceDocumentÚSourceDescriptorÚInstanceDescriptorÚAxisDescriptorÚRuleDescriptorÚ BaseDocReaderÚ BaseDocWriterz&{http://www.w3.org/XML/1998/namespace}ÚlangcCs>tj|jtjjƒŽ}|jdƒr(d|}n|jdƒr:d|}|S)z.gettercs |dk rt|ƒ}t|ˆ|ƒdS)N)rÚsetattr)rÚvalue)r rrÚsetter/sz"posixpath_property..setter)Úproperty)r r!r$r)r rÚposixpath_property*s  r&c@seZdZddd„Zdd„ZdS)r NcCs||_||_dS)N)ÚmsgÚobj)rr'r(rrrÚ__init__9sz!DesignSpaceDocumentError.__init__cCs"t|jƒ|jdk rd|jndS)Nz: %rÚ)Ústrr'r()rrrrÚ__str__=sz DesignSpaceDocumentError.__str__)N)Ú__name__Ú __module__Ú __qualname__r)r,rrrrr 8s c@seZdZdd„ZdS)Ú AsDictMixincCs`i}xV|jjƒD]H\}}|jdƒr$qt|dƒr8|jƒ}nt|tƒrPdd„|Dƒ}|||<qW|S)NÚ_ÚasdictcSs"g|]}t|dƒr|jƒn|‘qS)r2)Úhasattrr2)Ú.0Úvrrrú Msz&AsDictMixin.asdict..)Ú__dict__Úitemsrr3r2Ú isinstanceÚlist)rÚdÚattrr#rrrr2Ds     zAsDictMixin.asdictN)r-r.r/r2rrrrr0Bsr0c@seZdZdZdd„ZdS)ÚSimpleDescriptorz% Containers for a bunch of attributescCsbx\|jD]R}yt||ƒt||ƒks&t‚Wqtk rXtd|t||ƒdt||ƒƒYqXqWdS)Nzfailed attributez!=)Ú_attrsrÚAssertionErrorÚprint)rÚotherr<rrrÚcompareXs  zSimpleDescriptor.compareN)r-r.r/Ú__doc__rBrrrrr=Ssr=c@sleZdZdZdZddddddd d d d d ddg Zddddddddddddddddœdd„ZedƒZedƒZ dS)r z/Simple container for data related to the sourceÚsourceÚfilenamerÚnameÚ layerNameÚlocationÚcopyLibÚ copyGroupsÚ copyFeaturesÚ muteKerningÚmuteInfoÚmutedGlyphNamesÚ familyNameÚ styleNameNF)rErÚfontrFrHrGrOrPrIÚcopyInforJrKrLrMrNcCsb||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ ||_ |pZg|_dS)N)rErrQrFrHrGrOrPrIrRrJrKrLrMrN)rrErrQrFrHrGrOrPrIrRrJrKrLrMrNrrrr)ks zSourceDescriptor.__init__Ú_pathÚ _filename) r-r.r/rCÚflavorr>r)r&rrErrrrr as2"c@s,eZdZdZdddgZddddœdd„ZdS) raë rFÚ conditionSetsÚsubsN)rFrVrWcCs||_|p g|_|pg|_dS)N)rFrVrW)rrFrVrWrrrr)²s zRuleDescriptor.__init__)r-r.r/rCr>r)rrrrr¢s  cst‡fdd„|jDƒƒS)zK Return True if any of the rule's conditionsets matches the given location.c3s|]}t|ˆƒVqdS)N)ÚevaluateConditions)r4Úc)rHrrú ¼szevaluateRule..)ÚanyrV)ÚrulerHr)rHrÚ evaluateRuleºsr]cCs‚x||D]t}||d}|jdƒdkr6||dkrzdSq|jdƒdkrV|d|krzdSq|d|kop|dknsdSqWdS)z» Return True if all the conditions matches the given location. If a condition has no minimum, check for < maximum. If a condition has no maximum, check for > minimum. rFÚminimumNÚmaximumFT)Úget)Ú conditionsrHÚcdr#rrrrX¿s     rXc Csvg}xl|D]d}t||ƒr xL|D]D}d}x |jD]\}}||kr.d}Pq.W|rX|j|ƒq|j|ƒqW|}g}q W|S)zY Apply these rules at this location to these glyphnames - rule order matters FT)r]rWÚappend) ÚrulesrHZ glyphNamesZnewNamesr\rFZswapÚaÚbrrrÚ processRulesÑs    rgc@sÂeZdZdZdZdZdddddd d d d d dg Zdddddddddddddddddddœdd„ZedƒZ edƒZ d&dd„Z d'dd„Z d(dd„Z d)dd„Zd*dd„Zd+d d!„Zd,d"d#„Zd-d$d%„ZdS).r z1Simple container for data related to the instanceÚinstanceÚenrrFrHrOrPÚpostScriptFontNameÚstyleMapFamilyNameÚstyleMapStyleNameÚkerningÚinfoÚlibNT)rErrQrFrHrOrPrjrkrlÚlocalisedFamilyNameÚlocalisedStyleNameÚlocalisedStyleMapFamilyNameÚlocalisedStyleMapStyleNameÚglyphsrmrnrocCsˆ||_||_||_||_||_||_||_||_| |_| |_ | pBi|_ | pLi|_ | pVi|_ |p`i|_ |pji|_||_||_|p€i|_dS)N)rErrQrFrHrOrPrjrkrlrprqrrrsrtrmrnro)rrErrQrFrHrOrPrjrkrlrprqrrrsrtrmrnrorrrr)÷s&      zInstanceDescriptor.__init__rSrTcCst|ƒ|j|<dS)N)rrq)rrPÚ languageCoderrrÚ setStyleName(szInstanceDescriptor.setStyleNamecCs |jj|ƒS)N)rqr`)rrurrrÚ getStyleName+szInstanceDescriptor.getStyleNamecCst|ƒ|j|<dS)N)rrp)rrOrurrrÚ setFamilyName.sz InstanceDescriptor.setFamilyNamecCs |jj|ƒS)N)rpr`)rrurrrÚ getFamilyName1sz InstanceDescriptor.getFamilyNamecCst|ƒ|j|<dS)N)rrs)rrlrurrrÚsetStyleMapStyleName4sz'InstanceDescriptor.setStyleMapStyleNamecCs |jj|ƒS)N)rsr`)rrurrrÚgetStyleMapStyleName7sz'InstanceDescriptor.getStyleMapStyleNamecCst|ƒ|j|<dS)N)rrr)rrkrurrrÚsetStyleMapFamilyName:sz(InstanceDescriptor.setStyleMapFamilyNamecCs |jj|ƒS)N)rrr`)rrurrrÚgetStyleMapFamilyName=sz(InstanceDescriptor.getStyleMapFamilyName)ri)ri)ri)ri)ri)ri)ri)ri)r-r.r/rCrUZ_defaultLanguageCoder>r)r&rrErvrwrxryrzr{r|r}rrrrr çsT       cCs–dtdd�fdtdd�fdtdd�fdtd d�fd td d�fd œ}|jƒ|krZ||jƒSt|ƒd kr||dd t|ƒ}n |dd …}|t|d�fS)NZwghtZWeight)riZwdthZWidthZopszz Optical SizeZslntZSlantZitalZItalic)ZweightÚwidthZopticalZslantZitalicéÚ*)ÚdictÚlowerÚlen)rFÚnamesÚtagrrrÚtagForAxisNameAs        r†c @sXeZdZdZdZddddddgZd d d d d d d d d œd d „Zdd„Zdd„Zdd„Z d S)r zH Simple container for the axis data Add more localisations? Úaxisr…rFr_r^ÚdefaultÚmapNF)r…rFÚ labelNamesr^rˆr_Úhiddenr‰c Cs<||_||_|pi|_||_||_||_||_|p4g|_dS)N)r…rFrŠr^r_rˆr‹r‰) rr…rFrŠr^rˆr_r‹r‰rrrr)Zs  zAxisDescriptor.__init__c Cs(t|j|j|j|j|j|j|j|jd�S)N)r…rFrŠr_r^rˆr‹r‰) r�r…rFrŠr_r^rˆr‹r‰)rrrrÚ serializerszAxisDescriptor.serializecCs,ddlm}|js|S||dd„|jDƒƒS)Nr)ÚpiecewiseLinearMapcSsi|]\}}||“qSrr)r4Úkr5rrrú „sz.AxisDescriptor.map_forward..)ÚfontTools.varLib.modelsr�r‰)rr5r�rrrÚ map_forwards zAxisDescriptor.map_forwardcCs,ddlm}|js|S||dd„|jDƒƒS)Nr)r�cSsi|]\}}||“qSrr)r4rŽr5rrrr�‹sz/AxisDescriptor.map_backward..)r�r�r‰)rr5r�rrrÚ map_backward†s zAxisDescriptor.map_backward) r-r.r/rCrUr>r)rŒr‘r’rrrrr Ss c@s¤eZdZdZeZeZeZ e Z e dd„ƒZ e dd„ƒZe dd„ƒZe dd „ƒZd d „Zd!dd„Zd"dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „ZdS)#rz cCs|jƒS)N)ÚaxisDescriptorClass)ÚclsrrrÚgetAxisDecriptor•szBaseDocWriter.getAxisDecriptorcCs|jƒS)N)ÚsourceDescriptorClass)r”rrrÚgetSourceDescriptor™sz!BaseDocWriter.getSourceDescriptorcCs|jƒS)N)ÚinstanceDescriptorClass)r”rrrÚgetInstanceDescriptor�sz#BaseDocWriter.getInstanceDescriptorcCs|jƒS)N)ÚruleDescriptorClass)r”rrrÚgetRuleDescriptor¡szBaseDocWriter.getRuleDescriptorcCs<||_||_d|_tjdƒ|_|j|jjd<g|_g|_dS)Nz4.1Z designspaceÚformat) rÚdocumentObjectZdocumentVersionÚETÚElementÚrootÚattribÚ_axesÚ_rules)rÚ documentPathr�rrrr)¥s zBaseDocWriter.__init__TúUTF-8c Cs4|jjr|jjtjdƒƒx|jjD]}|j|ƒq$W|jjrnt|jddƒrVddi}ni}|jjtjd|ƒƒx|jjD]}|j |ƒqxW|jj r¤|jjtjdƒƒx|jj D]}|j |ƒq®W|jj rÚ|jjtjdƒƒx|jj D]}|j |ƒqäW|jj�r|j|jjƒtj|jƒ} | j|j|d ||d �dS) NÚaxesÚrulesProcessingLastFÚ processingÚlastrdÚsourcesÚ instancesÚxml)ÚencodingÚmethodÚxml_declarationZ pretty_print)r�r¦r rcržrŸÚ_addAxisrdrÚ_addRulerªÚ _addSourcer«Ú _addInstanceroÚ_addLibÚ ElementTreeÚwriter) rÚprettyr­r¯Ú axisObjectÚ attributesÚ ruleObjectÚ sourceObjectÚinstanceObjectÚtreerrrr¶®s8   zBaseDocWriter.writeNc CsÎtjdƒ}|dk r||jd<|jjƒ}x$|jƒD]\}}||kr0|||<q0Wxx|jƒD]l\}}tjdƒ} || jd<t|ƒtkr¨|j|dƒ| jd<|j|dƒ| jd<n|j|ƒ| jd<|j | ƒqVW||fS) z, Convert Location dict to a locationElement.rHNrFZ dimensionrÚxvalueéÚyvalue) ržrŸr¡r�ÚnewDefaultLocationr8ÚtypeÚtupleÚ intOrFloatrc) rZlocationObjectrFZ locElementZvalidatedLocationZaxisNameZ axisValueZ dimensionNameZdimensionValueZ dimElementrrrÚ_makeLocationElementÓs        z"BaseDocWriter._makeLocationElementcCst|ƒ|krd|Sd|S)Nz%dz%f)Úint)rÚnumrrrrÄès zBaseDocWriter.intOrFloatc CsT|jj|ƒtjdƒ}|jdk r,|j|jd<xÂ|jD]¸}tjdƒ}x–|D]Ž}|jdƒdkrj|jdƒdkrjqHtjdƒ}|jdƒ|jd<|jdƒdk r¨|j|jdƒƒ|jd<|jdƒdk rÌ|j|jdƒƒ|jd<|j|ƒqHWt |ƒr4|j|ƒq4Wx>|j D]4}tjdƒ}|d|jd<|d |jd <|j|ƒqøWt |ƒ�rP|j j d ƒdj|ƒdS) Nr\rFZ conditionsetr^r_Ú conditionÚsubrr¿Úwithz.rules) r£rcržrŸrFr¡rVr`rÄrƒrWr Úfindall) rrºÚ ruleElementraZconditionsetElementÚcondÚconditionElementrÉÚ subElementrrrr±ís2           zBaseDocWriter._addRulec Cs|jj|ƒtjdƒ}|j|jd<|j|jd<|j|jƒ|jd<|j|j ƒ|jd<|j|j ƒ|jd<|j rtd|jd<x>t |j jƒƒD],\}}tjd ƒ}||jt<||_|j|ƒq„W|j�rxF|jD]<\}}tjd ƒ}|j|ƒ|jd <|j|ƒ|jd <|j|ƒqÄW|jjd ƒdj|ƒdS)Nr‡r…rFr^r_rˆÚ1r‹Ú labelnamer‰ÚinputÚoutputz.axesr)r¢rcržrŸr…r¡rFrÄr^r_rˆr‹ÚsortedrŠr8ÚXML_LANGÚtextr‰r rË) rr¸Ú axisElementruZ labelNameZlanguageElementÚ inputValueÚ outputValueÚ mapElementrrrr° s*        zBaseDocWriter._addAxiscCsTtjdƒ}|jdk r |j|jd<|jdk r6|j|jd<|jdk rL|j|jd<|jrªt|jjƒƒ}|j ƒx@|D]8}|dkr|qntjdƒ}||jt <|j |ƒ|_ |j |ƒqnW|j�r t|jjƒƒ}|j ƒx@|D]8}|dkrÜqÎtjdƒ}||jt <|j|ƒ|_ |j |ƒqÎW|j�rpt|jjƒƒ}|j ƒxF|D]>}|dk�r@�q.tjdƒ}||jt <|j|ƒ|_ |j |ƒ�q.W|j�rÖt|jjƒƒ}|j ƒxF|D]>}|dk�r¦�q”tjdƒ}||jt <|j|ƒ|_ |j |ƒ�q”W|jdk �rþ|j|jƒ\} |_|j | ƒ|jdk �r|j|jd<|jdk �r.|j|jd <|jdk �rF|j|jd<|jdk �r^|j|jd<|j�rÐ|jd ƒgk�rŠtjd ƒ} |j | ƒ|jd ƒd } x6t|jjƒƒD]$\} } |j||| | ƒ} | j | ƒ�q¨W|j�rìtjd ƒ}|j |ƒ|j �rtjdƒ}|j |ƒ|j!�r:tjdƒ}|j t"j#|j!dd�ƒ|j |ƒ|j$jdƒd j |ƒdS)NrhrFÚ familynameÚ stylenameriÚstylemapstylenameÚstylemapfamilynamerEÚpostscriptfontnamez.glyphsrtrrmrnror)Ú indent_levelz .instances)%ržrŸrFr¡rOrPrqr:ÚkeysÚsortrÕrwrÖrcrpryrsr{rrr}rHrÅrErjrkrlrtrËrÔr8Ú_writeGlyphElementrmrnrorÚtotreer )rr¼ÚinstanceElementZ languageCodesÚcodeZlocalisedStyleNameElementZlocalisedFamilyNameElementZ!localisedStyleMapStyleNameElementZ"localisedStyleMapFamilyNameElementÚlocationElementZ glyphsElementÚ glyphNameÚdataÚ glyphElementÚkerningElementÚ infoElementÚ libElementrrrr³!sš                                           zBaseDocWriter._addInstancec CsØtjdƒ}|jdk r |j|jd<|jdk rF|jjdƒdkrF|j|jd<|jdk r\|j|jd<|jdk rr|j|jd<|jdk rˆ|j|jd<|j r¬tjd ƒ}d |jd <|j |ƒ|j rÐtjd ƒ}d |jd <|j |ƒ|j rôtjd ƒ}d |jd <|j |ƒ|j pþ|j�r:tjdƒ}|j �rd |jd <|j�r0d |jd<|j |ƒ|j�r`tjdƒ}d |jd<|j |ƒ|j�r¢x8|jD].}tjdƒ} || jd<d | jd<|j | ƒ�qpW|j|jƒ\} |_|j | ƒ|jjdƒdj |ƒdS)NrDrEZ temp_masterrrFrÛrÜÚlayerrorÐÚcopyÚgroupsÚfeaturesrnÚmutermÚglyphz.sources)ržrŸrEr¡rFÚfindrOrPrGrIrcrJrKrRrMrLrNrÅrHr rË) rr»Ú sourceElementríÚ groupsElementÚfeaturesElementrìrërFrêrçrrrr²rsX                                zBaseDocWriter._addSourcecCs.tjdƒ}|jtj|dd�ƒ|jj|ƒdS)Nroé)rà)ržrŸrcrrär )rr�rírrrr´¡s zBaseDocWriter._addLibc Cs~tjdƒ}|jdƒrd|jd<|jdƒdk rLdjdd„|jdƒDƒƒ|jd<|jd ƒdk r||j|jd ƒƒ\}|d <|j|ƒ|dk rŽ||jd <|jd ƒdk r¼tjd ƒ}|jd ƒ|_|j|ƒ|jd ƒdk �rztjd ƒ}x˜|jd ƒD]Š} tjd ƒ} | jdƒdk �r| jdƒ| jd<| jdƒdk �r0| jdƒ| jd<| jdƒdk �rb|j| jdƒƒ\}| d<| j|ƒ|j| ƒqâW|j|ƒ|S)NróròrÐÚunicodesú cSsg|] }t|ƒ‘qSr)Úhex)r4Úurrrr6«sz4BaseDocWriter._writeGlyphElement..ÚunicodeÚinstanceLocationrFÚnoteÚmastersZmasterrèÚ glyphnamerQrDrH)ržrŸr`r¡rrÅrcrÖ) rrår¼rèrérêrçÚ noteElementZmastersElementÚmÚ masterElementrrrrã¦s8             z BaseDocWriter._writeGlyphElement)Tr¥T)N)r-r.r/Z _whiteSpacerršr r“r r–r r˜Ú classmethodr•r—r™r›r)r¶rÅrÄr±r°r³r²r´rãrrrrrŽs&     % Q/c@s¦eZdZeZeZeZe Z dd„Z e dd„ƒZ dd„Zdd„Zd#d d „Zd d „Zdd„Zdd„Zdd„Zd$dd„Zd%dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd S)&rcCs^||_||_tj|jƒ}|jƒ|_|jjjddƒ|j_g|_ g|_ g|_ g|_ i|_ d|_dS)Nrœz3.0T)rr�ržÚparseÚgetrootr r¡r`Ú formatVersionr¢rdrªr«Ú axisDefaultsÚ_strictAxisNames)rr¤r�r½rrrr)Ës  zBaseDocReader.__init__cCs$tt|dd�ƒ}|||ƒ}d|_|S)Nzutf-8)r­)rrr)r”Ústringr�ÚfrrrrÚ fromstringØs zBaseDocReader.fromstringcCs,|jƒ|jƒ|jƒ|jƒ|jƒdS)N)ÚreadAxesÚ readRulesÚ readSourcesÚ readInstancesÚreadLib)rrrrÚreadßs zBaseDocReader.readc Cs g}|jjdƒ}|dk rF|jjddƒ}|d kr:td|ƒ‚|dk|j_xÌ|jjdƒD]¼}|jƒ}|jjdƒ}|_ |j ||ƒ}|rš|j j |ƒ|j jdƒx2|jd ƒD]$}|j ||ƒ} | dk r¦|j j | ƒq¦Wx6|jd ƒD](} | jd} | jd } |jj | | fƒqÚW|j |ƒqTW||j_dS) Nz.rulesr¨Úfirstr©zO processing attribute value is not valid: %r, expected 'first' or 'last'z .rules/rulerFzWFound stray rule conditions outside a conditionset. Wrapped them in a new conditionset.z .conditionsetz.subrÊ>r©r)r rôr¡r`r r�r§rËršrFÚ_readConditionElementsrVrcÚlogrnrWrd) rrdZ rulesElementZprocessingValuerÌrºÚruleNameZexternalConditionsZconditionSetElementZ conditionSetrÏrerfrrrræs>     zBaseDocReader.readRulesNcCsÆg}x¼|jdƒD]®}i}|jjdƒ}|dk r:t|ƒ|d<nd|d<|jjdƒ}|dk rdt|ƒ|d<nd|d<|jjdƒ|d<|jdƒdkr´|jdƒdkr´td|dk r¬d|ndƒ‚|j|ƒqW|S)Nz .conditionr^r_rFz5condition missing required minimum or maximum in rulez '%s'r*)rËr¡r`Úfloatr rc)rZ parentElementrZcdsrÎrbZcdMinZcdMaxrrrrs$  z$BaseDocReader._readConditionElementsc Cs6|jjdƒ}|sdS�x|D�]}|jƒ}|jjdƒ|_t|jjdƒƒ|_t|jjdƒƒ|_|jjddƒrpd|_ t|jjdƒƒ|_ |jjd ƒ|_ x>|jd ƒD]0}t|jd ƒ}t|jd ƒ}|j j ||fƒqœWx@|jd ƒD]2}x,|jƒD] \}} |tkrêt|jƒ|j| <qêWqÜW|jjj |ƒ|j |j|j<qWdS)Nz .axes/axisrFr^r_r‹FTrˆr…r‰rÒrÓrÑ)r rËr“r¡r`rFrr^r_r‹rˆr…r‰rcr8rÕrrÖrŠr�r¦r ) rZ axisElementsr×r¸rÚrerfZlabelNameElementÚkeyrrrrr's, zBaseDocReader.readAxescCsP�xHt|jjdƒƒD�]2\}}|jjdƒ}|dk r^|jdk r^tjjtjjtjj |jƒ|ƒƒ}nd}|jjdƒ}|dkr~d|}|j ƒ}||_||_ ||_ |jjdƒ}|dk r²||_ |jjdƒ}|dk rÌ||_|j|ƒ|_|jjdƒ} | dk rò| |_x(|jdƒD]} | jjd ƒd krþd |_qþWx,|jd ƒD]} | jjd ƒd k�r(d |_�q(WxD|jd ƒD]6} | jjd ƒd k�rrd |_| jjdƒd k�rVd |_�qVWx,|jdƒD]} | jjd ƒd k�rœd |_�qœWxL|jdƒD]>}|jjdƒ}|dk�rè�qÊ|jjdƒd k�rÊ|jj|ƒ�qÊWx,|jdƒD]}|jjdƒd k�rd |_�qW|jjj|ƒqWdS)Nz.sources/sourcerErFztemp_master.%drÛrÜrîz.librïrÐTz.groupsz.inforòz .featuresz.glyphz.kerning)Ú enumerater rËr¡r`rrÚabspathrÚdirnamer–rErFrOrPÚlocationFromElementrHrGrIrJrRrMrKrNrcrLr�rª)rZ sourceCountrõrEZ sourcePathZ sourceNamer»rOrPrGrírörìr÷rêrèrërrrrBs\ "            zBaseDocReader.readSourcescCs(d}x|jdƒD]}|j|ƒ}PqW|S)Nz .location)rËÚreadLocationElement)rÚelementZelementLocationrçrrrrts  z!BaseDocReader.locationFromElementcCsø|jr|jj rtdƒ‚i}xÖ|jdƒD]È}|jjdƒ}|jrX||jkrX|jj d|ƒq(d}}y|jjdƒ}t |ƒ}Wn"t k rš|jj d|ƒYnXy |jjdƒ}|dk rºt |ƒ}Wnt k rÐYnX|dk rè||f||<q(|||<q(W|S) z Format 0 location reader zNo axes definedz .dimensionrFz#Location with undefined axis: "%s".Nr¾z%KeyError in readLocation xValue %3.3frÀ) r r�r¦r rËr¡r`r rÚwarningrÚ ValueError)rrçÚlocZdimensionElementZdimNameZxValueZyValuerrrr{s0      z!BaseDocReader.readLocationElementTcCs0|jjdƒ}x|D]}|j||||d�qWdS)Nz.instances/instance)Ú makeGlyphsÚ makeKerningÚmakeInfo)r rËÚ_readSingleInstanceElement)rr#r$r%ZinstanceElementsrårrrr˜s  zBaseDocReader.readInstancescCs¨|jjdƒ}|dk r<|jjdk r This is an instance from an anisotropic interpolation. rFNz#Glyph object without name attributeròrÐTrýcSsg|]}t|dƒ‘qS)é)rÆ)r4rürrrr6ýsz2BaseDocReader.readGlyphElement..rúrùz"unicode values %s are not integersz.noterÿrþz.masters/masterrDr)rQrHrèr) r¡r`r rr!rËrÖrr�rcrt)rrêr¼Ú glyphDatarèròrùrrþZ glyphSourcesrZfontSourceNameZsourceLocationZmasterGlyphNamer;rrrr'åsH             zBaseDocReader.readGlyphElementcCs,x&|jjdƒD]}tj|dƒ|j_qWdS)z,Read the lib element for the whole document.z.librN)r rËrr*r�ro)rrírrrrszBaseDocReader.readLib)N)TTT)TTT)r-r.r/rršr r“r r–r r˜r)rr rrrrrrrrr&r)r(r+r'rrrrrrÅs( ( 2  ;5c@súeZdZdZd;dd„Zedd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd?d'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„ZdS)@r z+ Read, write data from the designspace fileNcCsld|_d|_d|_g|_g|_g|_g|_d|_d|_i|_ |dk rL||_ nt |_ |dk rb||_ nt |_ dS)NF)rrErrªr«r¦rdr§rˆroÚ readerClassrÚ writerClassr)rr.r/rrrr)"s  zDesignSpaceDocument.__init__cCs|||d�}|j|ƒ|S)N)r.r/)r)r”rr.r/rrrrÚfromfileBs  zDesignSpaceDocument.fromfilecCs4|||d�}|jj||ƒ}|jƒ|jr0|jƒ|S)N)r.r/)r.r rrªÚ findDefault)r”r r.r/rÚreaderrrrr Hs  zDesignSpaceDocument.fromstringcCsv|tks|dk r(|jƒdkr(tƒ}d}n,|dks8|dkrHtƒ}d}d}n td|ƒ‚|j||ƒ}|j||d�|jƒS)NrýFzutf-8zUTF-8Tzunsupported encoding: '%s')r­r¯)r+r‚rrr!r/r¶Úgetvalue)rr­r r¯ÚwriterrrrÚtostringQs  zDesignSpaceDocument.tostringcCsLt|dƒr|jƒ}||_tjj|ƒ|_|j||ƒ}|jƒ|jrH|j ƒdS)NÚ __fspath__) r3r6rrÚbasenamerEr.rrªr1)rrr2rrrras  zDesignSpaceDocument.readcCsFt|dƒr|jƒ}||_tjj|ƒ|_|jƒ|j||ƒ}|jƒdS)Nr6) r3r6rrr7rEÚ updatePathsr/r¶)rrr4rrrr¶ks  zDesignSpaceDocument.writecCs tjj|tjj|jƒƒ}t|ƒS)N)rrÚrelpathrr)rZ otherPathZrelativerrrÚ_posixRelativePathtsz&DesignSpaceDocument._posixRelativePathcCs@|jdk st‚x,|j|jD]}|jdk r|j|jƒ|_qWdS)a Right before we save we need to identify and respond to the following situations: In each descriptor, we have to do the right thing for the filename attribute. case 1. descriptor.filename == None descriptor.path == None -- action: write as is, descriptors will not have a filename attr. useless, but no reason to interfere. case 2. descriptor.filename == "../something" descriptor.path == None -- action: write as is. The filename attr should not be touched. case 3. descriptor.filename == None descriptor.path == "~/absolute/path/there" -- action: calculate the relative path for filename. We're not overwriting some other value for filename, it should be fine case 4. descriptor.filename == '../somewhere' descriptor.path == "~/absolute/path/there" -- action: there is a conflict between the given filename, and the path. So we know where the file is relative to the document. Can't guess why they're different, we just choose for path to be correct and update filename. N)rr?rªr«r:rE)rÚ descriptorrrrr8xs* zDesignSpaceDocument.updatePathscCs|jj|ƒdS)N)rªrc)rÚsourceDescriptorrrrÚ addSource¨szDesignSpaceDocument.addSourcecKs|jjf|Ž}|j|ƒ|S)N)r/r–r=)rÚkwargsrDrrrÚaddSourceDescriptor«s z'DesignSpaceDocument.addSourceDescriptorcCs|jj|ƒdS)N)r«rc)rZinstanceDescriptorrrrÚ addInstance°szDesignSpaceDocument.addInstancecKs|jjf|Ž}|j|ƒ|S)N)r/r˜r@)rr>rhrrrÚaddInstanceDescriptor³s z)DesignSpaceDocument.addInstanceDescriptorcCs|jj|ƒdS)N)r¦rc)rÚaxisDescriptorrrrÚaddAxis¸szDesignSpaceDocument.addAxiscKs|jjf|Ž}|j|ƒ|S)N)r/r“rC)rr>r‡rrrÚaddAxisDescriptor»s z%DesignSpaceDocument.addAxisDescriptorcCs|jj|ƒdS)N)rdrc)rZruleDescriptorrrrÚaddRuleÀszDesignSpaceDocument.addRulecKs|jjf|Ž}|j|ƒ|S)N)r/ršrE)rr>r\rrrÚaddRuleDescriptorÃs z%DesignSpaceDocument.addRuleDescriptorcCs.tjƒ}x |jD]}|j|jƒ||j<qW|S)z(Return default location in design space.)Ú collectionsÚ OrderedDictr¦r‘rˆrF)rr"rBrrrrÁÈs  z&DesignSpaceDocument.newDefaultLocationTFcCs€|r>x8|jD].}|jdk r"| r"q |jdk r |j|jƒ|_q W|r|x8|jD].}|jdk r`| r`qJ|jdk rJ|j|jƒ|_qJWdS)N)rªrErr:r«)rrr«Úforcer;rrrÚupdateFilenameFromPathÓs    z*DesignSpaceDocument.updateFilenameFromPathcCs |jjƒS)N)r/r•)rrrrÚnewAxisDescriptorãsz%DesignSpaceDocument.newAxisDescriptorcCs |jjƒS)N)r/r—)rrrrÚnewSourceDescriptorçsz'DesignSpaceDocument.newSourceDescriptorcCs |jjƒS)N)r/r™)rrrrÚnewInstanceDescriptorësz)DesignSpaceDocument.newInstanceDescriptorcCs$g}x|jD]}|j|jƒq W|S)N)r¦rcrF)rr„rBrrrÚ getAxisOrderïs z DesignSpaceDocument.getAxisOrdercCs"x|jD]}|j|kr|SqWdS)N)r¦rF)rrFrBrrrÚgetAxisõs  zDesignSpaceDocument.getAxiscCs6d|_|jƒ}x"|jD]}|j|kr||_|SqWdS)z­Set and return SourceDescriptor at the default location or None. The default location is the set of all `default` values in user space of all axes. N)rˆrÁrªrH)rZdefault_location_designr<rrrr1ûs  zDesignSpaceDocument.findDefaultcszddlm}i}xd|jD]Z‰ˆj|kr(q|ˆj}t|tƒrD|d}‡fdd„ˆjˆjˆjfDƒ}|||ƒ|ˆj<qW|S)Nr)ÚnormalizeValuecsg|]}ˆj|ƒ‘qSr)r‘)r4r5)r‡rrr6sz9DesignSpaceDocument.normalizeLocation..) r�rPr¦rFr9rÃr^rˆr_)rrHrPÚnewr#Ztripler)r‡rÚnormalizeLocations     z%DesignSpaceDocument.normalizeLocationc Csx|jD]}|j|jƒ|_qWxj|jD]`}xL|jjƒD]>\}}|j|dƒ|d<x"|dD]}|j|dƒ|d<qZWq6W|j|jƒ|_q&Wx¶|jD]¬}g}x8|jD].\}}|j|j|iƒj |jƒ} |j || fƒq¢W|rÞ||_|j|j|j iƒj |jƒ} |j|j|j iƒj |jƒ} |j|j|j iƒj |jƒ} | |_ | |_ | |_ q’WxÎ|jD]Ä} g}x²| jD]¨}g}x’|D]Š}|j dƒdk �rž|j|d|diƒj |dƒ} nd} |j dƒdk �rÔ|j|d|diƒj |dƒ} nd} |j t|d| | d�ƒ�qhW|j |ƒ�qZW|| _�qJWdS)NrþrrHr^rFr_)rFr^r_)rªrRrHr«rtr8r¦r‰rFr`rcr^r_rˆrdrVr�)rÚitemr1r-Z glyphMasterr‡ZnewMaprØrÙZnewOutputValuer^r_rˆr\ZnewConditionSetsraZ newConditionsrÍrrrÚ normalize sF       ""zDesignSpaceDocument.normalizecKs�i}g}x‚|jD]x}|jdk r,|j|jƒq|j|krD||j|_n8|jdkr`td|jpZdƒ‚||jf|Ž|_|j||j<|j|jƒqW|S)a¢Ensure SourceDescriptor.font attributes are loaded, and return list of fonts. Takes a callable which initializes a new font object (e.g. TTFont, or defcon.Font, etc.) from the SourceDescriptor.path, and sets the SourceDescriptor.font attribute. If the font attribute is already not None, it is not loaded again. Fonts with the same path are only loaded once and shared among SourceDescriptors. For example, to load UFO sources using defcon: designspace = DesignSpaceDocument.fromfile("path/to/my.designspace") designspace.loadSourceFonts(defcon.Font) Or to load masters as FontTools binary fonts, including extra options: designspace.loadSourceFonts(ttLib.TTFont, recalcBBoxes=False) Args: opener (Callable): takes one required positional argument, the source.path, and an optional list of keyword arguments, and returns a new font object loaded from the path. **kwargs: extra options passed on to the opener function. Returns: List of font objects in the order they appear in the sources list. Nz/Designspace source '%s' has no 'path' attributez )rªrQrcrr rF)rÚopenerr>ZloadedZfontsrDrrrÚloadSourceFontsRs       z#DesignSpaceDocument.loadSourceFonts)NN)NN)NN)N)TTF) r-r.r/rCr)rr0r r5rr¶r:r8r=r?r@rArCrDrErFrÁrJrKrLrMrNrOr1rRrTrVrrrrr s<      0 2)$ZfontTools.misc.loggingToolsrZfontTools.misc.textToolsrrrGÚiorrrrZfontTools.miscrržrÚ__all__ZXML_NSrÕrr&Ú Exceptionr Úobjectr0r=r rr]rXrgr r†r rrr rrrrÚs@     AZ;9]