Fixed drawing of justified text in the Qt port.
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2007 15:28:39 +0000 (15:28 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2007 15:28:39 +0000 (15:28 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@20860 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/qt/FontQt.cpp

index 1004cb58969c332a770aefbe08709dfbc7ad303e..5a86117cab980ace65e05caf3e2b7aebe4368e13 100644 (file)
@@ -1,3 +1,12 @@
+2007-04-12  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Zack.
+
+        Fixed drawing of justified text in the Qt port.
+
+        * platform/qt/FontQt.cpp:
+        (Font::drawGlyphs):
+
 2007-04-11  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Maciej.
index 637d24b3540365886fa978f2fdcce5078f14e486..cf5baa58db7c3a76ac561a56fcc2b1bb66e350fa 100644 (file)
@@ -52,12 +52,29 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext, const FontData* font, co
     p.setPen(QColor(color));
     p.setFont(font->platformData().font());
 
-    // TODO: rework this to make justified text work.  Qt doesn't provide a good
-    // API to solve this problem yet.
-    const QChar* buffer = reinterpret_cast<const QChar*>(glyphBuffer.glyphs(from));
-    QString str = QString::fromRawData(buffer, numGlyphs);
+    const GlyphBufferGlyph *glyphs = glyphBuffer.glyphs(from);
+    const GlyphBufferAdvance *advances = glyphBuffer.advances(from);
 
-    p.drawText(point, str);
+    int spanStart = 0;
+    qreal x = point.x();
+    qreal y = point.y();
+    qreal width = 0;
+    int i = 0;
+    for (; i < numGlyphs; ++i) {
+        if (advances[i].width() == font->widthForGlyph(glyphs[i])
+            && advances[i].height() == 0) {
+            width += advances[i].width();
+            continue;
+        }
+        QString string = QString::fromRawData(reinterpret_cast<const QChar *>(glyphs + spanStart), i - spanStart);
+        p.drawText(QPointF(x, y), string);
+        x += width;
+        width = advances[i].width();
+        spanStart = i;
+    }
+
+    if (i - spanStart > 0)
+        p.drawText(QPointF(x, y), QString::fromRawData(reinterpret_cast<const QChar *>(glyphs + spanStart), i - spanStart));
 }
 
 void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const TextStyle&, const FloatPoint& point, int from, int to) const