Qt 4.8
Public Types | Public Functions | Private Functions | Properties | Friends | List of all members
QTextLine Class Reference

The QTextLine class represents a line of text inside a QTextLayout. More...

#include <qtextlayout.h>

Public Types

enum  CursorPosition { CursorBetweenCharacters, CursorOnCharacter }
 
enum  Edge { Leading, Trailing }
 

Public Functions

qreal ascent () const
 Returns the line's ascent. More...
 
qreal cursorToX (int *cursorPos, Edge edge=Leading) const
 Converts the cursor position cursorPos to the corresponding x position inside the line, taking account of the edge. More...
 
qreal cursorToX (int cursorPos, Edge edge=Leading) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
qreal descent () const
 Returns the line's descent. More...
 
void draw (QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection=0) const
 Draws a line on the given painter at the specified position. More...
 
qreal height () const
 Returns the line's height. More...
 
qreal horizontalAdvance () const
 Returns the horizontal advance of the text. More...
 
bool isValid () const
 Returns true if this text line is valid; otherwise returns false. More...
 
qreal leading () const
 Returns the line's leading. More...
 
bool leadingIncluded () const
 Returns true if positive leading is included into the line's height; otherwise returns false. More...
 
int lineNumber () const
 Returns the position of the line in the text engine. More...
 
QRectF naturalTextRect () const
 Returns the rectangle covered by the line. More...
 
qreal naturalTextWidth () const
 Returns the width of the line that is occupied by text. More...
 
QPointF position () const
 Returns the line's position relative to the text layout's position. More...
 
 QTextLine ()
 Creates an invalid line. More...
 
QRectF rect () const
 Returns the line's bounding rectangle. More...
 
void setLeadingIncluded (bool included)
 Includes positive leading into the line's height if included is true; otherwise does not include leading. More...
 
void setLineWidth (qreal width)
 Lays out the line with the given width. More...
 
void setNumColumns (int columns)
 Lays out the line. More...
 
void setNumColumns (int columns, qreal alignmentWidth)
 Lays out the line. More...
 
void setPosition (const QPointF &pos)
 Moves the line to position pos. More...
 
int textLength () const
 Returns the length of the text in the line. More...
 
int textStart () const
 Returns the start of the line from the beginning of the string passed to the QTextLayout. More...
 
qreal width () const
 Returns the line's width as specified by the layout() function. More...
 
qreal x () const
 Returns the line's x position. More...
 
int xToCursor (qreal x, CursorPosition=CursorBetweenCharacters) const
 Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor position type, cpos. More...
 
qreal y () const
 Returns the line's y position. More...
 

Private Functions

QList< QGlyphRunglyphs (int from, int length) const
 Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems that overlap with the range defined by from and length. More...
 
void layout_helper (int numGlyphs)
 
 QTextLine (int line, QTextEngine *e)
 

Properties

QTextEngineeng
 
int i
 

Friends

class QTextFragment
 
class QTextLayout
 

Detailed Description

The QTextLine class represents a line of text inside a QTextLayout.

Note
This class or function is reentrant.

A text line is usually created by QTextLayout::createLine().

After being created, the line can be filled using the setLineWidth() or setNumColumns() functions. A line has a number of attributes including the rectangle it occupies, rect(), its coordinates, x() and y(), its textLength(), width() and naturalTextWidth(), and its ascent() and decent() relative to the text. The position of the cursor in terms of the line is available from cursorToX() and its inverse from xToCursor(). A line can be moved with setPosition().

Definition at line 197 of file qtextlayout.h.

Enumerations

◆ CursorPosition

  • CursorBetweenCharacters
  • CursorOnCharacter
Enumerator
CursorBetweenCharacters 
CursorOnCharacter 

Definition at line 223 of file qtextlayout.h.

◆ Edge

  • Leading
  • Trailing
Enumerator
Leading 
Trailing 

Definition at line 219 of file qtextlayout.h.

219  {
220  Leading,
221  Trailing
222  };

Constructors and Destructors

◆ QTextLine() [1/2]

QTextLine::QTextLine ( )
inline

Creates an invalid line.

Definition at line 200 of file qtextlayout.h.

200 : i(0), eng(0) {}
QTextEngine * eng
Definition: qtextlayout.h:258

◆ QTextLine() [2/2]

QTextLine::QTextLine ( int  line,
QTextEngine e 
)
inlineprivate
Warning
This function is not part of the public interface.

Constructs a new text line using the line at position line in the text engine e.

Definition at line 248 of file qtextlayout.h.

248 : i(line), eng(e) {}
QTextEngine * eng
Definition: qtextlayout.h:258

Functions

◆ ascent()

qreal QTextLine::ascent ( ) const

Returns the line's ascent.

See also
descent(), height()

Definition at line 1461 of file qtextlayout.cpp.

Referenced by QSvgText::draw(), getLineHeightParams(), QLineControl::updateDisplayText(), and QCommonStylePrivate::viewItemDrawText().

