Flutter Engine
The Flutter Engine
Functions | Variables
SkPDFMetadata.cpp File Reference
#include "src/pdf/SkPDFMetadata.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/docs/SkPDFDocument.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkTime.h"
#include "src/base/SkUtils.h"
#include "src/core/SkMD5.h"
#include "src/pdf/SkPDFTypes.h"
#include "src/pdf/SkPDFUtils.h"
#include <cstdint>
#include <cstring>
#include <utility>

Go to the source code of this file.

Functions

static bool operator!= (const SkPDF::DateTime &u, const SkPDF::DateTime &v)
 
static SkString pdf_date (const SkPDF::DateTime &dt)
 
static void hexify (const uint8_t **inputPtr, char **outputPtr, int count)
 
static SkString uuid_to_string (const SkUUID &uuid)
 
static int count_xml_escape_size (const SkString &input)
 
SkString escape_xml (const SkString &input, const char *before=nullptr, const char *after=nullptr)
 

Variables

static constexpr SkPDF::DateTime kZeroTime = {0, 0, 0, 0, 0, 0, 0, 0}
 

Function Documentation

◆ count_xml_escape_size()

static int count_xml_escape_size ( const SkString input)
static

Definition at line 182 of file SkPDFMetadata.cpp.

182 {
183 int extra = 0;
184 for (size_t i = 0; i < input.size(); ++i) {
185 if (input[i] == '&') {
186 extra += 4; // strlen("&amp;") - strlen("&")
187 } else if (input[i] == '<') {
188 extra += 3; // strlen("&lt;") - strlen("<")
189 }
190 }
191 return extra;
192}
size_t size() const
Definition: SkString.h:131

◆ escape_xml()

SkString escape_xml ( const SkString input,
const char *  before = nullptr,
const char *  after = nullptr 
)

Definition at line 194 of file SkPDFMetadata.cpp.

196 {
197 if (input.size() == 0) {
198 return input;
199 }
200 // "&" --> "&amp;" and "<" --> "&lt;"
201 // text is assumed to be in UTF-8
202 // all strings are xml content, not attribute values.
203 size_t beforeLen = before ? strlen(before) : 0;
204 size_t afterLen = after ? strlen(after) : 0;
205 int extra = count_xml_escape_size(input);
206 SkString output(input.size() + extra + beforeLen + afterLen);
207 char* out = output.data();
208 if (before) {
209 strncpy(out, before, beforeLen);
210 out += beforeLen;
211 }
212 static const char kAmp[] = "&amp;";
213 static const char kLt[] = "&lt;";
214 for (size_t i = 0; i < input.size(); ++i) {
215 if (input[i] == '&') {
216 memcpy(out, kAmp, strlen(kAmp));
217 out += strlen(kAmp);
218 } else if (input[i] == '<') {
219 memcpy(out, kLt, strlen(kLt));
220 out += strlen(kLt);
221 } else {
222 *out++ = input[i];
223 }
224 }
225 if (after) {
226 strncpy(out, after, afterLen);
227 out += afterLen;
228 }
229 // Validate that we haven't written outside of our string.
230 SkASSERT(out == &output.data()[output.size()]);
231 *out = '\0';
232 return output;
233}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int count_xml_escape_size(const SkString &input)

◆ hexify()

static void hexify ( const uint8_t **  inputPtr,
char **  outputPtr,
int  count 
)
static

Definition at line 129 of file SkPDFMetadata.cpp.

129 {
130 SkASSERT(inputPtr && *inputPtr);
131 SkASSERT(outputPtr && *outputPtr);
132 while (count-- > 0) {
133 uint8_t value = *(*inputPtr)++;
134 *(*outputPtr)++ = SkHexadecimalDigits::gLower[value >> 4];
135 *(*outputPtr)++ = SkHexadecimalDigits::gLower[value & 0xF];
136 }
137}
int count
Definition: FontMgrTest.cpp:50
uint8_t value
const char gLower[16]
Definition: SkUtils.cpp:12

◆ operator!=()

static bool operator!= ( const SkPDF::DateTime u,
const SkPDF::DateTime v 
)
static

Definition at line 29 of file SkPDFMetadata.cpp.

29 {
30 return u.fTimeZoneMinutes != v.fTimeZoneMinutes ||
31 u.fYear != v.fYear ||
32 u.fMonth != v.fMonth ||
33 u.fDayOfWeek != v.fDayOfWeek ||
34 u.fDay != v.fDay ||
35 u.fHour != v.fHour ||
36 u.fMinute != v.fMinute ||
37 u.fSecond != v.fSecond;
38}
uint8_t fMinute
0..59
Definition: SkPDFDocument.h:77
uint8_t fMonth
1..12
Definition: SkPDFDocument.h:73
uint8_t fDay
1..31
Definition: SkPDFDocument.h:75
uint16_t fYear
e.g. 2005
Definition: SkPDFDocument.h:72
uint8_t fSecond
0..59
Definition: SkPDFDocument.h:78
int16_t fTimeZoneMinutes
Definition: SkPDFDocument.h:70
uint8_t fHour
0..23
Definition: SkPDFDocument.h:76
uint8_t fDayOfWeek
0..6, 0==Sunday
Definition: SkPDFDocument.h:74

◆ pdf_date()

static SkString pdf_date ( const SkPDF::DateTime dt)
static

Definition at line 40 of file SkPDFMetadata.cpp.

40 {
41 int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes);
42 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-';
43 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60;
44 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60;
45 return SkStringPrintf(
46 "D:%04u%02u%02u%02u%02u%02u%c%02d'%02d'",
47 static_cast<unsigned>(dt.fYear), static_cast<unsigned>(dt.fMonth),
48 static_cast<unsigned>(dt.fDay), static_cast<unsigned>(dt.fHour),
49 static_cast<unsigned>(dt.fMinute),
50 static_cast<unsigned>(dt.fSecond), timezoneSign, timeZoneHours,
51 timeZoneMinutes);
52}
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static T SkTAbs(T value)
Definition: SkTemplates.h:43
constexpr int SkToInt(S x)
Definition: SkTo.h:29

◆ uuid_to_string()

static SkString uuid_to_string ( const SkUUID uuid)
static

Definition at line 139 of file SkPDFMetadata.cpp.

139 {
140 // 8-4-4-4-12
141 char buffer[36]; // [32 + 4]
142 char* ptr = buffer;
143 const uint8_t* data = uuid.fData;
144 hexify(&data, &ptr, 4);
145 *ptr++ = '-';
146 hexify(&data, &ptr, 2);
147 *ptr++ = '-';
148 hexify(&data, &ptr, 2);
149 *ptr++ = '-';
150 hexify(&data, &ptr, 2);
151 *ptr++ = '-';
152 hexify(&data, &ptr, 6);
153 SkASSERT(ptr == buffer + 36);
154 SkASSERT(data == uuid.fData + 16);
155 return SkString(buffer, 36);
156}
static void hexify(const uint8_t **inputPtr, char **outputPtr, int count)
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
uint8_t fData[16]
Definition: SkUUID.h:10
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

Variable Documentation

◆ kZeroTime

constexpr SkPDF::DateTime kZeroTime = {0, 0, 0, 0, 0, 0, 0, 0}
staticconstexpr

Definition at line 27 of file SkPDFMetadata.cpp.