text_stack_engine.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "ui/text/text.h"
  9. #include <private/qfontengine_p.h>
  10. namespace Ui::Text {
  11. class StackEngine final {
  12. public:
  13. explicit StackEngine(
  14. not_null<const String*> t,
  15. gsl::span<QScriptAnalysis> analysis,
  16. int from = 0,
  17. int till = -1,
  18. int blockIndexHint = 0);
  19. explicit StackEngine(
  20. not_null<const String*> t,
  21. int offset,
  22. const QString &text,
  23. gsl::span<QScriptAnalysis> analysis,
  24. int blockIndexHint = 0,
  25. int blockIndexLimit = -1);
  26. [[nodiscard]] QTextEngine &wrapped() {
  27. return _engine;
  28. }
  29. void itemize();
  30. std::vector<Block>::const_iterator shapeGetBlock(int item);
  31. [[nodiscard]] int blockIndex(int position) const;
  32. private:
  33. void updateFont(not_null<const AbstractBlock*> block);
  34. [[nodiscard]] std::vector<Block>::const_iterator adjustBlock(
  35. int offset) const;
  36. [[nodiscard]] int blockPosition(
  37. std::vector<Block>::const_iterator i) const;
  38. [[nodiscard]] int blockEnd(std::vector<Block>::const_iterator i) const;
  39. const not_null<const String*> _t;
  40. const QString &_text;
  41. QScriptAnalysis *_analysis = nullptr;
  42. const int _offset = 0;
  43. const int _positionEnd = 0;
  44. style::font _font;
  45. QStackTextEngine _engine;
  46. const std::vector<Block> &_tBlocks;
  47. std::vector<Block>::const_iterator _bStart;
  48. std::vector<Block>::const_iterator _bEnd;
  49. mutable std::vector<Block>::const_iterator _bCached;
  50. };
  51. } // namespace Ui::Text