diff options
Diffstat (limited to 'WebCore/platform/graphics/qt/FontQt.cpp')
-rw-r--r-- | WebCore/platform/graphics/qt/FontQt.cpp | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/WebCore/platform/graphics/qt/FontQt.cpp b/WebCore/platform/graphics/qt/FontQt.cpp index deeea99..9ed5915 100644 --- a/WebCore/platform/graphics/qt/FontQt.cpp +++ b/WebCore/platform/graphics/qt/FontQt.cpp @@ -1,6 +1,7 @@ /* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) Copyright (C) 2008 Holger Hans Peter Freyther + Copyright (C) 2009 Dirk Schulze <krit@webkit.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -24,11 +25,18 @@ #include "FontFallbackList.h" #include "FontSelector.h" +#include "Gradient.h" #include "GraphicsContext.h" -#include <QTextLayout> -#include <QPainter> -#include <QFontMetrics> +#include "Pattern.h" +#include "TransformationMatrix.h" + +#include <QBrush> #include <QFontInfo> +#include <QFontMetrics> +#include <QPainter> +#include <QPainterPath> +#include <QPen> +#include <QTextLayout> #include <qalgorithms.h> #include <qdebug.h> @@ -37,20 +45,27 @@ #if QT_VERSION >= 0x040400 namespace WebCore { -static QString qstring(const TextRun& run) +static const QString qstring(const TextRun& run) +{ + //We don't detach + return QString::fromRawData((const QChar *)run.characters(), run.length()); +} + +static const QString fixSpacing(const QString &string) { - QString string((QChar *)run.characters(), run.length()); - QChar *uc = string.data(); + //Only detach if we're actually changing something + QString possiblyDetached = string; for (int i = 0; i < string.length(); ++i) { - if (Font::treatAsSpace(uc[i].unicode())) - uc[i] = 0x20; - else if (Font::treatAsZeroWidthSpace(uc[i].unicode())) - uc[i] = 0x200c; + const QChar c = string.at(i); + if (c.unicode() != 0x20 && Font::treatAsSpace(c.unicode())) { + possiblyDetached[i] = 0x20; //detach + } else if (c.unicode() != 0x200c && Font::treatAsZeroWidthSpace(c.unicode())) { + possiblyDetached[i] = 0x200c; //detach + } } - return string; + return possiblyDetached; } - static QTextLine setupLayout(QTextLayout* layout, const TextRun& style) { int flags = style.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight; @@ -72,10 +87,32 @@ void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const Float to = run.length(); QPainter *p = ctx->platformContext(); - Color color = ctx->fillColor(); - p->setPen(QColor(color)); - QString string = qstring(run); + if (ctx->textDrawingMode() & cTextFill) { + if (ctx->fillGradient()) { + QBrush brush(*ctx->fillGradient()->platformGradient()); + brush.setTransform(ctx->fillGradient()->gradientSpaceTransform()); + p->setPen(QPen(brush, 0)); + } else if (ctx->fillPattern()) { + TransformationMatrix affine; + p->setPen(QPen(QBrush(ctx->fillPattern()->createPlatformPattern(affine)), 0)); + } else + p->setPen(QColor(ctx->fillColor())); + } + + if (ctx->textDrawingMode() & cTextStroke) { + if (ctx->strokeGradient()) { + QBrush brush(*ctx->strokeGradient()->platformGradient()); + brush.setTransform(ctx->strokeGradient()->gradientSpaceTransform()); + p->setPen(QPen(brush, ctx->strokeThickness())); + } else if (ctx->strokePattern()) { + TransformationMatrix affine; + p->setPen(QPen(QBrush(ctx->strokePattern()->createPlatformPattern(affine)), ctx->strokeThickness())); + } else + p->setPen(QPen(QColor(ctx->strokeColor()), ctx->strokeThickness())); + } + + const QString string = fixSpacing(qstring(run)); // text shadow IntSize shadowSize; @@ -137,14 +174,20 @@ void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const Float p->drawText(pt, string, flags, run.padding()); p->restore(); } - p->drawText(pt, string, flags, run.padding()); + if (ctx->textDrawingMode() & cTextStroke) { + QPainterPath path; + path.addText(pt, font(), string); + p->strokePath(path, p->pen()); + } + if (ctx->textDrawingMode() & cTextFill) + p->drawText(pt, string, flags, run.padding()); } float Font::floatWidthForComplexText(const TextRun& run) const { if (!run.length()) return 0; - QString string = qstring(run); + const QString string = fixSpacing(qstring(run)); QTextLayout layout(string, font()); QTextLine line = setupLayout(&layout, run); int w = int(line.naturalTextWidth()); @@ -157,7 +200,7 @@ float Font::floatWidthForComplexText(const TextRun& run) const int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const { - QString string = qstring(run); + const QString string = fixSpacing(qstring(run)); QTextLayout layout(string, font()); QTextLine line = setupLayout(&layout, run); return line.xToCursor(position); @@ -165,7 +208,7 @@ int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const { - QString string = qstring(run); + const QString string = fixSpacing(qstring(run)); QTextLayout layout(string, font()); QTextLine line = setupLayout(&layout, run); |