Update ooo320-m1
[ooovba.git] / drawinglayer / source / primitive2d / pagepreviewprimitive2d.cxx
bloba6e292eeeca56ab6e7a67e471262ecdca7a939dc
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: pagepreviewprimitive2d.cxx,v $
7 * $Revision: 1.3 $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/pagepreviewprimitive2d.hxx>
40 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
41 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
42 #include <basegfx/polygon/b2dpolygontools.hxx>
43 #include <basegfx/polygon/b2dpolygon.hxx>
44 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
46 //////////////////////////////////////////////////////////////////////////////
48 using namespace com::sun::star;
50 //////////////////////////////////////////////////////////////////////////////
52 namespace drawinglayer
54 namespace primitive2d
56 Primitive2DSequence PagePreviewPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& rViewInformation) const
58 Primitive2DSequence xRetval;
59 Primitive2DSequence aContent(getChildren());
61 if(aContent.hasElements()
62 && basegfx::fTools::more(getContentWidth(), 0.0)
63 && basegfx::fTools::more(getContentHeight(), 0.0))
65 // the decomposed matrix will be needed
66 basegfx::B2DVector aScale, aTranslate;
67 double fRotate, fShearX;
68 getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
70 if(basegfx::fTools::more(aScale.getX(), 0.0) && basegfx::fTools::more(aScale.getY(), 0.0))
72 // check if content overlaps with tageted size and needs to be embedded with a
73 // clipping primitive
74 const basegfx::B2DRange aRealContentRange(getB2DRangeFromPrimitive2DSequence(aContent, rViewInformation));
75 const basegfx::B2DRange aAllowedContentRange(0.0, 0.0, getContentWidth(), getContentHeight());
77 if(!aAllowedContentRange.isInside(aRealContentRange))
79 const Primitive2DReference xReferenceA(new MaskPrimitive2D(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aAllowedContentRange)), aContent));
80 aContent = Primitive2DSequence(&xReferenceA, 1);
83 // create a mapping from content to object.
84 basegfx::B2DHomMatrix aPageTrans;
86 if(getKeepAspectRatio())
88 // #i101075# when keeping the aspect ratio is wanted, it is necessary to calculate
89 // an equidistant scaling in X and Y and a corresponding translation to
90 // center the output. Calculate needed scale factors
91 const double fScaleX(aScale.getX() / getContentWidth());
92 const double fScaleY(aScale.getY() / getContentHeight());
94 // to keep the aspect, use the smaller scale and adapt missing size by translation
95 if(fScaleX < fScaleY)
97 // height needs to be adapted
98 const double fNeededHeight(aScale.getY() / fScaleX);
99 const double fSpaceToAdd(fNeededHeight - getContentHeight());
101 aPageTrans.translate(0.0, fSpaceToAdd * 0.5);
102 aPageTrans.scale(fScaleX, aScale.getY() / fNeededHeight);
104 else
106 // width needs to be adapted
107 const double fNeededWidth(aScale.getX() / fScaleY);
108 const double fSpaceToAdd(fNeededWidth - getContentWidth());
110 aPageTrans.translate(fSpaceToAdd * 0.5, 0.0);
111 aPageTrans.scale(aScale.getX() / fNeededWidth, fScaleY);
114 // add the missing object transformation aspects
115 aPageTrans.shearX(fShearX);
116 aPageTrans.rotate(fRotate);
117 aPageTrans.translate(aTranslate.getX(), aTranslate.getY());
119 else
121 // completely scale to PageObject size. Scale to unit size.
122 aPageTrans.scale(1.0/ getContentWidth(), 1.0 / getContentHeight());
124 // apply object matrix
125 aPageTrans *= getTransform();
128 // embed in necessary transformation to map from SdrPage to SdrPageObject
129 const Primitive2DReference xReferenceB(new TransformPrimitive2D(aPageTrans, aContent));
130 xRetval = Primitive2DSequence(&xReferenceB, 1);
134 return xRetval;
137 PagePreviewPrimitive2D::PagePreviewPrimitive2D(
138 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxDrawPage,
139 const basegfx::B2DHomMatrix& rTransform,
140 double fContentWidth,
141 double fContentHeight,
142 const Primitive2DSequence& rChildren,
143 bool bKeepAspectRatio)
144 : GroupPrimitive2D(rChildren),
145 mxDrawPage(rxDrawPage),
146 maTransform(rTransform),
147 mfContentWidth(fContentWidth),
148 mfContentHeight(fContentHeight),
149 mbKeepAspectRatio(bKeepAspectRatio)
153 bool PagePreviewPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
155 if(GroupPrimitive2D::operator==(rPrimitive))
157 const PagePreviewPrimitive2D& rCompare = static_cast< const PagePreviewPrimitive2D& >(rPrimitive);
159 return (getXDrawPage() == rCompare.getXDrawPage()
160 && getTransform() == rCompare.getTransform()
161 && getContentWidth() == rCompare.getContentWidth()
162 && getContentHeight() == rCompare.getContentHeight()
163 && getKeepAspectRatio() == rCompare.getKeepAspectRatio());
166 return false;
169 basegfx::B2DRange PagePreviewPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation`*/) const
171 // nothing is allowed to stick out of a PagePreviewPrimitive, thus we
172 // can quickly deliver our range here
173 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
174 aRetval.transform(getTransform());
175 return aRetval;
178 // provide unique ID
179 ImplPrimitrive2DIDBlock(PagePreviewPrimitive2D, PRIMITIVE2D_ID_PAGEPREVIEWPRIMITIVE2D)
181 } // end of namespace primitive2d
182 } // end of namespace drawinglayer
184 //////////////////////////////////////////////////////////////////////////////
185 // eof