diff --git a/ext/import-font.cpp b/ext/import-font.cpp index 0281fb1..352f1bb 100644 --- a/ext/import-font.cpp +++ b/ext/import-font.cpp @@ -37,11 +37,12 @@ class FontHandle { friend void destroyFont(FontHandle *font); friend bool getFontMetrics(FontMetrics &metrics, FontHandle *font); friend bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font); + friend bool getGlyphCount(unsigned &output, FontHandle *font); friend bool getGlyphIndex(GlyphIndex &glyphIndex, FontHandle *font, unicode_t unicode); friend bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *advance); friend bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance); - friend bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2); - friend bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2); + friend bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1); + friend bool getKerning(double &output, FontHandle *font, unicode_t unicode0, unicode_t unicode1); #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS friend bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate); friend bool listFontVariationAxes(std::vector &axes, FreetypeHandle *library, FontHandle *font); @@ -200,6 +201,11 @@ bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle return true; } +bool getGlyphCount(unsigned &output, FontHandle *font) { + output = (unsigned) font->face->num_glyphs; + return true; +} + bool getGlyphIndex(GlyphIndex &glyphIndex, FontHandle *font, unicode_t unicode) { glyphIndex = GlyphIndex(FT_Get_Char_Index(font->face, unicode)); return glyphIndex.getIndex() != 0; @@ -220,9 +226,9 @@ bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advan return loadGlyph(output, font, GlyphIndex(FT_Get_Char_Index(font->face, unicode)), advance); } -bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2) { +bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1) { FT_Vector kerning; - if (FT_Get_Kerning(font->face, glyphIndex1.getIndex(), glyphIndex2.getIndex(), FT_KERNING_UNSCALED, &kerning)) { + if (FT_Get_Kerning(font->face, glyphIndex0.getIndex(), glyphIndex1.getIndex(), FT_KERNING_UNSCALED, &kerning)) { output = 0; return false; } @@ -230,8 +236,8 @@ bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphI return true; } -bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2) { - return getKerning(output, font, GlyphIndex(FT_Get_Char_Index(font->face, unicode1)), GlyphIndex(FT_Get_Char_Index(font->face, unicode2))); +bool getKerning(double &output, FontHandle *font, unicode_t unicode0, unicode_t unicode1) { + return getKerning(output, font, GlyphIndex(FT_Get_Char_Index(font->face, unicode0)), GlyphIndex(FT_Get_Char_Index(font->face, unicode1))); } #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS diff --git a/ext/import-font.h b/ext/import-font.h index 292a7b8..1d796c9 100644 --- a/ext/import-font.h +++ b/ext/import-font.h @@ -61,20 +61,22 @@ FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline); FontHandle *loadFont(FreetypeHandle *library, const char *filename); /// Loads a font from binary data and returns its handle. FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length); -/// Unloads a font file. +/// Unloads a font. void destroyFont(FontHandle *font); -/// Outputs the metrics of a font file. +/// Outputs the metrics of a font. bool getFontMetrics(FontMetrics &metrics, FontHandle *font); /// Outputs the width of the space and tab characters. bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font); +/// Outputs the total number of glyphs available in the font. +bool getGlyphCount(unsigned &output, FontHandle *font); /// Outputs the glyph index corresponding to the specified Unicode character. bool getGlyphIndex(GlyphIndex &glyphIndex, FontHandle *font, unicode_t unicode); -/// Loads the geometry of a glyph from a font file. +/// Loads the geometry of a glyph from a font. bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *advance = NULL); bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance = NULL); /// Outputs the kerning distance adjustment between two specific glyphs. -bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2); -bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2); +bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1); +bool getKerning(double &output, FontHandle *font, unicode_t unicode0, unicode_t unicode1); #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS /// Sets a single variation axis of a variable font.