SVGDecodedImageData.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/HTML/DecodedImageData.h>
  8. namespace Web::SVG {
  9. class SVGDecodedImageData final : public HTML::DecodedImageData {
  10. public:
  11. static ErrorOr<NonnullRefPtr<SVGDecodedImageData>> create(Page&, AK::URL const&, ByteBuffer encoded_svg);
  12. virtual ~SVGDecodedImageData() override;
  13. virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index, Gfx::IntSize) const override;
  14. virtual Optional<CSSPixels> intrinsic_width() const override;
  15. virtual Optional<CSSPixels> intrinsic_height() const override;
  16. virtual Optional<float> intrinsic_aspect_ratio() const override;
  17. // FIXME: Support SVG animations. :^)
  18. virtual int frame_duration(size_t) const override { return 0; }
  19. virtual size_t frame_count() const override { return 1; }
  20. virtual size_t loop_count() const override { return 0; }
  21. virtual bool is_animated() const override { return false; }
  22. private:
  23. class SVGPageClient;
  24. SVGDecodedImageData(NonnullOwnPtr<Page>, NonnullOwnPtr<SVGPageClient>, JS::Handle<DOM::Document>, JS::Handle<SVG::SVGSVGElement>);
  25. void render(Gfx::IntSize) const;
  26. mutable RefPtr<Gfx::Bitmap> m_bitmap;
  27. NonnullOwnPtr<Page> m_page;
  28. NonnullOwnPtr<SVGPageClient> m_page_client;
  29. JS::Handle<DOM::Document> m_document;
  30. JS::Handle<SVG::SVGSVGElement> m_root_element;
  31. };
  32. }