1462 {
1463  return eng->lines[i].ascent.toReal();
1464 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ cursorToX() [1/2]

qreal QTextLine::cursorToX ( int *  cursorPos,
Edge  edge = Leading 
) const

Converts the cursor position cursorPos to the corresponding x position inside the line, taking account of the edge.

If cursorPos is not a valid cursor position, the nearest valid cursor position will be used instead, and cpos will be modified to point to this valid cursor position.

See also
xToCursor()

Definition at line 2570 of file qtextlayout.cpp.

Referenced by QAccessibleTextWidget::characterRect(), QLineControl::cursorRect(), QTextLayout::drawCursor(), QTextControlPrivate::extendWordwiseSelection(), QTextControlPrivate::rectForPosition(), and QTextCursorPrivate::setX().

2571 {
2572  if (!eng->layoutData)
2573  eng->itemize();
2574 
2575  const QScriptLine &line = eng->lines[i];
2576  bool lastLine = i >= eng->lines.size() - 1;
2577 
2578  QFixed x = line.x;
2579  x += eng->alignLine(line) - eng->leadingSpaceWidth(line);
2580 
2581  if (!i && !eng->layoutData->items.size()) {
2582  *cursorPos = 0;
2583  return x.toReal();
2584  }
2585 
2586  int lineEnd = line.from + line.length + line.trailingSpaces;
2587  int pos = *cursorPos;
2588  int itm;
2589  const HB_CharAttributes *attributes = eng->attributes();
2590  if (!attributes) {
2591  *cursorPos = 0;
2592  return x.toReal();
2593  }
2594  while (pos < lineEnd && !attributes[pos].charStop)
2595  pos++;
2596  if (pos == lineEnd) {
2597  // end of line ensure we have the last item on the line
2598  itm = eng->findItem(pos-1);
2599  }
2600  else
2601  itm = eng->findItem(pos);
2602  eng->shapeLine(line);
2603 
2604  const QScriptItem *si = &eng->layoutData->items[itm];
2605  if (!si->num_glyphs)
2606  eng->shape(itm);
2607  pos -= si->position;
2608 
2610  unsigned short *logClusters = eng->logClusters(si);
2611  Q_ASSERT(logClusters);
2612 
2613  int l = eng->length(itm);
2614  if (pos > l)
2615  pos = l;
2616  if (pos < 0)
2617  pos = 0;
2618 
2619  int glyph_pos = pos == l ? si->num_glyphs : logClusters[pos];
2620  if (edge == Trailing) {
2621  // trailing edge is leading edge of next cluster
2622  while (glyph_pos < si->num_glyphs && !glyphs.attributes[glyph_pos].clusterStart)
2623  glyph_pos++;
2624  }
2625 
2626  bool reverse = eng->layoutData->items[itm].analysis.bidiLevel % 2;
2627 
2628 
2629  // add the items left of the cursor
2630 
2631  int firstItem = eng->findItem(line.from);
2632  int lastItem = eng->findItem(lineEnd - 1);
2633  int nItems = (firstItem >= 0 && lastItem >= firstItem)? (lastItem-firstItem+1) : 0;
2634 
2635  QVarLengthArray<int> visualOrder(nItems);
2636  QVarLengthArray<uchar> levels(nItems);
2637  for (int i = 0; i < nItems; ++i)
2638  levels[i] = eng->layoutData->items[i+firstItem].analysis.bidiLevel;
2639  QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data());
2640 
2641  for (int i = 0; i < nItems; ++i) {
2642  int item = visualOrder[i]+firstItem;
2643  if (item == itm)
2644  break;
2645  QScriptItem &si = eng->layoutData->items[item];
2646  if (!si.num_glyphs)
2647  eng->shape(item);
2648 
2650  x += si.width;
2651  continue;
2652  }
2653  int start = qMax(line.from, si.position);
2654  int end = qMin(lineEnd, si.position + eng->length(item));
2655 
2656  logClusters = eng->logClusters(&si);
2657 
2658  int gs = logClusters[start-si.position];
2659  int ge = (end == si.position + eng->length(item)) ? si.num_glyphs-1 : logClusters[end-si.position-1];
2660 
2661  QGlyphLayout glyphs = eng->shapedGlyphs(&si);
2662 
2663  while (gs <= ge) {
2664  x += glyphs.effectiveAdvance(gs);
2665  ++gs;
2666  }
2667  }
2668 
2669  logClusters = eng->logClusters(si);
2670  glyphs = eng->shapedGlyphs(si);
2672  if (pos == (reverse ? 0 : l))
2673  x += si->width;
2674  } else {
2675  bool rtl = eng->isRightToLeft();
2676  bool visual = eng->visualCursorMovement();
2677  int end = qMin(lineEnd, si->position + l) - si->position;
2678  if (reverse) {
2679  int glyph_end = end == l ? si->num_glyphs : logClusters[end];
2680  int glyph_start = glyph_pos;
2681  if (visual && !rtl && !(lastLine && itm == (visualOrder[nItems - 1] + firstItem)))
2682  glyph_start++;
2683  for (int i = glyph_end - 1; i >= glyph_start; i--)
2684  x += glyphs.effectiveAdvance(i);
2685  } else {
2686  int start = qMax(line.from - si->position, 0);
2687  int glyph_start = logClusters[start];
2688  int glyph_end = glyph_pos;
2689  if (!visual || !rtl || (lastLine && itm == visualOrder[0] + firstItem))
2690  glyph_end--;
2691  for (int i = glyph_start; i <= glyph_end; i++)
2692  x += glyphs.effectiveAdvance(i);
2693  }
2694  x += eng->offsetInLigature(si, pos, end, glyph_pos);
2695  }
2696 
2697  if (eng->option.wrapMode() != QTextOption::NoWrap && x > line.x + line.width)
2698  x = line.x + line.width;
2699 
2700  if (eng->option.wrapMode() != QTextOption::NoWrap && x < 0)
2701  x = 0;
2702 
2703  *cursorPos = pos + si->position;
2704  return x.toReal();
2705 }
bool isRightToLeft() const
unsigned short trailingSpaces
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QList< QGlyphRun > glyphs(int from, int length) const
Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems...
static C reverse(const C &l)
int findItem(int strPos) const
QScriptItemArray items
QFixed offsetInLigature(const QScriptItem *si, int pos, int max, int glyph_pos)
LayoutData * layoutData
unsigned short * logClusters(const QScriptItem *si) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const HB_CharAttributes * attributes() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QTextEngine * eng
Definition: qtextlayout.h:258
void shapeLine(const QScriptLine &line)
QGlyphLayout shapedGlyphs(const QScriptItem *si) const
static void bidiReorder(int numRuns, const quint8 *levels, int *visualOrder)
qreal x() const
Returns the line&#39;s x position.
unsigned short num_glyphs
QScriptLineArray lines
void itemize() const
QTextOption option
unsigned short flags
void shape(int item) const
int length(int item) const
QFixed alignLine(const QScriptLine &line)
if(void) toggleToolbarShown
WrapMode wrapMode() const
Returns the text wrap mode defined by the option.
Definition: qtextoption.h:110
QFactoryLoader * l
qreal toReal() const
Definition: qfixed_p.h:77
signed int length
QFixed effectiveAdvance(int item) const
HB_GlyphAttributes * attributes
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
bool visualCursorMovement() const
QFixed leadingSpaceWidth(const QScriptLine &line)
QScriptAnalysis analysis

◆ cursorToX() [2/2]

