import-font.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <cstdlib>
  3. #include "../core/Shape.h"
  4. namespace msdfgen {
  5. typedef unsigned unicode_t;
  6. class FreetypeHandle;
  7. class FontHandle;
  8. class GlyphIndex {
  9. public:
  10. explicit GlyphIndex(unsigned index = 0);
  11. unsigned getIndex() const;
  12. bool operator!() const;
  13. private:
  14. unsigned index;
  15. };
  16. /// Global metrics of a typeface (in font units).
  17. struct FontMetrics {
  18. /// The size of one EM.
  19. double emSize;
  20. /// The vertical position of the ascender and descender relative to the baseline.
  21. double ascenderY, descenderY;
  22. /// The vertical difference between consecutive baselines.
  23. double lineHeight;
  24. /// The vertical position and thickness of the underline.
  25. double underlineY, underlineThickness;
  26. };
  27. /// Initializes the FreeType library.
  28. FreetypeHandle * initializeFreetype();
  29. /// Deinitializes the FreeType library.
  30. void deinitializeFreetype(FreetypeHandle *library);
  31. #ifdef FT_FREETYPE_H
  32. /// Creates a FontHandle from FT_Face that was loaded by the user. destroyFont must still be called but will not affect the FT_Face.
  33. FontHandle * adoptFreetypeFont(FT_Face ftFace);
  34. #endif
  35. /// Loads a font file and returns its handle.
  36. FontHandle * loadFont(FreetypeHandle *library, const char *filename);
  37. /// Unloads a font file.
  38. void destroyFont(FontHandle *font);
  39. /// Outputs the metrics of a font file.
  40. bool getFontMetrics(FontMetrics &metrics, FontHandle *font);
  41. /// Outputs the width of the space and tab characters.
  42. bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font);
  43. /// Outputs the glyph index corresponding to the specified Unicode character.
  44. bool getGlyphIndex(GlyphIndex &glyphIndex, FontHandle *font, unicode_t unicode);
  45. /// Loads the geometry of a glyph from a font file.
  46. bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *advance = NULL);
  47. bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance = NULL);
  48. /// Outputs the kerning distance adjustment between two specific glyphs.
  49. bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2);
  50. bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2);
  51. }