build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / bitmap / BitmapTools.cxx
blob40e79b721b71afb2d98fc7ae2c3bcfc0d5d5526b
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 */
11 #include <vcl/BitmapTools.hxx>
13 #include <comphelper/processfactory.hxx>
14 #include <comphelper/seqstream.hxx>
15 #include <vcl/canvastools.hxx>
17 #include <com/sun/star/graphic/SvgTools.hpp>
18 #include <com/sun/star/graphic/Primitive2DTools.hpp>
20 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
22 #include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
24 #include <tools/resmgr.hxx>
25 #include <tools/rc.h>
26 #include <vcl/svapp.hxx>
28 using namespace css;
30 using drawinglayer::primitive2d::Primitive2DSequence;
31 using drawinglayer::primitive2d::Primitive2DReference;
33 namespace vcl
36 namespace bitmap
39 BitmapEx loadFromName(const OUString& rFileName, const ImageLoadFlags eFlags)
41 BitmapEx aBitmapEx;
43 OUString aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
45 ImageTree::get().loadImage(rFileName, aIconTheme, aBitmapEx, true, eFlags);
47 return aBitmapEx;
50 BitmapEx loadFromResource(const ResId& rResId, const ImageLoadFlags eFlags)
52 ResMgr* pResMgr = nullptr;
54 ResMgr::GetResourceSkipHeader(rResId.SetRT( RSC_BITMAP ), &pResMgr);
55 pResMgr->ReadLong();
56 pResMgr->ReadLong();
58 const OUString aFileName(pResMgr->ReadString());
60 return loadFromName(aFileName, eFlags);
63 void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, double fScalingFactor)
65 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
66 const uno::Reference<graphic::XSvgParser> xSvgParser = graphic::SvgTools::create(xContext);
68 std::size_t nSize = rStream.remainingSize();
69 std::vector<sal_Int8> aBuffer(nSize + 1);
70 rStream.ReadBytes(aBuffer.data(), nSize);
71 aBuffer[nSize] = 0;
73 uno::Sequence<sal_Int8> aData(aBuffer.data(), nSize + 1);
74 uno::Reference<io::XInputStream> aInputStream(new comphelper::SequenceInputStream(aData));
76 Primitive2DSequence aPrimitiveSequence = xSvgParser->getDecomposition(aInputStream, sPath);
78 if (aPrimitiveSequence.hasElements())
80 uno::Sequence<beans::PropertyValue> aViewParameters;
82 const sal_Int32 nCount(aPrimitiveSequence.getLength());
83 geometry::RealRectangle2D aRealRect;
84 basegfx::B2DRange aRange;
85 for (sal_Int32 a = 0L; a < nCount; ++a)
87 const Primitive2DReference xReference(aPrimitiveSequence[a]);
89 if (xReference.is())
91 aRealRect = xReference->getRange(aViewParameters);
92 aRange.expand(basegfx::B2DRange(aRealRect.X1, aRealRect.Y1, aRealRect.X2, aRealRect.Y2));
96 aRealRect.X1 = 0;
97 aRealRect.Y1 = 0;
98 aRealRect.X2 = aRange.getMaxX() - aRange.getMinX();
99 aRealRect.Y2 = aRange.getMaxY() - aRange.getMinY();
101 double nDPI = 96 * fScalingFactor;
103 const css::uno::Reference<css::graphic::XPrimitive2DRenderer> xPrimitive2DRenderer = css::graphic::Primitive2DTools::create(xContext);
104 const css::uno::Reference<css::rendering::XBitmap> xBitmap(
105 xPrimitive2DRenderer->rasterize(aPrimitiveSequence, aViewParameters, nDPI, nDPI, aRealRect, 256*256));
107 if (xBitmap.is())
109 const css::uno::Reference<css::rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW);
111 if (xIntBmp.is())
113 rBitmapEx = vcl::unotools::bitmapExFromXBitmap(xIntBmp);
119 }} // end vcl::bitmap
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */