aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/items/qsgtextnode.cpp
blob: f48b65f16808f6d5b16164321b602c950271e126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qsgtextnode_p.h"
#include "qsgsimplerectnode.h"
#include <private/qsgadaptationlayer_p.h>
#include <private/qsgdistancefieldglyphcache_p.h>
#include <private/qsgdistancefieldglyphnode_p.h>

#include <private/qsgcontext_p.h>

#include <QtCore/qpoint.h>
#include <qmath.h>
#include <qtextdocument.h>
#include <qtextlayout.h>
#include <qabstracttextdocumentlayout.h>
#include <qxmlstream.h>
#include <qrawfont.h>
#include <private/qdeclarativestyledtext_p.h>
#include <private/qfont_p.h>
#include <private/qfontengine_p.h>
#include <private/qrawfont_p.h>

QT_BEGIN_NAMESPACE

/*!
  Creates an empty QSGTextNode
*/
QSGTextNode::QSGTextNode(QSGContext *context)
    : m_context(context), m_cursorNode(0)
{
#if defined(QML_RUNTIME_TESTING)
    description = QLatin1String("text");
#endif
}

QSGTextNode::~QSGTextNode()
{
}

#if 0
void QSGTextNode::setColor(const QColor &color)
{
    if (m_usePixmapCache) {
        setUpdateFlag(UpdateNodes);
    } else {
        for (int i=0; i<childCount(); ++i) {
            QSGNode *childNode = childAtIndex(i);
            if (childNode->subType() == GlyphNodeSubType) {
                QSGGlyphNode *glyphNode = static_cast<QSGGlyphNode *>(childNode);
                if (glyphNode->color() == m_color)
                    glyphNode->setColor(color);
            } else if (childNode->subType() == SolidRectNodeSubType) {
                QSGSimpleRectNode *solidRectNode = static_cast<QSGSimpleRectNode *>(childNode);
                if (solidRectNode->color() == m_color)
                    solidRectNode->setColor(color);
            }
        }
    }
    m_color = color;
}

void QSGTextNode::setStyleColor(const QColor &styleColor)
{
    if (m_textStyle != QSGTextNode::NormalTextStyle) {
        if (m_usePixmapCache) {
            setUpdateFlag(UpdateNodes);
        } else {
            for (int i=0; i<childCount(); ++i) {
                QSGNode *childNode = childAtIndex(i);
                if (childNode->subType() == GlyphNodeSubType) {
                    QSGGlyphNode *glyphNode = static_cast<QSGGlyphNode *>(childNode);
                    if (glyphNode->color() == m_styleColor)
                        glyphNode->setColor(styleColor);
                } else if (childNode->subType() == SolidRectNodeSubType) {
                    QSGSimpleRectNode *solidRectNode = static_cast<QSGSimpleRectNode *>(childNode);
                    if (solidRectNode->color() == m_styleColor)
                        solidRectNode->setColor(styleColor);
                }
            }
        }
    }
    m_styleColor = styleColor;
}
#endif

void QSGTextNode::addTextDecorations(const QPointF &position, const QRawFont &font, const QColor &color,
                                     qreal width, bool hasOverline, bool hasStrikeOut, bool hasUnderline)
{
    Q_ASSERT(font.isValid());
    QRawFontPrivate *dptrFont = QRawFontPrivate::get(font);
    QFontEngine *fontEngine = dptrFont->fontEngine;

    qreal lineThickness = fontEngine->lineThickness().toReal();

    QRectF line(position.x(), position.y() - lineThickness / 2.0, width, lineThickness);

    if (hasUnderline) {
        int underlinePosition = fontEngine->underlinePosition().ceil().toInt();
        QRectF underline(line);
        underline.translate(0.0, underlinePosition);
        appendChildNode(new QSGSimpleRectNode(underline, color));
    }

    qreal ascent = font.ascent();
    if (hasOverline) {
        QRectF overline(line);
        overline.translate(0.0, -ascent);
        appendChildNode(new QSGSimpleRectNode(overline, color));
    }

    if (hasStrikeOut) {
        QRectF strikeOut(line);
        strikeOut.translate(0.0, ascent / -3.0);
        appendChildNode(new QSGSimpleRectNode(strikeOut, color));
    }
}

