Bump version to 6.4-15
[LibreOffice.git] / include / vcl / vectorgraphicdata.hxx
blobe671a17a26e08e853cf6b2349d33e12905747e02
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_VCL_VECTORGRAPHICDATA_HXX
21 #define INCLUDED_VCL_VECTORGRAPHICDATA_HXX
23 #include <basegfx/range/b2drange.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <vcl/bitmapex.hxx>
26 #include <rtl/ustring.hxx>
27 #include <deque>
28 #include <memory>
29 #include <algorithm>
31 namespace com { namespace sun { namespace star { namespace graphic { class XPrimitive2D; } } } }
32 struct WmfExternal;
34 typedef css::uno::Sequence<sal_Int8> VectorGraphicDataArray;
37 // helper to convert any Primitive2DSequence to a good quality BitmapEx,
38 // using default parameters and graphic::XPrimitive2DRenderer
40 BitmapEx VCL_DLLPUBLIC convertPrimitive2DSequenceToBitmapEx(
41 const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > >& rSequence,
42 const basegfx::B2DRange& rTargetRange,
43 const sal_uInt32 nMaximumQuadraticPixels = 500000);
46 enum class VectorGraphicDataType
48 Svg = 0,
49 Emf = 1,
50 Wmf = 2,
51 Pdf = 3
54 class VCL_DLLPUBLIC VectorGraphicData
56 private:
57 // the file and length
58 VectorGraphicDataArray maVectorGraphicDataArray;
60 // The absolute Path if available
61 OUString const maPath;
63 // on demand created content
64 bool mbSequenceCreated;
65 basegfx::B2DRange maRange;
66 std::deque< css::uno::Reference< css::graphic::XPrimitive2D > > maSequence;
67 BitmapEx maReplacement;
68 size_t mNestedBitmapSize;
69 VectorGraphicDataType const meVectorGraphicDataType;
71 // extra:
72 std::unique_ptr<WmfExternal> mpExternalHeader;
74 // If the vector format has more pages this denotes which page to render
75 sal_Int32 mnPageIndex;
77 /// Useful for PDF, which is vector-based, but still rendered to a bitmap.
78 basegfx::B2DTuple maSizeHint;
80 // on demand creators
81 void ensurePdfReplacement();
82 void ensureReplacement();
83 void ensureSequenceAndRange();
85 VectorGraphicData(const VectorGraphicData&) = delete;
86 VectorGraphicData& operator=(const VectorGraphicData&) = delete;
88 public:
89 VectorGraphicData(
90 const VectorGraphicDataArray& rVectorGraphicDataArray,
91 const OUString& rPath,
92 VectorGraphicDataType eVectorDataType,
93 sal_Int32 nPageIndex = -1);
94 VectorGraphicData(const OUString& rPath, VectorGraphicDataType eVectorDataType);
95 ~VectorGraphicData();
97 /// compare op
98 bool operator==(const VectorGraphicData& rCandidate) const;
100 /// special: needed for emf/wmf, maybe replaced by scaling the result later (?)
101 void setWmfExternalHeader(const WmfExternal& aExtHeader);
103 /// data read
104 const VectorGraphicDataArray& getVectorGraphicDataArray() const { return maVectorGraphicDataArray; }
105 sal_uInt32 getVectorGraphicDataArrayLength() const { return maVectorGraphicDataArray.getLength(); }
106 enum class State { UNPARSED, PARSED };
107 std::pair<State, size_t> getSizeBytes() const;
108 const OUString& getPath() const { return maPath; }
109 const VectorGraphicDataType& getVectorGraphicDataType() const { return meVectorGraphicDataType; }
111 /// data read and evtl. on demand creation
112 const basegfx::B2DRange& getRange() const;
113 const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > >& getPrimitive2DSequence() const;
114 const BitmapEx& getReplacement() const;
115 BitmapChecksum GetChecksum() const;
117 sal_Int32 getPageIndex() const { return std::max(sal_Int32(0), mnPageIndex); }
119 void setPageIndex(sal_Int32 nPageIndex)
121 mnPageIndex = nPageIndex;
124 void setSizeHint(const basegfx::B2DTuple& rSizeHint)
126 maSizeHint = rSizeHint;
129 const basegfx::B2DTuple& getSizeHint() const { return maSizeHint; }
131 bool isPrimitiveSequenceCreated() const { return mbSequenceCreated; }
134 typedef std::shared_ptr< VectorGraphicData > VectorGraphicDataPtr;
136 #endif // INCLUDED_VCL_VECTORGRAPHICDATA_HXX
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */