mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 23:59:49 +00:00
LibWeb: Layout/Shape font-variant-* css properties
This commit is contained in:
parent
1c42d6831b
commit
083f4f3d08
Notes:
github-actions[bot]
2024-12-17 18:08:20 +00:00
Author: https://github.com/jdahlin
Commit: 083f4f3d08
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2197
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/kalenikaliaksandr
Reviewed-by: https://github.com/tcl3
8 changed files with 310 additions and 14 deletions
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace Gfx {
|
||||
|
||||
RefPtr<GlyphRun> shape_text(FloatPoint baseline_start, float letter_spacing, Utf8View string, Gfx::Font const& font, GlyphRun::TextType text_type)
|
||||
RefPtr<GlyphRun> shape_text(FloatPoint baseline_start, float letter_spacing, Utf8View string, Gfx::Font const& font, GlyphRun::TextType text_type, ShapeFeatures const& features)
|
||||
{
|
||||
hb_buffer_t* buffer = hb_buffer_create();
|
||||
ScopeGuard destroy_buffer = [&]() { hb_buffer_destroy(buffer); };
|
||||
|
@ -24,7 +24,22 @@ RefPtr<GlyphRun> shape_text(FloatPoint baseline_start, float letter_spacing, Utf
|
|||
Vector<hb_glyph_info_t> const input_glyph_info({ glyph_info, glyph_count });
|
||||
|
||||
auto* hb_font = font.harfbuzz_font();
|
||||
hb_shape(hb_font, buffer, nullptr, 0);
|
||||
hb_feature_t const* hb_features_data = nullptr;
|
||||
Vector<hb_feature_t> hb_features;
|
||||
if (!features.is_empty()) {
|
||||
hb_features.ensure_capacity(features.size());
|
||||
for (auto const& feature : features) {
|
||||
hb_features.append({
|
||||
.tag = HB_TAG(feature.tag[0], feature.tag[1], feature.tag[2], feature.tag[3]),
|
||||
.value = feature.value,
|
||||
.start = 0,
|
||||
.end = HB_FEATURE_GLOBAL_END,
|
||||
});
|
||||
}
|
||||
hb_features_data = hb_features.data();
|
||||
}
|
||||
|
||||
hb_shape(hb_font, buffer, hb_features_data, features.size());
|
||||
|
||||
glyph_info = hb_buffer_get_glyph_infos(buffer, &glyph_count);
|
||||
auto* positions = hb_buffer_get_glyph_positions(buffer, &glyph_count);
|
||||
|
@ -45,12 +60,14 @@ RefPtr<GlyphRun> shape_text(FloatPoint baseline_start, float letter_spacing, Utf
|
|||
point.translate_by(letter_spacing, 0);
|
||||
}
|
||||
|
||||
hb_buffer_reset(buffer);
|
||||
|
||||
return adopt_ref(*new Gfx::GlyphRun(move(glyph_run), font, text_type, point.x()));
|
||||
}
|
||||
|
||||
float measure_text_width(Utf8View const& string, Gfx::Font const& font)
|
||||
float measure_text_width(Utf8View const& string, Gfx::Font const& font, ShapeFeatures const& features)
|
||||
{
|
||||
auto glyph_run = shape_text({}, 0, string, font, GlyphRun::TextType::Common);
|
||||
auto glyph_run = shape_text({}, 0, string, font, GlyphRun::TextType::Common, features);
|
||||
return glyph_run->width();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue