我对 HarfBuzz 有疑问。我想要:
设置文字内容
重绘时
一个。更新字体大小
湾。塑造文字
但如果文本没有更改,我会收到以下错误:
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff79ff859 in __GI_abort () at abort.c:79
#2 0x00007ffff79ff729 in __assert_fail_base (fmt=0x7ffff7b95588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=0x7ffff7f69168 "buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE",
file=0x7ffff7f68df3 "../../src/hb-shape-plan.cc", line=389, function=<optimized out>) at assert.c:92
#3 0x00007ffff7a10f36 in __GI___assert_fail (
assertion=0x7ffff7f69168 "buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE",
file=0x7ffff7f68df3 "../../src/hb-shape-plan.cc", line=389,
function=0x7ffff7f690d0 "hb_bool_t hb_shape_plan_execute(hb_shape_plan_t*, hb_font_t*, hb_buffer_t*, const hb_feature_t*, unsigned int)") at assert.c:101
#4 0x00007ffff7f5431c in hb_shape_plan_execute () from /lib/x86_64-linux-gnu/libharfbuzz.so.0
#5 0x00007ffff7f5469a in hb_shape_full () from /lib/x86_64-linux-gnu/libharfbuzz.so.0
#6 0x000055555558a791 in fruit::TextSegment::shape_impl (this=0x7fffffffdcb0, shaper=...)
at fruit/lib/text_segment.cpp:186
#7 0x0000555555588820 in fruit::TextSegment::shape(fruit::TextShaper const&) const & (this=0x7fffffffdcb0,
shaper=...) at fruit/lib/././text_segment.hpp:201
#8 0x0000555555588039 in fruit::TextLine::do_render (this=0x7fffffffdcb0) at fruit/lib/text_line.cpp:22
#9 0x0000555555587f13 in fruit::TextLine::handle_no_result (this=0x7fffffffdcb0) at fruit/lib/text_line.cpp:7
#10 0x000055555555c773 in fruit::TextLine::handle (this=0x7fffffffdcb0) at fruit/lib/./text_line.hpp:112
#11 0x000055555555ae7d in Testcases::TextLineSizeReqUpdatedSizeKeepContent::doRun (this=0x5555555f9980)
at fruit/lib/text_line.test.cpp:66
这是由
fruit::FontfaceLoader loader;
fruit::FontFace face{loader, fruit::io_utils::load("testdata/DejaVuSans.ttf")};
fruit::TextLine obj{face};
obj.char_height(20).text(u8"Hello, World");
auto const size_a = obj.handle(fruit::SizeRequestEvent{});
obj.char_height(30);
auto const size_b = obj.handle(fruit::SizeRequestEvent{}); // <= This will trigger the crash
EXPECT_NE(size_a.min_size, size_b.min_size);
设置字符高度时,我会清除所有缓存的结果。这个结构看起来像这样:
struct GlyphInfo
{
GlyphIndex index;
uint32_t start_offset;
};
struct GlyphGeometry
{
Vector<int> cursor_increment{0, 0, 0};
Vector<int> render_offset{0, 0, 0};
};
class TextShapeResult
{
public:
explicit TextShapeResult(uint32_t num_glyphs,
hb_glyph_info_t const* info,
hb_glyph_position_t const* geom,
std::reference_wrapper<FontFace const> font,
TextDirection direction,
int char_height);
std::span<GlyphInfo const> glyph_info() const
{
FRUIT_ASSERT(m_glyph_info.get() != nullptr);
return std::span{m_glyph_info.get(), m_glyph_count};
}
std::span<GlyphGeometry const> glyph_geometry() const
{
FRUIT_ASSERT(m_glyph_geometry.get() != nullptr);
return std::span{m_glyph_geometry.get(), m_glyph_count};
}
FontFace const& font() const
{
return m_font;
}
int char_height() const
{
return m_char_height;
}
TextDirection direction() const
{
return m_direction;
}
size_t glyph_count() const { return m_glyph_count; }
private:
size_t m_glyph_count;
std::unique_ptr<GlyphInfo[]> m_glyph_info; // Output from HarfBuzz
std::unique_ptr<GlyphGeometry[]> m_glyph_geometry; // Output from HarfBuzz
std::reference_wrapper<FontFace const> m_font; // FreeType handle
TextDirection m_direction;
int m_char_height;
};
因此,它不包含对 HarfBuzz 结构的引用。hb_shape 使文本内容无效是真的吗。如果是这样,在调用hb_shape
.