1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.gui.textlayout; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.global; 19 import qt.core.list; 20 import qt.core.namespace; 21 import qt.core.point; 22 import qt.core.rect; 23 import qt.core.string; 24 import qt.core.vector; 25 import qt.gui.font; 26 import qt.gui.paintdevice; 27 import qt.gui.painter; 28 import qt.gui.textformat; 29 import qt.gui.textobject; 30 import qt.gui.textoption; 31 import qt.helpers; 32 version(QT_NO_RAWFONT){}else 33 { 34 import qt.gui.glyphrun; 35 import qt.gui.rawfont; 36 } 37 38 /+ class QTextEngine; 39 class QFont; 40 #ifndef QT_NO_RAWFONT 41 class QRawFont; 42 #endif 43 class QRect; 44 class QRegion; 45 class QTextFormat; 46 class QPalette; 47 class QPainter; +/ 48 49 extern(C++, class) struct /+ Q_GUI_EXPORT +/ QTextInlineObject 50 { 51 public: 52 this(int i, QTextEngine* e) 53 { 54 this.itm = i; 55 this.eng = e; 56 } 57 @disable this(); 58 /+pragma(inline, true) this() 59 { 60 this.itm = 0; 61 this.eng = null; 62 }+/ 63 pragma(inline, true) bool isValid() const { return cast(bool)(eng); } 64 65 QRectF rect() const; 66 qreal width() const; 67 qreal ascent() const; 68 qreal descent() const; 69 qreal height() const; 70 71 /+ Qt:: +/qt.core.namespace.LayoutDirection textDirection() const; 72 73 void setWidth(qreal w); 74 void setAscent(qreal a); 75 void setDescent(qreal d); 76 77 int textPosition() const; 78 79 int formatIndex() const; 80 QTextFormat format() const; 81 82 private: 83 /+ friend class QTextLayout; +/ 84 int itm = 0; 85 QTextEngine* eng = null; 86 } 87 88 /+ class QPaintDevice; 89 class QTextFormat; 90 class QTextLine; 91 class QTextBlock; 92 class QTextOption; +/ 93 94 extern(C++, class) struct /+ Q_GUI_EXPORT +/ QTextLayout 95 { 96 public: 97 // does itemization 98 @disable this(); 99 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 100 ref typeof(this) rawConstructor(); 101 static typeof(this) create() 102 { 103 typeof(this) r = typeof(this).init; 104 r.rawConstructor(); 105 return r; 106 } 107 108 this(ref const(QString) text); 109 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/ 110 this(ref const(QString) text, ref const(QFont) font, QPaintDevice paintdevice = null); 111 /+ #ifndef Q_QDOC +/ 112 // the template is necessary to make QTextLayout(font,text,nullptr) and QTextLayout(font,text,NULL) 113 // not ambiguous. Implementation detail that should not be documented. 114 /+ template<char = 0> 115 #endif +/ 116 /+ QTextLayout(const QString &textData, const QFont &textFont, const QPaintDevice *paintdevice) 117 : QTextLayout(textData, textFont, const_cast<QPaintDevice*>(paintdevice)) 118 {} +/ 119 /+ #else 120 QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice = nullptr); 121 #endif +/ 122 this(ref const(QTextBlock) b); 123 ~this(); 124 125 void setFont(ref const(QFont) f); 126 QFont font() const; 127 128 version(QT_NO_RAWFONT){}else 129 { 130 void setRawFont(ref const(QRawFont) rawFont); 131 } 132 133 void setText(ref const(QString) string); 134 QString text() const; 135 136 void setTextOption(ref const(QTextOption) option); 137 ref const(QTextOption) textOption() const; 138 139 void setPreeditArea(int position, ref const(QString) text); 140 int preeditAreaPosition() const; 141 QString preeditAreaText() const; 142 143 struct FormatRange { 144 int start; 145 int length; 146 QTextCharFormat format; 147 148 /+ friend bool operator==(const FormatRange &lhs, const FormatRange &rhs) 149 { return lhs.start == rhs.start && lhs.length == rhs.length && lhs.format == rhs.format; } +/ 150 /+ friend bool operator!=(const FormatRange &lhs, const FormatRange &rhs) 151 { return !operator==(lhs, rhs); } +/ 152 } 153 /+ #if QT_DEPRECATED_SINCE(5, 6) +/ 154 /+ QT_DEPRECATED_X("Use setFormats()") +/ void setAdditionalFormats(ref const(QList!(FormatRange)) overrides); 155 /+ QT_DEPRECATED_X("Use formats()") +/ QList!(FormatRange) additionalFormats() const; 156 /+ QT_DEPRECATED_X("Use clearFormats()") +/ void clearAdditionalFormats(); 157 /+ #endif +/ 158 void setFormats(ref const(QVector!(FormatRange)) overrides); 159 QVector!(FormatRange) formats() const; 160 void clearFormats(); 161 162 void setCacheEnabled(bool enable); 163 bool cacheEnabled() const; 164 165 void setCursorMoveStyle(/+ Qt:: +/qt.core.namespace.CursorMoveStyle style); 166 /+ Qt:: +/qt.core.namespace.CursorMoveStyle cursorMoveStyle() const; 167 168 void beginLayout(); 169 void endLayout(); 170 void clearLayout(); 171 172 QTextLine createLine(); 173 174 int lineCount() const; 175 QTextLine lineAt(int i) const; 176 QTextLine lineForTextPosition(int pos) const; 177 178 enum CursorMode { 179 SkipCharacters, 180 SkipWords 181 } 182 bool isValidCursorPosition(int pos) const; 183 int nextCursorPosition(int oldPos, CursorMode mode = CursorMode.SkipCharacters) const; 184 int previousCursorPosition(int oldPos, CursorMode mode = CursorMode.SkipCharacters) const; 185 int leftCursorPosition(int oldPos) const; 186 int rightCursorPosition(int oldPos) const; 187 188 void draw(QPainter* p, ref const(QPointF) pos, ref const(QVector!(FormatRange)) selections = globalInitVar!(QVector!(FormatRange)), 189 ref const(QRectF) clip = globalInitVar!QRectF) const; 190 void drawCursor(QPainter* p, ref const(QPointF) pos, int cursorPosition) const; 191 void drawCursor(QPainter* p, ref const(QPointF) pos, int cursorPosition, int width) const; 192 193 QPointF position() const; 194 void setPosition(ref const(QPointF) p); 195 196 QRectF boundingRect() const; 197 198 qreal minimumWidth() const; 199 qreal maximumWidth() const; 200 201 version(QT_NO_RAWFONT){}else 202 { 203 QList!(QGlyphRun) glyphRuns(int from = -1, int length = -1) const; 204 } 205 206 // QTextEngine* engine() const { return d; } 207 void setFlags(int flags); 208 private: 209 this(QTextEngine* e) 210 { 211 this.d = e; 212 } 213 /+ Q_DISABLE_COPY(QTextLayout) +/ 214 @disable this(this); 215 /+this(ref const(QTextLayout));+//+ref QTextLayout operator =(ref const(QTextLayout));+/ 216 /+ friend class QPainter; +/ 217 /+ friend class QGraphicsSimpleTextItemPrivate; +/ 218 /+ friend class QGraphicsSimpleTextItem; +/ 219 /+ friend void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *, const QString& str, 220 QRectF *brect, int tabstops, int* tabarray, int tabarraylen, 221 QPainter *painter); +/ 222 QTextEngine* d; 223 } 224 /+ Q_DECLARE_TYPEINFO(QTextLayout::FormatRange, Q_RELOCATABLE_TYPE); +/ 225 226 227 extern(C++, class) struct /+ Q_GUI_EXPORT +/ QTextLine 228 { 229 public: 230 @disable this(); 231 /+pragma(inline, true) this() 232 { 233 this.index = 0; 234 this.eng = null; 235 }+/ 236 pragma(inline, true) bool isValid() const { return cast(bool)(eng); } 237 238 QRectF rect() const; 239 qreal x() const; 240 qreal y() const; 241 qreal width() const; 242 qreal ascent() const; 243 qreal descent() const; 244 qreal height() const; 245 qreal leading() const; 246 247 void setLeadingIncluded(bool included); 248 bool leadingIncluded() const; 249 250 qreal naturalTextWidth() const; 251 qreal horizontalAdvance() const; 252 QRectF naturalTextRect() const; 253 254 enum Edge { 255 Leading, 256 Trailing 257 } 258 enum CursorPosition { 259 CursorBetweenCharacters, 260 CursorOnCharacter 261 } 262 263 /* cursorPos gets set to the valid position */ 264 qreal cursorToX(int* cursorPos, Edge edge = Edge.Leading) const; 265 pragma(inline, true) qreal cursorToX(int cursorPos, Edge edge = Edge.Leading) const { return cursorToX(&cursorPos, edge); } 266 int xToCursor(qreal x, CursorPosition /+ = CursorBetweenCharacters +/) const; 267 268 void setLineWidth(qreal width); 269 void setNumColumns(int columns); 270 void setNumColumns(int columns, qreal alignmentWidth); 271 272 void setPosition(ref const(QPointF) pos); 273 QPointF position() const; 274 275 int textStart() const; 276 int textLength() const; 277 278 int lineNumber() const { return index; } 279 280 void draw(QPainter* p, ref const(QPointF) point, const(QTextLayout.FormatRange)* selection = null) const; 281 282 version(QT_NO_RAWFONT){}else 283 { 284 QList!(QGlyphRun) glyphRuns(int from = -1, int length = -1) const; 285 } 286 287 private: 288 this(int line, QTextEngine* e) 289 { 290 this.index = line; 291 this.eng = e; 292 } 293 void layout_helper(int numGlyphs); 294 295 /+ friend class QTextLayout; +/ 296 /+ friend class QTextFragment; +/ 297 int index = 0; 298 QTextEngine* eng = null; 299 } 300