FontDatabase.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/DeprecatedString.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/Typeface.h>
  13. #include <LibGfx/Forward.h>
  14. namespace Gfx {
  15. namespace FontWeight {
  16. enum {
  17. Thin = 100,
  18. ExtraLight = 200,
  19. Light = 300,
  20. Regular = 400,
  21. Medium = 500,
  22. SemiBold = 600,
  23. Bold = 700,
  24. ExtraBold = 800,
  25. Black = 900,
  26. ExtraBlack = 950
  27. };
  28. }
  29. class FontDatabase {
  30. public:
  31. static FontDatabase& the();
  32. static Font& default_font();
  33. static Font& default_fixed_width_font();
  34. static Font& window_title_font();
  35. static DeprecatedString default_font_query();
  36. static DeprecatedString window_title_font_query();
  37. static DeprecatedString fixed_width_font_query();
  38. static DeprecatedString default_fonts_lookup_path();
  39. static void set_default_font_query(DeprecatedString);
  40. static void set_window_title_font_query(DeprecatedString);
  41. static void set_fixed_width_font_query(DeprecatedString);
  42. RefPtr<Gfx::Font> get(FlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
  43. RefPtr<Gfx::Font> get(FlyString const& family, FlyString const& variant, float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
  44. RefPtr<Gfx::Font> get_by_name(StringView);
  45. void for_each_font(Function<void(Gfx::Font const&)>);
  46. void for_each_fixed_width_font(Function<void(Gfx::Font const&)>);
  47. void for_each_typeface(Function<void(Typeface const&)>);
  48. void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)>);
  49. void load_all_fonts_from_uri(StringView);
  50. private:
  51. FontDatabase();
  52. ~FontDatabase() = default;
  53. RefPtr<Typeface> get_or_create_typeface(FlyString const& family, FlyString const& variant);
  54. struct Private;
  55. OwnPtr<Private> m_private;
  56. };
  57. }