LCOV - code coverage report
Current view: top level - svx/source/xoutdev - xtabgrdt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 7 85 8.2 %
Date: 2015-06-13 12:38:46 Functions: 4 9 44.4 %
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 "svx/XPropertyTable.hxx"
      21             : 
      22             : #include <vcl/virdev.hxx>
      23             : #include <svx/dialogs.hrc>
      24             : #include <svx/dialmgr.hxx>
      25             : #include <svx/xtable.hxx>
      26             : 
      27             : #include <vcl/svapp.hxx>
      28             : #include <vcl/settings.hxx>
      29             : 
      30             : #include <drawinglayer/attribute/fillgradientattribute.hxx>
      31             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      32             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      33             : #include <drawinglayer/processor2d/processor2dtools.hxx>
      34             : #include <basegfx/polygon/b2dpolygontools.hxx>
      35             : #include <boost/scoped_ptr.hpp>
      36             : 
      37             : using namespace com::sun::star;
      38             : 
      39        4192 : XGradientList::XGradientList( const OUString& rPath, const OUString& rReferer )
      40        4192 : :   XPropertyList( XGRADIENT_LIST, rPath, rReferer )
      41             : {
      42        4192 : }
      43             : 
      44        8306 : XGradientList::~XGradientList()
      45             : {
      46        8306 : }
      47             : 
      48           0 : XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex )
      49             : {
      50           0 :     return static_cast<XGradientEntry*>( XPropertyList::Replace( pEntry, nIndex ) );
      51             : }
      52             : 
      53           0 : XGradientEntry* XGradientList::Remove(long nIndex)
      54             : {
      55           0 :     return static_cast<XGradientEntry*>( XPropertyList::Remove( nIndex ) );
      56             : }
      57             : 
      58           0 : XGradientEntry* XGradientList::GetGradient(long nIndex) const
      59             : {
      60           0 :     return static_cast<XGradientEntry*>( XPropertyList::Get( nIndex ) );
      61             : }
      62             : 
      63         146 : uno::Reference< container::XNameContainer > XGradientList::createInstance()
      64             : {
      65             :     return uno::Reference< container::XNameContainer >(
      66             :         SvxUnoXGradientTable_createInstance( this ),
      67         146 :         uno::UNO_QUERY );
      68             : }
      69             : 
      70           0 : bool XGradientList::Create()
      71             : {
      72           0 :     rtl::OUStringBuffer aStr(SVX_RESSTR(RID_SVXSTR_GRADIENT));
      73           0 :     aStr.append(" 1");
      74           0 :     sal_Int32 nLen = aStr.getLength() - 1;
      75           0 :     Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK  ),RGB_Color(COL_WHITE  ),css::awt::GradientStyle_LINEAR    ,    0,10,10, 0,100,100),aStr.toString()));
      76           0 :     aStr[nLen] = '2';
      77           0 :     Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE   ),RGB_Color(COL_RED    ),css::awt::GradientStyle_AXIAL     ,  300,20,20,10,100,100),aStr.toString()));
      78           0 :     aStr[nLen] = '3';
      79           0 :     Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED    ),RGB_Color(COL_YELLOW ),css::awt::GradientStyle_RADIAL    ,  600,30,30,20,100,100),aStr.toString()));
      80           0 :     aStr[nLen] = '4';
      81           0 :     Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN  ),css::awt::GradientStyle_ELLIPTICAL,  900,40,40,30,100,100),aStr.toString()));
      82           0 :     aStr[nLen] = '5';
      83           0 :     Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN  ),RGB_Color(COL_MAGENTA),css::awt::GradientStyle_SQUARE    , 1200,50,50,40,100,100),aStr.toString()));
      84           0 :     aStr[nLen] = '6';
      85           0 :     Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),css::awt::GradientStyle_RECT      , 1900,60,60,50,100,100),aStr.toString()));
      86             : 
      87           0 :     return true;
      88             : }
      89             : 
      90           0 : Bitmap XGradientList::CreateBitmapForUI( long nIndex )
      91             : {
      92           0 :     Bitmap aRetval;
      93             : 
      94             :     OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
      95             : 
      96           0 :     if(nIndex < Count())
      97             :     {
      98           0 :         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
      99           0 :         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
     100             : 
     101             :         // prepare polygon geometry for rectangle
     102             :         const basegfx::B2DPolygon aRectangle(
     103             :             basegfx::tools::createPolygonFromRect(
     104           0 :                 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
     105             : 
     106           0 :         const XGradient& rGradient = GetGradient(nIndex)->GetGradient();
     107           0 :         const sal_uInt16 nStartIntens(rGradient.GetStartIntens());
     108           0 :         basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
     109             : 
     110           0 :         if(nStartIntens != 100)
     111             :         {
     112           0 :             const basegfx::BColor aBlack;
     113           0 :             aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01);
     114             :         }
     115             : 
     116           0 :         const sal_uInt16 nEndIntens(rGradient.GetEndIntens());
     117           0 :         basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
     118             : 
     119           0 :         if(nEndIntens != 100)
     120             :         {
     121           0 :             const basegfx::BColor aBlack;
     122           0 :             aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01);
     123             :         }
     124             : 
     125           0 :         drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GRADIENTSTYLE_RECT);
     126             : 
     127           0 :         switch(rGradient.GetGradientStyle())
     128             :         {
     129             :             case css::awt::GradientStyle_LINEAR :
     130             :             {
     131           0 :                 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_LINEAR;
     132           0 :                 break;
     133             :             }
     134             :             case css::awt::GradientStyle_AXIAL :
     135             :             {
     136           0 :                 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_AXIAL;
     137           0 :                 break;
     138             :             }
     139             :             case css::awt::GradientStyle_RADIAL :
     140             :             {
     141           0 :                 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RADIAL;
     142           0 :                 break;
     143             :             }
     144             :             case css::awt::GradientStyle_ELLIPTICAL :
     145             :             {
     146           0 :                 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_ELLIPTICAL;
     147           0 :                 break;
     148             :             }
     149             :             case css::awt::GradientStyle_SQUARE :
     150             :             {
     151           0 :                 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_SQUARE;
     152           0 :                 break;
     153             :             }
     154             :             default :
     155             :             {
     156           0 :                 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RECT; // css::awt::GradientStyle_RECT
     157           0 :                 break;
     158             :             }
     159             :         }
     160             : 
     161           0 :         const sal_uInt16 nSteps((rSize.Width() + rSize.Height()) / 3);
     162             :         const drawinglayer::attribute::FillGradientAttribute aFillGradient(
     163             :             aGradientStyle,
     164           0 :             (double)rGradient.GetBorder() * 0.01,
     165           0 :             (double)rGradient.GetXOffset() * 0.01,
     166           0 :             (double)rGradient.GetYOffset() * 0.01,
     167           0 :             (double)rGradient.GetAngle() * F_PI1800,
     168             :             aStart,
     169             :             aEnd,
     170           0 :             nSteps);
     171             : 
     172             :         const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive(
     173             :             new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
     174             :                 basegfx::B2DPolyPolygon(aRectangle),
     175           0 :                 aFillGradient));
     176             : 
     177           0 :         const basegfx::BColor aBlack(0.0, 0.0, 0.0);
     178             :         const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
     179             :             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
     180             :                 aRectangle,
     181           0 :                 aBlack));
     182             : 
     183             :         // prepare VirtualDevice
     184           0 :         ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
     185           0 :         const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
     186             : 
     187           0 :         pVirtualDevice->SetOutputSizePixel(rSize);
     188           0 :         pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
     189           0 :             ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
     190           0 :             : DrawModeFlags::Default);
     191             : 
     192             :         // create processor and draw primitives
     193             :         boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
     194           0 :             *pVirtualDevice.get(),
     195           0 :             aNewViewInformation2D));
     196             : 
     197           0 :         if(pProcessor2D)
     198             :         {
     199           0 :             drawinglayer::primitive2d::Primitive2DSequence aSequence(2);
     200             : 
     201           0 :             aSequence[0] = aGradientPrimitive;
     202           0 :             aSequence[1] = aBlackRectanglePrimitive;
     203             : 
     204           0 :             pProcessor2D->process(aSequence);
     205           0 :             pProcessor2D.reset();
     206             :         }
     207             : 
     208             :         // get result bitmap and scale
     209           0 :         aRetval = pVirtualDevice->GetBitmap(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
     210             :     }
     211             : 
     212           0 :     return aRetval;
     213             : }
     214             : 
     215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11