From 7fb31670f080c224249279c35240a8eb95f8d877 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Date: Tue, 20 Jul 2010 14:26:06 +0200
Subject: Add QTextFragment::glyphs() accessor

Add a function to retrieve fonts, glyph indexes and positions needed to
visualize the text in a QTextFragment to allow converting the text of
a QTextDocument to QGlyphs objects.

Reviewed-by: Simon Hausmann
---
 src/gui/text/qtextlayout.cpp | 15 ++++++++++++---
 src/gui/text/qtextlayout.h   |  3 ++-
 src/gui/text/qtextobject.cpp | 29 +++++++++++++++++++++++++++++
 src/gui/text/qtextobject.h   |  3 +++
 4 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index aff88f6..531e46b 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1134,7 +1134,7 @@ QList<QGlyphs> QTextLayout::glyphs() const
 {
     QList<QGlyphs> glyphs;
     for (int i=0; i<d->lines.size(); ++i)
-        glyphs += QTextLine(i, d).glyphs();
+        glyphs += QTextLine(i, d).glyphs(-1, -1);
 
     return glyphs;
 }
@@ -2198,13 +2198,16 @@ namespace {
 /*!
     \internal
 
-    Returns the glyph indexes and positions for all glyphs in this QTextLine.
+    Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in
+    QScriptItems that overlap with the range defined by \a from and \a length. 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
 
     \sa QTextLayout::glyphs()
 */
-QList<QGlyphs> QTextLine::glyphs() const
+QList<QGlyphs> QTextLine::glyphs(int from, int length) const
 {
     const QScriptLine &line = eng->lines[i];
 
@@ -2217,7 +2220,13 @@ QList<QGlyphs> QTextLine::glyphs() const
     qreal y = line.y.toReal() + line.base().toReal();
     while (!iterator.atEnd()) {
         QScriptItem &si = iterator.next();
+        if (si.analysis.flags >= QScriptAnalysis::TabOrObject)
+            continue;
+
         QPointF pos(iterator.x.toReal(), y);
+        if (from >= 0 && length >= 0 &&
+            (from >= si.position + eng->length(&si) || from + length <= si.position))
+            continue;
 
         QFont font = eng->font(si);
 
diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h
index f6aaf22..32d6d0e 100644
--- a/src/gui/text/qtextlayout.h
+++ b/src/gui/text/qtextlayout.h
@@ -239,9 +239,10 @@ public:
 private:
     QTextLine(int line, QTextEngine *e) : i(line), eng(e) {}
     void layout_helper(int numGlyphs);
-    QList<QGlyphs> glyphs() const;
+    QList<QGlyphs> glyphs(int from, int length) const;
 
     friend class QTextLayout;
+    friend class QTextFragment;
     int i;
     QTextEngine *eng;
 };
diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp
index 5fb3384..e366f77 100644
--- a/src/gui/text/qtextobject.cpp
+++ b/src/gui/text/qtextobject.cpp
@@ -1650,6 +1650,35 @@ QTextBlock::iterator &QTextBlock::iterator::operator--()
     than the \a other text fragment; otherwise returns false.
 */
 
+/*!
+    Returns the glyphs of this text fragment. The positions of the glyphs are
+    relative to the position of the QTextBlock's layout.
+
+    \sa QGlyphs, QTextBlock::layout(), QTextLayout::position(), QPainter::drawGlyphs()
+*/
+QList<QGlyphs> QTextFragment::glyphs() const
+{
+    if (!p || !n)
+        return QList<QGlyphs>();
+
+    int pos = position();
+    int len = length();
+    if (len == 0)
+        return QList<QGlyphs>();
+
+    int blockNode = p->blockMap().findNode(pos);
+
+    const QTextBlockData *blockData = p->blockMap().fragment(blockNode);
+    QTextLayout *layout = blockData->layout;
+
+    QList<QGlyphs> ret;
+    for (int i=0; i<layout->lineCount(); ++i) {
+        QTextLine textLine = layout->lineAt(i);
+        ret += textLine.glyphs(pos, len);
+    }
+
+    return ret;
+}
 
 /*!
     Returns the position of this text fragment in the document.
diff --git a/src/gui/text/qtextobject.h b/src/gui/text/qtextobject.h
index a573a26..332458d 100644
--- a/src/gui/text/qtextobject.h
+++ b/src/gui/text/qtextobject.h
@@ -44,6 +44,7 @@
 
 #include <QtCore/qobject.h>
 #include <QtGui/qtextformat.h>
+#include <QtGui/qglyphs.h>
 
 QT_BEGIN_HEADER
 
@@ -315,6 +316,8 @@ public:
     int charFormatIndex() const;
     QString text() const;
 
+    QList<QGlyphs> glyphs() const;
+
 private:
     const QTextDocumentPrivate *p;
     int n;
-- 
cgit v0.12


From 794c7c77f28bb530db017cc25a5e33e00933253b Mon Sep 17 00:00:00 2001
From: Fabien Freling <fabien.freling@nokia.com>
Date: Tue, 3 Aug 2010 13:36:22 +0200
Subject: Fix the issue of resizing a window with the raster engine on Mac OS
 X.

Reviewed-by: Richard Moe Gustavsen
---
 src/gui/kernel/qcocoaview_mac.mm | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm
index 5780ebc..3229e71 100644
--- a/src/gui/kernel/qcocoaview_mac.mm
+++ b/src/gui/kernel/qcocoaview_mac.mm
@@ -532,9 +532,23 @@ static int qCocoaViewCount = 0;
     if (!qwidget)
         return;
 
+    // We use a different graphics system.
     if (QApplicationPrivate::graphicsSystem() != 0) {
-        qwidget->update(qwidget->rect());
-        qwidgetprivate->syncBackingStore(qwidget->rect());
+
+        // Qt handles the painting occuring inside the window.
+        // Cocoa also keeps track of all widgets as NSView and therefore might
+        // ask for a repainting of a widget even if Qt is already taking care of it.
+        //
+        // The only valid reason for Cocoa to call drawRect: is for window manipulation
+        // (ie. resize, ...).
+        //
+        // Qt will then forward the update to the children.
+        if (qwidget->isWindow()) {
+            qwidget->update(qwidget->rect());
+            qwidgetprivate->syncBackingStore(qwidget->rect());
+        }
+
+        // Since we don't want to use the native engine, we must exit.
         return;
     }
 
-- 
cgit v0.12