import-font.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include "../core/Shape.h"
  3. namespace msdfgen {
  4. typedef unsigned unicode_t;
  5. class FreetypeHandle;
  6. class FontHandle;
  7. class GlyphIndex {
  8. public:
  9. explicit GlyphIndex(unsigned index = 0);
  10. unsigned getIndex() const;
  11. private:
  12. unsigned index;
  13. };
  14. /// Global metrics of a typeface (in font units).
  15. struct FontMetrics {
  16. /// The size of one EM.
  17. double emSize;
  18. /// The vertical position of the ascender and descender relative to the baseline.
  19. double ascenderY, descenderY;
  20. /// The vertical difference between consecutive baselines.
  21. double lineHeight;
  22. /// The vertical position and thickness of the underline.
  23. double underlineY, underlineThickness;
  24. };
  25. /// A structure to model a given axis of a variable font.
  26. struct FontVariationAxis {
  27. /// The name of the variation axis.
  28. const char *name;
  29. /// The axis's minimum coordinate value.
  30. double minValue;
  31. /// The axis's maximum coordinate value.
  32. double maxValue;
  33. /// The axis's default coordinate value. FreeType computes meaningful default values for Adobe MM fonts.
  34. double defaultValue;
  35. };
  36. /// Initializes the FreeType library.
  37. FreetypeHandle *initializeFreetype();
  38. /// Deinitializes the FreeType library.
  39. void deinitializeFreetype(FreetypeHandle *library);
  40. #ifdef FT_LOAD_DEFAULT // FreeType included
  41. /// Creates a FontHandle from FT_Face that was loaded by the user. destroyFont must still be called but will not affect the FT_Face.
  42. FontHandle *adoptFreetypeFont(FT_Face ftFace);
  43. /// Converts the geometry of FreeType's FT_Outline to a Shape object.
  44. FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline);
  45. #endif
  46. /// Loads a font file and returns its handle.
  47. FontHandle *loadFont(FreetypeHandle *library, const char *filename);
  48. /// Loads a font from binary data and returns its handle.
  49. FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length);
  50. /// Unloads a font.
  51. void destroyFont(FontHandle *font);
  52. /// Outputs the metrics of a font.
  53. bool getFontMetrics(FontMetrics &metrics, FontHandle *font);
  54. /// Outputs the width of the space and tab characters.
  55. bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font);
  56. /// Outputs the total number of glyphs available in the font.
  57. bool getGlyphCount(unsigned &output, FontHandle *font);
  58. /// Outputs the glyph index corresponding to the specified Unicode character.
  59. bool getGlyphIndex(GlyphIndex &glyphIndex, FontHandle *font, unicode_t unicode);
  60. /// Loads the geometry of a glyph from a font.
  61. bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *advance = NULL);
  62. bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance = NULL);
  63. /// Outputs the kerning distance adjustment between two specific glyphs.
  64. bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1);
  65. bool getKerning(double &output, FontHandle *font, unicode_t unicode0, unicode_t unicode1);
  66. #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
  67. /// Sets a single variation axis of a variable font.
  68. bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate);
  69. /// Lists names and ranges of variation axes of a variable font.
  70. bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle *library, FontHandle *font);
  71. #endif
  72. }