StringMetrics.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. #include <AK/Vector.h>
  9. namespace Line {
  10. struct StringMetrics {
  11. struct MaskedChar {
  12. size_t position { 0 };
  13. size_t original_length { 0 };
  14. size_t masked_length { 0 };
  15. };
  16. struct LineMetrics {
  17. Vector<MaskedChar> masked_chars;
  18. size_t length { 0 };
  19. size_t visible_length { 0 };
  20. Optional<size_t> bit_length { 0 };
  21. size_t total_length() const { return length; }
  22. };
  23. Vector<LineMetrics> line_metrics;
  24. Vector<size_t> grapheme_breaks {};
  25. size_t total_length { 0 };
  26. size_t max_line_length { 0 };
  27. size_t lines_with_addition(StringMetrics const& offset, size_t column_width) const;
  28. size_t offset_with_addition(StringMetrics const& offset, size_t column_width) const;
  29. void reset()
  30. {
  31. line_metrics.clear();
  32. total_length = 0;
  33. max_line_length = 0;
  34. line_metrics.append({ {}, 0 });
  35. }
  36. };
  37. }