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