calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / svx / source / xoutdev / xtabhtch.cxx
blob2091924ea5188783fb4d315d27b698d740f8a156
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/PolygonHairlinePrimitive2D.hxx>
31 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
32 #include <drawinglayer/processor2d/processor2dtools.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <osl/diagnose.h>
36 #include <rtl/ustrbuf.hxx>
37 #include <memory>
39 using namespace ::com::sun::star;
41 XHatchList::XHatchList(const OUString& rPath, const OUString& rReferer)
42 : XPropertyList( XPropertyListType::Hatch, rPath, rReferer )
46 XHatchList::~XHatchList()
50 void XHatchList::Replace(std::unique_ptr<XHatchEntry> pEntry, tools::Long nIndex)
52 XPropertyList::Replace(std::move(pEntry), nIndex);
55 XHatchEntry* XHatchList::GetHatch(tools::Long nIndex) const
57 return static_cast<XHatchEntry*>( XPropertyList::Get(nIndex) );
60 uno::Reference< container::XNameContainer > XHatchList::createInstance()
62 return SvxUnoXHatchTable_createInstance( *this );
65 bool XHatchList::Create()
67 OUStringBuffer aStr(SvxResId(RID_SVXSTR_HATCH));
68 aStr.append(" 1");
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()));
77 return true;
80 BitmapEx XHatchList::CreateBitmap( tools::Long nIndex, const Size& rSize) const
82 BitmapEx aRetval;
83 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
85 if(nIndex < Count())
87 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
89 // prepare polygon geometry for rectangle
90 basegfx::B2DPolygon aRectangle(
91 basegfx::utils::createPolygonFromRect(
92 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
94 const XHatch& rHatch = GetHatch(nIndex)->GetHatch();
95 drawinglayer::attribute::HatchStyle aHatchStyle(drawinglayer::attribute::HatchStyle::Triple);
97 switch(rHatch.GetHatchStyle())
99 case css::drawing::HatchStyle_SINGLE :
101 aHatchStyle = drawinglayer::attribute::HatchStyle::Single;
102 break;
104 case css::drawing::HatchStyle_DOUBLE :
106 aHatchStyle = drawinglayer::attribute::HatchStyle::Double;
107 break;
109 default :
111 aHatchStyle = drawinglayer::attribute::HatchStyle::Triple; // css::drawing::HatchStyle_TRIPLE
112 break;
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());
120 drawinglayer::attribute::FillHatchAttribute aFillHatch(
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);
128 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
129 const drawinglayer::primitive2d::Primitive2DReference aHatchPrimitive(
130 new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
131 basegfx::B2DPolyPolygon(aRectangle),
132 aBlack,
133 std::move(aFillHatch)));
135 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
136 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
137 std::move(aRectangle),
138 aBlack));
140 // prepare VirtualDevice
141 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
142 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
144 pVirtualDevice->SetOutputSizePixel(rSize);
145 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
146 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
147 : DrawModeFlags::Default);
149 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
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);
157 else
159 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
160 pVirtualDevice->Erase();
163 // create processor and draw primitives
164 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
165 *pVirtualDevice,
166 aNewViewInformation2D));
168 drawinglayer::primitive2d::Primitive2DContainer aSequence(2);
170 aSequence[0] = aHatchPrimitive;
171 aSequence[1] = aBlackRectanglePrimitive;
172 pProcessor2D->process(aSequence);
173 pProcessor2D.reset();
175 // get result bitmap and scale
176 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
179 return aRetval;
182 BitmapEx XHatchList::CreateBitmapForUI(tools::Long nIndex)
184 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
185 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
186 BitmapEx aRetVal = CreateBitmap(nIndex, rSize);
187 return aRetVal;
190 BitmapEx XHatchList::GetBitmapForPreview(tools::Long nIndex, const Size& rSize)
192 return CreateBitmap(nIndex, rSize);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */