FontFaceHandle.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  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 ROCKETCOREFONTFACEHANDLE_H
  28. #define ROCKETCOREFONTFACEHANDLE_H
  29. #include "../../Include/Rocket/Core/ReferenceCountable.h"
  30. #include "UnicodeRange.h"
  31. #include "../../Include/Rocket/Core/Font.h"
  32. #include "../../Include/Rocket/Core/FontEffect.h"
  33. #include "../../Include/Rocket/Core/FontGlyph.h"
  34. #include "../../Include/Rocket/Core/Geometry.h"
  35. #include "../../Include/Rocket/Core/String.h"
  36. #include "../../Include/Rocket/Core/Texture.h"
  37. namespace Rocket {
  38. namespace Core {
  39. class FontFaceLayer;
  40. /**
  41. @author Peter Curry
  42. */
  43. class FontFaceHandle : public ReferenceCountable
  44. {
  45. public:
  46. FontFaceHandle();
  47. virtual ~FontFaceHandle();
  48. /// Returns the average advance of all glyphs in this font face.
  49. /// @return An approximate width of the characters in this font face.
  50. int GetCharacterWidth() const;
  51. /// Returns the point size of this font face.
  52. /// @return The face's point size.
  53. int GetSize() const;
  54. /// Returns the pixel height of a lower-case x in this font face.
  55. /// @return The height of a lower-case x.
  56. int GetXHeight() const;
  57. /// Returns the default height between this font face's baselines.
  58. /// @return The default line height.
  59. int GetLineHeight() const;
  60. /// Returns the font's baseline, as a pixel offset from the bottom of the font.
  61. /// @return The font's baseline.
  62. int GetBaseline() const;
  63. /// Returns the font's glyphs.
  64. /// @return The font's glyphs.
  65. const FontGlyphList& GetGlyphs() const;
  66. /// Returns the width a string will take up if rendered with this handle.
  67. /// @param[in] string The string to measure.
  68. /// @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.
  69. /// @return The width, in pixels, this string will occupy if rendered with this handle.
  70. virtual int GetStringWidth(const WString& string, word prior_character = 0) const = 0;
  71. /// Generates, if required, the layer configuration for a given array of font effects.
  72. /// @param[in] font_effects The list of font effects to generate the configuration for.
  73. /// @return The index to use when generating geometry using this configuration.
  74. virtual int GenerateLayerConfiguration(FontEffectMap& font_effects) = 0;
  75. /// Generates the texture data for a layer (for the texture database).
  76. /// @param[out] texture_data The pointer to be set to the generated texture data.
  77. /// @param[out] texture_dimensions The dimensions of the texture.
  78. /// @param[in] layer_id The id of the layer to request the texture data from.
  79. /// @param[in] texture_id The index of the texture within the layer to generate.
  80. virtual bool GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, FontEffect* layer_id, int texture_id) = 0;
  81. /// Generates the geometry required to render a single line of text.
  82. /// @param[out] geometry An array of geometries to generate the geometry into.
  83. /// @param[in] string The string to render.
  84. /// @param[in] position The position of the baseline of the first character to render.
  85. /// @param[in] colour The colour to render the text.
  86. /// @return The width, in pixels, of the string geometry.
  87. virtual int GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration = 0) const = 0;
  88. /// Generates the geometry required to render a line above, below or through a line of text.
  89. /// @param[out] geometry The geometry to append the newly created geometry into.
  90. /// @param[in] position The position of the baseline of the lined text.
  91. /// @param[in] width The width of the string to line.
  92. /// @param[in] height The height to render the line at.
  93. /// @param[in] colour The colour to draw the line in.
  94. virtual void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const = 0;
  95. /// Returns the font face's raw charset (the charset range as a string).
  96. /// @return The font face's charset.
  97. const String& GetRawCharset() const;
  98. /// Returns the font face's charset.
  99. /// @return The font face's charset.
  100. const UnicodeRangeList& GetCharset() const;
  101. protected:
  102. /// Destroys the handle.
  103. virtual void OnReferenceDeactivate();
  104. FontFaceLayer* GenerateLayer(FontEffect* font_effect);
  105. virtual int GetKerning(word lhs, word rhs) const = 0;
  106. typedef std::vector< int > GlyphKerningList;
  107. typedef std::vector< GlyphKerningList > FontKerningList;
  108. FontGlyphList glyphs;
  109. FontKerningList kerning;
  110. typedef std::map< const FontEffect*, FontFaceLayer* > FontLayerMap;
  111. typedef std::map< String, FontFaceLayer* > FontLayerCache;
  112. typedef std::vector< FontFaceLayer* > LayerConfiguration;
  113. typedef std::vector< LayerConfiguration > LayerConfigurationList;
  114. // The list of all font layers, index by the effect that instanced them.
  115. FontFaceLayer* base_layer;
  116. FontLayerMap layers;
  117. // Each font layer that generated geometry or textures, indexed by the respective generation
  118. // key.
  119. FontLayerCache layer_cache;
  120. // All configurations currently in use on this handle. New configurations will be generated as
  121. // required.
  122. LayerConfigurationList layer_configurations;
  123. // The average advance (in pixels) of all of this face's glyphs.
  124. int average_advance;
  125. int size;
  126. int x_height;
  127. int line_height;
  128. int baseline;
  129. float underline_position;
  130. float underline_thickness;
  131. String raw_charset;
  132. UnicodeRangeList charset;
  133. unsigned int max_codepoint;
  134. };
  135. }
  136. }
  137. #endif