Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fixed_size_data_vector.h
Go to the documentation of this file.
1// Copyright 2022 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CORE_FXCRT_FIXED_SIZE_DATA_VECTOR_H_
6#define CORE_FXCRT_FIXED_SIZE_DATA_VECTOR_H_
7
8#include <stddef.h>
9
10#include <memory>
11#include <utility>
12
13#include "core/fxcrt/fx_memory_wrappers.h"
14#include "third_party/base/containers/span.h"
15
16namespace fxcrt {
17
18// A simple data container that has a fixed size.
19// Unlike std::vector, it cannot be implicitly copied and its data is only
20// accessible using spans.
21// It can either initialize its data with zeros, or leave its data
22// uninitialized.
23template <typename T>
25 public:
27
28 // Allocates a vector of the given size with uninitialized memory.
29 // A CHECK() failure occurs when insufficient memory.
30 static FixedSizeDataVector Uninit(size_t size) {
31 if (size == 0) {
32 return FixedSizeDataVector();
33 }
34 return FixedSizeDataVector(FX_AllocUninit(T, size), size);
35 }
36
37 // Allocates a vector of the given size with zeroed memory.
38 // A CHECK() failure occurs when insufficient memory.
39 static FixedSizeDataVector Zeroed(size_t size) {
40 if (size == 0) {
41 return FixedSizeDataVector();
42 }
43 return FixedSizeDataVector(FX_Alloc(T, size), size);
44 }
45
46 // Same as above, but return an empty vector when insufficient memory.
47 static FixedSizeDataVector TryZeroed(size_t size) {
48 if (size == 0) {
49 return FixedSizeDataVector();
50 }
51 T* ptr = FX_TryAlloc(T, size);
52 return FixedSizeDataVector(ptr, ptr ? size : 0u);
53 }
54
57
59 : data_(std::move(that.data_)), size_(std::exchange(that.size_, 0)) {}
60
62 data_ = std::move(that.data_);
63 size_ = std::exchange(that.size_, 0);
64 return *this;
65 }
66
67 ~FixedSizeDataVector() = default;
68
69 bool empty() const { return size_ == 0; }
70 size_t size() const { return size_; }
71
72 // Implicit access to data via span.
73 operator pdfium::span<T>() { return span(); }
74 operator pdfium::span<const T>() const { return span(); }
75
76 // Explicit access to data via span.
77 pdfium::span<T> span() { return pdfium::span<T>(data_.get(), size_); }
78 pdfium::span<const T> span() const {
79 return pdfium::span<const T>(data_.get(), size_);
80 }
81
82 // Convenience methods to slice the vector into spans.
83 pdfium::span<T> subspan(size_t offset,
84 size_t count = pdfium::dynamic_extent) {
85 return span().subspan(offset, count);
86 }
87 pdfium::span<const T> subspan(size_t offset,
88 size_t count = pdfium::dynamic_extent) const {
89 return span().subspan(offset, count);
90 }
91
92 pdfium::span<T> first(size_t count) { return span().first(count); }
93 pdfium::span<const T> first(size_t count) const {
94 return span().first(count);
95 }
96
97 pdfium::span<T> last(size_t count) { return span().last(count); }
98 pdfium::span<const T> last(size_t count) const { return span().last(count); }
99
100 private:
101 FixedSizeDataVector(T* ptr, size_t size) : data_(ptr), size_(size) {}
102
103 std::unique_ptr<T, FxFreeDeleter> data_;
104 size_t size_ = 0;
105};
106
107} // namespace fxcrt
108
109using fxcrt::FixedSizeDataVector;
110
111#endif // CORE_FXCRT_FIXED_SIZE_DATA_VECTOR_H_
CFX_FloatRect(const FX_RECT &rect)
FX_RECT GetOuterRect() const
static constexpr uint32_t MakeTag(char c1, char c2, char c3, char c4)
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
~CPDF_CIDFont() override
size_t CountChar(ByteStringView pString) const override
uint32_t GetNextChar(ByteStringView pString, size_t *pOffset) const override
bool IsCIDFont() const override
const uint8_t * GetCIDTransform(uint16_t cid) const
bool IsUnicodeCompatible() const override
int AppendChar(char *str, uint32_t charcode) const override
CFX_Point16 GetVertOrigin(uint16_t cid) const
int GetCharWidthF(uint32_t charcode) override
const CPDF_CIDFont * AsCIDFont() const override
uint16_t CIDFromCharCode(uint32_t charcode) const
bool Load() override
int GlyphFromCharCode(uint32_t charcode, bool *pVertGlyph) override
int16_t GetVertWidth(uint16_t cid) const
FX_RECT GetCharBBox(uint32_t charcode) override
static float CIDTransformToFloat(uint8_t ch)
bool IsVertWriting() const override
uint32_t CharCodeFromUnicode(wchar_t Unicode) const override
int GetCharSize(uint32_t charcode) const
WideString UnicodeFromCharCode(uint32_t charcode) const override
CPDF_CIDFont * AsCIDFont() override
static CIDSet CharsetFromOrdering(ByteStringView ordering)
bool IsVertWriting() const
Definition cpdf_cmap.h:61
void SetVertical(bool vert)
Definition cpdf_cmap.h:70
~CPDF_CMap() override
static constexpr size_t kDirectMapTableSize
Definition cpdf_cmap.h:37
CIDCoding GetCoding() const
Definition cpdf_cmap.h:75
size_t CountChar(ByteStringView pString) const
uint32_t GetNextChar(ByteStringView pString, size_t *pOffset) const
int AppendChar(char *str, uint32_t charcode) const
void SetCharset(CIDSet set)
Definition cpdf_cmap.h:78
bool IsLoaded() const
Definition cpdf_cmap.h:60
@ MixedTwoBytes
Definition cpdf_cmap.h:42
@ MixedFourBytes
Definition cpdf_cmap.h:43
const fxcmap::CMap * GetEmbedMap() const
Definition cpdf_cmap.h:76
uint16_t CIDFromCharCode(uint32_t charcode) const
void SetAdditionalMappings(std::vector< CIDRange > mappings)
int GetCharSize(uint32_t charcode) const
bool IsDirectCharcodeToCIDTableIsEmpty() const
Definition cpdf_cmap.h:83
void SetMixedFourByteLeadingRanges(std::vector< CodeRange > ranges)
CIDSet GetCharset() const
Definition cpdf_cmap.h:77
void SetDirectCharcodeToCIDTableRange(uint32_t start_code, uint32_t end_code, uint16_t start_cid)
void SetCodingScheme(CodingScheme scheme)
Definition cpdf_cmap.h:71
static CPDF_FontGlobals * GetInstance()
void LoadFontDescriptor(const CPDF_Dictionary *pFontDesc)
virtual uint32_t CharCodeFromUnicode(wchar_t Unicode) const
static bool UseTTCharmapMacRoman(const RetainPtr< CFX_Face > &face)
Definition cpdf_font.h:152
static bool UseTTCharmapMSUnicode(const RetainPtr< CFX_Face > &face)
Definition cpdf_font.h:146
virtual WideString UnicodeFromCharCode(uint32_t charcode) const
static FX_RECT GetCharBBoxForFace(const RetainPtr< CFX_Face > &face)
void CheckFontMetrics()
bool IsEmbedded() const
Definition cpdf_font.h:101
bool operator==(const char *ptr) const
pdfium::span< T > last(size_t count)
pdfium::span< const T > subspan(size_t offset, size_t count=pdfium::dynamic_extent) const
static FixedSizeDataVector Uninit(size_t size)
operator pdfium::span< const T >() const
pdfium::span< const T > first(size_t count) const
FixedSizeDataVector(FixedSizeDataVector< T > &&that) noexcept
FixedSizeDataVector(const FixedSizeDataVector &)=delete
pdfium::span< T > first(size_t count)
static FixedSizeDataVector TryZeroed(size_t size)
static FixedSizeDataVector Zeroed(size_t size)
pdfium::span< const T > last(size_t count) const
FixedSizeDataVector & operator=(const FixedSizeDataVector &)=delete
pdfium::span< T > subspan(size_t offset, size_t count=pdfium::dynamic_extent)
FixedSizeDataVector & operator=(FixedSizeDataVector< T > &&that) noexcept
WideString(wchar_t ch)
CharType operator[](const size_t index) const
Definition widestring.h:146
bool IsEmpty() const
Definition widestring.h:118
CIDSet
@ CIDSET_JAPAN1
@ CIDSET_UNKNOWN
@ CIDSET_GB1
@ CIDSET_NUM_SETS
CIDCoding
Definition cpdf_cmap.h:24
uint32_t CharCodeFromUnicodeForEncoding(fxge::FontEncoding encoding, wchar_t unicode)
FontEncoding
FX_CodePage
Definition fx_codepage.h:18
wchar_t UnicodeFromAdobeName(const char *name)
Definition fx_font.cpp:138
#define FXFONT_FW_NORMAL
Definition fx_font.h:22
constexpr wchar_t kBoxDrawingsLightVerical
Definition fx_unicode.h:102
#define CONSTRUCT_VIA_MAKE_RETAIN
Definition retain_ptr.h:224
uint16_t m_StartCID
Definition cpdf_cmap.h:55
uint32_t m_StartCode
Definition cpdf_cmap.h:53
uint8_t m_Lower[4]
Definition cpdf_cmap.h:48
uint8_t m_Upper[4]
Definition cpdf_cmap.h:49
FX_RECT & operator=(const FX_RECT &that)=default
int32_t bottom
int32_t right
int32_t top
constexpr FX_RECT(int l, int t, int r, int b)