Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
SkPDFResourceDict.cpp File Reference
#include "include/core/SkStream.h"
#include "src/pdf/SkPDFResourceDict.h"
#include "src/pdf/SkPDFTypes.h"

Go to the source code of this file.

Functions

static char * get_resource_name (char dst[kMaxResourceNameLength], SkPDFResourceType type, int key)
 
void SkPDFWriteResourceName (SkWStream *dst, SkPDFResourceType type, int key)
 
static const char * resource_name (SkPDFResourceType type)
 
static SkString resource (SkPDFResourceType type, int index)
 
static void add_subdict (const std::vector< SkPDFIndirectReference > &resourceList, SkPDFResourceType type, SkPDFDict *dst)
 
static std::unique_ptr< SkPDFArraymake_proc_set ()
 
std::unique_ptr< SkPDFDictSkPDFMakeResourceDict (const std::vector< SkPDFIndirectReference > &graphicStateResources, const std::vector< SkPDFIndirectReference > &shaderResources, const std::vector< SkPDFIndirectReference > &xObjectResources, const std::vector< SkPDFIndirectReference > &fontResources)
 

Variables

constexpr size_t kMaxResourceNameLength = 1 + kSkStrAppendS32_MaxSize
 

Function Documentation

◆ add_subdict()

static void add_subdict ( const std::vector< SkPDFIndirectReference > &  resourceList,
SkPDFResourceType  type,
SkPDFDict dst 
)
static

Definition at line 62 of file SkPDFResourceDict.cpp.

64 {
65 if (!resourceList.empty()) {
66 auto resources = SkPDFMakeDict();
67 for (SkPDFIndirectReference ref : resourceList) {
68 resources->insertRef(resource(type, ref.fValue), ref);
69 }
70 dst->insertObject(resource_name(type), std::move(resources));
71 }
72}
static SkString resource(SkPDFResourceType type, int index)
static const char * resource_name(SkPDFResourceType type)
static std::unique_ptr< SkPDFDict > SkPDFMakeDict(const char *type=nullptr)
Definition SkPDFTypes.h:195
dst
Definition cp.py:12

◆ get_resource_name()

static char * get_resource_name ( char  dst[kMaxResourceNameLength],
SkPDFResourceType  type,
int  key 
)
static

Definition at line 25 of file SkPDFResourceDict.cpp.

25 {
26 static const char kResourceTypePrefixes[] = {
27 'G', // kExtGState
28 'P', // kPattern
29 'X', // kXObject
30 'F' // kFont
31 };
32 SkASSERT((unsigned)type < std::size(kResourceTypePrefixes));
33 dst[0] = kResourceTypePrefixes[(unsigned)type];
34 return SkStrAppendS32(dst + 1, key);
35}
#define SkASSERT(cond)
Definition SkAssert.h:116
char * SkStrAppendS32(char buffer[], int32_t)
Definition SkString.cpp:120

◆ make_proc_set()

static std::unique_ptr< SkPDFArray > make_proc_set ( )
static

Definition at line 74 of file SkPDFResourceDict.cpp.

74 {
75 auto procSets = SkPDFMakeArray();
76 static const char kProcs[][7] = { "PDF", "Text", "ImageB", "ImageC", "ImageI"};
77 procSets->reserve(std::size(kProcs));
78 for (const char* proc : kProcs) {
79 procSets->appendName(proc);
80 }
81 return procSets;
82}
static std::unique_ptr< SkPDFArray > SkPDFMakeArray(Args... args)
Definition SkPDFTypes.h:135

◆ resource()

static SkString resource ( SkPDFResourceType  type,
int  index 
)
static

Definition at line 56 of file SkPDFResourceDict.cpp.

56 {
58 char* end = get_resource_name(buffer, type, index);
59 return SkString(buffer, (size_t)(end - buffer));
60}
constexpr size_t kMaxResourceNameLength
static char * get_resource_name(char dst[kMaxResourceNameLength], SkPDFResourceType type, int key)
glong glong end
static const uint8_t buffer[]

◆ resource_name()

static const char * resource_name ( SkPDFResourceType  type)
static

Definition at line 45 of file SkPDFResourceDict.cpp.

45 {
46 static const char* kResourceTypeNames[] = {
47 "ExtGState",
48 "Pattern",
49 "XObject",
50 "Font"
51 };
52 SkASSERT((unsigned)type < std::size(kResourceTypeNames));
53 return kResourceTypeNames[(unsigned)type];
54}

◆ SkPDFMakeResourceDict()

std::unique_ptr< SkPDFDict > SkPDFMakeResourceDict ( const std::vector< SkPDFIndirectReference > &  graphicStateResources,
const std::vector< SkPDFIndirectReference > &  shaderResources,
const std::vector< SkPDFIndirectReference > &  xObjectResources,
const std::vector< SkPDFIndirectReference > &  fontResources 
)

Create a PDF resource dictionary. The full set of ProcSet entries is automatically created for backwards compatibility, as recommended by the PDF spec.

Any arguments can be nullptr.

Definition at line 84 of file SkPDFResourceDict.cpp.

88 {
89 auto dict = SkPDFMakeDict();
90 dict->insertObject("ProcSet", make_proc_set());
91 add_subdict(graphicStateResources, SkPDFResourceType::kExtGState, dict.get());
92 add_subdict(shaderResources, SkPDFResourceType::kPattern, dict.get());
93 add_subdict(xObjectResources, SkPDFResourceType::kXObject, dict.get());
94 add_subdict(fontResources, SkPDFResourceType::kFont, dict.get());
95 return dict;
96}
static void add_subdict(const std::vector< SkPDFIndirectReference > &resourceList, SkPDFResourceType type, SkPDFDict *dst)
static std::unique_ptr< SkPDFArray > make_proc_set()

◆ SkPDFWriteResourceName()

void SkPDFWriteResourceName ( SkWStream dst,
SkPDFResourceType  type,
int  key 
)

Writes the name for the resource that will be generated by the resource dict.

Parameters
typeThe type of resource being entered
keyThe resource key, should be unique within its type.

Definition at line 37 of file SkPDFResourceDict.cpp.

37 {
38 // One extra character for the leading '/'.
40 buffer[0] = '/';
41 char* end = get_resource_name(buffer + 1, type, key);
42 dst->write(buffer, (size_t)(end - buffer));
43}

Variable Documentation

◆ kMaxResourceNameLength

constexpr size_t kMaxResourceNameLength = 1 + kSkStrAppendS32_MaxSize
constexpr

Definition at line 22 of file SkPDFResourceDict.cpp.