import-font.h 3.2 KB

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