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) + " 1");
68
69 sal_Int32 nLen = aStr.getLength() - 1;
70 Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLACK,css::drawing::HatchStyle_SINGLE,100, 0_deg10),aStr.toString()));
71 aStr[nLen] = '2';
72 Insert(std::make_unique<XHatchEntry>(XHatch(COL_RED ,css::drawing::HatchStyle_DOUBLE, 80,450_deg10),aStr.toString()));
73 aStr[nLen] = '3';
74 Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLUE ,css::drawing::HatchStyle_TRIPLE,120, 0_deg10),aStr.toString()));
75
76 return true;
77}
78
80{
81 BitmapEx aRetval;
82 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
83
84 if(nIndex < Count())
85 {
87
88 // prepare polygon geometry for rectangle
89 basegfx::B2DPolygon aRectangle(
91 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
92
93 const XHatch& rHatch = GetHatch(nIndex)->GetHatch();
95
96 switch(rHatch.GetHatchStyle())
97 {
98 case css::drawing::HatchStyle_SINGLE :
99 {
101 break;
102 }
103 case css::drawing::HatchStyle_DOUBLE :
104 {
106 break;
107 }
108 default :
109 {
110 aHatchStyle = drawinglayer::attribute::HatchStyle::Triple; // css::drawing::HatchStyle_TRIPLE
111 break;
112 }
113 }
114
115 const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapPixel)));
116 const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
117 const double fScaleValue(aScaleVector.getLength());
118
120 aHatchStyle,
121 static_cast<double>(rHatch.GetDistance()) * fScaleValue,
122 toRadians(rHatch.GetAngle()),
123 rHatch.GetColor().getBColor(),
124 3, // same default as VCL, a minimum of three discrete units (pixels) offset
125 false);
126
127 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
130 basegfx::B2DPolyPolygon(aRectangle),
131 aBlack,
132 std::move(aFillHatch)));
133
134 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
136 std::move(aRectangle),
137 aBlack));
138
139 // prepare VirtualDevice
141 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
142
143 pVirtualDevice->SetOutputSizePixel(rSize);
144 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
145 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
146 : DrawModeFlags::Default);
147
148 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
149 {
150 const Point aNull(0, 0);
151 static const sal_uInt32 nLen(8);
152 static const Color aW(COL_WHITE);
153 static const Color aG(0xef, 0xef, 0xef);
154 pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
155 }
156 else
157 {
158 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
159 pVirtualDevice->Erase();
160 }
161
162 // create processor and draw primitives
163 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
164 *pVirtualDevice,
165 aNewViewInformation2D));
166
168
169 aSequence[0] = aHatchPrimitive;
170 aSequence[1] = aBlackRectanglePrimitive;
171 pProcessor2D->process(aSequence);
172 pProcessor2D.reset();
173
174 // get result bitmap and scale
175 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
176 }
177
178 return aRetval;
179}
180
182{
183 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
184 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
185 BitmapEx aRetVal = CreateBitmap(nIndex, rSize);
186 return aRetVal;
187}
188
190{
191 return CreateBitmap(nIndex, rSize);
192}
193
194/* 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:181
BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size &rSize)
Definition: xtabhtch.cxx:189
virtual ~XHatchList() override
Definition: xtabhtch.cxx:46
BitmapEx CreateBitmap(tools::Long nIndex, const Size &rSize) const
Definition: xtabhtch.cxx:79
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