Qt 4.8
Macros | Functions
qtextlayout.cpp File Reference
#include "qtextlayout.h"
#include "qtextengine_p.h"
#include <qfont.h>
#include <qapplication.h>
#include <qmath.h>
#include <qpainter.h>
#include <qvarlengtharray.h>
#include <qtextformat.h>
#include <qabstracttextdocumentlayout.h>
#include "qtextdocument_p.h"
#include "qtextformat_p.h"
#include "qstyleoption.h"
#include "qpainterpath.h"
#include "qglyphrun.h"
#include "qglyphrun_p.h"
#include "qrawfont.h"
#include "qrawfont_p.h"
#include <limits.h>
#include <qdebug.h>
#include "qfontengine_p.h"
#include "qfontengine_ft_p.h"

Go to the source code of this file.

Macros

#define LB_DEBUG   if (0) qDebug
 
#define ObjectSelectionBrush   (QTextFormat::ForegroundBrush + 1)
 
#define SuppressBackground   0x513
 
#define SuppressText   0x5012
 

Functions

static void addNextCluster (int &pos, int end, QScriptLine &line, int &glyphCount, const QScriptItem &current, const unsigned short *logClusters, const QGlyphLayout &glyphs)
 
static void addSelectedRegionsToPath (QTextEngine *eng, int lineNumber, const QPointF &pos, QTextLayout::FormatRange *selection, QPainterPath *region, QRectF boundingRect)
 
static QRectF clipIfValid (const QRectF &rect, const QRectF &clip)
 
static void drawMenuText (QPainter *p, QFixed x, QFixed y, const QScriptItem &si, QTextItemInt &gf, QTextEngine *eng, int start, int glyph_start)
 
static void setPenAndDrawBackground (QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf, const QRectF &r)
 

Macro Definition Documentation

◆ LB_DEBUG

#define LB_DEBUG   if (0) qDebug

Definition at line 1639 of file qtextlayout.cpp.

Referenced by QTextLine::layout_helper().

◆ ObjectSelectionBrush

#define ObjectSelectionBrush   (QTextFormat::ForegroundBrush + 1)

Definition at line 72 of file qtextlayout.cpp.

Referenced by QTextLayout::draw(), and QTextLine::draw().

◆ SuppressBackground

#define SuppressBackground   0x513

Definition at line 74 of file qtextlayout.cpp.

Referenced by QTextLayout::draw(), and setPenAndDrawBackground().

◆ SuppressText

#define SuppressText   0x5012

Definition at line 73 of file qtextlayout.cpp.

Referenced by QTextLayout::draw(), and QTextLine::draw().

Function Documentation

◆ addNextCluster()

static void addNextCluster ( int &  pos,
int  end,
QScriptLine line,
int &  glyphCount,
const QScriptItem current,
const unsigned short *  logClusters,
const QGlyphLayout glyphs 
)
inlinestatic

Definition at line 1760 of file qtextlayout.cpp.

Referenced by QTextLine::layout_helper().

1763 {
1764  int glyphPosition = logClusters[pos];
1765  do { // got to the first next cluster
1766  ++pos;
1767  ++line.length;
1768  } while (pos < end && logClusters[pos] == glyphPosition);
1769  do { // calculate the textWidth for the rest of the current cluster.
1770  if (!glyphs.attributes[glyphPosition].dontPrint)
1771  line.textWidth += glyphs.advances_x[glyphPosition];
1772  ++glyphPosition;
1773  } while (glyphPosition < current.num_glyphs && !glyphs.attributes[glyphPosition].clusterStart);
1774 
1775  Q_ASSERT((pos == end && glyphPosition == current.num_glyphs) || logClusters[pos] == glyphPosition);
1776 
1777  ++glyphCount;
1778 }
QFixed * advances_x
QFixed textWidth
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned short num_glyphs
signed int length
HB_GlyphAttributes * attributes
static const KeyPair *const end

◆ addSelectedRegionsToPath()

static void addSelectedRegionsToPath ( QTextEngine eng,
int  lineNumber,
const QPointF pos,
QTextLayout::FormatRange selection,
QPainterPath region,
QRectF  boundingRect 
)
static

Definition at line 1000 of file qtextlayout.cpp.

Referenced by QTextLayout::draw().

1002 {
1003  const QScriptLine &line = eng->lines[lineNumber];
1004 
1005  QTextLineItemIterator iterator(eng, lineNumber, pos, selection);
1006 
1007 
1008 
1009  const qreal selectionY = pos.y() + line.y.toReal();
1010  const qreal lineHeight = line.height().toReal();
1011 
1012  QFixed lastSelectionX = iterator.x;
1013  QFixed lastSelectionWidth;
1014 
1015  while (!iterator.atEnd()) {
1016  iterator.next();
1017 
1018  QFixed selectionX, selectionWidth;
1019  if (iterator.getSelectionBounds(&selectionX, &selectionWidth)) {
1020  if (selectionX == lastSelectionX + lastSelectionWidth) {
1021  lastSelectionWidth += selectionWidth;
1022  continue;
1023  }
1024 
1025  if (lastSelectionWidth > 0) {
1026  QRectF rect = boundingRect & QRectF(lastSelectionX.toReal(), selectionY, lastSelectionWidth.toReal(), lineHeight);
1027  rect.moveLeft(qFloor(rect.left()));
1028  rect.moveTop(qFloor(rect.top()));
1029  region->addRect(rect);
1030  }
1031 
1032  lastSelectionX = selectionX;
1033  lastSelectionWidth = selectionWidth;
1034  }
1035  }
1036  if (lastSelectionWidth > 0) {
1037  QRectF rect = boundingRect & QRectF(lastSelectionX.toReal(), selectionY, lastSelectionWidth.toReal(), lineHeight);
1038  rect.moveLeft(qFloor(rect.left()));
1039  rect.moveTop(qFloor(rect.top()));
1040  region->addRect(rect);
1041  }
1042 }
void moveTop(qreal pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top line at the given y coordinate.
Definition: qrect.h:691
double qreal
Definition: qglobal.h:1193
void moveLeft(qreal pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:689
int qFloor(qreal v)
Definition: qmath.h:73
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
QFixed height() const
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
QScriptLineArray lines
qreal toReal() const
Definition: qfixed_p.h:77
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526

◆ clipIfValid()

static QRectF clipIfValid ( const QRectF rect,
const QRectF clip 
)
inlinestatic

Definition at line 1044 of file qtextlayout.cpp.

Referenced by QTextLayout::draw().

1045 {
1046  return clip.isValid() ? (rect & clip) : rect;
1047 }
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661

◆ drawMenuText()

static void drawMenuText ( QPainter p,
QFixed  x,
QFixed  y,
const QScriptItem si,
QTextItemInt gf,
QTextEngine eng,
int  start,
int  glyph_start 
)
static

Definition at line 2077 of file qtextlayout.cpp.

Referenced by QTextLine::draw().

2079 {
2080  int ge = glyph_start + gf.glyphs.numGlyphs;
2081  int gs = glyph_start;
2082  int end = start + gf.num_chars;
2083  unsigned short *logClusters = eng->logClusters(&si);
2084  QGlyphLayout glyphs = eng->shapedGlyphs(&si);
2085  QFixed orig_width = gf.width;
2086 
2087  int *ul = eng->underlinePositions;
2088  if (ul)
2089  while (*ul != -1 && *ul < start)
2090  ++ul;
2091  bool rtl = si.analysis.bidiLevel % 2;
2092  if (rtl)
2093  x += si.width;
2094 
2095  do {
2096  int gtmp = ge;
2097  int stmp = end;
2098  if (ul && *ul != -1 && *ul < end) {
2099  stmp = *ul;
2100  gtmp = logClusters[*ul-si.position];
2101  }
2102 
2103  gf.glyphs = glyphs.mid(gs, gtmp - gs);
2104  gf.num_chars = stmp - start;
2105  gf.chars = eng->layoutData->string.unicode() + start;
2106  QFixed w = 0;
2107  while (gs < gtmp) {
2108  w += glyphs.effectiveAdvance(gs);
2109  ++gs;
2110  }
2111  start = stmp;
2112  gf.width = w;
2113  if (rtl)
2114  x -= w;
2115  if (gf.num_chars)
2116  p->drawTextItem(QPointF(x.toReal(), y.toReal()), gf);
2117  if (!rtl)
2118  x += w;
2119  if (ul && *ul != -1 && *ul < end) {
2120  // draw underline
2121  gtmp = (*ul == end-1) ? ge : logClusters[*ul+1-si.position];
2122  ++stmp;
2123  gf.glyphs = glyphs.mid(gs, gtmp - gs);
2124  gf.num_chars = stmp - start;
2125  gf.chars = eng->layoutData->string.unicode() + start;
2126  gf.logClusters = logClusters + start - si.position;
2127  w = 0;
2128  while (gs < gtmp) {
2129  w += glyphs.effectiveAdvance(gs);
2130  ++gs;
2131  }
2132  ++start;
2133  gf.width = w;
2135  if (rtl)
2136  x -= w;
2137  p->drawTextItem(QPointF(x.toReal(), y.toReal()), gf);
2138  if (!rtl)
2139  x += w;
2141  ++gf.chars;
2142  ++ul;
2143  }
2144  } while (gs < ge);
2145 
2146  gf.width = orig_width;
2147 }
const QChar * chars
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int * underlinePositions
const unsigned short * logClusters
LayoutData * layoutData
unsigned short * logClusters(const QScriptItem *si) const
QGlyphLayout mid(int position, int n=-1) const
QGlyphLayout glyphs
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
QGlyphLayout shapedGlyphs(const QScriptItem *si) const
unsigned short bidiLevel
QTextCharFormat::UnderlineStyle underlineStyle
void drawTextItem(const QPointF &p, const QTextItem &ti)
Draws the text item ti at position p.
Definition: qpainter.cpp:6864
qreal toReal() const
Definition: qfixed_p.h:77
QFixed effectiveAdvance(int item) const
static const KeyPair *const end
QScriptAnalysis analysis

◆ setPenAndDrawBackground()

static void setPenAndDrawBackground ( QPainter p,
const QPen defaultPen,
const QTextCharFormat chf,
const QRectF r 
)
static

Definition at line 2150 of file qtextlayout.cpp.

Referenced by QTextLine::draw().

2151 {
2152  QBrush c = chf.foreground();
2153  if (c.style() == Qt::NoBrush) {
2154  p->setPen(defaultPen);
2155  }
2156 
2157  QBrush bg = chf.background();
2158  if (bg.style() != Qt::NoBrush && !chf.property(SuppressBackground).toBool())
2159  p->fillRect(QRectF(qFloor(r.x()), qFloor(r.y()), r.width(), r.height()), bg);
2160  if (c.style() != Qt::NoBrush) {
2161  p->setPen(QPen(c, 0));
2162  }
2163 
2164 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
unsigned char c[8]
Definition: qnumeric_p.h:62
int qFloor(qreal v)
Definition: qmath.h:73
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
#define SuppressBackground
Definition: qtextlayout.cpp:74
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
QVariant property(int propertyId) const
Returns the property specified by the given propertyId.
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
QBrush foreground() const
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition: qtextformat.h:352
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420