1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/BinaryDataContainer.hxx>
27 #include <rtl/ustring.hxx>
33 namespace com::sun::star::graphic
{ class XPrimitive2D
; }
36 // helper to convert any Primitive2DSequence to a good quality BitmapEx,
37 // using default parameters and graphic::XPrimitive2DRenderer
39 BitmapEx VCL_DLLPUBLIC
convertPrimitive2DSequenceToBitmapEx(
40 const std::deque
< css::uno::Reference
< css::graphic::XPrimitive2D
> >& rSequence
,
41 const basegfx::B2DRange
& rTargetRange
,
42 const sal_uInt32 nMaximumQuadraticPixels
= 500000,
43 const o3tl::Length eTargetUnit
= o3tl::Length::mm100
,
44 const std::optional
<Size
>& rTargetDPI
= std::nullopt
);
47 enum class VectorGraphicDataType
55 class VCL_DLLPUBLIC VectorGraphicData
58 // the file and length
59 BinaryDataContainer maDataContainer
;
61 // on demand created content
62 bool mbSequenceCreated
;
63 basegfx::B2DRange maRange
;
64 std::deque
< css::uno::Reference
< css::graphic::XPrimitive2D
> > maSequence
;
65 BitmapEx maReplacement
;
66 size_t mNestedBitmapSize
;
67 VectorGraphicDataType meType
;
69 /// If the vector format has more pages this denotes which page to render
70 sal_Int32 mnPageIndex
;
72 /// Useful for PDF, which is vector-based, but still rendered to a bitmap.
73 basegfx::B2DTuple maSizeHint
;
75 bool mbEnableEMFPlus
= true;
78 void ensurePdfReplacement();
79 void ensureReplacement();
80 void ensureSequenceAndRange();
82 VectorGraphicData(const VectorGraphicData
&) = delete;
83 VectorGraphicData
& operator=(const VectorGraphicData
&) = delete;
86 VectorGraphicData(const OUString
& rPath
, VectorGraphicDataType eVectorDataType
);
88 BinaryDataContainer aDataContainer
,
89 VectorGraphicDataType eVectorDataType
,
90 sal_Int32 nPageIndex
= -1);
94 bool operator==(const VectorGraphicData
& rCandidate
) const;
97 const BinaryDataContainer
& getBinaryDataContainer() const
99 return maDataContainer
;
102 enum class State
{ UNPARSED
, PARSED
};
103 std::pair
<State
, size_t> getSizeBytes() const;
105 const VectorGraphicDataType
& getType() const { return meType
; }
107 /// data read and evtl. on demand creation
108 const basegfx::B2DRange
& getRange() const;
109 const std::deque
<css::uno::Reference
<css::graphic::XPrimitive2D
>>& getPrimitive2DSequence() const;
110 const BitmapEx
& getReplacement() const;
111 BitmapChecksum
GetChecksum() const;
113 sal_Int32
getPageIndex() const
115 return std::max(sal_Int32(0), mnPageIndex
);
118 void setPageIndex(sal_Int32 nPageIndex
)
120 mnPageIndex
= nPageIndex
;
123 void setSizeHint(const basegfx::B2DTuple
& rSizeHint
)
125 maSizeHint
= rSizeHint
;
128 const basegfx::B2DTuple
& getSizeHint() const { return maSizeHint
; }
130 void setEnableEMFPlus(bool bEnableEMFPlus
) { mbEnableEMFPlus
= bEnableEMFPlus
; }
132 bool isPrimitiveSequenceCreated() const { return mbSequenceCreated
; }
135 #endif // INCLUDED_VCL_VECTORGRAPHICDATA_HXX
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */