FontCache.h 739 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include <AK/HashMap.h>
  3. #include <AK/String.h>
  4. class Font;
  5. struct FontSelector {
  6. String family;
  7. String weight;
  8. bool operator==(const FontSelector& other) const
  9. {
  10. return family == other.family && weight == other.weight;
  11. }
  12. };
  13. namespace AK {
  14. template<>
  15. struct Traits<FontSelector> : public GenericTraits<FontSelector> {
  16. static unsigned hash(const FontSelector& key) { return pair_int_hash(key.family.hash(), key.weight.hash()); }
  17. };
  18. }
  19. class FontCache {
  20. public:
  21. static FontCache& the();
  22. RefPtr<Font> get(const FontSelector&) const;
  23. void set(const FontSelector&, NonnullRefPtr<Font>);
  24. private:
  25. FontCache() {}
  26. mutable HashMap<FontSelector, NonnullRefPtr<Font>> m_fonts;
  27. };