FontFace.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "FontFace.h"
  2. #include "../../../Include/RmlUi/Core/Log.h"
  3. #include "FontFaceHandleDefault.h"
  4. #include "FreeTypeInterface.h"
  5. namespace Rml {
  6. FontFace::FontFace(FontFaceHandleFreetype _face, Style::FontStyle _style, Style::FontWeight _weight)
  7. {
  8. style = _style;
  9. weight = _weight;
  10. face = _face;
  11. }
  12. FontFace::~FontFace()
  13. {
  14. if (face)
  15. FreeType::ReleaseFace(face);
  16. }
  17. Style::FontStyle FontFace::GetStyle() const
  18. {
  19. return style;
  20. }
  21. Style::FontWeight FontFace::GetWeight() const
  22. {
  23. return weight;
  24. }
  25. FontFaceHandleDefault* FontFace::GetHandle(int size, bool load_default_glyphs)
  26. {
  27. auto it = handles.find(size);
  28. if (it != handles.end())
  29. return it->second.get();
  30. // See if this face has been released.
  31. if (!face)
  32. {
  33. Log::Message(Log::LT_WARNING, "Font face has been released, unable to generate new handle.");
  34. return nullptr;
  35. }
  36. // Construct and initialise the new handle.
  37. auto handle = MakeUnique<FontFaceHandleDefault>();
  38. if (!handle->Initialize(face, size, load_default_glyphs))
  39. {
  40. handles[size] = nullptr;
  41. return nullptr;
  42. }
  43. FontFaceHandleDefault* result = handle.get();
  44. // Save the new handle to the font face
  45. handles[size] = std::move(handle);
  46. return result;
  47. }
  48. void FontFace::ReleaseFontResources()
  49. {
  50. HandleMap().swap(handles);
  51. }
  52. } // namespace Rml