FontDatabase.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <AK/HashMap.h>
  9. #include <AK/OwnPtr.h>
  10. #include <AK/String.h>
  11. #include <LibGfx/Forward.h>
  12. #include <LibGfx/Typeface.h>
  13. namespace Gfx {
  14. namespace FontWeight {
  15. enum {
  16. Thin = 100,
  17. ExtraLight = 200,
  18. Light = 300,
  19. Regular = 400,
  20. Medium = 500,
  21. SemiBold = 600,
  22. Bold = 700,
  23. ExtraBold = 800,
  24. Black = 900,
  25. ExtraBlack = 950
  26. };
  27. }
  28. class FontDatabase {
  29. public:
  30. static FontDatabase& the();
  31. static Font& default_font();
  32. static Font& default_bold_font();
  33. static Font& default_fixed_width_font();
  34. static Font& default_bold_fixed_width_font();
  35. RefPtr<Gfx::Font> get(const String& family, unsigned size, unsigned weight);
  36. RefPtr<Gfx::Font> get(const String& family, const String& variant, unsigned size);
  37. RefPtr<Gfx::Font> get_by_name(const StringView&);
  38. void for_each_font(Function<void(const Gfx::Font&)>);
  39. void for_each_fixed_width_font(Function<void(const Gfx::Font&)>);
  40. void for_each_typeface(Function<void(const Typeface&)>);
  41. private:
  42. FontDatabase();
  43. ~FontDatabase();
  44. RefPtr<Typeface> get_or_create_typeface(const String& family, const String& variant);
  45. struct Private;
  46. OwnPtr<Private> m_private;
  47. };
  48. }