Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkPDFUnion Class Reference

#include <SkPDFUnion.h>

Public Member Functions

 SkPDFUnion (SkPDFUnion &&)
 
SkPDFUnionoperator= (SkPDFUnion &&)
 
 ~SkPDFUnion ()
 
void emitObject (SkWStream *) const
 
bool isName () const
 

Static Public Member Functions

static SkPDFUnion Int (int32_t)
 
static SkPDFUnion Int (size_t v)
 
static SkPDFUnion Bool (bool)
 
static SkPDFUnion Scalar (SkScalar)
 
static SkPDFUnion ColorComponent (uint8_t)
 
static SkPDFUnion ColorComponentF (float)
 
static SkPDFUnion Name (const char *)
 
static SkPDFUnion ByteString (const char *)
 
static SkPDFUnion TextString (const char *)
 
static SkPDFUnion Name (SkString)
 
static SkPDFUnion ByteString (SkString)
 
static SkPDFUnion TextString (SkString)
 
static SkPDFUnion Object (std::unique_ptr< SkPDFObject >)
 
static SkPDFUnion Ref (SkPDFIndirectReference)
 

Detailed Description

A SkPDFUnion is a non-virtualized implementation of the non-compound, non-specialized PDF Object types: Name, String, Number, Boolean.

Definition at line 23 of file SkPDFUnion.h.

Constructor & Destructor Documentation

◆ SkPDFUnion()

SkPDFUnion::SkPDFUnion ( SkPDFUnion &&  that)

Definition at line 52 of file SkPDFTypes.cpp.

52 : fType(that.fType) {
53 SkASSERT(this != &that);
54
55 switch (fType) {
56 case Type::kDestroyed:
57 break;
58 case Type::kInt:
59 case Type::kColorComponent:
60 case Type::kRef:
61 fIntValue = that.fIntValue;
62 break;
63 case Type::kBool:
65 break;
66 case Type::kColorComponentF:
67 case Type::kScalar:
69 break;
70 case Type::kName:
71 case Type::kByteString:
72 case Type::kTextString:
74 break;
75 case Type::kNameSkS:
76 case Type::kByteStringSkS:
77 case Type::kTextStringSkS:
78 new (&fSkString) SkString(std::move(that.fSkString));
79 break;
80 case Type::kObject:
81 new (&fObject) PDFObject(std::move(that.fObject));
82 break;
83 default:
84 SkDEBUGFAIL("SkPDFUnion::SkPDFUnion with bad type");
85 }
86 that.fType = Type::kDestroyed;
87}
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
#define SkASSERT(cond)
Definition: SkAssert.h:116
int32_t fIntValue
Definition: SkPDFUnion.h:84
SkScalar fScalarValue
Definition: SkPDFUnion.h:86
PDFObject fObject
Definition: SkPDFUnion.h:89
const char * fStaticString
Definition: SkPDFUnion.h:87
SkString fSkString
Definition: SkPDFUnion.h:88
bool fBoolValue
Definition: SkPDFUnion.h:85

◆ ~SkPDFUnion()

SkPDFUnion::~SkPDFUnion ( )

Definition at line 37 of file SkPDFTypes.cpp.

37 {
38 switch (fType) {
39 case Type::kNameSkS:
40 case Type::kByteStringSkS:
41 case Type::kTextStringSkS:
43 return;
44 case Type::kObject:
45 fObject.~PDFObject();
46 return;
47 default:
48 return;
49 }
50}

Member Function Documentation

◆ Bool()

SkPDFUnion SkPDFUnion::Bool ( bool  value)
static

Definition at line 317 of file SkPDFTypes.cpp.

317 {
318 return SkPDFUnion(Type::kBool, value);
319}
SkPDFUnion(SkPDFUnion &&)
Definition: SkPDFTypes.cpp:52
uint8_t value

◆ ByteString() [1/2]

SkPDFUnion SkPDFUnion::ByteString ( const char *  value)
static

SkPDFUnion::String will encode the passed string. This will not copy.

Definition at line 331 of file SkPDFTypes.cpp.

331 {
333 return SkPDFUnion(Type::kByteString, value);
334}

◆ ByteString() [2/2]

SkPDFUnion SkPDFUnion::ByteString ( SkString  s)
static

SkPDFUnion::String will encode the passed string.

Definition at line 345 of file SkPDFTypes.cpp.

345 {
346 return SkPDFUnion(Type::kByteStringSkS, std::move(s));
347}
struct MyStruct s

◆ ColorComponent()

SkPDFUnion SkPDFUnion::ColorComponent ( uint8_t  value)
static

Definition at line 309 of file SkPDFTypes.cpp.

309 {
310 return SkPDFUnion(Type::kColorComponent, SkTo<int32_t>(value));
311}

◆ ColorComponentF()

SkPDFUnion SkPDFUnion::ColorComponentF ( float  value)
static

Definition at line 313 of file SkPDFTypes.cpp.

313 {
314 return SkPDFUnion(Type::kColorComponentF, value);
315}

◆ emitObject()

void SkPDFUnion::emitObject ( SkWStream stream) const

These two non-virtual methods mirror SkPDFObject's corresponding virtuals.

Definition at line 252 of file SkPDFTypes.cpp.

