FontDatabase.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/Function.h>
  9. #include <AK/HashMap.h>
  10. #include <AK/OwnPtr.h>
  11. #include <LibGfx/Font/Typeface.h>
  12. #include <LibGfx/Forward.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 Font& window_title_font();
  34. static DeprecatedString default_font_query();
  35. static DeprecatedString window_title_font_query();
  36. static DeprecatedString fixed_width_font_query();
  37. static DeprecatedString default_fonts_lookup_path();
  38. static void set_default_font_query(DeprecatedString);
  39. static void set_window_title_font_query(DeprecatedString);
  40. static void set_fixed_width_font_query(DeprecatedString);
  41. static void set_default_fonts_lookup_path(DeprecatedString);
  42. RefPtr<Gfx::Font> get(DeprecatedFlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
  43. RefPtr<Gfx::Font> get(DeprecatedFlyString const& family, DeprecatedFlyString 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 load_all_fonts_from_path(DeprecatedString const&);
  49. private:
  50. FontDatabase();
  51. ~FontDatabase() = default;
  52. RefPtr<Typeface> get_or_create_typeface(DeprecatedString const& family, DeprecatedString const& variant);
  53. struct Private;
  54. OwnPtr<Private> m_private;
  55. };
  56. }