diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2017-09-28 10:20:15 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2017-10-20 14:13:22 +0200 |
commit | d9b16effeda21488911d1b5035f9d3be05731ca2 (patch) | |
tree | 3c16a374a8bb42c7b0207e0e34bcacd66efb150f /basegfx/source/matrix | |
parent | 4ddd74e2d119eb7b25df75a65fcb214ce08ec672 (diff) |
RotGrfFlyFrame: Adapt Crop functionality to rotated Graphic
The FlyFrame which may contain a Graphic needs working Crop,
interactive and in core. Adapted this to work with now possible
rotation, changed common code in svx which has to handle cases
for Draw/Impress/Calc and Writer differently. Tried to use as
much in common as possible. Additionally furter adaptions
to rotation itself.
Change-Id: Ia961e9490e2627c74220b186116f5aa4fcabca78
Diffstat (limited to 'basegfx/source/matrix')
-rw-r--r-- | basegfx/source/matrix/b2dhommatrixtools.cxx | 42 |
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, |