Changeset 39207 in webkit


Ignore:
Timestamp:
Dec 11, 2008, 6:46:52 AM (16 years ago)
Author:
zecke@webkit.org
Message:

2008-12-11 Holger Freyther <zecke@selfish.org>

Reviewed by Simon Hausmann.

https://bugs.webkit.org/show_bug.cgi?id=20953

Make the Qt port follow the Win, Mac, Gtk+ port in regard to Font
handling. FontQt.cpp from now on is only implementing the complex path. Create
FontFallbackListQt.cpp and FontPlatformDataQt.cpp to work within
the framework set by the Font code.

Sharing the Font.cpp implementation allows the Qt port to support
the CSS font faces and SVG fonts.

Split out the Qt4.3 Font handling into FonQt43.cpp to allow to more
easily deprecate it.

This commit is removing a lot of #ifdefs from Font.h as the Qt Font
implementation is now in line with the rest of WebCore.

  • WebCore.pro:
  • platform/graphics/Font.h: Remove #ifdefs (WebCore::Font::letterSpacing): (WebCore::Font::setLetterSpacing): (WebCore::Font::isPlatformFont):
  • platform/graphics/FontFallbackList.h:
  • platform/graphics/SimpleFontData.cpp: (WebCore::SimpleFontData::SimpleFontData): (WebCore::SimpleFontData::platformGlyphInit): There is no GlyphCache on Qt, move the initialisation over. (WebCore::SimpleFontData::~SimpleFontData):
  • platform/graphics/SimpleFontData.h: (WebCore::SimpleFontData::getQtFont):
  • platform/graphics/qt/FontCacheQt.cpp: (WebCore::FontCache::getCachedFontPlatformData): Remove unused parameter (WebCore::FontCache::releaseFontData): Add to build
  • platform/graphics/qt/FontCustomPlatformData.cpp: (WebCore::FontCustomPlatformData::~FontCustomPlatformData): (WebCore::FontCustomPlatformData::fontPlatformData): (WebCore::createFontCustomPlatformData):
  • platform/graphics/qt/FontCustomPlatformData.h:
  • platform/graphics/qt/FontFallbackListQt.cpp: Added. (WebCore::FontFallbackList::FontFallbackList): (WebCore::FontFallbackList::invalidate): (WebCore::FontFallbackList::releaseFontData): (WebCore::FontFallbackList::determinePitch): (WebCore::FontFallbackList::fontDataAt): (WebCore::FontFallbackList::fontDataForCharacters): (WebCore::FontFallbackList::setPlatformFont):
  • platform/graphics/qt/FontPlatformData.h: (WebCore::FontPlatformData::font): (WebCore::FontPlatformData::size):
  • platform/graphics/qt/FontPlatformDataQt.cpp: Added. (WebCore::FontPlatformData::FontPlatformData):
  • platform/graphics/qt/FontQt.cpp: (WebCore::Font::drawComplexText): (WebCore::Font::floatWidthForComplexText): (WebCore::Font::offsetForPositionForComplexText): (WebCore::Font::selectionRectForComplexText): (WebCore::Font::font):
  • platform/graphics/qt/FontQt43.cpp: Added. Moved Qt4.3 code from FontQt.cpp (WebCore::Font::drawComplexText): (WebCore::Font::floatWidthForComplexText): (WebCore::Font::offsetForPositionForComplexText): (WebCore::Font::selectionRectForComplexText):
  • platform/graphics/qt/GlyphPageTreeNodeQt.cpp: (WebCore::GlyphPageTreeNode::pruneTreeCustomFontData): (WebCore::GlyphPageTreeNode::pruneTreeFontData):
  • platform/graphics/qt/SimpleFontDataQt.cpp: (WebCore::SimpleFontData::determinePitch): (WebCore::SimpleFontData::containsCharacters): (WebCore::SimpleFontData::platformInit): (WebCore::SimpleFontData::platformGlyphInit): (WebCore::SimpleFontData::platformDestroy):
  • platform/qt/RenderThemeQt.cpp: (WebCore::RenderThemeQt::adjustButtonStyle): Avoid crashes.
Location:
trunk/WebCore
Files:
2 added
13 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r39206 r39207  
     12008-12-11  Holger Freyther  <zecke@selfish.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=20953
     6
     7        Make the Qt port follow the Win, Mac, Gtk+ port in regard to Font
     8        handling. FontQt.cpp from now on is only implementing the complex path. Create
     9        FontFallbackListQt.cpp and FontPlatformDataQt.cpp to work within
     10        the framework set by the Font code.
     11
     12        Sharing the Font.cpp implementation allows the Qt port to support
     13        the CSS font faces and SVG fonts.
     14
     15        Split out the Qt4.3 Font handling into FonQt43.cpp to allow to more
     16        easily deprecate it.
     17
     18        This commit is removing a lot of #ifdefs from Font.h as the Qt Font
     19        implementation is now in line with the rest of WebCore.
     20
     21        * WebCore.pro:
     22        * platform/graphics/Font.h: Remove #ifdefs
     23        (WebCore::Font::letterSpacing):
     24        (WebCore::Font::setLetterSpacing):
     25        (WebCore::Font::isPlatformFont):
     26        * platform/graphics/FontFallbackList.h:
     27        * platform/graphics/SimpleFontData.cpp:
     28        (WebCore::SimpleFontData::SimpleFontData):
     29        (WebCore::SimpleFontData::platformGlyphInit): There is no GlyphCache
     30        on Qt, move the initialisation over.
     31        (WebCore::SimpleFontData::~SimpleFontData):
     32        * platform/graphics/SimpleFontData.h:
     33        (WebCore::SimpleFontData::getQtFont):
     34        * platform/graphics/qt/FontCacheQt.cpp:
     35        (WebCore::FontCache::getCachedFontPlatformData): Remove unused parameter
     36        (WebCore::FontCache::releaseFontData): Add to build
     37        * platform/graphics/qt/FontCustomPlatformData.cpp:
     38        (WebCore::FontCustomPlatformData::~FontCustomPlatformData):
     39        (WebCore::FontCustomPlatformData::fontPlatformData):
     40        (WebCore::createFontCustomPlatformData):
     41        * platform/graphics/qt/FontCustomPlatformData.h:
     42        * platform/graphics/qt/FontFallbackListQt.cpp: Added.
     43        (WebCore::FontFallbackList::FontFallbackList):
     44        (WebCore::FontFallbackList::invalidate):
     45        (WebCore::FontFallbackList::releaseFontData):
     46        (WebCore::FontFallbackList::determinePitch):
     47        (WebCore::FontFallbackList::fontDataAt):
     48        (WebCore::FontFallbackList::fontDataForCharacters):
     49        (WebCore::FontFallbackList::setPlatformFont):
     50        * platform/graphics/qt/FontPlatformData.h:
     51        (WebCore::FontPlatformData::font):
     52        (WebCore::FontPlatformData::size):
     53        * platform/graphics/qt/FontPlatformDataQt.cpp: Added.
     54        (WebCore::FontPlatformData::FontPlatformData):
     55        * platform/graphics/qt/FontQt.cpp:
     56        (WebCore::Font::drawComplexText):
     57        (WebCore::Font::floatWidthForComplexText):
     58        (WebCore::Font::offsetForPositionForComplexText):
     59        (WebCore::Font::selectionRectForComplexText):
     60        (WebCore::Font::font):
     61        * platform/graphics/qt/FontQt43.cpp: Added. Moved Qt4.3 code from FontQt.cpp
     62        (WebCore::Font::drawComplexText):
     63        (WebCore::Font::floatWidthForComplexText):
     64        (WebCore::Font::offsetForPositionForComplexText):
     65        (WebCore::Font::selectionRectForComplexText):
     66        * platform/graphics/qt/GlyphPageTreeNodeQt.cpp:
     67        (WebCore::GlyphPageTreeNode::pruneTreeCustomFontData):
     68        (WebCore::GlyphPageTreeNode::pruneTreeFontData):
     69        * platform/graphics/qt/SimpleFontDataQt.cpp:
     70        (WebCore::SimpleFontData::determinePitch):
     71        (WebCore::SimpleFontData::containsCharacters):
     72        (WebCore::SimpleFontData::platformInit):
     73        (WebCore::SimpleFontData::platformGlyphInit):
     74        (WebCore::SimpleFontData::platformDestroy):
     75        * platform/qt/RenderThemeQt.cpp:
     76        (WebCore::RenderThemeQt::adjustButtonStyle): Avoid crashes.
     77
    1782008-12-11  Holger Freyther  <zecke@selfish.org>
    279
  • trunk/WebCore/WebCore.pro

    r39171 r39207  
    7878!contains(DEFINES, ENABLE_WML=.): DEFINES += ENABLE_WML=0
    7979!contains(DEFINES, ENABLE_SVG=.): DEFINES += ENABLE_SVG=1
    80 #!contains(DEFINES, ENABLE_SVG_FONTS=.): DEFINES += ENABLE_SVG_FONTS=1
     80!contains(DEFINES, ENABLE_SVG_FONTS=.): DEFINES += ENABLE_SVG_FONTS=1
    8181!contains(DEFINES, ENABLE_SVG_FILTERS=.): DEFINES += ENABLE_SVG_FILTERS=1
    8282!contains(DEFINES, ENABLE_SVG_FOREIGN_OBJECT=.): DEFINES += ENABLE_SVG_FOREIGN_OBJECT=1
     
    837837    platform/graphics/FloatSize.cpp \
    838838    platform/graphics/FontData.cpp \
     839    platform/graphics/Font.cpp \
    839840    platform/graphics/GeneratedImage.cpp \
    840841    platform/graphics/Gradient.cpp \
     
    848849    platform/graphics/Pen.cpp \
    849850    platform/graphics/SegmentedFontData.cpp \
     851    platform/graphics/SimpleFontData.cpp \
    850852    platform/KURL.cpp \
    851853    platform/Length.cpp \
     
    10391041    platform/graphics/qt/AffineTransformQt.cpp \
    10401042    platform/graphics/qt/ColorQt.cpp \
     1043    platform/graphics/qt/FontQt.cpp \
     1044    platform/graphics/qt/FontQt43.cpp \
     1045    platform/graphics/qt/FontPlatformDataQt.cpp \
    10411046    platform/graphics/qt/FloatPointQt.cpp \
    10421047    platform/graphics/qt/FloatRectQt.cpp \
     
    10711076    platform/graphics/qt/FontCacheQt.cpp \
    10721077    platform/graphics/qt/FontCustomPlatformData.cpp \
    1073     platform/graphics/qt/FontQt.cpp \
     1078    platform/graphics/qt/FontFallbackListQt.cpp \
    10741079    platform/graphics/qt/GlyphPageTreeNodeQt.cpp \
    10751080    platform/graphics/qt/SimpleFontDataQt.cpp \
     
    14881493        svg/SVGGlyphElement.idl \
    14891494        svg/SVGGradientElement.idl \
     1495        svg/SVGHKernElement.idl \
    14901496        svg/SVGImageElement.idl \
    14911497        svg/SVGLength.idl \
     
    16361642        svg/SVGGlyphElement.cpp \
    16371643        svg/SVGGradientElement.cpp \
     1644        svg/SVGHKernElement.cpp \
    16381645        svg/SVGImageElement.cpp \
    16391646        svg/SVGLangSpace.cpp \
  • trunk/WebCore/platform/graphics/Font.h

    r39206 r39207  
    44 *           (C) 2000 Dirk Mueller (mueller@kde.org)
    55 * Copyright (C) 2003, 2006, 2007 Apple Computer, Inc.
     6 * Copyright (C) 2008 Holger Hans Peter Freyther
    67 *
    78 * This library is free software; you can redistribute it and/or
     
    3031
    3132#if PLATFORM(QT)
    32 #include <QtGui/qfont.h>
    33 #include <QtGui/qfontmetrics.h>
     33#include <QFont>
    3434#endif
    3535
     
    5555    Font();
    5656    Font(const FontDescription&, short letterSpacing, short wordSpacing);
    57 #if !PLATFORM(QT)
    58     Font(const FontPlatformData&, bool isPrinting); // This constructor is only used if the platform wants to start with a native font.
    59 #endif
     57    // This constructor is only used if the platform wants to start with a native font.
     58    Font(const FontPlatformData&, bool isPrinting);
    6059    ~Font();
    6160
     
    8887    short wordSpacing() const { return m_wordSpacing; }
    8988    short letterSpacing() const { return m_letterSpacing; }
    90 #if !PLATFORM(QT)
    9189    void setWordSpacing(short s) { m_wordSpacing = s; }
    9290    void setLetterSpacing(short s) { m_letterSpacing = s; }
    93 #else
    94     void setWordSpacing(short s);
    95     void setLetterSpacing(short s);
    96 #endif
    9791    bool isFixedPitch() const;
    9892    bool isPrinterFont() const { return m_fontDescription.usePrinterFont(); }
     
    106100    FontWeight weight() const { return m_fontDescription.weight(); }
    107101
    108 #if !PLATFORM(QT)
    109102    bool isPlatformFont() const { return m_isPlatformFont; }
    110 #endif
    111 
    112 #if PLATFORM(QT)
    113     inline const QFont &font() const { return m_font; }
    114     inline const QFont &scFont() const { return m_scFont; }
    115 #endif
    116103
    117104    // Metrics that we query the FontFallbackList for.
     
    126113    int tabWidth() const { return 8 * spaceWidth(); }
    127114
    128 #if !PLATFORM(QT)
    129115    const SimpleFontData* primaryFont() const {
    130116        if (!m_cachedPrimaryFont)
     
    137123    // Used for complex text, and does not utilize the glyph map cache.
    138124    const FontData* fontDataForCharacters(const UChar*, int length) const;
     125
     126#if PLATFORM(QT)
     127    QFont font() const;
    139128#endif
    140129
     
    167156
    168157public:
    169 #if PLATFORM(QT)
    170     FontSelector* fontSelector() const { return 0; }
    171 #else
    172158    // Useful for debugging the different font rendering code paths.
    173159#if USE(FONT_FAST_PATH)
     
    185171
    186172    FontSelector* fontSelector() const;
    187 #endif
    188173    static bool treatAsSpace(UChar c) { return c == ' ' || c == '\t' || c == '\n' || c == 0x00A0; }
    189174    static bool treatAsZeroWidthSpace(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == 0x200e || c == 0x200f || (c >= 0x202a && c <= 0x202e) || c == 0xFFFC; }
     
    196181private:
    197182    FontDescription m_fontDescription;
    198 #if !PLATFORM(QT)
    199183    mutable RefPtr<FontFallbackList> m_fontList;
    200184    mutable HashMap<int, GlyphPageTreeNode*> m_pages;
    201185    mutable GlyphPageTreeNode* m_pageZero;
    202186    mutable const SimpleFontData* m_cachedPrimaryFont;
    203 #endif
    204187    short m_letterSpacing;
    205188    short m_wordSpacing;
    206 #if !PLATFORM(QT)
    207189    bool m_isPlatformFont;
    208 #else
    209     QFont m_font;
    210     QFont m_scFont;
    211     int m_spaceWidth;
    212 #endif
    213190};
    214191
  • trunk/WebCore/platform/graphics/SimpleFontData.cpp

    r33056 r39207  
    5151    , m_smallCapsFontData(0)
    5252{
    53 #if ENABLE(SVG_FONTS) && !PLATFORM(QT)
     53#if ENABLE(SVG_FONTS)
    5454    if (SVGFontFaceElement* svgFontFaceElement = svgFontData ? svgFontData->svgFontFaceElement() : 0) {
    5555       m_unitsPerEm = svgFontFaceElement->unitsPerEm();
     
    7676
    7777    platformInit();
     78    platformGlyphInit();
     79}
    7880
     81#if !PLATFORM(QT)
     82void SimpleFontData::platformGlyphInit()
     83{
    7984    GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
    8085    if (!glyphPageZero) {
     
    114119    m_missingGlyphData.glyph = 0;
    115120}
     121#endif
    116122
    117123SimpleFontData::~SimpleFontData()
     
    123129    }
    124130
    125 #if ENABLE(SVG_FONTS) && !PLATFORM(QT)
     131#if ENABLE(SVG_FONTS)
    126132    if (!m_svgFontData || !m_svgFontData->svgFontFaceElement())
    127133#endif
     
    129135}
    130136
     137#if !PLATFORM(QT)
    131138float SimpleFontData::widthForGlyph(Glyph glyph) const
    132139{
     
    140147    return width;
    141148}
     149#endif
    142150
    143151const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const
  • trunk/WebCore/platform/graphics/SimpleFontData.h

    r37801 r39207  
    4040#if PLATFORM(CAIRO)
    4141#include <cairo.h>
     42#endif
     43
     44#if PLATFORM(QT)
     45#include <QFont>
    4246#endif
    4347
     
    110114#endif
    111115
     116#if PLATFORM(QT)
     117    QFont getQtFont() const { return m_font.font(); }
     118#endif
     119
    112120#if PLATFORM(WIN)
    113121    bool isSystemFont() const { return m_isSystemFont; }
     
    129137private:
    130138    void platformInit();
     139    void platformGlyphInit();
    131140    void platformDestroy();
    132141   
  • trunk/WebCore/platform/graphics/qt/FontCacheQt.cpp

    r37061 r39207  
    11/*
    22    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     3    Copyright (C) 2008 Holger Hans Peter Freyther
    34
    45    This library is free software; you can redistribute it and/or
     
    2223#include "config.h"
    2324#include "FontCache.h"
     25
    2426#include "FontDescription.h"
     27#include "FontPlatformData.h"
    2528#include "Font.h"
    2629
     
    3134}
    3235
    33 FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName)
     36FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& description, const AtomicString& family, bool checkingAlternateName)
    3437{
    35     return 0;
     38    return new FontPlatformData(description);
    3639}
    3740
     
    4649}
    4750
     51void FontCache::releaseFontData(const WebCore::SimpleFontData*)
     52{
     53}
     54
    4855void FontCache::addClient(FontSelector*)
    4956{
  • trunk/WebCore/platform/graphics/qt/FontCustomPlatformData.cpp

    r37061 r39207  
    2626#include "SharedBuffer.h"
    2727#include <QFontDatabase>
     28#include <QStringList>
    2829
    2930namespace WebCore {
     
    3132FontCustomPlatformData::~FontCustomPlatformData()
    3233{
    33     QFontDatabase::removeApplicationFont(handle);
     34    QFontDatabase::removeApplicationFont(m_handle);
    3435}
    3536
    3637FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontRenderingMode)
    3738{
    38     FontPlatformData result;
    39     result.handle = handle;
    40     return result;
     39    QFont font;
     40    font.setFamily(QFontDatabase::applicationFontFamilies(m_handle)[0]);
     41    font.setPixelSize(size);
     42    if (bold)
     43        font.setWeight(QFont::Bold);
     44    font.setItalic(italic);
     45
     46    return FontPlatformData(font, bold);
    4147}
    4248
     
    4854    if (id == -1)
    4955        return 0;
     56
     57    Q_ASSERT(QFontDatabase::applicationFontFamilies(id).size() > 0);
     58
    5059    FontCustomPlatformData *data = new FontCustomPlatformData;
    51     data->handle = id;
     60    data->m_handle = id;
    5261    return data;
    5362}
  • trunk/WebCore/platform/graphics/qt/FontCustomPlatformData.h

    r37061 r39207  
    3434    ~FontCustomPlatformData();
    3535
    36     int handle; // for use with QFontDatabase::addApplicationFont/removeApplicationFont
     36    // for use with QFontDatabase::addApplicationFont/removeApplicationFont
     37    int m_handle;
    3738
    3839    FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
  • trunk/WebCore/platform/graphics/qt/FontPlatformData.h

    r37061 r39207  
    11/*
    22    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     3    Copyright (C) 2008 Holger Hans Peter Freyther
    34
    45    This library is free software; you can redistribute it and/or
     
    2324#define FontPlatformData_h
    2425
     26#include "FontDescription.h"
     27
     28#include <QFont>
     29
    2530namespace WebCore {
    2631
     
    2833{
    2934public:
    30     // this is only used for custom loaded fonts and represents the id handle passed to
    31     // QFontDatabase::addApplicationFont/removeApplicationFont
    32     int handle;
     35#if ENABLE(SVG_FONTS)
     36    FontPlatformData(float size, bool bold, bool oblique);
     37#endif
     38    FontPlatformData();
     39    FontPlatformData(const FontDescription&, int wordSpacing = 0, int letterSpacing = 0);
     40    FontPlatformData(const QFont&, bool bold);
     41
     42    QFont font() const { return m_font; }
     43    float size() const { return m_size; }
     44
     45    float m_size;
     46    bool m_bold;
     47    bool m_oblique;
     48    QFont m_font;
    3349};
    3450
  • trunk/WebCore/platform/graphics/qt/FontQt.cpp

    r37061 r39207  
    11/*
    22    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     3    Copyright (C) 2008 Holger Hans Peter Freyther
    34
    45    This library is free software; you can redistribute it and/or
     
    2122#include "Font.h"
    2223#include "FontDescription.h"
     24#include "FontFallbackList.h"
    2325#include "FontSelector.h"
    2426
     
    3234
    3335#include <limits.h>
    34 namespace WebCore {
    3536
    3637#if QT_VERSION >= 0x040400
    37 
    38 Font::Font()
    39     : m_letterSpacing(0)
    40     , m_wordSpacing(0)
    41     , m_font()
    42     , m_scFont()
    43 {
    44     QFontMetrics metrics(m_font);
    45     m_spaceWidth = metrics.width(QLatin1Char(' '));
    46 }
    47 
    48 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing)
    49     : m_fontDescription(description)
    50     , m_letterSpacing(letterSpacing)
    51     , m_wordSpacing(wordSpacing)
    52 {
    53     const FontFamily* family = &description.family();
    54     QString familyName;
    55     while (family) {
    56         familyName += family->family();
    57         family = family->next();
    58         if (family)
    59             familyName += QLatin1Char(',');
    60     }
    61 
    62     m_font.setFamily(familyName);
    63     m_font.setPixelSize(qRound(description.computedSize()));
    64     m_font.setItalic(description.italic());
    65     // FIXME: Map all FontWeight values to QFont weights.
    66     if (description.weight() >= FontWeight600)
    67         m_font.setWeight(QFont::Bold);
    68     else
    69         m_font.setWeight(QFont::Normal);
    70 
    71     bool smallCaps = description.smallCaps();
    72     m_font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase);
    73 
    74     QFontMetrics metrics = QFontMetrics(m_font);
    75     m_spaceWidth = metrics.width(QLatin1Char(' '));
    76 
    77     if (wordSpacing)
    78         m_font.setWordSpacing(wordSpacing);
    79     if (letterSpacing)
    80         m_font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing);
    81 }
    82 
    83 void Font::setWordSpacing(short s)
    84 {
    85     m_font.setWordSpacing(s);
    86     m_wordSpacing = s;
    87 }
    88 void Font::setLetterSpacing(short s)
    89 {
    90     m_font.setLetterSpacing(QFont::AbsoluteSpacing, s);
    91     m_letterSpacing = s;
    92 }
    93 
     38namespace WebCore {
    9439
    9540static QString qstring(const TextRun& run)
     
    12267}
    12368
    124 void Font::drawText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
     69void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
    12570{
    12671    if (to < 0)
    12772        to = run.length();
     73
    12874    QPainter *p = ctx->platformContext();
    12975    Color color = ctx->fillColor();
     
    13985
    14086    if (from > 0 || to < run.length()) {
    141         QTextLayout layout(string, m_font);
     87        QTextLayout layout(string, font());
    14288        QTextLine line = setupLayout(&layout, run);
    14389        float x1 = line.cursorToX(from);
     
    14692            qSwap(x1, x2);
    14793
    148         QFontMetrics fm(m_font);
     94        QFontMetrics fm(font());
    14995        int ascent = fm.ascent();
    15096        QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
     
    180126    }
    181127
    182     p->setFont(m_font);
     128    p->setFont(font());
    183129
    184130    QPointF pt(point.x(), point.y());
     
    195141}
    196142
    197 int Font::width(const TextRun& run) const
     143float Font::floatWidthForComplexText(const TextRun& run) const
    198144{
    199145    if (!run.length())
    200146        return 0;
    201147    QString string = qstring(run);
    202     QTextLayout layout(string, m_font);
     148    QTextLayout layout(string, font());
    203149    QTextLine line = setupLayout(&layout, run);
    204150    int w = int(line.naturalTextWidth());
     
    210156}
    211157
    212 float Font::floatWidth(const TextRun& run) const
    213 {
    214     return width(run);
    215 }
    216 
    217 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const
    218 {
    219     charsConsumed = run.length();
    220     glyphName = "";
    221     return width(run);
    222 }
    223 
    224 int Font::offsetForPosition(const TextRun& run, int position, bool /*includePartialGlyphs*/) const
     158int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const
    225159{
    226160    QString string = qstring(run);
    227     QTextLayout layout(string, m_font);
     161    QTextLayout layout(string, font());
    228162    QTextLine line = setupLayout(&layout, run);
    229163    return line.xToCursor(position);
    230164}
    231165
    232 FloatRect Font::selectionRectForText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const
     166FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const
    233167{
    234168    QString string = qstring(run);
    235     QTextLayout layout(string, m_font);
     169    QTextLayout layout(string, font());
    236170    QTextLine line = setupLayout(&layout, run);
    237171
     
    244178}
    245179
    246 #else
    247 
    248 
    249 struct TextRunComponent {
    250     TextRunComponent() : font(0) {}
    251     TextRunComponent(const UChar *start, int length, bool rtl, const QFont *font, int offset, bool sc = false);
    252     TextRunComponent(int spaces, bool rtl, const QFont *font, int offset);
    253 
    254     inline bool isSpace() const { return spaces != 0; }
    255 
    256     QString string;
    257     const QFont *font;
    258     int width;
    259     int offset;
    260     int spaces;
    261 };
    262 
    263 TextRunComponent::TextRunComponent(const UChar *start, int length, bool rtl, const QFont *f, int o, bool sc)
    264     : string(reinterpret_cast<const QChar*>(start), length)
    265     , font(f)
    266     , offset(o)
    267     , spaces(0)
     180QFont Font::font() const
    268181{
    269     if (sc)
    270         string = string.toUpper();
    271     string.prepend(rtl ? QChar(0x202e) : QChar(0x202d));
    272     width = QFontMetrics(*font).width(string);
    273 }
    274 
    275 TextRunComponent::TextRunComponent(int s, bool rtl, const QFont *f, int o)
    276     : string(s, QLatin1Char(' '))
    277     , font(f)
    278     , offset(o)
    279     , spaces(s)
    280 {
    281     string.prepend(rtl ? QChar(0x202e) : QChar(0x202d));
    282     width = spaces * QFontMetrics(*font).width(QLatin1Char(' '));
    283 }
    284 
    285 
    286 Font::Font()
    287     : m_letterSpacing(0)
    288     , m_wordSpacing(0)
    289     , m_font()
    290     , m_scFont()
    291 {
    292     QFontMetrics metrics(m_font);
    293     m_spaceWidth = metrics.width(QLatin1Char(' '));
    294     qreal pointsize = m_font.pointSizeF();
    295     if (pointsize > 0)
    296         m_scFont.setPointSizeF(pointsize*0.7);
    297     else
    298         m_scFont.setPixelSize(qRound(m_font.pixelSize()*.7));
    299 }
    300 
    301 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing)
    302     : m_fontDescription(description)
    303     , m_letterSpacing(letterSpacing)
    304     , m_wordSpacing(wordSpacing)
    305 {
    306     const FontFamily* family = &description.family();
    307     QString familyName;
    308     while (family) {
    309         familyName += family->family();
    310         family = family->next();
    311         if (family)
    312             familyName += QLatin1Char(',');
    313     }
    314 
    315     m_font.setFamily(familyName);
    316     m_font.setPixelSize(qRound(description.computedSize()));
    317     m_font.setItalic(description.italic());
    318     // FIXME: Map all FontWeight values to QFont weights.
    319     if (description.weight() >= FontWeight600)
    320         m_font.setWeight(QFont::Bold);
    321     else
    322         m_font.setWeight(QFont::Normal);
    323 
    324     QFontMetrics metrics = QFontMetrics(m_font);
    325     m_spaceWidth = metrics.width(QLatin1Char(' '));
    326     m_scFont = m_font;
    327     m_scFont.setPixelSize(qRound(description.computedSize()*.7));
    328 }
    329 
    330 void Font::setWordSpacing(short s)
    331 {
    332     m_wordSpacing = s;
    333 }
    334 void Font::setLetterSpacing(short s)
    335 {
    336     m_letterSpacing = s;
    337 }
    338 
    339 static int generateComponents(Vector<TextRunComponent, 1024>* components, const Font &font, const TextRun &run)
    340 {
    341 //     qDebug() << "generateComponents" << QString((const QChar *)run.characters(), run.length());
    342     int letterSpacing = font.letterSpacing();
    343     int wordSpacing = font.wordSpacing();
    344     bool smallCaps = font.fontDescription().smallCaps();
    345     int padding = run.padding();
    346     int numSpaces = 0;
    347     if (padding) {
    348         for (int i = 0; i < run.length(); i++)
    349             if (Font::treatAsSpace(run[i]))
    350                 ++numSpaces;
    351     }
    352 
    353     int offset = 0;
    354     const QFont *f = &font.font();
    355     if (letterSpacing || smallCaps) {
    356         // need to draw every letter on it's own
    357         int start = 0;
    358         if (Font::treatAsSpace(run[0])) {
    359             int add = 0;
    360             if (numSpaces) {
    361                 add = padding/numSpaces;
    362                 padding -= add;
    363                 --numSpaces;
    364             }
    365             components->append(TextRunComponent(1, run.rtl(), &font.font(), offset));
    366             offset += add + letterSpacing + components->last().width;
    367             start = 1;
    368 //         qDebug() << "space at 0" << offset;
    369         } else if (smallCaps) {
    370             f = (QChar::category(run[0]) == QChar::Letter_Lowercase ? &font.scFont() : &font.font());
    371         }
    372         for (int i = 1; i < run.length(); ++i) {
    373             uint ch = run[i];
    374             if (QChar(ch).isHighSurrogate() && QChar(run[i-1]).isLowSurrogate())
    375                 ch = QChar::surrogateToUcs4(ch, run[i-1]);
    376             if (QChar(ch).isLowSurrogate() || QChar::category(ch) == QChar::Mark_NonSpacing)
    377                 continue;
    378             if (Font::treatAsSpace(run[i])) {
    379                 int add = 0;
    380 //                 qDebug() << "    treatAsSpace:" << i << start;
    381                 if (i - start > 0) {
    382                     components->append(TextRunComponent(run.characters() + start, i - start,
    383                                                         run.rtl(),
    384                                                         f, offset, f == &font.scFont()));
    385                     offset += components->last().width + letterSpacing;
    386 //                     qDebug() << "   appending(1) " << components->last().string << components->last().width;
    387                 }
    388                 if (numSpaces) {
    389                     add = padding/numSpaces;
    390                     padding -= add;
    391                     --numSpaces;
    392                 }
    393                 components->append(TextRunComponent(1, run.rtl(), &font.font(), offset));
    394                 offset += wordSpacing + add + components->last().width + letterSpacing;
    395                 start = i + 1;
    396                 continue;
    397             } else if (!letterSpacing) {
    398 //                 qDebug() << i << char(run[i]) << (QChar::category(ch) == QChar::Letter_Lowercase) <<
    399 //                     QFontInfo(*f).pointSizeF();
    400                 if (QChar::category(ch) == QChar::Letter_Lowercase) {
    401                     if (f == &font.scFont())
    402                         continue;
    403                 } else {
    404                     if (f == &font.font())
    405                         continue;
    406                 }
    407             }
    408             if (i - start > 0) {
    409                 components->append(TextRunComponent(run.characters() + start, i - start,
    410                                                     run.rtl(),
    411                                                     f, offset, f == &font.scFont()));
    412                 offset += components->last().width + letterSpacing;
    413 //                 qDebug() << "   appending(2) " << components->last().string << components->last().width;
    414             }
    415             if (smallCaps)
    416                 f = (QChar::category(ch) == QChar::Letter_Lowercase ? &font.scFont() : &font.font());
    417             start = i;
    418         }
    419         if (run.length() - start > 0) {
    420             components->append(TextRunComponent(run.characters() + start, run.length() - start,
    421                                                 run.rtl(),
    422                                                 f, offset, f == &font.scFont()));
    423             offset += components->last().width;
    424 //             qDebug() << "   appending(3) " << components->last().string << components->last().width;
    425         }
    426         offset += letterSpacing;
    427     } else {
    428         int start = 0;
    429         for (int i = 0; i < run.length(); ++i) {
    430             if (Font::treatAsSpace(run[i])) {
    431                 if (i - start > 0) {
    432                     components->append(TextRunComponent(run.characters() + start, i - start,
    433                                                         run.rtl(),
    434                                                         f, offset));
    435                     offset += components->last().width;
    436                 }
    437                 int add = 0;
    438                 if (numSpaces) {
    439                     add = padding/numSpaces;
    440                     padding -= add;
    441                     --numSpaces;
    442                 }
    443                 components->append(TextRunComponent(1, run.rtl(), &font.font(), offset));
    444                 offset += add + components->last().width;
    445                 if (i)
    446                     offset += wordSpacing;
    447                 start = i + 1;
    448             }
    449         }
    450         if (run.length() - start > 0) {
    451             components->append(TextRunComponent(run.characters() + start, run.length() - start,
    452                                                 run.rtl(),
    453                                                 f, offset));
    454             offset += components->last().width;
    455         }
    456     }
    457     return offset;
    458 }
    459 
    460 void Font::drawText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
    461 {
    462     if (to < 0)
    463         to = run.length();
    464     QPainter *p = ctx->platformContext();
    465     Color color = ctx->fillColor();
    466     p->setPen(QColor(color));
    467 
    468     Vector<TextRunComponent, 1024> components;
    469     int w = generateComponents(&components, *this, run);
    470 
    471     if (from > 0 || to < run.length()) {
    472         FloatRect clip = selectionRectForText(run,
    473                                               IntPoint(qRound(point.x()), qRound(point.y())),
    474                                               QFontMetrics(m_font).height(), from, to);
    475         QRectF rect(clip.x(), clip.y() - ascent(), clip.width(), clip.height());
    476         p->save();
    477         p->setClipRect(rect.toRect());
    478     }
    479 
    480     if (run.rtl()) {
    481         for (int i = 0; i < components.size(); ++i) {
    482             if (!components.at(i).isSpace()) {
    483                 p->setFont(*components.at(i).font);
    484                 QPointF pt(point.x() + w - components.at(i).offset - components.at(i).width, point.y());
    485                 p->drawText(pt, components.at(i).string);
    486             }
    487         }
    488     } else {
    489         for (int i = 0; i < components.size(); ++i) {
    490             if (!components.at(i).isSpace()) {
    491                 p->setFont(*components.at(i).font);
    492                 QPointF pt(point.x() + components.at(i).offset, point.y());
    493                 p->drawText(pt, components.at(i).string);
    494             }
    495         }
    496     }
    497     if (from > 0 || to < run.length())
    498         p->restore();
    499 }
    500 
    501 int Font::width(const TextRun& run) const
    502 {
    503     Vector<TextRunComponent, 1024> components;
    504     int w = generateComponents(&components, *this, run);
    505 
    506 //     qDebug() << "     width=" << w;
    507     return w;
    508 }
    509 
    510 float Font::floatWidth(const TextRun& run) const
    511 {
    512     return width(run);
    513 }
    514 
    515 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const
    516 {
    517     charsConsumed = run.length();
    518     glyphName = "";
    519     return width(run);
    520 }
    521 
    522 int Font::offsetForPosition(const TextRun& run, int position, bool includePartialGlyphs) const
    523 {
    524     Vector<TextRunComponent, 1024> components;
    525     int w = generateComponents(&components, *this, run);
    526 
    527     int offset = 0;
    528     if (run.rtl()) {
    529         for (int i = 0; i < components.size(); ++i) {
    530             int xe = w - components.at(i).offset;
    531             int xs = xe - components.at(i).width;
    532             if (position >= xs) {
    533                 QTextLayout layout(components.at(i).string, *components.at(i).font);
    534                 layout.beginLayout();
    535                 QTextLine l = layout.createLine();
    536                 if (!l.isValid())
    537                     return offset;
    538 
    539                 l.setLineWidth(INT_MAX/256);
    540                 layout.endLayout();
    541 
    542                 if (position - xs >= l.width())
    543                     return offset;
    544                 int cursor = l.xToCursor(position - xs);
    545                 if (cursor > 1)
    546                     --cursor;
    547                 return offset + cursor;
    548             } else {
    549                 offset += components.at(i).string.length() - 1;
    550             }
    551         }
    552     } else {
    553         for (int i = 0; i < components.size(); ++i) {
    554             int xs = components.at(i).offset;
    555             int xe = xs + components.at(i).width;
    556             if (position <= xe) {
    557                 QTextLayout layout(components.at(i).string, *components.at(i).font);
    558                 layout.beginLayout();
    559                 QTextLine l = layout.createLine();
    560                 if (!l.isValid())
    561                     return offset;
    562 
    563                 l.setLineWidth(INT_MAX/256);
    564                 layout.endLayout();
    565 
    566                 if (position - xs >= l.width())
    567                     return offset + components.at(i).string.length() - 1;
    568                 int cursor = l.xToCursor(position - xs);
    569                 if (cursor > 1)
    570                     --cursor;
    571                 return offset + cursor;
    572             } else {
    573                 offset += components.at(i).string.length() - 1;
    574             }
    575         }
    576     }
    577     return run.length();
    578 }
    579 
    580 static float cursorToX(const Vector<TextRunComponent, 1024>& components, int width, bool rtl, int cursor)
    581 {
    582     int start = 0;
    583     for (int i = 0; i < components.size(); ++i) {
    584         if (start + components.at(i).string.length() - 1 < cursor) {
    585             start += components.at(i).string.length() - 1;
    586             continue;
    587         }
    588         int xs = components.at(i).offset;
    589         if (rtl)
    590             xs = width - xs - components.at(i).width;
    591         QTextLayout layout(components.at(i).string, *components.at(i).font);
    592         layout.beginLayout();
    593         QTextLine l = layout.createLine();
    594         if (!l.isValid())
    595             return 0;
    596 
    597         l.setLineWidth(INT_MAX/256);
    598         layout.endLayout();
    599 
    600         return xs + l.cursorToX(cursor - start + 1);
    601     }
    602     return width;
    603 }
    604 
    605 FloatRect Font::selectionRectForText(const TextRun& run, const IntPoint& pt,
    606                                      int h, int from, int to) const
    607 {
    608     Vector<TextRunComponent, 1024> components;
    609     int w = generateComponents(&components, *this, run);
    610 
    611     if (from == 0 && to == run.length())
    612         return FloatRect(pt.x(), pt.y(), w, h);
    613 
    614     float x1 = cursorToX(components, w, run.rtl(), from);
    615     float x2 = cursorToX(components, w, run.rtl(), to);
    616     if (x2 < x1)
    617         qSwap(x1, x2);
    618 
    619     return FloatRect(pt.x() + x1, pt.y(), x2 - x1, h);
    620 }
    621 #endif
    622 
    623 
    624 Font::~Font()
    625 {
    626 }
    627 
    628 Font::Font(const Font& other)
    629     : m_fontDescription(other.m_fontDescription)
    630     , m_letterSpacing(other.m_letterSpacing)
    631     , m_wordSpacing(other.m_wordSpacing)
    632     , m_font(other.m_font)
    633     , m_scFont(other.m_scFont)
    634     , m_spaceWidth(other.m_spaceWidth)
    635 {
    636 }
    637 
    638 Font& Font::operator=(const Font& other)
    639 {
    640     m_fontDescription = other.m_fontDescription;
    641     m_letterSpacing = other.m_letterSpacing;
    642     m_wordSpacing = other.m_wordSpacing;
    643     m_font = other.m_font;
    644     m_scFont = other.m_scFont;
    645     m_spaceWidth = other.m_spaceWidth;
    646     return *this;
    647 }
    648 
    649 bool Font::operator==(const Font& other) const
    650 {
    651     return m_fontDescription == other.m_fontDescription
    652         && m_letterSpacing == other.m_letterSpacing
    653         && m_wordSpacing == other.m_wordSpacing
    654         && m_font == other.m_font
    655         && m_scFont == other.m_scFont
    656         && m_spaceWidth == other.m_spaceWidth;
    657 }
    658 
    659 void Font::update(PassRefPtr<FontSelector>) const
    660 {
    661     // don't think we need this
    662 }
    663 
    664 
    665 bool Font::isFixedPitch() const
    666 {
    667     return QFontInfo(m_font).fixedPitch();
    668 }
    669 
    670 // Metrics that we query the FontFallbackList for.
    671 int Font::ascent() const
    672 {
    673     return QFontMetrics(m_font).ascent();
    674 }
    675 
    676 int Font::descent() const
    677 {
    678     return QFontMetrics(m_font).descent();
    679 }
    680 
    681 int Font::lineSpacing() const
    682 {
    683     return QFontMetrics(m_font).lineSpacing();
    684 }
    685 
    686 int Font::lineGap() const
    687 {
    688     return QFontMetrics(m_font).leading();
    689 }
    690 
    691 float Font::xHeight() const
    692 {
    693     return QFontMetrics(m_font).xHeight();
    694 }
    695 
    696 unsigned Font::unitsPerEm() const
    697 {
    698     return 1; // FIXME!
    699 }
    700 
    701 int Font::spaceWidth() const
    702 {
    703     return m_spaceWidth;
     182    return primaryFont()->getQtFont();
    704183}
    705184
    706185}
     186
     187#endif
     188
  • trunk/WebCore/platform/graphics/qt/FontQt43.cpp

    r39205 r39207  
    11/*
    22    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     3    Copyright (C) 2008 Holger Hans Peter Freyther
    34
    45    This library is free software; you can redistribute it and/or
     
    2122#include "Font.h"
    2223#include "FontDescription.h"
     24#include "FontFallbackList.h"
    2325#include "FontSelector.h"
    2426
     
    3234
    3335#include <limits.h>
     36
     37#if QT_VERSION < 0x040400
     38
    3439namespace WebCore {
    35 
    36 #if QT_VERSION >= 0x040400
    37 
    38 Font::Font()
    39     : m_letterSpacing(0)
    40     , m_wordSpacing(0)
    41     , m_font()
    42     , m_scFont()
    43 {
    44     QFontMetrics metrics(m_font);
    45     m_spaceWidth = metrics.width(QLatin1Char(' '));
    46 }
    47 
    48 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing)
    49     : m_fontDescription(description)
    50     , m_letterSpacing(letterSpacing)
    51     , m_wordSpacing(wordSpacing)
    52 {
    53     const FontFamily* family = &description.family();
    54     QString familyName;
    55     while (family) {
    56         familyName += family->family();
    57         family = family->next();
    58         if (family)
    59             familyName += QLatin1Char(',');
    60     }
    61 
    62     m_font.setFamily(familyName);
    63     m_font.setPixelSize(qRound(description.computedSize()));
    64     m_font.setItalic(description.italic());
    65     // FIXME: Map all FontWeight values to QFont weights.
    66     if (description.weight() >= FontWeight600)
    67         m_font.setWeight(QFont::Bold);
    68     else
    69         m_font.setWeight(QFont::Normal);
    70 
    71     bool smallCaps = description.smallCaps();
    72     m_font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase);
    73 
    74     QFontMetrics metrics = QFontMetrics(m_font);
    75     m_spaceWidth = metrics.width(QLatin1Char(' '));
    76 
    77     if (wordSpacing)
    78         m_font.setWordSpacing(wordSpacing);
    79     if (letterSpacing)
    80         m_font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing);
    81 }
    82 
    83 void Font::setWordSpacing(short s)
    84 {
    85     m_font.setWordSpacing(s);
    86     m_wordSpacing = s;
    87 }
    88 void Font::setLetterSpacing(short s)
    89 {
    90     m_font.setLetterSpacing(QFont::AbsoluteSpacing, s);
    91     m_letterSpacing = s;
    92 }
    93 
    94 
    95 static QString qstring(const TextRun& run)
    96 {
    97     QString string((QChar *)run.characters(), run.length());
    98     QChar *uc = string.data();
    99     for (int i = 0; i < string.length(); ++i) {
    100         if (Font::treatAsSpace(uc[i].unicode()))
    101             uc[i] = 0x20;
    102         else if (Font::treatAsZeroWidthSpace(uc[i].unicode()))
    103             uc[i] = 0x200c;
    104     }
    105     return string;
    106 }
    107 
    108 
    109 static QTextLine setupLayout(QTextLayout* layout, const TextRun& style)
    110 {
    111     int flags = style.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
    112     if (style.padding())
    113         flags |= Qt::TextJustificationForced;
    114     layout->setFlags(flags);
    115     layout->beginLayout();
    116     QTextLine line = layout->createLine();
    117     line.setLineWidth(INT_MAX/256);
    118     if (style.padding())
    119         line.setLineWidth(line.naturalTextWidth() + style.padding());
    120     layout->endLayout();
    121     return line;
    122 }
    123 
    124 void Font::drawText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
    125 {
    126     if (to < 0)
    127         to = run.length();
    128     QPainter *p = ctx->platformContext();
    129     Color color = ctx->fillColor();
    130     p->setPen(QColor(color));
    131 
    132     QString string = qstring(run);
    133 
    134     // text shadow
    135     IntSize shadowSize;
    136     int shadowBlur;
    137     Color shadowColor;
    138     bool hasShadow = ctx->textDrawingMode() == cTextFill && ctx->getShadow(shadowSize, shadowBlur, shadowColor);
    139 
    140     if (from > 0 || to < run.length()) {
    141         QTextLayout layout(string, m_font);
    142         QTextLine line = setupLayout(&layout, run);
    143         float x1 = line.cursorToX(from);
    144         float x2 = line.cursorToX(to);
    145         if (x2 < x1)
    146             qSwap(x1, x2);
    147 
    148         QFontMetrics fm(m_font);
    149         int ascent = fm.ascent();
    150         QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
    151 
    152         if (hasShadow) {
    153             // TODO: when blur support is added, the clip will need to account
    154             // for the blur radius
    155             qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
    156             if (shadowSize.width() > 0)
    157                 dx2 = shadowSize.width();
    158             else
    159                 dx1 = -shadowSize.width();
    160             if (shadowSize.height() > 0)
    161                 dy2 = shadowSize.height();
    162             else
    163                 dy1 = -shadowSize.height();
    164             // expand the clip rect to include the text shadow as well
    165             clip.adjust(dx1, dx2, dy1, dy2);
    166         }
    167         p->save();
    168         p->setClipRect(clip.toRect());
    169         QPointF pt(point.x(), point.y() - ascent);
    170         if (hasShadow) {
    171             p->save();
    172             p->setPen(QColor(shadowColor));
    173             p->translate(shadowSize.width(), shadowSize.height());
    174             line.draw(p, pt);
    175             p->restore();
    176         }
    177         line.draw(p, pt);
    178         p->restore();
    179         return;
    180     }
    181 
    182     p->setFont(m_font);
    183 
    184     QPointF pt(point.x(), point.y());
    185     int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
    186     if (hasShadow) {
    187         // TODO: text shadow blur support
    188         p->save();
    189         p->setPen(QColor(shadowColor));
    190         p->translate(shadowSize.width(), shadowSize.height());
    191         p->drawText(pt, string, flags, run.padding());
    192         p->restore();
    193     }
    194     p->drawText(pt, string, flags, run.padding());
    195 }
    196 
    197 int Font::width(const TextRun& run) const
    198 {
    199     if (!run.length())
    200         return 0;
    201     QString string = qstring(run);
    202     QTextLayout layout(string, m_font);
    203     QTextLine line = setupLayout(&layout, run);
    204     int w = int(line.naturalTextWidth());
    205     // WebKit expects us to ignore word spacing on the first character (as opposed to what Qt does)
    206     if (treatAsSpace(run[0]))
    207         w -= m_wordSpacing;
    208 
    209     return w + run.padding();
    210 }
    211 
    212 float Font::floatWidth(const TextRun& run) const
    213 {
    214     return width(run);
    215 }
    216 
    217 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const
    218 {
    219     charsConsumed = run.length();
    220     glyphName = "";
    221     return width(run);
    222 }
    223 
    224 int Font::offsetForPosition(const TextRun& run, int position, bool /*includePartialGlyphs*/) const
    225 {
    226     QString string = qstring(run);
    227     QTextLayout layout(string, m_font);
    228     QTextLine line = setupLayout(&layout, run);
    229     return line.xToCursor(position);
    230 }
    231 
    232 FloatRect Font::selectionRectForText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const
    233 {
    234     QString string = qstring(run);
    235     QTextLayout layout(string, m_font);
    236     QTextLine line = setupLayout(&layout, run);
    237 
    238     float x1 = line.cursorToX(from);
    239     float x2 = line.cursorToX(to);
    240     if (x2 < x1)
    241         qSwap(x1, x2);
    242 
    243     return FloatRect(pt.x() + x1, pt.y(), x2 - x1, h);
    244 }
    245 
    246 #else
    247 
    24840
    24941struct TextRunComponent {
     
    28375}
    28476
    285 
    286 Font::Font()
    287     : m_letterSpacing(0)
    288     , m_wordSpacing(0)
    289     , m_font()
    290     , m_scFont()
    291 {
    292     QFontMetrics metrics(m_font);
    293     m_spaceWidth = metrics.width(QLatin1Char(' '));
    294     qreal pointsize = m_font.pointSizeF();
    295     if (pointsize > 0)
    296         m_scFont.setPointSizeF(pointsize*0.7);
    297     else
    298         m_scFont.setPixelSize(qRound(m_font.pixelSize()*.7));
    299 }
    300 
    301 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing)
    302     : m_fontDescription(description)
    303     , m_letterSpacing(letterSpacing)
    304     , m_wordSpacing(wordSpacing)
    305 {
    306     const FontFamily* family = &description.family();
    307     QString familyName;
    308     while (family) {
    309         familyName += family->family();
    310         family = family->next();
    311         if (family)
    312             familyName += QLatin1Char(',');
    313     }
    314 
    315     m_font.setFamily(familyName);
    316     m_font.setPixelSize(qRound(description.computedSize()));
    317     m_font.setItalic(description.italic());
    318     // FIXME: Map all FontWeight values to QFont weights.
    319     if (description.weight() >= FontWeight600)
    320         m_font.setWeight(QFont::Bold);
    321     else
    322         m_font.setWeight(QFont::Normal);
    323 
    324     QFontMetrics metrics = QFontMetrics(m_font);
    325     m_spaceWidth = metrics.width(QLatin1Char(' '));
    326     m_scFont = m_font;
    327     m_scFont.setPixelSize(qRound(description.computedSize()*.7));
    328 }
    329 
    330 void Font::setWordSpacing(short s)
    331 {
    332     m_wordSpacing = s;
    333 }
    334 void Font::setLetterSpacing(short s)
    335 {
    336     m_letterSpacing = s;
    337 }
    33877
    33978static int generateComponents(Vector<TextRunComponent, 1024>* components, const Font &font, const TextRun &run)
     
    458197}
    459198
    460 void Font::drawText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
     199void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
    461200{
    462201    if (to < 0)
    463202        to = run.length();
     203
    464204    QPainter *p = ctx->platformContext();
    465205    Color color = ctx->fillColor();
     
    470210
    471211    if (from > 0 || to < run.length()) {
    472         FloatRect clip = selectionRectForText(run,
     212        FloatRect clip = selectionRectForComplexText(run,
    473213                                              IntPoint(qRound(point.x()), qRound(point.y())),
    474                                               QFontMetrics(m_font).height(), from, to);
     214                                              QFontMetrics(font()).height(), from, to);
    475215        QRectF rect(clip.x(), clip.y() - ascent(), clip.width(), clip.height());
    476216        p->save();
     
    499239}
    500240
    501 int Font::width(const TextRun& run) const
     241float Font::floatWidthForComplexText(const TextRun& run) const
    502242{
    503243    Vector<TextRunComponent, 1024> components;
    504244    int w = generateComponents(&components, *this, run);
    505245
    506 //     qDebug() << "     width=" << w;
    507246    return w;
    508247}
    509248
    510 float Font::floatWidth(const TextRun& run) const
    511 {
    512     return width(run);
    513 }
    514 
    515 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const
    516 {
    517     charsConsumed = run.length();
    518     glyphName = "";
    519     return width(run);
    520 }
    521 
    522 int Font::offsetForPosition(const TextRun& run, int position, bool includePartialGlyphs) const
     249int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const
    523250{
    524251    Vector<TextRunComponent, 1024> components;
     
    603330}
    604331
    605 FloatRect Font::selectionRectForText(const TextRun& run, const IntPoint& pt,
     332FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& pt,
    606333                                     int h, int from, int to) const
    607334{
     
    619346    return FloatRect(pt.x() + x1, pt.y(), x2 - x1, h);
    620347}
     348
     349int Font::lineGap() const
     350{
     351    return QFontMetrics(m_font).leading();
     352}
     353
     354}
     355
    621356#endif
    622 
    623 
    624 Font::~Font()
    625 {
    626 }
    627 
    628 Font::Font(const Font& other)
    629     : m_fontDescription(other.m_fontDescription)
    630     , m_letterSpacing(other.m_letterSpacing)
    631     , m_wordSpacing(other.m_wordSpacing)
    632     , m_font(other.m_font)
    633     , m_scFont(other.m_scFont)
    634     , m_spaceWidth(other.m_spaceWidth)
    635 {
    636 }
    637 
    638 Font& Font::operator=(const Font& other)
    639 {
    640     m_fontDescription = other.m_fontDescription;
    641     m_letterSpacing = other.m_letterSpacing;
    642     m_wordSpacing = other.m_wordSpacing;
    643     m_font = other.m_font;
    644     m_scFont = other.m_scFont;
    645     m_spaceWidth = other.m_spaceWidth;
    646     return *this;
    647 }
    648 
    649 bool Font::operator==(const Font& other) const
    650 {
    651     return m_fontDescription == other.m_fontDescription
    652         && m_letterSpacing == other.m_letterSpacing
    653         && m_wordSpacing == other.m_wordSpacing
    654         && m_font == other.m_font
    655         && m_scFont == other.m_scFont
    656         && m_spaceWidth == other.m_spaceWidth;
    657 }
    658 
    659 void Font::update(PassRefPtr<FontSelector>) const
    660 {
    661     // don't think we need this
    662 }
    663 
    664 
    665 bool Font::isFixedPitch() const
    666 {
    667     return QFontInfo(m_font).fixedPitch();
    668 }
    669 
    670 // Metrics that we query the FontFallbackList for.
    671 int Font::ascent() const
    672 {
    673     return QFontMetrics(m_font).ascent();
    674 }
    675 
    676 int Font::descent() const
    677 {
    678     return QFontMetrics(m_font).descent();
    679 }
    680 
    681 int Font::lineSpacing() const
    682 {
    683     return QFontMetrics(m_font).lineSpacing();
    684 }
    685 
    686 int Font::lineGap() const
    687 {
    688     return QFontMetrics(m_font).leading();
    689 }
    690 
    691 float Font::xHeight() const
    692 {
    693     return QFontMetrics(m_font).xHeight();
    694 }
    695 
    696 unsigned Font::unitsPerEm() const
    697 {
    698     return 1; // FIXME!
    699 }
    700 
    701 int Font::spaceWidth() const
    702 {
    703     return m_spaceWidth;
    704 }
    705 
    706 }
  • trunk/WebCore/platform/graphics/qt/GlyphPageTreeNodeQt.cpp

    r37061 r39207  
    11/*
    22    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     3    Copyright (C) 2008 Holger Hans Peter Freyther
    34
    45    This library is free software; you can redistribute it and/or
     
    2526namespace WebCore {
    2627
    27 void GlyphPageTreeNode::pruneTreeCustomFontData(const FontData* fontData)
     28void GlyphPageTreeNode::pruneTreeCustomFontData(const FontData*)
     29{
     30}
     31
     32void GlyphPageTreeNode::pruneTreeFontData(const WebCore::SimpleFontData*)
    2833{
    2934}
  • trunk/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp

    r37061 r39207  
    11/*
    22    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     3    Copyright (C) 2008 Holger Hans Peter Freyther
    34
    45    This library is free software; you can redistribute it and/or
     
    2021    pages from the web. It has a memory cache for these objects.
    2122*/
     23
    2224#include "config.h"
    2325#include "SimpleFontData.h"
    2426
    25 #include "SVGFontData.h"
     27#include <QFontMetrics>
    2628
    2729namespace WebCore {
    2830
    29 SimpleFontData::SimpleFontData(const FontPlatformData& font, bool customFont, bool loading, SVGFontData*)
    30     : m_font(font)
    31     , m_isCustomFont(customFont)
    32     , m_isLoading(loading)
     31void SimpleFontData::determinePitch()
    3332{
     33    m_treatAsFixedPitch = m_font.font().fixedPitch();
    3434}
    3535
    36 SimpleFontData::~SimpleFontData()
    37 {
    38 }
    39 
    40 bool SimpleFontData::containsCharacters(const UChar* characters, int length) const
     36bool SimpleFontData::containsCharacters(unsigned short const*, int) const
    4137{
    4238    return true;
    4339}
    4440
    45 const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const
     41void SimpleFontData::platformInit()
    4642{
    47     return this;
     43    QFontMetrics fm(m_font.font());
     44
     45    m_ascent = fm.ascent();
     46    m_descent = fm.descent();
     47    m_lineSpacing = fm.lineSpacing();
     48    m_xHeight = fm.xHeight();
     49    m_spaceWidth = fm.width(' ');
     50    m_lineGap = fm.leading();
    4851}
    4952
    50 bool SimpleFontData::isSegmented() const
     53void SimpleFontData::platformGlyphInit()
    5154{
    52     return false;
     55    m_spaceGlyph = 0;
     56    m_adjustedSpaceWidth = m_spaceWidth;
     57    determinePitch();
     58    m_missingGlyphData.fontData = this;
     59    m_missingGlyphData.glyph = 0;
     60}
     61
     62void SimpleFontData::platformDestroy()
     63{
    5364}
    5465
  • trunk/WebCore/platform/qt/RenderThemeQt.cpp

    r39200 r39207  
    77 *               2006 Dirk Mueller <mueller@kde.org>
    88 *               2006 Nikolas Zimmermann <zimmermann@kde.org>
     9 * Copyright (C) 2008 Holger Hans Peter Freyther
    910 *
    1011 * All rights reserved.
     
    4647
    4748#include "Color.h"
     49#include "CSSStyleSelector.h"
    4850#include "CSSStyleSheet.h"
     51#include "FontSelector.h"
    4952#include "Document.h"
    5053#include "Page.h"
     
    399402    fontDescription.setFamily(fontFamily);
    400403    style->setFontDescription(fontDescription);
     404    style->font().update(selector->fontSelector());
    401405    style->setLineHeight(RenderStyle::initialLineHeight());
    402406
Note: See TracChangeset for help on using the changeset viewer.