LibreOffice Module xmloff (master) 1
MarkerStyle.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 <memory>
22#include <xexptran.hxx>
24#include <xmloff/xmluconv.hxx>
26#include <xmloff/xmltoken.hxx>
27#include <xmloff/xmlexp.hxx>
28#include <xmloff/xmlimp.hxx>
29#include <sal/log.hxx>
30#include <rtl/ustring.hxx>
31#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
35
36using namespace ::com::sun::star;
37
38using namespace ::xmloff::token;
39
40// Import
41
43 : m_rImport( rImp )
44{
45}
46
48 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
49 uno::Any& rValue,
50 OUString& rStrName )
51{
52 bool bHasViewBox = false;
53 bool bHasPathData = false;
54 OUString aDisplayName;
55
56 std::unique_ptr<SdXMLImExViewBox> xViewBox;
57
58 SvXMLUnitConverter& rUnitConverter = m_rImport.GetMM100UnitConverter();
59
60 OUString strPathData;
61
62 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
63 {
64 OUString aStrValue = aIter.toString();
65
66 switch (aIter.getToken() & TOKEN_MASK)
67 {
68 case XML_NAME:
69 rStrName = aStrValue;
70 break;
72 aDisplayName = aStrValue;
73 break;
74 case XML_VIEWBOX:
75 xViewBox.reset(new SdXMLImExViewBox(aStrValue, rUnitConverter));
76 bHasViewBox = true;
77 break;
78 case XML_D:
79 strPathData = aStrValue;
80 bHasPathData = true;
81 break;
82 default:
83 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter);
84 }
85 }
86
87 if( bHasViewBox && bHasPathData )
88 {
89 basegfx::B2DPolyPolygon aPolyPolygon;
90
91 if(basegfx::utils::importFromSvgD(aPolyPolygon, strPathData, m_rImport.needFixPositionAfterZ(), nullptr))
92 {
93 if(aPolyPolygon.count())
94 {
95 // ViewBox probably not used, but stay with former processing inside of
96 // SdXMLImExSvgDElement
97 const basegfx::B2DRange aSourceRange(
98 xViewBox->GetX(), xViewBox->GetY(),
99 xViewBox->GetX() + xViewBox->GetWidth(),
100 xViewBox->GetY() + xViewBox->GetHeight());
101 const basegfx::B2DRange aTargetRange(
102 0.0, 0.0,
103 xViewBox->GetWidth(), xViewBox->GetHeight());
104
105 if(!aSourceRange.equal(aTargetRange))
106 {
107 aPolyPolygon.transform(
109 aSourceRange,
110 aTargetRange));
111 }
112
113 // always use PolyPolygonBezierCoords here
114 drawing::PolyPolygonBezierCoords aSourcePolyPolygon;
115
117 aPolyPolygon,
118 aSourcePolyPolygon);
119 rValue <<= aSourcePolyPolygon;
120 }
121 }
122
123 if( !aDisplayName.isEmpty() )
124 {
125 m_rImport.AddStyleDisplayName( XmlStyleFamily::SD_MARKER_ID, rStrName,
126 aDisplayName );
127 rStrName = aDisplayName;
128 }
129 }
130
131 xViewBox.reset();
132}
133
134// Export
135
137 : m_rExport( rExp )
138{
139}
140
142 const OUString& rStrName,
143 const uno::Any& rValue )
144{
145 if(rStrName.isEmpty())
146 return;
147
148 drawing::PolyPolygonBezierCoords aBezier;
149
150 if(!(rValue >>= aBezier))
151 return;
152
153 // Name
154 bool bEncoded(false);
155
157
158 if( bEncoded )
159 {
161 }
162
163 const basegfx::B2DPolyPolygon aPolyPolygon(
165 aBezier));
166 const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange());
167
168
169 // Viewbox (viewBox="0 0 1500 1000")
170
171 SdXMLImExViewBox aViewBox(
172 aPolyPolygonRange.getMinX(),
173 aPolyPolygonRange.getMinY(),
174 aPolyPolygonRange.getWidth(),
175 aPolyPolygonRange.getHeight());
177
178 // Pathdata
179 const OUString aPolygonString(
181 aPolyPolygon,
182 true, // bUseRelativeCoordinates
183 false, // bDetectQuadraticBeziers: not used in old, but maybe activated now
184 true)); // bHandleRelativeNextPointCompatible
185
186 // write point array
188
189 // Do Write
191}
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SvXMLImport & m_rImport
const OUString & GetExportString()
Definition: xexptran.cxx:1034
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmlexp.cxx:1934
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
void exportXML(const OUString &rStrName, const css::uno::Any &rValue)
SvXMLExport & m_rExport
Definition: MarkerStyle.hxx:51
XMLMarkerStyleExport(SvXMLExport &rExport)
void importXML(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Any &rValue, OUString &rStrName)
Definition: MarkerStyle.cxx:47
XMLMarkerStyleImport(SvXMLImport &rImport)
Definition: MarkerStyle.cxx:42
SvXMLImport & m_rImport
Definition: MarkerStyle.hxx:38
void transform(const basegfx::B2DHomMatrix &rMatrix)
B2DRange getB2DRange() const
sal_uInt32 count() const
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
bool equal(const Range2D &rRange) const
TYPE getHeight() const
OUString exportToSvgD(const B2DPolyPolygon &rPolyPoly, bool bUseRelativeCoordinates, bool bDetectQuadraticBeziers, bool bHandleRelativeNextPointCompatible, bool bOOXMLMotionPath=false)
bool importFromSvgD(B2DPolyPolygon &o_rPolyPoly, std::u16string_view rSvgDAttribute, bool bHandleRelativeNextPointCompatible, PointIndexSet *pHelpPointIndexSet)
void B2DPolyPolygonToUnoPolyPolygonBezierCoords(const B2DPolyPolygon &rPolyPolygon, css::drawing::PolyPolygonBezierCoords &rPolyPolygonBezierCoordsRetval)
B2DHomMatrix createSourceRangeTargetRangeTransform(const B2DRange &rSourceRange, const B2DRange &rTargetRange)
B2DPolyPolygon UnoPolyPolygonBezierCoordsToB2DPolyPolygon(const css::drawing::PolyPolygonBezierCoords &rPolyPolygonBezierCoordsSource)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_SVG