LibreOffice Module drawinglayer (master) 1
xprimitive2drenderer.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 <sal/config.h>
21
22#include <com/sun/star/graphic/XPrimitive2DRenderer.hpp>
23#include <com/sun/star/lang/XServiceInfo.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
29#include <vcl/bitmapex.hxx>
30#include <vcl/canvastools.hxx>
31#include <com/sun/star/geometry/RealRectangle2D.hpp>
34
37
38using namespace ::com::sun::star;
39
40
42{
43 namespace {
44
45 class XPrimitive2DRenderer:
47 css::graphic::XPrimitive2DRenderer, css::lang::XServiceInfo>
48 {
49 public:
50 XPrimitive2DRenderer();
51
52 XPrimitive2DRenderer(const XPrimitive2DRenderer&) = delete;
53 const XPrimitive2DRenderer& operator=(const XPrimitive2DRenderer&) = delete;
54
55 // XPrimitive2DRenderer
56 virtual uno::Reference< rendering::XBitmap > SAL_CALL rasterize(
57 const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& Primitive2DSequence,
58 const uno::Sequence< beans::PropertyValue >& aViewInformationSequence,
59 ::sal_uInt32 DPI_X,
60 ::sal_uInt32 DPI_Y,
61 const css::geometry::RealRectangle2D& Range,
62 ::sal_uInt32 MaximumQuadraticPixels) override;
63
64 // XServiceInfo
65 virtual OUString SAL_CALL getImplementationName() override;
66 virtual sal_Bool SAL_CALL supportsService(const OUString&) override;
67 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
68 };
69
70 }
71
72 XPrimitive2DRenderer::XPrimitive2DRenderer()
73 {
74 }
75
76 uno::Reference< rendering::XBitmap > XPrimitive2DRenderer::rasterize(
77 const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& aPrimitive2DSequence,
78 const uno::Sequence< beans::PropertyValue >& aViewInformationSequence,
79 ::sal_uInt32 DPI_X,
80 ::sal_uInt32 DPI_Y,
81 const css::geometry::RealRectangle2D& Range,
82 ::sal_uInt32 MaximumQuadraticPixels)
83 {
85 comphelper::SequenceAsHashMap aViewInformationMap(aViewInformationSequence);
86 auto it = aViewInformationMap.find("RangeUnit");
87 if (it != aViewInformationMap.end())
88 {
89 sal_Int32 nVal{};
90 it->second >>= nVal;
91 eRangeUnit = static_cast<o3tl::Length>(nVal);
92 }
93
94 uno::Reference< rendering::XBitmap > XBitmap;
95
96 if(aPrimitive2DSequence.hasElements())
97 {
98 const basegfx::B2DRange aRange(Range.X1, Range.Y1, Range.X2, Range.Y2);
99 const double fWidth(aRange.getWidth());
100 const double fHeight(aRange.getHeight());
101
102 if(basegfx::fTools::more(fWidth, 0.0) && basegfx::fTools::more(fHeight, 0.0))
103 {
104 if(0 == DPI_X)
105 {
106 DPI_X = 75;
107 }
108
109 if(0 == DPI_Y)
110 {
111 DPI_Y = 75;
112 }
113
114 if(0 == MaximumQuadraticPixels)
115 {
116 MaximumQuadraticPixels = 500000;
117 }
118
119 auto aViewInformation2D = geometry::createViewInformation2D(aViewInformationSequence);
120
121 if(aViewInformation2D.getViewport().isEmpty())
122 {
123 // we have a Viewport since we create a discrete pixel device, use it
124 // if none is given
125 aViewInformation2D.setViewport(aRange);
126 }
127
128 const sal_uInt32 nDiscreteWidth(basegfx::fround(o3tl::convert(fWidth, eRangeUnit, o3tl::Length::in) * DPI_X));
129 const sal_uInt32 nDiscreteHeight(basegfx::fround(o3tl::convert(fHeight, eRangeUnit, o3tl::Length::in) * DPI_Y));
130
131 basegfx::B2DHomMatrix aEmbedding(
133 -aRange.getMinX(),
134 -aRange.getMinY()));
135
136 aEmbedding.scale(
137 nDiscreteWidth / fWidth,
138 nDiscreteHeight / fHeight);
139
140 const primitive2d::Primitive2DReference xEmbedRef(
142 aEmbedding,
143 aPrimitive2DSequence));
144 primitive2d::Primitive2DContainer xEmbedSeq { xEmbedRef };
145
146 BitmapEx aBitmapEx(
148 std::move(xEmbedSeq),
149 aViewInformation2D,
150 nDiscreteWidth,
151 nDiscreteHeight,
152 MaximumQuadraticPixels));
153
154 if(!aBitmapEx.IsEmpty())
155 {
156 aBitmapEx.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
157 aBitmapEx.SetPrefSize(Size(basegfx::fround(fWidth), basegfx::fround(fHeight)));
158 XBitmap = vcl::unotools::xBitmapFromBitmapEx(aBitmapEx);
159 }
160 }
161 }
162
163 return XBitmap;
164 }
165
166 OUString SAL_CALL XPrimitive2DRenderer::getImplementationName()
167 {
168 return "drawinglayer::unorenderer::XPrimitive2DRenderer";
169 }
170
171 sal_Bool SAL_CALL XPrimitive2DRenderer::supportsService(const OUString& rServiceName)
172 {
173 return cppu::supportsService(this, rServiceName);
174 }
175
176 uno::Sequence< OUString > SAL_CALL XPrimitive2DRenderer::getSupportedServiceNames()
177 {
178 return { "com.sun.star.graphic.Primitive2DTools" };
179 }
180
181} // end of namespace
182
183
184extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
186 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const& )
187{
188 return cppu::acquire(new drawinglayer::unorenderer::XPrimitive2DRenderer());
189}
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetPrefMapMode(const MapMode &rPrefMapMode)
void SetPrefSize(const Size &rPrefSize)
bool IsEmpty() const
void scale(double fX, double fY)
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
TYPE getHeight() const
iterator find(const OUString &rKey)
bool more(const T &rfValA, const T &rfValB)
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
B2IRange fround(const B2DRange &rRange)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
ViewInformation2D createViewInformation2D(const css::uno::Sequence< css::beans::PropertyValue > &rViewParameters)
css::uno::Sequence< css::uno::Reference< css::graphic::XPrimitive2D > > Primitive2DSequence
Definition: CommonTypes.hxx:29
BitmapEx convertToBitmapEx(drawinglayer::primitive2d::Primitive2DContainer &&rSeq, const geometry::ViewInformation2D &rViewInformation2D, sal_uInt32 nDiscreteWidth, sal_uInt32 nDiscreteHeight, sal_uInt32 nMaxSquarePixels)
Definition: converters.cxx:156
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
uno::Reference< rendering::XBitmap > xBitmapFromBitmapEx(const ::BitmapEx &inputBitmap)
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * drawinglayer_XPrimitive2DRenderer(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)