FontFaceFreeType.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // Copyright (c) 2008-2020 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 "../UI/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. explicit FontFaceFreeType(Font* font);
  34. /// Destruct.
  35. ~FontFaceFreeType() override;
  36. /// Load font face.
  37. bool Load(const unsigned char* fontData, unsigned fontDataSize, float pointSize) override;
  38. /// Return pointer to the glyph structure corresponding to a character. Return null if glyph not found.
  39. const FontGlyph* GetGlyph(unsigned c) override;
  40. /// Return if font face uses mutable glyphs.
  41. bool HasMutableGlyphs() const override { return hasMutableGlyph_; }
  42. private:
  43. /// Setup next texture.
  44. bool SetupNextTexture(int textureWidth, int textureHeight);
  45. /// Load char glyph.
  46. bool LoadCharGlyph(unsigned charCode, Image* image = nullptr);
  47. /// Smooth one row of a horizontally oversampled glyph image.
  48. void BoxFilter(unsigned char* dest, size_t destSize, const unsigned char* src, size_t srcSize);
  49. /// FreeType library.
  50. SharedPtr<FreeTypeLibrary> freeType_;
  51. /// FreeType face. Non-null after creation only in dynamic mode.
  52. void* face_{};
  53. /// Load mode.
  54. int loadMode_{};
  55. /// Use subpixel glyph positioning?
  56. bool subpixel_{};
  57. /// Oversampling level.
  58. int oversampling_{};
  59. /// Ascender.
  60. float ascender_{};
  61. /// Has mutable glyph.
  62. bool hasMutableGlyph_{};
  63. /// Glyph area allocator.
  64. AreaAllocator allocator_;
  65. };
  66. }