💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.9 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_TYPE_FONT_HPP
  20. #define ANTKEEPER_TYPE_FONT_HPP
  21. #include "type/kerning-table.hpp"
  22. #include "type/font-metrics.hpp"
  23. #include "type/glyph-metrics.hpp"
  24. namespace type {
  25. /**
  26. * Abstract base class for fonts.
  27. *
  28. * @see type::font_metrics
  29. * @see type::glyph_metrics
  30. * @see type::bitmap_font
  31. */
  32. class font
  33. {
  34. public:
  35. /**
  36. * Creates a font and sets its metrics.
  37. *
  38. * @param metrics Metrics describing the font.
  39. */
  40. font(const font_metrics& metrics);
  41. /// Creates an empty font.
  42. font();
  43. /// Destroys a font.
  44. virtual ~font();
  45. /**
  46. * Returns `true` if the font contains a glyph with the given character code.
  47. *
  48. * @param code UTF-32 character code of a glyph.
  49. * @return `true` if the font contains the glyph, `false` otherwise.
  50. */
  51. virtual bool contains(char32_t code) const = 0;
  52. /**
  53. * Sets the kerning offset for a pair of glyphs.
  54. *
  55. * @param first UTF-32 character code of the first glyph.
  56. * @param second UTF-32 character code of the second glyph.
  57. * @param offset Kerning offset.
  58. */
  59. void kern(char32_t first, char32_t second, const float2& offset);
  60. /**
  61. * Sets the font metrics
  62. *
  63. * @param metrics Font metrics.
  64. */
  65. void set_font_metrics(const font_metrics& metrics);
  66. /**
  67. * Returns metrics describing a glyph.
  68. *
  69. * @param code UTF-32 character code of a glyph.
  70. * @return Metrics describing the glyph.
  71. */
  72. virtual const glyph_metrics& get_glyph_metrics(char32_t code) const = 0;
  73. /**
  74. * Returns the kerning offset for a pair of glyphs.
  75. *
  76. * @param first UTF-32 character code of the first glyph.
  77. * @param second UTF-32 character code of the second glyph.
  78. * @return Kerning offset.
  79. */
  80. const float2& get_kerning(char32_t first, char32_t second) const;
  81. /// Returns the font's kerning table.
  82. const kerning_table& get_kerning_table() const;
  83. /// Returns metrics describing the font.
  84. const font_metrics& get_font_metrics() const;
  85. protected:
  86. font_metrics metrics;
  87. kerning_table kerning_table;
  88. };
  89. inline const kerning_table& font::get_kerning_table() const
  90. {
  91. return kerning_table;
  92. }
  93. inline const font_metrics& font::get_font_metrics() const
  94. {
  95. return metrics;
  96. }
  97. } // namespace type
  98. #endif // ANTKEEPER_TYPE_FONT_HPP