FontDatabase.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_fixed_width_font();
  33. static String default_font_query();
  34. static String fixed_width_font_query();
  35. static void set_default_font_query(String);
  36. static void set_fixed_width_font_query(String);
  37. RefPtr<Gfx::Font> get(const String& family, unsigned size, unsigned weight);
  38. RefPtr<Gfx::Font> get(const String& family, const String& variant, unsigned size);
  39. RefPtr<Gfx::Font> get_by_name(const StringView&);
  40. void for_each_font(Function<void(const Gfx::Font&)>);
  41. void for_each_fixed_width_font(Function<void(const Gfx::Font&)>);
  42. void for_each_typeface(Function<void(const Typeface&)>);
  43. private:
  44. FontDatabase();
  45. ~FontDatabase();
  46. RefPtr<Typeface> get_or_create_typeface(const String& family, const String& variant);
  47. struct Private;
  48. OwnPtr<Private> m_private;
  49. };
  50. }