FontCache.cpp 605 B

123456789101112131415161718192021222324252627
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Font.h>
  7. #include <LibWeb/FontCache.h>
  8. FontCache& FontCache::the()
  9. {
  10. static FontCache cache;
  11. return cache;
  12. }
  13. RefPtr<Gfx::Font> FontCache::get(const FontSelector& font_selector) const
  14. {
  15. auto cached_font = m_fonts.get(font_selector);
  16. if (cached_font.has_value())
  17. return cached_font.value();
  18. return nullptr;
  19. }
  20. void FontCache::set(const FontSelector& font_selector, NonnullRefPtr<Gfx::Font> font)
  21. {
  22. m_fonts.set(font_selector, move(font));
  23. }