int QTextLine::cursorToX ( int  cursorPos,
Edge  edge = Leading 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 230 of file qtextlayout.h.

Referenced by cursorToX().

230 { return cursorToX(&cursorPos, edge); }
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...

◆ descent()

qreal QTextLine::descent ( ) const

Returns the line's descent.

See also
ascent(), height()

Definition at line 1471 of file qtextlayout.cpp.

1472 {
1473  return eng->lines[i].descent.toReal();
1474 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ draw()

void QTextLine::draw ( QPainter painter,
const QPointF position,
const QTextLayout::FormatRange selection = 0 
) const

Draws a line on the given painter at the specified position.

The selection is reserved for internal use.

Definition at line 2361 of file qtextlayout.cpp.

Referenced by QTextLayout::draw(), qt_format_text(), and QCommonStylePrivate::viewItemDrawText().

2362 {
2363  const QScriptLine &line = eng->lines[i];
2364  QPen pen = p->pen();
2365 
2366  bool noText = (selection && selection->format.property(SuppressText).toBool());
2367 
2368  if (!line.length) {
2369  if (selection
2370  && selection->start <= line.from
2371  && selection->start + selection->length > line.from) {
2372 
2373  const qreal lineHeight = line.height().toReal();
2374  QRectF r(pos.x() + line.x.toReal(), pos.y() + line.y.toReal(),
2375  lineHeight / 2, QFontMetrics(eng->font()).width(QLatin1Char(' ')));
2376  setPenAndDrawBackground(p, QPen(), selection->format, r);
2377  p->setPen(pen);
2378  }
2379  return;
2380  }
2381 
2382 
2383  QTextLineItemIterator iterator(eng, i, pos, selection);
2384  QFixed lineBase = line.base();
2385 
2386  const QFixed y = QFixed::fromReal(pos.y()) + line.y + lineBase;
2387 
2388  bool suppressColors = (eng->option.flags() & QTextOption::SuppressColors);
2389  while (!iterator.atEnd()) {
2390  QScriptItem &si = iterator.next();
2391 
2392  if (selection && selection->start >= 0 && iterator.isOutsideSelection())
2393  continue;
2394 
2397  continue;
2398 
2399  QFixed itemBaseLine = y;
2400  QFont f = eng->font(si);
2402 
2403  if (eng->hasFormats() || selection) {
2404  format = eng->format(&si);
2405  if (suppressColors) {
2406  format.clearForeground();
2407  format.clearBackground();
2409  }
2410  if (selection)
2411  format.merge(selection->format);
2412 
2413  setPenAndDrawBackground(p, pen, format, QRectF(iterator.x.toReal(), (y - lineBase).toReal(),
2414  iterator.itemWidth.toReal(), line.height().toReal()));
2415 
2419  QFixed height = fe->ascent() + fe->descent();
2420  if (valign == QTextCharFormat::AlignSubScript)
2421  itemBaseLine += height / 6;
2422  else if (valign == QTextCharFormat::AlignSuperScript)
2423  itemBaseLine -= height / 2;
2424  }
2425  }
2426 
2428 
2429  if (eng->hasFormats()) {
2430  p->save();
2432  QFixed itemY = y - si.ascent;
2433  if (format.verticalAlignment() == QTextCharFormat::AlignTop) {
2434  itemY = y - lineBase;
2435  }
2436 
2437  QRectF itemRect(iterator.x.toReal(), itemY.toReal(), iterator.itemWidth.toReal(), si.height().toReal());
2438 
2439  eng->docLayout()->drawInlineObject(p, itemRect,
2440  QTextInlineObject(iterator.item, eng),
2441  si.position + eng->block.position(),
2442  format);
2443  if (selection) {
2445  if (bg.style() != Qt::NoBrush) {
2446  QColor c = bg.color();
2447  c.setAlpha(128);
2448  p->fillRect(itemRect, c);
2449  }
2450  }
2451  } else { // si.isTab
2452  QFont f = eng->font(si);
2453  QTextItemInt gf(si, &f, format);
2454  gf.chars = 0;
2455  gf.num_chars = 0;
2456  gf.width = iterator.itemWidth;
2457  p->drawTextItem(QPointF(iterator.x.toReal(), y.toReal()), gf);
2459  QChar visualTab(0x2192);
2460  int w = QFontMetrics(f).width(visualTab);
2461  qreal x = iterator.itemWidth.toReal() - w; // Right-aligned
2462  if (x < 0)
2463  p->setClipRect(QRectF(iterator.x.toReal(), line.y.toReal(),
2464  iterator.itemWidth.toReal(), line.height().toReal()),
2466  else
2467  x /= 2; // Centered
2468  p->drawText(QPointF(iterator.x.toReal() + x,
2469  y.toReal()), visualTab);
2470  }
2471 
2472  }
2473  p->restore();
2474  }
2475 
2476  continue;
2477  }
2478 
2479  unsigned short *logClusters = eng->logClusters(&si);
2481 
2482  QTextItemInt gf(glyphs.mid(iterator.glyphsStart, iterator.glyphsEnd - iterator.glyphsStart),
2483  &f, eng->layoutData->string.unicode() + iterator.itemStart,
2484  iterator.itemEnd - iterator.itemStart, eng->fontEngine(si), format);
2485  gf.logClusters = logClusters + iterator.itemStart - si.position;
2486  gf.width = iterator.itemWidth;
2487  gf.justified = line.justified;
2488  gf.initWithScriptItem(si);
2489 
2490  Q_ASSERT(gf.fontEngine);
2491 
2492  if (eng->underlinePositions) {
2493  // can't have selections in this case
2494  drawMenuText(p, iterator.x, itemBaseLine, si, gf, eng, iterator.itemStart, iterator.glyphsStart);
2495  } else {
2496  QPointF pos(iterator.x.toReal(), itemBaseLine.toReal());
2498  QPainterPath path;
2500 
2501  if (gf.glyphs.numGlyphs)
2502  gf.fontEngine->addOutlineToPath(pos.x(), pos.y(), gf.glyphs, &path, gf.flags);
2503  if (gf.flags) {
2504  const QFontEngine *fe = gf.fontEngine;
2505  const qreal lw = fe->lineThickness().toReal();
2506  if (gf.flags & QTextItem::Underline) {
2507  qreal offs = fe->underlinePosition().toReal();
2508  path.addRect(pos.x(), pos.y() + offs, gf.width.toReal(), lw);
2509  }
2510  if (gf.flags & QTextItem::Overline) {
2511  qreal offs = fe->ascent().toReal() + 1;
2512  path.addRect(pos.x(), pos.y() - offs, gf.width.toReal(), lw);
2513  }
2514  if (gf.flags & QTextItem::StrikeOut) {
2515  qreal offs = fe->ascent().toReal() / 3;
2516  path.addRect(pos.x(), pos.y() - offs, gf.width.toReal(), lw);
2517  }
2518  }
2519 
2520  p->save();
2521  p->setRenderHint(QPainter::Antialiasing);
2522  //Currently QPen with a Qt::NoPen style still returns a default
2523  //QBrush which != Qt::NoBrush so we need this specialcase to reset it
2524  if (p->pen().style() == Qt::NoPen)
2525  p->setBrush(Qt::NoBrush);
2526  else
2527  p->setBrush(p->pen().brush());
2528 
2529  p->setPen(format.textOutline());
2530  p->drawPath(path);
2531  p->restore();
2532  } else {
2533  if (noText)
2534  gf.glyphs.numGlyphs = 0; // slightly less elegant than it should be
2535  p->drawTextItem(pos, gf);
2536  }
2537  }
2540  QBrush c = format.foreground();
2541  if (c.style() != Qt::NoBrush)
2542  p->setPen(c.color());
2543  QChar visualSpace((ushort)0xb7);
2544  p->drawText(QPointF(iterator.x.toReal(), itemBaseLine.toReal()), visualSpace);
2545  p->setPen(pen);
2546  }
2547  }
2548 
2549 
2550  if (eng->hasFormats())
2551  p->setPen(pen);
2552 }
virtual QFixed lineThickness() const
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QTextCharFormat format(const QScriptItem *si) const
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
QFont font(const QScriptItem &si) const
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
qreal y() const
Returns the line&#39;s y position.
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si, QTextItemInt &gf, QTextEngine *eng, int start, int glyph_start)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QList< QGlyphRun > glyphs(int from, int length) const
Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems...
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
virtual void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format)
This function is called to draw the inline object, object, with the given painter within the rectangl...
QBrush brushProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::Brush type...
void clearBackground()
Clears the brush used to paint the document&#39;s background.
Definition: qtextformat.h:347
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int * underlinePositions
Flags flags() const
Returns the flags associated with the option.
Definition: qtextoption.h:121
QFontEngine * fontEngine(const QScriptItem &si, QFixed *ascent=0, QFixed *descent=0, QFixed *leading=0) const
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
const unsigned short * logClusters
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
LayoutData * layoutData
unsigned short * logClusters(const QScriptItem *si) const
bool hasFormats() const
QFixed height() const
QGlyphLayout mid(int position, int n=-1) const
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void clearForeground()
Clears the brush used to paint the document&#39;s foreground.
Definition: qtextformat.h:354
int position() const
Returns the index of the block&#39;s first character within the document.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
QTextEngine * eng
Definition: qtextlayout.h:258
VerticalAlignment
This enum describes the ways that adjacent characters can be vertically aligned.
Definition: qtextformat.h:375
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
QFixed height() const
QGlyphLayout shapedGlyphs(const QScriptItem *si) const
virtual QFixed ascent() const =0
virtual QFixed descent() const =0
Internal QTextItem.
qreal x() const
Returns the line&#39;s x position.
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QScriptLineArray lines
QTextOption option
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
unsigned short flags
QTextBlock block
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
#define ObjectSelectionBrush
Definition: qtextlayout.cpp:72
VerticalAlignment verticalAlignment() const
Returns the vertical alignment used for characters with this format.
Definition: qtextformat.h:486
unsigned short script
#define SuppressText
Definition: qtextlayout.cpp:73
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
The QTextInlineObject class represents an inline object in a QTextLayout.
Definition: qtextlayout.h:69
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
unsigned short ushort
Definition: qglobal.h:995
QVariant property(int propertyId) const
Returns the property specified by the given propertyId.
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343
void setAlpha(int alpha)
Sets the alpha of this color to alpha.
Definition: qcolor.cpp:1094
QBrush foreground() const
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition: qtextformat.h:352
qreal width() const
Returns the line&#39;s width as specified by the layout() function.
qreal toReal() const
Definition: qfixed_p.h:77
signed int length
static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf, const QRectF &r)
QFixed base() const
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
QTextDocumentPrivate * docHandle() const
Definition: qtextobject.h:283
QPen penProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::Pen type...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
qreal height() const
Returns the line&#39;s height.
QAbstractTextDocumentLayout * docLayout() const
virtual QFixed underlinePosition() const
QPen textOutline() const
Returns the pen used to draw the outlines of characters in this format.
Definition: qtextformat.h:491
static qreal toReal(Register *reg, int type, bool *ok=0)
QScriptAnalysis analysis

◆ glyphs()

QList< QGlyphRun > QTextLine::glyphs ( int  from,
int  length 
) const
private

Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems that overlap with the range defined by from and length.

Warning
This function is not part of the public interface.

The arguments specify characters, relative to the text in the layout. Note that it is not possible to use this function to retrieve a subset of the glyphs in a QScriptItem.

Since
4.8
See also
QTextLayout::glyphRuns()

Definition at line 2197 of file qtextlayout.cpp.

Referenced by QTextLayout::glyphRuns(), and QTextFragment::glyphRuns().

2198 {
2199  const QScriptLine &line = eng->lines[i];
2200 
2201  if (line.length == 0)
2202  return QList<QGlyphRun>();
2203 
2204  QHash<QFontEngine *, GlyphInfo> glyphLayoutHash;
2205 
2206  QTextLineItemIterator iterator(eng, i);
2207  qreal y = line.y.toReal() + line.base().toReal();
2208  while (!iterator.atEnd()) {
2209  QScriptItem &si = iterator.next();
2211  continue;
2212 
2213  QPointF pos(iterator.x.toReal(), y);
2214  if (from >= 0 && length >= 0 &&
2215  (from >= si.position + eng->length(&si) || from + length <= si.position))
2216  continue;
2217 
2218  QFont font = eng->font(si);
2219 
2220  QTextItem::RenderFlags flags;
2221  if (font.overline())
2222  flags |= QTextItem::Overline;
2223  if (font.underline())
2224  flags |= QTextItem::Underline;
2225  if (font.strikeOut())
2226  flags |= QTextItem::StrikeOut;
2227  if (si.analysis.bidiLevel % 2)
2228  flags |= QTextItem::RightToLeft;
2229 
2230  QGlyphLayout glyphLayout = eng->shapedGlyphs(&si).mid(iterator.glyphsStart,
2231  iterator.glyphsEnd - iterator.glyphsStart);
2232 
2233  if (glyphLayout.numGlyphs > 0) {
2234  QFontEngine *mainFontEngine = font.d->engineForScript(si.analysis.script);
2235  if (mainFontEngine->type() == QFontEngine::Multi) {
2236  QFontEngineMulti *multiFontEngine = static_cast<QFontEngineMulti *>(mainFontEngine);
2237  int start = 0;
2238  int end;
2239  int which = glyphLayout.glyphs[0] >> 24;
2240  for (end = 0; end < glyphLayout.numGlyphs; ++end) {
2241  const int e = glyphLayout.glyphs[end] >> 24;
2242  if (e == which)
2243  continue;
2244 
2245  QGlyphLayout subLayout = glyphLayout.mid(start, end - start);
2246  glyphLayoutHash.insertMulti(multiFontEngine->engine(which),
2247  GlyphInfo(subLayout, pos, flags));
2248  for (int i = 0; i < subLayout.numGlyphs; i++)
2249  pos += QPointF(subLayout.advances_x[i].toReal(),
2250  subLayout.advances_y[i].toReal());
2251 
2252  start = end;
2253  which = e;
2254  }
2255 
2256  QGlyphLayout subLayout = glyphLayout.mid(start, end - start);
2257  glyphLayoutHash.insertMulti(multiFontEngine->engine(which),
2258  GlyphInfo(subLayout, pos, flags));
2259 
2260  } else {
2261  glyphLayoutHash.insertMulti(mainFontEngine,
2262  GlyphInfo(glyphLayout, pos, flags));
2263  }
2264  }
2265  }
2266 
2268 
2269  QList<QFontEngine *> keys = glyphLayoutHash.uniqueKeys();
2270  for (int i=0; i<keys.size(); ++i) {
2271  QFontEngine *fontEngine = keys.at(i);
2272 
2273  // Make a font for this particular engine
2274  QRawFont font;
2275  QRawFontPrivate *fontD = QRawFontPrivate::get(font);
2276  fontD->fontEngine = fontEngine;
2277  fontD->fontEngine->ref.ref();
2278 
2279 #if defined(Q_WS_WIN)
2280  if (fontEngine->supportsSubPixelPositions())
2282  else
2284 #elif defined(Q_WS_MAC)
2286 #elif !defined(QT_NO_FREETYPE)
2287  if (fontEngine->type() == QFontEngine::Freetype) {
2288  QFontEngineFT *freeTypeEngine = static_cast<QFontEngineFT *>(fontEngine);
2289  switch (freeTypeEngine->defaultHintStyle()) {
2292  break;
2295  break;
2299  break;
2300  };
2301  }
2302 #endif
2303 
2304  QList<GlyphInfo> glyphLayouts = glyphLayoutHash.values(fontEngine);
2305  for (int j=0; j<glyphLayouts.size(); ++j) {
2306  const QPointF &pos = glyphLayouts.at(j).itemPosition;
2307  const QGlyphLayout &glyphLayout = glyphLayouts.at(j).glyphLayout;
2308  const QTextItem::RenderFlags &flags = glyphLayouts.at(j).flags;
2309 
2310  QVarLengthArray<glyph_t> glyphsArray;
2311  QVarLengthArray<QFixedPoint> positionsArray;
2312 
2313  fontEngine->getGlyphPositions(glyphLayout, QTransform(), flags, glyphsArray,
2314  positionsArray);
2315  Q_ASSERT(glyphsArray.size() == positionsArray.size());
2316 
2319  for (int i=0; i<glyphsArray.size(); ++i) {
2320  glyphs.append(glyphsArray.at(i) & 0xffffff);
2321  positions.append(positionsArray.at(i).toPointF() + pos);
2322  }
2323 
2324  QGlyphRun glyphIndexes;
2325  glyphIndexes.setGlyphIndexes(glyphs);
2326  glyphIndexes.setPositions(positions);
2327 
2328  glyphIndexes.setOverline(flags.testFlag(QTextItem::Overline));
2329  glyphIndexes.setUnderline(flags.testFlag(QTextItem::Underline));
2330  glyphIndexes.setStrikeOut(flags.testFlag(QTextItem::StrikeOut));
2331  glyphIndexes.setRawFont(font);
2332 
2333  QPair<QFontEngine *, int> key(fontEngine, int(flags));
2334  if (!glyphsHash.contains(key)) {
2335  glyphsHash.insert(key, glyphIndexes);
2336  } else {
2337  QGlyphRun &glyphRun = glyphsHash[key];
2338 
2339  QVector<quint32> indexes = glyphRun.glyphIndexes();
2340  QVector<QPointF> positions = glyphRun.positions();
2341 
2342  indexes += glyphIndexes.glyphIndexes();
2343  positions += glyphIndexes.positions();
2344 
2345  glyphRun.setGlyphIndexes(indexes);
2346  glyphRun.setPositions(positions);
2347  }
2348  }
2349  }
2350 
2351  return glyphsHash.values();
2352 }
QAtomicInt ref
QFont font(const QScriptItem &si) const
QFixed * advances_y
double qreal
Definition: qglobal.h:1193
void setStrikeOut(bool strikeOut)
Indicates that this QGlyphRun should be painted with an strike out decoration if strikeOut is true...
Definition: qglyphrun.cpp:353
qreal y() const
Returns the line&#39;s y position.
QFixed * advances_x
void setUnderline(bool underline)
Indicates that this QGlyphRun should be painted with an underline decoration if underline is true...
Definition: qglyphrun.cpp:328
HB_Glyph * glyphs
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition: qfont.cpp:1320
QList< QGlyphRun > glyphs(int from, int length) const
Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems...
void setPositions(const QVector< QPointF > &positions)
Sets the positions of the edge of the baseline for each glyph in this set of glyph indexes to positio...
Definition: qglyphrun.cpp:244
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static QRawFontPrivate * get(const QRawFont &font)
Definition: qrawfont_p.h:109
bool ref()
Atomically increments the value of this QAtomicInt.
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QVector< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes...
Definition: qglyphrun.cpp:228
QGlyphLayout mid(int position, int n=-1) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Type type() const =0
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
QStringList keys
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QTextEngine * eng
Definition: qtextlayout.h:258
bool overline() const
Returns true if overline has been set; otherwise returns false.
Definition: qfont.cpp:1344
QVector< quint32 > glyphIndexes() const
Returns the glyph indexes for this QGlyphRun object.
Definition: qglyphrun.cpp:202
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
QGlyphLayout shapedGlyphs(const QScriptItem *si) const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
unsigned short bidiLevel
void getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QScriptLineArray lines
const T & at(int idx) const
The QGlyphRun class provides direct access to the internal glyphs in a font.
Definition: qglyphrun.h:59
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
unsigned short flags
unsigned short script
void setOverline(bool overline)
Indicates that this QGlyphRun should be painted with an overline decoration if overline is true...
Definition: qglyphrun.cpp:303
QPointF toPointF() const
Definition: qfixed_p.h:194
The QRawFont class provides access to a single physical instance of a font.
Definition: qrawfont.h:63
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693
int key
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int length(int item) const
QFont::HintingPreference hintingPreference
Definition: qrawfont_p.h:112
qreal toReal() const
Definition: qfixed_p.h:77
signed int length
QFixed base() const
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
HintStyle defaultHintStyle() const
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
Definition: qfont.cpp:1367
static const KeyPair *const end
QFontEngine * engine(int at) const
void setGlyphIndexes(const QVector< quint32 > &glyphIndexes)
Set the glyph indexes for this QGlyphRun object to glyphIndexes.
Definition: qglyphrun.cpp:217
int size() const
virtual bool supportsSubPixelPositions() const
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void setRawFont(const QRawFont &rawFont)
Sets the font specified by rawFont to be the font used to look up the glyph indexes.
Definition: qglyphrun.cpp:191
QScriptAnalysis analysis

◆ height()

qreal QTextLine::height ( ) const

◆ horizontalAdvance()

qreal QTextLine::horizontalAdvance ( ) const

Returns the horizontal advance of the text.

Since
4.7 The advance of the text is the distance from its position to the next position at which text would naturally be drawn.

By adding the advance to the position of the text line and using this as the position of a second text line, you will be able to position the two lines side-by-side without gaps in-between.

Definition at line 1567 of file qtextlayout.cpp.

Referenced by qt_format_text().

1568 {
1569  return eng->lines[i].textAdvance.toReal();
1570 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ isValid()

bool QTextLine::isValid ( ) const
inline

◆ layout_helper()

void QTextLine::layout_helper ( int  numGlyphs)
private

Definition at line 1782 of file qtextlayout.cpp.

1783 {
1784  QScriptLine &line = eng->lines[i];
1785  line.length = 0;
1786  line.trailingSpaces = 0;
1787  line.textWidth = 0;
1788  line.hasTrailingSpaces = false;
1789 
1790  if (!eng->layoutData->items.size() || line.from >= eng->layoutData->string.length()) {
1791  line.setDefaultHeight(eng);
1792  return;
1793  }
1794 
1795  Q_ASSERT(line.from < eng->layoutData->string.length());
1796 
1797  LineBreakHelper lbh;
1798 
1799  lbh.maxGlyphs = maxGlyphs;
1800 
1801  QTextOption::WrapMode wrapMode = eng->option.wrapMode();
1802  bool breakany = (wrapMode == QTextOption::WrapAnywhere);
1803  lbh.manualWrap = (wrapMode == QTextOption::ManualWrap || wrapMode == QTextOption::NoWrap);
1804 
1805  int item = -1;
1806  int newItem = eng->findItem(line.from);
1807 
1808  LB_DEBUG("from: %d: item=%d, total %d, width available %f", line.from, newItem, eng->layoutData->items.size(), line.width.toReal());
1809 
1810  Qt::Alignment alignment = eng->option.alignment();
1811 
1812  const HB_CharAttributes *attributes = eng->attributes();
1813  if (!attributes)
1814  return;
1815  lbh.currentPosition = line.from;
1816  int end = 0;
1817  lbh.logClusters = eng->layoutData->logClustersPtr;
1818  lbh.resetPreviousGlyph();
1819 
1820  while (newItem < eng->layoutData->items.size()) {
1821  lbh.resetRightBearing();
1822  lbh.softHyphenWidth = 0;
1823  if (newItem != item) {
1824  item = newItem;
1825  const QScriptItem &current = eng->layoutData->items[item];
1826  if (!current.num_glyphs) {
1827  eng->shape(item);
1828  attributes = eng->attributes();
1829  if (!attributes)
1830  return;
1831  lbh.logClusters = eng->layoutData->logClustersPtr;
1832  }
1833  lbh.currentPosition = qMax(line.from, current.position);
1834  end = current.position + eng->length(item);
1835  lbh.glyphs = eng->shapedGlyphs(&current);
1836  QFontEngine *fontEngine = eng->fontEngine(current);
1837  if (lbh.fontEngine != fontEngine) {
1838  lbh.fontEngine = fontEngine;
1839  lbh.minimumRightBearing = qMin(QFixed(),
1840  QFixed::fromReal(fontEngine->minRightBearing()));
1841  }
1842  }
1843  const QScriptItem &current = eng->layoutData->items[item];
1844 
1845  lbh.tmpData.leading = qMax(lbh.tmpData.leading + lbh.tmpData.ascent,
1846  current.leading + current.ascent) - qMax(lbh.tmpData.ascent,
1847  current.ascent);
1848  lbh.tmpData.ascent = qMax(lbh.tmpData.ascent, current.ascent);
1849  lbh.tmpData.descent = qMax(lbh.tmpData.descent, current.descent);
1850 
1852  lbh.whiteSpaceOrObject = true;
1853  if (lbh.checkFullOtherwiseExtend(line))
1854  goto found;
1855 
1856  QFixed x = line.x + line.textWidth + lbh.tmpData.textWidth + lbh.spaceData.textWidth;
1857  QFixed tabWidth = eng->calculateTabWidth(item, x);
1858 
1859  lbh.spaceData.textWidth += tabWidth;
1860  lbh.spaceData.length++;
1861  newItem = item + 1;
1862 
1863  QFixed averageCharWidth = eng->fontEngine(current)->averageCharWidth();
1864  lbh.glyphCount += qRound(tabWidth / averageCharWidth);
1865 
1866  if (lbh.checkFullOtherwiseExtend(line))
1867  goto found;
1869  lbh.whiteSpaceOrObject = true;
1870  // if the line consists only of the line separator make sure
1871  // we have a sane height
1872  if (!line.length && !lbh.tmpData.length)
1873  line.setDefaultHeight(eng);
1875  addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount,
1876  current, lbh.logClusters, lbh.glyphs);
1877  } else {
1878  lbh.tmpData.length++;
1879  lbh.adjustPreviousRightBearing();
1880  }
1881  line += lbh.tmpData;
1882  goto found;
1883  } else if (current.analysis.flags == QScriptAnalysis::Object) {
1884  lbh.whiteSpaceOrObject = true;
1885  lbh.tmpData.length++;
1886 
1888  if (eng->block.docHandle())
1890 
1891  lbh.tmpData.textWidth += current.width;
1892 
1893  newItem = item + 1;
1894  ++lbh.glyphCount;
1895  if (lbh.checkFullOtherwiseExtend(line))
1896  goto found;
1897  } else if (attributes[lbh.currentPosition].whiteSpace) {
1898  lbh.whiteSpaceOrObject = true;
1899  while (lbh.currentPosition < end && attributes[lbh.currentPosition].whiteSpace)
1900  addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount,
1901  current, lbh.logClusters, lbh.glyphs);
1902 
1903  if (!lbh.manualWrap && lbh.spaceData.textWidth > line.width) {
1904  lbh.spaceData.textWidth = line.width; // ignore spaces that fall out of the line.
1905  goto found;
1906  }
1907  } else {
1908  lbh.whiteSpaceOrObject = false;
1909  bool sb_or_ws = false;
1910  lbh.saveCurrentGlyph();
1911  do {
1912  addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount,
1913  current, lbh.logClusters, lbh.glyphs);
1914 
1915  if (attributes[lbh.currentPosition].whiteSpace || attributes[lbh.currentPosition-1].lineBreakType != HB_NoBreak) {
1916  sb_or_ws = true;
1917  break;
1918  } else if (breakany && attributes[lbh.currentPosition].charStop) {
1919  break;
1920  }
1921  } while (lbh.currentPosition < end);
1922  lbh.minw = qMax(lbh.tmpData.textWidth, lbh.minw);
1923 
1924  if (lbh.currentPosition && attributes[lbh.currentPosition - 1].lineBreakType == HB_SoftHyphen) {
1925  // if we are splitting up a word because of
1926  // a soft hyphen then we ...
1927  //
1928  // a) have to take the width of the soft hyphen into
1929  // account to see if the first syllable(s) /and/
1930  // the soft hyphen fit into the line
1931  //
1932  // b) if we are so short of available width that the
1933  // soft hyphen is the first breakable position, then
1934  // we don't want to show it. However we initially
1935  // have to take the width for it into account so that
1936  // the text document layout sees the overflow and
1937  // switch to break-anywhere mode, in which we
1938  // want the soft-hyphen to slip into the next line
1939  // and thus become invisible again.
1940  //
1941  if (line.length)
1942  lbh.softHyphenWidth = lbh.glyphs.advances_x[lbh.logClusters[lbh.currentPosition - 1]];
1943  else if (breakany)
1944  lbh.tmpData.textWidth += lbh.glyphs.advances_x[lbh.logClusters[lbh.currentPosition - 1]];
1945  }
1946 
1947  // The actual width of the text needs to take the right bearing into account. The
1948  // right bearing is left-ward, which means that if the rightmost pixel is to the right
1949  // of the advance of the glyph, the bearing will be negative. We flip the sign
1950  // for the code to be more readable. Logic borrowed from qfontmetrics.cpp.
1951  // We ignore the right bearing if the minimum negative bearing is too little to
1952  // expand the text beyond the edge.
1953  if (sb_or_ws|breakany) {
1954  QFixed rightBearing = lbh.rightBearing; // store previous right bearing
1955 #if !defined(Q_WS_MAC)
1956  if (lbh.calculateNewWidth(line) - lbh.minimumRightBearing > line.width)
1957 #endif
1958  lbh.adjustRightBearing();
1959  if (lbh.checkFullOtherwiseExtend(line)) {
1960  // we are too wide, fix right bearing
1961  if (rightBearing <= 0)
1962  lbh.rightBearing = rightBearing; // take from cache
1963  else
1964  lbh.adjustPreviousRightBearing();
1965 
1966  if (!breakany) {
1967  line.textWidth += lbh.softHyphenWidth;
1968  }
1969 
1970  goto found;
1971  }
1972  }
1973  lbh.saveCurrentGlyph();
1974  }
1975  if (lbh.currentPosition == end)
1976  newItem = item + 1;
1977  }
1978  LB_DEBUG("reached end of line");
1979  lbh.checkFullOtherwiseExtend(line);
1980 found:
1981  if (lbh.rightBearing > 0 && !lbh.whiteSpaceOrObject) // If right bearing has not yet been adjusted
1982  lbh.adjustRightBearing();
1983  line.textAdvance = line.textWidth;
1984  line.textWidth -= qMin(QFixed(), lbh.rightBearing);
1985 
1986  if (line.length == 0) {
1987  LB_DEBUG("no break available in line, adding temp: length %d, width %f, space: length %d, width %f",
1988  lbh.tmpData.length, lbh.tmpData.textWidth.toReal(),
1989  lbh.spaceData.length, lbh.spaceData.textWidth.toReal());
1990  line += lbh.tmpData;
1991  }
1992 
1993  LB_DEBUG("line length = %d, ascent=%f, descent=%f, textWidth=%f (spacew=%f)", line.length, line.ascent.toReal(),
1994  line.descent.toReal(), line.textWidth.toReal(), lbh.spaceData.width.toReal());
1995  LB_DEBUG(" : '%s'", eng->layoutData->string.mid(line.from, line.length).toUtf8().data());
1996 
1997  if (lbh.manualWrap) {
1998  eng->minWidth = qMax(eng->minWidth, line.textWidth);
1999  eng->maxWidth = qMax(eng->maxWidth, line.textWidth);
2000  } else {
2001  eng->minWidth = qMax(eng->minWidth, lbh.minw);
2002  eng->maxWidth += line.textWidth;
2003  }
2004 
2005  if (line.textWidth > 0 && item < eng->layoutData->items.size())
2006  eng->maxWidth += lbh.spaceData.textWidth;
2008  line.textWidth += lbh.spaceData.textWidth;
2009  if (lbh.spaceData.length) {
2010  line.trailingSpaces = lbh.spaceData.length;
2011  line.hasTrailingSpaces = true;
2012  }
2013 
2014  line.justified = false;
2015  line.gridfitted = false;
2016 
2018  if ((lbh.maxGlyphs != INT_MAX && lbh.glyphCount > lbh.maxGlyphs)
2019  || (lbh.maxGlyphs == INT_MAX && line.textWidth > line.width)) {
2020 
2022  line.length = 0;
2023  line.textWidth = 0;
2024  layout_helper(lbh.maxGlyphs);
2026  }
2027  }
2028 }
virtual qreal minRightBearing() const
virtual QFixed averageCharWidth() const
unsigned short trailingSpaces
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static void addNextCluster(int &pos, int end, QScriptLine &line, int &glyphCount, const QScriptItem &current, const unsigned short *logClusters, const QGlyphLayout &glyphs)
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QFixed calculateTabWidth(int index, QFixed x) const
returns the width of tab at index (in the tabs array) with the tab-start at position x ...
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
int findItem(int strPos) const
WrapMode
This enum describes how text is wrapped in a document.
Definition: qtextoption.h:102
Flags flags() const
Returns the flags associated with the option.
Definition: qtextoption.h:121
QFontEngine * fontEngine(const QScriptItem &si, QFixed *ascent=0, QFixed *descent=0, QFixed *leading=0) const
QScriptItemArray items
QFixed textWidth
LayoutData * layoutData
QTextFormat format(int idx) const
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const HB_CharAttributes * attributes() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int position() const
Returns the index of the block&#39;s first character within the document.
QTextEngine * eng
Definition: qtextlayout.h:258
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
QGlyphLayout shapedGlyphs(const QScriptItem *si) const
void layout_helper(int numGlyphs)
qreal x() const
Returns the line&#39;s x position.
unsigned short num_glyphs
uint hasTrailingSpaces
QScriptLineArray lines
QTextOption option
QFixed descent
unsigned short flags
QTextBlock block
unsigned short * logClustersPtr
QFixed leading
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QFixed textAdvance
QFixed descent
void setDefaultHeight(QTextEngine *eng)
void shape(int item) const
The QTextInlineObject class represents an inline object in a QTextLayout.
Definition: qtextlayout.h:69
QFixed maxWidth
int length(int item) const
if(void) toggleToolbarShown
WrapMode wrapMode() const
Returns the text wrap mode defined by the option.
Definition: qtextoption.h:110
qreal toReal() const
Definition: qfixed_p.h:77
signed int length
int formatIndex(const QScriptItem *si) const
Qt::Alignment alignment() const
Returns the text alignment defined by the option.
Definition: qtextoption.h:97
#define LB_DEBUG
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
virtual void positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format)
Lays out the inline object item using the given text format.
QTextDocumentPrivate * docHandle() const
Definition: qtextobject.h:283
static const KeyPair *const end
QTextFormatCollection * formats() const
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QFixed minWidth
#define INT_MAX
QAbstractTextDocumentLayout * docLayout() const
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QScriptAnalysis analysis

