Line data Source code
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 :
20 : #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
21 : #include <drawinglayer/primitive2d/cropprimitive2d.hxx>
22 : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
23 : #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
24 : #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
25 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
26 : #include <vcl/svapp.hxx>
27 : #include <vcl/outdev.hxx>
28 :
29 : //////////////////////////////////////////////////////////////////////////////
30 :
31 : namespace drawinglayer
32 : {
33 : namespace primitive2d
34 : {
35 18 : Primitive2DSequence GraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D&
36 : ) const
37 : {
38 18 : Primitive2DSequence aRetval;
39 :
40 18 : if(255L != getGraphicAttr().GetTransparency())
41 : {
42 : // do not apply mirroring from GraphicAttr to the Metafile by calling
43 : // GetTransformedGraphic, this will try to mirror the Metafile using Scale()
44 : // at the Metafile. This again calls Scale at the single MetaFile actions,
45 : // but this implementation never worked. I reworked that implementations,
46 : // but for security reasons i will try not to use it.
47 18 : basegfx::B2DHomMatrix aTransform(getTransform());
48 :
49 18 : if(getGraphicAttr().IsMirrored())
50 : {
51 : // content needs mirroring
52 0 : const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_HORZ);
53 0 : const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_VERT);
54 :
55 : // mirror by applying negative scale to the unit primitive and
56 : // applying the object transformation on it.
57 0 : aTransform = basegfx::tools::createScaleB2DHomMatrix(
58 : bHMirr ? -1.0 : 1.0,
59 0 : bVMirr ? -1.0 : 1.0);
60 : aTransform.translate(
61 : bHMirr ? 1.0 : 0.0,
62 0 : bVMirr ? 1.0 : 0.0);
63 0 : aTransform = getTransform() * aTransform;
64 : }
65 :
66 : // Get transformed graphic. Suppress rotation and cropping, only filtering is needed
67 : // here (and may be replaced later on). Cropping is handled below as mask primitive (if set).
68 : // Also need to suppress mirroring, it is part of the transformation now (see above).
69 36 : GraphicAttr aSuppressGraphicAttr(getGraphicAttr());
70 18 : aSuppressGraphicAttr.SetCrop(0, 0, 0, 0);
71 18 : aSuppressGraphicAttr.SetRotation(0);
72 18 : aSuppressGraphicAttr.SetMirrorFlags(0);
73 :
74 18 : const GraphicObject& rGraphicObject = getGraphicObject();
75 36 : const Graphic aTransformedGraphic(rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr));
76 :
77 36 : aRetval = create2DDecompositionOfGraphic(
78 : aTransformedGraphic,
79 18 : aTransform);
80 :
81 18 : if(aRetval.getLength())
82 : {
83 : // check for cropping
84 18 : if(getGraphicAttr().IsCropped())
85 : {
86 : // calculate scalings between real image size and logic object size. This
87 : // is necessary since the crop values are relative to original bitmap size
88 0 : const basegfx::B2DVector aObjectScale(aTransform * basegfx::B2DVector(1.0, 1.0));
89 : const basegfx::B2DVector aCropScaleFactor(
90 : rGraphicObject.calculateCropScaling(
91 : aObjectScale.getX(),
92 : aObjectScale.getY(),
93 0 : getGraphicAttr().GetLeftCrop(),
94 0 : getGraphicAttr().GetTopCrop(),
95 0 : getGraphicAttr().GetRightCrop(),
96 0 : getGraphicAttr().GetBottomCrop()));
97 :
98 : // embed content in cropPrimitive
99 : Primitive2DReference xPrimitive(
100 : new CropPrimitive2D(
101 : aRetval,
102 : aTransform,
103 0 : getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(),
104 0 : getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(),
105 0 : getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(),
106 0 : getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY()));
107 :
108 0 : aRetval = Primitive2DSequence(&xPrimitive, 1);
109 : }
110 18 : }
111 : }
112 :
113 18 : return aRetval;
114 : }
115 :
116 58 : GraphicPrimitive2D::GraphicPrimitive2D(
117 : const basegfx::B2DHomMatrix& rTransform,
118 : const GraphicObject& rGraphicObject,
119 : const GraphicAttr& rGraphicAttr)
120 : : BufferedDecompositionPrimitive2D(),
121 : maTransform(rTransform),
122 : maGraphicObject(rGraphicObject),
123 58 : maGraphicAttr(rGraphicAttr)
124 : {
125 58 : }
126 :
127 0 : GraphicPrimitive2D::GraphicPrimitive2D(
128 : const basegfx::B2DHomMatrix& rTransform,
129 : const GraphicObject& rGraphicObject)
130 : : BufferedDecompositionPrimitive2D(),
131 : maTransform(rTransform),
132 : maGraphicObject(rGraphicObject),
133 0 : maGraphicAttr()
134 : {
135 0 : }
136 :
137 0 : bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
138 : {
139 0 : if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
140 : {
141 0 : const GraphicPrimitive2D& rCompare = (GraphicPrimitive2D&)rPrimitive;
142 :
143 0 : return (getTransform() == rCompare.getTransform()
144 0 : && getGraphicObject() == rCompare.getGraphicObject()
145 0 : && getGraphicAttr() == rCompare.getGraphicAttr());
146 : }
147 :
148 0 : return false;
149 : }
150 :
151 100 : basegfx::B2DRange GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
152 : {
153 100 : basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
154 100 : aRetval.transform(getTransform());
155 100 : return aRetval;
156 : }
157 :
158 : // provide unique ID
159 33 : ImplPrimitive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D)
160 :
161 : } // end of namespace primitive2d
162 408 : } // end of namespace drawinglayer
163 :
164 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|