Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
SkPDFMetadata.cpp File Reference
#include "src/pdf/SkPDFMetadata.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkUTF.h"
#include "src/base/SkUtils.h"
#include "src/core/SkMD5.h"
#include "src/pdf/SkPDFTypes.h"
#include "src/pdf/SkPDFUtils.h"
#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 175 of file SkPDFMetadata.cpp.

175 {
176 int extra = 0;
177 for (size_t i = 0; i < input.size(); ++i) {
178 if (input[i] == '&') {
179 extra += 4; // strlen("&amp;") - strlen("&")
180 } else if (input[i] == '<') {
181 extra += 3; // strlen("&lt;") - strlen("<")
182 }
183 }
184 return extra;
185}
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 187 of file SkPDFMetadata.cpp.

189 {
190 if (input.size() == 0) {
191 return input;
192 }
193 // "&" --> "&amp;" and "<" --> "&lt;"
194 // text is assumed to be in UTF-8
195 // all strings are xml content, not attribute values.
196 size_t beforeLen = before ? strlen(before) : 0;
197 size_t afterLen = after ? strlen(after) : 0;
198 int extra = count_xml_escape_size(input);
199 SkString output(input.size() + extra + beforeLen + afterLen);
200 char* out = output.data();
201 if (before) {
202 strncpy(out, before, beforeLen);
203 out += beforeLen;
204 }
205 static const char kAmp[] = "&amp;";
206 static const char kLt[] = "&lt;";
207 for (size_t i = 0; i < input.size(); ++i) {
208 if (input[i] == '&') {
209 memcpy(out, kAmp, strlen(kAmp));
210 out += strlen(kAmp);
211 } else if (input[i] == '<') {
212 memcpy(out, kLt, strlen(kLt));
213 out += strlen(kLt);
214 } else {
215 *out++ = input[i];
216 }
217 }
218 if (after) {
219 strncpy(out, after, afterLen);
220 out += afterLen;
221 }
222 // Validate that we haven't written outside of our string.
223 SkASSERT(out == &output.data()[output.size()]);
224 *out = '\0';
225 return output;
226}
#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 122 of file SkPDFMetadata.cpp.

122 {
123 SkASSERT(inputPtr && *inputPtr);
124 SkASSERT(outputPtr && *outputPtr);
125 while (count-- > 0) {
126 uint8_t value = *(*inputPtr)++;
127 *(*outputPtr)++ = SkHexadecimalDigits::gLower[value >> 4];
128 *(*outputPtr)++ = SkHexadecimalDigits::gLower[value & 0xF];
129 }
130}
int count
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 22 of file SkPDFMetadata.cpp.

22 {
23 return u.fTimeZoneMinutes != v.fTimeZoneMinutes ||
24 u.fYear != v.fYear ||
25 u.fMonth != v.fMonth ||
26 u.fDayOfWeek != v.fDayOfWeek ||
27 u.fDay != v.fDay ||
28 u.fHour != v.fHour ||
29 u.fMinute != v.fMinute ||
30 u.fSecond != v.fSecond;
31}
uint8_t fMinute
0..59
uint8_t fMonth
1..12
uint8_t fDay
1..31
uint16_t fYear
e.g. 2005
uint8_t fSecond
0..59
int16_t fTimeZoneMinutes
uint8_t fHour
0..23
uint8_t fDayOfWeek
0..6, 0==Sunday

◆ pdf_date()

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

Definition at line 33 of file SkPDFMetadata.cpp.

33 {
34 int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes);
35 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-';
36 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60;
37 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60;
38 return SkStringPrintf(
39 "D:%04u%02u%02u%02u%02u%02u%c%02d'%02d'",
40 static_cast<unsigned>(dt.fYear), static_cast<unsigned>(dt.fMonth),
41 static_cast<unsigned>(dt.fDay), static_cast<unsigned>(dt.fHour),
42 static_cast<unsigned>(dt.fMinute),
43 static_cast<unsigned>(dt.fSecond), timezoneSign, timeZoneHours,
44 timeZoneMinutes);
45}
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
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 132 of file SkPDFMetadata.cpp.

132 {
133 // 8-4-4-4-12
134 char buffer[36]; // [32 + 4]
135 char* ptr = buffer;
136 const uint8_t* data = uuid.fData;
137 hexify(&data, &ptr, 4);
138 *ptr++ = '-';
139 hexify(&data, &ptr, 2);
140 *ptr++ = '-';
141 hexify(&data, &ptr, 2);
142 *ptr++ = '-';
143 hexify(&data, &ptr, 2);
144 *ptr++ = '-';
145 hexify(&data, &ptr, 6);
146 SkASSERT(ptr == buffer + 36);
147 SkASSERT(data == uuid.fData + 16);
148 return SkString(buffer, 36);
149}
static void hexify(const uint8_t **inputPtr, char **outputPtr, int count)
static const uint8_t buffer[]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
uint8_t fData[16]
Definition SkUUID.h:10

Variable Documentation

◆ kZeroTime

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

Definition at line 20 of file SkPDFMetadata.cpp.

20{0, 0, 0, 0, 0, 0, 0, 0};