mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:57:47 +00:00
LibWeb: Use Gfx::AntiAliasingPainter to draw SVG paths
This is still quite bad, but it's much more pleasing to look at when drawing random SVGs :^)
This commit is contained in:
parent
e2cd558101
commit
5a2e7d30ce
4 changed files with 42 additions and 8 deletions
|
@ -16,7 +16,8 @@ static float fractional_part(float x)
|
|||
|
||||
// Base algorithm from https://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm,
|
||||
// because there seems to be no other known method for drawing AA'd lines (?)
|
||||
void Gfx::AntiAliasingPainter::draw_line(FloatPoint const& actual_from, FloatPoint const& actual_to, Color color, float thickness, Gfx::Painter::LineStyle style, Color)
|
||||
template<Gfx::AntiAliasingPainter::AntiAliasPolicy policy>
|
||||
void Gfx::AntiAliasingPainter::draw_anti_aliased_line(FloatPoint const& actual_from, FloatPoint const& actual_to, Color color, float thickness, Gfx::Painter::LineStyle style, Color)
|
||||
{
|
||||
// FIXME: Implement this :P
|
||||
VERIFY(style == Painter::LineStyle::Solid);
|
||||
|
@ -76,10 +77,18 @@ void Gfx::AntiAliasingPainter::draw_line(FloatPoint const& actual_from, FloatPoi
|
|||
auto x = first_end_point.x();
|
||||
while (x < last_end_point.x()) {
|
||||
if (is_steep) {
|
||||
draw_point({ floorf(next_intersection), x }, color_with_alpha(1 - fractional_part(next_intersection)));
|
||||
if constexpr (policy == AntiAliasPolicy::OnlyEnds) {
|
||||
draw_point({ floorf(next_intersection), x }, color);
|
||||
} else {
|
||||
draw_point({ floorf(next_intersection), x }, color_with_alpha(1 - fractional_part(next_intersection)));
|
||||
}
|
||||
draw_point({ floorf(next_intersection) + 1, x }, color_with_alpha(fractional_part(next_intersection)));
|
||||
} else {
|
||||
draw_point({ x, floorf(next_intersection) }, color_with_alpha(1 - fractional_part(next_intersection)));
|
||||
if constexpr (policy == AntiAliasPolicy::OnlyEnds) {
|
||||
draw_point({ x, floorf(next_intersection) }, color);
|
||||
} else {
|
||||
draw_point({ x, floorf(next_intersection) }, color_with_alpha(1 - fractional_part(next_intersection)));
|
||||
}
|
||||
draw_point({ x, floorf(next_intersection) + 1 }, color_with_alpha(fractional_part(next_intersection)));
|
||||
}
|
||||
next_intersection += delta_y;
|
||||
|
@ -87,6 +96,16 @@ void Gfx::AntiAliasingPainter::draw_line(FloatPoint const& actual_from, FloatPoi
|
|||
}
|
||||
}
|
||||
|
||||
void Gfx::AntiAliasingPainter::draw_aliased_line(FloatPoint const& actual_from, FloatPoint const& actual_to, Color color, float thickness, Gfx::Painter::LineStyle style, Color alternate_color)
|
||||
{
|
||||
draw_anti_aliased_line<AntiAliasPolicy::OnlyEnds>(actual_from, actual_to, color, thickness, style, alternate_color);
|
||||
}
|
||||
|
||||
void Gfx::AntiAliasingPainter::draw_line(FloatPoint const& actual_from, FloatPoint const& actual_to, Color color, float thickness, Gfx::Painter::LineStyle style, Color alternate_color)
|
||||
{
|
||||
draw_anti_aliased_line<AntiAliasPolicy::Full>(actual_from, actual_to, color, thickness, style, alternate_color);
|
||||
}
|
||||
|
||||
void Gfx::AntiAliasingPainter::fill_path(Path& path, Color color, Painter::WindingRule rule)
|
||||
{
|
||||
Detail::fill_path<Detail::FillPathMode::AllowFloatingPoints>(*this, path, color, rule);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue