295 {
298 if (!metricsPtr) {
299 return;
300 }
306
308 uint16_t emSize =
SkToU16(
font.typeface()->getUnitsPerEm());
310
311 int ttcIndex;
312 std::unique_ptr<SkStreamAsset> fontAsset = face->
openStream(&ttcIndex);
313 size_t fontSize = fontAsset ? fontAsset->getLength() : 0;
314 if (0 == fontSize) {
315 SkDebugf(
"Error: (SkTypeface)(%p)::openStream() returned "
316 "empty stream (%p) when identified as kType1CID_Font "
317 "or kTrueType_Font.\n", face, fontAsset.get());
320 {
325 }
326 std::unique_ptr<SkStreamAsset> subsetFontAsset;
327 if (subsetFontData) {
329 } else {
330
331 subsetFontAsset = std::move(fontAsset);
332 }
334 streamDict->insertInt("Length1", subsetFontAsset->getLength());
335 const char* fontFileKey;
337 fontFileKey = "FontFile2";
338 } else {
339 streamDict->insertName("Subtype", "OpenType");
340 fontFileKey = "FontFile3";
341 }
342 descriptor->insertRef(fontFileKey,
347 streamDict->insertName("Subtype", "CIDFontType0C");
348 descriptor->insertRef("FontFile3",
351 } else {
353 }
354
356 newCIDFont->insertRef(
"FontDescriptor", doc->
emit(*descriptor));
358
361 newCIDFont->insertName("Subtype", "CIDFontType0");
362 break;
364 newCIDFont->insertName("Subtype", "CIDFontType0");
365 newCIDFont->insertName("CIDToGIDMap", "Identity");
366 break;
368 newCIDFont->insertName("Subtype", "CIDFontType2");
369 newCIDFont->insertName("CIDToGIDMap", "Identity");
370 break;
371 default:
373 }
375
376 sysInfo->insertByteString("Registry", "Adobe");
377 sysInfo->insertByteString("Ordering", "Identity");
378 sysInfo->insertInt("Supplement", 0);
379 newCIDFont->insertObject("CIDSystemInfo", std::move(sysInfo));
380
381
382 int32_t defaultWidth = 0;
383 {
385 *face,
font.glyphUsage(), &defaultWidth);
387 newCIDFont->insertObject(
"W", std::move(
widths));
388 }
389 newCIDFont->insertInt("DW", defaultWidth);
390 }
391
392
393
395 fontDict.insertName("Subtype", "Type0");
397 fontDict.insertName("Encoding", "Identity-H");
399 descendantFonts->appendRef(doc->
emit(*newCIDFont));
400 fontDict.insertObject("DescendantFonts", std::move(descendantFonts));
401
402 const std::vector<SkUnichar>& glyphToUnicode =
405 std::unique_ptr<SkStreamAsset> toUnicode =
408 font.multiByteGlyphs(),
411 fontDict.insertRef(
"ToUnicode",
SkPDFStreamOut(
nullptr, std::move(toUnicode), doc));
412
413 doc->
emit(fontDict,
font.indirectReference());
414}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool can_subset(const SkAdvancedTypefaceMetrics &metrics)
static bool can_embed(const SkAdvancedTypefaceMetrics &metrics)
std::unique_ptr< SkPDFArray > SkPDFMakeCIDGlyphWidthsArray(const SkTypeface &typeface, const SkPDFGlyphUse &subset, int32_t *defaultAdvance)
std::unique_ptr< SkStreamAsset > SkPDFMakeToUnicodeCmap(const SkUnichar *glyphToUnicode, const SkPDFGlyphUse *subset, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID)
sk_sp< SkData > SkPDFSubsetFont(const SkTypeface &, const SkPDFGlyphUse &)
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)
constexpr size_t SkToSizeT(S x)
constexpr uint16_t SkToU16(S x)
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
SkPDFIndirectReference emit(const SkPDFObject &, SkPDFIndirectReference)
static const SkAdvancedTypefaceMetrics * GetMetrics(const SkTypeface *typeface, SkPDFDocument *canon)
static void PopulateCommonFontDescriptor(SkPDFDict *descriptor, const SkAdvancedTypefaceMetrics &, uint16_t emSize, int16_t defaultWidth)
static const std::vector< SkUnichar > & GetUnicodeMap(const SkTypeface *typeface, SkPDFDocument *canon)
std::unique_ptr< SkStreamAsset > openStream(int *ttcIndex) const
font
Font Metadata and Metrics.