LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrcaptionobj.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 57 62 91.9 %
Date: 2015-06-13 12:38:46 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          61 :         ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
      46          61 :         :   ViewContactOfSdrRectObj(rCaptionObj)
      47             :         {
      48          61 :         }
      49             : 
      50         116 :         ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
      51             :         {
      52         116 :         }
      53             : 
      54          28 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
      55             :         {
      56          28 :             drawinglayer::primitive2d::Primitive2DSequence xRetval;
      57          28 :             const SdrCaptionObj& rCaptionObj(GetCaptionObj());
      58          28 :             const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
      59             :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      60             :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      61             :                     rItemSet,
      62          28 :                     rCaptionObj.getText(0),
      63          84 :                     false));
      64             : 
      65             :             // take unrotated snap rect (direct model data) for position and size
      66          28 :             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          28 :             Point aGridOff = rCaptionObj.GetGridOffset();
      71          28 :             rRectangle += aGridOff;
      72             : 
      73             :             const ::basegfx::B2DRange aObjectRange(
      74          56 :                 rRectangle.Left(), rRectangle.Top(),
      75          84 :                 rRectangle.Right(), rRectangle.Bottom());
      76          28 :             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          56 :                 aObjectRange.getMinX(), aObjectRange.getMinY()));
      84             : 
      85             :             // calculate corner radius
      86             :             double fCornerRadiusX;
      87             :             double fCornerRadiusY;
      88             :             drawinglayer::primitive2d::calculateRelativeCornerRadius(
      89          28 :                 rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
      90          56 :             ::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          28 :             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          56 :                     fCornerRadiusY));
     104             : 
     105          28 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     106             : 
     107          28 :             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          28 :                 const XColorItem& rShadColItem = static_cast<const XColorItem&>(rItemSet.Get(SDRATTR_SHADOWCOLOR));
     112          28 :                 const sal_uInt16 nShadowTransparence((static_cast<const SdrPercentItem&>(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
     113          28 :                 const Color aShadowColor(rShadColItem.GetColorValue());
     114          28 :                 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          28 :                 SfxItemSet aSet(rItemSet);
     119          28 :                 aSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
     120             : 
     121          28 :                 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          28 :                     if(drawing::FillStyle_SOLID != eShadowStyle)
     131             :                     {
     132             :                         // force fill to solid (for Gradient, Bitmap and *no* fill (#119750# not filled comments *have* shadow))
     133           8 :                         aSet.Put(XFillStyleItem(drawing::FillStyle_SOLID));
     134             :                     }
     135             : 
     136          28 :                     aSet.Put(XFillColorItem(OUString(),aShadowColor));
     137          28 :                     aSet.Put(XFillTransparenceItem(nShadowTransparence));
     138             :                 }
     139             : 
     140             :                 // create FillAttribute from modified ItemSet
     141             :                 const drawinglayer::attribute::SdrFillAttribute aFill(
     142          56 :                     drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
     143          56 :                 drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
     144             : 
     145          28 :                 if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
     146             :                 {
     147             :                     // add shadow offset to object matrix
     148          28 :                     const sal_uInt32 nXDist((static_cast<const SdrMetricItem&>(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
     149          28 :                     const sal_uInt32 nYDist((static_cast<const SdrMetricItem&>(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
     150             : 
     151          28 :                     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          28 :                                 fCornerRadiusY));
     162          28 :                         aObjectOutline.transform(aObjectMatrix);
     163             : 
     164             :                         // create shadow outline
     165          56 :                         basegfx::B2DPolygon aShadowOutline(aObjectOutline);
     166             :                         aShadowOutline.transform(
     167          28 :                             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          56 :                                 false));
     176             : 
     177          28 :                         if(aClippedShadow.count())
     178             :                         {
     179             :                             // if there is shadow, create the specialized shadow primitive
     180          56 :                             xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
     181             :                                 aClippedShadow,
     182             :                                 aFill,
     183          28 :                                 drawinglayer::attribute::FillGradientAttribute());
     184          28 :                         }
     185             :                     }
     186             :                 }
     187             : 
     188          28 :                 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          28 :                     xRetval.realloc(2);
     193             : 
     194          28 :                     xRetval[0] = xSpecialShadow;
     195          28 :                     xRetval[1] = xReference;
     196          28 :                 }
     197             :             }
     198             : 
     199          56 :             return xRetval;
     200             :         }
     201             :     } // end of namespace contact
     202         435 : } // end of namespace sdr
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11