Truly independent web browser
LibGfx+Compositor: Keep paths in libgfx_rust instead of Skia
Aliaksandr Kalenike952d9c94e61
diff --git a/Libraries/LibGfx/CMakeLists.txt b/Libraries/LibGfx/CMakeLists.txtindex fcea4618013..e617c31e786 100644--- a/Libraries/LibGfx/CMakeLists.txt+++ b/Libraries/LibGfx/CMakeLists.txt@@ -40,7 +40,6 @@ set(SOURCESPaintStyle.cppPalette.cppPath.cpp- PathSkia.cppPoint.cppRect.cppSharedImage.cppdiff --git a/Libraries/LibGfx/Path.cpp b/Libraries/LibGfx/Path.cppindex b4547a11f9d..aa514d4cd2e 100644--- a/Libraries/LibGfx/Path.cpp+++ b/Libraries/LibGfx/Path.cpp@@ -4,58 +4,481 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <AK/ScopeGuard.h>+#include <AK/TypeCasts.h>+#include <LibGfx/Font/Font.h>#include <LibGfx/Path.h>-#include <LibGfx/PathSkia.h>+#include <LibGfx/RustFFI.h>#include <LibGfx/TextLayout.h>#include <LibIPC/Decoder.h>#include <LibIPC/Encoder.h>-#include <core/SkPath.h>-// A shaped run as Rust holds one: a font and the glyphs it placed, without the C++ GlyphRun object.-struct LadybirdGfxGlyphRun {- void const* font;- Gfx::DrawGlyph const* glyphs;- size_t glyph_count;-};+#include <harfbuzz/hb.h>++#ifdef AK_OS_MACOS+# include <LibGfx/Font/TypefaceCoreText.h>+#endif++static_assert(sizeof(Gfx::PathVertex) == sizeof(Gfx::FFI::PathVertex));+static_assert(offsetof(Gfx::PathVertex, point) == offsetof(Gfx::FFI::PathVertex, point));+static_assert(offsetof(Gfx::PathVertex, distance) == offsetof(Gfx::FFI::PathVertex, distance));+static_assert(offsetof(Gfx::PathVertex, direction) == offsetof(Gfx::FFI::PathVertex, direction));+static_assert(sizeof(Gfx::FloatPoint) == sizeof(Gfx::FFI::FloatPoint));+static_assert(to_underlying(Gfx::WindingRule::Nonzero) == 0 && to_underlying(Gfx::WindingRule::EvenOdd) == 1);+static_assert(to_underlying(Gfx::PathVerb::Move) == to_underlying(Gfx::FFI::PathVerb::Move));+static_assert(to_underlying(Gfx::PathVerb::Line) == to_underlying(Gfx::FFI::PathVerb::Line));+static_assert(to_underlying(Gfx::PathVerb::Quad) == to_underlying(Gfx::FFI::PathVerb::Quad));+static_assert(to_underlying(Gfx::PathVerb::Conic) == to_underlying(Gfx::FFI::PathVerb::Conic));+static_assert(to_underlying(Gfx::PathVerb::Cubic) == to_underlying(Gfx::FFI::PathVerb::Cubic));+static_assert(to_underlying(Gfx::PathVerb::Close) == to_underlying(Gfx::FFI::PathVerb::Close));-extern "C" {-void ladybird_gfx_path_destroy(void*);-bool ladybird_gfx_path_equals(void const*, void const*);-void ladybird_gfx_path_append_svg_string(void const*, void (*)(void*, char const*, size_t), void*);-void ladybird_gfx_path_bounding_box(void const*, float*);-void ladybird_gfx_path_serialize(void const*, void (*)(void*, u8 const*, size_t), void*);-float ladybird_gfx_path_length(void const*);-bool ladybird_gfx_path_point_at_length(void const*, float, float*);-void* ladybird_gfx_path_create_from_ops(u8 const* kinds, float const* values, size_t count);-void ladybird_gfx_path_append_ops(void*, u8 const* kinds, float const* values, size_t count);-void ladybird_gfx_path_append_path(void*, void const* other);-bool ladybird_gfx_path_is_empty(void const*);-void ladybird_gfx_path_last_point(void const*, float* out_x_y);-void* ladybird_gfx_path_clone(void const*);-void* ladybird_gfx_path_create_from_serialized_bytes(u8 const* bytes, size_t count);-void* ladybird_gfx_path_copy_transformed(void const*, float const* affine_values);-bool ladybird_gfx_path_contains(void const*, float, float, int);-void* ladybird_gfx_path_stroke_to_fill(void const*, float thickness, int cap_style, int join_style, float miter_limit, float const* dash_array, size_t dash_count, float dash_offset);-void ladybird_gfx_path_set_fill_type(void*, int);-void* ladybird_gfx_path_create_from_glyph_runs(LadybirdGfxGlyphRun const* runs, size_t run_count);-void* ladybird_gfx_path_place_glyph_runs_along(void const* path, LadybirdGfxGlyphRun const* runs, size_t run_count, float offset);+namespace Gfx {++Path::Path()+ : m_geometry(FFI::path_geometry_create())+{}-namespace Gfx {+Path::Path(FFI::PathGeometry* geometry)+ : m_geometry(geometry)+{+}++Path::~Path()+{+ FFI::path_geometry_destroy(m_geometry);+}++Path::Path(Path const& other)+ : m_geometry(FFI::path_geometry_clone(other.m_geometry))+{+}++Path& Path::operator=(Path const& other)+{+ if (this != &other) {+ FFI::path_geometry_destroy(m_geometry);+ m_geometry = FFI::path_geometry_clone(other.m_geometry);+ }+ return *this;+}++Path::Path(Path&& other)+ : m_geometry(exchange(other.m_geometry, nullptr))+{+}++Path& Path::operator=(Path&& other)+{+ if (this != &other)+ swap(m_geometry, other.m_geometry);+ return *this;+}Path Path::from_serialized_bytes(ReadonlyBytes bytes){- Gfx::Path path;- path.impl().deserialize_from_bytes(bytes);- return path;+ return Path { FFI::path_geometry_decode(bytes.data(), bytes.size()) };}-NonnullOwnPtr<Gfx::PathImpl> PathImpl::create()+void Path::clear(){- return PathImplSkia::create();+ FFI::path_geometry_clear(m_geometry);}-PathImpl::~PathImpl() = default;+void Path::move_to(FloatPoint const& point)+{+ FFI::path_geometry_move_to(m_geometry, point.x(), point.y());+}++void Path::line_to(FloatPoint const& point)+{+ FFI::path_geometry_line_to(m_geometry, point.x(), point.y());+}++void Path::close()+{+ FFI::path_geometry_close(m_geometry);+}++void Path::elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep)+{+ FFI::path_geometry_elliptical_arc_to(m_geometry, point.x(), point.y(), radii.width(), radii.height(), x_axis_rotation, large_arc, sweep);+}++void Path::arc_to(FloatPoint point, float radius, bool large_arc, bool sweep)+{+ FFI::path_geometry_arc_to(m_geometry, point.x(), point.y(), radius, large_arc, sweep);+}++void Path::quadratic_bezier_curve_to(FloatPoint through, FloatPoint point)+{+ FFI::path_geometry_quadratic_bezier_curve_to(m_geometry, through.x(), through.y(), point.x(), point.y());+}++void Path::cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2)+{+ FFI::path_geometry_cubic_bezier_curve_to(m_geometry, c1.x(), c1.y(), c2.x(), c2.y(), p2.x(), p2.y());+}++void Path::append_path(Path const& other)+{+ FFI::path_geometry_append_path(m_geometry, other.m_geometry);+}++static void append_to_byte_vector(void* context, u8 const* bytes, size_t count)+{+ static_cast<Vector<u8>*>(context)->append(bytes, count);+}++Vector<u8> Path::serialize_to_bytes() const+{+ Vector<u8> bytes;+ serialize_into(append_to_byte_vector, &bytes);+ return bytes;+}++void Path::serialize_into(void (*append)(void*, u8 const*, size_t), void* context) const+{+ FFI::path_geometry_encode(m_geometry, append, context);+}++bool Path::is_empty() const+{+ return FFI::path_geometry_is_empty(m_geometry);+}++FloatPoint Path::last_point() const+{+ float x_y[2];+ FFI::path_geometry_last_point(m_geometry, x_y);+ return { x_y[0], x_y[1] };+}++FloatRect Path::bounding_box() const+{+ float x_y_width_height[4];+ FFI::path_geometry_bounding_box(m_geometry, x_y_width_height);+ return { x_y_width_height[0], x_y_width_height[1], x_y_width_height[2], x_y_width_height[3] };+}++float Path::length() const+{+ return FFI::path_geometry_length(m_geometry);+}++Optional<PointAlongPath> Path::point_at_length(float distance) const+{+ float point_and_tangent[4];+ if (!FFI::path_geometry_point_at_length(m_geometry, distance, point_and_tangent))+ return {};+ return PointAlongPath { { point_and_tangent[0], point_and_tangent[1] }, { point_and_tangent[2], point_and_tangent[3] } };+}++Vector<PathVertex> Path::vertices() const+{+ Vector<PathVertex> vertices;+ FFI::path_geometry_vertices(+ m_geometry, [](void* context, FFI::PathVertex const* ffi_vertices, size_t count) {+ static_cast<Vector<PathVertex>*>(context)->append(reinterpret_cast<PathVertex const*>(ffi_vertices), count);+ },+ &vertices);+ return vertices;+}++bool Path::contains(FloatPoint point, WindingRule winding_rule) const+{+ return FFI::path_geometry_contains(m_geometry, point.x(), point.y(), to_underlying(winding_rule));+}++Path Path::stroke_to_fill(StrokeStyle const& style) const+{+ return Path { FFI::path_geometry_stroke_to_fill(m_geometry, style.thickness, to_underlying(style.cap_style), to_underlying(style.join_style), style.miter_limit, style.dash_array.data(), style.dash_array.size(), style.dash_offset) };+}++void Path::set_fill_type(WindingRule winding_rule)+{+ FFI::path_geometry_set_fill_rule(m_geometry, to_underlying(winding_rule));+}++static Array<float, 6> affine_values(AffineTransform const& transform)+{+ return { transform.a(), transform.b(), transform.c(), transform.d(), transform.e(), transform.f() };+}++Path Path::copy_transformed(AffineTransform const& transform) const+{+ auto values = affine_values(transform);+ return Path { FFI::path_geometry_copy_transformed(m_geometry, values.data()) };+}++void Path::transform(AffineTransform const& transform)+{+ auto values = affine_values(transform);+ FFI::path_geometry_transform(m_geometry, values.data());+}++String Path::to_svg_string() const+{+ String string;+ FFI::path_geometry_svg_string(+ m_geometry, [](void* context, u8 const* bytes, size_t count) {+ *static_cast<String*>(context) = String::from_utf8_without_validation({ bytes, count });+ },+ &string);+ return string;+}++PathData Path::data() const+{+ FFI::PathGeometryData data;+ FFI::path_geometry_data(m_geometry, &data);+ return {+ .verbs = { reinterpret_cast<PathVerb const*>(data.verbs), data.verb_count },+ .points = { reinterpret_cast<FloatPoint const*>(data.points), data.point_count },+ .conic_weights = { data.conic_weights, data.conic_weight_count },+ .winding_rule = static_cast<WindingRule>(data.fill_rule),+ };+}++bool Path::operator==(Path const& other) const+{+ return FFI::path_geometry_equals(m_geometry, other.m_geometry);+}++namespace {++// Maps the coordinates of a glyph outline from font units, with y up, to pixels, with y down. A contour starts only at+// its first segment that goes somewhere, and segments that stay at one point are left out, so contours of a single+// point, which fonts use as anchors, add nothing to the path.+struct GlyphOutline {+ FFI::PathGeometry* outline;+ float units_to_pixels_x;+ float units_to_pixels_y;+ bool has_contour { false };+ float current_x { 0 };+ float current_y { 0 };++ float x(float units) const { return units * units_to_pixels_x; }+ // Subtract from 0, so that a point on the baseline gets 0 and not -0.+ float y(float units) const { return 0.0f - units * units_to_pixels_y; }++ bool is_at(float to_x, float to_y) const { return current_x == to_x && current_y == to_y; }++ void go_to(float to_x, float to_y)+ {+ if (!has_contour) {+ has_contour = true;+ FFI::path_geometry_contour_move_to(outline, x(current_x), y(current_y));+ }+ current_x = to_x;+ current_y = to_y;+ }++ void close_contour()+ {+ if (!has_contour)+ return;+ FFI::path_geometry_contour_close(outline);+ has_contour = false;+ }+};++// NOTE: HarfBuzz emits the implicit line that closes each contour as a regular line_to before close_path. The+// quadratic callback must be set, otherwise HarfBuzz converts quadratic segments to cubics.+hb_draw_funcs_t* glyph_outline_draw_funcs()+{+ static hb_draw_funcs_t* draw_funcs = [] {+ auto* funcs = hb_draw_funcs_create();+ hb_draw_funcs_set_move_to_func(+ funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float to_x, float to_y, void*) {+ auto& outline = *static_cast<GlyphOutline*>(draw_data);+ outline.close_contour();+ outline.current_x = to_x;+ outline.current_y = to_y;+ },+ nullptr, nullptr);+ hb_draw_funcs_set_line_to_func(+ funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float to_x, float to_y, void*) {+ auto& outline = *static_cast<GlyphOutline*>(draw_data);+ if (outline.is_at(to_x, to_y))+ return;+ outline.go_to(to_x, to_y);+ FFI::path_geometry_contour_line_to(outline.outline, outline.x(to_x), outline.y(to_y));+ },+ nullptr, nullptr);+ hb_draw_funcs_set_quadratic_to_func(+ funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float control_x, float control_y, float to_x, float to_y, void*) {+ auto& outline = *static_cast<GlyphOutline*>(draw_data);+ if (outline.is_at(control_x, control_y) && outline.is_at(to_x, to_y))+ return;+ outline.go_to(to_x, to_y);+ FFI::path_geometry_contour_quad_to(outline.outline, outline.x(control_x), outline.y(control_y), outline.x(to_x), outline.y(to_y));+ },+ nullptr, nullptr);+ hb_draw_funcs_set_cubic_to_func(+ funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float control1_x, float control1_y, float control2_x, float control2_y, float to_x, float to_y, void*) {+ auto& outline = *static_cast<GlyphOutline*>(draw_data);+ if (outline.is_at(control1_x, control1_y) && outline.is_at(control2_x, control2_y) && outline.is_at(to_x, to_y))+ return;+ outline.go_to(to_x, to_y);+ FFI::path_geometry_contour_cubic_to(outline.outline, outline.x(control1_x), outline.y(control1_y), outline.x(control2_x), outline.y(control2_y), outline.x(to_x), outline.y(to_y));+ },+ nullptr, nullptr);+ hb_draw_funcs_set_close_path_func(+ funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, void*) {+ static_cast<GlyphOutline*>(draw_data)->close_contour();+ },+ nullptr, nullptr);+ hb_draw_funcs_make_immutable(funcs);+ return funcs;+ }();+ return draw_funcs;+}++#ifdef AK_OS_MACOS+void append_core_text_glyph_outline(FFI::PathGeometry* outline, CTFontRef font, u32 glyph_id)+{+ auto path = CTFontCreatePathForGlyph(font, static_cast<CGGlyph>(glyph_id), nullptr);+ if (!path)+ return;+ ScopeGuard release_path = [&] { CGPathRelease(path); };++ // CoreText gives points in pixels with y up.+ CGPathApply(path, outline, [](void* info, CGPathElement const* element) {+ auto* outline = static_cast<FFI::PathGeometry*>(info);+ auto x = [&](size_t index) { return static_cast<float>(element->points[index].x); };+ auto y = [&](size_t index) { return 0.0f - static_cast<float>(element->points[index].y); };+ switch (element->type) {+ case kCGPathElementMoveToPoint:+ FFI::path_geometry_contour_move_to(outline, x(0), y(0));+ break;+ case kCGPathElementAddLineToPoint:+ FFI::path_geometry_contour_line_to(outline, x(0), y(0));+ break;+ case kCGPathElementAddQuadCurveToPoint:+ FFI::path_geometry_contour_quad_to(outline, x(0), y(0), x(1), y(1));+ break;+ case kCGPathElementAddCurveToPoint:+ FFI::path_geometry_contour_cubic_to(outline, x(0), y(0), x(1), y(1), x(2), y(2));+ break;+ case kCGPathElementCloseSubpath:+ FFI::path_geometry_contour_close(outline);+ break;+ }+ });+}+#endif++// Gives the outlines of the glyphs of a font in pixels, with their origin on the baseline.+class GlyphOutliner {+ AK_MAKE_NONCOPYABLE(GlyphOutliner);+ AK_MAKE_NONMOVABLE(GlyphOutliner);++public:+ explicit GlyphOutliner(Font const& font)+ : m_font(font)+ {+#ifdef AK_OS_MACOS+ if (auto const* core_text_typeface = as_if<TypefaceCoreText>(font.typeface()); core_text_typeface && core_text_typeface->has_outlines_that_only_core_text_draws())+ m_core_text_font = create_core_text_font_with_variations(core_text_typeface->core_text_font(), font.pixel_size(), font.variation_settings().to_sorted_list());+#endif+ }++ ~GlyphOutliner()+ {+#ifdef AK_OS_MACOS+ if (m_core_text_font)+ CFRelease(m_core_text_font);+#endif+ }++ // Appends the outline of the glyph to the path, mapped by the affine transform with the values a, b, c, d, e and f.+ void append_outline(u32 glyph_id, FFI::PathGeometry* path, Array<float, 6> const& transform) const+ {+ auto* outline = FFI::path_geometry_create();+ ScopeGuard destroy_outline = [&] { FFI::path_geometry_destroy(outline); };+ draw_outline(glyph_id, outline);+ FFI::path_geometry_append_transformed_contours(path, outline, transform.data());+ }++private:+ void draw_outline(u32 glyph_id, FFI::PathGeometry* outline) const+ {+#ifdef AK_OS_MACOS+ if (m_core_text_font) {+ append_core_text_glyph_outline(outline, m_core_text_font, glyph_id);+ return;+ }+#endif++ auto* hb_font = m_font.harfbuzz_font();+ int x_scale = 0;+ int y_scale = 0;+ hb_font_get_scale(hb_font, &x_scale, &y_scale);+ if (x_scale <= 0 || y_scale <= 0)+ return;+ GlyphOutline glyph_outline {+ .outline = outline,+ .units_to_pixels_x = m_font.pixel_size() / static_cast<float>(x_scale),+ .units_to_pixels_y = m_font.pixel_size() / static_cast<float>(y_scale),+ };+ hb_font_draw_glyph(hb_font, glyph_id, glyph_outline_draw_funcs(), &glyph_outline);+ glyph_outline.close_contour();+ }++ Font const& m_font;+#ifdef AK_OS_MACOS+ // The font at its size and variations, for outlines that only CoreText draws.+ CTFontRef m_core_text_font { nullptr };+#endif+};++}++void Path::glyph_run(GlyphRun const& glyph_run)+{+ if (glyph_run.font().is_invisible())+ return;+ FFI::path_geometry_set_fill_rule(m_geometry, to_underlying(WindingRule::Nonzero));+ auto font_ascent = glyph_run.font().pixel_metrics().ascent;+ GlyphOutliner outliner { glyph_run.font() };+ for (auto const& glyph : glyph_run.glyphs())+ outliner.append_outline(glyph.glyph_id, m_geometry, { 1, 0, 0, 1, glyph.position.x(), glyph.position.y() + font_ascent });+ FFI::path_geometry_update_state_from_contours(m_geometry);+}++// Lays each glyph along the first subpath that has length, with its origin at the distance of its x position plus the+// offset and its baseline along the direction of the path there, until a glyph's middle would go past the end.+Path Path::place_glyph_runs_along(ReadonlySpan<NonnullRefPtr<GlyphRun>> glyph_runs, float offset) const+{+ Path output;+ auto* measure = FFI::path_geometry_measure_first_contour(m_geometry);+ if (!measure)+ return output;+ ScopeGuard destroy_measure = [&] { FFI::contour_measure_destroy(measure); };+ auto path_length = FFI::contour_measure_length(measure);++ auto append_glyph_outlines = [&] {+ for (auto const& glyph_run : glyph_runs) {+ if (glyph_run->font().is_invisible())+ continue;+ GlyphOutliner outliner { glyph_run->font() };+ for (auto const& glyph : glyph_run->glyphs()) {+ auto glyph_distance = offset + glyph.position.x();+ if (glyph_distance + (glyph.glyph_width / 2.0f) > path_length)+ return;++ float point_and_tangent[4];+ FFI::contour_measure_position_and_tangent(measure, glyph_distance, point_and_tangent);+ auto [x, y, tangent_x, tangent_y] = point_and_tangent;+ outliner.append_outline(glyph.glyph_id, output.m_geometry, { tangent_x, tangent_y, -tangent_y, tangent_x, x, y });+ }+ }+ };+ append_glyph_outlines();+ FFI::path_geometry_update_state_from_contours(output.m_geometry);+ return output;+}}@@ -76,18 +499,43 @@ ErrorOr<Gfx::Path> decode(Decoder& decoder)}+// The functions through which Rust code outside LibGfx builds and queries paths. See Rust/src/path.rs.++extern "C" {+void ladybird_gfx_path_destroy(void*);+bool ladybird_gfx_path_equals(void const*, void const*);+void ladybird_gfx_path_append_svg_string(void const*, void (*)(void*, u8 const*, size_t), void*);+void ladybird_gfx_path_bounding_box(void const*, float*);+void ladybird_gfx_path_serialize(void const*, void (*)(void*, u8 const*, size_t), void*);+float ladybird_gfx_path_length(void const*);+bool ladybird_gfx_path_point_at_length(void const*, float, float*);+void* ladybird_gfx_path_create_from_ops(u8 const* kinds, float const* values, size_t count);+void ladybird_gfx_path_append_ops(void*, u8 const* kinds, float const* values, size_t count);+void ladybird_gfx_path_append_path(void*, void const* other);+bool ladybird_gfx_path_is_empty(void const*);+void ladybird_gfx_path_last_point(void const*, float* out_x_y);+void* ladybird_gfx_path_clone(void const*);+void* ladybird_gfx_path_create_from_serialized_bytes(u8 const* bytes, size_t count);+void* ladybird_gfx_path_copy_transformed(void const*, float const* affine_values);+bool ladybird_gfx_path_contains(void const*, float, float, i32);+void* ladybird_gfx_path_stroke_to_fill(void const*, float thickness, i32 cap_style, i32 join_style, float miter_limit, float const* dash_array, size_t dash_count, float dash_offset);+void ladybird_gfx_path_set_fill_type(void*, i32);+void* ladybird_gfx_path_create_from_glyph_runs(Gfx::FFI::FfiGlyphRun const* runs, size_t run_count);+void* ladybird_gfx_path_place_glyph_runs_along(void const* path, Gfx::FFI::FfiGlyphRun const* runs, size_t run_count, float offset);+}+extern "C" void ladybird_gfx_path_destroy(void* path){delete static_cast<Gfx::Path*>(path);}-extern "C" void ladybird_gfx_path_append_svg_string(void const* path, void (*append)(void*, char const*, size_t), void* context)+extern "C" void ladybird_gfx_path_append_svg_string(void const* path, void (*append)(void*, u8 const*, size_t), void* context){auto string = static_cast<Gfx::Path const*>(path)->to_svg_string();- append(context, reinterpret_cast<char const*>(string.bytes().data()), string.bytes().size());+ append(context, string.bytes().data(), string.bytes().size());}-extern "C" void ladybird_gfx_path_set_fill_type(void* path, int winding_rule)+extern "C" void ladybird_gfx_path_set_fill_type(void* path, i32 winding_rule){static_cast<Gfx::Path*>(path)->set_fill_type(static_cast<Gfx::WindingRule>(winding_rule));}@@ -103,8 +551,7 @@ extern "C" void ladybird_gfx_path_bounding_box(void const* path, float* out_x_y_extern "C" void ladybird_gfx_path_serialize(void const* path, void (*append)(void*, u8 const*, size_t), void* context){- auto bytes = static_cast<Gfx::Path const*>(path)->serialize_to_bytes();- append(context, bytes.data(), bytes.size());+ static_cast<Gfx::Path const*>(path)->serialize_into(append, context);}extern "C" float ladybird_gfx_path_length(void const* path)@@ -196,13 +643,13 @@ extern "C" void* ladybird_gfx_path_clone(void const* path)return new Gfx::Path(static_cast<Gfx::Path const*>(path)->clone());}-static Vector<NonnullRefPtr<Gfx::GlyphRun>> adopt_glyph_runs(LadybirdGfxGlyphRun const* runs, size_t run_count)+static Vector<NonnullRefPtr<Gfx::GlyphRun>> adopt_glyph_runs(Gfx::FFI::FfiGlyphRun const* runs, size_t run_count){Vector<NonnullRefPtr<Gfx::GlyphRun>> glyph_runs;glyph_runs.ensure_capacity(run_count);for (size_t i = 0; i < run_count; ++i) {Vector<Gfx::DrawGlyph> glyphs;- glyphs.append(runs[i].glyphs, runs[i].glyph_count);+ glyphs.append(reinterpret_cast<Gfx::DrawGlyph const*>(runs[i].glyphs), runs[i].glyph_count);// The text type and width only matter to a caller that slices or measures the run, which neither of the two// path operations below does.glyph_runs.unchecked_append(adopt_ref(*new Gfx::GlyphRun(move(glyphs), *static_cast<Gfx::Font const*>(runs[i].font), Gfx::GlyphRun::TextType::Common, 0)));@@ -210,7 +657,7 @@ static Vector<NonnullRefPtr<Gfx::GlyphRun>> adopt_glyph_runs(LadybirdGfxGlyphRunreturn glyph_runs;}-extern "C" void* ladybird_gfx_path_create_from_glyph_runs(LadybirdGfxGlyphRun const* runs, size_t run_count)+extern "C" void* ladybird_gfx_path_create_from_glyph_runs(Gfx::FFI::FfiGlyphRun const* runs, size_t run_count){auto* path = new Gfx::Path;for (auto const& glyph_run : adopt_glyph_runs(runs, run_count))@@ -218,15 +665,14 @@ extern "C" void* ladybird_gfx_path_create_from_glyph_runs(LadybirdGfxGlyphRun coreturn path;}-extern "C" void* ladybird_gfx_path_place_glyph_runs_along(void const* path, LadybirdGfxGlyphRun const* runs, size_t run_count, float offset)+extern "C" void* ladybird_gfx_path_place_glyph_runs_along(void const* path, Gfx::FFI::FfiGlyphRun const* runs, size_t run_count, float offset){return new Gfx::Path(static_cast<Gfx::Path const*>(path)->place_glyph_runs_along(adopt_glyph_runs(runs, run_count), offset));}extern "C" void* ladybird_gfx_path_create_from_serialized_bytes(u8 const* bytes, size_t count){- auto path_bytes_at_an_aligned_address = MUST(ByteBuffer::copy(bytes, count));- return new Gfx::Path(Gfx::Path::from_serialized_bytes(path_bytes_at_an_aligned_address));+ return new Gfx::Path(Gfx::Path::from_serialized_bytes({ bytes, count }));}extern "C" void* ladybird_gfx_path_copy_transformed(void const* path, float const* affine_values)@@ -235,12 +681,12 @@ extern "C" void* ladybird_gfx_path_copy_transformed(void const* path, float consreturn new Gfx::Path(static_cast<Gfx::Path const*>(path)->copy_transformed(transform));}-extern "C" bool ladybird_gfx_path_contains(void const* path, float x, float y, int winding_rule)+extern "C" bool ladybird_gfx_path_contains(void const* path, float x, float y, i32 winding_rule){return static_cast<Gfx::Path const*>(path)->contains({ x, y }, static_cast<Gfx::WindingRule>(winding_rule));}-extern "C" void* ladybird_gfx_path_stroke_to_fill(void const* path, float thickness, int cap_style, int join_style, float miter_limit, float const* dash_array, size_t dash_count, float dash_offset)+extern "C" void* ladybird_gfx_path_stroke_to_fill(void const* path, float thickness, i32 cap_style, i32 join_style, float miter_limit, float const* dash_array, size_t dash_count, float dash_offset){Gfx::Path::StrokeStyle style {.thickness = thickness,@@ -255,7 +701,5 @@ extern "C" void* ladybird_gfx_path_stroke_to_fill(void const* path, float thicknextern "C" bool ladybird_gfx_path_equals(void const* a, void const* b){- auto const& path_a = *static_cast<Gfx::Path const*>(a);- auto const& path_b = *static_cast<Gfx::Path const*>(b);- return static_cast<Gfx::PathImplSkia const&>(path_a.impl()).sk_path() == static_cast<Gfx::PathImplSkia const&>(path_b.impl()).sk_path();+ return *static_cast<Gfx::Path const*>(a) == *static_cast<Gfx::Path const*>(b);}diff --git a/Libraries/LibGfx/Path.h b/Libraries/LibGfx/Path.hindex 2a6bc5306e8..a95ba7a0d32 100644--- a/Libraries/LibGfx/Path.h+++ b/Libraries/LibGfx/Path.h@@ -7,7 +7,7 @@#pragma once#include <AK/Forward.h>-#include <AK/NonnullOwnPtr.h>+#include <AK/NonnullRefPtr.h>#include <AK/Optional.h>#include <AK/String.h>#include <AK/Vector.h>@@ -22,6 +22,12 @@namespace Gfx {+namespace FFI {++struct PathGeometry;++}+struct PointAlongPath {FloatPoint point;FloatVector2 tangent;@@ -33,72 +39,42 @@ struct PathVertex {FloatVector2 direction;};-class PathImpl {-public:- AK_ALLOC_WITH_KMALLOC;-- static NonnullOwnPtr<Gfx::PathImpl> create();-- virtual ~PathImpl();-- virtual void clear() = 0;- virtual void move_to(Gfx::FloatPoint const&) = 0;- virtual void line_to(Gfx::FloatPoint const&) = 0;- virtual void close() = 0;- virtual void elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep) = 0;- virtual void arc_to(FloatPoint point, float radius, bool large_arc, bool sweep) = 0;- virtual void quadratic_bezier_curve_to(FloatPoint through, FloatPoint point) = 0;- virtual void cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2) = 0;- virtual void glyph_run(GlyphRun const&) = 0;-- virtual void append_path(Gfx::Path const&) = 0;-- [[nodiscard]] virtual Vector<u8> serialize_to_bytes() const = 0;- virtual void deserialize_from_bytes(ReadonlyBytes) = 0;-- [[nodiscard]] virtual bool is_empty() const = 0;- virtual Gfx::FloatPoint last_point() const = 0;- virtual Gfx::FloatRect bounding_box() const = 0;- virtual float length() const = 0;- virtual Optional<PointAlongPath> point_at_length(float distance) const = 0;- virtual Vector<PathVertex> vertices() const = 0;- virtual void set_fill_type(Gfx::WindingRule winding_rule) = 0;- virtual bool contains(FloatPoint point, Gfx::WindingRule) const = 0;-- virtual NonnullOwnPtr<PathImpl> clone() const = 0;- virtual NonnullOwnPtr<PathImpl> copy_transformed(Gfx::AffineTransform const&) const = 0;- virtual NonnullOwnPtr<PathImpl> place_glyph_runs_along(ReadonlySpan<NonnullRefPtr<GlyphRun>>, float offset = 0) const = 0;+enum class PathVerb : u8 {+ Move,+ Line,+ Quad,+ Conic,+ Cubic,+ Close,+};- virtual String to_svg_string() const = 0;+// The contours of a path, valid until the path changes or is destroyed. A path with a point that is not finite has+// none.+struct PathData {+ ReadonlySpan<PathVerb> verbs;+ ReadonlySpan<FloatPoint> points;+ ReadonlySpan<float> conic_weights;+ WindingRule winding_rule { WindingRule::Nonzero };};class Path {public:AK_ALLOC_WITH_KMALLOC;- Path() = default;+ Path();+ ~Path();- [[nodiscard]] static Path from_serialized_bytes(ReadonlyBytes);+ Path(Path const&);+ Path& operator=(Path const&);+ Path(Path&&);+ Path& operator=(Path&&);- Path(Path const& other)- : m_impl(other.impl().clone())- {- }-- Path& operator=(Path const& other)- {- if (this != &other)- m_impl = other.impl().clone();- return *this;- }-- Path(Path&& other) = default;- Path& operator=(Path&& other) = default;+ [[nodiscard]] static Path from_serialized_bytes(ReadonlyBytes);- void clear() { impl().clear(); }- void move_to(Gfx::FloatPoint const& point) { impl().move_to(point); }- void line_to(Gfx::FloatPoint const& point) { impl().line_to(point); }- void close() { impl().close(); }+ void clear();+ void move_to(Gfx::FloatPoint const&);+ void line_to(Gfx::FloatPoint const&);+ void close();enum class CapStyle {Butt,@@ -125,46 +101,45 @@ public:// nonzero winding rule.[[nodiscard]] Gfx::Path stroke_to_fill(StrokeStyle const&) const;- void elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep) { impl().elliptical_arc_to(point, radii, x_axis_rotation, large_arc, sweep); }- void arc_to(FloatPoint point, float radius, bool large_arc, bool sweep) { impl().arc_to(point, radius, large_arc, sweep); }- void quadratic_bezier_curve_to(FloatPoint through, FloatPoint point) { impl().quadratic_bezier_curve_to(through, point); }- void cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2) { impl().cubic_bezier_curve_to(c1, c2, p2); }- void glyph_run(GlyphRun const& glyph_run) { impl().glyph_run(glyph_run); }+ void elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep);+ void arc_to(FloatPoint point, float radius, bool large_arc, bool sweep);+ void quadratic_bezier_curve_to(FloatPoint through, FloatPoint point);+ void cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2);+ void glyph_run(GlyphRun const&);void horizontal_line_to(float x) { line_to({ x, last_point().y() }); }void vertical_line_to(float y) { line_to({ last_point().x(), y }); }- void append_path(Gfx::Path const& other) { impl().append_path(other); }+ void append_path(Gfx::Path const&);++ [[nodiscard]] Vector<u8> serialize_to_bytes() const;+ void serialize_into(void (*append)(void*, u8 const*, size_t), void* context) const;- [[nodiscard]] Vector<u8> serialize_to_bytes() const { return impl().serialize_to_bytes(); }+ [[nodiscard]] bool is_empty() const;+ Gfx::FloatPoint last_point() const;+ Gfx::FloatRect bounding_box() const;+ float length() const;+ Optional<PointAlongPath> point_at_length(float distance) const;+ Vector<PathVertex> vertices() const;+ bool contains(FloatPoint point, Gfx::WindingRule) const;+ void set_fill_type(Gfx::WindingRule);- [[nodiscard]] bool is_empty() const { return impl().is_empty(); }- Gfx::FloatPoint last_point() const { return impl().last_point(); }- Gfx::FloatRect bounding_box() const { return impl().bounding_box(); }- float length() const { return impl().length(); }- Optional<PointAlongPath> point_at_length(float distance) const { return impl().point_at_length(distance); }- Vector<PathVertex> vertices() const { return impl().vertices(); }- bool contains(FloatPoint point, Gfx::WindingRule winding_rule) const { return impl().contains(point, winding_rule); }- void set_fill_type(Gfx::WindingRule winding_rule) { impl().set_fill_type(winding_rule); }+ Gfx::Path clone() const { return *this; }+ Gfx::Path copy_transformed(Gfx::AffineTransform const&) const;+ Gfx::Path place_glyph_runs_along(ReadonlySpan<NonnullRefPtr<GlyphRun>>, float offset = 0) const;- Gfx::Path clone() const { return Gfx::Path { impl().clone() }; }- Gfx::Path copy_transformed(Gfx::AffineTransform const& transform) const { return Gfx::Path { impl().copy_transformed(transform) }; }- Gfx::Path place_glyph_runs_along(ReadonlySpan<NonnullRefPtr<GlyphRun>> glyph_runs, float offset = 0) const { return Gfx::Path { impl().place_glyph_runs_along(glyph_runs, offset) }; }+ String to_svg_string() const;- String to_svg_string() const { return impl().to_svg_string(); }+ void transform(Gfx::AffineTransform const&);- void transform(Gfx::AffineTransform const& transform) { m_impl = impl().copy_transformed(transform); }+ PathData data() const;- PathImpl& impl() { return *m_impl; }- PathImpl const& impl() const { return *m_impl; }+ bool operator==(Path const&) const;private:- explicit Path(NonnullOwnPtr<PathImpl>&& impl)- : m_impl(move(impl))- {- }+ explicit Path(FFI::PathGeometry*);- NonnullOwnPtr<PathImpl> m_impl { PathImpl::create() };+ FFI::PathGeometry* m_geometry { nullptr };};}diff --git a/Libraries/LibGfx/PathSkia.cpp b/Libraries/LibGfx/PathSkia.cppdeleted file mode 100644index 913058efca4..00000000000--- a/Libraries/LibGfx/PathSkia.cpp+++ /dev/null@@ -1,801 +0,0 @@-/*- * Copyright (c) 2024, Andreas Kling <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#define AK_DONT_REPLACE_STD--#include <AK/GenericShorthands.h>-#include <AK/Math.h>-#include <AK/Noncopyable.h>-#include <AK/ScopeGuard.h>-#include <AK/Span.h>-#include <AK/TypeCasts.h>-#include <LibGfx/Font/Font.h>-#include <LibGfx/PathSkia.h>-#include <LibGfx/Rect.h>-#include <LibGfx/TextLayout.h>-#include <core/SkPath.h>-#include <core/SkPathBuilder.h>-#include <core/SkPathMeasure.h>-#include <core/SkPathUtils.h>-#include <core/SkString.h>-#include <effects/SkDashPathEffect.h>-#include <utils/SkParsePath.h>--#include <harfbuzz/hb.h>--#ifdef AK_OS_MACOS-# include <LibGfx/Font/TypefaceCoreText.h>-#endif--template<>-constexpr bool AllocatedWithSystemAllocator<SkPath> = true;--template<>-constexpr bool AllocatedWithSystemAllocator<SkPathBuilder> = true;--namespace Gfx {--static FloatPoint to_gfx_point(SkPoint const& point)-{- return { point.x(), point.y() };-}--static SkPathFillType to_skia_path_fill_type(WindingRule winding_rule)-{- switch (winding_rule) {- case WindingRule::Nonzero:- return SkPathFillType::kWinding;- case WindingRule::EvenOdd:- return SkPathFillType::kEvenOdd;- }- VERIFY_NOT_REACHED();-}--namespace {--// Maps the coordinates of a glyph outline from font units, with y up, to pixels, with y down. A contour starts only at-// its first segment that goes somewhere, and segments that stay at one point are left out, so contours of a single-// point, which fonts use as anchors, add nothing to the path.-struct GlyphOutline {- SkPathBuilder& builder;- float units_to_pixels_x;- float units_to_pixels_y;- bool has_contour { false };- float current_x { 0 };- float current_y { 0 };-- float x(float units) const { return units * units_to_pixels_x; }- // Subtract from 0, so that a point on the baseline gets 0 and not -0.- float y(float units) const { return 0.0f - units * units_to_pixels_y; }-- bool is_at(float to_x, float to_y) const { return current_x == to_x && current_y == to_y; }-- void go_to(float to_x, float to_y)- {- if (!has_contour) {- has_contour = true;- builder.moveTo(x(current_x), y(current_y));- }- current_x = to_x;- current_y = to_y;- }-- void close_contour()- {- if (!has_contour)- return;- builder.close();- has_contour = false;- }-};--// NOTE: HarfBuzz emits the implicit line that closes each contour as a regular line_to before close_path. The-// quadratic callback must be set, otherwise HarfBuzz converts quadratic segments to cubics.-hb_draw_funcs_t* glyph_outline_draw_funcs()-{- static hb_draw_funcs_t* draw_funcs = [] {- auto* funcs = hb_draw_funcs_create();- hb_draw_funcs_set_move_to_func(- funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float to_x, float to_y, void*) {- auto& outline = *static_cast<GlyphOutline*>(draw_data);- outline.close_contour();- outline.current_x = to_x;- outline.current_y = to_y;- },- nullptr, nullptr);- hb_draw_funcs_set_line_to_func(- funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float to_x, float to_y, void*) {- auto& outline = *static_cast<GlyphOutline*>(draw_data);- if (outline.is_at(to_x, to_y))- return;- outline.go_to(to_x, to_y);- outline.builder.lineTo(outline.x(to_x), outline.y(to_y));- },- nullptr, nullptr);- hb_draw_funcs_set_quadratic_to_func(- funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float control_x, float control_y, float to_x, float to_y, void*) {- auto& outline = *static_cast<GlyphOutline*>(draw_data);- if (outline.is_at(control_x, control_y) && outline.is_at(to_x, to_y))- return;- outline.go_to(to_x, to_y);- outline.builder.quadTo(outline.x(control_x), outline.y(control_y), outline.x(to_x), outline.y(to_y));- },- nullptr, nullptr);- hb_draw_funcs_set_cubic_to_func(- funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, float control1_x, float control1_y, float control2_x, float control2_y, float to_x, float to_y, void*) {- auto& outline = *static_cast<GlyphOutline*>(draw_data);- if (outline.is_at(control1_x, control1_y) && outline.is_at(control2_x, control2_y) && outline.is_at(to_x, to_y))- return;- outline.go_to(to_x, to_y);- outline.builder.cubicTo(outline.x(control1_x), outline.y(control1_y), outline.x(control2_x), outline.y(control2_y), outline.x(to_x), outline.y(to_y));- },- nullptr, nullptr);- hb_draw_funcs_set_close_path_func(- funcs, [](hb_draw_funcs_t*, void* draw_data, hb_draw_state_t*, void*) {- static_cast<GlyphOutline*>(draw_data)->close_contour();- },- nullptr, nullptr);- hb_draw_funcs_make_immutable(funcs);- return funcs;- }();- return draw_funcs;-}--}--#ifdef AK_OS_MACOS-static SkPath core_text_glyph_outline(CTFontRef font, u32 glyph_id)-{- auto path = CTFontCreatePathForGlyph(font, static_cast<CGGlyph>(glyph_id), nullptr);- if (!path)- return {};- ScopeGuard release_path = [&] { CGPathRelease(path); };-- // CoreText gives points in pixels with y up.- SkPathBuilder builder;- CGPathApply(path, &builder, [](void* info, CGPathElement const* element) {- auto& builder = *static_cast<SkPathBuilder*>(info);- auto point = [&](size_t index) {- return SkPoint::Make(static_cast<float>(element->points[index].x), 0.0f - static_cast<float>(element->points[index].y));- };- switch (element->type) {- case kCGPathElementMoveToPoint:- builder.moveTo(point(0));- break;- case kCGPathElementAddLineToPoint:- builder.lineTo(point(0));- break;- case kCGPathElementAddQuadCurveToPoint:- builder.quadTo(point(0), point(1));- break;- case kCGPathElementAddCurveToPoint:- builder.cubicTo(point(0), point(1), point(2));- break;- case kCGPathElementCloseSubpath:- builder.close();- break;- }- });- return builder.detach();-}-#endif--namespace {--// Gives the outlines of the glyphs of a font in pixels, with their origin on the baseline.-class GlyphOutliner {- AK_MAKE_NONCOPYABLE(GlyphOutliner);- AK_MAKE_NONMOVABLE(GlyphOutliner);--public:- explicit GlyphOutliner(Font const& font)- : m_font(font)- {-#ifdef AK_OS_MACOS- if (auto const* core_text_typeface = as_if<TypefaceCoreText>(font.typeface()); core_text_typeface && core_text_typeface->has_outlines_that_only_core_text_draws())- m_core_text_font = create_core_text_font_with_variations(core_text_typeface->core_text_font(), font.pixel_size(), font.variation_settings().to_sorted_list());-#endif- }-- ~GlyphOutliner()- {-#ifdef AK_OS_MACOS- if (m_core_text_font)- CFRelease(m_core_text_font);-#endif- }-- SkPath outline(u32 glyph_id) const- {-#ifdef AK_OS_MACOS- if (m_core_text_font)- return core_text_glyph_outline(m_core_text_font, glyph_id);-#endif-- auto* hb_font = m_font.harfbuzz_font();- int x_scale = 0;- int y_scale = 0;- hb_font_get_scale(hb_font, &x_scale, &y_scale);- if (x_scale <= 0 || y_scale <= 0)- return {};- SkPathBuilder builder;- GlyphOutline outline {- .builder = builder,- .units_to_pixels_x = m_font.pixel_size() / static_cast<float>(x_scale),- .units_to_pixels_y = m_font.pixel_size() / static_cast<float>(y_scale),- };- hb_font_draw_glyph(hb_font, glyph_id, glyph_outline_draw_funcs(), &outline);- outline.close_contour();- return builder.detach();- }--private:- Font const& m_font;-#ifdef AK_OS_MACOS- // The font at its size and variations, for outlines that only CoreText draws.- CTFontRef m_core_text_font { nullptr };-#endif-};--}--NonnullOwnPtr<Gfx::PathImplSkia> PathImplSkia::create()-{- return adopt_own(*new PathImplSkia);-}--PathImplSkia::PathImplSkia()- : m_path_builder(adopt_own(*new SkPathBuilder))-{-}--PathImplSkia::PathImplSkia(PathImplSkia const& other)- : m_last_move_to(other.m_last_move_to)- , m_has_current_point(other.m_has_current_point)- , m_path_builder(adopt_own(*new SkPathBuilder(*other.m_path_builder)))-{-}--PathImplSkia::~PathImplSkia()-{- delete m_cached_path.load(AK::memory_order_relaxed);-}--SkPath const& PathImplSkia::sk_path() const-{- if (auto* cached_path = m_cached_path.load(AK::memory_order_acquire))- return *cached_path;- auto* path = new SkPath(m_path_builder->snapshot());- SkPath* expected = nullptr;- if (m_cached_path.compare_exchange_strong(expected, path, AK::memory_order_acq_rel))- return *path;- delete path;- return *expected;-}--SkPathBuilder& PathImplSkia::sk_path_builder()-{- delete m_cached_path.exchange(nullptr, AK::memory_order_relaxed);- return *m_path_builder;-}--void PathImplSkia::update_state_from_builder()-{- update_state_from_path(sk_path());-}--void PathImplSkia::set_path(SkPath const& path)-{- sk_path_builder() = SkPathBuilder(path);- update_state_from_path(path);-}--void PathImplSkia::update_state_from_path(SkPath const& path)-{- m_has_current_point = false;- m_last_move_to = {};-- auto const points = path.points();- size_t point_index = 0;- for (auto verb : path.verbs()) {- switch (verb) {- case SkPathVerb::kMove:- m_has_current_point = true;- m_last_move_to = to_gfx_point(points[point_index++]);- break;- case SkPathVerb::kLine:- m_has_current_point = true;- point_index += 1;- break;- case SkPathVerb::kQuad:- case SkPathVerb::kConic:- m_has_current_point = true;- point_index += 2;- break;- case SkPathVerb::kCubic:- m_has_current_point = true;- point_index += 3;- break;- case SkPathVerb::kClose:- m_has_current_point = true;- break;- }- }-}--void PathImplSkia::clear()-{- sk_path_builder().reset();- m_last_move_to = {};- m_has_current_point = false;-}--void PathImplSkia::move_to(Gfx::FloatPoint const& point)-{- m_last_move_to = point;- m_has_current_point = true;- sk_path_builder().moveTo(point.x(), point.y());-}--void PathImplSkia::line_to(Gfx::FloatPoint const& point)-{- if (!m_has_current_point) {- move_to(point);- return;- }- sk_path_builder().lineTo(point.x(), point.y());-}--void PathImplSkia::close()-{- if (!m_has_current_point)- return;- sk_path_builder().close();- sk_path_builder().moveTo(m_last_move_to.x(), m_last_move_to.y());-}--void PathImplSkia::elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep)-{- if (!m_has_current_point) {- move_to(point);- return;- }-- SkPoint skPoint = SkPoint::Make(point.x(), point.y());- SkPoint skRadii = SkPoint::Make(radii.width(), radii.height());- SkScalar skXRotation = SkFloatToScalar(sk_float_radians_to_degrees(x_axis_rotation));- SkPathBuilder::ArcSize skLargeArc = large_arc ? SkPathBuilder::kLarge_ArcSize : SkPathBuilder::kSmall_ArcSize;- SkPathDirection skSweep = sweep ? SkPathDirection::kCW : SkPathDirection::kCCW;- sk_path_builder().arcTo(skRadii, skXRotation, skLargeArc, skSweep, skPoint);-}--void PathImplSkia::arc_to(FloatPoint point, float radius, bool large_arc, bool sweep)-{- if (!m_has_current_point) {- move_to(point);- return;- }-- SkPoint skPoint = SkPoint::Make(point.x(), point.y());- SkPoint skRadii = SkPoint::Make(radius, radius);- SkPathBuilder::ArcSize skLargeArc = large_arc ? SkPathBuilder::kLarge_ArcSize : SkPathBuilder::kSmall_ArcSize;- SkPathDirection skSweep = sweep ? SkPathDirection::kCW : SkPathDirection::kCCW;- sk_path_builder().arcTo(skRadii, 0, skLargeArc, skSweep, skPoint);-}--void PathImplSkia::quadratic_bezier_curve_to(FloatPoint through, FloatPoint point)-{- if (!m_has_current_point)- move_to(through);- sk_path_builder().quadTo(through.x(), through.y(), point.x(), point.y());-}--void PathImplSkia::cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2)-{- if (!m_has_current_point)- move_to(c1);- sk_path_builder().cubicTo(c1.x(), c1.y(), c2.x(), c2.y(), p2.x(), p2.y());-}--void PathImplSkia::glyph_run(GlyphRun const& glyph_run)-{- if (glyph_run.font().is_invisible())- return;- auto& path_builder = sk_path_builder();- path_builder.setFillType(SkPathFillType::kWinding);- auto font_ascent = glyph_run.font().pixel_metrics().ascent;- GlyphOutliner outliner { glyph_run.font() };- for (auto const& glyph : glyph_run.glyphs())- path_builder.addPath(outliner.outline(glyph.glyph_id), glyph.position.x(), glyph.position.y() + font_ascent);- update_state_from_path(sk_path());-}--// By default, Skia measures a curve by the lengths of the lines between points along it that are at most half a unit off-// the curve, which leaves the length of a circle with a radius of 25 units about 1 unit short. Measure curves sixteen-// times as precisely instead.-static constexpr SkScalar path_measure_resolution_scale = 16;--// The furthest that the lines between points along a curve stay off it when Skia measures the curve.-static constexpr float path_measure_tolerance = 0.5f / path_measure_resolution_scale;--// The most lines with which to follow a single curve, which bounds the number of vertices of a huge curve.-static constexpr u32 maximum_line_count_along_curve = 4096;--NonnullOwnPtr<PathImpl> PathImplSkia::place_glyph_runs_along(ReadonlySpan<NonnullRefPtr<GlyphRun>> glyph_runs, float offset) const-{- SkPathMeasure path_measure(sk_path(), false, path_measure_resolution_scale);- SkScalar path_length = path_measure.getLength();-- auto output_path = PathImplSkia::create();-- bool reached_end_of_path = false;- for (auto const& glyph_run : glyph_runs) {- if (glyph_run->font().is_invisible())- continue;- GlyphOutliner outliner { glyph_run->font() };- for (auto const& glyph : glyph_run->glyphs()) {- SkScalar glyph_distance = offset + glyph.position.x();-- SkPoint position;- SkVector tangent;- if (!path_measure.getPosTan(glyph_distance, &position, &tangent))- continue;-- SkScalar midpoint_distance = glyph_distance + (glyph.glyph_width / 2.0f);- if (midpoint_distance > path_length) {- reached_end_of_path = true;- break;- }-- SkMatrix matrix;- matrix.setTranslate(position.x(), position.y());- matrix.preRotate(SkRadiansToDegrees(std::atan2(tangent.y(), tangent.x())));- output_path->sk_path_builder().addPath(outliner.outline(glyph.glyph_id), matrix);- }- if (reached_end_of_path)- break;- }- output_path->update_state_from_builder();-- return output_path;-}--static SkPathBuilder copy_without_last_verb(SkPathBuilder const& builder)-{- auto const verbs = builder.verbs();- auto const points = builder.points();- auto const conic_weights = builder.conicWeights();- SkPathBuilder copy(builder.fillType());- size_t point_index = 0;- size_t conic_weight_index = 0;- for (size_t verb_index = 0; verb_index + 1 < verbs.size(); ++verb_index) {- switch (verbs[verb_index]) {- case SkPathVerb::kMove:- copy.moveTo(points[point_index]);- point_index += 1;- break;- case SkPathVerb::kLine:- copy.lineTo(points[point_index]);- point_index += 1;- break;- case SkPathVerb::kQuad:- copy.quadTo(points[point_index], points[point_index + 1]);- point_index += 2;- break;- case SkPathVerb::kConic:- copy.conicTo(points[point_index], points[point_index + 1], conic_weights[conic_weight_index++]);- point_index += 2;- break;- case SkPathVerb::kCubic:- copy.cubicTo(points[point_index], points[point_index + 1], points[point_index + 2]);- point_index += 3;- break;- case SkPathVerb::kClose:- copy.close();- break;- }- }- return copy;-}--void PathImplSkia::append_path(Gfx::Path const& other)-{- auto const& other_impl = static_cast<PathImplSkia const&>(other.impl());- auto const other_path = other_impl.sk_path();- auto& path_builder = sk_path_builder();- // The other path starts with a move. If this path ends with a move, the result has two moves in sequence. That is- // not a valid path, and the compositor gets an empty path. Remove the move first. A subpath with one point is not- // filled or stroked.- auto const verbs = path_builder.verbs();- if (!other_path.isEmpty() && verbs.size() > 1 && verbs.back() == SkPathVerb::kMove)- path_builder = copy_without_last_verb(path_builder);- path_builder.addPath(other_path);- if (other_impl.m_has_current_point) {- m_has_current_point = true;- m_last_move_to = other_impl.m_last_move_to;- }-}--Vector<u8> PathImplSkia::serialize_to_bytes() const-{- auto const& path = sk_path();- auto path_data_size = path.writeToMemory(nullptr);- Vector<u8> path_data;- path_data.resize(path_data_size);- path.writeToMemory(path_data.data());- return path_data;-}--void PathImplSkia::deserialize_from_bytes(ReadonlyBytes bytes)-{- set_path(SkPath::ReadFromMemory(bytes.data(), bytes.size()).value_or(SkPath {}));-}--bool PathImplSkia::is_empty() const-{- return !m_has_current_point;-}--Gfx::FloatPoint PathImplSkia::last_point() const-{- auto last = m_path_builder->getLastPt();- if (!last.has_value())- return {};- return { last->fX, last->fY };-}--Gfx::FloatRect PathImplSkia::bounding_box() const-{- auto bounds = m_path_builder->computeBounds();- return { bounds.fLeft, bounds.fTop, bounds.fRight - bounds.fLeft, bounds.fBottom - bounds.fTop };-}--float PathImplSkia::length() const-{- SkPathMeasure path_measure(sk_path(), false, path_measure_resolution_scale);- float length = 0;- do {- length += path_measure.getLength();- } while (path_measure.nextContour());- return length;-}--// The point at a distance along the path, clamped to its ends, and the unit tangent of the path there. The gaps between-// the subpaths do not add to the distance. A path without length is only its start point, where it has no tangent.-Optional<PointAlongPath> PathImplSkia::point_at_length(float distance) const-{- SkPathMeasure path_measure(sk_path(), false, path_measure_resolution_scale);- Optional<PointAlongPath> end_of_path;- auto remaining_distance = max(distance, 0.f);- do {- auto subpath_length = path_measure.getLength();- if (subpath_length <= 0)- continue;- SkPoint position;- SkVector tangent;- auto distance_in_subpath = min(remaining_distance, subpath_length);- if (!path_measure.getPosTan(distance_in_subpath, &position, &tangent))- continue;- end_of_path = PointAlongPath { { position.x(), position.y() }, { tangent.x(), tangent.y() } };- if (remaining_distance <= subpath_length)- return end_of_path;- remaining_distance -= subpath_length;- } while (path_measure.nextContour());-- if (end_of_path.has_value())- return end_of_path;- if (sk_path().countPoints() == 0)- return {};- auto start = sk_path().getPoint(0);- return PointAlongPath { { start.x(), start.y() }, { 0, 0 } };-}--// The number of lines with which to start following a curve, by Wang's formula: the square root of the largest second-// difference of its control points, scaled by its degree, over the tolerance. That keeps lines between points at equal-// parameter steps within the tolerance of the curve, and depends on how much the curve bends rather than on how long it-// is.-static u32 line_count_to_follow_curve(SkPathIter::Rec const& segment)-{- auto const& points = segment.fPoints;- auto second_difference = [&](size_t index) {- return SkPoint::Length(points[index].x() - 2 * points[index + 1].x() + points[index + 2].x(),- points[index].y() - 2 * points[index + 1].y() + points[index + 2].y());- };-- float scaled_second_difference = 0;- switch (segment.fVerb) {- case SkPathVerb::kQuad:- scaled_second_difference = second_difference(0) / 4;- break;- case SkPathVerb::kConic:- // A conic with a weight of at most 1, like the arcs of SVG paths, bends no more than the quadratic with the same- // control points.- scaled_second_difference = max(1.f, segment.conicWeight()) * second_difference(0) / 4;- break;- case SkPathVerb::kCubic:- scaled_second_difference = 3 * max(second_difference(0), second_difference(1)) / 4;- break;- default:- return 1;- }- auto line_count = AK::ceil(AK::sqrt(static_cast<double>(scaled_second_difference) / path_measure_tolerance));- return static_cast<u32>(clamp(line_count, 1., static_cast<double>(maximum_line_count_along_curve)));-}--struct CurveToFollow {- SkPathMeasure& measure;- float distance_to_curve;- Vector<PathVertex>& vertices;- u32 remaining_line_count;-};--// Appends the vertices between two points along a curve, splitting the line between them in half for as long as the-// curve passes further than the tolerance from it halfway, or until the curve has as many lines as it may have.-static void follow_curve_between(CurveToFollow& curve, float start_distance, FloatPoint start_point, float end_distance, FloatPoint end_point)-{- if (curve.remaining_line_count == 0)- return;- auto middle_distance = (start_distance + end_distance) / 2;- SkPoint position;- SkVector tangent;- if (!curve.measure.getPosTan(middle_distance, &position, &tangent))- return;- FloatPoint middle_point { position.x(), position.y() };- if (middle_point.distance_from((start_point + end_point) / 2) <= path_measure_tolerance)- return;-- --curve.remaining_line_count;- follow_curve_between(curve, start_distance, start_point, middle_distance, middle_point);- curve.vertices.append({ middle_point, curve.distance_to_curve + middle_distance, { tangent.x(), tangent.y() } });- follow_curve_between(curve, middle_distance, middle_point, end_distance, end_point);-}--// The vertices of polylines through the ends of the segments of the path, with their distance along it. Along a curved-// segment, the polylines pass through points along the curve that keep them within path_measure_tolerance of it. The-// gaps between the subpaths do not add to the distance, so a subpath starts at the distance its predecessor ends at. A-// path without length is only its start point.-Vector<PathVertex> PathImplSkia::vertices() const-{- auto to_point = [](SkPoint point) { return FloatPoint { point.x(), point.y() }; };-- // Each vertex has the unit tangent of the path there as its direction. Where the path changes direction at once,- // the vertex appears twice: with the direction in which the path arrives, and with the one in which it leaves. A- // subpath start that no segment with length leaves from has no direction.- Vector<PathVertex> vertices;- float distance = 0;- auto iterator = sk_path().iter();- while (auto segment = iterator.next()) {- auto const& points = segment->fPoints;- SkPathBuilder segment_builder;- segment_builder.moveTo(points[0]);- switch (segment->fVerb) {- case SkPathVerb::kMove:- vertices.append({ to_point(points[0]), distance, {} });- continue;- case SkPathVerb::kLine:- case SkPathVerb::kClose:- segment_builder.lineTo(points[1]);- break;- case SkPathVerb::kQuad:- segment_builder.quadTo(points[1], points[2]);- break;- case SkPathVerb::kConic:- segment_builder.conicTo(points[1], points[2], segment->conicWeight());- break;- case SkPathVerb::kCubic:- segment_builder.cubicTo(points[1], points[2], points[3]);- break;- }-- // A segment without length has no direction, and leaves the path where it was.- SkPathMeasure segment_measure(segment_builder.detach(), false, path_measure_resolution_scale);- auto segment_length = segment_measure.getLength();- if (segment_length <= 0)- continue;- auto direction_at = [&](float distance_in_segment) {- SkVector tangent;- if (!segment_measure.getPosTan(distance_in_segment, nullptr, &tangent))- return FloatVector2 {};- return FloatVector2 { tangent.x(), tangent.y() };- };-- auto start_direction = direction_at(0);- if (vertices.last().direction == FloatVector2 {})- vertices.last().direction = start_direction;- else if (vertices.last().direction != start_direction)- vertices.append({ to_point(points[0]), distance, start_direction });-- auto line_count = line_count_to_follow_curve(*segment);- CurveToFollow curve { segment_measure, distance, vertices, maximum_line_count_along_curve - line_count };- auto previous_distance = 0.f;- auto previous_point = to_point(points[0]);- for (u32 line = 1; line <= line_count; ++line) {- auto distance_in_segment = segment_length * static_cast<float>(line) / static_cast<float>(line_count);- SkPoint position;- SkVector tangent;- if (line == line_count)- position = points.back();- else if (!segment_measure.getPosTan(distance_in_segment, &position, &tangent))- continue;- follow_curve_between(curve, previous_distance, previous_point, distance_in_segment, to_point(position));- if (line < line_count)- vertices.append({ to_point(position), distance + distance_in_segment, { tangent.x(), tangent.y() } });- previous_distance = distance_in_segment;- previous_point = to_point(position);- }- distance += segment_length;- vertices.append({ to_point(points.back()), distance, direction_at(segment_length) });- }-- // Skia's iterator leaves out a move that ends the path.- if (vertices.is_empty() && sk_path().countPoints() > 0)- vertices.append({ to_point(sk_path().getPoint(0)), 0, {} });- return vertices;-}--bool PathImplSkia::contains(FloatPoint point, Gfx::WindingRule winding_rule) const-{- SkPath temp_path = sk_path();- temp_path.setFillType(to_skia_path_fill_type(winding_rule));- return temp_path.contains(point.x(), point.y());-}--void PathImplSkia::set_fill_type(Gfx::WindingRule winding_rule)-{- sk_path_builder().setFillType(to_skia_path_fill_type(winding_rule));-}--NonnullOwnPtr<PathImpl> PathImplSkia::clone() const-{- return adopt_own(*new PathImplSkia(*this));-}--NonnullOwnPtr<PathImplSkia> PathImplSkia::stroke_to_fill(Path::StrokeStyle const& style) const-{- auto outline = PathImplSkia::create();- // NB: Skia treats zero thickness as a hairline, which covers no area.- if (!(style.thickness > 0))- return outline;-- SkPaint paint;- paint.setStyle(SkPaint::kStroke_Style);- paint.setStrokeWidth(style.thickness);- paint.setStrokeCap(to_skia_cap(style.cap_style));- paint.setStrokeJoin(to_skia_join(style.join_style));- paint.setStrokeMiter(style.miter_limit);- if (!style.dash_array.is_empty())- paint.setPathEffect(SkDashPathEffect::Make({ style.dash_array.data(), style.dash_array.size() }, style.dash_offset));- skpathutils::FillPathWithPaint(sk_path(), paint, &outline->sk_path_builder());- outline->sk_path_builder().setFillType(SkPathFillType::kWinding);- outline->update_state_from_builder();- return outline;-}--Gfx::Path Path::stroke_to_fill(StrokeStyle const& style) const-{- return Gfx::Path { static_cast<PathImplSkia const&>(impl()).stroke_to_fill(style) };-}--NonnullOwnPtr<PathImpl> PathImplSkia::copy_transformed(Gfx::AffineTransform const& transform) const-{- auto new_path = adopt_own(*new PathImplSkia(*this));- auto matrix = SkMatrix::MakeAll(- transform.a(), transform.c(), transform.e(),- transform.b(), transform.d(), transform.f(),- 0, 0, 1);- new_path->sk_path_builder().transform(matrix);- if (new_path->m_has_current_point)- new_path->m_last_move_to = transform.map(new_path->m_last_move_to);- return new_path;-}--String PathImplSkia::to_svg_string() const-{- auto svg_string = SkParsePath::ToSVGString(sk_path());- return MUST(String::from_utf8(StringView { svg_string.c_str(), svg_string.size() }));-}--}diff --git a/Libraries/LibGfx/PathSkia.h b/Libraries/LibGfx/PathSkia.hdeleted file mode 100644index e6d32b738d1..00000000000--- a/Libraries/LibGfx/PathSkia.h+++ /dev/null@@ -1,75 +0,0 @@-/*- * Copyright (c) 2024, Andreas Kling <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Atomic.h>-#include <AK/OwnPtr.h>-#include <LibGfx/Path.h>--class SkPath;-class SkPathBuilder;--namespace Gfx {--class PathImplSkia final : public PathImpl {-public:- static NonnullOwnPtr<Gfx::PathImplSkia> create();-- virtual ~PathImplSkia() override;-- virtual void clear() override;- virtual void move_to(Gfx::FloatPoint const&) override;- virtual void line_to(Gfx::FloatPoint const&) override;- virtual void close() override;- virtual void elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep) override;- virtual void arc_to(FloatPoint point, float radius, bool large_arc, bool sweep) override;- virtual void quadratic_bezier_curve_to(FloatPoint through, FloatPoint point) override;- virtual void cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2) override;- virtual void glyph_run(GlyphRun const&) override;-- virtual void append_path(Gfx::Path const&) override;-- [[nodiscard]] virtual Vector<u8> serialize_to_bytes() const override;- virtual void deserialize_from_bytes(ReadonlyBytes) override;-- [[nodiscard]] virtual bool is_empty() const override;- virtual Gfx::FloatPoint last_point() const override;- virtual Gfx::FloatRect bounding_box() const override;- virtual float length() const override;- virtual Optional<PointAlongPath> point_at_length(float distance) const override;- virtual Vector<PathVertex> vertices() const override;- virtual bool contains(FloatPoint point, Gfx::WindingRule) const override;- virtual void set_fill_type(Gfx::WindingRule winding_rule) override;-- virtual NonnullOwnPtr<PathImpl> clone() const override;- virtual NonnullOwnPtr<PathImpl> copy_transformed(Gfx::AffineTransform const&) const override;- virtual NonnullOwnPtr<PathImpl> place_glyph_runs_along(ReadonlySpan<NonnullRefPtr<GlyphRun>>, float offset = 0) const override;-- virtual String to_svg_string() const override;-- [[nodiscard]] NonnullOwnPtr<PathImplSkia> stroke_to_fill(Path::StrokeStyle const&) const;-- SkPath const& sk_path() const;- SkPathBuilder& sk_path_builder();- void update_state_from_builder();--private:- PathImplSkia();- PathImplSkia(PathImplSkia const& other);-- void set_path(SkPath const&);- void update_state_from_path(SkPath const&);-- Gfx::FloatPoint m_last_move_to;- bool m_has_current_point { false };- NonnullOwnPtr<SkPathBuilder> m_path_builder;- // NB: Const queries may run on several threads at once, so the lazily built snapshot is- // published with a compare-and-swap.- mutable Atomic<SkPath*> m_cached_path { nullptr };-};--}diff --git a/Libraries/LibGfx/Rust/src/path.rs b/Libraries/LibGfx/Rust/src/path.rsindex 179bad9c386..c77bc0b47b4 100644--- a/Libraries/LibGfx/Rust/src/path.rs+++ b/Libraries/LibGfx/Rust/src/path.rs@@ -350,8 +350,7 @@ pub struct OwnedPath {}// SAFETY: OwnedPath uniquely owns its Gfx::Path. Every operation on a shared reference is a const-// query, which PathImplSkia makes safe to run concurrently by publishing its lazily built SkPath-// with a compare-and-swap.+// query, which only reads the path.unsafe impl Send for OwnedPath {}// SAFETY: See the Send implementation above.unsafe impl Sync for OwnedPath {}diff --git a/Services/Compositor/PainterSkia.cpp b/Services/Compositor/PainterSkia.cppindex 9ed6826a673..f75e58f4fbb 100644--- a/Services/Compositor/PainterSkia.cpp+++ b/Services/Compositor/PainterSkia.cpp@@ -17,7 +17,6 @@#include <LibGfx/DecodedImageFrame.h>#include <LibGfx/Filter.h>#include <LibGfx/Font/Font.h>-#include <LibGfx/PathSkia.h>#include <core/SkCanvas.h>#include <core/SkFont.h>diff --git a/Services/Compositor/SkiaUtils.cpp b/Services/Compositor/SkiaUtils.cppindex 66a004369da..b074beb2391 100644--- a/Services/Compositor/SkiaUtils.cpp+++ b/Services/Compositor/SkiaUtils.cpp@@ -29,9 +29,23 @@namespace Gfx {+static_assert(to_underlying(PathVerb::Move) == to_underlying(SkPathVerb::kMove));+static_assert(to_underlying(PathVerb::Line) == to_underlying(SkPathVerb::kLine));+static_assert(to_underlying(PathVerb::Quad) == to_underlying(SkPathVerb::kQuad));+static_assert(to_underlying(PathVerb::Conic) == to_underlying(SkPathVerb::kConic));+static_assert(to_underlying(PathVerb::Cubic) == to_underlying(SkPathVerb::kCubic));+static_assert(to_underlying(PathVerb::Close) == to_underlying(SkPathVerb::kClose));+static_assert(sizeof(PathVerb) == sizeof(SkPathVerb));+static_assert(sizeof(FloatPoint) == sizeof(SkPoint));+SkPath to_skia_path(Path const& path){- return static_cast<PathImplSkia const&>(path.impl()).sk_path();+ auto data = path.data();+ return SkPath::Raw(+ { reinterpret_cast<SkPoint const*>(data.points.data()), data.points.size() },+ { reinterpret_cast<SkPathVerb const*>(data.verbs.data()), data.verbs.size() },+ { data.conic_weights.data(), data.conic_weights.size() },+ to_skia_path_fill_type(data.winding_rule));}namespace {diff --git a/Services/Compositor/SkiaUtils.h b/Services/Compositor/SkiaUtils.hindex 0d68e77ef7e..813d7db2ee5 100644--- a/Services/Compositor/SkiaUtils.h+++ b/Services/Compositor/SkiaUtils.h@@ -14,7 +14,7 @@#include <LibGfx/CompositingAndBlendingOperator.h>#include <LibGfx/Filter.h>#include <LibGfx/PaintStyle.h>-#include <LibGfx/PathSkia.h>+#include <LibGfx/Path.h>#include <LibGfx/ScalingMode.h>#include <LibGfx/WindingRule.h>#include <core/SkBlender.h>diff --git a/Tests/LibWeb/Ref/input/svg/offset-merge-filters.html b/Tests/LibWeb/Ref/input/svg/offset-merge-filters.htmlindex 13da1538117..53654d6fcfc 100644--- a/Tests/LibWeb/Ref/input/svg/offset-merge-filters.html+++ b/Tests/LibWeb/Ref/input/svg/offset-merge-filters.html@@ -1,6 +1,6 @@<!DOCTYPE html><link rel="match" href="../../expected/svg/offset-merge-filters-ref.html" />-<meta name="fuzzy" content="0-1;0-59">+<meta name="fuzzy" content="0-2;0-59"><svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><defs><filter id="offsetMergeFilter" x="0" y="0" width="100" height="100">diff --git a/Tests/LibWeb/Screenshot/expected/canvas-filters.png b/Tests/LibWeb/Screenshot/expected/canvas-filters.pngindex 58af214d129..68891348767 100644Binary files a/Tests/LibWeb/Screenshot/expected/canvas-filters.png and b/Tests/LibWeb/Screenshot/expected/canvas-filters.png differdiff --git a/Tests/LibWeb/Screenshot/expected/canvas-implict-moves-and-lines.png b/Tests/LibWeb/Screenshot/expected/canvas-implict-moves-and-lines.pngindex 435ff2c05d5..9c52431c8d2 100644Binary files a/Tests/LibWeb/Screenshot/expected/canvas-implict-moves-and-lines.png and b/Tests/LibWeb/Screenshot/expected/canvas-implict-moves-and-lines.png differdiff --git a/Tests/LibWeb/Screenshot/expected/canvas-stroke-styles.png b/Tests/LibWeb/Screenshot/expected/canvas-stroke-styles.pngindex d146d1827c0..f278e06ed10 100644Binary files a/Tests/LibWeb/Screenshot/expected/canvas-stroke-styles.png and b/Tests/LibWeb/Screenshot/expected/canvas-stroke-styles.png differdiff --git a/Tests/LibWeb/Screenshot/expected/clip-path-basic-shapes.png b/Tests/LibWeb/Screenshot/expected/clip-path-basic-shapes.pngindex a9e5f3222d4..a02ac53f575 100644Binary files a/Tests/LibWeb/Screenshot/expected/clip-path-basic-shapes.png and b/Tests/LibWeb/Screenshot/expected/clip-path-basic-shapes.png differdiff --git a/Tests/LibWeb/Screenshot/expected/css-border-style-double.png b/Tests/LibWeb/Screenshot/expected/css-border-style-double.pngindex 18af8eceeb4..0f9207dfe07 100644Binary files a/Tests/LibWeb/Screenshot/expected/css-border-style-double.png and b/Tests/LibWeb/Screenshot/expected/css-border-style-double.png differdiff --git a/Tests/LibWeb/Screenshot/expected/css-border-style-groove.png b/Tests/LibWeb/Screenshot/expected/css-border-style-groove.pngindex 701e7474880..5f4cd7eca44 100644Binary files a/Tests/LibWeb/Screenshot/expected/css-border-style-groove.png and b/Tests/LibWeb/Screenshot/expected/css-border-style-groove.png differdiff --git a/Tests/LibWeb/Screenshot/expected/css-border-style-ridge.png b/Tests/LibWeb/Screenshot/expected/css-border-style-ridge.pngindex 3c47963dd63..643bf73816f 100644Binary files a/Tests/LibWeb/Screenshot/expected/css-border-style-ridge.png and b/Tests/LibWeb/Screenshot/expected/css-border-style-ridge.png differdiff --git a/Tests/LibWeb/Screenshot/expected/out-of-line-svg-object-fitting.png b/Tests/LibWeb/Screenshot/expected/out-of-line-svg-object-fitting.pngindex 4febc613f66..34a9de1c0ab 100644Binary files a/Tests/LibWeb/Screenshot/expected/out-of-line-svg-object-fitting.png and b/Tests/LibWeb/Screenshot/expected/out-of-line-svg-object-fitting.png differdiff --git a/Tests/LibWeb/Screenshot/expected/svg-filters-lb-website.png b/Tests/LibWeb/Screenshot/expected/svg-filters-lb-website.pngindex 156138c5b3d..3997e2228dd 100644Binary files a/Tests/LibWeb/Screenshot/expected/svg-filters-lb-website.png and b/Tests/LibWeb/Screenshot/expected/svg-filters-lb-website.png differdiff --git a/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.png b/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.pngindex 6cefd3940c6..1db6823dff7 100644Binary files a/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.png and b/Tests/LibWeb/Screenshot/expected/svg-image-document-nested-clip-path.png differdiff --git a/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.png b/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.pngindex 66770faa822..a6a8edac408 100644Binary files a/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.png and b/Tests/LibWeb/Screenshot/expected/svg-maskContentUnits.png differdiff --git a/Tests/LibWeb/Screenshot/expected/svg-pattern-under-scaled-ancestor.png b/Tests/LibWeb/Screenshot/expected/svg-pattern-under-scaled-ancestor.pngindex 7dbc3181831..7cd3491d086 100644Binary files a/Tests/LibWeb/Screenshot/expected/svg-pattern-under-scaled-ancestor.png and b/Tests/LibWeb/Screenshot/expected/svg-pattern-under-scaled-ancestor.png differdiff --git a/Tests/LibWeb/Screenshot/expected/svg-textPath.png b/Tests/LibWeb/Screenshot/expected/svg-textPath.pngindex 1a1168ccb7a..1f76d8dedec 100644Binary files a/Tests/LibWeb/Screenshot/expected/svg-textPath.png and b/Tests/LibWeb/Screenshot/expected/svg-textPath.png differdiff --git a/Tests/LibWeb/Screenshot/input/canvas-arcs-and-ellipses.html b/Tests/LibWeb/Screenshot/input/canvas-arcs-and-ellipses.htmlindex 2c5aba5f9d2..7bb79ac4cce 100644--- a/Tests/LibWeb/Screenshot/input/canvas-arcs-and-ellipses.html+++ b/Tests/LibWeb/Screenshot/input/canvas-arcs-and-ellipses.html@@ -1,5 +1,5 @@<!DOCTYPE html>-<meta name="fuzzy" content="maxDifference=0-5;totalPixels=0-567">+<meta name="fuzzy" content="maxDifference=0-5;totalPixels=0-600"><style>canvas {border: 1px solid black;diff --git a/Tests/LibWeb/Screenshot/input/css-border-style-ridge.html b/Tests/LibWeb/Screenshot/input/css-border-style-ridge.htmlindex fe8d8170042..8fe106ba11d 100644--- a/Tests/LibWeb/Screenshot/input/css-border-style-ridge.html+++ b/Tests/LibWeb/Screenshot/input/css-border-style-ridge.html@@ -1,5 +1,5 @@<!doctype html>-<meta name="fuzzy" content="maxDifference=0-2;totalPixels=0-273">+<meta name="fuzzy" content="maxDifference=0-2;totalPixels=0-274"><style>div {width: 200px;diff --git a/Tests/LibWeb/Screenshot/input/out-of-line-svg-object-fitting.html b/Tests/LibWeb/Screenshot/input/out-of-line-svg-object-fitting.htmlindex d30ce9324b5..53a1eb76a17 100644--- a/Tests/LibWeb/Screenshot/input/out-of-line-svg-object-fitting.html+++ b/Tests/LibWeb/Screenshot/input/out-of-line-svg-object-fitting.html@@ -1,5 +1,5 @@<!doctype html>-<meta name="fuzzy" content="maxDifference=0-7;totalPixels=0-8908" />+<meta name="fuzzy" content="maxDifference=0-7;totalPixels=0-8910" /><style>body {margin: 0;diff --git a/Tests/LibWeb/Text/expected/SVG/svg-geometry-queries-all-shapes.txt b/Tests/LibWeb/Text/expected/SVG/svg-geometry-queries-all-shapes.txtindex c9442b3aa80..6f546ea35ad 100644--- a/Tests/LibWeb/Text/expected/SVG/svg-geometry-queries-all-shapes.txt+++ b/Tests/LibWeb/Text/expected/SVG/svg-geometry-queries-all-shapes.txt@@ -1,16 +1,16 @@rect: length=240 point=(90, 10) fill=1011-rect with rx and ry: length=228.42 point=(90, 19.03) fill=1011-rect with percentage rx and auto ry: length=262.81 point=(116.89, 12.76) fill=1110-rect with oversized ry and auto rx: length=198.62 point=(88.47, 36.31) fill=1010+rect with rx and ry: length=228.44 point=(90, 19.04) fill=1011+rect with percentage rx and auto ry: length=262.83 point=(116.9, 12.76) fill=1110+rect with oversized ry and auto rx: length=198.65 point=(88.47, 36.3) fill=1010rect with zero width: length=0 fill=0000-circle: length=125.61 point=(90, 67.32) fill=0100-circle with percentages: length=99.21 point=(92.1, 63.68) fill=0100+circle: length=125.66 point=(90, 67.32) fill=0100+circle with percentages: length=99.25 point=(92.1, 63.68) fill=0100circle with zero r: length=0 fill=0000-ellipse: length=193.74 point=(83.97, 68.32) fill=0100-ellipse with percentages: length=193.74 point=(83.97, 68.32) fill=0100-ellipse with auto rx: length=125.61 point=(90, 67.32) fill=0100+ellipse: length=193.77 point=(83.97, 68.32) fill=0100+ellipse with percentages: length=193.77 point=(83.97, 68.32) fill=0100+ellipse with auto rx: length=125.66 point=(90, 67.32) fill=0100ellipse with auto radii: length=0 fill=0000-ellipse with negative ry: length=188.46 point=(85, 75.98) fill=0100+ellipse with negative ry: length=188.5 point=(85, 75.98) fill=0100line: length=100 point=(36.67, 40) fill=0000line with percentages: length=170.88 point=(73.33, 40) fill=0000polyline: length=130 point=(53.33, 10) fill=1001@@ -21,11 +21,11 @@ path with evenodd fill: length=600 point=(100, 100) fill=0101path with nonzero fill: length=600 point=(100, 100) fill=1111path with d property: length=100 point=(30, 36.67) fill=0000path without d: length=0 fill=0000-circle in viewBox: length=49.66 point=(46.05, 31.85) fill=1000+circle in viewBox: length=49.68 point=(46.05, 31.85) fill=1000line in viewBox: length=111.8 point=(33.33, 16.67) fill=0100-detached rect: length=91.37 point=(30, 7.61) fill=0001-detached circle: length=62.81 point=(45, 38.66) fill=1000-detached ellipse: length=96.85 point=(41.98, 39.16) fill=1000+detached rect: length=91.42 point=(30, 7.62) fill=0001+detached circle: length=62.83 point=(45, 38.66) fill=1000+detached ellipse: length=96.88 point=(41.98, 39.16) fill=1000detached line: length=50 point=(10, 13.33) fill=0000detached polygon: length=224.34 point=(84.78, 10) fill=1001detached path: length=209.44 point=(79.81, 10) fill=1001diff --git a/Tests/LibWeb/Text/expected/display_list/border-inner-corner-right-angle-all-edges.txt b/Tests/LibWeb/Text/expected/display_list/border-inner-corner-right-angle-all-edges.txtindex b6d68ddde33..3d00d3b0c3b 100644--- a/Tests/LibWeb/Text/expected/display_list/border-inner-corner-right-angle-all-edges.txt+++ b/Tests/LibWeb/Text/expected/display_list/border-inner-corner-right-angle-all-edges.txt@@ -8,10 +8,10 @@ AccumulatedVisualContext Tree:DisplayList:FillPath@s1/e0 path_bounding_rect=[166,12.651531 20x110.696945]FillPath@s1/e0 path_bounding_rect=[11.232849,113 168.56511x15]-FillPath@s1/e0 path_bounding_rect=[8,14.061594 8x107.876816]-FillPath@s1/e0 path_bounding_rect=[11.232849,7.999998 168.56511x15.000002]-FillPath@s1/e0 path_bounding_rect=[173,134.20204 15.0000305x117.59592]+FillPath@s1/e0 path_bounding_rect=[7.999998,14.061594 8.000002x107.876816]+FillPath@s1/e0 path_bounding_rect=[11.232849,8 168.56511x15]+FillPath@s1/e0 path_bounding_rect=[173,134.20204 15x117.59592]FillPath@s1/e0 path_bounding_rect=[12.651531,238 170.69693x20]-FillPath@s1/e0 path_bounding_rect=[7.9999995,134.20204 15x117.59592]-FillPath@s1/e0 path_bounding_rect=[12.651531,127.99999 170.69693x20.000008]+FillPath@s1/e0 path_bounding_rect=[8,134.20204 15x117.59592]+FillPath@s1/e0 path_bounding_rect=[12.651531,128 170.69693x20]diff --git a/Tests/LibWeb/Text/expected/display_list/dashed-border-with-border-radius.txt b/Tests/LibWeb/Text/expected/display_list/dashed-border-with-border-radius.txtindex dd2fbd37ad2..0690cd6592c 100644--- a/Tests/LibWeb/Text/expected/display_list/dashed-border-with-border-radius.txt+++ b/Tests/LibWeb/Text/expected/display_list/dashed-border-with-border-radius.txt@@ -6,16 +6,16 @@ AccumulatedVisualContext Tree:[e0 in s0] effects=[]DisplayList:-StrokePath@s1/e0 path_bounding_rect=[8,8 120x80] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=29.72-StrokePath@s1/e0 path_bounding_rect=[110.677666,95.322334 17.322334x65.35534] thickness=10 color=rgb(0, 0, 255) dash_array_size=2 dash_offset=14.81 inline_clips=[clip_path=[bounds: [112,96 16x64], curved path: 68 commands]]-StrokePath@s1/e0 path_bounding_rect=[15.322332,150.67767 105.35533x17.322327] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=12.41 inline_clips=[clip_path=[bounds: [16,152 104x17], curved path: 68 commands]]-StrokePath@s1/e0 path_bounding_rect=[8,95.322334 17.322332x65.35534] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=14.81 inline_clips=[clip_path=[bounds: [7,96 17x64], curved path: 68 commands]]-StrokePath@s1/e0 path_bounding_rect=[15.322332,87.99999 105.35533x17.322342] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=12.41 inline_clips=[clip_path=[bounds: [16,88 104x16], curved path: 68 commands]]+StrokePath@s1/e0 path_bounding_rect=[8,8 120x80] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=29.73+StrokePath@s1/e0 path_bounding_rect=[110.677666,95.322334 17.322334x65.35534] thickness=10 color=rgb(0, 0, 255) dash_array_size=2 dash_offset=14.82 inline_clips=[clip_path=[bounds: [112,96 16x64], curved path: 68 commands]]+StrokePath@s1/e0 path_bounding_rect=[15.322332,150.67767 105.35533x17.322327] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=12.41 inline_clips=[clip_path=[bounds: [16,152 104x16], curved path: 68 commands]]+StrokePath@s1/e0 path_bounding_rect=[7.999999,95.322334 17.322334x65.35534] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=14.82 inline_clips=[clip_path=[bounds: [8,96 16x64], curved path: 68 commands]]+StrokePath@s1/e0 path_bounding_rect=[15.322332,88 105.35533x17.322334] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=12.41 inline_clips=[clip_path=[bounds: [16,88 104x16], curved path: 68 commands]]StrokePath@s1/e0 path_bounding_rect=[8,168 120x80] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=30.93StrokePath@s1/e0 path_bounding_rect=[8,248 120x80] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=9.91StrokePath@s1/e0 path_bounding_rect=[110.677666,335.32233 17.322334x65.35535] thickness=10 color=rgb(0, 0, 255) dash_array_size=2 dash_offset=9.88 inline_clips=[clip_path=[bounds: [112,336 16x64], curved path: 68 commands]]StrokePath@s1/e0 path_bounding_rect=[15.322332,390.67767 105.35533x17.322327] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=9.93 inline_clips=[clip_path=[bounds: [16,392 104x16], curved path: 68 commands]]-StrokePath@s1/e0 path_bounding_rect=[8,335.32233 17.322332x65.35535] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=9.88 inline_clips=[clip_path=[bounds: [7,336 17x64], curved path: 68 commands]]-StrokePath@s1/e0 path_bounding_rect=[15.322332,327.99997 105.35533x17.322357] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=9.93 inline_clips=[clip_path=[bounds: [16,328 104x16], curved path: 68 commands]]+StrokePath@s1/e0 path_bounding_rect=[7.999999,335.32233 17.322334x65.35535] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=9.88 inline_clips=[clip_path=[bounds: [8,336 16x64], curved path: 68 commands]]+StrokePath@s1/e0 path_bounding_rect=[15.322332,328 105.35533x17.322327] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=9.93 inline_clips=[clip_path=[bounds: [16,328 104x16], curved path: 68 commands]]StrokePath@s1/e0 path_bounding_rect=[8,408 120x80] thickness=10 color=rgb(255, 0, 0) dash_array_size=2 dash_offset=10.31diff --git a/Tests/LibWeb/Text/expected/display_list/double-border-with-asymmetric-radii.txt b/Tests/LibWeb/Text/expected/display_list/double-border-with-asymmetric-radii.txtindex 80aeced6ac4..742357a0660 100644--- a/Tests/LibWeb/Text/expected/display_list/double-border-with-asymmetric-radii.txt+++ b/Tests/LibWeb/Text/expected/display_list/double-border-with-asymmetric-radii.txt@@ -6,12 +6,12 @@ AccumulatedVisualContext Tree:[e0 in s0] effects=[]DisplayList:-FillPath@s1/e0 path_bounding_rect=[192.04163,10.928932 15.958389x135.35535]+FillPath@s1/e0 path_bounding_rect=[192.04163,10.928932 15.958374x135.35535]FillPath@s1/e0 path_bounding_rect=[182.14214,22 11.857864x114.38478]-FillPath@s1/e0 path_bounding_rect=[10.928932,142.04163 185.35535x15.958389]-FillPath@s1/e0 path_bounding_rect=[22,132.14214 164.38478x11.85788]-FillPath@s1/e0 path_bounding_rect=[7.999997,19.715729 15.958373x135.35535]+FillPath@s1/e0 path_bounding_rect=[10.928932,142.04163 185.35535x15.958374]+FillPath@s1/e0 path_bounding_rect=[22,132.14214 164.38478x11.857864]+FillPath@s1/e0 path_bounding_rect=[7.9999967,19.715729 15.958374x135.35535]FillPath@s1/e0 path_bounding_rect=[22,29.615223 11.857864x114.38478]-FillPath@s1/e0 path_bounding_rect=[19.715729,8 185.35535x15.95837]+FillPath@s1/e0 path_bounding_rect=[19.715729,7.9999967 185.35535x15.958374]FillPath@s1/e0 path_bounding_rect=[29.615223,22 164.38478x11.857864]