fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / xoutdev / xtabdash.cxx
blobe553fec4e1d8179d9ec4f49e2e6285073b237158
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 "svx/XPropertyTable.hxx"
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
25 #include <vcl/virdev.hxx>
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <svx/xtable.hxx>
30 #include <drawinglayer/attribute/lineattribute.hxx>
31 #include <drawinglayer/attribute/strokeattribute.hxx>
32 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
33 #include <drawinglayer/processor2d/processor2dtools.hxx>
34 #include <boost/scoped_ptr.hpp>
36 using namespace com::sun::star;
38 XDashList::XDashList(const OUString& rPath, const OUString& rReferer)
39 : XPropertyList(XDASH_LIST, rPath, rReferer)
40 , maBitmapSolidLine()
41 , maStringSolidLine()
42 , maStringNoLine()
46 XDashList::~XDashList()
50 XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
52 return static_cast<XDashEntry*>( XPropertyList::Replace(pEntry, nIndex) );
55 XDashEntry* XDashList::Remove(long nIndex)
57 return static_cast<XDashEntry*>( XPropertyList::Remove(nIndex) );
60 XDashEntry* XDashList::GetDash(long nIndex) const
62 return static_cast<XDashEntry*>( XPropertyList::Get(nIndex) );
65 uno::Reference< container::XNameContainer > XDashList::createInstance()
67 return uno::Reference< container::XNameContainer >(
68 SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
71 bool XDashList::Create()
73 const OUString aStr(SVX_RESSTR(RID_SVXSTR_LINESTYLE));
75 Insert(new XDashEntry(XDash(css::drawing::DashStyle_RECT,1, 50,1, 50, 50),aStr + " 1"));
76 Insert(new XDashEntry(XDash(css::drawing::DashStyle_RECT,1,500,1,500,500),aStr + " 2"));
77 Insert(new XDashEntry(XDash(css::drawing::DashStyle_RECT,2, 50,3,250,120),aStr + " 3"));
79 return true;
82 Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash)
84 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
85 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
86 const sal_uInt32 nFactor(2);
87 const Size aSize((rSize.Width() * 5 * 2) / 2, rSize.Height() * nFactor);
89 // prepare polygon geometry for line
90 basegfx::B2DPolygon aLine;
92 aLine.append(basegfx::B2DPoint(0.0, aSize.Height() / 2.0));
93 aLine.append(basegfx::B2DPoint(aSize.Width(), aSize.Height() / 2.0));
95 // prepare LineAttribute
96 const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
97 const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * (nFactor * 1.1));
98 const drawinglayer::attribute::LineAttribute aLineAttribute(
99 aLineColor,
100 fLineWidth);
102 // prepare StrokeAttribute
103 ::std::vector< double > aDotDashArray;
104 double fFullDotDashLen(0.0);
106 if(pDash && (pDash->GetDots() || pDash->GetDashes()))
108 const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MAP_100TH_MM, MAP_PIXEL));
109 const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
110 const double fScaleValue(aScaleVector.getLength() * (nFactor * (1.4 / 2.0)));
111 const double fLineWidthInUnits(fLineWidth / fScaleValue);
113 fFullDotDashLen = pDash->CreateDotDashArray(aDotDashArray, fLineWidthInUnits);
115 if(!aDotDashArray.empty())
117 for(sal_uInt32 a(0); a < aDotDashArray.size(); a++)
119 aDotDashArray[a] *= fScaleValue;
122 fFullDotDashLen *= fScaleValue;
126 const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
127 aDotDashArray,
128 fFullDotDashLen);
130 // cerate LinePrimitive
131 const drawinglayer::primitive2d::Primitive2DReference aLinePrimitive(
132 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
133 aLine,
134 aLineAttribute,
135 aStrokeAttribute));
137 // prepare VirtualDevice
138 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
139 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
141 pVirtualDevice->SetOutputSizePixel(aSize);
142 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
143 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
144 : DrawModeFlags::Default);
146 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
148 const Point aNull(0, 0);
149 static const sal_uInt32 nLen(8 * nFactor);
150 static const Color aW(COL_WHITE);
151 static const Color aG(0xef, 0xef, 0xef);
153 pVirtualDevice->DrawCheckered(aNull, aSize, nLen, aW, aG);
155 else
157 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
158 pVirtualDevice->Erase();
161 // create processor and draw primitives
162 boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
163 *pVirtualDevice.get(),
164 aNewViewInformation2D));
166 if(pProcessor2D)
168 const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLinePrimitive, 1);
170 pProcessor2D->process(aSequence);
171 pProcessor2D.reset();
174 // get result bitmap and scale
175 Bitmap aRetval(pVirtualDevice->GetBitmap(Point(0, 0), pVirtualDevice->GetOutputSizePixel()));
177 if(1 != nFactor)
179 aRetval.Scale(Size((rSize.Width() * 5) / 2, rSize.Height()), BmpScaleFlag::Default);
182 return aRetval;
185 Bitmap XDashList::CreateBitmapForUI( long nIndex )
187 const XDash& rDash = GetDash(nIndex)->GetDash();
189 return ImpCreateBitmapForXDash(&rDash);
192 Bitmap XDashList::GetBitmapForUISolidLine() const
194 if(maBitmapSolidLine.IsEmpty())
196 const_cast< XDashList* >(this)->maBitmapSolidLine = XDashList::ImpCreateBitmapForXDash(0);
199 return maBitmapSolidLine;
202 OUString XDashList::GetStringForUiSolidLine() const
204 if(maStringSolidLine.isEmpty())
206 const_cast< XDashList* >(this)->maStringSolidLine = ResId(RID_SVXSTR_SOLID, DIALOG_MGR()).toString();
209 return maStringSolidLine;
212 OUString XDashList::GetStringForUiNoLine() const
214 if(maStringNoLine.isEmpty())
216 // formally was RID_SVXSTR_INVISIBLE, but tomake equal
217 // everywhere, use RID_SVXSTR_NONE
218 const_cast< XDashList* >(this)->maStringNoLine = ResId(RID_SVXSTR_NONE, DIALOG_MGR()).toString();
221 return maStringNoLine;
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */