VectorFont.cpp 950 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Font/ScaledFont.h>
  7. #include <LibGfx/Font/VectorFont.h>
  8. namespace Gfx {
  9. VectorFont::VectorFont() = default;
  10. VectorFont::~VectorFont() = default;
  11. NonnullRefPtr<ScaledFont> VectorFont::scaled_font(float point_size) const
  12. {
  13. auto it = m_scaled_fonts.find(point_size);
  14. if (it != m_scaled_fonts.end())
  15. return *it->value;
  16. // FIXME: It might be nice to have a global cap on the number of fonts we cache
  17. // instead of doing it at the per-VectorFont level like this.
  18. constexpr size_t max_cached_font_size_count = 128;
  19. if (m_scaled_fonts.size() > max_cached_font_size_count)
  20. m_scaled_fonts.remove(m_scaled_fonts.begin());
  21. auto scaled_font = adopt_ref(*new ScaledFont(*this, point_size, point_size));
  22. m_scaled_fonts.set(point_size, scaled_font);
  23. return scaled_font;
  24. }
  25. }