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