Typeface.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <AK/RefCounted.h>
  9. #include <AK/String.h>
  10. #include <AK/Vector.h>
  11. #include <LibGfx/BitmapFont.h>
  12. #include <LibGfx/Font.h>
  13. #include <LibTTF/Font.h>
  14. namespace Gfx {
  15. class Typeface : public RefCounted<Typeface> {
  16. public:
  17. Typeface(const String& family, const String& variant)
  18. : m_family(family)
  19. , m_variant(variant)
  20. {
  21. }
  22. String family() const { return m_family; }
  23. String variant() const { return m_variant; }
  24. unsigned weight() const;
  25. bool is_fixed_width() const;
  26. bool is_fixed_size() const { return !m_bitmap_fonts.is_empty(); }
  27. void for_each_fixed_size_font(Function<void(const Font&)>) const;
  28. void add_bitmap_font(RefPtr<BitmapFont>);
  29. void set_ttf_font(RefPtr<TTF::Font>);
  30. RefPtr<Font> get_font(unsigned size);
  31. private:
  32. String m_family;
  33. String m_variant;
  34. Vector<RefPtr<BitmapFont>> m_bitmap_fonts;
  35. RefPtr<TTF::Font> m_ttf_font;
  36. };
  37. }