import-font.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 file.
  51. void destroyFont(FontHandle *font);
  52. /// Outputs the metrics of a font file.
  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 glyph index corresponding to the specified Unicode character.
  57. bool getGlyphIndex(GlyphIndex &glyphIndex, FontHandle *font, unicode_t unicode);
  58. /// Loads the geometry of a glyph from a font file.
  59. bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *advance = NULL);
  60. bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance = NULL);
  61. /// Outputs the kerning distance adjustment between two specific glyphs.
  62. bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2);
  63. bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2);
  64. #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
  65. /// Sets a single variation axis of a variable font.
  66. bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate);
  67. /// Lists names and ranges of variation axes of a variable font.
  68. bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle *library, FontHandle *font);
  69. #endif
  70. }