Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / oox / export / vmlexport.hxx
blob97084b827559bfce7a7fadf14529d85a8a3ef873
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 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_EXPORT_VMLEXPORT_HXX
21 #define INCLUDED_OOX_EXPORT_VMLEXPORT_HXX
23 #include <sal/config.h>
25 #include <string_view>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <editeng/outlobj.hxx>
29 #include <filter/msfilter/escherex.hxx>
30 #include <oox/dllapi.h>
31 #include <rtl/strbuf.hxx>
32 #include <rtl/string.hxx>
33 #include <rtl/ustring.hxx>
34 #include <sal/types.h>
35 #include <sax/fshelper.hxx>
36 #include <rtl/ref.hxx>
38 namespace com::sun::star {
39 namespace drawing {
40 class XShape;
44 namespace oox::drawingml {
45 class DrawingML;
49 namespace sax_fastparser {
50 class FastAttributeList;
53 class Point;
54 namespace tools { class Rectangle; }
55 class SdrObject;
57 namespace oox::vml {
59 /// Interface to be implemented by the parent exporter that knows how to handle shape text.
60 class OOX_DLLPUBLIC VMLTextExport
62 public:
63 virtual void WriteOutliner(const OutlinerParaObject& rParaObj) = 0;
64 virtual oox::drawingml::DrawingML& GetDrawingML() = 0;
65 /// Write the contents of the textbox that is associated to this shape in VML format.
66 virtual void WriteVMLTextBox(css::uno::Reference<css::drawing::XShape> xShape) = 0;
67 protected:
68 VMLTextExport() {}
69 virtual ~VMLTextExport() {}
72 class OOX_DLLPUBLIC VMLExport : public EscherEx
74 /// Fast serializer to output the data
75 ::sax_fastparser::FSHelperPtr m_pSerializer;
77 /// Parent exporter, used for text callback.
78 VMLTextExport* m_pTextExport;
80 /// Anchoring - Writer specific properties
81 sal_Int16 m_eHOri, m_eVOri, m_eHRel, m_eVRel;
82 rtl::Reference<sax_fastparser::FastAttributeList> m_pWrapAttrList;
83 bool m_bInline; // css::text::TextContentAnchorType_AS_CHARACTER
84 bool m_IsFollowingTextFlow = false;
86 /// The object we're exporting.
87 const SdrObject* m_pSdrObject;
89 /// Fill the shape attributes as they come.
90 rtl::Reference<::sax_fastparser::FastAttributeList> m_pShapeAttrList;
92 /// Remember the shape type.
93 sal_uInt32 m_nShapeType;
95 /// Remember the shape flags.
96 ShapeFlag m_nShapeFlags;
98 /// Remember style, the most important shape attribute ;-)
99 OStringBuffer m_ShapeStyle;
101 /// style for textbox
102 OStringBuffer m_TextboxStyle;
104 /// Remember the generated shape id.
105 OString m_sShapeId;
107 /// Remember which shape types we had already written.
108 std::vector<bool> m_aShapeTypeWritten;
110 /// It seems useless to write out an XML_ID attribute next to XML_id which defines the actual shape id
111 bool m_bSkipwzName;
113 /// Use '#' mark for type attribute (check Type Attribute of VML shape in OOXML documentation)
114 bool m_bUseHashMarkForType;
116 /** There is a shapeid generation mechanism in EscherEx, but it does not seem to work
117 * so override the existing behavior to get actually unique ids.
119 bool m_bOverrideShapeIdGeneration;
121 /// Prefix for overridden shape id generation (used if m_bOverrideShapeIdGeneration is true)
122 OString m_sShapeIDPrefix;
124 /// Counter for generating shape ids (used if m_bOverrideShapeIdGeneration is true)
125 sal_uInt64 m_nShapeIDCounter;
127 public:
128 VMLExport( ::sax_fastparser::FSHelperPtr pSerializer, VMLTextExport* pTextExport = nullptr);
129 virtual ~VMLExport() override;
131 const ::sax_fastparser::FSHelperPtr&
132 GetFS() const { return m_pSerializer; }
134 void SetFS(const ::sax_fastparser::FSHelperPtr& pSerializer);
136 /// Export the sdr object as VML.
138 /// Call this when you need to export the object as VML.
139 OString const & AddSdrObject( const SdrObject& rObj,
140 bool const bIsFollowingTextFlow = false,
141 sal_Int16 eHOri = -1, sal_Int16 eVOri = -1, sal_Int16 eHRel = -1,
142 sal_Int16 eVRel = -1,
143 sax_fastparser::FastAttributeList* pWrapAttrList = nullptr,
144 const bool bOOxmlExport = false, sal_uInt32 nId = 0);
145 OString const & AddInlineSdrObject( const SdrObject& rObj, const bool bOOxmlExport );
146 virtual void AddSdrObjectVMLObject( const SdrObject& rObj) override;
147 static bool IsWaterMarkShape(std::u16string_view rStr);
149 void SetSkipwzName(bool bSkipwzName) { m_bSkipwzName = bSkipwzName; }
150 void SetHashMarkForType(bool bUseHashMarkForType) { m_bUseHashMarkForType = bUseHashMarkForType; }
151 void OverrideShapeIDGen(bool bOverrideShapeIdGeneration,
152 const OString& sShapeIDPrefix = OString());
153 static OString GetVMLShapeTypeDefinition(std::string_view sShapeID, const bool bIsPictureFrame);
155 protected:
156 /// Add an attribute to the generated <v:shape/> element.
158 /// This should be called from within StartShape() to ensure that the
159 /// added attribute is preserved.
160 void AddShapeAttribute(sal_Int32 nAttribute, std::string_view sValue);
162 using EscherEx::StartShape;
163 using EscherEx::EndShape;
165 /// Override shape ID generation when m_bOverrideShapeIdGeneration is set to true
166 virtual sal_uInt32 GenerateShapeId() override;
168 /// Start the shape for which we just collected the information.
170 /// Returns the element's tag number, -1 means we wrote nothing.
171 virtual sal_Int32 StartShape();
173 /// End the shape.
175 /// The parameter is just what we got from StartShape().
176 virtual void EndShape( sal_Int32 nShapeElement );
177 virtual void Commit( EscherPropertyContainer& rProps, const tools::Rectangle& rRect ) override;
179 private:
181 virtual void OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance = 0 ) override;
182 virtual void CloseContainer() override;
184 virtual sal_uInt32 EnterGroup( const OUString& rShapeName, const tools::Rectangle* pBoundRect ) override;
185 virtual void LeaveGroup() override;
187 virtual void AddShape( sal_uInt32 nShapeType, ShapeFlag nShapeFlags, sal_uInt32 nShapeId = 0 ) override;
189 private:
190 /// Create an OString representing the id from a numerical id.
191 OString ShapeIdString( sal_uInt32 nId );
193 /// Add flip X and\or flip Y
194 void AddFlipXY( );
196 /// Add starting and ending point of a line to the m_pShapeAttrList.
197 void AddLineDimensions( const tools::Rectangle& rRectangle );
199 /// Add position and size to the OStringBuffer.
200 void AddRectangleDimensions( OStringBuffer& rBuffer, const tools::Rectangle& rRectangle, bool rbAbsolutePos = true );
204 } // namespace oox::vml
206 #endif
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */