这是Python可解析的已知数据格式吗?

时间:2018-06-03 12:38:25

标签: python python-3.x true-type-fonts

这是一种可以被Python解析为dict或其他数据结构的格式吗?当然,任何格式都可以解析,但我想知道这种格式是否已知"已知"并且可以由一些现有的库解析或者解析必须是手写的吗?

这是fc-scan

提供的请求字体信息的输出

我可以在这里看到输出: fc-scan : family /usr/share/fonts/truetype/yaldevicolombo/YaldeviColombo-ExtraLight.ttf

(venv35) ubuntu@ip-10-0-0-196:~/font/fonts-master$ fc-scan : family /usr/share/fonts/truetype/yaldevicolombo/YaldeviColombo-ExtraLight.ttf
Pattern has 23 elts (size 32)
    family: "Yaldevi Colombo ExtraLight"(s) "Yaldevi Colombo"(s)
    familylang: "en"(s) "en"(s)
    style: "Regular"(s) "ExtraLight"(s)
    stylelang: "en"(s) "en"(s)
    fullname: "Yaldevi Colombo ExtraLight"(s)
    fullnamelang: "en"(s)
    slant: 0(i)(s)
    weight: 48(i)(s)
    width: 100(i)(s)
    foundry: "unknown"(s)
    file: "/usr/share/fonts/truetype/yaldevicolombo/YaldeviColombo-ExtraLight.ttf"(s)
    index: 0(i)(s)
    outline: True(s)
    scalable: True(s)
    charset:
    0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffffffff ffffffff ffffffff
    0001: cfcff0ff 7ec3cc0c cfff31fe 7f0fcc3f 00040000 00000000 00000000 00000000
    0002: 0f000000 00000000 00000000 00000000 00000000 00000000 3f0002c0 00000000
    0003: 00000000 00000000 00000000 00000000 00000000 00000000 00000001 00000000
    000d: 00000000 00000000 00000000 00000000 fc7fffec 2ffbffff ff5f847f 001c0000
    0020: 77183000 06010047 00000010 00000000 00000000 24001000 00000000 00000000
    0021: 00080000 00004044 00000000 00000000 00000000 00000000 00000000 00000000
    0022: 46268044 00000800 00000100 00000031 00000000 00000000 00000000 00000000
    0025: 00000000 00000000 00000000 00000000 00000000 00000000 00001400 00000000
    00fb: 00000006 00000000 00000000 00000000 00000000 00000000 00000000 00000000
(s)
    lang: aa|ay|bi|br|bs|ch|co|cs|da|de|en|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|io|is|it|lb|lt|lv|mg|mh|nb|nds|nl|nn|no|nr|nso|oc|om|pl|pt|rm|ro|si|sk|sl|sma|smj|so|sq|ss|st|sv|sw|tk|tl|tn|tr|ts|uz|vo|vot|wa|wen|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s)
    fontversion: 66846(i)(s)
    capability: "otlayout:DFLT otlayout:sinh"(s)
    fontformat: "TrueType"(s)
    decorative: False(s)
    postscriptname: "YaldeviColombo-ExtraLight"(s)
    color: False(s)
    symbol: False(s)

(venv35) ubuntu@ip-10-0-0-196:~/font/fonts-master$

2 个答案:

答案 0 :(得分:1)

不,这看起来像是一种完全特定的人类可读输出格式,专门针对这种精确工具的特定模式。解析原始.ttf文件可能是一种更富有成效的方法。

答案 1 :(得分:0)

.ttf文件可以使用fontTools库使用python进行操作(并转换为/从xml转换):

https://pypi.python.org/pypi/FontTools

from fontTools.ttLib import TTFont

font_path = "/usr/share/fonts/truetype/yaldevicolombo/YaldeviColombo-ExtraLight.ttf"

font = TTFont(font_path)
print(font)
<fontTools.ttLib.TTFont object at 0x10c34ed50>