import-font.h 2.3 KB

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