Text3DFontFace.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../../Container/ArrayPtr.h"
  24. #include "../../Container/List.h"
  25. #include "../../Math/AreaAllocator.h"
  26. namespace Atomic
  27. {
  28. class Text3DFont;
  29. class Image;
  30. class Texture2D;
  31. /// %Font glyph description.
  32. struct ATOMIC_API Text3DFontGlyph
  33. {
  34. /// Construct.
  35. Text3DFontGlyph();
  36. /// X position in texture.
  37. short x_;
  38. /// Y position in texture.
  39. short y_;
  40. /// Width.
  41. short width_;
  42. /// Height.
  43. short height_;
  44. /// Glyph X offset from origin.
  45. short offsetX_;
  46. /// Glyph Y offset from origin.
  47. short offsetY_;
  48. /// Horizontal advance.
  49. float advanceX_;
  50. /// Texture page. M_MAX_UNSIGNED if not yet resident on any texture.
  51. unsigned page_;
  52. /// Used flag.
  53. bool used_;
  54. };
  55. /// %Font face description.
  56. class ATOMIC_API Text3DFontFace : public RefCounted
  57. {
  58. friend class Text3DFont;
  59. ATOMIC_REFCOUNTED(FontFace)
  60. public:
  61. /// Construct.
  62. Text3DFontFace(Text3DFont* font);
  63. /// Destruct.
  64. ~Text3DFontFace();
  65. /// Load font face.
  66. virtual bool Load(const unsigned char* fontData, unsigned fontDataSize, float pointSize) = 0;
  67. /// Return pointer to the glyph structure corresponding to a character. Return null if glyph not found.
  68. virtual const Text3DFontGlyph* GetGlyph(unsigned c);
  69. /// Return if font face uses mutable glyphs.
  70. virtual bool HasMutableGlyphs() const { return false; }
  71. /// Return the kerning for a character and the next character.
  72. float GetKerning(unsigned c, unsigned d) const;
  73. /// Return true when one of the texture has a data loss.
  74. bool IsDataLost() const;
  75. /// Return point size.
  76. float GetPointSize() const { return pointSize_; }
  77. /// Return row height.
  78. float GetRowHeight() const { return rowHeight_; }
  79. /// Return textures.
  80. const Vector<SharedPtr<Texture2D> >& GetTextures() const { return textures_; }
  81. protected:
  82. friend class Text3DBitmap;
  83. /// Create a texture for font rendering.
  84. SharedPtr<Texture2D> CreateFaceTexture();
  85. /// Load font face texture from image resource.
  86. SharedPtr<Texture2D> LoadFaceTexture(SharedPtr<Image> image);
  87. /// Parent font.
  88. Text3DFont* font_;
  89. /// Glyph mapping.
  90. HashMap<unsigned, Text3DFontGlyph> glyphMapping_;
  91. /// Kerning mapping.
  92. HashMap<unsigned, float> kerningMapping_;
  93. /// Glyph texture pages.
  94. Vector<SharedPtr<Texture2D> > textures_;
  95. /// Point size.
  96. float pointSize_;
  97. /// Row height.
  98. float rowHeight_;
  99. };
  100. }