在Python中测试一个glyph是否是同一字体中另一个glyph的反射
受此启发,我试图找到一个给定字体中所有unicode标志符号的列表,它们是彼此的反映。首先,我只需要能够测试一个标志符号是否是另一个标志符号的反射。下面我有两种不同的尝试(我的在Python中测试一个glyph是否是同一字体中另一个glyph的反射,python,fonts,python-imaging-library,glyph,Python,Fonts,Python Imaging Library,Glyph,受此启发,我试图找到一个给定字体中所有unicode标志符号的列表,它们是彼此的反映。首先,我只需要能够测试一个标志符号是否是另一个标志符号的反射。下面我有两种不同的尝试(我的render_char函数的两种不同实现),但我无法使用其中任何一种将“(”和“')”识别为镜像。我该怎么做 from PIL import Image,ImageDraw,ImageFont import freetype import numpy as np def render_char0(c): # Ba
render_char
函数的两种不同实现),但我无法使用其中任何一种将“(”和“')”识别为镜像。我该怎么做
from PIL import Image,ImageDraw,ImageFont
import freetype
import numpy as np
def render_char0(c):
# Based on https://github.com/rougier/freetype-py/blob/master/examples/hello-world.py
# Needs numpy (blech) and the image comes out the inverse of the way I expect
face = freetype.Face("/Library/Fonts/Verdana.ttf")
face.set_char_size( 48*64 )
face.load_char(c)
bitmap = face.glyph.bitmap
w,h = bitmap.width, bitmap.rows
Z = np.array(bitmap.buffer, dtype=np.ubyte).reshape(h,w)
return Image.fromarray(Z, mode='L').convert('1')
def render_char1(c):
# Based on https://stackoverflow.com/a/14446201/2829764
verdana_font = ImageFont.truetype("/Library/Fonts/Verdana.ttf", 20, encoding="unic")
text_width, text_height = verdana_font.getsize(c)
canvas = Image.new('RGB', (text_width+10, text_height+10), (255, 255, 255))
draw = ImageDraw.Draw(canvas)
draw.text((5,5), c, font = verdana_font, fill = "#000000")
return canvas
for render_char in [render_char0, render_char1]:
lparen = render_char('(')
rparen = render_char(')')
mirror = lparen.transpose(Image.FLIP_LEFT_RIGHT)
mirror.show()
rparen.show()
print mirror.tobytes() == rparen.tobytes() # False
Unicode纯文本数据库中有一个名为
BidiMirroring.txt
的文本文件,其中包含所有镜像字符的列表。这个文件很容易被程序解析
当前url为
我认为使用渲染的glyph无法可靠地工作。有很多原因,例如,
(
和)
没有精确的镜像,比如字符周围的间距、暗示和抗锯齿,可能字体稍微倾斜,或者可能字体设计师只是使两个括号稍有不同等等。其他字符是旋转的,而不是镜像的,比如“
和”
在某些字体中,以及中文引号“
和”
在Unicode纯文本数据库中有一个名为BidiMirroring.txt
的文本文件,其中包含所有镜像字符的列表。该文件很容易被程序解析
当前url为
我不认为使用渲染的图示符可以可靠地工作。原因有很多,例如
(
和)
没有精确的镜像,如字符周围的间距、提示和抗锯齿,可能字体略微倾斜,或者字体设计师只是使两个括号稍微不同,等等。其他字符是旋转的,而不是镜像的,如“
和”
在一些字体中,以及中文引号“
和”
我认为渲染是错误的。这取决于字体以及字体是否知道如何渲染。我听说unicode字符对这种对称性有一个规范。可能是用它们的名称编码的。“左”和“右”下标。看一看我认为渲染是错误的做法。这取决于字体以及字体是否知道如何渲染。我听说unicode字符对这种对称性有一个规范。可能是用它们的名称编码的。“左”和“右”下标.看一看我认为rendering是一种错误的方法。这取决于字体以及字体是否知道如何呈现这种对称性。我听说unicode字符对此有一个规范。可能是用它们的名称编码的。“左”和“右”下标.看一看我认为rendering是错误的方法。这取决于字体以及字体是否知道如何呈现这种对称性。我听说unicode字符对此有一个规范。可能是用它们的名称编码的。“左”和“右”下标。看一看