252 {
253 switch (fType) {
254 case Type::kInt:
255 stream->writeDecAsText(fIntValue);
256 return;
257 case Type::kColorComponent:
259 return;
260 case Type::kColorComponentF:
262 return;
263 case Type::kBool:
264 stream->writeText(fBoolValue ? "true" : "false");
265 return;
266 case Type::kScalar:
268 return;
269 case Type::kName:
270 stream->writeText("/");
272 stream->writeText(fStaticString);
273 return;
274 case Type::kByteString:
277 return;
278 case Type::kTextString:
281 return;
282 case Type::kNameSkS:
283 stream->writeText("/");
285 return;
286 case Type::kByteStringSkS:
288 return;
289 case Type::kTextStringSkS:
291 return;
292 case Type::kObject:
293 fObject->emitObject(stream);
294 return;
295 case Type::kRef:
296 SkASSERT(fIntValue >= 0);
297 stream->writeDecAsText(fIntValue);
298 stream->writeText(" 0 R"); // Generation number is always 0.
299 return;
300 default:
301 SkDEBUGFAIL("SkPDFUnion::emitObject with bad type");
302 }
303}
static bool is_valid_name(const SkString &name)
static void write_byte_string(SkWStream *wStream, const char *cin, size_t len)
Definition: SkPDFTypes.cpp:176
static void write_name_escaped(SkWStream *o, const char *name)
Definition: SkPDFTypes.cpp:116
static void write_text_string(SkWStream *wStream, const char *cin, size_t len)
Definition: SkPDFTypes.cpp:194
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
void AppendColorComponent(uint8_t value, SkWStream *wStream)
Definition: SkPDFUtils.h:87
void AppendScalar(SkScalar value, SkWStream *stream)
Definition: SkPDFUtils.h:98
void AppendColorComponentF(float value, SkWStream *wStream)
Definition: SkPDFUtils.h:92

◆ Int() [1/2]

SkPDFUnion SkPDFUnion::Int ( int32_t  value)
static

The following nine functions are the standard way of creating SkPDFUnion objects.

Definition at line 305 of file SkPDFTypes.cpp.

305 {
306 return SkPDFUnion(Type::kInt, value);
307}

◆ Int() [2/2]

static SkPDFUnion SkPDFUnion::Int ( size_t  v)
inlinestatic

Definition at line 37 of file SkPDFUnion.h.

37{ return SkPDFUnion::Int(SkToS32(v)); }
constexpr int32_t SkToS32(S x)
Definition: SkTo.h:25
static SkPDFUnion Int(int32_t)
Definition: SkPDFTypes.cpp:305

◆ isName()

bool SkPDFUnion::isName ( ) const

Definition at line 97 of file SkPDFTypes.cpp.

97 {
98 return Type::kName == fType || Type::kNameSkS == fType;
99}

◆ Name() [1/2]

SkPDFUnion SkPDFUnion::Name ( const char *  value)
static

These two functions do NOT take ownership of char*, and do NOT copy the string. Suitable for passing in static const strings. For example: SkPDFUnion n = SkPDFUnion::Name("Length"); SkPDFUnion u = SkPDFUnion::String("Identity"); SkPDFUnion::Name(const char*) assumes that the passed string is already a valid name (that is: it has no control or whitespace characters). This will not copy the name.

Definition at line 325 of file SkPDFTypes.cpp.

325 {
328 return SkPDFUnion(Type::kName, value);
329}

◆ Name() [2/2]

SkPDFUnion SkPDFUnion::Name ( SkString  s)
static

SkPDFUnion::Name(SkString) does not assume that the passed string is already a valid name and it will escape the string.

Definition at line 341 of file SkPDFTypes.cpp.

341 {
342 return SkPDFUnion(Type::kNameSkS, std::move(s));
343}

◆ Object()

SkPDFUnion SkPDFUnion::Object ( std::unique_ptr< SkPDFObject objSp)
static

Definition at line 353 of file SkPDFTypes.cpp.

353 {
354 SkASSERT(objSp.get());
355 return SkPDFUnion(Type::kObject, std::move(objSp));
356}

◆ operator=()

SkPDFUnion & SkPDFUnion::operator= ( SkPDFUnion &&  that)

Definition at line 89 of file SkPDFTypes.cpp.

89 {
90 if (this != &that) {
91 this->~SkPDFUnion();
92 new (this) SkPDFUnion(std::move(that));
93 }
94 return *this;
95}

◆ Ref()

SkPDFUnion SkPDFUnion::Ref ( SkPDFIndirectReference  ref)
static

Definition at line 358 of file SkPDFTypes.cpp.

358 {
359 SkASSERT(ref.fValue > 0);
360 return SkPDFUnion(Type::kRef, SkTo<int32_t>(ref.fValue));
361}

◆ Scalar()

SkPDFUnion SkPDFUnion::Scalar ( SkScalar  value)
static

Definition at line 321 of file SkPDFTypes.cpp.

321 {
322 return SkPDFUnion(Type::kScalar, value);
323}

◆ TextString() [1/2]

SkPDFUnion SkPDFUnion::TextString ( const char *  value)
static

Definition at line 336 of file SkPDFTypes.cpp.

336 {
338 return SkPDFUnion(Type::kTextString, value);
339}

◆ TextString() [2/2]

SkPDFUnion SkPDFUnion::TextString ( SkString  s)
static

Definition at line 349 of file SkPDFTypes.cpp.

349 {
350 return SkPDFUnion(Type::kTextStringSkS, std::move(s));
351}

Member Data Documentation

◆ fBoolValue

bool SkPDFUnion::fBoolValue

Definition at line 85 of file SkPDFUnion.h.

◆ fIntValue

int32_t SkPDFUnion::fIntValue

Definition at line 84 of file SkPDFUnion.h.

◆ fObject

PDFObject SkPDFUnion::fObject

Definition at line 89 of file SkPDFUnion.h.

◆ fScalarValue

SkScalar SkPDFUnion::fScalarValue

Definition at line 86 of file SkPDFUnion.h.

◆ fSkString

SkString SkPDFUnion::fSkString

Definition at line 88 of file SkPDFUnion.h.

◆ fStaticString

const char* SkPDFUnion::fStaticString

Definition at line 87 of file SkPDFUnion.h.


The documentation for this class was generated from the following files: