LibreOffice Module svx (master) 1
xtabhtch.cxx
Go to the documentation of this file.
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 <XPropertyTable.hxx>
21#include <vcl/svapp.hxx>
22
23#include <vcl/virdev.hxx>
24#include <vcl/settings.hxx>
25#include <svx/strings.hrc>
26#include <svx/dialmgr.hxx>
27
35#include <osl/diagnose.h>
36#include <rtl/ustrbuf.hxx>
37#include <memory>
38
39using namespace ::com::sun::star;
40
41XHatchList::XHatchList(const OUString& rPath, const OUString& rReferer)
42 : XPropertyList( XPropertyListType::Hatch, rPath, rReferer )
43{
44}
45
47{
48}
49
50void XHatchList::Replace(std::unique_ptr<XHatchEntry> pEntry, tools::Long nIndex)
51{
52 XPropertyList::Replace(std::move(pEntry), nIndex);
53}
54
56{
57 return static_cast<XHatchEntry*>( XPropertyList::Get(nIndex) );
58}
59
60uno::Reference< container::XNameContainer > XHatchList::createInstance()
61{
63}
64
66{
67 OUStringBuffer aStr(SvxResId(RID_SVXSTR_HATCH));
68 aStr.append(" 1");
69
70 sal_Int32 nLen = aStr.getLength() - 1;
71 Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLACK,css::drawing::HatchStyle_SINGLE,100, 0_deg10),aStr.toString()));
72 aStr[nLen] = '2';
73 Insert(std::make_unique<XHatchEntry>(XHatch(COL_RED ,css::drawing::HatchStyle_DOUBLE, 80,450_deg10),aStr.toString()));
74 aStr[nLen] = '3';
75 Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLUE ,css::drawing::HatchStyle_TRIPLE,120, 0_deg10),aStr.toString()));
76
77 return true;
78}
79
81{
82 BitmapEx aRetval;
83 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
84
85 if(nIndex < Count())
86 {
88
89 // prepare polygon geometry for rectangle
90 basegfx::B2DPolygon aRectangle(
92 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
93
94 const XHatch& rHatch = GetHatch(nIndex)->GetHatch();
96
97 switch(rHatch.GetHatchStyle())
98 {
99 case css::drawing::HatchStyle_SINGLE :
100 {
102 break;
103 }
104 case css::drawing::HatchStyle_DOUBLE :
105 {
107 break;
108 }
109 default :
110 {
111 aHatchStyle = drawinglayer::attribute::HatchStyle::Triple; // css::drawing::HatchStyle_TRIPLE
112 break;
113 }
114 }
115
116 const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapPixel)));
117 const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
118 const double fScaleValue(aScaleVector.getLength());
119
121 aHatchStyle,
122 static_cast<double>(rHatch.GetDistance()) * fScaleValue,
123 toRadians(rHatch.GetAngle()),
124 rHatch.GetColor().getBColor(),
125 3, // same default as VCL, a minimum of three discrete units (pixels) offset
126 false);
127
128 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
131 basegfx::B2DPolyPolygon(aRectangle),
132 aBlack,
133 std::move(aFillHatch)));
134
135 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
137 std::move(aRectangle),
138 aBlack));
139
140 // prepare VirtualDevice
142 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
143
144 pVirtualDevice->SetOutputSizePixel(rSize);
145 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
146 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
147 : DrawModeFlags::Default);
148
149 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
150 {
151 const Point aNull(0, 0);
152 static const sal_uInt32 nLen(8);
153 static const Color aW(COL_WHITE);
154 static const Color aG(0xef, 0xef, 0xef);
155 pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
156 }
157 else
158 {
159 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
160 pVirtualDevice->Erase();
161 }
162
163 // create processor and draw primitives
164 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
165 *pVirtualDevice,
166 aNewViewInformation2D));
167
169
170 aSequence[0] = aHatchPrimitive;
171 aSequence[1] = aBlackRectanglePrimitive;
172 pProcessor2D->process(aSequence);
173 pProcessor2D.reset();
174
175 // get result bitmap and scale
176 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
177 }
178
179 return aRetval;
180}
181
183{
184 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
185 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
186 BitmapEx aRetVal = CreateBitmap(nIndex, rSize);
187 return aRetVal;
188}
189
191{
192 return CreateBitmap(nIndex, rSize);
193}
194
195/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< container::XNameContainer > SvxUnoXHatchTable_createInstance(XPropertyList &rTable) noexcept
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
basegfx::BColor getBColor() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool GetPreviewUsesCheckeredBackground() const
bool GetHighContrastMode() const
const Color & GetFieldColor() const
const Size & GetListBoxPreviewDefaultPixelSize() const
const XHatch & GetHatch() const
Definition: xtable.hxx:95
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtabhtch.cxx:182
BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size &rSize)
Definition: xtabhtch.cxx:190
virtual ~XHatchList() override
Definition: xtabhtch.cxx:46
BitmapEx CreateBitmap(tools::Long nIndex, const Size &rSize) const
Definition: xtabhtch.cxx:80
XHatchEntry * GetHatch(tools::Long nIndex) const
Definition: xtabhtch.cxx:55
void Replace(std::unique_ptr< XHatchEntry > pEntry, tools::Long nIndex)
Definition: xtabhtch.cxx:50
XHatchList(const OUString &rPath, const OUString &rReferer)
Definition: xtabhtch.cxx:41
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtabhtch.cxx:60
virtual bool Create() override
Definition: xtabhtch.cxx:65
const Color & GetColor() const
Definition: xhatch.hxx:52
tools::Long GetDistance() const
Definition: xhatch.hxx:53
css::drawing::HatchStyle GetHatchStyle() const
Definition: xhatch.hxx:51
Degree10 GetAngle() const
Definition: xhatch.hxx:54
tools::Long Count() const
Definition: xtable.cxx:122
void Insert(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex=std::numeric_limits< tools::Long >::max())
Definition: xtable.cxx:178
void Replace(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex)
Definition: xtable.cxx:193
XPropertyEntry * Get(tools::Long nIndex) const
Definition: xtable.cxx:132
double getLength() const
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_RED(0x80, 0x00, 0x00)
constexpr ::Color COL_BLUE(0x00, 0x00, 0x80)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
double toRadians(D x)
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
sal_Int32 nIndex
aStr
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
long Long
XPropertyListType
Definition: xtable.hxx:131