~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/platform/graphics/qt/FontQt.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3
3
    Copyright (C) 2008 Holger Hans Peter Freyther
 
4
    Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4
5
 
5
6
    This library is free software; you can redistribute it and/or
6
7
    modify it under the terms of the GNU Library General Public
24
25
#include "FontFallbackList.h"
25
26
#include "FontSelector.h"
26
27
 
 
28
#include "Gradient.h"
27
29
#include "GraphicsContext.h"
 
30
#include "Pattern.h"
 
31
#include "TransformationMatrix.h"
 
32
 
 
33
#include <QBrush>
 
34
#include <QFontInfo>
 
35
#include <QFontMetrics>
 
36
#include <QPainter>
 
37
#include <QPainterPath>
 
38
#include <QPen>
28
39
#include <QTextLayout>
29
 
#include <QPainter>
30
 
#include <QFontMetrics>
31
 
#include <QFontInfo>
32
40
#include <qalgorithms.h>
33
41
#include <qdebug.h>
34
42
 
39
47
 
40
48
static const QString qstring(const TextRun& run)
41
49
{
42
 
    //We don't detach
43
 
    return QString::fromRawData((const QChar *)run.characters(), run.length());
 
50
    // We don't detach
 
51
    return QString::fromRawData(reinterpret_cast<const QChar*>(run.characters()), run.length());
44
52
}
45
53
 
46
54
static const QString fixSpacing(const QString &string)
49
57
    QString possiblyDetached = string;
50
58
    for (int i = 0; i < string.length(); ++i) {
51
59
        const QChar c = string.at(i);
52
 
        if (c.unicode() != 0x20 && Font::treatAsSpace(c.unicode())) {
53
 
            possiblyDetached[i] = 0x20; //detach
54
 
        } else if (c.unicode() != 0x200c && Font::treatAsZeroWidthSpace(c.unicode())) {
55
 
            possiblyDetached[i] = 0x200c; //detach
56
 
        }
 
60
        if (c.unicode() != 0x20 && Font::treatAsSpace(c.unicode()))
 
61
            possiblyDetached[i] = 0x20; // detach
 
62
        else if (c.unicode() != 0x200c && Font::treatAsZeroWidthSpace(c.unicode()))
 
63
            possiblyDetached[i] = 0x200c; // detach
57
64
    }
58
65
    return possiblyDetached;
59
66
}
79
86
        to = run.length();
80
87
 
81
88
    QPainter *p = ctx->platformContext();
82
 
    Color color = ctx->fillColor();
83
 
    p->setPen(QColor(color));
 
89
 
 
90
    if (ctx->textDrawingMode() & cTextFill) {
 
91
        if (ctx->fillGradient()) {
 
92
            QBrush brush(*ctx->fillGradient()->platformGradient());
 
93
            brush.setTransform(ctx->fillGradient()->gradientSpaceTransform());
 
94
            p->setPen(QPen(brush, 0));
 
95
        } else if (ctx->fillPattern()) {
 
96
            TransformationMatrix affine;
 
97
            p->setPen(QPen(QBrush(ctx->fillPattern()->createPlatformPattern(affine)), 0));
 
98
        } else
 
99
            p->setPen(QColor(ctx->fillColor()));
 
100
    }
 
101
 
 
102
    if (ctx->textDrawingMode() & cTextStroke) {
 
103
        if (ctx->strokeGradient()) {
 
104
            QBrush brush(*ctx->strokeGradient()->platformGradient());
 
105
            brush.setTransform(ctx->strokeGradient()->gradientSpaceTransform());
 
106
            p->setPen(QPen(brush, ctx->strokeThickness()));
 
107
        } else if (ctx->strokePattern()) {
 
108
            TransformationMatrix affine;
 
109
            p->setPen(QPen(QBrush(ctx->strokePattern()->createPlatformPattern(affine)), ctx->strokeThickness()));
 
110
        } else
 
111
            p->setPen(QPen(QColor(ctx->strokeColor()), ctx->strokeThickness()));
 
112
    }
84
113
 
85
114
    const QString string = fixSpacing(qstring(run));
86
115
 
144
173
        p->drawText(pt, string, flags, run.padding());
145
174
        p->restore();
146
175
    }
147
 
    p->drawText(pt, string, flags, run.padding());
 
176
    if (ctx->textDrawingMode() & cTextStroke) {
 
177
        QPainterPath path;
 
178
        path.addText(pt, font(), string);
 
179
        p->strokePath(path, p->pen());
 
180
    }
 
181
    if (ctx->textDrawingMode() & cTextFill)
 
182
        p->drawText(pt, string, flags, run.padding());
148
183
}
149
184
 
150
 
float Font::floatWidthForComplexText(const TextRun& run) const
 
185
float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>*) const
151
186
{
152
187
    if (!run.length())
153
188
        return 0;
162
197
    return w + run.padding();
163
198
}
164
199
 
165
 
int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const
 
200
int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool) const
166
201
{
167
202
    const QString string = fixSpacing(qstring(run));
168
203
    QTextLayout layout(string, font());
186
221
 
187
222
QFont Font::font() const
188
223
{
189
 
    return primaryFont()->getQtFont();
 
224
    QFont f = primaryFont()->getQtFont();
 
225
    f.setLetterSpacing(QFont::AbsoluteSpacing, m_letterSpacing);
 
226
    f.setWordSpacing(m_wordSpacing);
 
227
    return f;
190
228
}
191
229
 
192
230
}