[英]How do I render text with pixel heights rather than points in pyglet?
Pyglet only seems to use points. Pyglet似乎只使用点。 Is there a way to convert easily?
有没有一种容易转换的方法? Surely there must be a simple way because it's something obviously important, to be able to use pixels for text height.
当然,必须有一种简单的方法,因为它很明显很重要,它能够使用像素表示文本高度。
class Font():
def __init__(self,font,size):
self.size = size
self.font = font
def return_surface(self,label):
surface = Surface((label.content_width,label.content_height))
surface.set_background_alpha(0)
setup_framebuffer(surface,True)
label.draw()
end_framebuffer()
return surface
def render(self,text,colour):
colour = fix_colour(colour)
label = pyglet.text.Label(text,font_name=self.font,font_size=self.size,color = colour,dpi=72)
return self.return_surface(label)
def render_wordwrap(self,text,width,colour,alignment):
if alignment == 0:
alignment = 'left'
elif alignment == 1:
alignment = 'center'
else:
alignment = 'right'
colour = fix_colour(colour)
label = pyglet.text.Label(text,font_name=self.font,font_size=self.size,color = colour,width=width,halign=alignment, multiline=True,dpi=72)
return self.return_surface(label)
The number of pixels taken up by a certain point size will depend on your screens DPI. 某个点大小占用的像素数将取决于您的屏幕DPI。 For example, "14pt" is the distance covering 14 points, which at a default DPI of 96 is around 18 pixels.
例如,“ 14pt”是覆盖14个点的距离,默认DPI为96时约为18个像素。
This site give a good explanation of converting point sizes to pixels. 该站点对将点大小转换为像素提供了很好的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.