FontEffect.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 ROCKETCOREFONTEFFECT_H
  28. #define ROCKETCOREFONTEFFECT_H
  29. #include "FontGlyph.h"
  30. namespace Rocket {
  31. namespace Core {
  32. class FontEffectInstancer;
  33. /**
  34. @author Peter Curry
  35. */
  36. class FontEffect : public ReferenceCountable
  37. {
  38. public:
  39. FontEffect();
  40. virtual ~FontEffect();
  41. /// Returns the name of the effect; this is the type that instanced the effect.
  42. /// @return The effect's name.
  43. const String& GetName() const;
  44. /// Asks the font effect if it requires, and will generate, its own unique texture. If it does
  45. /// not, it will share the font's base layer's textures instead.
  46. /// @return True if the effect generates its own textures, false if not. The default implementation returns false.
  47. virtual bool HasUniqueTexture() const;
  48. /// Requests the effect for a size and position of a single glyph's bitmap.
  49. /// @param[out] origin The desired origin of the effect's glyph bitmap, as a pixel offset from its original origin. This defaults to (0, 0).
  50. /// @param[out] dimensions The desired dimensions of the effect's glyph bitmap, in pixels. This defaults to the dimensions of the glyph's original bitmap. If the font effect is not generating a unique texture, this will be ignored.
  51. /// @param[in] glyph The glyph the effect is being asked to size.
  52. /// @return False if the effect is not providing support for the glyph, true otherwise.
  53. virtual bool GetGlyphMetrics(Vector2i& origin, Vector2i& dimensions, const FontGlyph& glyph) const;
  54. /// Requests the effect to generate the texture data for a single glyph's bitmap. The default implementation does
  55. /// nothing.
  56. /// @param[out] destination_data The top-left corner of the glyph's 32-bit, RGBA-ordered, destination texture. Note that they glyph shares its texture with other glyphs.
  57. /// @param[in] destination_dimensions The dimensions of the glyph's area on its texture.
  58. /// @param[in] destination_stride The stride of the glyph's texture.
  59. /// @param[in] glyph The glyph the effect is being asked to generate an effect texture for.
  60. virtual void GenerateGlyphTexture(byte* destination_data, const Vector2i& destination_dimensions, int destination_stride, const FontGlyph& glyph) const;
  61. /// Sets the colour of the effect's geometry.
  62. /// @param[in] colour The effect's colour.
  63. void SetColour(const Colourb& colour);
  64. /// Returns the effect's colour.
  65. /// @return The colour of the effect.
  66. const Colourb& GetColour() const;
  67. /// Sets the z-index of the font effect. An effect with a higher z-index will be rendered after
  68. /// an effect with a lower z-index. By default, all effects have a z-index of 0.
  69. /// @param[in] z-index The new z-index of the effect.
  70. void SetZIndex(float z_index);
  71. /// Returns the font effect's z-index.
  72. /// @return The z-index of the effect.
  73. float GetZIndex() const;
  74. /// Sets the specificity of the font effect.
  75. /// @param[in] specificity The specificity of the effect.
  76. void SetSpecificity(int specificity);
  77. /// Returns the specificity of the font effect. This is used when multiple pseudo-classes are
  78. /// active on an element, each with similarly-named font effects.
  79. /// @return The specificity of the effect.
  80. int GetSpecificity() const;
  81. /// Returns the font effect's generation key.
  82. /// @return A hash of the effect's properties used to generate the geometry and texture data.
  83. const String& GetGenerationKey() const;
  84. protected:
  85. /// Releases the effect through its instancer.
  86. virtual void OnReferenceDeactivate();
  87. private:
  88. FontEffectInstancer* instancer;
  89. // The name of the effect.
  90. String name;
  91. // The colour of the effect's geometry.
  92. Colourb colour;
  93. // The z-index of this font effect, used to resolve render order when multiple font effects are rendered.
  94. float z_index;
  95. // The maximum specificity of the properties used to define the font effect.
  96. int specificity;
  97. // A string identifying the properties that affected the generation of the effect's geometry and texture data.
  98. String generation_key;
  99. friend class Factory;
  100. };
  101. typedef std::vector< FontEffect* > FontEffectList;
  102. typedef std::map< String, FontEffect* > FontEffectMap;
  103. }
  104. }
  105. #endif