FontDatabase.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/ByteString.h>
  8. #include <AK/FlyString.h>
  9. #include <AK/Function.h>
  10. #include <AK/HashMap.h>
  11. #include <AK/OwnPtr.h>
  12. #include <LibGfx/Font/FontWeight.h>
  13. #include <LibGfx/Font/Typeface.h>
  14. #include <LibGfx/Forward.h>
  15. namespace Gfx {
  16. class FontDatabase {
  17. public:
  18. static FontDatabase& the();
  19. static Font& default_font();
  20. static Font& default_fixed_width_font();
  21. static Font& window_title_font();
  22. static ByteString default_font_query();
  23. static ByteString window_title_font_query();
  24. static ByteString fixed_width_font_query();
  25. static ByteString default_fonts_lookup_path();
  26. static void set_default_font_query(ByteString);
  27. static void set_window_title_font_query(ByteString);
  28. static void set_fixed_width_font_query(ByteString);
  29. RefPtr<Gfx::Font> get(FlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
  30. RefPtr<Gfx::Font> get(FlyString const& family, FlyString const& variant, float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
  31. RefPtr<Gfx::Font> get_by_name(StringView);
  32. void for_each_font(Function<void(Gfx::Font const&)>);
  33. void for_each_fixed_width_font(Function<void(Gfx::Font const&)>);
  34. void for_each_typeface(Function<void(Typeface const&)>);
  35. void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)>);
  36. void load_all_fonts_from_uri(StringView);
  37. private:
  38. FontDatabase();
  39. ~FontDatabase() = default;
  40. RefPtr<Typeface> get_or_create_typeface(FlyString const& family, FlyString const& variant);
  41. struct Private;
  42. OwnPtr<Private> m_private;
  43. };
  44. }