summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/source/matrix/b2dhommatrixtools.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/basegfx/source/matrix/b2dhommatrixtools.cxx b/basegfx/source/matrix/b2dhommatrixtools.cxx
index a267b05b96d1..26936aff2e5c 100644
--- a/basegfx/source/matrix/b2dhommatrixtools.cxx
+++ b/basegfx/source/matrix/b2dhommatrixtools.cxx
@@ -358,6 +358,48 @@ namespace basegfx
return aRetval;
}
+ BASEGFX_DLLPUBLIC B2DHomMatrix createRotateAroundCenterKeepAspectRatioStayInsideRange(
+ const basegfx::B2DRange& rTargetRange,
+ double fRotate)
+ {
+ basegfx::B2DHomMatrix aRetval;
+
+ // RotGrfFlyFrame: Take rotation into account. Rotation is in 10th degrees
+ if(0.0 != fRotate)
+ {
+ // Fit rotated graphic to center of available space, keeping page ratio:
+ // Adapt scaling ratio of unit object and rotate it
+ aRetval.scale(1.0, rTargetRange.getHeight() / rTargetRange.getWidth());
+ aRetval.rotate(fRotate);
+
+ // get the range to see where we are in unit coordinates
+ basegfx::B2DRange aFullRange(0.0, 0.0, 1.0, 1.0);
+ aFullRange.transform(aRetval);
+
+ // detect needed scales in X/Y and choose the smallest for staying inside the
+ // available space while keeping aspect ratio of the source
+ const double fScaleX(rTargetRange.getWidth() / aFullRange.getWidth());
+ const double fScaleY(rTargetRange.getHeight() / aFullRange.getHeight());
+ const double fScaleMin(std::min(fScaleX, fScaleY));
+
+ // TopLeft to zero, then scale, then move to center of available space
+ aRetval.translate(-aFullRange.getMinX(), -aFullRange.getMinY());
+ aRetval.scale(fScaleMin, fScaleMin);
+ aRetval.translate(
+ rTargetRange.getCenterX() - (0.5 * fScaleMin * aFullRange.getWidth()),
+ rTargetRange.getCenterY() - (0.5 * fScaleMin * aFullRange.getHeight()));
+ }
+ else
+ {
+ // just scale/translate needed
+ aRetval *= createScaleTranslateB2DHomMatrix(
+ rTargetRange.getRange(),
+ rTargetRange.getMinimum());
+ }
+
+ return aRetval;
+ }
+
/// special for the case to map from source range to target range
B2DHomMatrix createSourceRangeTargetRangeTransform(
const B2DRange& rSourceRange,