FontEngineInterface.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef RMLUI_CORE_FONTENGINEINTERFACE_H
  28. #define RMLUI_CORE_FONTENGINEINTERFACE_H
  29. #include "FontMetrics.h"
  30. #include "Header.h"
  31. #include "Mesh.h"
  32. #include "StyleTypes.h"
  33. #include "TextShapingContext.h"
  34. #include "Types.h"
  35. namespace Rml {
  36. /**
  37. The abstract base class for an application-specific font engine implementation.
  38. By default, RmlUi will use its own font engine with characters rendered through FreeType. To use your own engine,
  39. provide a concrete implementation of this class and install it through Rml::SetFontEngineInterface().
  40. */
  41. class RMLUICORE_API FontEngineInterface {
  42. public:
  43. FontEngineInterface();
  44. virtual ~FontEngineInterface();
  45. /// Called when RmlUi is being initialized.
  46. virtual void Initialize();
  47. /// Called when RmlUi is being shut down.
  48. virtual void Shutdown();
  49. /// Called by RmlUi when it wants to load a font face from file.
  50. /// @param[in] file_name The file to load the face from.
  51. /// @param[in] face_index The index of the font face within a font collection.
  52. /// @param[in] fallback_face True to use this font face for unknown characters in other font faces.
  53. /// @param[in] weight The weight to load when the font face contains multiple weights, otherwise the weight to register the font as.
  54. /// @return True if the face was loaded successfully, false otherwise.
  55. virtual bool LoadFontFace(const String& file_name, int face_index, bool fallback_face, Style::FontWeight weight);
  56. /// Called by RmlUi when it wants to load a font face from memory, registered using the provided family, style, and weight.
  57. /// @param[in] data The font data.
  58. /// @param[in] face_index The index of the font face within a font collection.
  59. /// @param[in] family The family to register the font as.
  60. /// @param[in] style The style to register the font as.
  61. /// @param[in] weight The weight to load when the font face contains multiple weights, otherwise the weight to register the font as.
  62. /// @param[in] fallback_face True to use this font face for unknown characters in other font faces.
  63. /// @return True if the face was loaded successfully, false otherwise.
  64. /// @note The debugger plugin will load its embedded font faces through this method using the family name 'rmlui-debugger-font'.
  65. virtual bool LoadFontFace(Span<const byte> data, int face_index, const String& family, Style::FontStyle style, Style::FontWeight weight, bool fallback_face);
  66. /// Called by RmlUi when a font configuration is resolved for an element. Should return a handle that
  67. /// can later be used to resolve properties of the face, and generate string geometry to be rendered.
  68. /// @param[in] family The family of the desired font handle.
  69. /// @param[in] style The style of the desired font handle.
  70. /// @param[in] weight The weight of the desired font handle.
  71. /// @param[in] size The size of desired handle, in points.
  72. /// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
  73. virtual FontFaceHandle GetFontFaceHandle(const String& family, Style::FontStyle style, Style::FontWeight weight, int size);
  74. /// Called by RmlUi when a list of font effects is resolved for an element with a given font face.
  75. /// @param[in] handle The font handle.
  76. /// @param[in] font_effects The list of font effects to generate the configuration for.
  77. /// @return A handle to the prepared font effects which will be used when generating geometry for a string.
  78. virtual FontEffectsHandle PrepareFontEffects(FontFaceHandle handle, const FontEffectList& font_effects);
  79. /// Should return the font metrics of the given font face.
  80. /// @param[in] handle The font handle.
  81. /// @return The face's metrics.
  82. virtual const FontMetrics& GetFontMetrics(FontFaceHandle handle);
  83. /// Called by RmlUi when it wants to retrieve the width of a string when rendered with this handle.
  84. /// @param[in] handle The font handle.
  85. /// @param[in] string The string to measure.
  86. /// @param[in] text_shaping_context Additional parameters that provide context for text shaping.
  87. /// @param[in] prior_character The optionally-specified character that immediately precedes the string. This may have an impact on the string
  88. /// width due to kerning.
  89. /// @return The width, in pixels, this string will occupy if rendered with this handle.
  90. virtual int GetStringWidth(FontFaceHandle handle, StringView string, const TextShapingContext& text_shaping_context,
  91. Character prior_character = Character::Null);
  92. /// Called by RmlUi when it wants to retrieve the meshes required to render a single line of text.
  93. /// @param[in] render_manager The render manager responsible for rendering the string.
  94. /// @param[in] face_handle The font handle.
  95. /// @param[in] font_effects_handle The handle to the prepared font effects for which the geometry should be generated.
  96. /// @param[in] string The string to render.
  97. /// @param[in] position The position of the baseline of the first character to render.
  98. /// @param[in] colour The colour to render the text.
  99. /// @param[in] opacity The opacity of the text, should be applied to font effects.
  100. /// @param[in] text_shaping_context Additional parameters that provide context for text shaping.
  101. /// @param[out] mesh_list A list to place the meshes and textures representing the string to be rendered.
  102. /// @return The width, in pixels, of the string mesh.
  103. virtual int GenerateString(RenderManager& render_manager, FontFaceHandle face_handle, FontEffectsHandle font_effects_handle, StringView string,
  104. Vector2f position, ColourbPremultiplied colour, float opacity, const TextShapingContext& text_shaping_context, TexturedMeshList& mesh_list);
  105. /// Called by RmlUi to determine if the text geometry is required to be re-generated. Whenever the returned version
  106. /// is changed, all geometry belonging to the given face handle will be re-generated.
  107. /// @param[in] face_handle The font handle.
  108. /// @return The version required for using any geometry generated with the face handle.
  109. virtual int GetVersion(FontFaceHandle handle);
  110. /// Called by RmlUi when it wants to garbage collect memory used by fonts.
  111. /// @note All existing FontFaceHandles and FontEffectsHandles are considered invalid after this call.
  112. virtual void ReleaseFontResources();
  113. };
  114. } // namespace Rml
  115. #endif