python ttf svg path_解析svg:path d属性

Copyright2012ChristopherL.RamseyLicensedunder theApacheLicense,Version2.0(the"License");you maynotuse this fileexceptincompliancewiththeLicense.Youmay obtain a copy of theLicenseat

http://www.apache.org/licenses/LICENSE-2.0Unlessrequired by applicable laworagreed toinwriting,software

distributed under theLicenseisdistributed on an"AS IS"BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either expressorimplied.SeetheLicenseforthe specific language governing permissionsandlimitations under theLicense.fromcollectionsimportOrderedDictfromreimportmatchfromreimportsplitfromreimportsubclassPathIterator(object):EOI='End of Iteration'PATH_IDENTIFIERS=r'[MLHVCSQTAmlhvcsqa]'NUMBERS=r'[0-9.-^A-z]'SEPERATORS=r'\s|\,'PATH_END=r'[Zz]'def__init__(self,path):self.parseable=path.translate(None,'\t\f')self.parseable=self.parseable.replace('\n',' ')print'strip_newlines: {}'.format(self.parseable)self.parseable=sub(r'([A-Za-z])([0-9]|\-)',self.insert,self.parseable)print'add_space: {}'.format(self.parseable)self.parseable=self.parseable.replace(',',' ')print'replace_commas: {}'.format(self.parseable)self.parseable=sub(r'\s+',' ',self.parseable)# replace any double space with a single spaceprint'strip_extra_space: {}'.format(self.parseable)self.tokens=split(' ',self.parseable)self.map=self.produce_map(self.tokens)printself.map

self.elements=self.process(self.map)defproduce_map(self,tkns):self.m=OrderedDict()self.i=0whileself.i

M600,350 l 50,-25

a25,25 -30 0,1 50,-25 l 50,-25

a25,50 -30 0,1 50,-25 l 50,-25

a25,75 -30 0,1 50,-25 l 50,-25

a25,100 -30 0,1 50,-25 l 50,-25

'''paths=[inkscape_path,mdn_path,w3c_path,str.strip(w3c_path_nl),w3c_path_neg]forpathinpaths:p=PathIterator(path)char=''whilechar!=PathIterator.EOI:char=p.next()printchar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值