◆ leading()

qreal QTextLine::leading ( ) const

Returns the line's leading.

Since
4.6
See also
ascent(), descent(), height()

Definition at line 1498 of file qtextlayout.cpp.

Referenced by QAccessibleTextWidget::characterRect(), and getLineHeightParams().

1499 {
1500  return eng->lines[i].leading.toReal();
1501 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ leadingIncluded()

bool QTextLine::leadingIncluded ( ) const

Returns true if positive leading is included into the line's height; otherwise returns false.

Since
4.6

By default, leading is not included.

See also
setLeadingIncluded()

Definition at line 1539 of file qtextlayout.cpp.

Referenced by QAccessibleTextWidget::characterRect().

1540 {
1541  return eng->lines[i].leadingIncluded;
1542 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ lineNumber()

int QTextLine::lineNumber ( ) const
inline

Returns the position of the line in the text engine.

Definition at line 243 of file qtextlayout.h.

Referenced by QTextControlPrivate::cursorMoveKeyEvent(), QPlainTextEditPrivate::ensureVisible(), QTextCursorPrivate::movePosition(), qt_format_text(), and QTextControl::selectionRect().

243 { return i; }

◆ naturalTextRect()

QRectF QTextLine::naturalTextRect ( ) const

Returns the rectangle covered by the line.

Definition at line 1413 of file qtextlayout.cpp.

Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), QTextLayout::draw(), QTextDocumentLayoutPrivate::drawListItem(), QPlainTextEditPrivate::ensureVisible(), QPlainTextEditControl::hitTest(), QTextDocumentLayoutPrivate::hitTest(), QPlainTextEditPrivate::pageUpDown(), QDeclarativeTextPrivate::setupTextLayout(), and QPlainTextEditPrivate::verticalOffset().

1414 {
1415  const QScriptLine& sl = eng->lines[i];
1416  QFixed x = sl.x + eng->alignLine(sl);
1417 
1418  QFixed width = sl.textWidth;
1419  if (sl.justified)
1420  width = sl.width;
1421 
1422  return QRectF(x.toReal(), sl.y.toReal(), width.toReal(), sl.height().toReal());
1423 }
QFixed textWidth
QFixed height() const
QTextEngine * eng
Definition: qtextlayout.h:258
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal x() const
Returns the line&#39;s x position.
QScriptLineArray lines
QFixed alignLine(const QScriptLine &line)
qreal width() const
Returns the line&#39;s width as specified by the layout() function.
qreal toReal() const
Definition: qfixed_p.h:77

◆ naturalTextWidth()

qreal QTextLine::naturalTextWidth ( ) const

Returns the width of the line that is occupied by text.

This is always <= to width(), and is the minimum width that could be used by layout() without changing the line break position.

Definition at line 1549 of file qtextlayout.cpp.

Referenced by QPlainTextDocumentLayout::blockBoundingRect(), QPlainTextDocumentLayout::blockWidth(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutBlock(), QTextDocumentLayoutPrivate::positionFloat(), qt_format_text(), setupTextLayout(), QCommonStylePrivate::viewItemDrawText(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().

1550 {
1551  return eng->lines[i].textWidth.toReal();
1552 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ position()

QPointF QTextLine::position ( ) const

Returns the line's position relative to the text layout's position.

Definition at line 2042 of file qtextlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::layoutBlock(), and QDeclarativeTextPrivate::setupTextLayout().

2043 {
2044  return QPointF(eng->lines[i].x.toReal(), eng->lines[i].y.toReal());
2045 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ rect()

QRectF QTextLine::rect ( ) const

Returns the line's bounding rectangle.

See also
x(), y(), textLength(), width()

Definition at line 1404 of file qtextlayout.cpp.

Referenced by QTextLayout::draw(), and QTextObjectInterface::~QTextObjectInterface().

1405 {
1406  const QScriptLine& sl = eng->lines[i];
1407  return QRectF(sl.x.toReal(), sl.y.toReal(), sl.width.toReal(), sl.height().toReal());
1408 }
QFixed height() const
QTextEngine * eng
Definition: qtextlayout.h:258
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QScriptLineArray lines
qreal toReal() const
Definition: qfixed_p.h:77

◆ setLeadingIncluded()

void QTextLine::setLeadingIncluded ( bool  included)

Includes positive leading into the line's height if included is true; otherwise does not include leading.

Since
4.6

By default, leading is not included.

Note that negative leading is ignored, it must be handled in the code using the text lines by letting the lines overlap.

See also
leadingIncluded()

Definition at line 1520 of file qtextlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::drawListItem(), QPlainTextDocumentLayout::layoutBlock(), and QTextDocumentLayoutPrivate::layoutBlock().

1521 {
1522  eng->lines[i].leadingIncluded= included;
1523 
1524 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ setLineWidth()

void QTextLine::setLineWidth ( qreal  width)

Lays out the line with the given width.

The line is filled from its starting position with as many characters as will fit into the line. In case the text cannot be split at the end of the line, it will be filled with additional characters to the next whitespace or end of the text.

Definition at line 1579 of file qtextlayout.cpp.

Referenced by QCommandLinkButtonPrivate::descriptionHeight(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutBlock(), QStaticTextPrivate::paintText(), qt_format_text(), QDeclarativeTextPrivate::setupTextLayout(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().

1580 {
1581  QScriptLine &line = eng->lines[i];
1582  if (!eng->layoutData) {
1583  qWarning("QTextLine: Can't set a line width while not layouting.");
1584  return;
1585  }
1586 
1587  if (width > QFIXED_MAX)
1588  width = QFIXED_MAX;
1589 
1590  line.width = QFixed::fromReal(width);
1591  if (line.length
1592  && line.textWidth <= line.width
1593  && line.from + line.length == eng->layoutData->string.length())
1594  // no need to do anything if the line is already layouted and the last one. This optimization helps
1595  // when using things in a single line layout.
1596  return;
1597  line.length = 0;
1598  line.textWidth = 0;
1599 
1601 }
#define QFIXED_MAX
Definition: qfixed_p.h:158
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QFixed textWidth
LayoutData * layoutData
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
QTextEngine * eng
Definition: qtextlayout.h:258
Q_CORE_EXPORT void qWarning(const char *,...)
void layout_helper(int numGlyphs)
QScriptLineArray lines
qreal width() const
Returns the line&#39;s width as specified by the layout() function.
signed int length
#define INT_MAX

◆ setNumColumns() [1/2]

void QTextLine::setNumColumns ( int  numColumns)

Lays out the line.

The line is filled from its starting position with as many characters as are specified by numColumns. In case the text cannot be split until numColumns characters, the line will be filled with as many characters to the next whitespace or end of the text.

Definition at line 1610 of file qtextlayout.cpp.

Referenced by QTextLayout::createLine(), QTextLayout::endLayout(), and QTextDocumentLayoutPrivate::layoutBlock().

1611 {
1612  QScriptLine &line = eng->lines[i];
1613  line.width = QFIXED_MAX;
1614  line.length = 0;
1615  line.textWidth = 0;
1616  layout_helper(numColumns);
1617 }
#define QFIXED_MAX
Definition: qfixed_p.h:158
QFixed textWidth
QTextEngine * eng
Definition: qtextlayout.h:258
void layout_helper(int numGlyphs)
QScriptLineArray lines
signed int length

◆ setNumColumns() [2/2]

void QTextLine::setNumColumns ( int  numColumns,
qreal  alignmentWidth 
)

Lays out the line.

The line is filled from its starting position with as many characters as are specified by numColumns. In case the text cannot be split until numColumns characters, the line will be filled with as many characters to the next whitespace or end of the text. The provided alignmentWidth is used as reference width for alignment.

Definition at line 1627 of file qtextlayout.cpp.

1628 {
1629  QScriptLine &line = eng->lines[i];
1630  line.width = QFixed::fromReal(alignmentWidth);
1631  line.length = 0;
1632  line.textWidth = 0;
1633  layout_helper(numColumns);
1634 }
QFixed textWidth
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
QTextEngine * eng
Definition: qtextlayout.h:258
void layout_helper(int numGlyphs)
QScriptLineArray lines
signed int length

◆ setPosition()

void QTextLine::setPosition ( const QPointF pos)

Moves the line to position pos.

Definition at line 2033 of file qtextlayout.cpp.

Referenced by QCommandLinkButtonPrivate::descriptionHeight(), QItemDelegatePrivate::doTextLayout(), QSvgText::draw(), QPlainTextDocumentLayout::layoutBlock(), QTextDocumentLayoutPrivate::layoutBlock(), QTextDocumentLayoutPrivate::layoutFlow(), QStaticTextPrivate::paintText(), qt_format_text(), QDeclarativeTextPrivate::setupTextLayout(), setupTextLayout(), QCommonStylePrivate::viewItemSize(), and viewItemTextLayout().

2034 {
2035  eng->lines[i].x = QFixed::fromReal(pos.x());
2036  eng->lines[i].y = QFixed::fromReal(pos.y());
2037 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ textLength()

int QTextLine::textLength ( ) const

Returns the length of the text in the line.

See also
naturalTextWidth()

Definition at line 2068 of file qtextlayout.cpp.

Referenced by QAccessibleTextWidget::characterRect(), QTextDocumentLayoutPrivate::drawBlock(), QPlainTextEditControl::hitTest(), QTextDocumentLayoutPrivate::hitTest(), QTextControlPrivate::mouseDoubleClickEvent(), QTextCursorPrivate::movePosition(), QPlainTextEdit::paintEvent(), QTextControlPrivate::rectForPosition(), QDeclarativeTextPrivate::setupTextLayout(), and QCommonStylePrivate::viewItemDrawText().

2069 {
2071  && eng->block.isValid() && i == eng->lines.count()-1) {
2072  return eng->lines[i].length - 1;
2073  }
2074  return eng->lines[i].length + eng->lines[i].trailingSpaces;
2075 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
Flags flags() const
Returns the flags associated with the option.
Definition: qtextoption.h:121
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines
QTextOption option
QTextBlock block
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208

◆ textStart()

int QTextLine::textStart ( ) const

◆ width()

qreal QTextLine::width ( ) const

Returns the line's width as specified by the layout() function.

See also
naturalTextWidth(), x(), y(), textLength(), rect()

Definition at line 1450 of file qtextlayout.cpp.

Referenced by QCommonStylePrivate::viewItemDrawText().

1451 {
1452  return eng->lines[i].width.toReal();
1453 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ x()

qreal QTextLine::x ( ) const

Returns the line's x position.

See also
rect(), y(), textLength(), width()

Definition at line 1430 of file qtextlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::layoutBlock(), and QCommonStylePrivate::viewItemDrawText().

1431 {
1432  return eng->lines[i].x.toReal();
1433 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

◆ xToCursor()

int QTextLine::xToCursor ( qreal  x,
CursorPosition  cpos = CursorBetweenCharacters 
) const

Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor position type, cpos.

See also
cursorToX()

Definition at line 2718 of file qtextlayout.cpp.

Referenced by QPlainTextEditControl::hitTest(), QTextDocumentLayoutPrivate::hitTest(), QTextCursorPrivate::movePosition(), and QLineControl::xToPos().

2719 {
2720  QFixed x = QFixed::fromReal(_x);
2721  const QScriptLine &line = eng->lines[i];
2722  bool lastLine = i >= eng->lines.size() - 1;
2723  int lineNum = i;
2724 
2725  if (!eng->layoutData)
2726  eng->itemize();
2727 
2728  int line_length = textLength();
2729 
2730  if (!line_length)
2731  return line.from;
2732 
2733  int firstItem = eng->findItem(line.from);
2734  int lastItem = eng->findItem(line.from + line_length - 1);
2735  int nItems = (firstItem >= 0 && lastItem >= firstItem)? (lastItem-firstItem+1) : 0;
2736 
2737  if (!nItems)
2738  return 0;
2739 
2740  x -= line.x;
2741  x -= eng->alignLine(line);
2742 // qDebug("xToCursor: x=%f, cpos=%d", x.toReal(), cpos);
2743 
2744  QVarLengthArray<int> visualOrder(nItems);
2745  QVarLengthArray<unsigned char> levels(nItems);
2746  for (int i = 0; i < nItems; ++i)
2747  levels[i] = eng->layoutData->items[i+firstItem].analysis.bidiLevel;
2748  QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data());
2749 
2750  bool visual = eng->visualCursorMovement();
2751  if (x <= 0) {
2752  // left of first item
2753  int item = visualOrder[0]+firstItem;
2754  QScriptItem &si = eng->layoutData->items[item];
2755  if (!si.num_glyphs)
2756  eng->shape(item);
2757  int pos = si.position;
2758  if (si.analysis.bidiLevel % 2)
2759  pos += eng->length(item);
2760  pos = qMax(line.from, pos);
2761  pos = qMin(line.from + line_length, pos);
2762  return pos;
2763  } else if (x < line.textWidth
2764  || (line.justified && x < line.width)) {
2765  // has to be in one of the runs
2766  QFixed pos;
2767  bool rtl = eng->isRightToLeft();
2768 
2769  eng->shapeLine(line);
2770  QVector<int> insertionPoints;
2771  if (visual && rtl)
2772  eng->insertionPointsForLine(lineNum, insertionPoints);
2773  int nchars = 0;
2774  for (int i = 0; i < nItems; ++i) {
2775  int item = visualOrder[i]+firstItem;
2776  QScriptItem &si = eng->layoutData->items[item];
2777  int item_length = eng->length(item);
2778 // qDebug(" item %d, visual %d x_remain=%f", i, item, x.toReal());
2779 
2780  int start = qMax(line.from - si.position, 0);
2781  int end = qMin(line.from + line_length - si.position, item_length);
2782 
2783  unsigned short *logClusters = eng->logClusters(&si);
2784 
2785  int gs = logClusters[start];
2786  int ge = (end == item_length ? si.num_glyphs : logClusters[end]) - 1;
2788 
2789  QFixed item_width = 0;
2791  item_width = si.width;
2792  } else {
2793  int g = gs;
2794  while (g <= ge) {
2795  item_width += glyphs.effectiveAdvance(g);
2796  ++g;
2797  }
2798  }
2799 // qDebug(" start=%d, end=%d, gs=%d, ge=%d item_width=%f", start, end, gs, ge, item_width.toReal());
2800 
2801  if (pos + item_width < x) {
2802  pos += item_width;
2803  nchars += end;
2804  continue;
2805  }
2806 // qDebug(" inside run");
2808  if (cpos == QTextLine::CursorOnCharacter)
2809  return si.position;
2810  bool left_half = (x - pos) < item_width/2;
2811 
2812  if (bool(si.analysis.bidiLevel % 2) != left_half)
2813  return si.position;
2814  return si.position + 1;
2815  }
2816 
2817  int glyph_pos = -1;
2818  QFixed edge;
2819  // has to be inside run
2820  if (cpos == QTextLine::CursorOnCharacter) {
2821  if (si.analysis.bidiLevel % 2) {
2822  pos += item_width;
2823  glyph_pos = gs;
2824  while (gs <= ge) {
2825  if (glyphs.attributes[gs].clusterStart) {
2826  if (pos < x)
2827  break;
2828  glyph_pos = gs;
2829  edge = pos;
2830  break;
2831  }
2832  pos -= glyphs.effectiveAdvance(gs);
2833  ++gs;
2834  }
2835  } else {
2836  glyph_pos = gs;
2837  while (gs <= ge) {
2838  if (glyphs.attributes[gs].clusterStart) {
2839  if (pos > x)
2840  break;
2841  glyph_pos = gs;
2842  edge = pos;
2843  }
2844  pos += glyphs.effectiveAdvance(gs);
2845  ++gs;
2846  }
2847  }
2848  } else {
2849  QFixed dist = INT_MAX/256;
2850  if (si.analysis.bidiLevel % 2) {
2851  if (!visual || rtl || (lastLine && i == nItems - 1)) {
2852  pos += item_width;
2853  while (gs <= ge) {
2854  if (glyphs.attributes[gs].clusterStart && qAbs(x-pos) < dist) {
2855  glyph_pos = gs;
2856  edge = pos;
2857  dist = qAbs(x-pos);
2858  }
2859  pos -= glyphs.effectiveAdvance(gs);
2860  ++gs;
2861  }
2862  } else {
2863  while (ge >= gs) {
2864  if (glyphs.attributes[ge].clusterStart && qAbs(x-pos) < dist) {
2865  glyph_pos = ge;
2866  edge = pos;
2867  dist = qAbs(x-pos);
2868  }
2869  pos += glyphs.effectiveAdvance(ge);
2870  --ge;
2871  }
2872  }
2873  } else {
2874  if (!visual || !rtl || (lastLine && i == 0)) {
2875  while (gs <= ge) {
2876  if (glyphs.attributes[gs].clusterStart && qAbs(x-pos) < dist) {
2877  glyph_pos = gs;
2878  edge = pos;
2879  dist = qAbs(x-pos);
2880  }
2881  pos += glyphs.effectiveAdvance(gs);
2882  ++gs;
2883  }
2884  } else {
2885  QFixed oldPos = pos;
2886  while (gs <= ge) {
2887  pos += glyphs.effectiveAdvance(gs);
2888  if (glyphs.attributes[gs].clusterStart && qAbs(x-pos) < dist) {
2889  glyph_pos = gs;
2890  edge = pos;
2891  dist = qAbs(x-pos);
2892  }
2893  ++gs;
2894  }
2895  pos = oldPos;
2896  }
2897  }
2898  if (qAbs(x-pos) < dist) {
2899  if (visual) {
2900  if (!rtl && i < nItems - 1) {
2901  nchars += end;
2902  continue;
2903  }
2904  if (rtl && nchars > 0)
2905  return insertionPoints[lastLine ? nchars : nchars - 1];
2906  }
2907  return eng->positionInLigature(&si, end, x, pos, -1,
2909  }
2910  }
2911  Q_ASSERT(glyph_pos != -1);
2912  return eng->positionInLigature(&si, end, x, edge, glyph_pos,
2914  }
2915  }
2916  // right of last item
2917 // qDebug() << "right of last";
2918  int item = visualOrder[nItems-1]+firstItem;
2919  QScriptItem &si = eng->layoutData->items[item];
2920  if (!si.num_glyphs)
2921  eng->shape(item);
2922  int pos = si.position;
2923  if (!(si.analysis.bidiLevel % 2))
2924  pos += eng->length(item);
2925  pos = qMax(line.from, pos);
2926 
2927  int maxPos = line.from + line_length;
2928 
2929  // except for the last line we assume that the
2930  // character between lines is a space and we want
2931  // to position the cursor to the left of that
2932  // character.
2933  // ###### breaks with japanese for example
2934  if (this->i < eng->lines.count() - 1)
2935  --maxPos;
2936 
2937  pos = qMin(pos, maxPos);
2938  return pos;
2939 }
bool isRightToLeft() const
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QList< QGlyphRun > glyphs(int from, int length) const
Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in QScriptItems...
int findItem(int strPos) const
int textLength() const
Returns the length of the text in the line.
void insertionPointsForLine(int lineNum, QVector< int > &insertionPoints)
QScriptItemArray items
QFixed textWidth
LayoutData * layoutData
unsigned short * logClusters(const QScriptItem *si) const
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QTextEngine * eng
Definition: qtextlayout.h:258
void shapeLine(const QScriptLine &line)
QGlyphLayout shapedGlyphs(const QScriptItem *si) const
unsigned short bidiLevel
static void bidiReorder(int numRuns, const quint8 *levels, int *visualOrder)
qreal x() const
Returns the line&#39;s x position.
unsigned short num_glyphs
int positionInLigature(const QScriptItem *si, int end, QFixed x, QFixed edge, int glyph_pos, bool cursorOnCharacter)
QScriptLineArray lines
void itemize() const
unsigned short flags
void shape(int item) const
int length(int item) const
QFixed alignLine(const QScriptLine &line)
QFixed effectiveAdvance(int item) const
HB_GlyphAttributes * attributes
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
bool visualCursorMovement() const
#define INT_MAX
QScriptAnalysis analysis

◆ y()

qreal QTextLine::y ( ) const

Returns the line's y position.

See also
x(), rect(), textLength(), width()

Definition at line 1440 of file qtextlayout.cpp.

Referenced by QAccessibleTextWidget::characterRect(), flowPosition(), QTextControlPrivate::rectForPosition(), and QCommonStylePrivate::viewItemDrawText().

1441 {
1442  return eng->lines[i].y.toReal();
1443 }
QTextEngine * eng
Definition: qtextlayout.h:258
QScriptLineArray lines

Friends and Related Functions

◆ QTextFragment

friend class QTextFragment
friend

Definition at line 256 of file qtextlayout.h.

◆ QTextLayout

friend class QTextLayout
friend

Definition at line 255 of file qtextlayout.h.

Properties

◆ eng

QTextEngine* QTextLine::eng
private

Definition at line 258 of file qtextlayout.h.

◆ i

int QTextLine::i
private

Definition at line 257 of file qtextlayout.h.


The documentation for this class was generated from the following files: