SVGGraphicsElement.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibGfx/PaintStyle.h>
  9. #include <LibGfx/Painter.h>
  10. #include <LibGfx/Path.h>
  11. #include <LibWeb/DOM/Node.h>
  12. #include <LibWeb/SVG/AttributeParser.h>
  13. #include <LibWeb/SVG/SVGElement.h>
  14. #include <LibWeb/SVG/SVGGradientElement.h>
  15. #include <LibWeb/SVG/TagNames.h>
  16. #include <LibWeb/SVG/ViewBox.h>
  17. namespace Web::SVG {
  18. class SVGGraphicsElement : public SVGElement {
  19. WEB_PLATFORM_OBJECT(SVGGraphicsElement, SVGElement);
  20. public:
  21. virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
  22. virtual void attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  23. Optional<Gfx::Color> fill_color() const;
  24. Optional<FillRule> fill_rule() const;
  25. Optional<Gfx::Color> stroke_color() const;
  26. Optional<float> stroke_width() const;
  27. Optional<float> fill_opacity() const;
  28. Optional<float> stroke_opacity() const;
  29. float visible_stroke_width() const
  30. {
  31. if (auto color = stroke_color(); color.has_value() && color->alpha() > 0)
  32. return stroke_width().value_or(0);
  33. return 0;
  34. }
  35. Gfx::AffineTransform get_transform() const;
  36. Optional<Gfx::PaintStyle const&> fill_paint_style(SVGPaintContext const&) const;
  37. Optional<Gfx::PaintStyle const&> stroke_paint_style(SVGPaintContext const&) const;
  38. Optional<ViewBox> view_box() const;
  39. protected:
  40. SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
  41. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  42. Optional<Gfx::PaintStyle const&> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
  43. Gfx::AffineTransform m_transform = {};
  44. };
  45. Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);
  46. }