QSGGlyphNode *QSGTextNode::addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
                                           QSGText::TextStyle style, const QColor &styleColor)
{
    QSGGlyphNode *node = m_context->createGlyphNode();
    if (QSGDistanceFieldGlyphCache::distanceFieldEnabled()) {
        QSGDistanceFieldGlyphNode *dfNode = static_cast<QSGDistanceFieldGlyphNode *>(node);
        dfNode->setStyle(style);
        dfNode->setStyleColor(styleColor);
    }
    node->setGlyphs(position, glyphs);
    node->setColor(color);

    appendChildNode(node);

    return node;
}

void QSGTextNode::addTextDocument(const QPointF &position, QTextDocument *textDocument, const QColor &color,
                                  QSGText::TextStyle style, const QColor &styleColor)
{
    Q_UNUSED(position)
    QTextFrame *textFrame = textDocument->rootFrame();
    QPointF p = textDocument->documentLayout()->frameBoundingRect(textFrame).topLeft();

    QTextFrame::iterator it = textFrame->begin();
    while (!it.atEnd()) {
        addTextBlock(p, textDocument, it.currentBlock(), color, style, styleColor);
        ++it;
    }
}

void QSGTextNode::setCursor(const QRectF &rect, const QColor &color)
{
    if (m_cursorNode != 0)
        delete m_cursorNode;

    m_cursorNode = new QSGSimpleRectNode(rect, color);
    appendChildNode(m_cursorNode);
}

QSGGlyphNode *QSGTextNode::addGlyphsAndDecoration(const QPointF &position, const QGlyphRun &glyphRun,
                                         const QColor &color, QSGText::TextStyle style,
                                         const QColor &styleColor,
                                         const QPointF &decorationPosition)
{
    QSGGlyphNode *node = addGlyphs(position, glyphRun, color, style, styleColor);

    if (glyphRun.strikeOut() || glyphRun.overline() || glyphRun.underline()) {
        QRectF rect = glyphRun.boundingRect();
        qreal width = rect.right() - decorationPosition.x();

        addTextDecorations(decorationPosition, glyphRun.rawFont(), color, width,
                           glyphRun.overline(), glyphRun.strikeOut(), glyphRun.underline());
    }

    return node;
}

namespace {

    struct BinaryTreeNode {
        enum SelectionState {
            Unselected,
            Selected
        };

        BinaryTreeNode()
            : selectionState(Unselected)
            , leftChildIndex(-1)
            , rightChildIndex(-1)
        {

        }

        BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect)
            : glyphRun(g)
            , boundingRect(brect)
            , selectionState(selState)
            , leftChildIndex(-1)
            , rightChildIndex(-1)
        {
        }

        QGlyphRun glyphRun;
        QRectF boundingRect;
        SelectionState selectionState;

        int leftChildIndex;
        int rightChildIndex;

        static void insert(QVarLengthArray<BinaryTreeNode> *binaryTree,
                           const QGlyphRun &glyphRun,
                           SelectionState selectionState)
        {
            int newIndex = binaryTree->size();
            QRectF searchRect = glyphRun.boundingRect();

            binaryTree->append(BinaryTreeNode(glyphRun, selectionState, searchRect));
            if (newIndex == 0)
                return;

            int searchIndex = 0;
            forever {
                BinaryTreeNode *node = binaryTree->data() + searchIndex;
                if (searchRect.left() < node->boundingRect.left()) {
                    if (node->leftChildIndex < 0) {
                        node->leftChildIndex = newIndex;
                        break;
                    } else {
                        searchIndex = node->leftChildIndex;
                    }
                } else {
                    if (node->rightChildIndex < 0) {
                        node->rightChildIndex = newIndex;
                        break;
                    } else {
                        searchIndex = node->rightChildIndex;
                    }
                }
            }
        }

