Flutter Engine
The Flutter Engine
SkPDFResourceDict.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
13#include "src/pdf/SkPDFTypes.h"
14
15#include <cstddef>
16#include <utility>
17
18// Verify that the values of enum ResourceType correspond to the expected values
19// as defined in the arrays below.
20// If these are failing, you may need to update the kResourceTypePrefixes
21// and kResourceTypeNames arrays below.
22static_assert(0 == (int)SkPDFResourceType::kExtGState, "resource_type_mismatch");
23static_assert(1 == (int)SkPDFResourceType::kPattern, "resource_type_mismatch");
24static_assert(2 == (int)SkPDFResourceType::kXObject, "resource_type_mismatch");
25static_assert(3 == (int)SkPDFResourceType::kFont, "resource_type_mismatch");
26
27// One extra character for the Prefix.
29
30// returns pointer just past end of what's written into `dst`.
32 static const char kResourceTypePrefixes[] = {
33 'G', // kExtGState
34 'P', // kPattern
35 'X', // kXObject
36 'F' // kFont
37 };
38 SkASSERT((unsigned)type < std::size(kResourceTypePrefixes));
39 dst[0] = kResourceTypePrefixes[(unsigned)type];
40 return SkStrAppendS32(dst + 1, key);
41}
42
44 // One extra character for the leading '/'.
46 buffer[0] = '/';
47 char* end = get_resource_name(buffer + 1, type, key);
48 dst->write(buffer, (size_t)(end - buffer));
49}
50
52 static const char* kResourceTypeNames[] = {
53 "ExtGState",
54 "Pattern",
55 "XObject",
56 "Font"
57 };
58 SkASSERT((unsigned)type < std::size(kResourceTypeNames));
59 return kResourceTypeNames[(unsigned)type];
60}
61
64 char* end = get_resource_name(buffer, type, index);
65 return SkString(buffer, (size_t)(end - buffer));
66}
67
68static void add_subdict(const std::vector<SkPDFIndirectReference>& resourceList,
70 SkPDFDict* dst) {
71 if (!resourceList.empty()) {
72 auto resources = SkPDFMakeDict();
73 for (SkPDFIndirectReference ref : resourceList) {
74 resources->insertRef(resource(type, ref.fValue), ref);
75 }
76 dst->insertObject(resource_name(type), std::move(resources));
77 }
78}
79
80static std::unique_ptr<SkPDFArray> make_proc_set() {
81 auto procSets = SkPDFMakeArray();
82 static const char kProcs[][7] = { "PDF", "Text", "ImageB", "ImageC", "ImageI"};
83 procSets->reserve(std::size(kProcs));
84 for (const char* proc : kProcs) {
85 procSets->appendName(proc);
86 }
87 return procSets;
88}
89
90std::unique_ptr<SkPDFDict> SkPDFMakeResourceDict(
91 const std::vector<SkPDFIndirectReference>& graphicStateResources,
92 const std::vector<SkPDFIndirectReference>& shaderResources,
93 const std::vector<SkPDFIndirectReference>& xObjectResources,
94 const std::vector<SkPDFIndirectReference>& fontResources) {
95 auto dict = SkPDFMakeDict();
96 dict->insertObject("ProcSet", make_proc_set());
97 add_subdict(graphicStateResources, SkPDFResourceType::kExtGState, dict.get());
98 add_subdict(shaderResources, SkPDFResourceType::kPattern, dict.get());
99 add_subdict(xObjectResources, SkPDFResourceType::kXObject, dict.get());
100 add_subdict(fontResources, SkPDFResourceType::kFont, dict.get());
101 return dict;
102}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void add_subdict(const std::vector< SkPDFIndirectReference > &resourceList, SkPDFResourceType type, SkPDFDict *dst)
constexpr size_t kMaxResourceNameLength
void SkPDFWriteResourceName(SkWStream *dst, SkPDFResourceType type, int key)
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)
static SkString resource(SkPDFResourceType type, int index)
static const char * resource_name(SkPDFResourceType type)
static std::unique_ptr< SkPDFArray > make_proc_set()
static char * get_resource_name(char dst[kMaxResourceNameLength], SkPDFResourceType type, int key)
SkPDFResourceType
static std::unique_ptr< SkPDFDict > SkPDFMakeDict(const char *type=nullptr)
Definition: SkPDFTypes.h:185
static std::unique_ptr< SkPDFArray > SkPDFMakeArray(Args... args)
Definition: SkPDFTypes.h:125
static constexpr int kSkStrAppendS32_MaxSize
Definition: SkString.h:89
char * SkStrAppendS32(char buffer[], int32_t)
Definition: SkString.cpp:120
GLenum type
glong glong end
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
dst
Definition: cp.py:12