Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 13 of file SkPDFUnion.h.

Constructor & Destructor Documentation

◆ SkPDFUnion()

SkPDFUnion::SkPDFUnion ( SkPDFUnion &&  that)

Definition at line 46 of file SkPDFTypes.cpp.

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

◆ ~SkPDFUnion()

SkPDFUnion::~SkPDFUnion ( )

Definition at line 31 of file SkPDFTypes.cpp.

31 {
32 switch (fType) {
33 case Type::kNameSkS:
34 case Type::kByteStringSkS:
35 case Type::kTextStringSkS:
37 return;
38 case Type::kObject:
39 fObject.~PDFObject();
40 return;
41 default:
42 return;
43 }
44}

Member Function Documentation

◆ Bool()

SkPDFUnion SkPDFUnion::Bool ( bool  value)
static

Definition at line 311 of file SkPDFTypes.cpp.

311 {
312 return SkPDFUnion(Type::kBool, value);
313}

◆ ByteString() [1/2]

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

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

Definition at line 325 of file SkPDFTypes.cpp.

325 {
326 SkASSERT(value);
327 return SkPDFUnion(Type::kByteString, value);
328}

◆ ByteString() [2/2]

SkPDFUnion SkPDFUnion::ByteString ( SkString  s)
static

SkPDFUnion::String will encode the passed string.

Definition at line 339 of file SkPDFTypes.cpp.

339 {
340 return SkPDFUnion(Type::kByteStringSkS, std::move(s));
341}
struct MyStruct s

◆ ColorComponent()

SkPDFUnion SkPDFUnion::ColorComponent ( uint8_t  value)
static

Definition at line 303 of file SkPDFTypes.cpp.

303 {
304 return SkPDFUnion(Type::kColorComponent, SkTo<int32_t>(value));
305}

◆ ColorComponentF()

SkPDFUnion SkPDFUnion::ColorComponentF ( float  value)
static

Definition at line 307 of file SkPDFTypes.cpp.

307 {
308 return SkPDFUnion(Type::kColorComponentF, value);
309}

◆ emitObject()

void SkPDFUnion::emitObject ( SkWStream stream) const

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

Definition at line 246 of file SkPDFTypes.cpp.

246 {
247 switch (fType) {
248 case Type::kInt:
249 stream->writeDecAsText(fIntValue);
250 return;
251 case Type::kColorComponent:
253 return;
254 case Type::kColorComponentF:
256 return;
257 case Type::kBool:
258 stream->writeText(fBoolValue ? "true" : "false");
259 return;
260 case Type::kScalar:
262 return;
263 case Type::kName:
264 stream->writeText("/");
266 stream->writeText(fStaticString);
267 return;
268 case Type::kByteString:
271 return;
272 case Type::kTextString:
275 return;
276 case Type::kNameSkS:
277 stream->writeText("/");
279 return;
280 case Type::kByteStringSkS:
282 return;
283 case Type::kTextStringSkS:
285 return;
286 case Type::kObject:
287 fObject->emitObject(stream);
288 return;
289 case Type::kRef:
290 SkASSERT(fIntValue >= 0);
291 stream->writeDecAsText(fIntValue);
292 stream->writeText(" 0 R"); // Generation number is always 0.
293 return;
294 default:
295 SkDEBUGFAIL("SkPDFUnion::emitObject with bad type");
296 }
297}
static bool is_valid_name(const SkString &name)
static void write_byte_string(SkWStream *wStream, const char *cin, size_t len)
static void write_name_escaped(SkWStream *o, const char *name)
static void write_text_string(SkWStream *wStream, const char *cin, size_t len)
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:75
void AppendScalar(SkScalar value, SkWStream *stream)
Definition SkPDFUtils.h:86
void AppendColorComponentF(float value, SkWStream *wStream)
Definition SkPDFUtils.h:80

◆ 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 299 of file SkPDFTypes.cpp.

299 {
300 return SkPDFUnion(Type::kInt, value);
301}

◆ Int() [2/2]

static SkPDFUnion SkPDFUnion::Int ( size_t  v)
inlinestatic

Definition at line 27 of file SkPDFUnion.h.

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

◆ isName()

bool SkPDFUnion::isName ( ) const

Definition at line 91 of file SkPDFTypes.cpp.

91 {
92 return Type::kName == fType || Type::kNameSkS == fType;
93}

◆ 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 319 of file SkPDFTypes.cpp.

319 {
320 SkASSERT(value);
321 SkASSERT(is_valid_name(value));
322 return SkPDFUnion(Type::kName, value);
323}

◆ 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 335 of file SkPDFTypes.cpp.

335 {
336 return SkPDFUnion(Type::kNameSkS, std::move(s));
337}

◆ Object()

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

Definition at line 347 of file SkPDFTypes.cpp.

347 {
348 SkASSERT(objSp.get());
349 return SkPDFUnion(Type::kObject, std::move(objSp));
350}

◆ operator=()

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

Definition at line 83 of file SkPDFTypes.cpp.

83 {
84 if (this != &that) {
85 this->~SkPDFUnion();
86 new (this) SkPDFUnion(std::move(that));
87 }
88 return *this;
89}

◆ Ref()

SkPDFUnion SkPDFUnion::Ref ( SkPDFIndirectReference  ref)
static

Definition at line 352 of file SkPDFTypes.cpp.

352 {
353 SkASSERT(ref.fValue > 0);
354 return SkPDFUnion(Type::kRef, SkTo<int32_t>(ref.fValue));
355}

◆ Scalar()

SkPDFUnion SkPDFUnion::Scalar ( SkScalar  value)
static

Definition at line 315 of file SkPDFTypes.cpp.

315 {
316 return SkPDFUnion(Type::kScalar, value);
317}

◆ TextString() [1/2]

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

Definition at line 330 of file SkPDFTypes.cpp.

330 {
331 SkASSERT(value);
332 return SkPDFUnion(Type::kTextString, value);
333}

◆ TextString() [2/2]

SkPDFUnion SkPDFUnion::TextString ( SkString  s)
static

Definition at line 343 of file SkPDFTypes.cpp.

343 {
344 return SkPDFUnion(Type::kTextStringSkS, std::move(s));
345}

Member Data Documentation

◆ fBoolValue

bool SkPDFUnion::fBoolValue

Definition at line 75 of file SkPDFUnion.h.

◆ fIntValue

int32_t SkPDFUnion::fIntValue

Definition at line 74 of file SkPDFUnion.h.

◆ fObject

PDFObject SkPDFUnion::fObject

Definition at line 79 of file SkPDFUnion.h.

◆ fScalarValue

SkScalar SkPDFUnion::fScalarValue

Definition at line 76 of file SkPDFUnion.h.

◆ fSkString

SkString SkPDFUnion::fSkString

Definition at line 78 of file SkPDFUnion.h.

◆ fStaticString

const char* SkPDFUnion::fStaticString

Definition at line 77 of file SkPDFUnion.h.


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