mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 09:52:31 +00:00
LibGfx+LibWeb: Draw glyph runs with subpixel accuracy
This improves the quality of our font rendering, especially when animations are involved. Relevant changes: * Skia fonts have their subpixel flag set, which means that individual glyphs are rendered at subpixel offsets causing glyph runs as a whole to look better. * Fragment offsets are no longer rounded to whole device pixels, and instead the floating point offset is kept. This allows us to pass through the floating point baseline position all the way to the Skia calls, which already expected that to be a float position. The `scrollable-contains-table.html` ref test needed different table headings since they would slightly inflate the column size in the test file, but not the reference.
This commit is contained in:
parent
e32a9b2c6f
commit
4d9f17eddf
Notes:
github-actions[bot]
2024-12-21 22:10:48 +00:00
Author: https://github.com/gmta
Commit: 4d9f17eddf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2850
Reviewed-by: https://github.com/shlyakpavel
83 changed files with 524 additions and 525 deletions
|
@ -683,16 +683,19 @@ void paint_text_fragment(PaintContext& context, TextPaintable const& paintable,
|
|||
if (!glyph_run)
|
||||
return;
|
||||
|
||||
DevicePixelPoint baseline_start { fragment_absolute_device_rect.x(), fragment_absolute_device_rect.y() + context.rounded_device_pixels(fragment.baseline()) };
|
||||
auto scale = context.device_pixels_per_css_pixel();
|
||||
painter.draw_text_run(baseline_start.to_type<int>(), *glyph_run, paintable.computed_values().webkit_text_fill_color(), fragment_absolute_device_rect.to_type<int>(), scale, fragment.orientation());
|
||||
auto baseline_start = Gfx::FloatPoint {
|
||||
fragment_absolute_rect.x().to_float(),
|
||||
fragment_absolute_rect.y().to_float() + fragment.baseline().to_float(),
|
||||
} * scale;
|
||||
painter.draw_text_run(baseline_start, *glyph_run, paintable.computed_values().webkit_text_fill_color(), fragment_absolute_device_rect.to_type<int>(), scale, fragment.orientation());
|
||||
|
||||
auto selection_rect = context.enclosing_device_rect(fragment.selection_rect()).to_type<int>();
|
||||
if (!selection_rect.is_empty()) {
|
||||
painter.fill_rect(selection_rect, CSS::SystemColor::highlight());
|
||||
DisplayListRecorderStateSaver saver(painter);
|
||||
painter.add_clip_rect(selection_rect);
|
||||
painter.draw_text_run(baseline_start.to_type<int>(), *glyph_run, CSS::SystemColor::highlight_text(), fragment_absolute_device_rect.to_type<int>(), scale, fragment.orientation());
|
||||
painter.draw_text_run(baseline_start, *glyph_run, CSS::SystemColor::highlight_text(), fragment_absolute_device_rect.to_type<int>(), scale, fragment.orientation());
|
||||
}
|
||||
|
||||
paint_text_decoration(context, paintable, fragment);
|
||||
|
@ -744,9 +747,8 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
|
|||
// So, we paint the shadows before painting any text.
|
||||
// FIXME: Find a smarter way to do this?
|
||||
if (phase == PaintPhase::Foreground) {
|
||||
for (auto& fragment : fragments()) {
|
||||
for (auto& fragment : fragments())
|
||||
paint_text_shadow(context, fragment, fragment.shadows());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& fragment : m_fragments) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue