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 
34 #include <rtl/ustrbuf.hxx>
35 #include <memory>
36 
37 using namespace ::com::sun::star;
38 
39 XHatchList::XHatchList(const OUString& rPath, const OUString& rReferer)
40  : XPropertyList( XPropertyListType::Hatch, rPath, rReferer )
41 {
42 }
43 
45 {
46 }
47 
48 void XHatchList::Replace(std::unique_ptr<XHatchEntry> pEntry, tools::Long nIndex)
49 {
50  XPropertyList::Replace(std::move(pEntry), nIndex);
51 }
52 
54 {
55  return static_cast<XHatchEntry*>( XPropertyList::Get(nIndex) );
56 }
57 
58 uno::Reference< container::XNameContainer > XHatchList::createInstance()
59 {
60  return uno::Reference< container::XNameContainer >(
61  SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
62 }
63 
65 {
66  OUStringBuffer aStr(SvxResId(RID_SVXSTR_HATCH));
67  aStr.append(" 1");
68 
69  sal_Int32 nLen = aStr.getLength() - 1;
70  Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLACK,css::drawing::HatchStyle_SINGLE,100, Degree10(0)),aStr.toString()));
71  aStr[nLen] = '2';
72  Insert(std::make_unique<XHatchEntry>(XHatch(COL_RED ,css::drawing::HatchStyle_DOUBLE, 80,Degree10(450)),aStr.toString()));
73  aStr[nLen] = '3';
74  Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLUE ,css::drawing::HatchStyle_TRIPLE,120, Degree10(0)),aStr.toString()));
75 
76  return true;
77 }
78 
79 BitmapEx XHatchList::CreateBitmap( tools::Long nIndex, const Size& rSize) const
80 {
81  BitmapEx aRetval;
82  OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
83 
84  if(nIndex < Count())
85  {
86  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
87 
88  // prepare polygon geometry for rectangle
89  const 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  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);
126 
127  const basegfx::BColor aBlack(0.0, 0.0, 0.0);
130  basegfx::B2DPolyPolygon(aRectangle),
131  aBlack,
132  aFillHatch));
133 
134  const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
136  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 
167  if(pProcessor2D)
168  {
170 
171  aSequence[0] = aHatchPrimitive;
172  aSequence[1] = aBlackRectanglePrimitive;
173  pProcessor2D->process(aSequence);
174  pProcessor2D.reset();
175  }
176 
177  // get result bitmap and scale
178  aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
179  }
180 
181  return aRetval;
182 }
183 
185 {
186  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
187  const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
188  BitmapEx aRetVal = CreateBitmap(nIndex, rSize);
189  return aRetVal;
190 }
191 
193 {
194  return CreateBitmap(nIndex, rSize);
195 }
196 
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size &rSize)
Definition: xtabhtch.cxx:192
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr::Color COL_RED(0x80, 0x00, 0x00)
long Long
const StyleSettings & GetStyleSettings() const
#define F_PI1800
static const AllSettings & GetSettings()
BitmapEx CreateBitmap(tools::Long nIndex, const Size &rSize) const
Definition: xtabhtch.cxx:79
bool GetPreviewUsesCheckeredBackground() const
const Size & GetListBoxPreviewDefaultPixelSize() const
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:25
bool GetHighContrastMode() const
void Replace(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex)
Definition: xtable.cxx:192
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtabhtch.cxx:58
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
XPropertyListType
Definition: xtable.hxx:131
void Insert(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex=std::numeric_limits< tools::Long >::max())
Definition: xtable.cxx:177
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
tools::Long Width() const
const Color & GetFieldColor() const
XPropertyEntry * Get(tools::Long nIndex) const
Definition: xtable.cxx:131
tools::Long Count() const
Definition: xtable.cxx:121
XHatchEntry * GetHatch(tools::Long nIndex) const
Definition: xtabhtch.cxx:53
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
const XHatch & GetHatch() const
Definition: xtable.hxx:95
virtual bool Create() override
Definition: xtabhtch.cxx:64
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
tools::Long Height() const
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
double getLength() const
uno::Reference< uno::XInterface > SvxUnoXHatchTable_createInstance(XPropertyList *pTable)
void Replace(std::unique_ptr< XHatchEntry > pEntry, tools::Long nIndex)
Definition: xtabhtch.cxx:48
constexpr::Color COL_BLUE(0x00, 0x00, 0x80)
XHatchList(const OUString &rPath, const OUString &rReferer)
Definition: xtabhtch.cxx:39
aStr
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtabhtch.cxx:184
virtual ~XHatchList() override
Definition: xtabhtch.cxx:44