爬虫–简单woff文件的处理

2022-11-17 17:06:17 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

woff文件

Web开放字体格式(Web Open Font Format,简称WOFF)是一种网页所采用的字体格式标准。此字体格式发展于2009年,现在正由万维网联盟的Web字体工作小组标准化,以求成为推荐标准。此字体格式不但能够有效利用压缩来减少档案大小,并且不包含加密也不受DRM(数位著作权管理)限制。

而且有时候再页面接受的时候其返回的是一个字符串:如下

不过看其这个url,其实简单理解就是

data:font/truetype;charset=utf-8;base64, 字符串

有要尝试的可以试着用下面字符串:

代码语言:javascript复制
AAEAAAAKAIAAAwAgT1MvMgzfYhQAAAEoAAAAYGNtYXBVYMOIAAABpAAAAYpnbHlmxN0tQQAAA0gAAAQCaGVhZBhcfSYAAACsAAAANmhoZWEGtgFLAAAA5AAAACRobXR4ArwAAAAAAYgAAAAabG9jYQSIBa4AAAMwAAAAGG1heHABGABFAAABCAAAACBuYW1lUGhGMAAAB0wAAAJzcG9zdDbQaFwAAAnAAAAAiAABAAAAAQAA g95jl8PPPUACQPoAAAAANnIUd8AAAAA3S7nlAAS/ wCNgLiAAAACAACAAAAAAAAAAEAAAQk/qwAfgJYAAAARAISAAEAAAAAAAAAAAAAAAAAAAACAAEAAAALADkAAwAAAAAAAgAAAAoACgAAAP8AAAAAAAAABAIqAZAABQAIAtED0wAAAMQC0QPTAAACoABEAWkAAAIABQMAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUGZFZABAsVPxhgQk/qwAfgQkAVQAAAABAAAAAAAAAAAAAAAgAAAAZAAAAlgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAcAAEAAAAAAIQAAwABAAAAHAAEAGgAAAAWABAAAwAGsVOzFLOBtZTCVuEk4hfoduk38Yb//wAAsVOzFLOBtZTCVuEk4hfoduk38Yb//061TPVMhUpzPa0e3h3zF4sWzQ5/AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBgAAAAAAAAAAAAAAAAAAAAAAAA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zJ0dGYgZnJvbSBGb250ZWxsbyBwcm9qZWN0Lmh0dHA6Ly9mb250ZWxsby5jb20AQwByAGUAYQB0AGUAZAAgAGIAeQAgAGYAbwBuAHQALQBjAGEAcgByAGkAZQByAC4AUABpAG4AZwBGAGEAbgBnACAAUwBDAFIAZQBnAHUAbABhAHIALgBQAGkAbgBnAEYAYQBuAGcALQBTAEMALQBSAGUAZwB1AGwAYQByAFYAZQByAHMAaQBvAG4AIAAxAC4AMABHAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAHMAdgBnADIAdAB0AGYAIABmAHIAbwBtACAARgBvAG4AdABlAGwAbABvACAAcAByAG8AagBlAGMAdAAuAGgAdAB0AHAAOgAvAC8AZgBvAG4AdABlAGwAbABvAC4AYwBvAG0AAAIAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAsACwAAAQYBCQECAQcBCwEIAQQBBQEDAQoHdW5pYzI1Ngd1bmliMzE0B3VuaWI1OTQHdW5pYjE1Mwd1bmllODc2B3VuaWU5MzcHdW5pYjM4MQd1bmllMTI0B3VuaWUyMTcHdW5pZjE4Ng==

前面是格式。可以将其用python的字符串转成woff格式文件。

代码语言:javascript复制
import base64
with open('1.woff','wb') as f:
f.write( base64.b64decode(jsobject["woff"]) )

其转成woff格式的文件,需要用High-Logic FontCreator这个软件可以将其打开。

如下

woff文件转xml –fontTools

对于woff文件,其实有时候我们很难观察到其具体的逻辑是什么,或者说是很难总结其规律。那就是需要将其转换成xml文件,而这个xml文件,说实话个人也不是很懂,只能说是简单的解读。其中就需要一个第三方的插件fontTools。使用文档

安装fontTools

代码语言:javascript复制
pip install fontTools

fontTools使用其实很多,但是我用于其对字体进行逻辑整理,观察其规律。(用于爬虫)

将1.woff文件转成xml文件

代码语言:javascript复制
from fontTools.ttLib import TTFont
font=TTFont('1.woff')
font.saveXML('1.xml')

很简单,就是简单的两个命令然后输出xml文件,打开看一下:

代码语言:javascript复制
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="x00x01x00x00" ttLibVersion="4.25">
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="unie876"/>
<GlyphID id="2" name="unie124"/>
<GlyphID id="3" name="unic256"/>
<GlyphID id="4" name="unie937"/>
<GlyphID id="5" name="unif186"/>
<GlyphID id="6" name="unib381"/>
<GlyphID id="7" name="unib594"/>
<GlyphID id="8" name="unib153"/>
<GlyphID id="9" name="unib314"/>
<GlyphID id="10" name="unie217"/>
</GlyphOrder>
<head>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
<checkSumAdjustment value="0xfa0f798e"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00000000 00001001"/>
<unitsPerEm value="1000"/>
<created value="Sun Oct 13 04:00:31 2019"/>
<modified value="Tue Aug 3 12:31:16 2021"/>
<xMin value="18"/>
<yMin value="-20"/>
<xMax value="566"/>
<yMax value="738"/>
<macStyle value="00000000 00000000"/>
<lowestRecPPEM value="8"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="0"/>
</head>
<hhea>
<tableVersion value="0x00010000"/>
<ascent value="1060"/>
<descent value="-340"/>
<lineGap value="126"/>
<advanceWidthMax value="600"/>
<minLeftSideBearing value="0"/>
<minRightSideBearing value="68"/>
<xMaxExtent value="530"/>
<caretSlopeRise value="1"/>
<caretSlopeRun value="0"/>
<caretOffset value="0"/>
<reserved0 value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<metricDataFormat value="0"/>
<numberOfHMetrics value="2"/>
</hhea>
<maxp>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="0x10000"/>
<numGlyphs value="11"/>
<maxPoints value="57"/>
<maxContours value="3"/>
<maxCompositePoints value="0"/>
<maxCompositeContours value="0"/>
<maxZones value="2"/>
<maxTwilightPoints value="0"/>
<maxStorage value="10"/>
<maxFunctionDefs value="10"/>
<maxInstructionDefs value="0"/>
<maxStackElements value="255"/>
<maxSizeOfInstructions value="0"/>
<maxComponentElements value="0"/>
<maxComponentDepth value="0"/>
</maxp>
<OS_2>
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex' will be recalculated by the compiler -->
<version value="4"/>
<xAvgCharWidth value="554"/>
<usWeightClass value="400"/>
<usWidthClass value="5"/>
<fsType value="00000000 00001000"/>
<ySubscriptXSize value="721"/>
<ySubscriptYSize value="979"/>
<ySubscriptXOffset value="0"/>
<ySubscriptYOffset value="196"/>
<ySuperscriptXSize value="721"/>
<ySuperscriptYSize value="979"/>
<ySuperscriptXOffset value="0"/>
<ySuperscriptYOffset value="672"/>
<yStrikeoutSize value="68"/>
<yStrikeoutPosition value="361"/>
<sFamilyClass value="0"/>
<panose>
<bFamilyType value="2"/>
<bSerifStyle value="0"/>
<bWeight value="5"/>
<bProportion value="3"/>
<bContrast value="0"/>
<bStrokeVariation value="0"/>
<bArmStyle value="0"/>
<bLetterForm value="0"/>
<bMidline value="0"/>
<bXHeight value="0"/>
</panose>
<ulUnicodeRange1 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange2 value="00010000 00000000 00000000 00000000"/>
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
<achVendID value="PfEd"/>
<fsSelection value="00000000 01000000"/>
<usFirstCharIndex value="45395"/>
<usLastCharIndex value="61830"/>
<sTypoAscender value="1060"/>
<sTypoDescender value="-340"/>
<sTypoLineGap value="126"/>
<usWinAscent value="1060"/>
<usWinDescent value="340"/>
<ulCodePageRange1 value="00000000 00000000 00000000 00000001"/>
<ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
<sxHeight value="0"/>
<sCapHeight value="0"/>
<usDefaultChar value="0"/>
<usBreakChar value="32"/>
<usMaxContext value="0"/>
</OS_2>
<hmtx>
<mtx name=".notdef" width="100" lsb="0"/>
<mtx name="unib153" width="600" lsb="0"/>
<mtx name="unib314" width="600" lsb="0"/>
<mtx name="unib381" width="600" lsb="0"/>
<mtx name="unib594" width="600" lsb="0"/>
<mtx name="unic256" width="600" lsb="0"/>
<mtx name="unie124" width="600" lsb="0"/>
<mtx name="unie217" width="600" lsb="0"/>
<mtx name="unie876" width="600" lsb="0"/>
<mtx name="unie937" width="600" lsb="0"/>
<mtx name="unif186" width="600" lsb="0"/>
</hmtx>
<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
<map code="0xb153" name="unib153"/><!-- HANGUL SYLLABLE NYEOS -->
<map code="0xb314" name="unib314"/><!-- HANGUL SYLLABLE DAESS -->
<map code="0xb381" name="unib381"/><!-- HANGUL SYLLABLE DEB -->
<map code="0xb594" name="unib594"/><!-- HANGUL SYLLABLE DDYAEM -->
<map code="0xc256" name="unic256"/><!-- HANGUL SYLLABLE SWENH -->
<map code="0xe124" name="unie124"/><!-- ???? -->
<map code="0xe217" name="unie217"/><!-- ???? -->
<map code="0xe876" name="unie876"/><!-- ???? -->
<map code="0xe937" name="unie937"/><!-- ???? -->
<map code="0xf186" name="unif186"/><!-- ???? -->
</cmap_format_4>
<cmap_format_0 platformID="1" platEncID="0" language="0">
</cmap_format_0>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0xb153" name="unib153"/><!-- HANGUL SYLLABLE NYEOS -->
<map code="0xb314" name="unib314"/><!-- HANGUL SYLLABLE DAESS -->
<map code="0xb381" name="unib381"/><!-- HANGUL SYLLABLE DEB -->
<map code="0xb594" name="unib594"/><!-- HANGUL SYLLABLE DDYAEM -->
<map code="0xc256" name="unic256"/><!-- HANGUL SYLLABLE SWENH -->
<map code="0xe124" name="unie124"/><!-- ???? -->
<map code="0xe217" name="unie217"/><!-- ???? -->
<map code="0xe876" name="unie876"/><!-- ???? -->
<map code="0xe937" name="unie937"/><!-- ???? -->
<map code="0xf186" name="unif186"/><!-- ???? -->
</cmap_format_4>
</cmap>
<loca>
<!-- The 'loca' table will be calculated by the compiler -->
</loca>
<glyf>
<!-- The xMin, yMin, xMax and yMax values will be recalculated by the compiler. -->
<TTGlyph name=".notdef" xMin="18" yMin="-20" xMax="50" yMax="14">
<contour>
<pt x="18" y="14" on="1"/>
<pt x="50" y="14" on="1"/>
<pt x="50" y="-20" on="1"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unib153" xMin="36" yMin="-14" xMax="557" yMax="738">
<contour>
<pt x="329" y="738" on="1"/>
<pt x="188" y="738" on="0"/>
<pt x="123" y="661" on="1"/>
<pt x="54" y="614" on="0"/>
<pt x="54" y="533" on="1"/>
<pt x="54" y="490" on="0"/>
<pt x="92" y="469" on="1"/>
<pt x="159" y="411" on="0"/>
<pt x="165" y="385" on="1"/>
<pt x="165" y="376" on="1"/>
<pt x="109" y="357" on="0"/>
<pt x="80" y="349" on="1"/>
<pt x="36" y="265" on="0"/>
<pt x="36" y="190" on="1"/>
<pt x="36" y="99" on="0"/>
<pt x="187" y="-14" on="0"/>
<pt x="416" y="-14" on="0"/>
<pt x="487" y="48" on="1"/>
<pt x="557" y="99" on="0"/>
<pt x="557" y="190" on="1"/>
<pt x="557" y="265" on="0"/>
<pt x="501" y="349" on="1"/>
<pt x="487" y="357" on="0"/>
<pt x="416" y="376" on="1"/>
<pt x="416" y="385" on="1"/>
<pt x="464" y="411" on="0"/>
<pt x="522" y="469" on="1"/>
<pt x="520" y="490" on="0"/>
<pt x="520" y="533" on="1"/>
<pt x="520" y="614" on="0"/>
<pt x="464" y="661" on="1"/>
<pt x="416" y="738" on="0"/>
</contour>
<contour>
<pt x="329" y="653" on="1"/>
<pt x="371" y="653" on="0"/>
<pt x="412" y="640" on="1"/>
<pt x="444" y="591" on="0"/>
<pt x="444" y="490" on="0"/>
<pt x="416" y="438" on="1"/>
<pt x="398" y="402" on="0"/>
<pt x="236" y="402" on="0"/>
<pt x="164" y="438" on="1"/>
<pt x="159" y="490" on="0"/>
<pt x="159" y="591" on="0"/>
<pt x="166" y="640" on="1"/>
<pt x="243" y="653" on="0"/>
</contour>
<contour>
<pt x="329" y="350" on="1"/>
<pt x="379" y="350" on="0"/>
<pt x="448" y="299" on="1"/>
<pt x="487" y="252" on="0"/>
<pt x="487" y="132" on="0"/>
<pt x="448" y="91" on="1"/>
<pt x="385" y="97" on="0"/>
<pt x="212" y="97" on="0"/>
<pt x="109" y="132" on="0"/>
<pt x="109" y="252" on="0"/>
<pt x="165" y="299" on="1"/>
<pt x="212" y="350" on="0"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unib314" xMin="36" yMin="0" xMax="566" yMax="701">
<contour>
<pt x="398" y="701" on="1"/>
<pt x="36" y="240" on="1"/>
<pt x="36" y="149" on="1"/>
<pt x="398" y="149" on="1"/>
<pt x="398" y="0" on="1"/>
<pt x="456" y="0" on="1"/>
<pt x="456" y="149" on="1"/>
<pt x="566" y="149" on="1"/>
<pt x="566" y="219" on="1"/>
<pt x="456" y="219" on="1"/>
<pt x="456" y="701" on="1"/>
</contour>
<contour>
<pt x="376" y="600" on="1"/>
<pt x="398" y="600" on="1"/>
<pt x="398" y="219" on="1"/>
<pt x="125" y="219" on="1"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unib381" xMin="50" yMin="-14" xMax="537" yMax="738">
<contour>
<pt x="286" y="738" on="1"/>
<pt x="187" y="738" on="0"/>
<pt x="50" y="591" on="0"/>
<pt x="50" y="477" on="1"/>
<pt x="50" y="380" on="0"/>
<pt x="108" y="317" on="1"/>
<pt x="173" y="268" on="0"/>
<pt x="266" y="268" on="1"/>
<pt x="340" y="243" on="0"/>
<pt x="437" y="299" on="0"/>
<pt x="476" y="385" on="1"/>
<pt x="458" y="385" on="1"/>
<pt x="474" y="332" on="1"/>
<pt x="474" y="219" on="0"/>
<pt x="413" y="127" on="1"/>
<pt x="371" y="55" on="0"/>
<pt x="286" y="55" on="1"/>
<pt x="165" y="55" on="0"/>
<pt x="159" y="173" on="1"/>
<pt x="50" y="173" on="1"/>
<pt x="86" y="-14" on="0"/>
<pt x="289" y="-14" on="1"/>
<pt x="403" y="-13" on="0"/>
<pt x="496" y="99" on="1"/>
<pt x="537" y="207" on="0"/>
<pt x="537" y="363" on="1"/>
<pt x="537" y="540" on="0"/>
<pt x="487" y="678" on="1"/>
<pt x="416" y="738" on="0"/>
</contour>
<contour>
<pt x="289" y="678" on="1"/>
<pt x="357" y="678" on="0"/>
<pt x="400" y="604" on="1"/>
<pt x="461" y="547" on="0"/>
<pt x="461" y="411" on="0"/>
<pt x="354" y="317" on="0"/>
<pt x="289" y="317" on="1"/>
<pt x="205" y="317" on="0"/>
<pt x="159" y="411" on="0"/>
<pt x="159" y="477" on="1"/>
<pt x="159" y="556" on="0"/>
<pt x="213" y="678" on="0"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unib594" xMin="50" yMin="-14" xMax="537" yMax="701">
<contour>
<pt x="103" y="701" on="1"/>
<pt x="54" y="318" on="1"/>
<pt x="159" y="318" on="1"/>
<pt x="165" y="350" on="0"/>
<pt x="236" y="384" on="1"/>
<pt x="250" y="405" on="0"/>
<pt x="329" y="405" on="1"/>
<pt x="375" y="396" on="0"/>
<pt x="459" y="317" on="0"/>
<pt x="459" y="219" on="1"/>
<pt x="459" y="137" on="0"/>
<pt x="357" y="79" on="0"/>
<pt x="305" y="79" on="1"/>
<pt x="236" y="79" on="0"/>
<pt x="178" y="85" on="1"/>
<pt x="138" y="114" on="0"/>
<pt x="159" y="180" on="1"/>
<pt x="50" y="180" on="1"/>
<pt x="50" y="91" on="0"/>
<pt x="144" y="41" on="1"/>
<pt x="188" y="-14" on="0"/>
<pt x="289" y="-14" on="1"/>
<pt x="388" y="-14" on="0"/>
<pt x="461" y="58" on="1"/>
<pt x="537" y="105" on="0"/>
<pt x="537" y="219" on="1"/>
<pt x="537" y="342" on="0"/>
<pt x="414" y="469" on="0"/>
<pt x="312" y="469" on="1"/>
<pt x="261" y="474" on="0"/>
<pt x="236" y="453" on="1"/>
<pt x="170" y="458" on="0"/>
<pt x="147" y="411" on="1"/>
<pt x="159" y="411" on="1"/>
<pt x="157" y="678" on="1"/>
<pt x="522" y="678" on="1"/>
<pt x="522" y="701" on="1"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unic256" xMin="50" yMin="-14" xMax="537" yMax="738">
<contour>
<pt x="329" y="738" on="1"/>
<pt x="179" y="738" on="0"/>
<pt x="126" y="624" on="1"/>
<pt x="50" y="501" on="0"/>
<pt x="50" y="332" on="1"/>
<pt x="50" y="179" on="0"/>
<pt x="125" y="70" on="1"/>
<pt x="165" y="-13" on="0"/>
<pt x="301" y="-14" on="1"/>
<pt x="403" y="-13" on="0"/>
<pt x="537" y="127" on="0"/>
<pt x="537" y="344" on="0"/>
<pt x="421" y="469" on="0"/>
<pt x="319" y="469" on="1"/>
<pt x="248" y="469" on="0"/>
<pt x="200" y="425" on="1"/>
<pt x="165" y="405" on="0"/>
<pt x="132" y="342" on="1"/>
<pt x="159" y="342" on="1"/>
<pt x="126" y="363" on="1"/>
<pt x="126" y="484" on="0"/>
<pt x="164" y="566" on="1"/>
<pt x="215" y="656" on="0"/>
<pt x="301" y="678" on="1"/>
<pt x="424" y="656" on="0"/>
<pt x="461" y="538" on="1"/>
<pt x="536" y="538" on="1"/>
<pt x="501" y="724" on="0"/>
</contour>
<contour>
<pt x="297" y="411" on="1"/>
<pt x="376" y="423" on="0"/>
<pt x="421" y="349" on="1"/>
<pt x="480" y="309" on="0"/>
<pt x="480" y="140" on="0"/>
<pt x="413" y="91" on="1"/>
<pt x="367" y="79" on="0"/>
<pt x="297" y="55" on="1"/>
<pt x="231" y="55" on="0"/>
<pt x="188" y="96" on="1"/>
<pt x="159" y="147" on="0"/>
<pt x="159" y="293" on="0"/>
<pt x="232" y="411" on="0"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unie124" xMin="50" yMin="-14" xMax="537" yMax="738">
<contour>
<pt x="329" y="738" on="1"/>
<pt x="165" y="724" on="0"/>
<pt x="101" y="624" on="1"/>
<pt x="50" y="529" on="0"/>
<pt x="50" y="205" on="0"/>
<pt x="101" y="90" on="1"/>
<pt x="165" y="-14" on="0"/>
<pt x="424" y="-14" on="0"/>
<pt x="481" y="90" on="1"/>
<pt x="537" y="205" on="0"/>
<pt x="537" y="529" on="0"/>
<pt x="481" y="624" on="1"/>
<pt x="424" y="724" on="0"/>
</contour>
<contour>
<pt x="329" y="656" on="1"/>
<pt x="385" y="656" on="0"/>
<pt x="435" y="550" on="1"/>
<pt x="480" y="477" on="0"/>
<pt x="480" y="226" on="0"/>
<pt x="435" y="153" on="1"/>
<pt x="385" y="57" on="0"/>
<pt x="196" y="57" on="0"/>
<pt x="165" y="153" on="1"/>
<pt x="159" y="226" on="0"/>
<pt x="159" y="477" on="0"/>
<pt x="165" y="550" on="1"/>
<pt x="196" y="656" on="0"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unie217" xMin="50" yMin="-14" xMax="537" yMax="738">
<contour>
<pt x="297" y="738" on="1"/>
<pt x="191" y="738" on="0"/>
<pt x="159" y="661" on="1"/>
<pt x="76" y="601" on="0"/>
<pt x="80" y="504" on="1"/>
<pt x="144" y="504" on="1"/>
<pt x="163" y="575" on="0"/>
<pt x="240" y="656" on="0"/>
<pt x="305" y="652" on="1"/>
<pt x="375" y="656" on="0"/>
<pt x="421" y="640" on="1"/>
<pt x="445" y="591" on="0"/>
<pt x="445" y="458" on="0"/>
<pt x="367" y="393" on="0"/>
<pt x="297" y="393" on="1"/>
<pt x="250" y="393" on="1"/>
<pt x="250" y="330" on="1"/>
<pt x="329" y="330" on="1"/>
<pt x="378" y="344" on="0"/>
<pt x="459" y="265" on="0"/>
<pt x="459" y="127" on="0"/>
<pt x="421" y="97" on="1"/>
<pt x="367" y="79" on="0"/>
<pt x="329" y="79" on="1"/>
<pt x="243" y="57" on="0"/>
<pt x="190" y="90" on="1"/>
<pt x="130" y="139" on="0"/>
<pt x="138" y="210" on="1"/>
<pt x="50" y="210" on="1"/>
<pt x="58" y="87" on="0"/>
<pt x="159" y="36" on="1"/>
<pt x="187" y="-13" on="0"/>
<pt x="329" y="-14" on="1"/>
<pt x="400" y="-14" on="0"/>
<pt x="537" y="105" on="0"/>
<pt x="537" y="207" on="1"/>
<pt x="537" y="266" on="0"/>
<pt x="507" y="317" on="1"/>
<pt x="476" y="350" on="0"/>
<pt x="405" y="373" on="1"/>
<pt x="520" y="411" on="0"/>
<pt x="520" y="532" on="1"/>
<pt x="520" y="614" on="0"/>
<pt x="395" y="738" on="0"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unie876" xMin="80" yMin="0" xMax="520" yMax="701">
<contour>
<pt x="80" y="701" on="1"/>
<pt x="80" y="624" on="1"/>
<pt x="456" y="624" on="1"/>
<pt x="187" y="0" on="1"/>
<pt x="258" y="0" on="1"/>
<pt x="520" y="637" on="1"/>
<pt x="520" y="701" on="1"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unie937" xMin="99" yMin="0" xMax="369" yMax="701">
<contour>
<pt x="291" y="701" on="1"/>
<pt x="283" y="667" on="0"/>
<pt x="160" y="601" on="0"/>
<pt x="99" y="594" on="1"/>
<pt x="99" y="533" on="1"/>
<pt x="200" y="547" on="0"/>
<pt x="286" y="608" on="1"/>
<pt x="286" y="0" on="1"/>
<pt x="369" y="0" on="1"/>
<pt x="369" y="701" on="1"/>
</contour>
<instructions/>
</TTGlyph>
<TTGlyph name="unif186" xMin="58" yMin="0" xMax="536" yMax="738">
<contour>
<pt x="329" y="738" on="1"/>
<pt x="200" y="738" on="0"/>
<pt x="61" y="575" on="0"/>
<pt x="76" y="477" on="1"/>
<pt x="155" y="477" on="1"/>
<pt x="147" y="547" on="0"/>
<pt x="193" y="604" on="1"/>
<pt x="231" y="678" on="0"/>
<pt x="297" y="656" on="1"/>
<pt x="369" y="656" on="0"/>
<pt x="452" y="576" on="0"/>
<pt x="452" y="510" on="1"/>
<pt x="452" y="458" on="0"/>
<pt x="388" y="387" on="1"/>
<pt x="367" y="385" on="0"/>
<pt x="282" y="293" on="1"/>
<pt x="173" y="231" on="0"/>
<pt x="144" y="173" on="1"/>
<pt x="58" y="99" on="0"/>
<pt x="58" y="0" on="1"/>
<pt x="536" y="0" on="1"/>
<pt x="536" y="85" on="1"/>
<pt x="163" y="85" on="1"/>
<pt x="174" y="142" on="0"/>
<pt x="325" y="222" on="1"/>
<pt x="437" y="317" on="0"/>
<pt x="462" y="349" on="1"/>
<pt x="530" y="423" on="0"/>
<pt x="530" y="608" on="0"/>
<pt x="413" y="738" on="0"/>
</contour>
<instructions/>
</TTGlyph>
</glyf>
<name>
<namerecord nameID="0" platformID="1" platEncID="0" langID="0x0" unicode="True">
Created by font-carrier
</namerecord>
<namerecord nameID="1" platformID="1" platEncID="0" langID="0x0" unicode="True">
.PingFang SC
</namerecord>
<namerecord nameID="2" platformID="1" platEncID="0" langID="0x0" unicode="True">
Regular
</namerecord>
<namerecord nameID="3" platformID="1" platEncID="0" langID="0x0" unicode="True">
.PingFang-SC-Regular
</namerecord>
<namerecord nameID="4" platformID="1" platEncID="0" langID="0x0" unicode="True">
.PingFang-SC-Regular
</namerecord>
<namerecord nameID="5" platformID="1" platEncID="0" langID="0x0" unicode="True">
Version 1.0
</namerecord>
<namerecord nameID="6" platformID="1" platEncID="0" langID="0x0" unicode="True">
.PingFang-SC-Regular
</namerecord>
<namerecord nameID="10" platformID="1" platEncID="0" langID="0x0" unicode="True">
Generated by svg2ttf from Fontello project.
</namerecord>
<namerecord nameID="11" platformID="1" platEncID="0" langID="0x0" unicode="True">
http://fontello.com
</namerecord>
<namerecord nameID="0" platformID="3" platEncID="1" langID="0x409">
Created by font-carrier
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
.PingFang SC
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
Regular
</namerecord>
<namerecord nameID="3" platformID="3" platEncID="1" langID="0x409">
.PingFang-SC-Regular
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
.PingFang-SC-Regular
</namerecord>
<namerecord nameID="5" platformID="3" platEncID="1" langID="0x409">
Version 1.0
</namerecord>
<namerecord nameID="6" platformID="3" platEncID="1" langID="0x409">
.PingFang-SC-Regular
</namerecord>
<namerecord nameID="10" platformID="3" platEncID="1" langID="0x409">
Generated by svg2ttf from Fontello project.
</namerecord>
<namerecord nameID="11" platformID="3" platEncID="1" langID="0x409">
http://fontello.com
</namerecord>
</name>
<post>
<formatType value="2.0"/>
<italicAngle value="0.0"/>
<underlinePosition value="14"/>
<underlineThickness value="0"/>
<isFixedPitch value="0"/>
<minMemType42 value="0"/>
<maxMemType42 value="0"/>
<minMemType1 value="0"/>
<maxMemType1 value="11"/>
<psNames>
<!-- This file uses unique glyph names based on the information found in the 'post' table. Since these names might not be unique, we have to invent artificial names in case of clashes. In order to be able to retain the original information, we need a name to ps name mapping for those cases where they differ. That's what you see below. -->
</psNames>
<extraNames>
<!-- following are the name that are not taken from the standard Mac glyph order -->
<psName name="unic256"/>
<psName name="unib314"/>
<psName name="unib594"/>
<psName name="unib153"/>
<psName name="unie876"/>
<psName name="unie937"/>
<psName name="unib381"/>
<psName name="unie124"/>
<psName name="unie217"/>
<psName name="unif186"/>
</extraNames>
</post>
</ttFont>

开始下面是1到10的值如何获得

代码语言:javascript复制
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="unie876"/>
<GlyphID id="2" name="unie124"/>
<GlyphID id="3" name="unic256"/>
<GlyphID id="4" name="unie937"/>
<GlyphID id="5" name="unif186"/>
<GlyphID id="6" name="unib381"/>
<GlyphID id="7" name="unib594"/>
<GlyphID id="8" name="unib153"/>
<GlyphID id="9" name="unib314"/>
<GlyphID id="10" name="unie217"/>
</GlyphOrder>
代码语言:javascript复制
from fontTools.ttLib import TTFont
font=TTFont('1.woff')
uni_list = font.getGlyphOrder()
for uni in uni_list:
print(uni)
#输出
.notdef
unie876
…………
unie217

得到画图的轨迹参数: x,y

代码语言:javascript复制
 <TTGlyph name="unif186" xMin="58" yMin="0" xMax="536" yMax="738">
<contour>
<pt x="329" y="738" on="1"/>
<pt x="200" y="738" on="0"/>
<pt x="61" y="575" on="0"/>
<pt x="76" y="477" on="1"/>
<pt x="155" y="477" on="1"/>
<pt x="147" y="547" on="0"/>
<pt x="193" y="604" on="1"/>
<pt x="231" y="678" on="0"/>
<pt x="297" y="656" on="1"/>
<pt x="369" y="656" on="0"/>
<pt x="452" y="576" on="0"/>
<pt x="452" y="510" on="1"/>
<pt x="452" y="458" on="0"/>
<pt x="388" y="387" on="1"/>
<pt x="367" y="385" on="0"/>
<pt x="282" y="293" on="1"/>
<pt x="173" y="231" on="0"/>
<pt x="144" y="173" on="1"/>
<pt x="58" y="99" on="0"/>
<pt x="58" y="0" on="1"/>
<pt x="536" y="0" on="1"/>
<pt x="536" y="85" on="1"/>
<pt x="163" y="85" on="1"/>
<pt x="174" y="142" on="0"/>
<pt x="325" y="222" on="1"/>
<pt x="437" y="317" on="0"/>
<pt x="462" y="349" on="1"/>
<pt x="530" y="423" on="0"/>
<pt x="530" y="608" on="0"/>
<pt x="413" y="738" on="0"/>
</contour>
<instructions/>
</TTGlyph>
代码语言:javascript复制
 for i in font['glyf']["unif186"].coordinates:
