xref: /AOO41X/main/drawinglayer/source/primitive2d/graphicprimitive2d.cxx (revision 035a2f44eca4e31ced924464e6584eacbf3e9114)
1464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5464702f4SAndrew Rist  * distributed with this work for additional information
6464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14464702f4SAndrew Rist  * software distributed under the License is distributed on an
15464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17464702f4SAndrew Rist  * specific language governing permissions and limitations
18464702f4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20464702f4SAndrew Rist  *************************************************************/
21464702f4SAndrew Rist 
22464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
28ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/cropprimitive2d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
30ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
31*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
32*035a2f44SArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx>
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34*035a2f44SArmin Le Grand #include <vcl/outdev.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace drawinglayer
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	namespace primitive2d
41cdf0e10cSrcweir 	{
42cdf0e10cSrcweir 		Primitive2DSequence GraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D&
43cdf0e10cSrcweir #ifdef USE_DEBUG_CODE_TO_TEST_METAFILE_DECOMPOSE
44cdf0e10cSrcweir             rViewInformation
45cdf0e10cSrcweir #else
46cdf0e10cSrcweir             /*rViewInformation*/
47cdf0e10cSrcweir #endif // USE_DEBUG_CODE_TO_TEST_METAFILE_DECOMPOSE
48cdf0e10cSrcweir             ) const
49cdf0e10cSrcweir 		{
50cdf0e10cSrcweir 			Primitive2DSequence aRetval;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 			if(255L != getGraphicAttr().GetTransparency())
53cdf0e10cSrcweir 			{
54cdf0e10cSrcweir                 // do not apply mirroring from GraphicAttr to the Metafile by calling
55cdf0e10cSrcweir                 // GetTransformedGraphic, this will try to mirror the Metafile using Scale()
56cdf0e10cSrcweir                 // at the Metafile. This again calls Scale at the single MetaFile actions,
57cdf0e10cSrcweir                 // but this implementation never worked. I reworked that implementations,
58cdf0e10cSrcweir                 // but for security reasons i will try not to use it.
59cdf0e10cSrcweir                 basegfx::B2DHomMatrix aTransform(getTransform());
60cdf0e10cSrcweir 
61cdf0e10cSrcweir                 if(getGraphicAttr().IsMirrored())
62cdf0e10cSrcweir                 {
63cdf0e10cSrcweir                     // content needs mirroring
64cdf0e10cSrcweir                     const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_HORZ);
65cdf0e10cSrcweir                     const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_VERT);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir                     // mirror by applying negative scale to the unit primitive and
68cdf0e10cSrcweir                     // applying the object transformation on it.
69cdf0e10cSrcweir                     aTransform = basegfx::tools::createScaleB2DHomMatrix(
70cdf0e10cSrcweir                         bHMirr ? -1.0 : 1.0,
71cdf0e10cSrcweir                         bVMirr ? -1.0 : 1.0);
72cdf0e10cSrcweir                     aTransform.translate(
73cdf0e10cSrcweir                         bHMirr ? 1.0 : 0.0,
74cdf0e10cSrcweir                         bVMirr ? 1.0 : 0.0);
75cdf0e10cSrcweir                     aTransform = getTransform() * aTransform;
76cdf0e10cSrcweir                 }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 		        // Get transformed graphic. Suppress rotation and cropping, only filtering is needed
79cdf0e10cSrcweir 		        // here (and may be replaced later on). Cropping is handled below as mask primitive (if set).
80cdf0e10cSrcweir                 // Also need to suppress mirroring, it is part of the transformation now (see above).
81cdf0e10cSrcweir 		        GraphicAttr aSuppressGraphicAttr(getGraphicAttr());
82cdf0e10cSrcweir 		        aSuppressGraphicAttr.SetCrop(0, 0, 0, 0);
83cdf0e10cSrcweir 		        aSuppressGraphicAttr.SetRotation(0);
84cdf0e10cSrcweir 		        aSuppressGraphicAttr.SetMirrorFlags(0);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir                 const GraphicObject& rGraphicObject = getGraphicObject();
87cdf0e10cSrcweir                 const Graphic aTransformedGraphic(rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr));
88cdf0e10cSrcweir 
89*035a2f44SArmin Le Grand                 aRetval = create2DDecompositionOfGraphic(
90*035a2f44SArmin Le Grand                     aTransformedGraphic,
91*035a2f44SArmin Le Grand                     aTransform);
92cdf0e10cSrcweir 
93*035a2f44SArmin Le Grand                 if(aRetval.getLength())
94cdf0e10cSrcweir                 {
95cdf0e10cSrcweir                     // check for cropping
96cdf0e10cSrcweir                     if(getGraphicAttr().IsCropped())
97cdf0e10cSrcweir                     {
98cdf0e10cSrcweir                         // calculate scalings between real image size and logic object size. This
99cdf0e10cSrcweir                         // is necessary since the crop values are relative to original bitmap size
100cdf0e10cSrcweir                         double fFactorX(1.0);
101cdf0e10cSrcweir                         double fFactorY(1.0);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir                         {
104cdf0e10cSrcweir                             const MapMode aMapMode100thmm(MAP_100TH_MM);
105cdf0e10cSrcweir                             Size aBitmapSize(rGraphicObject.GetPrefSize());
106cdf0e10cSrcweir 
107cdf0e10cSrcweir                             // #i95968# better support PrefMapMode; special for MAP_PIXEL was missing
108cdf0e10cSrcweir                             if(MAP_PIXEL == rGraphicObject.GetPrefMapMode().GetMapUnit())
109cdf0e10cSrcweir                             {
110cdf0e10cSrcweir                                 aBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aBitmapSize, aMapMode100thmm);
111cdf0e10cSrcweir                             }
112cdf0e10cSrcweir                             else
113cdf0e10cSrcweir                             {
114cdf0e10cSrcweir                                 aBitmapSize = Application::GetDefaultDevice()->LogicToLogic(aBitmapSize, rGraphicObject.GetPrefMapMode(), aMapMode100thmm);
115cdf0e10cSrcweir                             }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir                             const double fDivX(aBitmapSize.Width() - getGraphicAttr().GetLeftCrop() - getGraphicAttr().GetRightCrop());
118cdf0e10cSrcweir                             const double fDivY(aBitmapSize.Height() - getGraphicAttr().GetTopCrop() - getGraphicAttr().GetBottomCrop());
119ddde725dSArmin Le Grand                             const basegfx::B2DVector aScale(aTransform * basegfx::B2DVector(1.0, 1.0));
120cdf0e10cSrcweir 
121cdf0e10cSrcweir                             if(!basegfx::fTools::equalZero(fDivX))
122cdf0e10cSrcweir                             {
123ddde725dSArmin Le Grand                                 fFactorX = fabs(aScale.getX()) / fDivX;
124cdf0e10cSrcweir                             }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir                             if(!basegfx::fTools::equalZero(fDivY))
127cdf0e10cSrcweir                             {
128ddde725dSArmin Le Grand                                 fFactorY = fabs(aScale.getY()) / fDivY;
129cdf0e10cSrcweir                             }
130cdf0e10cSrcweir                         }
131cdf0e10cSrcweir 
132ddde725dSArmin Le Grand                         // embed content in cropPrimitive
133*035a2f44SArmin Le Grand                         Primitive2DReference xPrimitive(
134*035a2f44SArmin Le Grand                             new CropPrimitive2D(
135*035a2f44SArmin Le Grand                                 aRetval,
136ddde725dSArmin Le Grand                                 aTransform,
137ddde725dSArmin Le Grand                                 getGraphicAttr().GetLeftCrop() * fFactorX,
138ddde725dSArmin Le Grand                                 getGraphicAttr().GetTopCrop() * fFactorY,
139ddde725dSArmin Le Grand                                 getGraphicAttr().GetRightCrop() * fFactorX,
140*035a2f44SArmin Le Grand                                 getGraphicAttr().GetBottomCrop() * fFactorY));
141cdf0e10cSrcweir 
142*035a2f44SArmin Le Grand                         aRetval = Primitive2DSequence(&xPrimitive, 1);
143*035a2f44SArmin Le Grand                     }
144cdf0e10cSrcweir                 }
145cdf0e10cSrcweir 			}
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 			return aRetval;
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		GraphicPrimitive2D::GraphicPrimitive2D(
151cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTransform,
152cdf0e10cSrcweir 			const GraphicObject& rGraphicObject,
153cdf0e10cSrcweir 			const GraphicAttr& rGraphicAttr)
154cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
155cdf0e10cSrcweir 			maTransform(rTransform),
156cdf0e10cSrcweir 			maGraphicObject(rGraphicObject),
157cdf0e10cSrcweir 			maGraphicAttr(rGraphicAttr)
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 		}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 		GraphicPrimitive2D::GraphicPrimitive2D(
162cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTransform,
163cdf0e10cSrcweir 			const GraphicObject& rGraphicObject)
164cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
165cdf0e10cSrcweir 			maTransform(rTransform),
166cdf0e10cSrcweir 			maGraphicObject(rGraphicObject),
167cdf0e10cSrcweir 			maGraphicAttr()
168cdf0e10cSrcweir 		{
169cdf0e10cSrcweir 		}
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 		bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
174cdf0e10cSrcweir 			{
175cdf0e10cSrcweir 				const GraphicPrimitive2D& rCompare = (GraphicPrimitive2D&)rPrimitive;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 				return (getTransform() == rCompare.getTransform()
178cdf0e10cSrcweir 					&& getGraphicObject() == rCompare.getGraphicObject()
179cdf0e10cSrcweir 					&& getGraphicAttr() == rCompare.getGraphicAttr());
180cdf0e10cSrcweir 			}
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 			return false;
183cdf0e10cSrcweir 		}
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 		basegfx::B2DRange GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
186cdf0e10cSrcweir 		{
187cdf0e10cSrcweir 			basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
188cdf0e10cSrcweir 			aRetval.transform(getTransform());
189cdf0e10cSrcweir 			return aRetval;
190cdf0e10cSrcweir 		}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 		// provide unique ID
193cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D)
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	} // end of namespace primitive2d
196cdf0e10cSrcweir } // end of namespace drawinglayer
197cdf0e10cSrcweir 
198cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
199cdf0e10cSrcweir // eof
200