/src/serenity/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibWeb/Layout/SVGGraphicsBox.h> |
10 | | #include <LibWeb/Painting/SVGMaskable.h> |
11 | | #include <LibWeb/Painting/SVGPaintable.h> |
12 | | |
13 | | namespace Web::Painting { |
14 | | |
15 | | class SVGGraphicsPaintable : public SVGPaintable |
16 | | , public SVGMaskable { |
17 | | JS_CELL(SVGGraphicsPaintable, SVGPaintable); |
18 | | |
19 | | public: |
20 | | class ComputedTransforms { |
21 | | public: |
22 | | ComputedTransforms(Gfx::AffineTransform svg_to_viewbox_transform, Gfx::AffineTransform svg_transform) |
23 | 0 | : m_svg_to_viewbox_transform(svg_to_viewbox_transform) |
24 | 0 | , m_svg_transform(svg_transform) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | 0 | ComputedTransforms() = default; |
29 | | |
30 | 0 | Gfx::AffineTransform const& svg_to_viewbox_transform() const { return m_svg_to_viewbox_transform; } |
31 | 0 | Gfx::AffineTransform const& svg_transform() const { return m_svg_transform; } |
32 | | |
33 | | Gfx::AffineTransform svg_to_css_pixels_transform( |
34 | | Optional<Gfx::AffineTransform const&> additional_svg_transform = {}) const |
35 | 0 | { |
36 | 0 | return Gfx::AffineTransform {}.multiply(svg_to_viewbox_transform()).multiply(additional_svg_transform.value_or(Gfx::AffineTransform {})).multiply(svg_transform()); |
37 | 0 | } |
38 | | |
39 | | Gfx::AffineTransform svg_to_device_pixels_transform(PaintContext const& context) const |
40 | 0 | { |
41 | 0 | auto css_scale = context.device_pixels_per_css_pixel(); |
42 | 0 | return Gfx::AffineTransform {}.scale({ css_scale, css_scale }).multiply(svg_to_css_pixels_transform(context.svg_transform())); |
43 | 0 | } |
44 | | |
45 | | private: |
46 | | Gfx::AffineTransform m_svg_to_viewbox_transform {}; |
47 | | Gfx::AffineTransform m_svg_transform {}; |
48 | | }; |
49 | | |
50 | | static JS::NonnullGCPtr<SVGGraphicsPaintable> create(Layout::SVGGraphicsBox const&); |
51 | | |
52 | | Layout::SVGGraphicsBox const& layout_box() const; |
53 | | |
54 | 0 | virtual JS::GCPtr<DOM::Node const> dom_node_of_svg() const override { return dom_node(); } |
55 | 0 | virtual Optional<CSSPixelRect> get_masking_area() const override { return get_masking_area_of_svg(); } |
56 | 0 | virtual Optional<Gfx::Bitmap::MaskKind> get_mask_type() const override { return get_mask_type_of_svg(); } |
57 | 0 | virtual RefPtr<Gfx::Bitmap> calculate_mask(PaintContext& paint_context, CSSPixelRect const& masking_area) const override { return calculate_mask_of_svg(paint_context, masking_area); } |
58 | | |
59 | | void set_computed_transforms(ComputedTransforms computed_transforms) |
60 | 0 | { |
61 | 0 | m_computed_transforms = computed_transforms; |
62 | 0 | } |
63 | | |
64 | | ComputedTransforms const& computed_transforms() const |
65 | 0 | { |
66 | 0 | return m_computed_transforms; |
67 | 0 | } |
68 | | |
69 | | protected: |
70 | | SVGGraphicsPaintable(Layout::SVGGraphicsBox const&); |
71 | | |
72 | | ComputedTransforms m_computed_transforms; |
73 | | }; |
74 | | |
75 | | } |