Changeset 113968 in webkit


Ignore:
Timestamp:
Apr 12, 2012 6:28:22 AM (12 years ago)
Author:
pierre.rossi@gmail.com
Message:

[Qt] Use QRawFont when building with Qt 5
https://bugs.webkit.org/show_bug.cgi?id=78001

Source/WebCore:

Up until now, fonts in the Qt port have been handled via
the QFont API. QRawFont offers a lower-level API enabling
us to be more in line with what other WebKit ports do.
This patch proceeds to switching over to QRawFont, and
effectively use an earlier change by Andreas Kling
that remained guarded up until now.

Reviewed by Simon Hausmann.

No new tests since this is refactoring of existing
functionality.

  • Target.pri:
  • platform/graphics/Font.cpp:

(WebCore::Font::drawText):

  • platform/graphics/Font.h:

(Font):
(WebCore):
(WebCore::Font::syntheticFont): Added.

  • platform/graphics/SimpleFontData.h:

(SimpleFontData):
(WebCore::SimpleFontData::getQtRawFont):
(WebCore):

  • platform/graphics/qt/FontCacheQt.cpp:

(WebCore::rawFontForCharacters):
(WebCore):
(WebCore::FontCache::getFontDataForCharacters):
(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/qt/FontCustomPlatformData.h:

(FontCustomPlatformData):

  • platform/graphics/qt/FontCustomPlatformDataQt.cpp:

(WebCore::FontCustomPlatformData::~FontCustomPlatformData):
(WebCore::FontCustomPlatformData::fontPlatformData):
(WebCore::createFontCustomPlatformData):

  • platform/graphics/qt/FontPlatformData.h:

(WebCore::FontPlatformDataPrivate::FontPlatformDataPrivate):
(FontPlatformDataPrivate):
(FontPlatformData):

  • platform/graphics/qt/FontPlatformDataQt.cpp:

(WebCore::FontPlatformData::FontPlatformData):
(WebCore):
(WebCore::FontPlatformData::operator==):

  • platform/graphics/qt/FontQt.cpp:

(WebCore::fillPenForContext):
(WebCore::pathForGlyphs):
(WebCore::drawQtGlyphRun):
(WebCore::Font::drawComplexText):
(WebCore::Font::floatWidthForComplexText):
(WebCore::Font::offsetForPositionForComplexText):
(WebCore::Font::selectionRectForComplexText):
(WebCore::Font::initFormatForTextLayout):
(WebCore):
(WebCore::Font::drawGlyphs):
(WebCore::Font::syntheticFont):
(WebCore::Font::rawFont):

  • platform/graphics/qt/FontQt4.cpp: Copied from Source/WebCore/platform/graphics/qt/FontQt.cpp.

(WebCore):
(WebCore::fromRawDataWithoutRef):
(WebCore::setupLayout):
(WebCore::fillPenForContext):
(WebCore::strokePenForContext):
(WebCore::drawTextCommon):
(WebCore::Font::drawComplexText):
(WebCore::Font::floatWidthForComplexText):
(WebCore::Font::offsetForPositionForComplexText):
(WebCore::Font::selectionRectForComplexText):
(WebCore::Font::canReturnFallbackFontsForComplexText):
(WebCore::Font::drawEmphasisMarksForComplexText):
(WebCore::Font::drawSimpleText):
(WebCore::Font::offsetForPositionForSimpleText):
(WebCore::Font::floatWidthForSimpleText):
(WebCore::Font::selectionRectForSimpleText):
(WebCore::Font::canExpandAroundIdeographsInComplexText):
(WebCore::Font::primaryFontHasGlyphForCharacter):
(WebCore::Font::emphasisMarkAscent):
(WebCore::Font::emphasisMarkDescent):
(WebCore::Font::emphasisMarkHeight):
(WebCore::Font::drawEmphasisMarksForSimpleText):
(WebCore::Font::font):

  • platform/graphics/qt/SimpleFontDataQt.cpp:

(WebCore::SimpleFontData::platformInit):

  • platform/qt/RenderThemeQt.cpp:

(WebCore::RenderThemeQt::fileListNameForWidth):

  • platform/qt/RenderThemeQtMobile.cpp:

(WebCore::RenderThemeQtMobile::computeSizeBasedOnStyle):

Source/WebKit/qt:

Since QFont is not used internally, we now need
to query for a QFont that should be a good
enough match.

Reviewed by Simon Hausmann.

  • Api/qwebpage.cpp:

(QWebPage::inputMethodQuery):

  • WebCoreSupport/PopupMenuQt.cpp:

(WebCore::PopupMenuQt::show):

  • WebCoreSupport/RenderThemeQStyle.cpp:

(WebCore::RenderThemeQStyle::computeSizeBasedOnStyle):

Tools:

Flip the QRawFont switch for Qt 5.

Reviewed by Simon Hausmann.

  • qmake/mkspecs/features/features.prf:
Location:
trunk
Files:
20 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r113967 r113968  
     12012-03-05  Pierre Rossi  <pierre.rossi@gmail.com>
     2
     3        [Qt] Use QRawFont when building with Qt 5
     4        https://bugs.webkit.org/show_bug.cgi?id=78001
     5
     6        Up until now, fonts in the Qt port have been handled via
     7        the QFont API. QRawFont offers a lower-level API enabling
     8        us to be more in line with what other WebKit ports do.
     9        This patch proceeds to switching over to QRawFont, and
     10        effectively use an earlier change by Andreas Kling
     11        that remained guarded up until now.
     12
     13        Reviewed by Simon Hausmann.
     14
     15        No new tests since this is refactoring of existing
     16        functionality.
     17
     18        * Target.pri:
     19        * platform/graphics/Font.cpp:
     20        (WebCore::Font::drawText):
     21        * platform/graphics/Font.h:
     22        (Font):
     23        (WebCore):
     24        (WebCore::Font::syntheticFont): Added.
     25        * platform/graphics/SimpleFontData.h:
     26        (SimpleFontData):
     27        (WebCore::SimpleFontData::getQtRawFont):
     28        (WebCore):
     29        * platform/graphics/qt/FontCacheQt.cpp:
     30        (WebCore::rawFontForCharacters):
     31        (WebCore):
     32        (WebCore::FontCache::getFontDataForCharacters):
     33        (WebCore::FontCache::createFontPlatformData):
     34        * platform/graphics/qt/FontCustomPlatformData.h:
     35        (FontCustomPlatformData):
     36        * platform/graphics/qt/FontCustomPlatformDataQt.cpp:
     37        (WebCore::FontCustomPlatformData::~FontCustomPlatformData):
     38        (WebCore::FontCustomPlatformData::fontPlatformData):
     39        (WebCore::createFontCustomPlatformData):
     40        * platform/graphics/qt/FontPlatformData.h:
     41        (WebCore::FontPlatformDataPrivate::FontPlatformDataPrivate):
     42        (FontPlatformDataPrivate):
     43        (FontPlatformData):
     44        * platform/graphics/qt/FontPlatformDataQt.cpp:
     45        (WebCore::FontPlatformData::FontPlatformData):
     46        (WebCore):
     47        (WebCore::FontPlatformData::operator==):
     48        * platform/graphics/qt/FontQt.cpp:
     49        (WebCore::fillPenForContext):
     50        (WebCore::pathForGlyphs):
     51        (WebCore::drawQtGlyphRun):
     52        (WebCore::Font::drawComplexText):
     53        (WebCore::Font::floatWidthForComplexText):
     54        (WebCore::Font::offsetForPositionForComplexText):
     55        (WebCore::Font::selectionRectForComplexText):
     56        (WebCore::Font::initFormatForTextLayout):
     57        (WebCore):
     58        (WebCore::Font::drawGlyphs):
     59        (WebCore::Font::syntheticFont):
     60        (WebCore::Font::rawFont):
     61        * platform/graphics/qt/FontQt4.cpp: Copied from Source/WebCore/platform/graphics/qt/FontQt.cpp.
     62        (WebCore):
     63        (WebCore::fromRawDataWithoutRef):
     64        (WebCore::setupLayout):
     65        (WebCore::fillPenForContext):
     66        (WebCore::strokePenForContext):
     67        (WebCore::drawTextCommon):
     68        (WebCore::Font::drawComplexText):
     69        (WebCore::Font::floatWidthForComplexText):
     70        (WebCore::Font::offsetForPositionForComplexText):
     71        (WebCore::Font::selectionRectForComplexText):
     72        (WebCore::Font::canReturnFallbackFontsForComplexText):
     73        (WebCore::Font::drawEmphasisMarksForComplexText):
     74        (WebCore::Font::drawSimpleText):
     75        (WebCore::Font::offsetForPositionForSimpleText):
     76        (WebCore::Font::floatWidthForSimpleText):
     77        (WebCore::Font::selectionRectForSimpleText):
     78        (WebCore::Font::canExpandAroundIdeographsInComplexText):
     79        (WebCore::Font::primaryFontHasGlyphForCharacter):
     80        (WebCore::Font::emphasisMarkAscent):
     81        (WebCore::Font::emphasisMarkDescent):
     82        (WebCore::Font::emphasisMarkHeight):
     83        (WebCore::Font::drawEmphasisMarksForSimpleText):
     84        (WebCore::Font::font):
     85        * platform/graphics/qt/SimpleFontDataQt.cpp:
     86        (WebCore::SimpleFontData::platformInit):
     87        * platform/qt/RenderThemeQt.cpp:
     88        (WebCore::RenderThemeQt::fileListNameForWidth):
     89        * platform/qt/RenderThemeQtMobile.cpp:
     90        (WebCore::RenderThemeQtMobile::computeSizeBasedOnStyle):
     91
    1922012-04-12  JungJik Lee  <jungjik.lee@samsung.com>
    293
  • trunk/Source/WebCore/Target.pri

    r113848 r113968  
    28272827    platform/graphics/qt/TransformationMatrixQt.cpp \
    28282828    platform/graphics/qt/ColorQt.cpp \
    2829     platform/graphics/qt/FontQt.cpp \
    28302829    platform/graphics/qt/FontPlatformDataQt.cpp \
    28312830    platform/graphics/qt/FloatPointQt.cpp \
     
    33913390}
    33923391
    3393 # QRawFont feature added in Qt 4.8.0
     3392# QRawFont transition handling.
    33943393#
    3395 # If available, this is used to implement the fast path for text rendering
    3396 # and measurement in WebCore. Because the feature is still undergoing
    3397 # development, it is disabled in builds.
    3398 #
    3399 # exists($$[QT_INSTALL_HEADERS]/QtGui/QRawFont): HAVE_QRAWFONT=1
    3400 
    3401 !isEmpty(HAVE_QRAWFONT) {
    3402     DEFINES += HAVE_QRAWFONT=1
    3403 
     3394# Even though QRawFont was already available in Qt 4.8, it had
     3395# limitations that made switching fully to it impossible.
     3396# We preserve the old code path when building with Qt 4.
     3397
     3398contains(DEFINES, HAVE_QRAWFONT=1) {
    34043399    SOURCES += \
     3400        platform/graphics/qt/FontQt.cpp \
    34053401        platform/graphics/FontFastPath.cpp \
    34063402        platform/graphics/GlyphPageTreeNode.cpp \
     
    34113407        platform/graphics/WidthIterator.h \
    34123408        platform/graphics/SurrogatePairAwareTextIterator.h
     3409} else {
     3410    SOURCES += \
     3411        platform/graphics/qt/FontQt4.cpp
    34133412}
     3413
    34143414
    34153415contains(DEFINES, ENABLE_GEOLOCATION=1) {
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r108574 r113968  
    2828#include "FontCache.h"
    2929#include "FontTranscoder.h"
    30 #if PLATFORM(QT) && HAVE(QRAWFONT)
    31 #include "GraphicsContext.h"
    32 #endif
    3330#include "IntPoint.h"
    3431#include "GlyphBuffer.h"
     
    152149    CodePath codePathToUse = codePath(run);
    153150
    154 #if PLATFORM(QT) && HAVE(QRAWFONT)
    155     if (context->textDrawingMode() & TextModeStroke)
    156         codePathToUse = Complex;
    157 #endif
    158 
    159151    if (codePathToUse != Complex)
    160152        return drawSimpleText(context, run, point, from, to);
  • trunk/Source/WebCore/platform/graphics/Font.h

    r111589 r113968  
    3737
    3838#if PLATFORM(QT)
     39#if HAVE(QRAWFONT)
     40#include <QRawFont>
     41class QTextLayout;
     42#else
    3943#include <QFont>
     44#endif
    4045#endif
    4146
     
    176181
    177182#if PLATFORM(QT)
     183#if HAVE(QRAWFONT)
     184    QRawFont rawFont() const;
     185#else
    178186    QFont font() const;
     187#endif
     188    QFont syntheticFont() const;
    179189#endif
    180190
     
    254264        return m_fontList && m_fontList->loadingCustomFonts();
    255265    }
     266#if PLATFORM(QT) && HAVE(QRAWFONT)
     267    void initFormatForTextLayout(QTextLayout*) const;
     268#endif
    256269
    257270    FontDescription m_fontDescription;
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r112816 r113968  
    5555
    5656#if PLATFORM(QT)
     57#if !HAVE(QRAWFONT)
    5758#include <QFont>
     59#else
     60#include <QRawFont>
     61#endif
    5862#endif
    5963
     
    191195
    192196#if PLATFORM(QT)
     197#if !HAVE(QRAWFONT)
    193198    QFont getQtFont() const { return m_platformData.font(); }
     199#else
     200    QRawFont getQtRawFont() const { return m_platformData.rawFont(); }
     201#endif // !HAVE(QRAWFONT)
    194202#endif
    195203
     
    347355    return width;
    348356}
    349 #endif
     357#endif // HAVE(QRAWFONT)
    350358
    351359} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/qt/FontCacheQt.cpp

    r97990 r113968  
    5050
    5151#if HAVE(QRAWFONT)
    52 static QRawFont rawFontForCharacters(const QString& string, const QFont& requestedFont)
     52static QRawFont rawFontForCharacters(const QString& string, const QRawFont& font)
    5353{
    54     QFont font(requestedFont);
    55     font.setStyleStrategy(QFont::NoFontMerging);
    56 
    57     QTextLayout layout(string, font);
     54    QTextLayout layout(string);
     55    layout.setRawFont(font);
    5856    layout.beginLayout();
    5957    layout.createLine();
     
    6159
    6260    QList<QGlyphRun> glyphList = layout.glyphRuns();
    63 
    64     ASSERT(glyphList.size() == 1);
     61    ASSERT(glyphList.size() <= 1);
     62    if (!glyphList.size())
     63        return QRawFont();
    6564
    6665    const QGlyphRun& glyphs(glyphList.at(0));
    67     QVector<quint32> glyphIndexes = glyphs.glyphIndexes();
    68 
    69     if (glyphIndexes.isEmpty())
    70         return QRawFont();
    71 
    7266    return glyphs.rawFont();
    7367}
    74 #endif
     68#endif // HAVE(QRAWFONT)
    7569
    7670const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
     
    7872#if HAVE(QRAWFONT)
    7973    QString qstring = QString::fromRawData(reinterpret_cast<const QChar*>(characters), length);
    80     QRawFont computedFont = rawFontForCharacters(qstring, font.font());
     74    QRawFont computedFont = rawFontForCharacters(qstring, font.rawFont());
    8175    if (!computedFont.isValid())
    8276        return 0;
     
    108102FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
    109103{
    110 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
    111104    QFontDatabase db;
    112105    if (!db.hasFamily(familyName))
    113106        return 0;
    114 #endif
    115107    return new FontPlatformData(fontDescription, familyName);
    116108}
  • trunk/Source/WebCore/platform/graphics/qt/FontCustomPlatformData.h

    r80582 r113968  
    3030#include <wtf/Forward.h>
    3131#include <wtf/Noncopyable.h>
     32#if HAVE(QRAWFONT)
     33#include <QRawFont>
     34#endif
    3235
    3336namespace WebCore {
     
    4245    ~FontCustomPlatformData();
    4346
     47#if !HAVE(QRAWFONT)
    4448    // for use with QFontDatabase::addApplicationFont/removeApplicationFont
    4549    int m_handle;
     50#else
     51    QRawFont m_rawFont;
     52#endif
    4653
    4754    FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight,
  • trunk/Source/WebCore/platform/graphics/qt/FontCustomPlatformDataQt.cpp

    r80582 r113968  
    2525#include "FontPlatformData.h"
    2626#include "SharedBuffer.h"
     27#if !HAVE(QRAWFONT)
    2728#include <QFontDatabase>
     29#endif
    2830#include <QStringList>
    2931
     
    3234FontCustomPlatformData::~FontCustomPlatformData()
    3335{
     36#if !HAVE(QRAWFONT)
    3437    QFontDatabase::removeApplicationFont(m_handle);
     38#endif
    3539}
    3640
    3741FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation, TextOrientation, FontWidthVariant, FontRenderingMode)
    3842{
     43#if !HAVE(QRAWFONT)
    3944    QFont font;
    4045    font.setFamily(QFontDatabase::applicationFontFamilies(m_handle)[0]);
     
    4348        font.setWeight(QFont::Bold);
    4449    font.setItalic(italic);
    45 
    4650    return FontPlatformData(font);
     51#else
     52    Q_ASSERT(m_rawFont.isValid());
     53    m_rawFont.setPixelSize(qreal(size));
     54    return FontPlatformData(m_rawFont);
     55#endif
    4756}
    4857
     
    5160    ASSERT_ARG(buffer, buffer);
    5261
    53     int id = QFontDatabase::addApplicationFontFromData(QByteArray(buffer->data(), buffer->size()));
     62    const QByteArray fontData(buffer->data(), buffer->size());
     63#if !HAVE(QRAWFONT)
     64    int id = QFontDatabase::addApplicationFontFromData(fontData);
    5465    if (id == -1)
    5566        return 0;
    56 
    5767    Q_ASSERT(QFontDatabase::applicationFontFamilies(id).size() > 0);
     68#endif
    5869
    5970    FontCustomPlatformData *data = new FontCustomPlatformData;
     71#if !HAVE(QRAWFONT)
    6072    data->m_handle = id;
     73#else
     74    // Pixel size doesn't matter at this point, it is set in FontCustomPlatformData::fontPlatformData.
     75    data->m_rawFont.loadFromData(fontData, /*pixelSize = */0, QFont::PreferDefaultHinting);
     76#endif
    6177    return data;
    6278}
  • trunk/Source/WebCore/platform/graphics/qt/FontPlatformData.h

    r86078 r113968  
    4141public:
    4242    FontPlatformDataPrivate()
     43#if !HAVE(QRAWFONT)
    4344        : size(font.pixelSize())
    4445        , bold(font.bold())
     46#else
     47        : size(0)
     48        , bold(false)
     49#endif
    4550        , oblique(false)
    4651        , isDeletedValue(false)
     
    5257        , isDeletedValue(false)
    5358    { }
     59#if !HAVE(QRAWFONT)
    5460    FontPlatformDataPrivate(const QFont& font)
    5561        : font(font)
    56 #if HAVE(QRAWFONT)
    57         , rawFont(QRawFont::fromFont(font, QFontDatabase::Any))
    58 #endif
    5962        , size(font.pixelSize())
    6063        , bold(font.bold())
     
    6265        , isDeletedValue(false)
    6366    { }
    64 #if HAVE(QRAWFONT)
     67#else
    6568    FontPlatformDataPrivate(const QRawFont& rawFont)
    66         : font()
    67         , rawFont(rawFont)
     69        : rawFont(rawFont)
    6870        , size(rawFont.pixelSize())
    6971        , bold(rawFont.weight() >= QFont::Bold)
     
    7678    { }
    7779
     80#if !HAVE(QRAWFONT)
    7881    QFont font;
    79 #if HAVE(QRAWFONT)
     82#else
    8083    QRawFont rawFont;
    8184#endif
     
    9194    FontPlatformData(float size, bool bold, bool oblique);
    9295    FontPlatformData(const FontDescription&, const AtomicString& familyName, int wordSpacing = 0, int letterSpacing = 0);
     96#if !HAVE(QRAWFONT)
    9397    FontPlatformData(const QFont& font)
    9498        : m_data(adoptRef(new FontPlatformDataPrivate(font)))
    9599    { }
    96 #if HAVE(QRAWFONT)
     100#else
    97101    FontPlatformData(const FontPlatformData&, float size);
    98102    FontPlatformData(const QRawFont& rawFont)
     
    113117    }
    114118
     119#if !HAVE(QRAWFONT)
    115120    QFont font() const
    116121    {
     
    120125        return m_data->font;
    121126    }
    122 #if HAVE(QRAWFONT)
     127#else
    123128    QRawFont rawFont() const
    124129    {
  • trunk/Source/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp

    r91452 r113968  
    6464    : m_data(adoptRef(new FontPlatformDataPrivate()))
    6565{
     66#if !HAVE(QRAWFONT)
    6667    QFont& font = m_data->font;
     68#else
     69    QFont font;
     70#endif
    6771    int requestedSize = description.computedPixelSize();
    6872    font.setFamily(familyName);
     
    7276    font.setWordSpacing(wordSpacing);
    7377    font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing);
    74     const bool smallCaps = description.smallCaps();
    75     font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase);
    7678    font.setStyleStrategy(QFont::ForceIntegerMetrics);
    7779
    7880    m_data->bold = font.bold();
     81#if !HAVE(QRAWFONT)
     82    const bool smallCaps = description.smallCaps();
     83    font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase);
    7984    // WebKit allows font size zero but QFont does not. We will return
    8085    // m_data->size if a font size of zero is requested and pixelSize()
    8186    // otherwise.
    8287    m_data->size = (!requestedSize) ? requestedSize : font.pixelSize();
    83 #if HAVE(QRAWFONT)
     88#else
    8489    m_data->rawFont = QRawFont::fromFont(font, QFontDatabase::Any);
     90    m_data->size = requestedSize;
    8591#endif
    8692}
     
    9096    : m_data(adoptRef(new FontPlatformDataPrivate()))
    9197{
    92     m_data->font = other.m_data->font;
    9398    m_data->rawFont = other.m_data->rawFont;
    9499    m_data->bold = other.m_data->bold;
    95100    m_data->oblique = other.m_data->oblique;
    96     m_data->font.setPixelSize(size);
    97101    m_data->rawFont.setPixelSize(size);
    98     m_data->size = size ? m_data->font.pixelSize() : 0;
     102    m_data->size = m_data->rawFont.pixelSize();
    99103}
    100 #endif
     104#endif // HAVE(QRAWFONT)
    101105
    102106bool FontPlatformData::operator==(const FontPlatformData& other) const
     
    111115                         && m_data->bold == other.m_data->bold
    112116                         && m_data->oblique == other.m_data->oblique
     117#if !HAVE(QRAWFONT)
    113118                         && m_data->font == other.m_data->font);
     119#else
     120                         && m_data->rawFont == other.m_data->rawFont);
     121#endif
    114122    return equals;
    115123}
     
    121129    if (m_data->isDeletedValue)
    122130        return 1;
    123     return qHash(m_data->font.toString())
    124            ^ qHash(*reinterpret_cast<quint32*>(&m_data->size))
    125            ^ qHash(m_data->bold)
    126            ^ qHash(m_data->oblique);
     131#if !HAVE(QRAWFONT)
     132    return (qHash(m_data->font.toString()) ^ qHash(m_data->bold)
     133            ^ qHash(m_data->oblique))
     134            ^ qHash(*reinterpret_cast<quint32*>(&m_data->size));
     135#else
     136    return qHash(m_data->rawFont.familyName()) ^ qHash(m_data->rawFont.style())
     137            ^ qHash(m_data->rawFont.weight())
     138            ^ qHash(*reinterpret_cast<quint32*>(&m_data->size));
     139#endif
    127140}
    128141
  • trunk/Source/WebCore/platform/graphics/qt/FontQt.cpp

    r90919 r113968  
    11/*
    2     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     2    Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
    33    Copyright (C) 2008, 2010 Holger Hans Peter Freyther
    44    Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
     
    2727#include "FontFallbackList.h"
    2828#include "FontSelector.h"
    29 #if HAVE(QRAWFONT)
    3029#include "GlyphBuffer.h"
    31 #endif
    3230#include "Gradient.h"
    3331#include "GraphicsContext.h"
     
    3836
    3937#include <QBrush>
    40 #include <QFontInfo>
    41 #include <QFontMetrics>
    4238#include <QPainter>
    4339#include <QPainterPath>
    4440#include <QPen>
    45 #if HAVE(QRAWFONT)
    4641#include <QPointF>
    47 #endif
    4842#include <QTextLayout>
    4943#include <qalgorithms.h>
    50 #include <qdebug.h>
    5144
    5245#include <limits.h>
     
    9386    }
    9487
    95     return QPen(QColor(ctx->fillColor()));
     88    return QPen(QColor(ctx->fillColor()), 0);
    9689}
    9790
     
    113106}
    114107
    115 static void drawTextCommon(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to, const QFont& font, bool isComplexText)
    116 {
    117     if (to < 0)
    118         to = run.length();
    119 
    120     QPainter *p = ctx->platformContext();
    121 
    122     QPen textFillPen;
    123     if (ctx->textDrawingMode() & TextModeFill)
    124         textFillPen = fillPenForContext(ctx);
    125 
    126     QPen textStrokePen;
    127     if (ctx->textDrawingMode() & TextModeStroke)
    128         textStrokePen = strokePenForContext(ctx);
    129 
     108static QPainterPath pathForGlyphs(const QGlyphRun& glyphRun, const QPointF& offset)
     109{
     110    QPainterPath path;
     111    const QRawFont rawFont(glyphRun.rawFont());
     112    const QVector<quint32> glyphIndices = glyphRun.glyphIndexes();
     113    const QVector<QPointF> positions = glyphRun.positions();
     114    for (int i = 0; i < glyphIndices.size(); ++i) {
     115        QPainterPath glyphPath = rawFont.pathForGlyph(glyphIndices.at(i));
     116        glyphPath.translate(positions.at(i) + offset);
     117        path.addPath(glyphPath);
     118    }
     119    return path;
     120}
     121
     122static void drawQtGlyphRun(GraphicsContext* context, const QGlyphRun& qtGlyphRun, const QPointF& point, int baseLineOffset)
     123{
     124    QPainter* painter = context->platformContext();
     125
     126    QPainterPath textStrokePath;
     127    if (context->textDrawingMode() & TextModeStroke)
     128        textStrokePath = pathForGlyphs(qtGlyphRun, point);
     129
     130    ShadowBlur* shadow = context->shadowBlur();
     131    if (context->hasShadow() && shadow->type() != ShadowBlur::NoShadow) {
     132        switch (shadow->type()) {
     133        case ShadowBlur::SolidShadow: {
     134            QPen previousPen = painter->pen();
     135            painter->setPen(context->state().shadowColor);
     136            const QPointF shadowOffset(context->state().shadowOffset.width(), context->state().shadowOffset.height());
     137            painter->translate(shadowOffset);
     138            if (context->textDrawingMode() & TextModeFill)
     139                painter->drawGlyphRun(point, qtGlyphRun);
     140            else if (context->textDrawingMode() & TextModeStroke)
     141                painter->strokePath(textStrokePath, painter->pen());
     142            painter->translate(-shadowOffset);
     143            painter->setPen(previousPen);
     144            break;
     145        }
     146        case ShadowBlur::BlurShadow: {
     147            const int width = qtGlyphRun.boundingRect().width();
     148            const QRawFont& font = qtGlyphRun.rawFont();
     149            const int height = font.ascent() + font.descent();
     150            const QRectF boundingRect(point.x(), point.y() - font.ascent() + baseLineOffset, width, height);
     151            GraphicsContext* shadowContext = shadow->beginShadowLayer(context, boundingRect);
     152            if (shadowContext) {
     153                QPainter* shadowPainter = shadowContext->platformContext();
     154                shadowPainter->setPen(shadowContext->state().shadowColor);
     155                if (shadowContext->textDrawingMode() & TextModeFill)
     156                    shadowPainter->drawGlyphRun(point, qtGlyphRun);
     157                else if (shadowContext->textDrawingMode() & TextModeStroke)
     158                    shadowPainter->strokePath(textStrokePath, shadowPainter->pen());
     159                shadow->endShadowLayer(context);
     160            }
     161            break;
     162        }
     163        case ShadowBlur::NoShadow:
     164        default:
     165            ASSERT_NOT_REACHED();
     166            break;
     167        }
     168    }
     169
     170    if (context->textDrawingMode() & TextModeStroke)
     171        painter->strokePath(textStrokePath, strokePenForContext(context));
     172
     173    if (context->textDrawingMode() & TextModeFill) {
     174        QPen previousPen = painter->pen();
     175        painter->setPen(fillPenForContext(context));
     176        painter->drawGlyphRun(point, qtGlyphRun);
     177        painter->setPen(previousPen);
     178    }
     179}
     180
     181void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
     182{
     183    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
     184    const QString string = fromRawDataWithoutRef(sanitized);
     185    QTextLayout layout(string);
     186    layout.setRawFont(rawFont());
     187    initFormatForTextLayout(&layout);
     188    QTextLine line = setupLayout(&layout, run);
     189    const QPointF adjustedPoint(point.x(), point.y() - line.ascent());
     190
     191    QList<QGlyphRun> runs = line.glyphRuns(from, to - from);
     192    Q_FOREACH(QGlyphRun glyphRun, runs)
     193        drawQtGlyphRun(ctx, glyphRun, adjustedPoint, line.ascent());
     194}
     195
     196float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>*, GlyphOverflow*) const
     197{
     198    if (!primaryFont()->platformData().size())
     199        return 0;
     200
     201    if (!run.length())
     202        return 0;
     203
     204    if (run.length() == 1 && treatAsSpace(run[0]))
     205        return primaryFont()->spaceWidth() + run.expansion();
    130206    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    131207    QString string = fromRawDataWithoutRef(sanitized);
    132     QPointF pt(point.x(), point.y());
    133 
    134     if (from > 0 || to < run.length()) {
    135         if (isComplexText) {
    136             QTextLayout layout(string, font);
    137             QTextLine line = setupLayout(&layout, run);
    138             float x1 = line.cursorToX(from);
    139             float x2 = line.cursorToX(to);
    140             if (x2 < x1)
    141                 qSwap(x1, x2);
    142 
    143             QFontMetrics fm(font);
    144             int ascent = fm.ascent();
    145             QRectF boundingRect(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
    146             QRectF clip = boundingRect;
    147 
    148             ShadowBlur* ctxShadow = ctx->shadowBlur();
    149             if (ctxShadow->type() != ShadowBlur::NoShadow) {
    150                 const QPointF shadowOffset(ctx->state().shadowOffset.width(), ctx->state().shadowOffset.height());
    151                 qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
    152                 if (shadowOffset.x() > 0)
    153                     dx2 = shadowOffset.x();
    154                 else
    155                     dx1 = -shadowOffset.x();
    156                 if (shadowOffset.y() > 0)
    157                     dy2 = shadowOffset.y();
    158                 else
    159                     dy1 = -shadowOffset.y();
    160                 // expand the clip rect to include the text shadow as well
    161                 const float blurDistance = ctx->state().shadowBlur;
    162                 clip.adjust(dx1, dx2, dy1, dy2);
    163                 clip.adjust(-blurDistance, -blurDistance, blurDistance, blurDistance);
    164             }
    165             p->save();
    166             p->setClipRect(clip.toRect(), Qt::IntersectClip);
    167             pt.setY(pt.y() - ascent);
    168 
    169             if (ctxShadow->type() != ShadowBlur::NoShadow) {
    170                 ShadowBlur* ctxShadow = ctx->shadowBlur();
    171                 if (ctxShadow->type() != ShadowBlur::BlurShadow
    172                     && (!ctxShadow->shadowsIgnoreTransforms() || ctx->getCTM().isIdentity())) {
    173                     p->save();
    174                     p->setPen(ctx->state().shadowColor);
    175                     p->translate(QPointF(ctx->state().shadowOffset.width(), ctx->state().shadowOffset.height()));
    176                     line.draw(p, pt);
    177                     p->restore();
    178                 } else {
    179                     GraphicsContext* shadowContext = ctxShadow->beginShadowLayer(ctx, boundingRect);
    180                     if (shadowContext) {
    181                         QPainter* shadowPainter = shadowContext->platformContext();
    182                         // Since it will be blurred anyway, we don't care about render hints.
    183                         shadowPainter->setFont(p->font());
    184                         shadowPainter->setPen(ctx->state().shadowColor);
    185                         line.draw(shadowPainter, pt);
    186                         ctxShadow->endShadowLayer(ctx);
    187                     }
    188                 }
    189             }
    190             p->setPen(textFillPen);
    191             line.draw(p, pt);
    192             p->restore();
    193             return;
    194         }
    195         int skipWidth = QFontMetrics(font).width(string, from, Qt::TextBypassShaping);
    196         pt.setX(pt.x() + skipWidth);
    197         string = fromRawDataWithoutRef(sanitized, from, to - from);
    198     }
    199 
    200     p->setFont(font);
    201 
    202     int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
    203     if (!isComplexText && !(ctx->textDrawingMode() & TextModeStroke))
    204         flags |= Qt::TextBypassShaping;
    205 
    206     QPainterPath textStrokePath;
    207     if (ctx->textDrawingMode() & TextModeStroke)
    208         textStrokePath.addText(pt, font, string);
    209 
    210     ShadowBlur* ctxShadow = ctx->shadowBlur();
    211     if (ctx->hasShadow() && ctxShadow->type() != ShadowBlur::NoShadow) {
    212         if (ctx->textDrawingMode() & TextModeFill) {
    213             if (ctxShadow->type() != ShadowBlur::BlurShadow) {
    214                 p->save();
    215                 p->setPen(ctx->state().shadowColor);
    216                 p->translate(QPointF(ctx->state().shadowOffset.width(), ctx->state().shadowOffset.height()));
    217                 p->drawText(pt, string, flags, run.expansion());
    218                 p->restore();
    219             } else {
    220                 QFontMetrics fm(font);
    221                 QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string, -1, flags), fm.height());
    222                 GraphicsContext* shadowContext = ctxShadow->beginShadowLayer(ctx, boundingRect);
    223                 if (shadowContext) {
    224                     QPainter* shadowPainter = shadowContext->platformContext();
    225                     // Since it will be blurred anyway, we don't care about render hints.
    226                     shadowPainter->setFont(p->font());
    227                     shadowPainter->setPen(ctx->state().shadowColor);
    228                     shadowPainter->drawText(pt, string, flags, run.expansion());
    229                     ctxShadow->endShadowLayer(ctx);
    230                 }
    231             }
    232         } else if (ctx->textDrawingMode() & TextModeStroke) {
    233             if (ctxShadow->type() != ShadowBlur::BlurShadow) {
    234                 const QPointF shadowOffset(ctx->state().shadowOffset.width(), ctx->state().shadowOffset.height());
    235                 p->translate(shadowOffset);
    236                 p->strokePath(textStrokePath, QPen(ctx->state().shadowColor));
    237                 p->translate(-shadowOffset);
    238             } else {
    239                 QFontMetrics fm(font);
    240                 QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string, -1, flags), fm.height());
    241                 GraphicsContext* shadowContext = ctxShadow->beginShadowLayer(ctx, boundingRect);
    242                 if (shadowContext) {
    243                     QPainter* shadowPainter = shadowContext->platformContext();
    244                     // Since it will be blurred anyway, we don't care about render hints.
    245                     shadowPainter->setFont(p->font());
    246                     shadowPainter->strokePath(textStrokePath, QPen(ctx->state().shadowColor));
    247                     ctxShadow->endShadowLayer(ctx);
    248                 }
    249             }
    250         }
    251     }
    252 
    253     if (ctx->textDrawingMode() & TextModeStroke)
    254         p->strokePath(textStrokePath, textStrokePen);
    255 
    256     if (ctx->textDrawingMode() & TextModeFill) {
    257         QPen previousPen = p->pen();
    258         p->setPen(textFillPen);
    259         p->drawText(pt, string, flags, run.expansion());
    260         p->setPen(previousPen);
    261     }
    262 }
    263 
    264 void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
    265 {
    266     drawTextCommon(ctx, run, point, from, to, font(), /* isComplexText = */true);
    267 }
    268 
    269 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>*, GlyphOverflow*) const
    270 {
    271     if (!primaryFont()->platformData().size())
    272         return 0;
    273 
    274     if (!run.length())
    275         return 0;
    276 
    277     if (run.length() == 1 && treatAsSpace(run[0]))
    278         return QFontMetrics(font()).width(space) + run.expansion();
    279 
     208
     209    QTextLayout layout(string);
     210    layout.setRawFont(rawFont());
     211    initFormatForTextLayout(&layout);
     212    QTextLine line = setupLayout(&layout, run);
     213    float x1 = line.cursorToX(0);
     214    float x2 = line.cursorToX(run.length());
     215    const float width = qAbs(x2 - x1);
     216
     217    return width + run.expansion();
     218}
     219
     220int Font::offsetForPositionForComplexText(const TextRun& run, float position, bool) const
     221{
    280222    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    281223    QString string = fromRawDataWithoutRef(sanitized);
    282224
    283     int w = QFontMetrics(font()).width(string);
    284     // WebKit expects us to ignore word spacing on the first character (as opposed to what Qt does)
    285     if (treatAsSpace(run[0]))
    286         w -= m_wordSpacing;
    287 
    288     return w + run.expansion();
    289 }
    290 
    291 int Font::offsetForPositionForComplexText(const TextRun& run, float position, bool) const
     225    QTextLayout layout(string);
     226    layout.setRawFont(rawFont());
     227    initFormatForTextLayout(&layout);
     228    QTextLine line = setupLayout(&layout, run);
     229    return line.xToCursor(position);
     230}
     231
     232FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& pt, int h, int from, int to) const
    292233{
    293234    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    294235    QString string = fromRawDataWithoutRef(sanitized);
    295236
    296     QTextLayout layout(string, font());
    297     QTextLine line = setupLayout(&layout, run);
    298     return line.xToCursor(position);
    299 }
    300 
    301 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& pt, int h, int from, int to) const
    302 {
    303     String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    304     QString string = fromRawDataWithoutRef(sanitized);
    305 
    306     QTextLayout layout(string, font());
     237    QTextLayout layout(string);
     238    layout.setRawFont(rawFont());
     239    initFormatForTextLayout(&layout);
    307240    QTextLine line = setupLayout(&layout, run);
    308241
     
    315248}
    316249
     250void Font::initFormatForTextLayout(QTextLayout* layout) const
     251{
     252    QTextLayout::FormatRange range;
     253    range.start = 0;
     254    range.length = layout->text().length();
     255    if (m_wordSpacing)
     256        range.format.setFontWordSpacing(m_wordSpacing);
     257    if (m_letterSpacing)
     258        range.format.setFontLetterSpacing(m_letterSpacing);
     259    if (typesettingFeatures() & Kerning)
     260        range.format.setFontKerning(true);
     261    if (isSmallCaps())
     262        range.format.setFontCapitalization(QFont::SmallCaps);
     263
     264    if (range.format.propertyCount())
     265        layout->setAdditionalFormats(QList<QTextLayout::FormatRange>() << range);
     266}
     267
    317268bool Font::canReturnFallbackFontsForComplexText()
    318269{
     
    325276}
    326277
    327 #if HAVE(QRAWFONT)
    328278void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
    329279{
     
    334284    bool shouldStroke = context->textDrawingMode() & TextModeStroke;
    335285
    336     // Stroking text should always take the complex path.
    337     ASSERT(!shouldStroke);
    338 
    339286    if (!shouldFill && !shouldStroke)
    340287        return;
     
    345292    glyphIndexes.reserve(numGlyphs);
    346293    positions.reserve(numGlyphs);
     294    const QRawFont& font(fontData->getQtRawFont());
    347295
    348296    float width = 0;
     
    358306    }
    359307
    360     QRawFont rawFont(fontData->platformData().rawFont());
    361 
    362308    QGlyphRun qtGlyphs;
    363309    qtGlyphs.setGlyphIndexes(glyphIndexes);
    364310    qtGlyphs.setPositions(positions);
    365     qtGlyphs.setRawFont(rawFont);
    366 
    367     QPainter* painter = context->platformContext();
    368 
    369     ShadowBlur* shadow = context->shadowBlur();
    370     switch (shadow->type()) {
    371     case ShadowBlur::SolidShadow: {
    372         QPen previousPen = painter->pen();
    373         painter->setPen(context->state().shadowColor);
    374         const QPointF shadowOffset(context->state().shadowOffset.width(), context->state().shadowOffset.height());
    375         painter->translate(shadowOffset);
    376         painter->drawGlyphRun(point, qtGlyphs);
    377         painter->translate(-shadowOffset);
    378         painter->setPen(previousPen);
    379         break;
    380     }
    381     case ShadowBlur::BlurShadow: {
    382         qreal height = rawFont.ascent() + rawFont.descent() + 1;
    383         QRectF boundingRect(point.x(), point.y() - rawFont.ascent(), width, height);
    384         GraphicsContext* shadowContext = shadow->beginShadowLayer(context, boundingRect);
    385         if (shadowContext) {
    386             QPainter* shadowPainter = shadowContext->platformContext();
    387             shadowPainter->setPen(context->state().shadowColor);
    388             shadowPainter->drawGlyphRun(point, qtGlyphs);
    389             shadow->endShadowLayer(context);
    390         }
    391         break;
    392     }
    393     case ShadowBlur::NoShadow:
    394         break;
    395     default:
    396         ASSERT_NOT_REACHED();
    397         break;
    398     }
    399 
    400     QPen previousPen = painter->pen();
    401     painter->setPen(fillPenForContext(context));
    402     painter->drawGlyphRun(point, qtGlyphs);
    403     painter->setPen(previousPen);
    404 }
     311    qtGlyphs.setRawFont(font);
     312
     313    drawQtGlyphRun(context, qtGlyphs, point, /* baselineOffset = */0);
     314}
     315
    405316
    406317bool Font::canExpandAroundIdeographsInComplexText()
     
    409320}
    410321
    411 #else // !HAVE(QRAWFONT)
    412 
    413 void Font::drawSimpleText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
    414 {
    415     drawTextCommon(ctx, run, point, from, to, font(), /* isComplexText = */false);
    416 }
    417 
    418 int Font::offsetForPositionForSimpleText(const TextRun& run, float position, bool includePartialGlyphs) const
    419 {
    420     String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    421     QString string = fromRawDataWithoutRef(sanitized);
    422 
    423     QFontMetrics fm(font());
    424     float delta = position;
    425     int curPos = 0;
    426     do {
    427         float charWidth = fm.width(string[curPos]);
    428         delta -= charWidth;
    429         if (includePartialGlyphs) {
    430             if (delta + charWidth / 2 <= 0)
    431                 break;
    432         } else {
    433             if (delta + charWidth <= 0)
    434                 break;
    435         }
    436     } while (++curPos < string.size());
    437 
    438     return curPos;
    439 }
    440 
    441 
    442 float Font::floatWidthForSimpleText(const TextRun& run, GlyphBuffer* glyphBuffer, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
    443 {
    444     if (!primaryFont()->platformData().size())
    445         return 0;
    446 
    447     if (!run.length())
    448         return 0;
    449 
    450     String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    451     QString string = fromRawDataWithoutRef(sanitized);
    452 
    453     int w = QFontMetrics(font()).width(string, -1, Qt::TextBypassShaping);
    454 
    455     // WebKit expects us to ignore word spacing on the first character (as opposed to what Qt does)
    456     if (treatAsSpace(run[0]))
    457         w -= m_wordSpacing;
    458 
    459     return w + run.expansion();
    460 }
    461 
    462 
    463 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& pt, int h, int from, int to) const
    464 {
    465     String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    466     QString wholeText = fromRawDataWithoutRef(sanitized);
    467     QString selectedText = fromRawDataWithoutRef(sanitized, from, qMin(to - from, wholeText.length() - from));
    468 
    469     int startX = QFontMetrics(font()).width(wholeText, from, Qt::TextBypassShaping);
    470     int width = QFontMetrics(font()).width(selectedText, -1, Qt::TextBypassShaping);
    471 
    472     return FloatRect(pt.x() + startX, pt.y(), width, h);
    473 }
    474 
    475 bool Font::canExpandAroundIdeographsInComplexText()
    476 {
    477     return false;
    478 }
    479 
    480 bool Font::primaryFontHasGlyphForCharacter(UChar32) const
    481 {
    482     notImplemented();
    483     return true;
    484 }
    485 
    486 int Font::emphasisMarkAscent(const AtomicString&) const
    487 {
    488     notImplemented();
    489     return 0;
    490 }
    491 
    492 int Font::emphasisMarkDescent(const AtomicString&) const
    493 {
    494     notImplemented();
    495     return 0;
    496 }
    497 
    498 int Font::emphasisMarkHeight(const AtomicString&) const
    499 {
    500     notImplemented();
    501     return 0;
    502 }
    503 
    504 void Font::drawEmphasisMarksForSimpleText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const
    505 {
    506     notImplemented();
    507 }
    508 #endif // HAVE(QRAWFONT)
    509 
    510 QFont Font::font() const
    511 {
    512     QFont f = primaryFont()->getQtFont();
    513     if (m_letterSpacing != 0)
     322QFont Font::syntheticFont() const
     323{
     324    QRawFont rawFont(primaryFont()->getQtRawFont());
     325    QFont f(rawFont.familyName());
     326    if (rawFont.pixelSize())
     327        f.setPixelSize(rawFont.pixelSize());
     328    f.setWeight(rawFont.weight());
     329    f.setStyle(rawFont.style());
     330    if (m_letterSpacing)
    514331        f.setLetterSpacing(QFont::AbsoluteSpacing, m_letterSpacing);
    515     if (m_wordSpacing != 0)
     332    if (m_wordSpacing)
    516333        f.setWordSpacing(m_wordSpacing);
    517334    return f;
     
    519336
    520337
    521 }
    522 
     338QRawFont Font::rawFont() const
     339{
     340    return primaryFont()->getQtRawFont();
     341}
     342
     343}
  • trunk/Source/WebCore/platform/graphics/qt/FontQt4.cpp

    r113967 r113968  
    2727#include "FontFallbackList.h"
    2828#include "FontSelector.h"
    29 #if HAVE(QRAWFONT)
    3029#include "GlyphBuffer.h"
    31 #endif
    3230#include "Gradient.h"
    3331#include "GraphicsContext.h"
     
    4341#include <QPainterPath>
    4442#include <QPen>
    45 #if HAVE(QRAWFONT)
    46 #include <QPointF>
    47 #endif
    4843#include <QTextLayout>
     44#include <limits.h>
    4945#include <qalgorithms.h>
    5046#include <qdebug.h>
    5147
    52 #include <limits.h>
    5348
    5449namespace WebCore {
     
    7368    layout->beginLayout();
    7469    QTextLine line = layout->createLine();
    75     line.setLineWidth(INT_MAX/256);
     70    line.setLineWidth(INT_MAX / 256);
    7671    if (style.expansion())
    7772        line.setLineWidth(line.naturalTextWidth() + style.expansion());
     
    118113        to = run.length();
    119114
    120     QPainter *p = ctx->platformContext();
     115    QPainter* p = ctx->platformContext();
    121116
    122117    QPen textFillPen;
     
    325320}
    326321
    327 #if HAVE(QRAWFONT)
    328 void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
    329 {
    330     if (context->paintingDisabled())
    331         return;
    332 
    333     bool shouldFill = context->textDrawingMode() & TextModeFill;
    334     bool shouldStroke = context->textDrawingMode() & TextModeStroke;
    335 
    336     // Stroking text should always take the complex path.
    337     ASSERT(!shouldStroke);
    338 
    339     if (!shouldFill && !shouldStroke)
    340         return;
    341 
    342     QVector<quint32> glyphIndexes;
    343     QVector<QPointF> positions;
    344 
    345     glyphIndexes.reserve(numGlyphs);
    346     positions.reserve(numGlyphs);
    347 
    348     float width = 0;
    349 
    350     for (int i = 0; i < numGlyphs; ++i) {
    351         Glyph glyph = glyphBuffer.glyphAt(from + i);
    352         float advance = glyphBuffer.advanceAt(from + i);
    353         if (!glyph)
    354             continue;
    355         glyphIndexes.append(glyph);
    356         positions.append(QPointF(width, 0));
    357         width += advance;
    358     }
    359 
    360     QRawFont rawFont(fontData->platformData().rawFont());
    361 
    362     QGlyphRun qtGlyphs;
    363     qtGlyphs.setGlyphIndexes(glyphIndexes);
    364     qtGlyphs.setPositions(positions);
    365     qtGlyphs.setRawFont(rawFont);
    366 
    367     QPainter* painter = context->platformContext();
    368 
    369     ShadowBlur* shadow = context->shadowBlur();
    370     switch (shadow->type()) {
    371     case ShadowBlur::SolidShadow: {
    372         QPen previousPen = painter->pen();
    373         painter->setPen(context->state().shadowColor);
    374         const QPointF shadowOffset(context->state().shadowOffset.width(), context->state().shadowOffset.height());
    375         painter->translate(shadowOffset);
    376         painter->drawGlyphRun(point, qtGlyphs);
    377         painter->translate(-shadowOffset);
    378         painter->setPen(previousPen);
    379         break;
    380     }
    381     case ShadowBlur::BlurShadow: {
    382         qreal height = rawFont.ascent() + rawFont.descent() + 1;
    383         QRectF boundingRect(point.x(), point.y() - rawFont.ascent(), width, height);
    384         GraphicsContext* shadowContext = shadow->beginShadowLayer(context, boundingRect);
    385         if (shadowContext) {
    386             QPainter* shadowPainter = shadowContext->platformContext();
    387             shadowPainter->setPen(context->state().shadowColor);
    388             shadowPainter->drawGlyphRun(point, qtGlyphs);
    389             shadow->endShadowLayer(context);
    390         }
    391         break;
    392     }
    393     case ShadowBlur::NoShadow:
    394         break;
    395     default:
    396         ASSERT_NOT_REACHED();
    397         break;
    398     }
    399 
    400     QPen previousPen = painter->pen();
    401     painter->setPen(fillPenForContext(context));
    402     painter->drawGlyphRun(point, qtGlyphs);
    403     painter->setPen(previousPen);
    404 }
    405 
    406 bool Font::canExpandAroundIdeographsInComplexText()
    407 {
    408     return false;
    409 }
    410 
    411 #else // !HAVE(QRAWFONT)
    412 
    413322void Font::drawSimpleText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
    414323{
     
    506415    notImplemented();
    507416}
    508 #endif // HAVE(QRAWFONT)
    509417
    510418QFont Font::font() const
    511419{
    512420    QFont f = primaryFont()->getQtFont();
    513     if (m_letterSpacing != 0)
     421    if (m_letterSpacing)
    514422        f.setLetterSpacing(QFont::AbsoluteSpacing, m_letterSpacing);
    515     if (m_wordSpacing != 0)
     423    if (m_wordSpacing)
    516424        f.setWordSpacing(m_wordSpacing);
    517425    return f;
    518426}
    519427
    520 
    521 }
    522 
     428QFont Font::syntheticFont() const
     429{
     430    return font();
     431}
     432
     433}
     434
  • trunk/Source/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp

    r108788 r113968  
    135135    float ascent = rawFont.ascent();
    136136    float xHeight = rawFont.xHeight();
    137     float lineSpacing = ascent + descent + rawFont.leading() + 1;
     137    float lineSpacing = ascent + descent + rawFont.leading();
    138138
    139139    QVector<quint32> indexes = rawFont.glyphIndexesForString(QLatin1String(" "));
     
    166166
    167167    m_fontMetrics.setAscent(ascent);
    168     m_fontMetrics.setDescent(descent);
     168    // WebKit expects the descent to be positive.
     169    m_fontMetrics.setDescent(qAbs(descent));
    169170    m_fontMetrics.setLineSpacing(lineSpacing);
    170171    m_fontMetrics.setXHeight(xHeight);
  • trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp

    r113484 r113968  
    881881    else if (fileList->length() == 1) {
    882882        String fname = fileList->item(0)->path();
    883         QFontMetrics fm(font.font());
     883        QFontMetrics fm(font.syntheticFont());
    884884        string = fm.elidedText(fname, Qt::ElideLeft, width);
    885885    } else {
  • trunk/Source/WebCore/platform/qt/RenderThemeQtMobile.cpp

    r113532 r113968  
    4646#include <QColor>
    4747#include <QFile>
    48 #include <QFontMetrics>
    4948#include <QPainter>
    5049#include <QPixmapCache>
     
    582581{
    583582    QSize size(0, 0);
    584     const QFontMetrics fm(renderStyle->font().font());
    585583
    586584    switch (renderStyle->appearance()) {
     
    618616    case ButtonPart:
    619617    case MenulistPart: {
    620         const int height = fm.height() * buttonHeightRatio * renderStyle->effectiveZoom();
     618        const int height = renderStyle->fontMetrics().height() * buttonHeightRatio * renderStyle->effectiveZoom();
    621619        size = QSize(renderStyle->width().value(), height);
    622620        break;
  • trunk/Source/WebKit/qt/Api/qwebpage.cpp

    r113361 r113968  
    13931393            if (renderTextControl) {
    13941394                RenderStyle* renderStyle = renderTextControl->style();
    1395                 return QVariant(QFont(renderStyle->font().font()));
     1395                return QVariant(QFont(renderStyle->font().syntheticFont()));
    13961396            }
    13971397            return QVariant(QFont());
  • trunk/Source/WebKit/qt/ChangeLog

    r113484 r113968  
     12012-03-05  Pierre Rossi  <pierre.rossi@gmail.com>
     2
     3        [Qt] Use QRawFont when building with Qt 5
     4        https://bugs.webkit.org/show_bug.cgi?id=78001
     5
     6        Since QFont is not used internally, we now need
     7        to query for a QFont that should be a good
     8        enough match.
     9
     10        Reviewed by Simon Hausmann.
     11
     12        * Api/qwebpage.cpp:
     13        (QWebPage::inputMethodQuery):
     14        * WebCoreSupport/PopupMenuQt.cpp:
     15        (WebCore::PopupMenuQt::show):
     16        * WebCoreSupport/RenderThemeQStyle.cpp:
     17        (WebCore::RenderThemeQStyle::computeSizeBasedOnStyle):
     18
    1192012-04-06  Levi Weintraub  <leviw@chromium.org>
    220
  • trunk/Source/WebKit/qt/WebCoreSupport/PopupMenuQt.cpp

    r102419 r113968  
    104104    geometry.moveTopLeft(view->contentsToWindow(rect.location()));
    105105    m_popup->setGeometry(geometry);
    106     m_popup->setFont(m_popupClient->menuStyle().font().font());
     106    m_popup->setFont(m_popupClient->menuStyle().font().syntheticFont());
    107107
    108108    m_selectData = adoptPtr(new SelectData(m_popupClient));
  • trunk/Source/WebKit/qt/WebCoreSupport/RenderThemeQStyle.cpp

    r113484 r113968  
    210210{
    211211    QSize size(0, 0);
    212     const QFontMetrics fm(renderStyle->font().font());
     212    const QFontMetrics fm(renderStyle->font().syntheticFont());
    213213    QStyle* style = qStyle();
    214214
  • trunk/Tools/ChangeLog

    r113966 r113968  
     12012-03-05  Pierre Rossi  <pierre.rossi@gmail.com>
     2
     3        [Qt] Use QRawFont when building with Qt 5
     4        https://bugs.webkit.org/show_bug.cgi?id=78001
     5
     6        Flip the QRawFont switch for Qt 5.
     7
     8        Reviewed by Simon Hausmann.
     9
     10        * qmake/mkspecs/features/features.prf:
     11
    1122012-04-11  Vivek Galatage  <vivekgalatage@gmail.com>
    213
  • trunk/Tools/qmake/mkspecs/features/features.prf

    r113853 r113968  
    4444    DEFINES -= WTF_USE_ICU_UNICODE
    4545}
     46
     47# Use of QRawFont in Qt 5:
     48haveQt(5): DEFINES += HAVE_QRAWFONT=1
    4649
    4750isEmpty(HAVE_QRAWFONT) {
     
    231234    DEFINES += ENABLE_JAVASCRIPT_DEBUGGER=0
    232235}
    233 
    234236haveQt(4) {
    235237    haveQtModule(declarative): DEFINES += HAVE_QQUICK1=1
Note: See TracChangeset for help on using the changeset viewer.