        static void inOrder(const QVarLengthArray<BinaryTreeNode> &binaryTree,
                            QVarLengthArray<int> *sortedIndexes,
                            int currentIndex = 0)
        {
            Q_ASSERT(currentIndex < binaryTree.size());

            const BinaryTreeNode *node = binaryTree.data() + currentIndex;
            if (node->leftChildIndex >= 0)
                inOrder(binaryTree, sortedIndexes, node->leftChildIndex);

            sortedIndexes->append(currentIndex);

            if (node->rightChildIndex >= 0)
                inOrder(binaryTree, sortedIndexes, node->rightChildIndex);
        }
    };
}

void QSGTextNode::addTextLayout(const QPointF &position, QTextLayout *textLayout, const QColor &color,
                                QSGText::TextStyle style, const QColor &styleColor,
                                const QColor &selectionColor, const QColor &selectedTextColor,
                                int selectionStart, int selectionEnd)
{
    QFont font = textLayout->font();
    bool overline = font.overline();
    bool underline = font.underline();
    bool strikeOut = font.strikeOut();
    QRawFont decorationRawFont = QRawFont::fromFont(font);

    if (selectionStart < 0 || selectionEnd < 0) {
        for (int i=0; i<textLayout->lineCount(); ++i) {
            QTextLine line = textLayout->lineAt(i);

            QList<QGlyphRun> glyphRuns = line.glyphRuns();
            for (int j=0; j<glyphRuns.size(); ++j) {
                QGlyphRun glyphRun = glyphRuns.at(j);
                QPointF pos(position + QPointF(0, glyphRun.rawFont().ascent()));
                addGlyphs(pos, glyphRun, color, style, styleColor);
            }

            addTextDecorations(QPointF(line.x(), line.y() + decorationRawFont.ascent()),
                               decorationRawFont, color, line.naturalTextWidth(),
                               overline, strikeOut, underline);
        }

    } else {
        QVarLengthArray<BinaryTreeNode> binaryNodes;
        for (int i=0; i<textLayout->lineCount(); ++i) {
            QTextLine line = textLayout->lineAt(i);

            // Make a list of glyph runs sorted on left-most x coordinate to make it possible
            // to find the correct selection rects
            if (line.textStart() < selectionStart) {
                QList<QGlyphRun> glyphRuns = line.glyphRuns(line.textStart(),
                                                            qMin(selectionStart - line.textStart(),
                                                                 line.textLength()));
                for (int j=0; j<glyphRuns.size(); ++j) {
                    const QGlyphRun &glyphRun = glyphRuns.at(j);
                    BinaryTreeNode::insert(&binaryNodes, glyphRun, BinaryTreeNode::Unselected);
                }
            }

            int lineEnd = line.textStart() + line.textLength();

            // Add selected text
            if (lineEnd >= selectionStart && selectionStart >= line.textStart()) {
                QList<QGlyphRun> selectedGlyphRuns = line.glyphRuns(selectionStart,
                                                                    selectionEnd - selectionStart + 1);
                for (int j=0; j<selectedGlyphRuns.size(); ++j) {
                    const QGlyphRun &selectedGlyphRun = selectedGlyphRuns.at(j);
                    BinaryTreeNode::insert(&binaryNodes, selectedGlyphRun, BinaryTreeNode::Selected);
                }
            }

            // If there is selected text in this line, add regular text after selection
            if (selectionEnd >= line.textStart() && selectionEnd < lineEnd) {
                QList<QGlyphRun> glyphRuns = line.glyphRuns(selectionEnd + 1, lineEnd - selectionEnd);
                for (int j=0; j<glyphRuns.size(); ++j) {
                    const QGlyphRun &glyphRun = glyphRuns.at(j);
                    BinaryTreeNode::insert(&binaryNodes, glyphRun, BinaryTreeNode::Unselected);
                }
            }

            // Go through glyph runs sorted by x position and add glyph nodes/text decoration
            // and selection rects to the graph
            QVarLengthArray<int> sortedIndexes;
            BinaryTreeNode::inOrder(binaryNodes, &sortedIndexes);

            Q_ASSERT(sortedIndexes.size() == binaryNodes.size());

            BinaryTreeNode::SelectionState currentSelectionState = BinaryTreeNode::Unselected;
            QRectF currentRect = QRectF(line.x(), line.y(), 1, 1);
            for (int i=0; i<=sortedIndexes.size(); ++i) {
                BinaryTreeNode *node = 0;
                if (i < sortedIndexes.size()) {
                    int sortedIndex = sortedIndexes.at(i);
                    Q_ASSERT(sortedIndex < binaryNodes.size());

                    node = binaryNodes.data() + sortedIndex;
                    const QGlyphRun &glyphRun = node->glyphRun;

                    QColor currentColor = node->selectionState == BinaryTreeNode::Unselected
                            ? color
                            : selectedTextColor;

                    QPointF pos(position + QPointF(0, glyphRun.rawFont().ascent()));
                    addGlyphs(pos, glyphRun, currentColor, style, styleColor);

                    if (i == 0)
                        currentSelectionState = node->selectionState;
                }

                // If we've reached an unselected node from a selected node, we add the
                // selection rect to the graph, and we add decoration every time the
                // selection state changes, because that means the text color changes
                if (node == 0 || node->selectionState != currentSelectionState) {
                    if (node != 0)
                        currentRect.setRight(node->boundingRect.left());
                    else
                        currentRect.setWidth(line.naturalTextWidth() - (currentRect.x() - line.x()));
                    currentRect.setY(line.y());
                    currentRect.setHeight(line.height());

                    // Draw selection all the way up to the left edge of the unselected item
                    if (currentSelectionState == BinaryTreeNode::Selected)
                        prependChildNode(new QSGSimpleRectNode(currentRect, selectionColor));

                    if (overline || underline || strikeOut) {
                        QColor currentColor = currentSelectionState == BinaryTreeNode::Unselected
                                ? color
                                : selectedTextColor;
                        addTextDecorations(currentRect.topLeft() + QPointF(0, decorationRawFont.ascent()),
                                           decorationRawFont, currentColor, currentRect.width(),
                                           overline, strikeOut, underline);
                    }

                    if (node != 0) {
                        currentSelectionState = node->selectionState;
                        currentRect = node->boundingRect;
                    }
                } else {
                    if (currentRect.isEmpty())
                        currentRect = node->boundingRect;
                    else
                        currentRect = currentRect.united(node->boundingRect);
                }
            }
        }
    }
}


