Skip to content

Commit

Permalink
Fix viewBox clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Jan 19, 2025
1 parent e82b745 commit 651bef6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions source/svgproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,13 @@ bool SVGPreserveAspectRatio::parse(std::string_view input)
Rect SVGPreserveAspectRatio::getClipRect(const Rect& viewBoxRect, const Size& viewportSize) const
{
assert(!viewBoxRect.isEmpty() && !viewportSize.isEmpty());
if(m_meetOrSlice == MeetOrSlice::Meet)
return viewBoxRect;
auto scale = std::max(viewportSize.w / viewBoxRect.w, viewportSize.h / viewBoxRect.h);
auto xScale = viewportSize.w / viewBoxRect.w;
auto yScale = viewportSize.h / viewBoxRect.h;
if(m_alignType == AlignType::None) {
return Rect(viewBoxRect.x, viewBoxRect.y, viewportSize.w / xScale, viewportSize.h / yScale);
}

auto scale = (m_meetOrSlice == MeetOrSlice::Meet) ? std::min(xScale, yScale) : std::max(xScale, yScale);
auto xOffset = -viewBoxRect.x * scale;
auto yOffset = -viewBoxRect.y * scale;
auto viewWidth = viewBoxRect.w * scale;
Expand Down

0 comments on commit 651bef6

Please sign in to comment.