java ttf

编程入门 行业动态 更新时间:2024-10-08 08:32:34

<a href=https://www.elefans.com/category/jswz/34/1770091.html style=java ttf"/>

java ttf

#安装python包

pip3 install fonttoos

pip3 install reportlab

ttftoImages.py 脚本

from __future__ import print_function, division, absolute_import

from fontTools.ttLib import TTFont

from fontTools.pens.basePen import BasePen

from reportlab.graphics.shapes import Path

from reportlab.lib import colors

from reportlab.graphics import renderPM

from reportlab.graphics.shapes import Group, Drawing, scale

class ReportLabPen(BasePen):

"""A pen for drawing onto a reportlab.graphics.shapes.Path object."""

def __init__(self, glyphSet, path=None):

BasePen.__init__(self, glyphSet)

if path is None:

path = Path()

self.path = path

def _moveTo(self, p):

(x,y) = p

self.path.moveTo(x,y)

def _lineTo(self, p):

(x,y) = p

self.path.lineTo(x,y)

def _curveToOne(self, p1, p2, p3):

(x1,y1) = p1

(x2,y2) = p2

(x3,y3) = p3

self.path.curveTo(x1, y1, x2, y2, x3, y3)

def _closePath(self):

self.path.closePath()

def ttfToImage(fontName,imagePath,fmt="png"):

font = TTFont(fontName)

gs = font.getGlyphSet()

glyphNames = font.getGlyphNames()

for i in glyphNames:

if i[0] == '.':#跳过'.notdef', '.null'

continue

g = gs[i]

pen = ReportLabPen(gs, Path(fillColor=colors.red, strokeWidth=5))

g.draw(pen)

w, h = g.width, g.width

g = Group(pen.path)

g.translate(0, 200)

d = Drawing(w, h)

d.add(g)

imageFile = imagePath+"/"+i+".png"

renderPM.drawToFile(d, imageFile, fmt)

print(i)

# break;

# print(glyphNames)

ttfToImage(fontName="AAVUNG+DFKai-SB-B5pc-H-0225.ttf",imagePath="images")

转载至链接:

更多推荐

java ttf

本文发布于:2024-02-13 08:18:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1757556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java   ttf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!