mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-04 23:30:20 +00:00
LibWeb: Clip underlying Painter in CRC2D::clip()
This commit is contained in:
parent
57128f489a
commit
5aeb8ebebc
Notes:
github-actions[bot]
2024-08-20 07:37:46 +00:00
Author: https://github.com/awesomekling
Commit: 5aeb8ebebc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1024
5 changed files with 15 additions and 14 deletions
|
@ -35,6 +35,8 @@ public:
|
||||||
|
|
||||||
virtual void save() = 0;
|
virtual void save() = 0;
|
||||||
virtual void restore() = 0;
|
virtual void restore() = 0;
|
||||||
|
|
||||||
|
virtual void clip(Gfx::Path const&, Gfx::WindingRule) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,4 +275,11 @@ void PainterSkia::restore()
|
||||||
impl().canvas()->restore();
|
impl().canvas()->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PainterSkia::clip(Gfx::Path const& path, Gfx::WindingRule winding_rule)
|
||||||
|
{
|
||||||
|
auto sk_path = to_skia_path(path);
|
||||||
|
sk_path.setFillType(to_skia_path_fill_type(winding_rule));
|
||||||
|
impl().canvas()->clipPath(sk_path, SkClipOp::kIntersect, true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
virtual void set_transform(Gfx::AffineTransform const&) override;
|
virtual void set_transform(Gfx::AffineTransform const&) override;
|
||||||
virtual void save() override;
|
virtual void save() override;
|
||||||
virtual void restore() override;
|
virtual void restore() override;
|
||||||
|
virtual void clip(Gfx::Path const&, Gfx::WindingRule) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Impl;
|
struct Impl;
|
||||||
|
|
|
@ -24,11 +24,6 @@ namespace Web::HTML {
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvasstate
|
// https://html.spec.whatwg.org/multipage/canvas.html#canvasstate
|
||||||
class CanvasState {
|
class CanvasState {
|
||||||
public:
|
public:
|
||||||
struct ClipPath {
|
|
||||||
Gfx::Path path;
|
|
||||||
Gfx::WindingRule winding_rule;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~CanvasState() = default;
|
virtual ~CanvasState() = default;
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
@ -87,7 +82,6 @@ public:
|
||||||
bool image_smoothing_enabled { true };
|
bool image_smoothing_enabled { true };
|
||||||
Bindings::ImageSmoothingQuality image_smoothing_quality { Bindings::ImageSmoothingQuality::Low };
|
Bindings::ImageSmoothingQuality image_smoothing_quality { Bindings::ImageSmoothingQuality::Low };
|
||||||
float global_alpha = { 1 };
|
float global_alpha = { 1 };
|
||||||
Optional<ClipPath> clip;
|
|
||||||
RefPtr<CSS::CSSStyleValue> font_style_value { nullptr };
|
RefPtr<CSS::CSSStyleValue> font_style_value { nullptr };
|
||||||
RefPtr<Gfx::Font const> current_font { nullptr };
|
RefPtr<Gfx::Font const> current_font { nullptr };
|
||||||
Bindings::CanvasTextAlign text_align { Bindings::CanvasTextAlign::Start };
|
Bindings::CanvasTextAlign text_align { Bindings::CanvasTextAlign::Start };
|
||||||
|
|
|
@ -543,15 +543,12 @@ CanvasRenderingContext2D::PreparedText CanvasRenderingContext2D::prepare_text(By
|
||||||
|
|
||||||
void CanvasRenderingContext2D::clip_internal(Gfx::Path& path, Gfx::WindingRule winding_rule)
|
void CanvasRenderingContext2D::clip_internal(Gfx::Path& path, Gfx::WindingRule winding_rule)
|
||||||
{
|
{
|
||||||
// FIXME: This should calculate the new clip path by intersecting the given path with the current one.
|
auto* painter = this->painter();
|
||||||
// See: https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-clip-dev
|
if (!painter)
|
||||||
path.close_all_subpaths();
|
|
||||||
if (drawing_state().clip.has_value()) {
|
|
||||||
auto& current_clip = drawing_state().clip->path;
|
|
||||||
current_clip.intersect(path);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
drawing_state().clip = CanvasState::ClipPath { path, winding_rule };
|
path.close_all_subpaths();
|
||||||
|
painter->clip(path, winding_rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasRenderingContext2D::clip(StringView fill_rule)
|
void CanvasRenderingContext2D::clip(StringView fill_rule)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue