Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkPDFType1Font.h File Reference
#include "src/pdf/SkPDFDocumentPriv.h"
#include "src/pdf/SkPDFFont.h"

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 287 of file SkPDFType1Font.cpp.

287 {
288 SkTypeface* typeface = pdfFont.typeface();
289 const std::vector<SkString>& glyphNames = type_1_glyphnames(doc, typeface);
290 SkGlyphID firstGlyphID = pdfFont.firstGlyphID();
291 SkGlyphID lastGlyphID = pdfFont.lastGlyphID();
292
293 SkPDFDict font("Font");
294 font.insertRef("FontDescriptor", type1_font_descriptor(doc, typeface));
295 font.insertName("Subtype", "Type1");
296 if (const SkAdvancedTypefaceMetrics* info = SkPDFFont::GetMetrics(typeface, doc)) {
297 font.insertName("BaseFont", info->fPostScriptName);
298 }
299
300 // glyphCount not including glyph 0
301 unsigned glyphCount = 1 + lastGlyphID - firstGlyphID;
302 SkASSERT(glyphCount > 0 && glyphCount <= 255);
303 font.insertInt("FirstChar", (size_t)0);
304 font.insertInt("LastChar", (size_t)glyphCount);
305 {
306 int emSize;
307 auto widths = SkPDFMakeArray();
308
309 int glyphRangeSize = lastGlyphID - firstGlyphID + 2;
310 AutoTArray<SkGlyphID> glyphIDs{glyphRangeSize};
311 glyphIDs[0] = 0;
312 for (unsigned gId = firstGlyphID; gId <= lastGlyphID; gId++) {
313 glyphIDs[gId - firstGlyphID + 1] = gId;
314 }
315 SkStrikeSpec strikeSpec = SkStrikeSpec::MakePDFVector(*typeface, &emSize);
316 SkBulkGlyphMetrics metrics{strikeSpec};
317 auto glyphs = metrics.glyphs(SkSpan(glyphIDs.get(), glyphRangeSize));
318 for (int i = 0; i < glyphRangeSize; ++i) {
319 widths->appendScalar(from_font_units(glyphs[i]->advanceX(), SkToU16(emSize)));
320 }
321 font.insertObject("Widths", std::move(widths));
322 }
323 auto encDiffs = SkPDFMakeArray();
324 encDiffs->reserve(lastGlyphID - firstGlyphID + 3);
325 encDiffs->appendInt(0);
326
327 SkASSERT(glyphNames.size() > lastGlyphID);
328 const SkString unknown("UNKNOWN");
329 encDiffs->appendName(glyphNames[0].isEmpty() ? unknown : glyphNames[0]);
330 for (int gID = firstGlyphID; gID <= lastGlyphID; gID++) {
331 encDiffs->appendName(glyphNames[gID].isEmpty() ? unknown : glyphNames[gID]);
332 }
333
334 auto encoding = SkPDFMakeDict("Encoding");
335 encoding->insertObject("Differences", std::move(encDiffs));
336 font.insertObject("Encoding", std::move(encoding));
337
338 doc->emit(font, pdfFont.indirectReference());
339}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
uint16_t glyphs[5]
#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:195
static std::unique_ptr< SkPDFArray > SkPDFMakeArray(Args... args)
Definition SkPDFTypes.h:135
constexpr uint16_t SkToU16(S x)
Definition SkTo.h:24
uint16_t SkGlyphID
Definition SkTypes.h:179
const SkScalar widths[]
SkPDFIndirectReference emit(const SkPDFObject &, SkPDFIndirectReference)
static const SkAdvancedTypefaceMetrics * GetMetrics(const SkTypeface *typeface, SkPDFDocument *canon)
SkPDFIndirectReference indirectReference() const
Definition SkPDFFont.h:81
SkGlyphID lastGlyphID() const
Definition SkPDFFont.h:119
SkGlyphID firstGlyphID() const
Definition SkPDFFont.h:118
SkTypeface * typeface() const
Definition SkPDFFont.h:39
static SkStrikeSpec MakePDFVector(const SkTypeface &typeface, int *size)
font
Font Metadata and Metrics.