FontFace.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // Copyright (c) 2008-2015 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 Image;
  29. class Texture2D;
  30. namespace SystemUI
  31. {
  32. class Font;
  33. /// %Font glyph description.
  34. struct FontGlyph
  35. {
  36. /// Construct.
  37. FontGlyph();
  38. /// X position in texture.
  39. short x_;
  40. /// Y position in texture.
  41. short y_;
  42. /// Width.
  43. short width_;
  44. /// Height.
  45. short height_;
  46. /// Glyph X offset from origin.
  47. short offsetX_;
  48. /// Glyph Y offset from origin.
  49. short offsetY_;
  50. /// Horizontal advance.
  51. short advanceX_;
  52. /// Texture page. M_MAX_UNSIGNED if not yet resident on any texture.
  53. unsigned page_;
  54. /// Used flag.
  55. bool used_;
  56. };
  57. /// %Font face description.
  58. class ATOMIC_API FontFace : public RefCounted
  59. {
  60. friend class Font;
  61. REFCOUNTED(FontFace)
  62. public:
  63. /// Construct.
  64. FontFace(Font* font);
  65. /// Destruct.
  66. ~FontFace();
  67. /// Load font face.
  68. virtual bool Load(const unsigned char* fontData, unsigned fontDataSize, int pointSize) = 0;
  69. /// Return pointer to the glyph structure corresponding to a character. Return null if glyph not found.
  70. virtual const FontGlyph* GetGlyph(unsigned c);
  71. /// Return if font face uses mutable glyphs.
  72. virtual bool HasMutableGlyphs() const { return false; }
  73. /// Return the kerning for a character and the next character.
  74. short GetKerning(unsigned c, unsigned d) const;
  75. /// Return true when one of the texture has a data loss.
  76. bool IsDataLost() const;
  77. /// Return point size.
  78. int GetPointSize() const { return pointSize_; }
  79. /// Return row height.
  80. int GetRowHeight() const { return rowHeight_; }
  81. /// Return textures.
  82. const Vector<SharedPtr<Texture2D> >& GetTextures() const { return textures_; }
  83. protected:
  84. friend class FontFaceBitmap;
  85. /// Create a texture for font rendering.
  86. SharedPtr<Texture2D> CreateFaceTexture();
  87. /// Load font face texture from image resource.
  88. SharedPtr<Texture2D> LoadFaceTexture(SharedPtr<Image> image);
  89. /// Parent font.
  90. Font* font_;
  91. /// Glyph mapping.
  92. HashMap<unsigned, FontGlyph> glyphMapping_;
  93. /// Kerning mapping.
  94. HashMap<unsigned, short> kerningMapping_;
  95. /// Glyph texture pages.
  96. Vector<SharedPtr<Texture2D> > textures_;
  97. /// Point size.
  98. int pointSize_;
  99. /// Row height.
  100. int rowHeight_;
  101. };
  102. }
  103. }