print(i)
#输出
(329,738)
…………
(413,738)

当然也可以得到这个轨迹中的on的值

代码语言:javascript复制
for i in font['glyf']["unif186"].flags:
print(i)
#输出 
1
0
………………
0

不过由于对文档的具体参数属性不太属性,所以暂时不知on的值有什么意义。

可以使用pyplot 对其进行画图看一下可以画出数字的

代码语言:javascript复制
import matplotlib.pyplot as plt
import re
str = """ <TTGlyph name="unif186" xMin="58" yMin="0" xMax="536" yMax="738"> <contour> <pt x="329" y="738" on="1"/> <pt x="200" y="738" on="0"/> <pt x="61" y="575" on="0"/> <pt x="76" y="477" on="1"/> <pt x="155" y="477" on="1"/> <pt x="147" y="547" on="0"/> <pt x="193" y="604" on="1"/> <pt x="231" y="678" on="0"/> <pt x="297" y="656" on="1"/> <pt x="369" y="656" on="0"/> <pt x="452" y="576" on="0"/> <pt x="452" y="510" on="1"/> <pt x="452" y="458" on="0"/> <pt x="388" y="387" on="1"/> <pt x="367" y="385" on="0"/> <pt x="282" y="293" on="1"/> <pt x="173" y="231" on="0"/> <pt x="144" y="173" on="1"/> <pt x="58" y="99" on="0"/> <pt x="58" y="0" on="1"/> <pt x="536" y="0" on="1"/> <pt x="536" y="85" on="1"/> <pt x="163" y="85" on="1"/> <pt x="174" y="142" on="0"/> <pt x="325" y="222" on="1"/> <pt x="437" y="317" on="0"/> <pt x="462" y="349" on="1"/> <pt x="530" y="423" on="0"/> <pt x="530" y="608" on="0"/> <pt x="413" y="738" on="0"/> </contour> <instructions/> </TTGlyph> """
x = [int(i) for i in re.findall(r'<pt x="(.*?)" y=', str)]
y = [int(i) for i in re.findall(r'y="(.*?)" on=', str)]
plt.plot(x, y)
plt.show()

具体如下

大概可以看出一个数字2.其中将on的值全部改成0或者1好像也不影响图片。所以不太懂。

因为一共就10个数字,有时候对于返回的比如name=”unif186″对应的数字,进行一次训练即可知道其代表的是数字多少,这个就10个还好训练,以及数字格式不变,可以简单将x,y的值作为一个数字判断依据。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/213465.html原文链接:https://javaforall.cn

0 人点赞