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 :
21 : #include <svx/sdr/contact/viewcontactofsdrcaptionobj.hxx>
22 : #include <svx/svdocapt.hxx>
23 : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
24 : #include <svx/sdr/primitive2d/sdrcaptionprimitive2d.hxx>
25 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
26 :
27 : //////////////////////////////////////////////////////////////////////////////
28 : // includes for special text box shadow (SC)
29 :
30 : #include <svl/itemset.hxx>
31 : #include <svx/xhatch.hxx>
32 : #include <svx/xflhtit.hxx>
33 : #include <svx/xflclit.hxx>
34 : #include <svx/xfltrit.hxx>
35 : #include <basegfx/polygon/b2dpolygontools.hxx>
36 : #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
37 :
38 : //////////////////////////////////////////////////////////////////////////////
39 :
40 : namespace sdr
41 : {
42 : namespace contact
43 : {
44 2 : ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
45 2 : : ViewContactOfSdrRectObj(rCaptionObj)
46 : {
47 2 : }
48 :
49 4 : ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
50 : {
51 4 : }
52 :
53 0 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
54 : {
55 0 : drawinglayer::primitive2d::Primitive2DSequence xRetval;
56 0 : const SdrCaptionObj& rCaptionObj(GetCaptionObj());
57 0 : const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
58 : const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
59 : drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
60 : rItemSet,
61 0 : rCaptionObj.getText(0)));
62 :
63 : // take unrotated snap rect (direct model data) for position and size
64 0 : Rectangle rRectangle = rCaptionObj.GetGeoRect();
65 : // Hack for calc, transform position of object according
66 : // to current zoom so as objects relative position to grid
67 : // appears stable
68 0 : Point aGridOff = rCaptionObj.GetGridOffset();
69 0 : rRectangle += aGridOff;
70 :
71 : const ::basegfx::B2DRange aObjectRange(
72 0 : rRectangle.Left(), rRectangle.Top(),
73 0 : rRectangle.Right(), rRectangle.Bottom());
74 0 : const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
75 :
76 : // fill object matrix
77 : basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
78 : aObjectRange.getWidth(), aObjectRange.getHeight(),
79 0 : rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
80 : rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
81 0 : aObjectRange.getMinX(), aObjectRange.getMinY()));
82 :
83 : // calculate corner radius
84 : double fCornerRadiusX;
85 : double fCornerRadiusY;
86 : drawinglayer::primitive2d::calculateRelativeCornerRadius(
87 0 : rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
88 0 : ::basegfx::B2DPolygon aTail = rCaptionObj.getTailPolygon();
89 : // Hack for calc, transform position of tail according
90 : // to current zoom so as objects relative position to grid
91 : // appears stable
92 0 : aTail.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
93 : // create primitive. Always create one (even if invisible) to let the decomposition
94 : // of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
95 : const drawinglayer::primitive2d::Primitive2DReference xReference(
96 : new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
97 : aObjectMatrix,
98 : aAttribute,
99 : aTail,
100 : fCornerRadiusX,
101 0 : fCornerRadiusY));
102 :
103 0 : xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
104 :
105 0 : if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
106 : {
107 : // for SC, the caption object may have a specialized shadow. The usual object shadow is off
108 : // and a specialized shadow gets created here (see old paint)
109 0 : const SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR));
110 0 : const sal_uInt16 nTransp(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
111 0 : const Color aShadCol(rShadColItem.GetColorValue());
112 0 : const XFillStyle eStyle = ((XFillStyleItem&)(rItemSet.Get(XATTR_FILLSTYLE))).GetValue();
113 :
114 : // Create own ItemSet and modify as needed
115 : // Always hide lines for special calc shadow
116 0 : SfxItemSet aSet(rItemSet);
117 0 : aSet.Put(XLineStyleItem(XLINE_NONE));
118 :
119 0 : if(XFILL_HATCH == eStyle)
120 : {
121 : // #41666# Hatch color is set hard to shadow color
122 0 : XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue();
123 0 : aHatch.SetColor(aShadCol);
124 0 : aSet.Put(XFillHatchItem(String(),aHatch));
125 : }
126 : else
127 : {
128 0 : if(XFILL_NONE != eStyle && XFILL_SOLID != eStyle)
129 : {
130 : // force fill to solid (for Gradient and Bitmap)
131 0 : aSet.Put(XFillStyleItem(XFILL_SOLID));
132 : }
133 :
134 0 : aSet.Put(XFillColorItem(String(),aShadCol));
135 0 : aSet.Put(XFillTransparenceItem(nTransp));
136 : }
137 :
138 : // crete FillAttribute from modified ItemSet
139 : const drawinglayer::attribute::SdrFillAttribute aFill(
140 0 : drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
141 0 : drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
142 :
143 0 : if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
144 : {
145 : // add shadow offset to object matrix
146 0 : const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
147 0 : const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
148 0 : aObjectMatrix.translate(nXDist, nYDist);
149 :
150 : // create unit outline polygon as geometry (see SdrCaptionPrimitive2D::create2DDecomposition)
151 : basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
152 0 : basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), fCornerRadiusX, fCornerRadiusY));
153 :
154 : // create the specialized shadow primitive
155 : xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
156 : basegfx::B2DPolyPolygon(aUnitOutline),
157 : aObjectMatrix,
158 : aFill,
159 0 : drawinglayer::attribute::FillGradientAttribute());
160 : }
161 :
162 0 : if(xSpecialShadow.is())
163 : {
164 : // if we really got a special shadow, create a two-element retval with the shadow
165 : // behind the standard object's geometry
166 0 : xRetval.realloc(2);
167 :
168 0 : xRetval[0] = xSpecialShadow;
169 0 : xRetval[1] = xReference;
170 0 : }
171 : }
172 :
173 0 : return xRetval;
174 : }
175 : } // end of namespace contact
176 : } // end of namespace sdr
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|