FontCascadeList.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/FontCascadeList.h>
  7. namespace Gfx {
  8. void FontCascadeList::add(NonnullRefPtr<Font> font)
  9. {
  10. m_fonts.append({ move(font), {} });
  11. }
  12. void FontCascadeList::add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges)
  13. {
  14. m_fonts.append({ move(font), move(unicode_ranges) });
  15. }
  16. void FontCascadeList::extend(FontCascadeList const& other)
  17. {
  18. for (auto const& font : other.m_fonts) {
  19. m_fonts.append({ font.font, font.unicode_ranges });
  20. }
  21. }
  22. Gfx::Font const& FontCascadeList::font_for_code_point(u32 code_point) const
  23. {
  24. for (auto const& entry : m_fonts) {
  25. if (!entry.unicode_ranges.has_value())
  26. return entry.font;
  27. if (!entry.font->contains_glyph(code_point))
  28. continue;
  29. for (auto const& range : *entry.unicode_ranges) {
  30. if (range.contains(code_point))
  31. return entry.font;
  32. }
  33. }
  34. VERIFY_NOT_REACHED();
  35. }
  36. bool FontCascadeList::equals(FontCascadeList const& other) const
  37. {
  38. if (m_fonts.size() != other.m_fonts.size())
  39. return false;
  40. for (size_t i = 0; i < m_fonts.size(); ++i) {
  41. if (m_fonts[i].font != other.m_fonts[i].font)
  42. return false;
  43. }
  44. return true;
  45. }
  46. }