💿🐜 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.

153 lines
4.1 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_TYPEFACE_HPP
  20. #define ANTKEEPER_TYPE_TYPEFACE_HPP
  21. #include "type/font-metrics.hpp"
  22. #include "type/glyph-metrics.hpp"
  23. #include "resources/image.hpp"
  24. #include "utility/fundamental-types.hpp"
  25. namespace type {
  26. /// Emumerates typeface styles.
  27. enum class typeface_style
  28. {
  29. /// Normal typeface style.
  30. normal,
  31. /// Italic typeface style.
  32. italic,
  33. /// Oblique typeface style.
  34. oblique
  35. };
  36. /**
  37. * Abstract base class for a typeface, which corresponds to a single digital font file.
  38. *
  39. * @see type::font
  40. */
  41. class typeface
  42. {
  43. public:
  44. /**
  45. * Creates a typeface, setting its style and weight.
  46. *
  47. * @param style Typeface style.
  48. * @param weight Typeface weight.
  49. */
  50. typeface(typeface_style style, int weight);
  51. /// Creates an empty typeface.
  52. typeface();
  53. /// Destroys a typeface.
  54. virtual ~typeface() = default;
  55. /**
  56. * Sets the style of the typeface.
  57. *
  58. * @param style Typeface style.
  59. */
  60. void set_style(typeface_style style);
  61. /**
  62. * Sets the weight of the typeface.
  63. *
  64. * @param weight Typeface weight.
  65. */
  66. void set_weight(int weight);
  67. /// Returns the style of the typeface.
  68. typeface_style get_style() const;
  69. /// Returns the weight of the typeface.
  70. int get_weight() const;
  71. /// Returns `true` if the typeface contains kerning information, `false` otherwise.
  72. virtual bool has_kerning() const = 0;
  73. /**
  74. * Returns `true` if the typeface contains a glyph, `false` otherwise.
  75. *
  76. * @param code UTF-32 character code of a glyph.
  77. * @return `true` if the typeface contains the glyph, `false` otherwise.
  78. */
  79. virtual bool has_glyph(char32_t code) const = 0;
  80. /**
  81. * Gets metrics for a font of the specified size.
  82. *
  83. * @param[in] height Height of the font, in pixels.
  84. * @param[out] metrics Font metrics.
  85. * @return `true` if font metrics were returned, `false` otherwise.
  86. */
  87. virtual bool get_metrics(float height, font_metrics& metrics) const = 0;
  88. /**
  89. * Gets metrics for a glyph in a font of the specified size.
  90. *
  91. * @param[in] height Height of the font, in pixels.
  92. * @param[in] code UTF-32 character code of a glyph.
  93. * @param[out] metrics Glyph metrics.
  94. * @return `true` if glyph metrics were returned, `false` otherwise.
  95. */
  96. virtual bool get_metrics(float height, char32_t code, glyph_metrics& metrics) const = 0;
  97. /**
  98. * Gets a bitmap of a glyph in a font of the specified size.
  99. *
  100. * @param[in] height Height of the font, in pixels.
  101. * @param[in] code UTF-32 character code of a glyph.
  102. * @param[out] bitmap Glyph bitmap data.
  103. * @return `true` if glyph bitmap data was returned, `false` otherwise.
  104. */
  105. virtual bool get_bitmap(float height, char32_t code, image& bitmap) const = 0;
  106. /**
  107. * Gets the kerning offset for a pair of glyphs.
  108. *
  109. * @param[in] height Height of the font, in pixels.
  110. * @param[in] first UTF-32 character code of the first glyph.
  111. * @param[in] second UTF-32 character code of the second glyph.
  112. * @param[out] offset Kerning offset.
  113. * @return `true` if a kerning offset was returned, `false` otherwise.
  114. */
  115. virtual bool get_kerning(float height, char32_t first, char32_t second, float2& offset) const = 0;
  116. private:
  117. typeface_style style;
  118. int weight;
  119. };
  120. inline typeface_style typeface::get_style() const
  121. {
  122. return style;
  123. }
  124. inline int typeface::get_weight() const
  125. {
  126. return weight;
  127. }
  128. } // namespace type
  129. #endif // ANTKEEPER_TYPE_TYPEFACE_HPP