Skip to content

Commit 8c47fff

Browse files
committed
Round pattern tile dimensions to avoid subpixel artifacts #247
1 parent 909d9f8 commit 8c47fff

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

source/svgpaintelement.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "svglayoutstate.h"
33
#include "svgrenderstate.h"
44

5+
#include <cmath>
56
#include <set>
67

78
namespace lunasvg {
@@ -291,7 +292,10 @@ bool SVGPatternElement::applyPaint(SVGRenderState& state, float opacity) const
291292
auto xScale = currentTransform.xScale();
292293
auto yScale = currentTransform.yScale();
293294

294-
auto patternImage = Canvas::create(0, 0, patternRect.w * xScale, patternRect.h * yScale);
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);
295299
auto patternImageTransform = Transform::scaled(xScale, yScale);
296300

297301
const auto& viewBoxRect = attributes.viewBox();

0 commit comments

Comments
 (0)