1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
40 using namespace com::sun::star
;
42 XGradientList::XGradientList( const OUString
& rPath
, const OUString
& rReferer
)
43 : XPropertyList( XPropertyListType::Gradient
, rPath
, rReferer
)
47 XGradientList::~XGradientList()
51 void XGradientList::Replace(std::unique_ptr
<XGradientEntry
> pEntry
, tools::Long nIndex
)
53 XPropertyList::Replace(std::move(pEntry
), nIndex
);
56 XGradientEntry
* XGradientList::GetGradient(tools::Long nIndex
) const
58 return static_cast<XGradientEntry
*>( XPropertyList::Get( nIndex
) );
61 uno::Reference
< container::XNameContainer
> XGradientList::createInstance()
63 return SvxUnoXGradientTable_createInstance( *this );
66 bool XGradientList::Create()
68 OUStringBuffer
aStr(SvxResId(RID_SVXSTR_GRADIENT
) + " 1");
69 sal_Int32 nLen
= aStr
.getLength() - 1;
71 // XGradient() default already creates [COL_BLACK, COL_WHITE] as defaults
72 Insert(std::make_unique
<XGradientEntry
>(basegfx::BGradient(),aStr
.toString()));
75 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 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 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 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 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()));
88 BitmapEx
XGradientList::CreateBitmap( tools::Long nIndex
, const Size
& rSize
) const
92 OSL_ENSURE(nIndex
< Count(), "OOps, access out of range (!)");
96 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
97 // prepare polygon geometry for rectangle
98 basegfx::B2DPolygon
aRectangle(
99 basegfx::utils::createPolygonFromRect(
100 basegfx::B2DRange(0.0, 0.0, rSize
.Width(), rSize
.Height())));
102 const basegfx::BGradient
& rGradient
= GetGradient(nIndex
)->GetGradient();
103 basegfx::BColorStops
aColorStops(rGradient
.GetColorStops());
105 if (rGradient
.GetStartIntens() != 100 || rGradient
.GetEndIntens() != 100)
107 // Need to do the (old, crazy) blend against black
108 aColorStops
.blendToIntensity(
109 rGradient
.GetStartIntens() * 0.01,
110 rGradient
.GetEndIntens() * 0.01,
111 basegfx::BColor()); // COL_BLACK
114 drawinglayer::attribute::FillGradientAttribute
aFillGradient(
115 rGradient
.GetGradientStyle(),
116 static_cast<double>(rGradient
.GetBorder()) * 0.01,
117 static_cast<double>(rGradient
.GetXOffset()) * 0.01,
118 static_cast<double>(rGradient
.GetYOffset()) * 0.01,
119 toRadians(rGradient
.GetAngle()),
122 const drawinglayer::primitive2d::Primitive2DReference
aGradientPrimitive(
123 new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
124 basegfx::B2DPolyPolygon(aRectangle
),
125 std::move(aFillGradient
)));
127 const basegfx::BColor
aBlack(0.0, 0.0, 0.0);
128 const drawinglayer::primitive2d::Primitive2DReference
aBlackRectanglePrimitive(
129 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
130 std::move(aRectangle
),
133 // prepare VirtualDevice
134 ScopedVclPtrInstance
< VirtualDevice
> pVirtualDevice
;
135 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D
;
137 pVirtualDevice
->SetOutputSizePixel(rSize
);
138 pVirtualDevice
->SetDrawMode(rStyleSettings
.GetHighContrastMode()
139 ? DrawModeFlags::SettingsLine
| DrawModeFlags::SettingsFill
| DrawModeFlags::SettingsText
| DrawModeFlags::SettingsGradient
140 : DrawModeFlags::Default
);
142 // create processor and draw primitives
143 std::unique_ptr
<drawinglayer::processor2d::BaseProcessor2D
> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
145 aNewViewInformation2D
));
147 drawinglayer::primitive2d::Primitive2DContainer aSequence
{
149 aBlackRectanglePrimitive
};
151 pProcessor2D
->process(aSequence
);
152 pProcessor2D
.reset();
154 // get result bitmap and scale
155 aRetval
= pVirtualDevice
->GetBitmapEx(Point(0, 0), pVirtualDevice
->GetOutputSizePixel());
161 BitmapEx
XGradientList::CreateBitmapForUI(tools::Long nIndex
)
163 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
164 const Size
& rSize
= rStyleSettings
.GetListBoxPreviewDefaultPixelSize();
165 return CreateBitmap(nIndex
, rSize
);
168 BitmapEx
XGradientList::GetBitmapForPreview(tools::Long nIndex
, const Size
& rSize
)
170 return CreateBitmap(nIndex
, rSize
);
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */