js分析 猫_眼_电_影 字体文件 @font-face
2018-05-12 21:35
459 查看
0. 参考
https://developer.mozilla.org/zh-CN/docs/Web/CSS/@font-face
这是一个叫做@font-face 的CSS @规则 ,它允许网页开发者为其网页指定在线字体。 通过这种作者自备字体的方式,@font-face 可以消除对用户电脑字体的依赖。
反爬虫解析-字体替换(天眼查/猫眼电影) https://www.jianshu.com/p/79c4272c0969
woff 转 xml
猫眼破解数字反爬获取实时票房 https://zhuanlan.zhihu.com/p/33112359
专用工具 Font Creator 查看字体文件
1. 页面表现
In [3]: from fontTools.ttLib import TTFont In [4]: font1 = TTFont('font1.woff') In [5]: font2 = TTFont('font2.woff') In [6]: font1_8 = font1['glyf']['uniEF04'] ...: font2_8 = font2['glyf']['uniF72A'] ...: font1_4 = font1['glyf']['uniF380'] ...: font2_7 = font2['glyf']['uniF722'] ...: In [7]: font1_8? Type: Glyph String form: <fontTools.ttLib.tables._g_l_y_f.Glyph object at 0x000000000573A978> File: e:\programdata\anaconda3\envs\py3\lib\site-packages\fonttools\ttlib\tables\_g_l_y_f.py Docstring: <no docstring> In [8]: font1_8.coordinates Out[8]: GlyphCoordinates([(177, 388),(69, 428),(69, 534),(69, 614),(181, 719),(369, 719),(483, 608),(483, 532),(483, 428),(377, 388),(443, 366),(512, 271),(512, 205),(512, 112),(382, -12),(170, -12),(105, 50),(41, 110),(41, 207),(41, 277),(111, 371),(159, 537),(159, 485),(225, 422),(277, 422),(325, 422),(360, 454),(393, 485),(393, 579),(326, 646),(224, 646),(159, 582),(131, 207),(131, 168),(165, 99),(202, 79),(236, 60),(277, 60),(309, 60),(360, 81),(381, 101),(422, 140),(422, 268),(338, 350),(212, 350),(131, 269)]) In [9]: font2_8.coordinates Out[9]: GlyphCoordinates([(177, 388),(69, 428),(69, 534),(69, 614),(181, 719),(369, 719),(483, 608),(483, 532),(483, 428),(377, 388),(443, 366),(512, 271),(512, 205),(512, 112),(382, -12),(170, -12),(105, 50),(41, 110),(41, 207),(41, 277),(111, 371),(159, 537),(159, 485),(225, 422),(277, 422),(325, 422),(360, 454),(393, 485),(393, 579),(326, 646),(224, 646),(159, 582),(131, 207),(131, 168),(165, 99),(202, 79),(236, 60),(277, 60),(309, 60),(360, 81),(381, 101),(422, 140),(422, 268),(338, 350),(212, 350),(131, 269)]) In [11]: font1_8.coordinates == font2_8.coordinates Out[11]: True In [12]: font1_8 == font2_8 Out[12]: True In [13]: font1_4.coordinates Out[13]: GlyphCoordinates([(323, 0),(323, 171),(13, 171),(13, 252),(339, 716),(411, 716),(411, 252),(508, 252),(508, 171),(411, 171),(411, 0),(323, 252),(323, 575),(99, 252)]) In [14]: font2_7.coordinates Out[14]: GlyphCoordinates([(47, 622),(47, 707),(511, 707),(511, 638),(476, 602),(409, 505),(341, 384),(290, 261),(271, 197),(246, 107),(238, 0),(147, 0),(148, 42),(165, 144),(181, 204),(212, 324),(271, 435),(301, 492),(365, 584),(398, 622)]) In [15]: font1_4.coordinates != font2_7.coordinates Out[15]: True In [16]: font1_4 != font2_7 Out[16]: True In [17]: font1_4.coordinates != font1_8.coordinates Out[17]: True In [18]: font1_4 != font1_8 Out[18]: TrueView Code
3. 根据基准字体文件为新字体文件建立映射关系的代码实现
运行时访问不了 .coordinates 和 .compileCoordinates() 属性???'Glyph' object has no attribute 'coordinates'
from fontTools.ttLib import TTFont font1 = TTFont('font1.woff') print(font1['glyf'].keys()) keys = font1['glyf'].keys() values = list(' .4209716385') # 构建基准 {name: num} dict1 = dict((k,v) for k,v in zip(keys, values)) print(dict1) font2 = TTFont('font2.woff') dict2 = {} for key in font2['glyf'].keys(): for k, v in dict1.items(): # 通过比较 字形定义 填充新的name和num映射关系 if font1['glyf'][k] == font2['glyf'][key]: dict2[key] = v.strip() break print(dict2)
3.1 运行结果
3.2 通过下图确认输出 dict2 的正确性
相关文章推荐
- cocos2d js 使用 bmpfont生成的字体文件
- js分析 天_眼_查 字体文件
- 把vux中的@font-face为base64格式的字体信息解码成可用的字体文件
- 使用CSS3的 @font-face 显示自定义字体
- 利用private font改变PDF文件的字体
- 用JS分析、导出CSV文件
- 非网页安全字体不再依赖Cufon!CSS @font-face的使用
- 利用CSS3 @font-face使用图标字体
- CSS3用@font-face实现自定义英文字体
- 利用@font-face加载Web字体
- eclipse MyEclipse中安装 spket插件 js文件内容字体变小解决方案
- 【ttf 压缩】html网页引用中文字体,文件过大,加载缓慢的解决办法【字蛛】【web font】
- js生成pdf文件,支持中文字体,插入图片
- CSS @font-face(CSS 自定义字体)
- 利用private font改变PDF文件的字体
- 网页中导入特殊字体@font-face属性详解
- Flex中如何在mx:Style中用@font-face,在Flash SWF中嵌入字体
- 使用@font-face 属性 实现在网页中嵌入任意字体
- 非网页安全字体不再依赖Cufon!CSS @font-face的使用
- CSS3 关于@font-face引用中文字体解决办法