LibreOffice Module svgio (master) 1
svgfeimagenode.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
21#include <vcl/graphicfilter.hxx>
23#include <svgfeimagenode.hxx>
24#include <o3tl/string_view.hxx>
25#include <svgdocument.hxx>
26#include <comphelper/base64.hxx>
27#include <tools/stream.hxx>
28#include <rtl/uri.hxx>
29
30namespace svgio::svgreader
31{
33 : SvgFilterNode(SVGToken::FeImage, rDocument, pParent)
34{
35}
36
38
39void SvgFeImageNode::parseAttribute(const OUString& /*rTokenName*/, SVGToken aSVGToken,
40 const OUString& aContent)
41{
42 // parse own
43 switch (aSVGToken)
44 {
45 case SVGToken::Style:
46 {
47 readLocalCssStyle(aContent);
48 break;
49 }
50 case SVGToken::Href:
52 {
53 const sal_Int32 nLen(aContent.getLength());
54
55 if (nLen)
56 {
57 OUString aXLink;
58 readImageLink(aContent, aXLink, maUrl, maData);
59 }
60 break;
61 }
62
63 default:
64 {
65 break;
66 }
67 }
68}
69
71{
72 BitmapEx aBitmapEx;
73
74 if (!maData.isEmpty())
75 {
76 // use embedded base64 encoded data
77 css::uno::Sequence<sal_Int8> aPass;
79
80 if (aPass.hasElements())
81 {
82 SvMemoryStream aStream(aPass.getArray(), aPass.getLength(), StreamMode::READ);
83 Graphic aGraphic;
84
85 if (ERRCODE_NONE
86 == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, u"", aStream))
87 {
88 aBitmapEx = aGraphic.GetBitmapEx();
89 }
90 }
91 }
92 else if (!maUrl.isEmpty())
93 {
94 const OUString& rPath = getDocument().getAbsolutePath();
95 OUString aAbsUrl;
96 try
97 {
98 aAbsUrl = rtl::Uri::convertRelToAbs(rPath, maUrl);
99 }
100 catch (rtl::MalformedUriException& e)
101 {
102 SAL_WARN("svg", "caught rtl::MalformedUriException \"" << e.getMessage() << "\"");
103 }
104
105 if (!aAbsUrl.isEmpty() && rPath != aAbsUrl)
106 {
107 SvFileStream aStream(aAbsUrl, StreamMode::STD_READ);
108 Graphic aGraphic;
109
110 if (ERRCODE_NONE
111 == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aAbsUrl, aStream))
112 {
113 aBitmapEx = aGraphic.GetBitmapEx();
114 }
115 }
116 }
117
118 if (!aBitmapEx.IsEmpty() && 0 != aBitmapEx.GetSizePixel().Width()
119 && 0 != aBitmapEx.GetSizePixel().Height())
120 {
121 basegfx::B2DRange aViewBox
126 aViewBox.getRange(), aViewBox.getMinimum())));
127
129 }
130}
131
132} // end of namespace svgio::svgreader
133
134/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsEmpty() const
const Size & GetSizePixel() const
static GraphicFilter & GetGraphicFilter()
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
B2DVector getRange() const
B2DPoint getMinimum() const
static void decode(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
const OUString & getAbsolutePath() const
Definition: svgdocument.hxx:77
void apply(drawinglayer::primitive2d::Primitive2DContainer &rTarget) const override
SvgFeImageNode(SvgDocument &rDocument, SvgNode *pParent)
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
void readLocalCssStyle(std::u16string_view aContent)
scan helper to read and interpret a local CssStyle to mpLocalCssStyle
Definition: svgnode.cxx:412
const SvgDocument & getDocument() const
Definition: svgnode.hxx:157
float u
#define ERRCODE_NONE
FilterGroup & rTarget
#define SAL_WARN(area, stream)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
void readImageLink(const OUString &rCandidate, OUString &rXLink, OUString &rUrl, OUString &rData)
Definition: svgtools.cxx:1346