nss: upgrade to release 3.73
[LibreOffice.git] / drawinglayer / source / drawinglayeruno / xprimitive2drenderer.cxx
blob66b29591df7efe39ed771c26fbc46cfa2008fc01
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 <sal/config.h>
22 #include <com/sun/star/graphic/XPrimitive2DRenderer.hpp>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <cppuhelper/implbase2.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <comphelper/sequence.hxx>
28 #include <drawinglayer/geometry/viewinformation2d.hxx>
29 #include <basegfx/numeric/ftools.hxx>
30 #include <vcl/bitmapex.hxx>
31 #include <vcl/canvastools.hxx>
32 #include <com/sun/star/geometry/RealRectangle2D.hpp>
33 #include <basegfx/matrix/b2dhommatrixtools.hxx>
34 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
36 #include <converters.hxx>
38 using namespace ::com::sun::star;
41 namespace drawinglayer::unorenderer
43 namespace {
45 class XPrimitive2DRenderer:
46 public cppu::WeakAggImplHelper2<
47 css::graphic::XPrimitive2DRenderer, css::lang::XServiceInfo>
49 public:
50 XPrimitive2DRenderer();
52 XPrimitive2DRenderer(const XPrimitive2DRenderer&) = delete;
53 const XPrimitive2DRenderer& operator=(const XPrimitive2DRenderer&) = delete;
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;
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;
72 XPrimitive2DRenderer::XPrimitive2DRenderer()
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)
84 uno::Reference< rendering::XBitmap > XBitmap;
86 if(aPrimitive2DSequence.hasElements())
88 const basegfx::B2DRange aRange(Range.X1, Range.Y1, Range.X2, Range.Y2);
89 const double fWidth(aRange.getWidth());
90 const double fHeight(aRange.getHeight());
92 if(basegfx::fTools::more(fWidth, 0.0) && basegfx::fTools::more(fHeight, 0.0))
94 if(0 == DPI_X)
96 DPI_X = 75;
99 if(0 == DPI_Y)
101 DPI_Y = 75;
104 if(0 == MaximumQuadraticPixels)
106 MaximumQuadraticPixels = 500000;
109 const geometry::ViewInformation2D aViewInformation2D(aViewInformationSequence);
110 const double fFactor100th_mmToInch(1.0 / (2.54 * 1000.0));
111 const sal_uInt32 nDiscreteWidth(basegfx::fround((fWidth * fFactor100th_mmToInch) * DPI_X));
112 const sal_uInt32 nDiscreteHeight(basegfx::fround((fHeight * fFactor100th_mmToInch) * DPI_Y));
114 basegfx::B2DHomMatrix aEmbedding(
115 basegfx::utils::createTranslateB2DHomMatrix(
116 -aRange.getMinX(),
117 -aRange.getMinY()));
119 aEmbedding.scale(
120 nDiscreteWidth / fWidth,
121 nDiscreteHeight / fHeight);
123 const primitive2d::Primitive2DReference xEmbedRef(
124 new primitive2d::TransformPrimitive2D(
125 aEmbedding,
126 comphelper::sequenceToContainer<primitive2d::Primitive2DContainer>(aPrimitive2DSequence)));
127 const primitive2d::Primitive2DContainer xEmbedSeq { xEmbedRef };
129 BitmapEx aBitmapEx(
130 convertToBitmapEx(
131 xEmbedSeq,
132 aViewInformation2D,
133 nDiscreteWidth,
134 nDiscreteHeight,
135 MaximumQuadraticPixels));
137 if(!aBitmapEx.IsEmpty())
139 aBitmapEx.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
140 aBitmapEx.SetPrefSize(Size(basegfx::fround(fWidth), basegfx::fround(fHeight)));
141 XBitmap = vcl::unotools::xBitmapFromBitmapEx(aBitmapEx);
146 return XBitmap;
149 OUString SAL_CALL XPrimitive2DRenderer::getImplementationName()
151 return "drawinglayer::unorenderer::XPrimitive2DRenderer";
154 sal_Bool SAL_CALL XPrimitive2DRenderer::supportsService(const OUString& rServiceName)
156 return cppu::supportsService(this, rServiceName);
159 uno::Sequence< OUString > SAL_CALL XPrimitive2DRenderer::getSupportedServiceNames()
161 return { "com.sun.star.graphic.Primitive2DTools" };
164 } // end of namespace
167 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
168 drawinglayer_XPrimitive2DRenderer(
169 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const& )
171 return cppu::acquire(new drawinglayer::unorenderer::XPrimitive2DRenderer());
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */