Skip to content

Commit

Permalink
Implement PreserveAspectRatio clip
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Jan 6, 2024
1 parent 4d0322d commit f3dc82b
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion source/property.cpp
Expand Up @@ -677,8 +677,44 @@ Rect PreserveAspectRatio::getClip(double width, double height, const Rect& viewB
{
if(viewBox.empty())
return Rect{0, 0, width, height};
if(m_scale == MeetOrSlice::Meet)
return viewBox;
auto scale = std::max(width / viewBox.w, height / viewBox.h);
auto xOffset = -viewBox.x * scale;
auto yOffset = -viewBox.y * scale;
auto viewWidth = viewBox.w * scale;
auto viewHeight = viewBox.h * scale;
switch(m_align) {
case Align::xMidYMin:
case Align::xMidYMid:
case Align::xMidYMax:
xOffset += (width - viewWidth) * 0.5f;
break;
case Align::xMaxYMin:
case Align::xMaxYMid:
case Align::xMaxYMax:
xOffset += (width - viewWidth);
break;
default:
break;
}

switch(m_align) {
case Align::xMinYMid:
case Align::xMidYMid:
case Align::xMaxYMid:
yOffset += (height - viewHeight) * 0.5f;
break;
case Align::xMinYMax:
case Align::xMidYMax:
case Align::xMaxYMax:
yOffset += (height - viewHeight);
break;
default:
break;
}

return viewBox;
return Rect(-xOffset / scale, -yOffset / scale, width / scale, height / scale);
}

Angle::Angle(MarkerOrient type)
Expand Down

0 comments on commit f3dc82b

Please sign in to comment.