LCOV - code coverage report
Current view: top level - sw/source/core/unocore - unobrushitemhelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 106 0.0 %
Date: 2014-04-14 Functions: 0 4 0.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             : #include <unobrushitemhelper.hxx>
      21             : #include <svx/xfillit0.hxx>
      22             : #include <svx/xbtmpit.hxx>
      23             : #include <svx/xgrscit.hxx>
      24             : #include <svx/xflbmtit.hxx>
      25             : #include <svx/xflbmpit.hxx>
      26             : #include <svx/xflbmsxy.hxx>
      27             : #include <svx/xflbmsxy.hxx>
      28             : #include <svx/xflftrit.hxx>
      29             : #include <svx/xsflclit.hxx>
      30             : #include <svx/xflbmsli.hxx>
      31             : #include <svx/xflbtoxy.hxx>
      32             : #include <svx/xflbstit.hxx>
      33             : #include <svx/xflboxy.hxx>
      34             : #include <svx/xflbckit.hxx>
      35             : #include <svx/unoshape.hxx>
      36             : #include <hintids.hxx>
      37             : #include <svx/xflclit.hxx>
      38             : #include <svx/xfltrit.hxx>
      39             : #include <svx/xflhtit.hxx>
      40             : 
      41             : namespace sw {
      42             : 
      43             : //UUUU
      44           0 : void setSvxBrushItemAsFillAttributesToTargetSet(const SvxBrushItem& rBrush, SfxItemSet& rToSet)
      45             : {
      46           0 :     if(0xff != rBrush.GetColor().GetTransparency())
      47             :     {
      48           0 :         const Color aColor(rBrush.GetColor().GetRGBColor());
      49           0 :         const sal_uInt8 nTransparency(rBrush.GetColor().GetTransparency());
      50             : 
      51           0 :         rToSet.Put(XFillStyleItem(XFILL_SOLID));
      52           0 :         rToSet.Put(XFillColorItem(OUString(), aColor));
      53             : 
      54           0 :         if(0xff != nTransparency)
      55             :         {
      56             :             // nTransparency is in range [0..255]
      57           0 :             rToSet.Put(XFillTransparenceItem((((sal_Int32)nTransparency * 100) + 127) / 255));
      58             :         }
      59             :     }
      60           0 :     else if(GPOS_NONE != rBrush.GetGraphicPos())
      61             :     {
      62           0 :         const Graphic* pGraphic = rBrush.GetGraphic();
      63             : 
      64           0 :         if(pGraphic)
      65             :         {
      66             :             // set fill style and graphic itself
      67           0 :             rToSet.Put(XFillStyleItem(XFILL_BITMAP));
      68           0 :             rToSet.Put(XFillBitmapItem(OUString(), *pGraphic));
      69             : 
      70             :             // set defaults
      71             :             // already pool default rToSet.Put(XFillBmpPosItem(RP_MM));
      72             :             // already pool default rToSet.Put(XFillBmpTileOffsetXItem(0));
      73             :             // already pool default rToSet.Put(XFillBmpTileOffsetYItem(0));
      74             :             // already pool default rToSet.Put(XFillBmpPosOffsetXItem(0));
      75             :             // already pool default rToSet.Put(XFillBmpPosOffsetYItem(0));
      76             :             // already pool default rToSet.Put(XFillBmpSizeLogItem(true));
      77             :             // already pool default rToSet.Put(XFillBmpSizeXItem(0));
      78             :             // already pool default rToSet.Put(XFillBmpSizeYItem(0));
      79             : 
      80           0 :             if(GPOS_AREA == rBrush.GetGraphicPos())
      81             :             {
      82             :                 // stretch, also means no tile (both items are defaulted to true)
      83             :                 // rToSet.Put(XFillBmpStretchItem(true));
      84           0 :                 rToSet.Put(XFillBmpTileItem(false));
      85             : 
      86             :                 // default for strech is also top-left, but this will not be visible
      87             :                 // rToSet.Put(XFillBmpPosItem(RP_LT));
      88             :             }
      89           0 :             else if(GPOS_TILED == rBrush.GetGraphicPos())
      90             :             {
      91             :                 // tiled, also means no stretch (both items are defaulted to true)
      92           0 :                 rToSet.Put(XFillBmpStretchItem(false));
      93             :                 //rToSet.Put(XFillBmpTileItem(true));
      94             : 
      95             :                 // default for tiled is top-left
      96           0 :                 rToSet.Put(XFillBmpPosItem(RP_LT));
      97             :             }
      98             :             else
      99             :             {
     100             :                 // everything else means no tile and no stretch
     101           0 :                 rToSet.Put(XFillBmpStretchItem(false));
     102           0 :                 rToSet.Put(XFillBmpTileItem(false));
     103             : 
     104           0 :                 switch(rBrush.GetGraphicPos())
     105             :                 {
     106           0 :                     case GPOS_LT: rToSet.Put(XFillBmpPosItem(RP_LT)); break;
     107           0 :                     case GPOS_MT: rToSet.Put(XFillBmpPosItem(RP_MT)); break;
     108           0 :                     case GPOS_RT: rToSet.Put(XFillBmpPosItem(RP_RT)); break;
     109           0 :                     case GPOS_LM: rToSet.Put(XFillBmpPosItem(RP_LM)); break;
     110           0 :                     case GPOS_MM: rToSet.Put(XFillBmpPosItem(RP_MM)); break;
     111           0 :                     case GPOS_RM: rToSet.Put(XFillBmpPosItem(RP_RM)); break;
     112           0 :                     case GPOS_LB: rToSet.Put(XFillBmpPosItem(RP_LB)); break;
     113           0 :                     case GPOS_MB: rToSet.Put(XFillBmpPosItem(RP_MB)); break;
     114           0 :                     case GPOS_RB: rToSet.Put(XFillBmpPosItem(RP_RB)); break;
     115           0 :                     default: break; // already handled GPOS_AREA, GPOS_TILED and GPOS_NONE
     116             :                 }
     117             :             }
     118             : 
     119             :             // check for transparency
     120           0 :             const sal_Int8 nTransparency(rBrush.getGraphicTransparency());
     121             : 
     122           0 :             if(0 != nTransparency)
     123             :             {
     124             :                 // nTransparency is in range [0..100]
     125           0 :                 rToSet.Put(XFillTransparenceItem(nTransparency));
     126             :             }
     127             :         }
     128             :         else
     129             :         {
     130             :             OSL_ENSURE(false, "Could not get Graphic from SvxBrushItem (!)");
     131             :         }
     132             :     }
     133           0 : }
     134             : 
     135             : //UUUU
     136           0 : sal_uInt16 getTransparenceForSvxBrushItem(const SfxItemSet& rSourceSet, sal_Bool bSearchInParents)
     137             : {
     138           0 :     sal_uInt16 nFillTransparence(static_cast< const XFillTransparenceItem& >(rSourceSet.Get(XATTR_FILLTRANSPARENCE, bSearchInParents)).GetValue());
     139           0 :     const SfxPoolItem* pGradientItem = 0;
     140             : 
     141           0 :     if(SFX_ITEM_SET == rSourceSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, bSearchInParents, &pGradientItem)
     142           0 :         && static_cast< const XFillFloatTransparenceItem* >(pGradientItem)->IsEnabled())
     143             :     {
     144           0 :         const XGradient& rGradient = static_cast< const XFillFloatTransparenceItem* >(pGradientItem)->GetGradientValue();
     145           0 :         const sal_uInt16 nStartLuminance(rGradient.GetStartColor().GetLuminance());
     146           0 :         const sal_uInt16 nEndLuminance(rGradient.GetEndColor().GetLuminance());
     147             : 
     148             :         // luminance is [0..255], transparence needs to be in [0..100].Maximum is 51200, thus sal_uInt16 is okay to use
     149           0 :         nFillTransparence = static_cast< sal_uInt16 >(((nStartLuminance + nEndLuminance) * 100) / 512);
     150             :     }
     151             : 
     152           0 :     return nFillTransparence;
     153             : }
     154             : 
     155             : //UUUU
     156           0 : SvxBrushItem getSvxBrushItemForSolid(const SfxItemSet& rSourceSet, sal_Bool bSearchInParents)
     157             : {
     158           0 :     Color aFillColor(static_cast< const XFillColorItem& >(rSourceSet.Get(XATTR_FILLCOLOR, bSearchInParents)).GetColorValue());
     159             : 
     160             :     // get evtl. mixed transparence
     161           0 :     const sal_uInt16 nFillTransparence(getTransparenceForSvxBrushItem(rSourceSet, bSearchInParents));
     162             : 
     163           0 :     if(0 != nFillTransparence)
     164             :     {
     165             :         // nFillTransparence is in range [0..100] and needs to be in [0..255] unsigned
     166           0 :         aFillColor.SetTransparency(static_cast< sal_uInt8 >((nFillTransparence * 255) / 100));
     167             :     }
     168             : 
     169           0 :     return SvxBrushItem(aFillColor, RES_BACKGROUND);
     170             : }
     171             : 
     172             : //UUUU
     173           0 : SvxBrushItem getSvxBrushItemFromSourceSet(const SfxItemSet& rSourceSet, sal_Bool bSearchInParents)
     174             : {
     175           0 :     SvxBrushItem aRetval(RES_BACKGROUND);
     176             : 
     177           0 :     const XFillStyleItem* pXFillStyleItem(static_cast< const XFillStyleItem*  >(rSourceSet.GetItem(XATTR_FILLSTYLE, bSearchInParents)));
     178             : 
     179           0 :     if(!pXFillStyleItem)
     180             :     {
     181           0 :         return aRetval;
     182             :     }
     183             : 
     184           0 :     switch(pXFillStyleItem->GetValue())
     185             :     {
     186             :         case XFILL_NONE:
     187             :         {
     188             :             // done; return default item
     189           0 :             break;
     190             :         }
     191             :         case XFILL_SOLID:
     192             :         {
     193             :             // create SvxBrushItem with fill color
     194           0 :             aRetval = getSvxBrushItemForSolid(rSourceSet, bSearchInParents);
     195           0 :             break;
     196             :         }
     197             :         case XFILL_GRADIENT:
     198             :         {
     199             :             // cannot be directly supported, but do the best possible
     200           0 :             const XGradient aXGradient(static_cast< const XFillGradientItem& >(rSourceSet.Get(XATTR_FILLGRADIENT)).GetGradientValue());
     201           0 :             const basegfx::BColor aStartColor(aXGradient.GetStartColor().getBColor() * (aXGradient.GetStartIntens() * 0.01));
     202           0 :             const basegfx::BColor aEndColor(aXGradient.GetEndColor().getBColor() * (aXGradient.GetEndIntens() * 0.01));
     203             : 
     204             :             // use half/half mixed color from gradient start and end
     205           0 :             Color aMixedColor((aStartColor + aEndColor) * 0.5);
     206             : 
     207             :             // get evtl. mixed transparence
     208           0 :             const sal_uInt16 nFillTransparence(getTransparenceForSvxBrushItem(rSourceSet, bSearchInParents));
     209             : 
     210           0 :             if(0 != nFillTransparence)
     211             :             {
     212             :                 // nFillTransparence is in range [0..100] and needs to be in [0..255] unsigned
     213           0 :                 aMixedColor.SetTransparency(static_cast< sal_uInt8 >((nFillTransparence * 255) / 100));
     214             :             }
     215             : 
     216           0 :             aRetval = SvxBrushItem(aMixedColor, RES_BACKGROUND);
     217           0 :             break;
     218             :         }
     219             :         case XFILL_HATCH:
     220             :         {
     221             :             // cannot be directly supported, but do the best possible
     222           0 :             const XHatch& rHatch(static_cast< const XFillHatchItem& >(rSourceSet.Get(XATTR_FILLHATCH)).GetHatchValue());
     223           0 :             const bool bFillBackground(static_cast< const XFillBackgroundItem& >(rSourceSet.Get(XATTR_FILLBACKGROUND)).GetValue());
     224             : 
     225           0 :             if(bFillBackground)
     226             :             {
     227             :                 // hatch is background-filled, use FillColor as if XFILL_SOLID
     228           0 :                 aRetval = getSvxBrushItemForSolid(rSourceSet, bSearchInParents);
     229             :             }
     230             :             else
     231             :             {
     232             :                 // hatch is not background-filled and using hatch color would be too dark; compensate
     233             :                 // somewhat by making it more transparent
     234           0 :                 Color aHatchColor(rHatch.GetColor());
     235             : 
     236             :                 // get evtl. mixed transparence
     237           0 :                 sal_uInt16 nFillTransparence(getTransparenceForSvxBrushItem(rSourceSet, bSearchInParents));
     238             : 
     239             :                 // take half orig transparence, add half transparent, clamp result
     240           0 :                 nFillTransparence = basegfx::clamp((sal_uInt16)((nFillTransparence / 2) + 50), (sal_uInt16)0, (sal_uInt16)255);
     241             : 
     242             :                 // nFillTransparence is in range [0..100] and needs to be in [0..255] unsigned
     243           0 :                 aHatchColor.SetTransparency(static_cast< sal_uInt8 >((nFillTransparence * 255) / 100));
     244             : 
     245           0 :                 aRetval = SvxBrushItem(aHatchColor, RES_BACKGROUND);
     246             :             }
     247             : 
     248           0 :             break;
     249             :         }
     250             :         case XFILL_BITMAP:
     251             :         {
     252             :             // create SvxBrushItem with bitmap info and flags
     253           0 :             const XFillBitmapItem& rBmpItm = static_cast< const XFillBitmapItem& >(rSourceSet.Get(XATTR_FILLBITMAP, bSearchInParents));
     254           0 :             const Graphic aGraphic(rBmpItm.GetGraphicObject().GetGraphic());
     255             : 
     256           0 :             if(GRAPHIC_NONE != aGraphic.GetType())
     257             :             {
     258             :                 // get graphic position
     259           0 :                 SvxGraphicPosition aSvxGraphicPosition(GPOS_NONE);
     260           0 :                 const XFillBmpStretchItem& rStretchItem = static_cast< const XFillBmpStretchItem& >(rSourceSet.Get(XATTR_FILLBMP_STRETCH, bSearchInParents));
     261           0 :                 const XFillBmpTileItem& rTileItem = static_cast< const XFillBmpTileItem& >(rSourceSet.Get(XATTR_FILLBMP_TILE, bSearchInParents));
     262             : 
     263           0 :                 if(rTileItem.GetValue())
     264             :                 {
     265           0 :                     aSvxGraphicPosition = GPOS_TILED;
     266             :                 }
     267           0 :                 else if(rStretchItem.GetValue())
     268             :                 {
     269           0 :                     aSvxGraphicPosition = GPOS_AREA;
     270             :                 }
     271             :                 else
     272             :                 {
     273           0 :                     const XFillBmpPosItem& rPosItem = static_cast< const XFillBmpPosItem& >(rSourceSet.Get(XATTR_FILLBMP_POS, bSearchInParents));
     274             : 
     275           0 :                     switch(rPosItem.GetValue())
     276             :                     {
     277           0 :                         case RP_LT: aSvxGraphicPosition = GPOS_LT; break;
     278           0 :                         case RP_MT: aSvxGraphicPosition = GPOS_MT; break;
     279           0 :                         case RP_RT: aSvxGraphicPosition = GPOS_RT; break;
     280           0 :                         case RP_LM: aSvxGraphicPosition = GPOS_LM; break;
     281           0 :                         case RP_MM: aSvxGraphicPosition = GPOS_MM; break;
     282           0 :                         case RP_RM: aSvxGraphicPosition = GPOS_RM; break;
     283           0 :                         case RP_LB: aSvxGraphicPosition = GPOS_LB; break;
     284           0 :                         case RP_MB: aSvxGraphicPosition = GPOS_MB; break;
     285           0 :                         case RP_RB: aSvxGraphicPosition = GPOS_RB; break;
     286             :                     }
     287             :                 }
     288             : 
     289             :                 // create with given graphic and position
     290           0 :                 aRetval = SvxBrushItem(aGraphic, aSvxGraphicPosition, RES_BACKGROUND);
     291             : 
     292             :                 // get evtl. mixed transparence
     293           0 :                 const sal_uInt16 nFillTransparence(getTransparenceForSvxBrushItem(rSourceSet, bSearchInParents));
     294             : 
     295           0 :                 if(0 != nFillTransparence)
     296             :                 {
     297             :                     // nFillTransparence is in range [0..100] and needs to be in [0..100] signed
     298           0 :                     aRetval.setGraphicTransparency(static_cast< sal_Int8 >(nFillTransparence));
     299             :                 }
     300             :             }
     301             : 
     302           0 :             break;
     303             :         }
     304             :     }
     305             : 
     306           0 :     return aRetval;
     307             : }
     308             : 
     309             : } // namespace sw
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10