Typeface.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Typeface.h>
  7. namespace Gfx {
  8. unsigned Typeface::weight() const
  9. {
  10. VERIFY(m_ttf_font || m_bitmap_fonts.size() > 0);
  11. if (is_fixed_size())
  12. return m_bitmap_fonts[0]->weight();
  13. return m_ttf_font->weight();
  14. }
  15. bool Typeface::is_fixed_width() const
  16. {
  17. VERIFY(m_ttf_font || m_bitmap_fonts.size() > 0);
  18. if (is_fixed_size())
  19. return m_bitmap_fonts[0]->is_fixed_width();
  20. return m_ttf_font->is_fixed_width();
  21. }
  22. void Typeface::add_bitmap_font(RefPtr<BitmapFont> font)
  23. {
  24. m_bitmap_fonts.append(font);
  25. }
  26. void Typeface::set_ttf_font(RefPtr<TTF::Font> font)
  27. {
  28. m_ttf_font = font;
  29. }
  30. RefPtr<Font> Typeface::get_font(unsigned size)
  31. {
  32. for (auto font : m_bitmap_fonts) {
  33. if (font->presentation_size() == size)
  34. return font;
  35. }
  36. if (m_ttf_font)
  37. return adopt_ref(*new TTF::ScaledFont(*m_ttf_font, size, size));
  38. return {};
  39. }
  40. void Typeface::for_each_fixed_size_font(Function<void(const Font&)> callback) const
  41. {
  42. for (auto font : m_bitmap_fonts) {
  43. callback(*font);
  44. }
  45. }
  46. }