test_text.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "tests/test_main.h"
  8. #include "base/invoke_queued.h"
  9. #include "base/integration.h"
  10. #include "ui/effects/animations.h"
  11. #include "ui/text/text.h"
  12. #include "ui/text/text_utilities.h"
  13. #include "ui/widgets/rp_window.h"
  14. #include "ui/painter.h"
  15. #include <QApplication>
  16. #include <QAbstractNativeEventFilter>
  17. #include <QThread>
  18. #include <QDir>
  19. namespace Test {
  20. QString name() {
  21. return u"text"_q;
  22. }
  23. void test(not_null<Ui::RpWindow*> window, not_null<Ui::RpWidget*> body) {
  24. auto text = new Ui::Text::String(scale(64));
  25. const auto like = QString::fromUtf8("\xf0\x9f\x91\x8d");
  26. const auto dislike = QString::fromUtf8("\xf0\x9f\x91\x8e");
  27. const auto hebrew = QString() + QChar(1506) + QChar(1460) + QChar(1489);
  28. auto data = TextWithEntities();
  29. data.append(
  30. u"Lorem ipsu7m dolor sit amet, "_q
  31. ).append(Ui::Text::Bold(
  32. u"consectetur adipiscing: "_q
  33. + hebrew
  34. + u" elit, sed do eiusmod tempor incididunt test"_q
  35. )).append(Ui::Text::Wrapped(Ui::Text::Bold(
  36. u". ut labore et dolore magna aliqua."_q
  37. + like
  38. + dislike
  39. + u"Ut enim ad minim veniam"_q
  40. ), EntityType::Italic)).append(
  41. u", quis nostrud exercitation ullamco laboris nisi ut aliquip ex \
  42. ea commodo consequat. Duis aute irure dolor in reprehenderit in \
  43. voluptate velit esse cillum dolore eu fugiat nulla pariatur. \
  44. Excepteur sint occaecat cupidatat non proident, sunt in culpa \
  45. qui officia deserunt mollit anim id est laborum."_q
  46. ).append(u"\n\n"_q).append(hebrew).append("\n\n").append(
  47. "Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeu\
  48. fugiatnullapariaturExcepteursintoccaecatcupidatatnonproident, sunt in culpa \
  49. qui officia deserunt mollit anim id est laborum. \
  50. Duisauteiruredolorinreprehenderitinvoluptate.");
  51. data.append(data);
  52. //data.append("hi\n\nguys");
  53. text->setMarkedText(st::defaultTextStyle, data);
  54. body->paintRequest() | rpl::start_with_next([=](QRect clip) {
  55. auto p = QPainter(body);
  56. auto hq = PainterHighQualityEnabler(p);
  57. const auto width = body->width();
  58. const auto height = body->height();
  59. p.fillRect(clip, QColor(255, 255, 255));
  60. const auto border = QColor(0, 128, 0, 16);
  61. auto skip = scale(20);
  62. p.fillRect(0, 0, skip, height, border);
  63. p.fillRect(skip, 0, width - skip, skip, border);
  64. p.fillRect(skip, height - skip, width - skip, skip, border);
  65. p.fillRect(width - skip, skip, skip, height - skip * 2, border);
  66. const auto inner = body->rect().marginsRemoved(
  67. { skip, skip, skip, skip });
  68. p.fillRect(QRect{
  69. inner.x(),
  70. inner.y(),
  71. inner.width(),
  72. text->countHeight(inner.width())
  73. }, QColor(128, 0, 0, 16));
  74. auto widths = text->countLineWidths(inner.width());
  75. auto top = 0;
  76. for (const auto width : widths) {
  77. p.fillRect(QRect{
  78. inner.x(),
  79. inner.y() + top,
  80. width,
  81. st::defaultTextStyle.font->height
  82. }, QColor(0, 0, 128, 16));
  83. top += st::defaultTextStyle.font->height;
  84. }
  85. text->draw(p, {
  86. .position = inner.topLeft(),
  87. .availableWidth = inner.width(),
  88. });
  89. //const auto to = QRectF(
  90. // inner.marginsRemoved({ 0, inner.height() / 2, 0, 0 }));
  91. //const auto t = u"hi\n\nguys"_q;
  92. //p.drawText(to, t);
  93. }, body->lifetime());
  94. }
  95. } // namespace Test