我刚看到这篇文章说,亚像素定位是在2019年添加到Pango 1.44中的--不过也有一些问题。显然是默认关闭。这两篇文章都说需要来自开罗的最新大师。也许在此期间它已经被释放了。
实际上有两个问题:
有多个Python绑定到pangocairo。我在Python 3中使用了以下方法:
import cairo
import gi
gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Pango, PangoCairo我的文本呈现如下:
_alignments = {
'tl': lambda width, height: (0.0, 0.0), # top left
'tc': lambda width, height: (-width / 2, 0.0), # top center
'tr': lambda width, height: (-width, 0.0), # top right
'cl': lambda width, height: (0.0, -height / 2), # center left
'cc': lambda width, height: (-width / 2, -height / 2), # center center
'cr': lambda width, height: (-width, -height / 2), # center right
'bl': lambda width, height: (0.0, -height), # bottom left
'bc': lambda width, height: (-width / 2, -height), # bottom center
'br': lambda width, height: (-width, -height), # bottom right
}
def make_font(family, size):
return Pango.font_description_from_string(f'{family:s} {size:.2f}')
font = make_font('Arial', 10.0)
x = 0.0
y = 0.0
angle = 0.0
font_color = (1.0, 0.0, 0.0, 0.5)
text = 'test'
_ctx.save() # _ctx is a cairo.Context object
layout = PangoCairo.create_layout(_ctx)
layout.set_font_description(font)
layout.set_markup(text, -1)
_ctx.set_source_rgba(*font_color)
_, text_extents = layout.get_pixel_extents()
text_width, text_height = text_extents.width, text_extents.height
_ctx.translate(x, y)
if angle != 0.0:
_ctx.rotate(angle)
_ctx.translate(*self._alignments[alignment](text_width, text_height))
_ctx.move_to(0.0, 0.0)
PangoCairo.show_layout(_ctx, layout)
_ctx.restore()发布于 2020-05-07 13:45:01
我需要哪个版本/版本的Cairo (或者pycairo )来激活这个特性?还是我(仍然)需要从(未发布的)主版构建cairo?
随机猜测:这与开罗的src/cairo-ft-font.c有关,因此我快速查看了git log src/cairo-ft-font.c的输出。第三个条目听起来像您要寻找的内容:
commit ea9329215d3431ded51a71b724baf0edc25ad633
Author: Matthias Clasen <mclasen@redhat.com>
Date: Sat Jul 28 12:25:47 2018 +0000
image compositor: Support subpixel positioning
Support subpixel positioning with a 4x4 subpixel grid.
When compositing glyphs in the image compositor,
we store the subpixel phases in the high bits of the
glyph index. The _cairo_scaled_glyph_index() macro
has been updated to discard these bits. By storing
the phases in the glyph index, the glyph cache just
keeps working. When loading a glyph, the Freetype
font backend shifts the outline according to the
phases.那么,包含此提交的第一个版本是什么?
$ git describe --contains ea9329215d3431ded51a71b724baf0edc25ad633
fatal: cannot describe 'ea9329215d3431ded51a71b724baf0edc25ad633'嗯,似乎没有发布,所以你需要主人。
如何激活Cairo (pycairo) / pangocairo的亚像素定位?
你不知道,据我所知,它是自动激活的。那么问题是:我如何使它停用呢?答案似乎也是“你不知道”。
编辑:根据https://blogs.gnome.org/mclasen/2019/08/07/pango-1-44-wrap-up/,答案似乎是(部分)在函数pango_context_set_round_glyph_positions中。这似乎处理了Pango和PangoCairo部分的支持。
https://stackoverflow.com/questions/61653970
复制相似问题