LibreOffice Module drawinglayer (master) 1
pagepreviewprimitive2d.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
27#include <utility>
28
29
30using namespace com::sun::star;
31
32
34{
36 {
38
39 if(!(!aContent.empty()
42 return;
43
44 // the decomposed matrix will be needed
45 basegfx::B2DVector aScale, aTranslate;
46 double fRotate, fShearX;
47 getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
48
49 if(!(basegfx::fTools::more(aScale.getX(), 0.0) && basegfx::fTools::more(aScale.getY(), 0.0)))
50 return;
51
52 // check if content overlaps with target size and needs to be embedded with a
53 // clipping primitive
54 const basegfx::B2DRange aRealContentRange(aContent.getB2DRange(rViewInformation));
55 const basegfx::B2DRange aAllowedContentRange(0.0, 0.0, getContentWidth(), getContentHeight());
56
57 if(!aAllowedContentRange.isInside(aRealContentRange))
58 {
59 const Primitive2DReference xReferenceA(
62 basegfx::utils::createPolygonFromRect(aAllowedContentRange)), std::move(aContent)));
63 aContent = Primitive2DContainer { xReferenceA };
64 }
65
66 // create a mapping from content to object.
67 basegfx::B2DHomMatrix aPageTrans;
68
69 // #i101075# when keeping the aspect ratio is wanted, it is necessary to calculate
70 // an equidistant scaling in X and Y and a corresponding translation to
71 // center the output. Calculate needed scale factors
72 const double fScaleX(aScale.getX() / getContentWidth());
73 const double fScaleY(aScale.getY() / getContentHeight());
74
75 // to keep the aspect, use the smaller scale and adapt missing size by translation
76 if(fScaleX < fScaleY)
77 {
78 // height needs to be adapted
79 const double fNeededHeight(aScale.getY() / fScaleX);
80 const double fSpaceToAdd(fNeededHeight - getContentHeight());
81
82 aPageTrans.translate(0.0, fSpaceToAdd * 0.5);
83 aPageTrans.scale(fScaleX, aScale.getY() / fNeededHeight);
84 }
85 else
86 {
87 // width needs to be adapted
88 const double fNeededWidth(aScale.getX() / fScaleY);
89 const double fSpaceToAdd(fNeededWidth - getContentWidth());
90
91 aPageTrans.translate(fSpaceToAdd * 0.5, 0.0);
92 aPageTrans.scale(aScale.getX() / fNeededWidth, fScaleY);
93 }
94
95 // add the missing object transformation aspects
97 fShearX, fRotate, aTranslate.getX(), aTranslate.getY()));
98 aPageTrans = aCombined * aPageTrans;
99
100 // embed in necessary transformation to map from SdrPage to SdrPageObject
101 rContainer.push_back(new TransformPrimitive2D(aPageTrans, std::move(aContent)));
102 }
103
105 css::uno::Reference< css::drawing::XDrawPage > xDrawPage,
106 basegfx::B2DHomMatrix aTransform,
107 double fContentWidth,
108 double fContentHeight,
109 Primitive2DContainer&& rPageContent)
110 : mxDrawPage(std::move(xDrawPage)),
111 maPageContent(std::move(rPageContent)),
112 maTransform(std::move(aTransform)),
113 mfContentWidth(fContentWidth),
114 mfContentHeight(fContentHeight)
115 {
116 }
117
119 {
120 if(BasePrimitive2D::operator==(rPrimitive))
121 {
122 const PagePreviewPrimitive2D& rCompare = static_cast< const PagePreviewPrimitive2D& >(rPrimitive);
123
124 return (getXDrawPage() == rCompare.getXDrawPage()
125 && getPageContent() == rCompare.getPageContent()
126 && getTransform() == rCompare.getTransform()
127 && getContentWidth() == rCompare.getContentWidth()
128 && getContentHeight() == rCompare.getContentHeight());
129 }
130
131 return false;
132 }
133
135 {
136 // nothing is allowed to stick out of a PagePreviewPrimitive, thus we
137 // can quickly deliver our range here
138 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
139 aRetval.transform(getTransform());
140 return aRetval;
141 }
142
143 // provide unique ID
145 {
147 }
148
149} // end of namespace
150
151/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
void translate(double fX, double fY)
void scale(double fX, double fY)
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
bool isInside(const Tuple2D< TYPE > &rTuple) const
TYPE getX() const
TYPE getY() const
const basegfx::B2DHomMatrix & getTransform() const
PagePreviewPrimitive2D(css::uno::Reference< css::drawing::XDrawPage > xDrawPage, basegfx::B2DHomMatrix aTransform, double fContentWidth, double fContentHeight, Primitive2DContainer &&rPageContent)
constructor
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition. Implementation will just return children
const Primitive2DContainer & getPageContent() const
const css::uno::Reference< css::drawing::XDrawPage > & getXDrawPage() const
data read access
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
own getB2DRange
basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &aViewInformation) const
#define PRIMITIVE2D_ID_PAGEPREVIEWPRIMITIVE2D
basegfx::B2DHomMatrix maTransform
the geometric definition
bool more(const T &rfValA, const T &rfValB)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
uno::Reference< drawing::XDrawPage > mxDrawPage