bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / xoutdev / xtabhtch.cxx
blob19bc8b737887e7bae7a6851dffe1be98096a7fd4
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>
21 #include <vcl/svapp.hxx>
23 #include <vcl/virdev.hxx>
24 #include <vcl/settings.hxx>
25 #include <svx/strings.hrc>
26 #include <svx/dialmgr.hxx>
28 #include <drawinglayer/attribute/fillhatchattribute.hxx>
29 #include <drawinglayer/primitive2d/PolyPolygonHatchPrimitive2D.hxx>
30 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
31 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
32 #include <drawinglayer/processor2d/processor2dtools.hxx>
33 #include <basegfx/polygon/b2dpolygontools.hxx>
34 #include <rtl/ustrbuf.hxx>
35 #include <memory>
37 using namespace ::com::sun::star;
39 XHatchList::XHatchList(const OUString& rPath, const OUString& rReferer)
40 : XPropertyList( XPropertyListType::Hatch, rPath, rReferer )
44 XHatchList::~XHatchList()
48 void XHatchList::Replace(std::unique_ptr<XHatchEntry> pEntry, tools::Long nIndex)
50 XPropertyList::Replace(std::move(pEntry), nIndex);
53 XHatchEntry* XHatchList::GetHatch(tools::Long nIndex) const
55 return static_cast<XHatchEntry*>( XPropertyList::Get(nIndex) );
58 uno::Reference< container::XNameContainer > XHatchList::createInstance()
60 return uno::Reference< container::XNameContainer >(
61 SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
64 bool XHatchList::Create()
66 OUStringBuffer aStr(SvxResId(RID_SVXSTR_HATCH));
67 aStr.append(" 1");
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()));
76 return true;
79 BitmapEx XHatchList::CreateBitmap( tools::Long nIndex, const Size& rSize) const
81 BitmapEx aRetval;
82 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
84 if(nIndex < Count())
86 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
88 // prepare polygon geometry for rectangle
89 const basegfx::B2DPolygon aRectangle(
90 basegfx::utils::createPolygonFromRect(
91 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
93 const XHatch& rHatch = GetHatch(nIndex)->GetHatch();
94 drawinglayer::attribute::HatchStyle aHatchStyle(drawinglayer::attribute::HatchStyle::Triple);
96 switch(rHatch.GetHatchStyle())
98 case css::drawing::HatchStyle_SINGLE :
100 aHatchStyle = drawinglayer::attribute::HatchStyle::Single;
101 break;
103 case css::drawing::HatchStyle_DOUBLE :
105 aHatchStyle = drawinglayer::attribute::HatchStyle::Double;
106 break;
108 default :
110 aHatchStyle = drawinglayer::attribute::HatchStyle::Triple; // css::drawing::HatchStyle_TRIPLE
111 break;
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());
119 const drawinglayer::attribute::FillHatchAttribute aFillHatch(
120 aHatchStyle,
121 static_cast<double>(rHatch.GetDistance()) * fScaleValue,
122 static_cast<double>(rHatch.GetAngle().get()) * F_PI1800,
123 rHatch.GetColor().getBColor(),
124 3, // same default as VCL, a minimum of three discrete units (pixels) offset
125 false);
127 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
128 const drawinglayer::primitive2d::Primitive2DReference aHatchPrimitive(
129 new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
130 basegfx::B2DPolyPolygon(aRectangle),
131 aBlack,
132 aFillHatch));
134 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
135 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
136 aRectangle,
137 aBlack));
139 // prepare VirtualDevice
140 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
141 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
143 pVirtualDevice->SetOutputSizePixel(rSize);
144 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
145 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
146 : DrawModeFlags::Default);
148 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
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);
156 else
158 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
159 pVirtualDevice->Erase();
162 // create processor and draw primitives
163 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
164 *pVirtualDevice,
165 aNewViewInformation2D));
167 drawinglayer::primitive2d::Primitive2DContainer aSequence(2);
169 aSequence[0] = aHatchPrimitive;
170 aSequence[1] = aBlackRectanglePrimitive;
171 pProcessor2D->process(aSequence);
172 pProcessor2D.reset();
174 // get result bitmap and scale
175 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
178 return aRetval;
181 BitmapEx XHatchList::CreateBitmapForUI(tools::Long nIndex)
183 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
184 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
185 BitmapEx aRetVal = CreateBitmap(nIndex, rSize);
186 return aRetVal;
189 BitmapEx XHatchList::GetBitmapForPreview(tools::Long nIndex, const Size& rSize)
191 return CreateBitmap(nIndex, rSize);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */