LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrcaptionobj.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 62 91.9 %
Date: 2014-11-03 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          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 <sdr/contact/viewcontactofsdrcaptionobj.hxx>
      22             : #include <svx/svdocapt.hxx>
      23             : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      24             : #include <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             : #include <basegfx/polygon/b2dpolygonclipper.hxx>
      38             : 
      39             : using namespace com::sun::star;
      40             : 
      41             : namespace sdr
      42             : {
      43             :     namespace contact
      44             :     {
      45         118 :         ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
      46         118 :         :   ViewContactOfSdrRectObj(rCaptionObj)
      47             :         {
      48         118 :         }
      49             : 
      50         224 :         ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
      51             :         {
      52         224 :         }
      53             : 
      54          48 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
      55             :         {
      56          48 :             drawinglayer::primitive2d::Primitive2DSequence xRetval;
      57          48 :             const SdrCaptionObj& rCaptionObj(GetCaptionObj());
      58          48 :             const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
      59             :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      60             :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      61             :                     rItemSet,
      62          48 :                     rCaptionObj.getText(0),
      63         144 :                     false));
      64             : 
      65             :             // take unrotated snap rect (direct model data) for position and size
      66          48 :             Rectangle rRectangle = rCaptionObj.GetGeoRect();
      67             :             // Hack for calc, transform position of object according
      68             :             // to current zoom so as objects relative position to grid
      69             :             // appears stable
      70          48 :             Point aGridOff = rCaptionObj.GetGridOffset();
      71          48 :             rRectangle += aGridOff;
      72             : 
      73             :             const ::basegfx::B2DRange aObjectRange(
      74          96 :                 rRectangle.Left(), rRectangle.Top(),
      75         144 :                 rRectangle.Right(), rRectangle.Bottom());
      76          48 :             const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
      77             : 
      78             :             // fill object matrix
      79             :             basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
      80             :                 aObjectRange.getWidth(), aObjectRange.getHeight(),
      81           0 :                 rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0,
      82           0 :                 rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0,
      83          96 :                 aObjectRange.getMinX(), aObjectRange.getMinY()));
      84             : 
      85             :             // calculate corner radius
      86             :             double fCornerRadiusX;
      87             :             double fCornerRadiusY;
      88             :             drawinglayer::primitive2d::calculateRelativeCornerRadius(
      89          48 :                 rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
      90          96 :             ::basegfx::B2DPolygon aTail = rCaptionObj.getTailPolygon();
      91             :             // Hack for calc, transform position of tail according
      92             :             // to current zoom so as objects relative position to grid
      93             :             // appears stable
      94          48 :             aTail.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
      95             :             // create primitive. Always create one (even if invisible) to let the decomposition
      96             :             // of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
      97             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
      98             :                 new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
      99             :                     aObjectMatrix,
     100             :                     aAttribute,
     101             :                     aTail,
     102             :                     fCornerRadiusX,
     103          96 :                     fCornerRadiusY));
     104             : 
     105          48 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     106             : 
     107          48 :             if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
     108             :             {
     109             :                 // for SC, the caption object may have a specialized shadow. The usual object shadow is off
     110             :                 // and a specialized shadow gets created here (see old paint)
     111          48 :                 const XColorItem& rShadColItem = static_cast<const XColorItem&>(rItemSet.Get(SDRATTR_SHADOWCOLOR));
     112          48 :                 const sal_uInt16 nShadowTransparence((static_cast<const SdrPercentItem&>(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
     113          48 :                 const Color aShadowColor(rShadColItem.GetColorValue());
     114          48 :                 const drawing::FillStyle eShadowStyle = (static_cast<const XFillStyleItem&>(rItemSet.Get(XATTR_FILLSTYLE))).GetValue();
     115             : 
     116             :                 // Create own ItemSet and modify as needed
     117             :                 // Always hide lines for special calc shadow
     118          48 :                 SfxItemSet aSet(rItemSet);
     119          48 :                 aSet.Put(XLineStyleItem(XLINE_NONE));
     120             : 
     121          48 :                 if(drawing::FillStyle_HATCH == eShadowStyle)
     122             :                 {
     123             :                     // #41666# Hatch color is set hard to shadow color
     124           0 :                     XHatch aHatch = (static_cast<const XFillHatchItem&>(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue();
     125           0 :                     aHatch.SetColor(aShadowColor);
     126           0 :                     aSet.Put(XFillHatchItem(OUString(),aHatch));
     127             :                 }
     128             :                 else
     129             :                 {
     130          48 :                     if(drawing::FillStyle_SOLID != eShadowStyle)
     131             :                     {
     132             :                         // force fill to solid (for Gradient, Bitmap and *no* fill (#119750# not filled comments *have* shadow))
     133          12 :                         aSet.Put(XFillStyleItem(drawing::FillStyle_SOLID));
     134             :                     }
     135             : 
     136          48 :                     aSet.Put(XFillColorItem(OUString(),aShadowColor));
     137          48 :                     aSet.Put(XFillTransparenceItem(nShadowTransparence));
     138             :                 }
     139             : 
     140             :                 // crete FillAttribute from modified ItemSet
     141             :                 const drawinglayer::attribute::SdrFillAttribute aFill(
     142          96 :                     drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
     143          96 :                 drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
     144             : 
     145          48 :                 if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
     146             :                 {
     147             :                     // add shadow offset to object matrix
     148          48 :                     const sal_uInt32 nXDist((static_cast<const SdrMetricItem&>(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
     149          48 :                     const sal_uInt32 nYDist((static_cast<const SdrMetricItem&>(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
     150             : 
     151          48 :                     if(nXDist || nYDist)
     152             :                     {
     153             :                         // #119750# create obect and shadow outline, clip shadow outline
     154             :                         // on object outline. If there is a rest, create shadow. Do this to
     155             :                         // emulate that shadow is *not* visible behind the object for
     156             :                         // transparent object fill for comments in excel
     157             :                         basegfx::B2DPolygon aObjectOutline(
     158             :                             basegfx::tools::createPolygonFromRect(
     159             :                                 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
     160             :                                 fCornerRadiusX,
     161          48 :                                 fCornerRadiusY));
     162          48 :                         aObjectOutline.transform(aObjectMatrix);
     163             : 
     164             :                         // create shadow outline
     165          96 :                         basegfx::B2DPolygon aShadowOutline(aObjectOutline);
     166             :                         aShadowOutline.transform(
     167          48 :                             basegfx::tools::createTranslateB2DHomMatrix(nXDist, nYDist));
     168             : 
     169             :                         // clip shadow outline against object outline
     170             :                         const basegfx::B2DPolyPolygon aClippedShadow(
     171             :                             basegfx::tools::clipPolygonOnPolyPolygon(
     172             :                                 aShadowOutline,
     173             :                                 basegfx::B2DPolyPolygon(aObjectOutline),
     174             :                                 false, // take the outside
     175          96 :                                 false));
     176             : 
     177          48 :                         if(aClippedShadow.count())
     178             :                         {
     179             :                             // if there is shadow, create the specialized shadow primitive
     180          96 :                             xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
     181             :                                 aClippedShadow,
     182             :                                 aFill,
     183          48 :                                 drawinglayer::attribute::FillGradientAttribute());
     184          48 :                         }
     185             :                     }
     186             :                 }
     187             : 
     188          48 :                 if(xSpecialShadow.is())
     189             :                 {
     190             :                     // if we really got a special shadow, create a two-element retval with the shadow
     191             :                     // behind the standard object's geometry
     192          48 :                     xRetval.realloc(2);
     193             : 
     194          48 :                     xRetval[0] = xSpecialShadow;
     195          48 :                     xRetval[1] = xReference;
     196          48 :                 }
     197             :             }
     198             : 
     199          96 :             return xRetval;
     200             :         }
     201             :     } // end of namespace contact
     202         651 : } // end of namespace sdr
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10