Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPDFUnion.h
Go to the documentation of this file.
1// Copyright 2018 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3#ifndef SkPDFUnion_DEFINED
4#define SkPDFUnion_DEFINED
5
7
8/**
9 A SkPDFUnion is a non-virtualized implementation of the
10 non-compound, non-specialized PDF Object types: Name, String,
11 Number, Boolean.
12 */
14public:
15 // Move constructor and assignment operator destroy the argument
16 // and steal their references (if needed).
19
21
22 /** The following nine functions are the standard way of creating
23 SkPDFUnion objects. */
24
25 static SkPDFUnion Int(int32_t);
26
27 static SkPDFUnion Int(size_t v) { return SkPDFUnion::Int(SkToS32(v)); }
28
29 static SkPDFUnion Bool(bool);
30
32
33 static SkPDFUnion ColorComponent(uint8_t);
34
35 static SkPDFUnion ColorComponentF(float);
36
37 /** These two functions do NOT take ownership of char*, and do NOT
38 copy the string. Suitable for passing in static const
39 strings. For example:
40 SkPDFUnion n = SkPDFUnion::Name("Length");
41 SkPDFUnion u = SkPDFUnion::String("Identity"); */
42
43 /** SkPDFUnion::Name(const char*) assumes that the passed string
44 is already a valid name (that is: it has no control or
45 whitespace characters). This will not copy the name. */
46 static SkPDFUnion Name(const char*);
47
48 /** SkPDFUnion::String will encode the passed string. This will not copy. */
49 static SkPDFUnion ByteString(const char*);
50 static SkPDFUnion TextString(const char*);
51
52 /** SkPDFUnion::Name(SkString) does not assume that the
53 passed string is already a valid name and it will escape the
54 string. */
55 static SkPDFUnion Name(SkString);
56
57 /** SkPDFUnion::String will encode the passed string. */
60
61 static SkPDFUnion Object(std::unique_ptr<SkPDFObject>);
62
64
65 /** These two non-virtual methods mirror SkPDFObject's
66 corresponding virtuals. */
67 void emitObject(SkWStream*) const;
68
69 bool isName() const;
70
71private:
72 using PDFObject = std::unique_ptr<SkPDFObject>;
73 union {
74 int32_t fIntValue;
77 const char* fStaticString;
79 PDFObject fObject;
80 };
81 enum class Type : char {
82 /** It is an error to call emitObject() or addResources() on an kDestroyed object. */
83 kDestroyed = 0,
84 kInt,
85 kColorComponent,
86 kColorComponentF,
87 kBool,
88 kScalar,
89 kName,
90 kByteString,
91 kTextString,
92 kNameSkS,
93 kByteStringSkS,
94 kTextStringSkS,
95 kObject,
96 kRef,
97 };
98 Type fType;
99
100 SkPDFUnion(Type, int32_t);
101 SkPDFUnion(Type, bool);
103 SkPDFUnion(Type, const char*);
105 SkPDFUnion(Type, PDFObject);
106
107 SkPDFUnion& operator=(const SkPDFUnion&) = delete;
108 SkPDFUnion(const SkPDFUnion&) = delete;
109};
110static_assert(sizeof(SkString) == sizeof(void*), "SkString_size");
111
112#endif // SkPDFUnion_DEFINED
constexpr int32_t SkToS32(S x)
Definition SkTo.h:25
int32_t fIntValue
Definition SkPDFUnion.h:74
static SkPDFUnion Ref(SkPDFIndirectReference)
static SkPDFUnion ColorComponentF(float)
SkScalar fScalarValue
Definition SkPDFUnion.h:76
static SkPDFUnion Bool(bool)
static SkPDFUnion Int(int32_t)
static SkPDFUnion TextString(const char *)
PDFObject fObject
Definition SkPDFUnion.h:79
void emitObject(SkWStream *) const
static SkPDFUnion ByteString(const char *)
static SkPDFUnion Object(std::unique_ptr< SkPDFObject >)
SkPDFUnion & operator=(SkPDFUnion &&)
static SkPDFUnion Name(const char *)
const char * fStaticString
Definition SkPDFUnion.h:77
SkString fSkString
Definition SkPDFUnion.h:78
bool fBoolValue
Definition SkPDFUnion.h:75
bool isName() const
static SkPDFUnion Int(size_t v)
Definition SkPDFUnion.h:27
static SkPDFUnion Scalar(SkScalar)
static SkPDFUnion ColorComponent(uint8_t)
float SkScalar
Definition extension.cpp:12