2
0

FontFaceHandle.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUICOREBITMAPFONTFONTFACEHANDLE_H
  29. #define RMLUICOREBITMAPFONTFONTFACEHANDLE_H
  30. #include "../UnicodeRange.h"
  31. #include "../../../Include/RmlUi/Core/Font.h"
  32. #include "../../../Include/RmlUi/Core/FontEffect.h"
  33. #include "../../../Include/RmlUi/Core/FontGlyph.h"
  34. #include "../../../Include/RmlUi/Core/Geometry.h"
  35. #include "../../../Include/RmlUi/Core/String.h"
  36. #include "../../../Include/RmlUi/Core/Texture.h"
  37. #include "../FontFaceHandle.h"
  38. #include "BitmapFontDefinitions.h"
  39. namespace Rml {
  40. namespace Core {
  41. namespace BitmapFont {
  42. /**
  43. @author Peter Curry
  44. */
  45. class FontFaceHandle : public Rml::Core::FontFaceHandle
  46. {
  47. public:
  48. FontFaceHandle();
  49. virtual ~FontFaceHandle();
  50. /// Initialises the handle so it is able to render text.
  51. /// @param[in] ft_face The FreeType face that this handle is rendering.
  52. /// @param[in] charset The comma-separated list of unicode ranges this handle must support.
  53. /// @param[in] size The size, in points, of the face this handle should render at.
  54. /// @return True if the handle initialised successfully and is ready for rendering, false if an error occured.
  55. bool Initialise(BitmapFontDefinitions *bm_face, const String& charset, int size);
  56. /// Returns the width a string will take up if rendered with this handle.
  57. /// @param[in] string The string to measure.
  58. /// @param[in] prior_character The optionally-specified character that immediately precedes the string. This may have an impact on the string width due to kerning.
  59. /// @return The width, in pixels, this string will occupy if rendered with this handle.
  60. int GetStringWidth(const WString& string, word prior_character = 0) const;
  61. /// Generates, if required, the layer configuration for a given array of font effects.
  62. /// @param[in] font_effects The list of font effects to generate the configuration for.
  63. /// @return The index to use when generating geometry using this configuration.
  64. int GenerateLayerConfiguration(Rml::Core::FontEffectMap& font_effects);
  65. /// Generates the texture data for a layer (for the texture database).
  66. /// @param[out] texture_data The pointer to be set to the generated texture data.
  67. /// @param[out] texture_dimensions The dimensions of the texture.
  68. /// @param[in] layer_id The id of the layer to request the texture data from.
  69. /// @param[in] texture_id The index of the texture within the layer to generate.
  70. bool GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, FontEffect* layer_id, int texture_id);
  71. /// Generates the geometry required to render a single line of text.
  72. /// @param[out] geometry An array of geometries to generate the geometry into.
  73. /// @param[in] string The string to render.
  74. /// @param[in] position The position of the baseline of the first character to render.
  75. /// @param[in] colour The colour to render the text.
  76. /// @return The width, in pixels, of the string geometry.
  77. int GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration = 0) const;
  78. /// Generates the geometry required to render a line above, below or through a line of text.
  79. /// @param[out] geometry The geometry to append the newly created geometry into.
  80. /// @param[in] position The position of the baseline of the lined text.
  81. /// @param[in] width The width of the string to line.
  82. /// @param[in] height The height to render the line at.
  83. /// @param[in] colour The colour to draw the line in.
  84. void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const;
  85. const String & GetTextureSource() const
  86. {
  87. return texture_source;
  88. }
  89. unsigned int GetTextureWidth() const
  90. {
  91. return texture_width;
  92. }
  93. unsigned int GetTextureHeight() const
  94. {
  95. return texture_height;
  96. }
  97. protected:
  98. /// Destroys the handle.
  99. virtual void OnReferenceDeactivate();
  100. private:
  101. void GenerateMetrics(BitmapFontDefinitions *bm_face);
  102. void BuildGlyphMap(BitmapFontDefinitions *bm_face, const UnicodeRange& unicode_range);
  103. void BuildGlyph(FontGlyph& glyph, CharacterInfo *ft_glyph);
  104. int GetKerning(word lhs, word rhs) const;
  105. // Generates (or shares) a layer derived from a font effect.
  106. virtual FontFaceLayer* GenerateLayer(FontEffect* font_effect);
  107. BitmapFontDefinitions * bm_face;
  108. String texture_source;
  109. String texture_directory;
  110. unsigned int texture_width;
  111. unsigned int texture_height;
  112. };
  113. }
  114. }
  115. }
  116. #endif