diff --git a/Libraries/LibGfx/ImageFormats/TinyVGLoader.cpp b/Libraries/LibGfx/ImageFormats/TinyVGLoader.cpp index 3b7a8933b21..0abdeb8756b 100644 --- a/Libraries/LibGfx/ImageFormats/TinyVGLoader.cpp +++ b/Libraries/LibGfx/ImageFormats/TinyVGLoader.cpp @@ -471,29 +471,25 @@ ErrorOr> TinyVGDecodedImageData::decode(St return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TinyVGDecodedImageData({ header.width, header.height }, move(draw_commands)))); } -void TinyVGDecodedImageData::draw_transformed(Painter& painter, AffineTransform transform) const +void TinyVGDecodedImageData::draw(Painter& painter) const { - // FIXME: Correctly handle non-uniform scales. - auto scale = max(transform.x_scale(), transform.y_scale()); for (auto const& command : draw_commands()) { - auto draw_path = command.path.copy_transformed(transform); + auto draw_path = command.path; if (command.fill.has_value()) { auto fill_path = draw_path; fill_path.close_all_subpaths(); command.fill->visit( [&](Color color) { painter.fill_path(fill_path, color, WindingRule::EvenOdd); }, - [&](NonnullRefPtr style) { - const_cast(*style).set_gradient_transform(transform); + [&](NonnullRefPtr const& style) { painter.fill_path(fill_path, style, 1.0f, WindingRule::EvenOdd); }); } if (command.stroke.has_value()) { command.stroke->visit( - [&](Color color) { painter.stroke_path(draw_path, color, command.stroke_width * scale); }, - [&](NonnullRefPtr style) { - const_cast(*style).set_gradient_transform(transform); - painter.stroke_path(draw_path, style, command.stroke_width * scale, 1.0f); + [&](Color color) { painter.stroke_path(draw_path, color, command.stroke_width); }, + [&](NonnullRefPtr const& style) { + painter.stroke_path(draw_path, style, command.stroke_width, 1.0f); }); } } diff --git a/Libraries/LibGfx/ImageFormats/TinyVGLoader.h b/Libraries/LibGfx/ImageFormats/TinyVGLoader.h index dff2af12f75..6f7864b7710 100644 --- a/Libraries/LibGfx/ImageFormats/TinyVGLoader.h +++ b/Libraries/LibGfx/ImageFormats/TinyVGLoader.h @@ -53,7 +53,7 @@ public: return m_size; } - virtual void draw_transformed(Painter&, AffineTransform) const override; + virtual void draw(Painter&) const override; ReadonlySpan draw_commands() const { diff --git a/Libraries/LibGfx/VectorGraphic.cpp b/Libraries/LibGfx/VectorGraphic.cpp index 255c55f44ad..0f3f7bee535 100644 --- a/Libraries/LibGfx/VectorGraphic.cpp +++ b/Libraries/LibGfx/VectorGraphic.cpp @@ -9,26 +9,25 @@ namespace Gfx { -void VectorGraphic::draw_into(Painter& painter, IntRect const& dest, AffineTransform transform) const +ErrorOr> VectorGraphic::bitmap(IntSize size, AffineTransform transform) const { + auto bitmap = TRY(Bitmap::create(Gfx::BitmapFormat::BGRA8888, size)); + auto painter = PainterSkia::create(bitmap); + // Apply the transform then center within destination rectangle (this ignores any translation from the transform): // This allows you to easily rotate or flip the image before painting. - auto transformed_rect = transform.map(FloatRect { {}, size() }); - auto scale = min(float(dest.width()) / transformed_rect.width(), float(dest.height()) / transformed_rect.height()); - auto centered = FloatRect { {}, transformed_rect.size().scaled(scale) }.centered_within(dest.to_type()); + auto transformed_rect = transform.map(FloatRect { {}, this->size() }); + auto scale = min(float(size.width()) / transformed_rect.width(), float(size.height()) / transformed_rect.height()); + auto centered = FloatRect { {}, transformed_rect.size().scaled(scale) }.centered_within(IntRect { {}, size }.to_type()); auto view_transform = AffineTransform {} .translate(centered.location()) .multiply(AffineTransform {}.scale(scale, scale)) .multiply(AffineTransform {}.translate(-transformed_rect.location())) .multiply(transform); - draw_transformed(painter, view_transform); -} -ErrorOr> VectorGraphic::bitmap(IntSize size, AffineTransform transform) const -{ - auto bitmap = TRY(Bitmap::create(Gfx::BitmapFormat::BGRA8888, size)); - auto painter = PainterSkia::create(bitmap); - draw_into(*painter, IntRect { {}, size }, transform); + painter->set_transform(view_transform); + draw(*painter); + return bitmap; } diff --git a/Libraries/LibGfx/VectorGraphic.h b/Libraries/LibGfx/VectorGraphic.h index 6f048b4dcec..73ad93ae250 100644 --- a/Libraries/LibGfx/VectorGraphic.h +++ b/Libraries/LibGfx/VectorGraphic.h @@ -17,13 +17,12 @@ namespace Gfx { class VectorGraphic : public RefCounted { public: virtual IntSize intrinsic_size() const = 0; - virtual void draw_transformed(Painter&, AffineTransform) const = 0; + virtual void draw(Painter&) const = 0; IntSize size() const { return intrinsic_size(); } IntRect rect() const { return { {}, size() }; } ErrorOr> bitmap(IntSize size, AffineTransform = {}) const; - void draw_into(Painter& painter, IntRect const& dest, AffineTransform = {}) const; virtual ~VectorGraphic() = default; }; diff --git a/UI/Qt/TVGIconEngine.cpp b/UI/Qt/TVGIconEngine.cpp index 862291bcbc8..9062b80dd0c 100644 --- a/UI/Qt/TVGIconEngine.cpp +++ b/UI/Qt/TVGIconEngine.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -34,12 +33,7 @@ QPixmap TVGIconEngine::pixmap(QSize const& size, QIcon::Mode mode, QIcon::State auto key = pixmap_cache_key(size, mode, state); if (QPixmapCache::find(key, &pixmap)) return pixmap; - auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { size.width(), size.height() })); - - auto painter = Gfx::PainterSkia::create(bitmap); - painter->clear_rect(bitmap->rect().to_type(), Gfx::Color::Transparent); - - m_image_data->draw_into(*painter, bitmap->rect()); + auto bitmap = MUST(m_image_data->bitmap({ size.width(), size.height() })); for (auto const& filter : m_filters) { if (filter->mode() == mode) {