2015-11-08 23:00:14 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vcl/BitmapTools.hxx>
|
|
|
|
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <comphelper/seqstream.hxx>
|
|
|
|
#include <vcl/canvastools.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/graphic/SvgTools.hpp>
|
|
|
|
#include <com/sun/star/graphic/Primitive2DTools.hpp>
|
|
|
|
|
|
|
|
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
|
|
|
|
|
|
|
|
using namespace css;
|
|
|
|
|
|
|
|
using drawinglayer::primitive2d::Primitive2DSequence;
|
|
|
|
using drawinglayer::primitive2d::Primitive2DReference;
|
|
|
|
|
|
|
|
namespace vcl
|
|
|
|
{
|
|
|
|
|
2016-02-26 10:36:34 +02:00
|
|
|
void BitmapTools::loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, double fScalingFactor)
|
2015-11-08 23:00:14 +01:00
|
|
|
{
|
|
|
|
uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
|
|
|
|
const uno::Reference<graphic::XSvgParser> xSvgParser = graphic::SvgTools::create(xContext);
|
|
|
|
|
2016-09-14 17:01:50 +02:00
|
|
|
std::size_t nSize = rStream.remainingSize();
|
2016-04-25 09:59:16 +02:00
|
|
|
std::vector<sal_Int8> aBuffer(nSize + 1);
|
2016-06-03 14:45:59 +02:00
|
|
|
rStream.ReadBytes(aBuffer.data(), nSize);
|
2016-04-25 09:59:16 +02:00
|
|
|
aBuffer[nSize] = 0;
|
2015-11-08 23:00:14 +01:00
|
|
|
|
2016-04-25 09:59:16 +02:00
|
|
|
uno::Sequence<sal_Int8> aData(aBuffer.data(), nSize + 1);
|
2015-11-08 23:00:14 +01:00
|
|
|
uno::Reference<io::XInputStream> aInputStream(new comphelper::SequenceInputStream(aData));
|
|
|
|
|
|
|
|
Primitive2DSequence aPrimitiveSequence = xSvgParser->getDecomposition(aInputStream, sPath);
|
|
|
|
|
|
|
|
if (aPrimitiveSequence.hasElements())
|
|
|
|
{
|
|
|
|
uno::Sequence<beans::PropertyValue> aViewParameters;
|
|
|
|
|
|
|
|
const sal_Int32 nCount(aPrimitiveSequence.getLength());
|
|
|
|
geometry::RealRectangle2D aRealRect;
|
|
|
|
basegfx::B2DRange aRange;
|
|
|
|
for (sal_Int32 a = 0L; a < nCount; ++a)
|
|
|
|
{
|
|
|
|
const Primitive2DReference xReference(aPrimitiveSequence[a]);
|
|
|
|
|
|
|
|
if (xReference.is())
|
|
|
|
{
|
|
|
|
aRealRect = xReference->getRange(aViewParameters);
|
|
|
|
aRange.expand(basegfx::B2DRange(aRealRect.X1, aRealRect.Y1, aRealRect.X2, aRealRect.Y2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aRealRect.X1 = 0;
|
|
|
|
aRealRect.Y1 = 0;
|
2016-02-26 10:36:34 +02:00
|
|
|
aRealRect.X2 = aRange.getMaxX() - aRange.getMinX();
|
|
|
|
aRealRect.Y2 = aRange.getMaxY() - aRange.getMinY();
|
2015-11-08 23:00:14 +01:00
|
|
|
|
|
|
|
double nDPI = 90 * fScalingFactor;
|
|
|
|
|
|
|
|
const css::uno::Reference<css::graphic::XPrimitive2DRenderer> xPrimitive2DRenderer = css::graphic::Primitive2DTools::create(xContext);
|
|
|
|
const css::uno::Reference<css::rendering::XBitmap> xBitmap(
|
|
|
|
xPrimitive2DRenderer->rasterize(aPrimitiveSequence, aViewParameters, nDPI, nDPI, aRealRect, 256*256));
|
|
|
|
|
|
|
|
if (xBitmap.is())
|
|
|
|
{
|
|
|
|
const css::uno::Reference<css::rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
if (xIntBmp.is())
|
|
|
|
{
|
|
|
|
rBitmapEx = vcl::unotools::bitmapExFromXBitmap(xIntBmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|