51 const uint8_t* buf = *
src;
52 if (*
len < 2 || buf[0] != 0x80 || buf[1] != sectionType) {
54 }
else if (buf[1] == 3) {
56 }
else if (*
len < 6) {
60 *
size = (size_t)buf[2] | ((
size_t)buf[3] << 8) | ((
size_t)buf[4] << 16) |
61 ((
size_t)buf[5] << 24);
62 size_t consumed = *
size + 6;
63 if (consumed > *
len) {
72 size_t* dataLen,
size_t* trailerLen) {
73 const uint8_t* srcPtr =
src;
74 size_t remaining =
size;
91 size_t* hexDataLen,
size_t* dataLen,
size_t* trailerLen) {
94 const char* dataPos = strstr(
src,
"eexec");
98 dataPos += strlen(
"eexec");
99 while ((*dataPos ==
'\n' || *dataPos ==
'\r' || *dataPos ==
' ') &&
103 *headerLen = dataPos -
src;
105 const char* trailerPos = strstr(dataPos,
"cleartomark");
110 for (trailerPos--; trailerPos > dataPos && zeroCount < 512; trailerPos--) {
111 if (*trailerPos ==
'\n' || *trailerPos ==
'\r' || *trailerPos ==
' ') {
113 }
else if (*trailerPos ==
'0') {
119 if (zeroCount != 512) {
123 *hexDataLen = trailerPos -
src - *headerLen;
124 *trailerLen =
size - *headerLen - *hexDataLen;
128 for (; dataPos < trailerPos; dataPos++) {
129 if (isspace(*dataPos)) {
133 if (
nullptr == strchr(
"0123456789abcdefABCDEF", *dataPos)) {
138 *dataLen = (nibbles + 1) / 2;
146 }
else if (c <=
'9') {
148 }
else if (c <=
'F') {
150 }
else if (c <=
'f') {
159 size_t* trailerLen) {
160 size_t srcLen = srcStream ? srcStream->getLength() : 0;
168 (void)srcStream->read(sourceBuffer.
get(), srcLen);
169 sourceBuffer[
SkToInt(srcLen)] = 0;
170 const uint8_t*
src = sourceBuffer.
get();
172 if (
parsePFB(
src, srcLen, headerLen, dataLen, trailerLen)) {
173 static const int kPFBSectionHeaderLength = 6;
174 const size_t length = *headerLen + *dataLen + *trailerLen;
180 const uint8_t*
const srcHeader =
src + kPFBSectionHeaderLength;
183 const uint8_t*
const srcData = srcHeader + *headerLen + kPFBSectionHeaderLength;
184 const uint8_t*
const srcTrailer = srcData + *headerLen;
186 uint8_t*
const resultHeader = (uint8_t*)
data->writable_data();
187 uint8_t*
const resultData = resultHeader + *headerLen;
188 uint8_t*
const resultTrailer = resultData + *dataLen;
192 memcpy(resultHeader, srcHeader, *headerLen);
193 memcpy(resultData, srcData, *dataLen);
194 memcpy(resultTrailer, srcTrailer, *trailerLen);
201 if (!
parsePFA((
const char*)
src, srcLen, headerLen, &hexDataLen, dataLen,
205 const size_t length = *headerLen + *dataLen + *trailerLen;
208 uint8_t*
buffer = (uint8_t*)
data->writable_data();
211 uint8_t*
const resultData = &(
buffer[*headerLen]);
213 const uint8_t* hexData =
src + *headerLen;
214 const uint8_t* trailer = hexData + hexDataLen;
215 size_t outputOffset = 0;
216 uint8_t dataByte = 0;
217 bool highNibble =
true;
218 for (; hexData < trailer; hexData++) {
219 int8_t curNibble =
hexToBin(*hexData);
224 dataByte = curNibble << 4;
227 dataByte |= curNibble;
229 resultData[outputOffset++] = dataByte;
233 resultData[outputOffset++] = dataByte;
237 uint8_t*
const resultTrailer = &(
buffer[
SkToInt(*headerLen + outputOffset)]);
238 memcpy(resultTrailer,
src + *headerLen + hexDataLen, *trailerLen);
247 return emSize == 1000 ? scaled : scaled * 1000 / emSize;
262 std::unique_ptr<SkStreamAsset> rawFontData = typeface->
openStream(&ttcIndex);
267 dict->insertInt(
"Length1",
header);
268 dict->insertInt(
"Length2",
data);
269 dict->insertInt(
"Length3", trailer);
277 return doc->
emit(descriptor);
303 return fontDescriptor;
315 font.insertName(
"Subtype",
"Type1");
317 font.insertName(
"BaseFont",
info->fPostScriptName);
321 unsigned glyphCount = 1 + lastGlyphID - firstGlyphID;
322 SkASSERT(glyphCount > 0 && glyphCount <= 255);
323 font.insertInt(
"FirstChar", (
size_t)0);
324 font.insertInt(
"LastChar", (
size_t)glyphCount);
329 int glyphRangeSize = lastGlyphID - firstGlyphID + 2;
332 for (
unsigned gId = firstGlyphID; gId <= lastGlyphID; gId++) {
333 glyphIDs[gId - firstGlyphID + 1] = gId;
337 auto glyphs = metrics.glyphs(
SkSpan(glyphIDs.get(), glyphRangeSize));
338 for (
int i = 0;
i < glyphRangeSize; ++
i) {
341 font.insertObject(
"Widths", std::move(
widths));
344 encDiffs->reserve(lastGlyphID - firstGlyphID + 3);
345 encDiffs->appendInt(0);
347 SkASSERT(glyphNames.size() > lastGlyphID);
349 encDiffs->appendName(glyphNames[0].isEmpty() ? unknown : glyphNames[0]);
350 for (
int gID = firstGlyphID; gID <= lastGlyphID; gID++) {
351 encDiffs->appendName(glyphNames[gID].isEmpty() ? unknown : glyphNames[gID]);
355 encoding->insertObject(
"Differences", std::move(encDiffs));
356 font.insertObject(
"Encoding", std::move(encoding));
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SK_INIT_TO_AVOID_WARNING
static bool parsePFBSection(const uint8_t **src, size_t *len, int sectionType, size_t *size)
static const std::vector< SkString > & type_1_glyphnames(SkPDFDocument *canon, const SkTypeface *typeface)
static sk_sp< SkData > convert_type1_font_stream(std::unique_ptr< SkStreamAsset > srcStream, size_t *headerLen, size_t *dataLen, size_t *trailerLen)
void SkPDFEmitType1Font(const SkPDFFont &pdfFont, SkPDFDocument *doc)
static SkPDFIndirectReference make_type1_font_descriptor(SkPDFDocument *doc, const SkTypeface *typeface, const SkAdvancedTypefaceMetrics *info)
static bool parsePFB(const uint8_t *src, size_t size, size_t *headerLen, size_t *dataLen, size_t *trailerLen)
static SkScalar from_font_units(SkScalar scaled, uint16_t emSize)
static bool parsePFA(const char *src, size_t size, size_t *headerLen, size_t *hexDataLen, size_t *dataLen, size_t *trailerLen)
static bool can_embed(const SkAdvancedTypefaceMetrics &metrics)
static int8_t hexToBin(uint8_t c)
static SkPDFIndirectReference type1_font_descriptor(SkPDFDocument *doc, const SkTypeface *typeface)
SkPDFIndirectReference SkPDFStreamOut(std::unique_ptr< SkPDFDict > dict, std::unique_ptr< SkStreamAsset > content, SkPDFDocument *doc, SkPDFSteamCompressionEnabled compress)
static std::unique_ptr< SkPDFDict > SkPDFMakeDict(const char *type=nullptr)
static std::unique_ptr< SkPDFArray > SkPDFMakeArray(Args... args)
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
constexpr uint16_t SkToU16(S x)
constexpr int SkToInt(S x)
static constexpr bool SkToBool(const T &x)
static sk_sp< SkData > MakeUninitialized(size_t length)
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
void insertRef(const char key[], SkPDFIndirectReference)
SkPDFIndirectReference emit(const SkPDFObject &, SkPDFIndirectReference)
skia_private::THashMap< uint32_t, SkPDFIndirectReference > fFontDescriptors
skia_private::THashMap< uint32_t, std::vector< SkString > > fType1GlyphNames
static const SkAdvancedTypefaceMetrics * GetMetrics(const SkTypeface *typeface, SkPDFDocument *canon)
static void PopulateCommonFontDescriptor(SkPDFDict *descriptor, const SkAdvancedTypefaceMetrics &, uint16_t emSize, int16_t defaultWidth)
SkPDFIndirectReference indirectReference() const
SkGlyphID lastGlyphID() const
SkGlyphID firstGlyphID() const
static void GetType1GlyphNames(const SkTypeface &, SkString *)
SkTypeface * typeface() const
static SkStrikeSpec MakePDFVector(const SkTypeface &typeface, int *size)
SkTypefaceID uniqueID() const
int getUnitsPerEm() const
std::unique_ptr< SkStreamAsset > openStream(int *ttcIndex) const
V * find(const K &key) const
static const char *const names[]
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
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
font
Font Metadata and Metrics.
static const char header[]
@ kNotEmbeddable_FontFlag
May not be embedded.
std::shared_ptr< const fml::Mapping > data