Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / xoutdev / xtabgrdt.cxx
blob40d881c19dae7ab24b78cd845d5f973a9888d7d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <XPropertyTable.hxx>
22 #include <vcl/virdev.hxx>
23 #include <svx/strings.hrc>
24 #include <svx/dialmgr.hxx>
25 #include <svx/xtable.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/settings.hxx>
30 #include <osl/diagnose.h>
32 #include <drawinglayer/attribute/fillgradientattribute.hxx>
33 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
34 #include <drawinglayer/primitive2d/PolyPolygonGradientPrimitive2D.hxx>
35 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
36 #include <drawinglayer/processor2d/processor2dtools.hxx>
37 #include <basegfx/polygon/b2dpolygontools.hxx>
38 #include <basegfx/utils/gradienttools.hxx>
39 #include <memory>
41 using namespace com::sun::star;
43 XGradientList::XGradientList( const OUString& rPath, const OUString& rReferer )
44 : XPropertyList( XPropertyListType::Gradient, rPath, rReferer )
48 XGradientList::~XGradientList()
52 void XGradientList::Replace(std::unique_ptr<XGradientEntry> pEntry, tools::Long nIndex)
54 XPropertyList::Replace(std::move(pEntry), nIndex);
57 XGradientEntry* XGradientList::GetGradient(tools::Long nIndex) const
59 return static_cast<XGradientEntry*>( XPropertyList::Get( nIndex ) );
62 uno::Reference< container::XNameContainer > XGradientList::createInstance()
64 return SvxUnoXGradientTable_createInstance( *this );
67 bool XGradientList::Create()
69 OUStringBuffer aStr(SvxResId(RID_SVXSTR_GRADIENT) + " 1");
70 sal_Int32 nLen = aStr.getLength() - 1;
72 // XGradient() default already creates [COL_BLACK, COL_WHITE] as defaults
73 Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(),aStr.toString()));
75 aStr[nLen] = '2';
76 Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_BLUE.getBColor(), COL_RED.getBColor()), css::awt::GradientStyle_AXIAL , 300_deg10,20,20,10,100,100),aStr.toString()));
77 aStr[nLen] = '3';
78 Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_RED.getBColor(), COL_YELLOW.getBColor()), css::awt::GradientStyle_RADIAL , 600_deg10,30,30,20,100,100),aStr.toString()));
79 aStr[nLen] = '4';
80 Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_YELLOW.getBColor(), COL_GREEN.getBColor()), css::awt::GradientStyle_ELLIPTICAL, 900_deg10,40,40,30,100,100),aStr.toString()));
81 aStr[nLen] = '5';
82 Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_GREEN.getBColor(), COL_MAGENTA.getBColor()), css::awt::GradientStyle_SQUARE , 1200_deg10,50,50,40,100,100),aStr.toString()));
83 aStr[nLen] = '6';
84 Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_MAGENTA.getBColor(), COL_YELLOW.getBColor()), css::awt::GradientStyle_RECT , 1900_deg10,60,60,50,100,100),aStr.toString()));
86 return true;
89 BitmapEx XGradientList::CreateBitmap( tools::Long nIndex, const Size& rSize ) const
91 BitmapEx aRetval;
93 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
95 if(nIndex < Count())
97 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
98 // prepare polygon geometry for rectangle
99 basegfx::B2DPolygon aRectangle(
100 basegfx::utils::createPolygonFromRect(
101 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
103 const basegfx::BGradient& rGradient = GetGradient(nIndex)->GetGradient();
104 basegfx::BColorStops aColorStops(rGradient.GetColorStops());
106 if (rGradient.GetStartIntens() != 100 || rGradient.GetEndIntens() != 100)
108 // Need to do the (old, crazy) blend against black
109 aColorStops.blendToIntensity(
110 rGradient.GetStartIntens() * 0.01,
111 rGradient.GetEndIntens() * 0.01,
112 basegfx::BColor()); // COL_BLACK
115 drawinglayer::attribute::FillGradientAttribute aFillGradient(
116 rGradient.GetGradientStyle(),
117 static_cast<double>(rGradient.GetBorder()) * 0.01,
118 static_cast<double>(rGradient.GetXOffset()) * 0.01,
119 static_cast<double>(rGradient.GetYOffset()) * 0.01,
120 toRadians(rGradient.GetAngle()),
121 aColorStops);
123 const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive(
124 new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
125 basegfx::B2DPolyPolygon(aRectangle),
126 std::move(aFillGradient)));
128 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
129 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
130 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
131 std::move(aRectangle),
132 aBlack));
134 // prepare VirtualDevice
135 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
136 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
138 pVirtualDevice->SetOutputSizePixel(rSize);
139 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
140 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
141 : DrawModeFlags::Default);
143 // create processor and draw primitives
144 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
145 *pVirtualDevice,
146 aNewViewInformation2D));
148 drawinglayer::primitive2d::Primitive2DContainer aSequence(2);
150 aSequence[0] = aGradientPrimitive;
151 aSequence[1] = aBlackRectanglePrimitive;
153 pProcessor2D->process(aSequence);
154 pProcessor2D.reset();
156 // get result bitmap and scale
157 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
160 return aRetval;
163 BitmapEx XGradientList::CreateBitmapForUI(tools::Long nIndex)
165 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
166 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
167 return CreateBitmap(nIndex, rSize);
170 BitmapEx XGradientList::GetBitmapForPreview(tools::Long nIndex, const Size& rSize)
172 return CreateBitmap(nIndex, rSize);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */