summaryrefslogtreecommitdiff
path: root/drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2009-04-23 14:51:28 +0000
committerIvo Hinkelmann <ihi@openoffice.org>2009-04-23 14:51:28 +0000
commita73ac8926a739fcbc434adf460cc1dba950ffeea (patch)
treeb54baaa0c6402f6fa800ebff350d3d0f0ebf9aeb /drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx
parent600b7c043d4e082432e5c63f74bdb5948b9767bc (diff)
CWS-TOOLING: integrate CWS aw070_DEV300
2009-04-14 15:12:41 +0200 hdu r270783 : #i100951# avoid expensive calls to basegfx::tools::clipPolygonOnRange() if possible 2009-04-14 15:04:05 +0200 hdu r270780 : #i100922# prevent needless stl::priority_queue reallacations by reserving 2009-04-14 14:44:18 +0200 aw r270776 : #i100851# corrected unxlngi4 warning 2009-04-14 14:41:44 +0200 aw r270774 : #i100851# applied suggested patch from task 2009-04-14 14:32:30 +0200 aw r270769 : #i101075# corrected offset usage for wrong spell and transformation mapping for page preview primitives with aspect ratio 2009-04-14 13:56:13 +0200 aw r270763 : #i101075# changed to empty range usage when collecting page conent for page preview object
Diffstat (limited to 'drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx')
-rw-r--r--drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx99
1 files changed, 55 insertions, 44 deletions
diff --git a/drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx b/drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx
index 6b0ffaaf39c2..01a82299682d 100644
--- a/drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/pagepreviewprimitive2d.cxx
@@ -58,66 +58,77 @@ namespace drawinglayer
Primitive2DSequence xRetval;
Primitive2DSequence aContent(getChildren());
- if(aContent.hasElements())
+ if(aContent.hasElements()
+ && basegfx::fTools::more(getContentWidth(), 0.0)
+ && basegfx::fTools::more(getContentHeight(), 0.0))
{
- // check if content overlaps with tageted size and needs to be embedded with a
- // clipping primitive
- const basegfx::B2DRange aRealContentRange(getB2DRangeFromPrimitive2DSequence(aContent, rViewInformation));
- const basegfx::B2DRange aAllowedContentRange(0.0, 0.0, getContentWidth(), getContentHeight());
-
- if(!aAllowedContentRange.isInside(aRealContentRange))
- {
- const Primitive2DReference xReferenceA(new MaskPrimitive2D(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aAllowedContentRange)), aContent));
- aContent = Primitive2DSequence(&xReferenceA, 1);
- }
-
- // content is not scaled or rotated and occupates aContentRange. Create a mapping
- // to own local geometry. Create matrix describing the content by setting scaling
- basegfx::B2DHomMatrix aPageTrans;
- aPageTrans.set(0, 0, getContentWidth());
- aPageTrans.set(1, 1, getContentHeight());
-
- // decompose to access own scaling
+ // the decomposed matrix will be needed
basegfx::B2DVector aScale, aTranslate;
double fRotate, fShearX;
getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
- if(getKeepAspectRatio())
+ if(basegfx::fTools::more(aScale.getX(), 0.0) && basegfx::fTools::more(aScale.getY(), 0.0))
{
- // look at the aspect ratio of the content and the local geometry
- const double fRatioOwn(aScale.getX() ? (aScale.getY() / aScale.getX()) : 1.0);
- const double fRatioContent(getContentWidth() ? (getContentHeight() / getContentWidth()) : 1.0);
+ // check if content overlaps with tageted size and needs to be embedded with a
+ // clipping primitive
+ const basegfx::B2DRange aRealContentRange(getB2DRangeFromPrimitive2DSequence(aContent, rViewInformation));
+ const basegfx::B2DRange aAllowedContentRange(0.0, 0.0, getContentWidth(), getContentHeight());
+
+ if(!aAllowedContentRange.isInside(aRealContentRange))
+ {
+ const Primitive2DReference xReferenceA(new MaskPrimitive2D(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aAllowedContentRange)), aContent));
+ aContent = Primitive2DSequence(&xReferenceA, 1);
+ }
- // the ratios are based on different coordinate systems, so look if they differ really more
- // than 0,1 percent
- if(fabs(fRatioOwn - fRatioContent) > 0.001)
+ // create a mapping from content to object.
+ basegfx::B2DHomMatrix aPageTrans;
+
+ if(getKeepAspectRatio())
{
- if(basegfx::fTools::more(fRatioOwn, fRatioContent))
+ // #i101075# when keeping the aspect ratio is wanted, it is necessary to calculate
+ // an equidistant scaling in X and Y and a corresponding translation to
+ // center the output. Calculate needed scale factors
+ const double fScaleX(aScale.getX() / getContentWidth());
+ const double fScaleY(aScale.getY() / getContentHeight());
+
+ // to keep the aspect, use the smaller scale and adapt missing size by translation
+ if(fScaleX < fScaleY)
{
- // vertically center the page by translating
- const double fFullY(aScale.getX() ? (aScale.getY() * getContentWidth()) / aScale.getX() : 0.0);
- const double fTransY((fFullY - getContentHeight()) * 0.5);
- aPageTrans.set(1, 2, fTransY);
+ // height needs to be adapted
+ const double fNeededHeight(aScale.getY() / fScaleX);
+ const double fSpaceToAdd(fNeededHeight - getContentHeight());
+
+ aPageTrans.translate(0.0, fSpaceToAdd * 0.5);
+ aPageTrans.scale(fScaleX, aScale.getY() / fNeededHeight);
}
else
{
- // horizontally center the page by translating
- const double fFullX(aScale.getY() ? (aScale.getX() * getContentHeight()) / aScale.getY() : 0.0);
- const double fTransX((fFullX - getContentWidth()) * 0.5);
- aPageTrans.set(0, 2, fTransX);
+ // width needs to be adapted
+ const double fNeededWidth(aScale.getX() / fScaleY);
+ const double fSpaceToAdd(fNeededWidth - getContentWidth());
+
+ aPageTrans.translate(fSpaceToAdd * 0.5, 0.0);
+ aPageTrans.scale(aScale.getX() / fNeededWidth, fScaleY);
}
+
+ // add the missing object transformation aspects
+ aPageTrans.shearX(fShearX);
+ aPageTrans.rotate(fRotate);
+ aPageTrans.translate(aTranslate.getX(), aTranslate.getY());
}
- }
+ else
+ {
+ // completely scale to PageObject size. Scale to unit size.
+ aPageTrans.scale(1.0/ getContentWidth(), 1.0 / getContentHeight());
- // create composed transformation from content to local geometry. An
- // eventually needed clipping is already added, so directly go to local coordinates
- basegfx::B2DHomMatrix aPageToObject(aPageTrans);
- aPageToObject.invert();
- aPageToObject *= getTransform();
+ // apply object matrix
+ aPageTrans *= getTransform();
+ }
- // embed in necessary transformation to map from SdrPage to SdrPageObject
- const Primitive2DReference xReferenceB(new TransformPrimitive2D(aPageToObject, aContent));
- xRetval = Primitive2DSequence(&xReferenceB, 1);
+ // embed in necessary transformation to map from SdrPage to SdrPageObject
+ const Primitive2DReference xReferenceB(new TransformPrimitive2D(aPageTrans, aContent));
+ xRetval = Primitive2DSequence(&xReferenceB, 1);
+ }
}
return xRetval;