SVGGraphicsElement.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. namespace Web::SVG {
  17. class SVGGraphicsElement : public SVGElement {
  18. WEB_PLATFORM_OBJECT(SVGGraphicsElement, SVGElement);
  19. public:
  20. virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
  21. virtual void attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  22. Optional<Gfx::Color> fill_color() const;
  23. Optional<FillRule> fill_rule() const;
  24. Optional<Gfx::Color> stroke_color() const;
  25. Optional<float> stroke_width() const;
  26. Optional<float> fill_opacity() const;
  27. Optional<float> stroke_opacity() const;
  28. float visible_stroke_width() const
  29. {
  30. if (auto color = stroke_color(); color.has_value() && color->alpha() > 0)
  31. return stroke_width().value_or(0);
  32. return 0;
  33. }
  34. Gfx::AffineTransform get_transform() const;
  35. Optional<Gfx::PaintStyle const&> fill_paint_style(SVGPaintContext const&) const;
  36. Optional<Gfx::PaintStyle const&> stroke_paint_style(SVGPaintContext const&) const;
  37. protected:
  38. SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
  39. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  40. Optional<Gfx::PaintStyle const&> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
  41. Gfx::AffineTransform m_transform = {};
  42. };
  43. Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);
  44. }