/*!
  Returns true if \a text contains any HTML tags, attributes or CSS properties which are unrelated
   to text, fonts or text layout. Otherwise the function returns false. If the return value is
  false, \a text is considered to be easily representable in the scenegraph. If it returns true,
  then the text should be prerendered into a pixmap before it's displayed on screen.
*/
bool QSGTextNode::isComplexRichText(QTextDocument *doc)
{
    if (doc == 0)
        return false;

    static QSet<QString> supportedTags;
    if (supportedTags.isEmpty()) {
        supportedTags.insert(QLatin1String("i"));
        supportedTags.insert(QLatin1String("b"));
        supportedTags.insert(QLatin1String("u"));
        supportedTags.insert(QLatin1String("div"));
        supportedTags.insert(QLatin1String("big"));
        supportedTags.insert(QLatin1String("blockquote"));
        supportedTags.insert(QLatin1String("body"));
        supportedTags.insert(QLatin1String("br"));
        supportedTags.insert(QLatin1String("center"));
        supportedTags.insert(QLatin1String("cite"));
        supportedTags.insert(QLatin1String("code"));
        supportedTags.insert(QLatin1String("tt"));
        supportedTags.insert(QLatin1String("dd"));
        supportedTags.insert(QLatin1String("dfn"));
        supportedTags.insert(QLatin1String("em"));
        supportedTags.insert(QLatin1String("font"));
        supportedTags.insert(QLatin1String("h1"));
        supportedTags.insert(QLatin1String("h2"));
        supportedTags.insert(QLatin1String("h3"));
        supportedTags.insert(QLatin1String("h4"));
        supportedTags.insert(QLatin1String("h5"));
        supportedTags.insert(QLatin1String("h6"));
        supportedTags.insert(QLatin1String("head"));
        supportedTags.insert(QLatin1String("html"));
        supportedTags.insert(QLatin1String("meta"));
        supportedTags.insert(QLatin1String("nobr"));
        supportedTags.insert(QLatin1String("p"));
        supportedTags.insert(QLatin1String("pre"));
        supportedTags.insert(QLatin1String("qt"));
        supportedTags.insert(QLatin1String("s"));
        supportedTags.insert(QLatin1String("samp"));
        supportedTags.insert(QLatin1String("small"));
        supportedTags.insert(QLatin1String("span"));
        supportedTags.insert(QLatin1String("strong"));
        supportedTags.insert(QLatin1String("sub"));
        supportedTags.insert(QLatin1String("sup"));
        supportedTags.insert(QLatin1String("title"));
        supportedTags.insert(QLatin1String("var"));
        supportedTags.insert(QLatin1String("style"));
    }

    static QSet<QCss::Property> supportedCssProperties;
    if (supportedCssProperties.isEmpty()) {
        supportedCssProperties.insert(QCss::Color);
        supportedCssProperties.insert(QCss::Float);
        supportedCssProperties.insert(QCss::Font);
        supportedCssProperties.insert(QCss::FontFamily);
        supportedCssProperties.insert(QCss::FontSize);
        supportedCssProperties.insert(QCss::FontStyle);
        supportedCssProperties.insert(QCss::FontWeight);
        supportedCssProperties.insert(QCss::Margin);
        supportedCssProperties.insert(QCss::MarginBottom);
        supportedCssProperties.insert(QCss::MarginLeft);
        supportedCssProperties.insert(QCss::MarginRight);
        supportedCssProperties.insert(QCss::MarginTop);
        supportedCssProperties.insert(QCss::TextDecoration);
        supportedCssProperties.insert(QCss::TextIndent);
        supportedCssProperties.insert(QCss::TextUnderlineStyle);
        supportedCssProperties.insert(QCss::VerticalAlignment);
        supportedCssProperties.insert(QCss::Whitespace);
        supportedCssProperties.insert(QCss::Padding);
        supportedCssProperties.insert(QCss::PaddingLeft);
        supportedCssProperties.insert(QCss::PaddingRight);
        supportedCssProperties.insert(QCss::PaddingTop);
        supportedCssProperties.insert(QCss::PaddingBottom);
        supportedCssProperties.insert(QCss::PageBreakBefore);
        supportedCssProperties.insert(QCss::PageBreakAfter);
        supportedCssProperties.insert(QCss::Width);
        supportedCssProperties.insert(QCss::Height);
        supportedCssProperties.insert(QCss::MinimumWidth);
        supportedCssProperties.insert(QCss::MinimumHeight);
        supportedCssProperties.insert(QCss::MaximumWidth);
        supportedCssProperties.insert(QCss::MaximumHeight);
        supportedCssProperties.insert(QCss::Left);
        supportedCssProperties.insert(QCss::Right);
        supportedCssProperties.insert(QCss::Top);
        supportedCssProperties.insert(QCss::Bottom);
        supportedCssProperties.insert(QCss::Position);
        supportedCssProperties.insert(QCss::TextAlignment);
        supportedCssProperties.insert(QCss::FontVariant);
    }

    QXmlStreamReader reader(doc->toHtml("utf-8"));
    while (!reader.atEnd()) {
        reader.readNext();

        if (reader.isStartElement()) {
            if (!supportedTags.contains(reader.name().toString().toLower()))
                return true;

            QXmlStreamAttributes attributes = reader.attributes();
            if (attributes.hasAttribute(QLatin1String("bgcolor")))
                return true;
            if (attributes.hasAttribute(QLatin1String("style"))) {
                QCss::StyleSheet styleSheet;
                QCss::Parser(attributes.value(QLatin1String("style")).toString()).parse(&styleSheet);

                QVector<QCss::Declaration> decls;
                for (int i=0; i<styleSheet.pageRules.size(); ++i)
                    decls += styleSheet.pageRules.at(i).declarations;

                QVector<QCss::StyleRule> styleRules =
                        styleSheet.styleRules
                        + styleSheet.idIndex.values().toVector()
                        + styleSheet.nameIndex.values().toVector();
                for (int i=0; i<styleSheet.mediaRules.size(); ++i)
                    styleRules += styleSheet.mediaRules.at(i).styleRules;

                for (int i=0; i<styleRules.size(); ++i)
                    decls += styleRules.at(i).declarations;

                for (int i=0; i<decls.size(); ++i) {
                    if (!supportedCssProperties.contains(decls.at(i).d->propertyId))
                        return true;
                }

            }
        }
    }

    return reader.hasError();
}

void QSGTextNode::addTextBlock(const QPointF &position, QTextDocument *textDocument, const QTextBlock &block,
                               const QColor &overrideColor, QSGText::TextStyle style, const QColor &styleColor)
{
    if (!block.isValid())
        return;

    QPointF blockPosition = textDocument->documentLayout()->blockBoundingRect(block).topLeft();

    QTextBlock::iterator it = block.begin();
    while (!it.atEnd()) {
        QTextFragment fragment = it.fragment();
        if (!fragment.text().isEmpty()) {
            QTextCharFormat charFormat = fragment.charFormat();
            QColor color = overrideColor.isValid()
                    ? overrideColor
                    : charFormat.foreground().color();

            QList<QGlyphRun> glyphsList = fragment.glyphRuns();
            for (int i=0; i<glyphsList.size(); ++i) {
                QGlyphRun glyphs = glyphsList.at(i);
                QRawFont font = glyphs.rawFont();
                QSGGlyphNode *glyphNode = addGlyphs(position + blockPosition + QPointF(0, font.ascent()),
                                                    glyphs, color, style, styleColor);

                QPointF baseLine = glyphNode->baseLine();
                qreal width = glyphNode->boundingRect().width();
                addTextDecorations(baseLine, font, color, width,
                                   glyphs.overline(), glyphs.strikeOut(), glyphs.underline());
            }
        }

        ++it;
    }
}

