1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:07:44 +00:00

LibGfx: Update fill_path() to support taking a PaintStyle

This means fill_path() now paints the scanlines its self rather than
calling draw_line() which easily allows each pixel along the scanline
to have a different color.
This commit is contained in:
MacDue 2023-01-15 22:15:24 +00:00 committed by Andreas Kling
parent b31d768e95
commit 223cedc896
5 changed files with 64 additions and 29 deletions

View file

@ -50,11 +50,6 @@ void AntiAliasingPainter::draw_anti_aliased_line(FloatPoint actual_from, FloatPo
// Axis-aligned lines:
if (mapped_from.y() == mapped_to.y()) {
auto start_point = (mapped_from.x() < mapped_to.x() ? mapped_from : mapped_to).translated(0, -int_thickness / 2);
if constexpr (path_hacks == FixmeEnableHacksForBetterPathPainting::Yes) {
// FIXME: SVG fill_path() hack:
// SVG asks for 1px scanlines at floating point y values, if they're not snapped to a pixel they look faint.
start_point.set_y(floorf(start_point.y()));
}
return fill_rect(Gfx::FloatRect(start_point, { length, thickness }), color);
}
if (mapped_from.x() == mapped_to.x()) {
@ -213,9 +208,20 @@ void AntiAliasingPainter::draw_line(FloatPoint actual_from, FloatPoint actual_to
draw_anti_aliased_line<FixmeEnableHacksForBetterPathPainting::No>(actual_from, actual_to, color, thickness, style, alternate_color, line_length_mode);
}
void AntiAliasingPainter::fill_path(Path& path, Color color, Painter::WindingRule rule)
// FIXME: In the fill_paths() m_transform.translation() throws away any other transforms
// this currently does not matter -- but may in future.
void AntiAliasingPainter::fill_path(Path const& path, Color color, Painter::WindingRule rule)
{
Detail::fill_path<Detail::FillPathMode::AllowFloatingPoints>(*this, path, color, rule);
Detail::fill_path<Detail::FillPathMode::AllowFloatingPoints>(
m_underlying_painter, path, [=](IntPoint) { return color; }, rule, m_transform.translation());
}
void AntiAliasingPainter::fill_path(Path const& path, PaintStyle const& paint_style, Painter::WindingRule rule)
{
paint_style.paint(enclosing_int_rect(path.bounding_box()), [&](PaintStyle::SamplerFunction sampler) {
Detail::fill_path<Detail::FillPathMode::AllowFloatingPoints>(m_underlying_painter, path, move(sampler), rule, m_transform.translation());
});
}
void AntiAliasingPainter::stroke_path(Path const& path, Color color, float thickness)