summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/qt/FontQt.cpp
diff options
context:
space:
mode:
authorShimeng (Simon) Wang <swang@google.com>2010-12-07 17:22:45 -0800
committerShimeng (Simon) Wang <swang@google.com>2010-12-22 14:15:40 -0800
commit4576aa36e9a9671459299c7963ac95aa94beaea9 (patch)
tree3863574e050f168c0126ecb47c83319fab0972d8 /WebCore/platform/graphics/qt/FontQt.cpp
parent55323ac613cc31553107b68603cb627264d22bb0 (diff)
downloadexternal_webkit-4576aa36e9a9671459299c7963ac95aa94beaea9.zip
external_webkit-4576aa36e9a9671459299c7963ac95aa94beaea9.tar.gz
external_webkit-4576aa36e9a9671459299c7963ac95aa94beaea9.tar.bz2
Merge WebKit at r73109: Initial merge by git.
Change-Id: I61f1a66d9642e3d8405d3ac6ccab2a53421c75d8
Diffstat (limited to 'WebCore/platform/graphics/qt/FontQt.cpp')
-rw-r--r--WebCore/platform/graphics/qt/FontQt.cpp78
1 files changed, 54 insertions, 24 deletions
diff --git a/WebCore/platform/graphics/qt/FontQt.cpp b/WebCore/platform/graphics/qt/FontQt.cpp
index b049181..89dfd00 100644
--- a/WebCore/platform/graphics/qt/FontQt.cpp
+++ b/WebCore/platform/graphics/qt/FontQt.cpp
@@ -182,32 +182,62 @@ static void drawTextCommon(GraphicsContext* ctx, const TextRun& run, const Float
if (!isComplexText && !(ctx->textDrawingMode() & cTextStroke))
flags |= Qt::TextBypassShaping;
#endif
- if (ctx->contextShadow()->m_type != ContextShadow::NoShadow) {
- ContextShadow* ctxShadow = ctx->contextShadow();
- if (ctxShadow->m_type != ContextShadow::BlurShadow) {
- p->save();
- p->setPen(ctxShadow->m_color);
- p->translate(ctxShadow->offset());
- p->drawText(pt, string, flags, run.padding());
- p->restore();
- } else {
- QFontMetrics fm(font);
- QRectF boundingRect(point.x(), point.y() - fm.ascent(), fm.width(string), fm.height());
- QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
- if (shadowPainter) {
- // Since it will be blurred anyway, we don't care about render hints.
- shadowPainter->setFont(p->font());
- shadowPainter->setPen(ctxShadow->m_color);
- shadowPainter->drawText(pt, string, flags, run.padding());
- ctxShadow->endShadowLayer(p);
+
+ QPainterPath textStrokePath;
+ if (ctx->textDrawingMode() & cTextStroke)
+ textStrokePath.addText(pt, font, string);
+
+ ContextShadow* ctxShadow = ctx->contextShadow();
+ if (ctxShadow->m_type != ContextShadow::NoShadow) {
+ if (ctx->textDrawingMode() & cTextFill) {
+ if (ctxShadow->m_type != ContextShadow::BlurShadow) {
+ p->save();
+ p->setPen(ctxShadow->m_color);
+ p->translate(ctxShadow->offset());
+ p->drawText(pt, string, flags, run.padding());
+ p->restore();
+ } else {
+ QFontMetrics fm(font);
+#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
+ QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string, -1, flags), fm.height());
+#else
+ QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string), fm.height());
+#endif
+ QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
+ if (shadowPainter) {
+ // Since it will be blurred anyway, we don't care about render hints.
+ shadowPainter->setFont(p->font());
+ shadowPainter->setPen(ctxShadow->m_color);
+ shadowPainter->drawText(pt, string, flags, run.padding());
+ ctxShadow->endShadowLayer(p);
+ }
+ }
+ } else if (ctx->textDrawingMode() & cTextStroke) {
+ if (ctxShadow->m_type != ContextShadow::BlurShadow) {
+ p->translate(ctxShadow->offset());
+ p->strokePath(textStrokePath, QPen(ctxShadow->m_color));
+ p->translate(-ctxShadow->offset());
+ } else {
+ QFontMetrics fm(font);
+#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
+ QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string, -1, flags), fm.height());
+#else
+ QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string), fm.height());
+#endif
+ QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
+ if (shadowPainter) {
+ // Since it will be blurred anyway, we don't care about render hints.
+ shadowPainter->setFont(p->font());
+ shadowPainter->strokePath(textStrokePath, QPen(ctxShadow->m_color));
+ ctxShadow->endShadowLayer(p);
+ }
}
}
}
- if (ctx->textDrawingMode() & cTextStroke) {
- QPainterPath path;
- path.addText(pt, font, string);
- p->strokePath(path, textStrokePen);
- }
+
+ if (ctx->textDrawingMode() & cTextStroke)
+ p->strokePath(textStrokePath, textStrokePen);
+
if (ctx->textDrawingMode() & cTextFill) {
QPen previousPen = p->pen();
p->setPen(textFillPen);
@@ -314,7 +344,7 @@ FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint&
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
String sanitized = Font::normalizeSpaces(String(run.characters(), run.length()));
QString wholeText = fromRawDataWithoutRef(sanitized);
- QString selectedText = fromRawDataWithoutRef(sanitized, from, to - from);
+ QString selectedText = fromRawDataWithoutRef(sanitized, from, qMin(to - from, wholeText.length() - from));
int startX = QFontMetrics(font()).width(wholeText, from, Qt::TextBypassShaping);
int width = QFontMetrics(font()).width(selectedText, -1, Qt::TextBypassShaping);