Font.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Ui/UiObject.h>
  7. #include <AnKi/Gr/Texture.h>
  8. #include <AnKi/Util/ClassWrapper.h>
  9. #include <AnKi/Util/WeakArray.h>
  10. namespace anki {
  11. /// @addtogroup ui
  12. /// @{
  13. /// Font class.
  14. class Font : public UiObject
  15. {
  16. public:
  17. Font(UiManager* manager)
  18. : UiObject(manager)
  19. {
  20. }
  21. ~Font();
  22. /// Initialize the font.
  23. Error init(const CString& filename, ConstWeakArray<U32> fontHeights);
  24. /// Get font image atlas.
  25. ANKI_INTERNAL const TextureViewPtr& getTextureView() const
  26. {
  27. return m_texView;
  28. }
  29. ANKI_INTERNAL const ImFont& getImFont(U32 fontHeight) const
  30. {
  31. for(const FontEntry& f : m_fonts)
  32. {
  33. if(f.m_height == fontHeight)
  34. {
  35. return *f.m_imFont;
  36. }
  37. }
  38. ANKI_ASSERT(0);
  39. return *m_fonts[0].m_imFont;
  40. }
  41. ANKI_INTERNAL const ImFont& getFirstImFont() const
  42. {
  43. return *m_fonts[0].m_imFont;
  44. }
  45. ANKI_INTERNAL ImFontAtlas* getImFontAtlas()
  46. {
  47. return m_imFontAtlas.get();
  48. }
  49. private:
  50. ClassWrapper<ImFontAtlas> m_imFontAtlas;
  51. DynamicArray<U8> m_fontData;
  52. class FontEntry
  53. {
  54. public:
  55. ImFont* m_imFont;
  56. U32 m_height;
  57. };
  58. DynamicArray<FontEntry> m_fonts;
  59. TexturePtr m_tex;
  60. TextureViewPtr m_texView; ///< Whole texture view
  61. void createTexture(const void* data, U32 width, U32 height);
  62. };
  63. /// @}
  64. } // end namespace anki