Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Functions
SkPDFType1Font.h File Reference

Go to the source code of this file.

Functions

void SkPDFEmitType1Font (const SkPDFFont &, SkPDFDocument *)
 

Function Documentation

◆ SkPDFEmitType1Font()

void SkPDFEmitType1Font ( const SkPDFFont pdfFont,
SkPDFDocument doc 
)

Definition at line 307 of file SkPDFType1Font.cpp.

307 {
308 SkTypeface* typeface = pdfFont.typeface();
309 const std::vector<SkString>& glyphNames = type_1_glyphnames(doc, typeface);
310 SkGlyphID firstGlyphID = pdfFont.firstGlyphID();
311 SkGlyphID lastGlyphID = pdfFont.lastGlyphID();
312
313 SkPDFDict font("Font");
314 font.insertRef("FontDescriptor", type1_font_descriptor(doc, typeface));
315 font.insertName("Subtype", "Type1");
316 if (const SkAdvancedTypefaceMetrics* info = SkPDFFont::GetMetrics(typeface, doc)) {
317 font.insertName("BaseFont", info->fPostScriptName);
318 }
319
320 // glyphCount not including glyph 0
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);
325 {
326 int emSize;
327 auto widths = SkPDFMakeArray();
328
329 int glyphRangeSize = lastGlyphID - firstGlyphID + 2;
330 AutoTArray<SkGlyphID> glyphIDs{glyphRangeSize};
331 glyphIDs[0] = 0;
332 for (unsigned gId = firstGlyphID; gId <= lastGlyphID; gId++) {
333 glyphIDs[gId - firstGlyphID + 1] = gId;
334 }
335 SkStrikeSpec strikeSpec = SkStrikeSpec::MakePDFVector(*typeface, &emSize);
336 SkBulkGlyphMetrics metrics{strikeSpec};
337 auto glyphs = metrics.glyphs(SkSpan(glyphIDs.get(), glyphRangeSize));
338 for (int i = 0; i < glyphRangeSize; ++i) {
339 widths->appendScalar(from_font_units(glyphs[i]->advanceX(), SkToU16(emSize)));
340 }
341 font.insertObject("Widths", std::move(widths));
342 }
343 auto encDiffs = SkPDFMakeArray();
344 encDiffs->reserve(lastGlyphID - firstGlyphID + 3);
345 encDiffs->appendInt(0);
346
347 SkASSERT(glyphNames.size() > lastGlyphID);
348 const SkString unknown("UNKNOWN");
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]);
352 }
353
354 auto encoding = SkPDFMakeDict("Encoding");
355 encoding->insertObject("Differences", std::move(encDiffs));
356 font.insertObject("Encoding", std::move(encoding));
357
358 doc->emit(font, pdfFont.indirectReference());
359}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
#define SkASSERT(cond)
Definition: SkAssert.h:116
static const std::vector< SkString > & type_1_glyphnames(SkPDFDocument *canon, const SkTypeface *typeface)
static SkScalar from_font_units(SkScalar scaled, uint16_t emSize)
static SkPDFIndirectReference type1_font_descriptor(SkPDFDocument *doc, const SkTypeface *typeface)
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
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
constexpr uint16_t SkToU16(S x)
Definition: SkTo.h:24
uint16_t SkGlyphID
Definition: SkTypes.h:179
const SkScalar widths[]
Definition: StrokerTest.cpp:39
SkPDFIndirectReference emit(const SkPDFObject &, SkPDFIndirectReference)
static const SkAdvancedTypefaceMetrics * GetMetrics(const SkTypeface *typeface, SkPDFDocument *canon)
Definition: SkPDFFont.cpp:118
SkPDFIndirectReference indirectReference() const
Definition: SkPDFFont.h:83
SkGlyphID lastGlyphID() const
Definition: SkPDFFont.h:121
SkGlyphID firstGlyphID() const
Definition: SkPDFFont.h:120
SkTypeface * typeface() const
Definition: SkPDFFont.h:41
static SkStrikeSpec MakePDFVector(const SkTypeface &typeface, int *size)
font
Font Metadata and Metrics.