FontFaceFreeType.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // Copyright (c) 2008-2014 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 "FontFace.h"
  24. namespace Urho3D
  25. {
  26. class FreeTypeLibrary;
  27. class Texture2D;
  28. /// Free type font face description.
  29. class URHO3D_API FontFaceFreeType : public FontFace
  30. {
  31. public:
  32. /// Construct.
  33. FontFaceFreeType(Font* font);
  34. /// Destruct.
  35. ~FontFaceFreeType();
  36. /// Load font face.
  37. virtual bool Load(const unsigned char* fontData, unsigned fontDataSize, int pointSize);
  38. /// Return pointer to the glyph structure corresponding to a character. Return null if glyph not found.
  39. virtual const FontGlyph* GetGlyph(unsigned c);
  40. /// Return if font face uses mutable glyphs.
  41. virtual bool HasMutableGlyphs() const { return hasMutableGlyph_; }
  42. private:
  43. /// Check can load all glyph in one texture, return true and texture size if can load.
  44. bool CanLoadAllGlyphs(unsigned numGlyphs, int loadMode, int& textureWidth, int& textureHeight) const;
  45. /// Setup next texture.
  46. bool SetupNextTexture(int textureWidth, int textureHeight);
  47. /// Load char glyph.
  48. bool LoadCharGlyph(unsigned charCode, Image* image = 0);
  49. /// FreeType library.
  50. SharedPtr<FreeTypeLibrary> freeType_;
  51. /// FreeType face. Non-null after creation only in dynamic mode.
  52. void* face_;
  53. /// Has mutable glyph.
  54. bool hasMutableGlyph_;
  55. /// Ascender.
  56. int ascender_;
  57. /// Glyph area allocator.
  58. AreaAllocator allocator_;
  59. };
  60. }