LibreOffice Module vcl (master)  1
vectorgraphicdata.hxx
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 #ifndef INCLUDED_VCL_VECTORGRAPHICDATA_HXX
21 #define INCLUDED_VCL_VECTORGRAPHICDATA_HXX
22 
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <vcl/bitmapex.hxx>
27 #include <rtl/ustring.hxx>
28 #include <deque>
29 #include <memory>
30 #include <algorithm>
31 #include <optional>
32 
33 namespace com::sun::star::graphic { class XPrimitive2D; }
34 struct WmfExternal;
35 
36 typedef css::uno::Sequence<sal_Int8> VectorGraphicDataArray;
37 
38 
39 // helper to convert any Primitive2DSequence to a good quality BitmapEx,
40 // using default parameters and graphic::XPrimitive2DRenderer
41 
43  const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > >& rSequence,
44  const basegfx::B2DRange& rTargetRange,
45  const sal_uInt32 nMaximumQuadraticPixels = 500000,
46  const o3tl::Length eTargetUnit = o3tl::Length::mm100,
47  const std::optional<Size>& rTargetDPI = std::nullopt);
48 
49 
51 {
52  Svg = 0,
53  Emf = 1,
54  Wmf = 2,
55  Pdf = 3
56 };
57 
59 {
60 private:
61  // the file and length
63 
64  // on demand created content
67  std::deque< css::uno::Reference< css::graphic::XPrimitive2D > > maSequence;
71 
72  // extra:
73  std::unique_ptr<WmfExternal> mpExternalHeader;
74 
76  sal_Int32 mnPageIndex;
77 
80 
81  bool mbEnableEMFPlus = true;
82 
83  // on demand creators
84  void ensurePdfReplacement();
85  void ensureReplacement();
86  void ensureSequenceAndRange();
87 
88  VectorGraphicData(const VectorGraphicData&) = delete;
89  VectorGraphicData& operator=(const VectorGraphicData&) = delete;
90 
91 public:
92  VectorGraphicData(const OUString& rPath, VectorGraphicDataType eVectorDataType);
94  const BinaryDataContainer& rDataContainer,
95  VectorGraphicDataType eVectorDataType,
96  sal_Int32 nPageIndex = -1);
98 
100  bool operator==(const VectorGraphicData& rCandidate) const;
101 
103  void setWmfExternalHeader(const WmfExternal& aExtHeader);
104 
107  {
108  return maDataContainer;
109  }
110 
111  enum class State { UNPARSED, PARSED };
112  std::pair<State, size_t> getSizeBytes() const;
113 
114  const VectorGraphicDataType& getType() const { return meType; }
115 
117  const basegfx::B2DRange& getRange() const;
118  const std::deque<css::uno::Reference<css::graphic::XPrimitive2D>>& getPrimitive2DSequence() const;
119  const BitmapEx& getReplacement() const;
120  BitmapChecksum GetChecksum() const;
121 
122  sal_Int32 getPageIndex() const
123  {
124  return std::max(sal_Int32(0), mnPageIndex);
125  }
126 
127  void setPageIndex(sal_Int32 nPageIndex)
128  {
129  mnPageIndex = nPageIndex;
130  }
131 
132  void setSizeHint(const basegfx::B2DTuple& rSizeHint)
133  {
134  maSizeHint = rSizeHint;
135  }
136 
137  const basegfx::B2DTuple& getSizeHint() const { return maSizeHint; }
138 
139  void setEnableEMFPlus(bool bEnableEMFPlus) { mbEnableEMFPlus = bEnableEMFPlus; }
140 
141  bool isPrimitiveSequenceCreated() const { return mbSequenceCreated; }
142 };
143 
144 #endif // INCLUDED_VCL_VECTORGRAPHICDATA_HXX
145 
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VectorGraphicDataType
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
sal_Int32 mnPageIndex
If the vector format has more pages this denotes which page to render.
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
basegfx::B2DTuple maSizeHint
Useful for PDF, which is vector-based, but still rendered to a bitmap.
const BinaryDataContainer & getBinaryDataContainer() const
data read
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
void setSizeHint(const basegfx::B2DTuple &rSizeHint)
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:202
basegfx::B2DRange maRange
bool isPrimitiveSequenceCreated() const
sal_Int32 getPageIndex() const
B2DRange getRange(const B2DPolygon &rCandidate)
void setPageIndex(sal_Int32 nPageIndex)
css::uno::Sequence< sal_Int8 > VectorGraphicDataArray
std::unique_ptr< WmfExternal > mpExternalHeader
BitmapEx VCL_DLLPUBLIC convertPrimitive2DSequenceToBitmapEx(const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > > &rSequence, const basegfx::B2DRange &rTargetRange, const sal_uInt32 nMaximumQuadraticPixels=500000, const o3tl::Length eTargetUnit=o3tl::Length::mm100, const std::optional< Size > &rTargetDPI=std::nullopt)
VectorGraphicDataType meType
void setEnableEMFPlus(bool bEnableEMFPlus)
const basegfx::B2DTuple & getSizeHint() const
const VectorGraphicDataType & getType() const
std::deque< css::uno::Reference< css::graphic::XPrimitive2D > > maSequence
BinaryDataContainer maDataContainer