FontEngineInterface.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 "Header.h"
  30. #include "Types.h"
  31. #include "ComputedValues.h"
  32. #include "Geometry.h"
  33. namespace Rml {
  34. /**
  35. The abstract base class for an application-specific font engine implementation.
  36. By default, RmlUi will use its own font engine with characters rendered through FreeType. To use your own engine,
  37. provide a concrete implementation of this class and install it through Rml::SetFontEngineInterface().
  38. */
  39. class RMLUICORE_API FontEngineInterface
  40. {
  41. public:
  42. FontEngineInterface();
  43. virtual ~FontEngineInterface();
  44. /// Called by RmlUi when it wants to load a font face from file.
  45. /// @param[in] file_name The file to load the face from.
  46. /// @param[in] fallback_face True to use this font face for unknown characters in other font faces.
  47. /// @return True if the face was loaded successfully, false otherwise.
  48. virtual bool LoadFontFace(const String& file_name, bool fallback_face);
  49. /// Called by RmlUi when it wants to load a font face from memory, registered using the provided family, style, and weight.
  50. /// @param[in] data A pointer to the data.
  51. /// @param[in] data_size Size of the data in bytes.
  52. /// @param[in] family The family to register the font as.
  53. /// @param[in] style The style to register the font as.
  54. /// @param[in] weight The weight to register the font as.
  55. /// @param[in] fallback_face True to use this font face for unknown characters in other font faces.
  56. /// @return True if the face was loaded successfully, false otherwise.
  57. /// Note: The debugger plugin will load its embedded font faces through this method using the family name 'rmlui-debugger-font'.
  58. virtual bool LoadFontFace(const byte* data, int data_size, const String& family, Style::FontStyle style, Style::FontWeight weight, bool fallback_face);
  59. /// Called by RmlUi when a font configuration is resolved for an element. Should return a handle that
  60. /// can later be used to resolve properties of the face, and generate string geometry to be rendered.
  61. /// @param[in] family The family of the desired font handle.
  62. /// @param[in] style The style of the desired font handle.
  63. /// @param[in] weight The weight of the desired font handle.
  64. /// @param[in] size The size of desired handle, in points.
  65. /// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
  66. virtual FontFaceHandle GetFontFaceHandle(const String& family, Style::FontStyle style, Style::FontWeight weight, int size);
  67. /// Called by RmlUi when a list of font effects is resolved for an element with a given font face.
  68. /// @param[in] handle The font handle.
  69. /// @param[in] font_effects The list of font effects to generate the configuration for.
  70. /// @return A handle to the prepared font effects which will be used when generating geometry for a string.
  71. virtual FontEffectsHandle PrepareFontEffects(FontFaceHandle handle, const FontEffectList &font_effects);
  72. /// Should return the point size of this font face.
  73. /// @param[in] handle The font handle.
  74. /// @return The face's point size.
  75. virtual int GetSize(FontFaceHandle handle);
  76. /// Should return the pixel height of a lower-case x in this font face.
  77. /// @param[in] handle The font handle.
  78. /// @return The height of a lower-case x.
  79. virtual int GetXHeight(FontFaceHandle handle);
  80. /// Should return the default height between this font face's baselines.
  81. /// @param[in] handle The font handle.
  82. /// @return The default line height.
  83. virtual int GetLineHeight(FontFaceHandle handle);
  84. /// Should return the font's baseline, as a pixel offset from the bottom of the font.
  85. /// @param[in] handle The font handle.
  86. /// @return The font's baseline.
  87. virtual int GetBaseline(FontFaceHandle handle);
  88. /// Should return the font's underline, as a pixel offset from the bottom of the font.
  89. /// @param[in] handle The font handle.
  90. /// @param[out] thickness The font's underline thickness in pixels.
  91. /// @return The underline pixel offset.
  92. virtual float GetUnderline(FontFaceHandle handle, float &thickness);
  93. /// Called by RmlUi when it wants to retrieve the width of a string when rendered with this handle.
  94. /// @param[in] handle The font handle.
  95. /// @param[in] string The string to measure.
  96. /// @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.
  97. /// @return The width, in pixels, this string will occupy if rendered with this handle.
  98. virtual int GetStringWidth(FontFaceHandle handle, const String& string, Character prior_character = Character::Null);
  99. /// Called by RmlUi when it wants to retrieve the geometry required to render a single line of text.
  100. /// @param[in] face_handle The font handle.
  101. /// @param[in] font_effects_handle The handle to the prepared font effects for which the geometry should be generated.
  102. /// @param[in] string The string to render.
  103. /// @param[in] position The position of the baseline of the first character to render.
  104. /// @param[in] colour The colour to render the text. Colour alpha is premultiplied with opacity.
  105. /// @param[in] opacity The opacity of the text, should be applied to font effects.
  106. /// @param[out] geometry An array of geometries to generate the geometry into.
  107. /// @return The width, in pixels, of the string geometry.
  108. virtual int GenerateString(FontFaceHandle face_handle, FontEffectsHandle font_effects_handle, const String& string, const Vector2f& position,
  109. const Colourb& colour, float opacity, GeometryList& geometry);
  110. /// Called by RmlUi to determine if the text geometry is required to be re-generated. Whenever the returned version
  111. /// is changed, all geometry belonging to the given face handle will be re-generated.
  112. /// @param[in] face_handle The font handle.
  113. /// @return The version required for using any geometry generated with the face handle.
  114. virtual int GetVersion(FontFaceHandle handle);
  115. };
  116. } // namespace Rml
  117. #endif