void QSGTextNode::deleteContent()
{
    while (childCount() > 0)
        delete childAtIndex(0);
    m_cursorNode = 0;
}

#if 0
void QSGTextNode::updateNodes()
{
    return;
    deleteContent();
    if (m_text.isEmpty())
        return;

    if (m_usePixmapCache) {
        // ### gunnar: port properly
//        QPixmap pixmap = generatedPixmap();
//        if (pixmap.isNull())
//            return;

//        QSGImageNode *pixmapNode = m_context->createImageNode();
//        pixmapNode->setRect(pixmap.rect());
//        pixmapNode->setSourceRect(pixmap.rect());
//        pixmapNode->setOpacity(m_opacity);
//        pixmapNode->setClampToEdge(true);
//        pixmapNode->setLinearFiltering(m_linearFiltering);

//        appendChildNode(pixmapNode);
    } else {
        if (m_text.isEmpty())
            return;

        // Implement styling by drawing text several times at slight shifts. shiftForStyle
        // contains the sequence of shifted positions at which to draw the text. All except
        // the last will be drawn with styleColor.
        QList<QPointF> shiftForStyle;
        switch (m_textStyle) {
        case OutlineTextStyle:
            // ### Should be made faster by implementing outline material
            shiftForStyle << QPointF(-1, 0);
            shiftForStyle << QPointF(0, -1);
            shiftForStyle << QPointF(1, 0);
            shiftForStyle << QPointF(0, 1);
            break;
        case SunkenTextStyle:
            shiftForStyle << QPointF(0, -1);
            break;
        case RaisedTextStyle:
            shiftForStyle << QPointF(0, 1);
            break;
        default:
            break;
        }

        shiftForStyle << QPointF(0, 0); // Regular position
        while (!shiftForStyle.isEmpty()) {
            QPointF shift = shiftForStyle.takeFirst();

            // Use styleColor for all but last shift
            if (m_richText) {
                QColor overrideColor = shiftForStyle.isEmpty() ? QColor() : m_styleColor;

                QTextFrame *textFrame = m_textDocument->rootFrame();
                QPointF p = m_textDocument->documentLayout()->frameBoundingRect(textFrame).topLeft();

                QTextFrame::iterator it = textFrame->begin();
                while (!it.atEnd()) {
                    addTextBlock(shift + p, it.currentBlock(), overrideColor);
                    ++it;
                }
            } else {
                addTextLayout(shift, m_textLayout, shiftForStyle.isEmpty()
                                                   ? m_color
                                                   : m_styleColor);
            }
        }
    }
}
#endif

QT_END_NAMESPACE