Skip to content

Commit a0803bb

Browse files
committed
Prevent pattern from being downscaled below its original size #247
Clamp `xScale` and `yScale` to a minimum of `1` when rendering patterns, ensuring the bitmap is never scaled below its native resolution. This avoids distortion and visual artifacts caused by downscaling at very small pattern scales while maintaining correct tiling and alignment.
1 parent 8c47fff commit a0803bb

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

source/svgpaintelement.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,10 @@ bool SVGPatternElement::applyPaint(SVGRenderState& state, float opacity) const
289289
}
290290

291291
auto currentTransform = attributes.patternTransform() * state.currentTransform();
292-
auto xScale = currentTransform.xScale();
293-
auto yScale = currentTransform.yScale();
292+
auto xScale = std::max(1.f, currentTransform.xScale());
293+
auto yScale = std::max(1.f, currentTransform.yScale());
294294

295-
auto tileWidth = std::round(patternRect.w * xScale);
296-
auto tileHeight = std::round(patternRect.h * yScale);
297-
298-
auto patternImage = Canvas::create(0, 0, tileWidth, tileHeight);
295+
auto patternImage = Canvas::create(0, 0, patternRect.w * xScale, patternRect.h * yScale);
299296
auto patternImageTransform = Transform::scaled(xScale, yScale);
300297

301298
const auto& viewBoxRect = attributes.viewBox();
@@ -312,7 +309,7 @@ bool SVGPatternElement::applyPaint(SVGRenderState& state, float opacity) const
312309

313310
auto patternTransform = attributes.patternTransform();
314311
patternTransform.translate(patternRect.x, patternRect.y);
315-
patternTransform.scale(patternRect.w / patternImage->width(), patternRect.h / patternImage->height());
312+
patternTransform.scale(1.f / xScale, 1.f / yScale);
316313
state->setTexture(*patternImage, TextureType::Tiled, opacity, patternTransform);
317314
return true;
318315
}

0 commit comments

Comments
 (0)