cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / include / vcl / vectorgraphicdata.hxx
blobc10b068e384a43c3110676560d9c0fee13488283
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 <vcl/bitmapex.hxx>
25 #include <vcl/BinaryDataContainer.hxx>
26 #include <rtl/ustring.hxx>
27 #include <deque>
28 #include <algorithm>
29 #include <optional>
31 namespace com::sun::star::graphic { class XPrimitive2D; }
34 // helper to convert any Primitive2DSequence to a good quality BitmapEx,
35 // using default parameters and graphic::XPrimitive2DRenderer
37 BitmapEx VCL_DLLPUBLIC convertPrimitive2DSequenceToBitmapEx(
38 const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > >& rSequence,
39 const basegfx::B2DRange& rTargetRange,
40 const sal_uInt32 nMaximumQuadraticPixels = 500000,
41 const o3tl::Length eTargetUnit = o3tl::Length::mm100,
42 const std::optional<Size>& rTargetDPI = std::nullopt);
45 enum class VectorGraphicDataType
47 Svg = 0,
48 Emf = 1,
49 Wmf = 2,
50 Pdf = 3
53 class VCL_DLLPUBLIC VectorGraphicData
55 private:
56 // the file and length
57 BinaryDataContainer maDataContainer;
59 // on demand created content
60 bool mbSequenceCreated;
61 basegfx::B2DRange maRange;
62 std::deque< css::uno::Reference< css::graphic::XPrimitive2D > > maSequence;
63 BitmapEx maReplacement;
64 size_t mNestedBitmapSize;
65 VectorGraphicDataType meType;
67 /// If the vector format has more pages this denotes which page to render
68 sal_Int32 mnPageIndex;
70 /// Useful for PDF, which is vector-based, but still rendered to a bitmap.
71 basegfx::B2DTuple maSizeHint;
73 bool mbEnableEMFPlus = true;
75 // on demand creators
76 void ensurePdfReplacement();
77 void ensureReplacement();
78 void ensureSequenceAndRange();
80 VectorGraphicData(const VectorGraphicData&) = delete;
81 VectorGraphicData& operator=(const VectorGraphicData&) = delete;
83 public:
84 VectorGraphicData(const OUString& rPath, VectorGraphicDataType eVectorDataType);
85 VectorGraphicData(
86 BinaryDataContainer aDataContainer,
87 VectorGraphicDataType eVectorDataType,
88 sal_Int32 nPageIndex = -1);
89 ~VectorGraphicData();
91 /// compare op
92 bool operator==(const VectorGraphicData& rCandidate) const;
94 /// data read
95 const BinaryDataContainer& getBinaryDataContainer() const
97 return maDataContainer;
100 enum class State { UNPARSED, PARSED };
101 std::pair<State, size_t> getSizeBytes() const;
103 const VectorGraphicDataType& getType() const { return meType; }
105 /// data read and evtl. on demand creation
106 const basegfx::B2DRange& getRange() const;
107 const std::deque<css::uno::Reference<css::graphic::XPrimitive2D>>& getPrimitive2DSequence() const;
108 BitmapEx getBitmap(const Size& pixelSize) const;
109 const BitmapEx& getReplacement() const;
110 BitmapChecksum GetChecksum() const;
112 sal_Int32 getPageIndex() const
114 return std::max(sal_Int32(0), mnPageIndex);
117 void setPageIndex(sal_Int32 nPageIndex)
119 mnPageIndex = nPageIndex;
122 void setSizeHint(const basegfx::B2DTuple& rSizeHint)
124 maSizeHint = rSizeHint;
127 const basegfx::B2DTuple& getSizeHint() const { return maSizeHint; }
129 void setEnableEMFPlus(bool bEnableEMFPlus) { mbEnableEMFPlus = bEnableEMFPlus; }
131 bool isPrimitiveSequenceCreated() const { return mbSequenceCreated; }
134 #endif // INCLUDED_VCL_VECTORGRAPHICDATA_HXX
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */