qstatictext.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qstatictext.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4QStaticTextUserData::~QStaticTextUserData()-
5{-
6}-
7QStaticText::QStaticText()-
8 : data(new QStaticTextPrivate)-
9{-
10}
never executed: end of block
0
11-
12-
13-
14-
15QStaticText::QStaticText(const QString &text)-
16 : data(new QStaticTextPrivate)-
17{-
18 data->text = text;-
19 data->invalidate();-
20}
never executed: end of block
0
21-
22-
23-
24-
25QStaticText::QStaticText(const QStaticText &other)-
26{-
27 data = other.data;-
28}
never executed: end of block
0
29-
30-
31-
32-
33QStaticText::~QStaticText()-
34{-
35 ((!(!data || data->ref.load() >= 1)) ? qt_assert("!data || data->ref.load() >= 1",__FILE__,183) : qt_noop());-
36}
never executed: end of block
0
37-
38-
39-
40-
41void QStaticText::detach()-
42{-
43 if (data->ref.load() != 1
data->ref.load() != 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
44 data.detach();
never executed: data.detach();
0
45}
never executed: end of block
0
46void QStaticText::prepare(const QTransform &matrix, const QFont &font)-
47{-
48 data->matrix = matrix;-
49 data->font = font;-
50 data->init();-
51}
never executed: end of block
0
52-
53-
54-
55-
56-
57QStaticText &QStaticText::operator=(const QStaticText &other)-
58{-
59 data = other.data;-
60 return
never executed: return *this;
*this;
never executed: return *this;
0
61}-
62bool QStaticText::operator==(const QStaticText &other) const-
63{-
64 return
never executed: return (data == other.data || (data->text == other.data->text && data->font == other.data->font && data->textWidth == other.data->textWidth));
(data == other.data
never executed: return (data == other.data || (data->text == other.data->text && data->font == other.data->font && data->textWidth == other.data->textWidth));
0
65 || (data->text == other.data->text
never executed: return (data == other.data || (data->text == other.data->text && data->font == other.data->font && data->textWidth == other.data->textWidth));
0
66 && data->font == other.data->font
never executed: return (data == other.data || (data->text == other.data->text && data->font == other.data->font && data->textWidth == other.data->textWidth));
0
67 && data->textWidth == other.data->textWidth));
never executed: return (data == other.data || (data->text == other.data->text && data->font == other.data->font && data->textWidth == other.data->textWidth));
0
68}-
69-
70-
71-
72-
73-
74bool QStaticText::operator!=(const QStaticText &other) const-
75{-
76 return
never executed: return !(*this == other);
!(*this == other);
never executed: return !(*this == other);
0
77}-
78void QStaticText::setText(const QString &text)-
79{-
80 detach();-
81 data->text = text;-
82 data->invalidate();-
83}
never executed: end of block
0
84void QStaticText::setTextFormat(Qt::TextFormat textFormat)-
85{-
86 detach();-
87 data->textFormat = textFormat;-
88 data->invalidate();-
89}
never executed: end of block
0
90-
91-
92-
93-
94-
95-
96Qt::TextFormat QStaticText::textFormat() const-
97{-
98 return
never executed: return Qt::TextFormat(data->textFormat);
Qt::TextFormat(data->textFormat);
never executed: return Qt::TextFormat(data->textFormat);
0
99}-
100-
101-
102-
103-
104-
105-
106QString QStaticText::text() const-
107{-
108 return
never executed: return data->text;
data->text;
never executed: return data->text;
0
109}-
110void QStaticText::setPerformanceHint(PerformanceHint performanceHint)-
111{-
112 if ((performanceHint == ModerateCaching
performanceHin...oderateCachingDescription
TRUEnever evaluated
FALSEnever evaluated
&& !data->useBackendOptimizations
!data->useBackendOptimizationsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
113 || (performanceHint == AggressiveCaching
performanceHin...ressiveCachingDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->useBackendOptimizations
data->useBackendOptimizationsDescription
TRUEnever evaluated
FALSEnever evaluated
)) {
0
114 return;
never executed: return;
0
115 }-
116 detach();-
117 data->useBackendOptimizations = (performanceHint == AggressiveCaching);-
118 data->invalidate();-
119}
never executed: end of block
0
120-
121-
122-
123-
124-
125-
126QStaticText::PerformanceHint QStaticText::performanceHint() const-
127{-
128 return
never executed: return data->useBackendOptimizations ? AggressiveCaching : ModerateCaching;
data->useBackendOptimizations ? AggressiveCaching : ModerateCaching;
never executed: return data->useBackendOptimizations ? AggressiveCaching : ModerateCaching;
0
129}-
130-
131-
132-
133-
134-
135-
136void QStaticText::setTextOption(const QTextOption &textOption)-
137{-
138 detach();-
139 data->textOption = textOption;-
140 data->invalidate();-
141}
never executed: end of block
0
142-
143-
144-
145-
146QTextOption QStaticText::textOption() const-
147{-
148 return
never executed: return data->textOption;
data->textOption;
never executed: return data->textOption;
0
149}-
150void QStaticText::setTextWidth(qreal textWidth)-
151{-
152 detach();-
153 data->textWidth = textWidth;-
154 data->invalidate();-
155}
never executed: end of block
0
156-
157-
158-
159-
160-
161-
162qreal QStaticText::textWidth() const-
163{-
164 return
never executed: return data->textWidth;
data->textWidth;
never executed: return data->textWidth;
0
165}-
166-
167-
168-
169-
170-
171-
172QSizeF QStaticText::size() const-
173{-
174 if (data->needsRelayout
data->needsRelayoutDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
175 data->init();
never executed: data->init();
0
176 return
never executed: return data->actualSize;
data->actualSize;
never executed: return data->actualSize;
0
177}-
178-
179QStaticTextPrivate::QStaticTextPrivate()-
180 : textWidth(-1.0), items(0), itemCount(0), glyphPool(0), positionPool(0),-
181 needsRelayout(true), useBackendOptimizations(false), textFormat(Qt::AutoText),-
182 untransformedCoordinates(false)-
183{-
184}
never executed: end of block
0
185-
186QStaticTextPrivate::QStaticTextPrivate(const QStaticTextPrivate &other)-
187 : text(other.text), font(other.font), textWidth(other.textWidth), matrix(other.matrix),-
188 items(0), itemCount(0), glyphPool(0), positionPool(0), textOption(other.textOption),-
189 needsRelayout(true), useBackendOptimizations(other.useBackendOptimizations),-
190 textFormat(other.textFormat), untransformedCoordinates(other.untransformedCoordinates)-
191{-
192}
never executed: end of block
0
193-
194QStaticTextPrivate::~QStaticTextPrivate()-
195{-
196 delete[] items;-
197 delete[] glyphPool;-
198 delete[] positionPool;-
199}
never executed: end of block
0
200-
201QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q)-
202{-
203 return
never executed: return q->data.data();
q->data.data();
never executed: return q->data.data();
0
204}-
205-
206namespace {-
207-
208 class DrawTextItemRecorder: public QPaintEngine-
209 {-
210 public:-
211 DrawTextItemRecorder(bool untransformedCoordinates, bool useBackendOptimizations)-
212 : m_dirtyPen(false), m_useBackendOptimizations(useBackendOptimizations),-
213 m_untransformedCoordinates(untransformedCoordinates), m_currentColor(Qt::black)-
214 {-
215 }
never executed: end of block
0
216-
217 virtual void updateState(const QPaintEngineState &newState) override-
218 {-
219 if (newState.state() & QPaintEngine::DirtyPen
newState.state...gine::DirtyPenDescription
TRUEnever evaluated
FALSEnever evaluated
0
220 && newState.pen().color() != m_currentColor
newState.pen()...m_currentColorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
221 m_dirtyPen = true;-
222 m_currentColor = newState.pen().color();-
223 }
never executed: end of block
0
224 }
never executed: end of block
0
225-
226 virtual void drawTextItem(const QPointF &position, const QTextItem &textItem) override-
227 {-
228 const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);-
229-
230 QStaticTextItem currentItem;-
231 currentItem.setFontEngine(ti.fontEngine);-
232 currentItem.font = ti.font();-
233 currentItem.glyphOffset = m_glyphs.size();-
234 currentItem.positionOffset = m_glyphs.size();-
235 currentItem.useBackendOptimizations = m_useBackendOptimizations;-
236 if (m_dirtyPen
m_dirtyPenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
237 currentItem.color = m_currentColor;
never executed: currentItem.color = m_currentColor;
0
238-
239 QTransform matrix = m_untransformedCoordinates
m_untransformedCoordinatesDescription
TRUEnever evaluated
FALSEnever evaluated
? QTransform() : state->transform();
0
240 matrix.translate(position.x(), position.y());-
241-
242 QVarLengthArray<glyph_t> glyphs;-
243 QVarLengthArray<QFixedPoint> positions;-
244 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);-
245-
246 int size = glyphs.size();-
247 ((!(size == positions.size())) ? qt_assert("size == positions.size()",__FILE__,472) : qt_noop());-
248 currentItem.numGlyphs = size;-
249-
250 m_glyphs.resize(m_glyphs.size() + size);-
251 m_positions.resize(m_glyphs.size());-
252-
253 glyph_t *glyphsDestination = m_glyphs.data() + currentItem.glyphOffset;-
254 memcpy(glyphsDestination, glyphs.constData(), sizeof(glyph_t) * currentItem.numGlyphs);-
255-
256 QFixedPoint *positionsDestination = m_positions.data() + currentItem.positionOffset;-
257 memcpy(positionsDestination, positions.constData(), sizeof(QFixedPoint) * currentItem.numGlyphs);-
258-
259 m_items.append(currentItem);-
260 }
never executed: end of block
0
261-
262 virtual void drawPolygon(const QPointF *, int , PolygonDrawMode ) override-
263 {-
264-
265 }-
266-
267 virtual bool begin(QPaintDevice *) override { return
never executed: return true;
true;
never executed: return true;
}
0
268 virtual bool end() override { return
never executed: return true;
true;
never executed: return true;
}
0
269 virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) override {}-
270 virtual Type type() const override-
271 {-
272 return
never executed: return User;
User;
never executed: return User;
0
273 }-
274-
275 QVector<QStaticTextItem> items() const-
276 {-
277 return
never executed: return m_items;
m_items;
never executed: return m_items;
0
278 }-
279-
280 QVector<QFixedPoint> positions() const-
281 {-
282 return
never executed: return m_positions;
m_positions;
never executed: return m_positions;
0
283 }-
284-
285 QVector<glyph_t> glyphs() const-
286 {-
287 return
never executed: return m_glyphs;
m_glyphs;
never executed: return m_glyphs;
0
288 }-
289-
290 private:-
291 QVector<QStaticTextItem> m_items;-
292 QVector<QFixedPoint> m_positions;-
293 QVector<glyph_t> m_glyphs;-
294-
295 bool m_dirtyPen;-
296 bool m_useBackendOptimizations;-
297 bool m_untransformedCoordinates;-
298 QColor m_currentColor;-
299 };-
300-
301 class DrawTextItemDevice: public QPaintDevice-
302 {-
303 public:-
304 DrawTextItemDevice(bool untransformedCoordinates, bool useBackendOptimizations)-
305 {-
306 m_paintEngine = new DrawTextItemRecorder(untransformedCoordinates,-
307 useBackendOptimizations);-
308 }
never executed: end of block
0
309-
310 ~DrawTextItemDevice()-
311 {-
312 delete m_paintEngine;-
313 }
never executed: end of block
0
314-
315 int metric(PaintDeviceMetric m) const override-
316 {-
317 int val;-
318 switch (m) {-
319 case
never executed: case PdmWidth:
PdmWidth:
never executed: case PdmWidth:
0
320 case
never executed: case PdmHeight:
PdmHeight:
never executed: case PdmHeight:
0
321 case
never executed: case PdmWidthMM:
PdmWidthMM:
never executed: case PdmWidthMM:
0
322 case
never executed: case PdmHeightMM:
PdmHeightMM:
never executed: case PdmHeightMM:
0
323 val = 0;-
324 break;
never executed: break;
0
325 case
never executed: case PdmDpiX:
PdmDpiX:
never executed: case PdmDpiX:
0
326 case
never executed: case PdmPhysicalDpiX:
PdmPhysicalDpiX:
never executed: case PdmPhysicalDpiX:
0
327 val = qt_defaultDpiX();-
328 break;
never executed: break;
0
329 case
never executed: case PdmDpiY:
PdmDpiY:
never executed: case PdmDpiY:
0
330 case
never executed: case PdmPhysicalDpiY:
PdmPhysicalDpiY:
never executed: case PdmPhysicalDpiY:
0
331 val = qt_defaultDpiY();-
332 break;
never executed: break;
0
333 case
never executed: case PdmNumColors:
PdmNumColors:
never executed: case PdmNumColors:
0
334 val = 16777216;-
335 break;
never executed: break;
0
336 case
never executed: case PdmDepth:
PdmDepth:
never executed: case PdmDepth:
0
337 val = 24;-
338 break;
never executed: break;
0
339 case
never executed: case PdmDevicePixelRatio:
PdmDevicePixelRatio:
never executed: case PdmDevicePixelRatio:
0
340 val = 1;-
341 break;
never executed: break;
0
342 case
never executed: case PdmDevicePixelRatioScaled:
PdmDevicePixelRatioScaled:
never executed: case PdmDevicePixelRatioScaled:
0
343 val = devicePixelRatioFScale();-
344 break;
never executed: break;
0
345 default
never executed: default:
:
never executed: default:
0
346 val = 0;-
347 QMessageLogger(__FILE__, 572, __PRETTY_FUNCTION__).warning("DrawTextItemDevice::metric: Invalid metric command");-
348 }
never executed: end of block
0
349 return
never executed: return val;
val;
never executed: return val;
0
350 }-
351-
352 virtual QPaintEngine *paintEngine() const override-
353 {-
354 return
never executed: return m_paintEngine;
m_paintEngine;
never executed: return m_paintEngine;
0
355 }-
356-
357 QVector<glyph_t> glyphs() const-
358 {-
359 return
never executed: return m_paintEngine->glyphs();
m_paintEngine->glyphs();
never executed: return m_paintEngine->glyphs();
0
360 }-
361-
362 QVector<QFixedPoint> positions() const-
363 {-
364 return
never executed: return m_paintEngine->positions();
m_paintEngine->positions();
never executed: return m_paintEngine->positions();
0
365 }-
366-
367 QVector<QStaticTextItem> items() const-
368 {-
369 return
never executed: return m_paintEngine->items();
m_paintEngine->items();
never executed: return m_paintEngine->items();
0
370 }-
371-
372 private:-
373 DrawTextItemRecorder *m_paintEngine;-
374 };-
375}-
376-
377void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p)-
378{-
379 bool preferRichText = textFormat == Qt::RichText
textFormat == Qt::RichTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 || (textFormat == Qt::AutoText
textFormat == Qt::AutoTextDescription
TRUEnever evaluated
FALSEnever evaluated
&& Qt::mightBeRichText(text)
Qt::mightBeRichText(text)Description
TRUEnever evaluated
FALSEnever evaluated
);
0
381-
382 if (!preferRichText
!preferRichTextDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
383 QTextLayout textLayout;-
384 textLayout.setText(text);-
385 textLayout.setFont(font);-
386 textLayout.setTextOption(textOption);-
387 textLayout.setCacheEnabled(true);-
388-
389 qreal leading = QFontMetricsF(font).leading();-
390 qreal height = -leading;-
391-
392 textLayout.beginLayout();-
393 while (1) {-
394 QTextLine line = textLayout.createLine();-
395 if (!line.isValid()
!line.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
396 break;
never executed: break;
0
397-
398 if (textWidth >= 0.0
textWidth >= 0.0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
399 line.setLineWidth(textWidth);
never executed: line.setLineWidth(textWidth);
0
400 height += leading;-
401 line.setPosition(QPointF(0.0, height));-
402 height += line.height();-
403 }
never executed: end of block
0
404 textLayout.endLayout();-
405-
406 actualSize = textLayout.boundingRect().size();-
407 textLayout.draw(p, topLeftPosition);-
408 }
never executed: end of block
else {
0
409 QTextDocument document;-
410-
411 QColor color = p->pen().color();-
412 document.setDefaultStyleSheet(QString::fromLatin1("body { color: #%1%2%3 }")-
413 .arg(QString::number(color.red(), 16), 2, QLatin1Char('0'))-
414 .arg(QString::number(color.green(), 16), 2, QLatin1Char('0'))-
415 .arg(QString::number(color.blue(), 16), 2, QLatin1Char('0')));-
416-
417 document.setDefaultFont(font);-
418 document.setDocumentMargin(0.0);-
419-
420 document.setHtml(text);-
421-
422-
423-
424 if (textWidth >= 0.0
textWidth >= 0.0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
425 document.setTextWidth(textWidth);
never executed: document.setTextWidth(textWidth);
0
426 else-
427 document.adjustSize();
never executed: document.adjustSize();
0
428 document.setDefaultTextOption(textOption);-
429-
430 p->save();-
431 p->translate(topLeftPosition);-
432 QAbstractTextDocumentLayout::PaintContext ctx;-
433 ctx.palette.setColor(QPalette::Text, p->pen().color());-
434 document.documentLayout()->draw(p, ctx);-
435 p->restore();-
436-
437 if (textWidth >= 0.0
textWidth >= 0.0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
438 document.adjustSize();
never executed: document.adjustSize();
0
439-
440 actualSize = document.size();-
441 }
never executed: end of block
0
442}-
443-
444void QStaticTextPrivate::init()-
445{-
446 delete[] items;-
447 delete[] glyphPool;-
448 delete[] positionPool;-
449-
450 position = QPointF(0, 0);-
451-
452 DrawTextItemDevice device(untransformedCoordinates, useBackendOptimizations);-
453 {-
454 QPainter painter(&device);-
455 painter.setFont(font);-
456 painter.setTransform(matrix);-
457-
458 paintText(QPointF(0, 0), &painter);-
459 }-
460-
461 QVector<QStaticTextItem> deviceItems = device.items();-
462 QVector<QFixedPoint> positions = device.positions();-
463 QVector<glyph_t> glyphs = device.glyphs();-
464-
465 itemCount = deviceItems.size();-
466 items = new QStaticTextItem[itemCount];-
467-
468 glyphPool = new glyph_t[glyphs.size()];-
469 memcpy(glyphPool, glyphs.constData(), glyphs.size() * sizeof(glyph_t));-
470-
471 positionPool = new QFixedPoint[positions.size()];-
472 memcpy(positionPool, positions.constData(), positions.size() * sizeof(QFixedPoint));-
473-
474 for (int i=0; i<itemCount
i<itemCountDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
475 items[i] = deviceItems.at(i);-
476-
477 items[i].glyphs = glyphPool + items[i].glyphOffset;-
478 items[i].glyphPositions = positionPool + items[i].positionOffset;-
479 }
never executed: end of block
0
480-
481 needsRelayout = false;-
482}
never executed: end of block
0
483-
484-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9