Changeset 126907 in webkit


Ignore:
Timestamp:
Aug 28, 2012 11:52:17 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

OPENTYPE_VERTICAL support for Chromium Win
https://bugs.webkit.org/show_bug.cgi?id=94822

Patch by Koji Ishii <Koji Ishii> on 2012-08-28
Reviewed by Tony Chang.

To fix bug 51450 - Glyphs in vertical text tests are rotated 90 degrees clockwise on Chromium Windows,
this patch adds support of OPENTYPE_VERTICAL feature for Chromium Windows.
Since enabling OPENTYPE_VERTICAL feature would require rather a big number of tests to rebaseline,
the actual fix is separated into this patch, and the feature will be enabled in bug 51450,
so that it is easier to revert on any perf regressions, as suggested by Tony in comment #50 of bug 51450.

All changes in this patch are behind #if ENABLE(OPENTYPE_VERTICAL) and therefore no tests are included in this patch.
All tests in fast/writing-modes currently skipped will be enabled in bug 51450.

  • WebCore.gyp/WebCore.gyp: Added platform/graphics/opentype/OpenType*.
  • WebCore.gypi: Ditto.
  • platform/graphics/FontCache.h: SKia uses uint32_t as FontFileKey.
  • platform/graphics/GlyphPageTreeNode.cpp:

(WebCore::fill): Replace vertical alternate glyphs if vertical flow.

  • platform/graphics/SimpleFontData.cpp: Added m_verticalData.

(WebCore::SimpleFontData::SimpleFontData):

  • platform/graphics/SimpleFontData.h:

(WebCore::SimpleFontData::verticalData):
(SimpleFontData):
(WebCore::SimpleFontData::widthForGlyph):

  • platform/graphics/chromium/FontChromiumWin.cpp:

(WebCore::Font::drawGlyphs): Draw glyphs verticaly if font->verticalData().

  • platform/graphics/chromium/FontPlatformDataChromiumWin.cpp:

(WebCore::FontPlatformData::verticalData): Added.
(WebCore):
(WebCore::FontPlatformData::openTypeTable): Added.

  • platform/graphics/chromium/FontPlatformDataChromiumWin.h:

(WebCore):
(FontPlatformData): Added verticalData() and openTypeTable().

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r126902 r126907  
     12012-08-28  Koji Ishii  <kojiishi@gmail.com>
     2
     3        OPENTYPE_VERTICAL support for Chromium Win
     4        https://bugs.webkit.org/show_bug.cgi?id=94822
     5
     6        Reviewed by Tony Chang.
     7
     8        To fix bug 51450 - Glyphs in vertical text tests are rotated 90 degrees clockwise on Chromium Windows,
     9        this patch adds support of OPENTYPE_VERTICAL feature for Chromium Windows.
     10        Since enabling OPENTYPE_VERTICAL feature would require rather a big number of tests to rebaseline,
     11        the actual fix is separated into this patch, and the feature will be enabled in bug 51450,
     12        so that it is easier to revert on any perf regressions, as suggested by Tony in comment #50 of bug 51450.
     13
     14        All changes in this patch are behind #if ENABLE(OPENTYPE_VERTICAL) and therefore no tests are included in this patch.
     15        All tests in fast/writing-modes currently skipped will be enabled in bug 51450.
     16
     17        * WebCore.gyp/WebCore.gyp: Added platform/graphics/opentype/OpenType*.
     18        * WebCore.gypi: Ditto.
     19        * platform/graphics/FontCache.h: SKia uses uint32_t as FontFileKey.
     20        * platform/graphics/GlyphPageTreeNode.cpp:
     21        (WebCore::fill): Replace vertical alternate glyphs if vertical flow.
     22        * platform/graphics/SimpleFontData.cpp: Added m_verticalData.
     23        (WebCore::SimpleFontData::SimpleFontData):
     24        * platform/graphics/SimpleFontData.h:
     25        (WebCore::SimpleFontData::verticalData):
     26        (SimpleFontData):
     27        (WebCore::SimpleFontData::widthForGlyph):
     28        * platform/graphics/chromium/FontChromiumWin.cpp:
     29        (WebCore::Font::drawGlyphs): Draw glyphs verticaly if font->verticalData().
     30        * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp:
     31        (WebCore::FontPlatformData::verticalData): Added.
     32        (WebCore):
     33        (WebCore::FontPlatformData::openTypeTable): Added.
     34        * platform/graphics/chromium/FontPlatformDataChromiumWin.h:
     35        (WebCore):
     36        (FontPlatformData): Added verticalData() and openTypeTable().
     37
    1382012-08-28  Andy Estes  <aestes@apple.com>
    239
  • trunk/Source/WebCore/WebCore.gyp/WebCore.gyp

    r126857 r126907  
    18451845            ['exclude', 'Posix\\.cpp$'],
    18461846
     1847            ['include', 'platform/graphics/opentype/OpenTypeTypes\\.h$'],
     1848            ['include', 'platform/graphics/opentype/OpenTypeVerticalData\\.cpp$'],
     1849            ['include', 'platform/graphics/opentype/OpenTypeVerticalData\\.h$'],
     1850
    18471851            # The Chromium Win currently uses GlyphPageTreeNodeChromiumWin.cpp from
    18481852            # platform/graphics/chromium, included by regex above, instead.
  • trunk/Source/WebCore/WebCore.gypi

    r126890 r126907  
    38743874            'platform/graphics/opentype/OpenTypeSanitizer.cpp',
    38753875            'platform/graphics/opentype/OpenTypeSanitizer.h',
     3876            'platform/graphics/opentype/OpenTypeTypes.h',
    38763877            'platform/graphics/opentype/OpenTypeUtilities.cpp',
    38773878            'platform/graphics/opentype/OpenTypeUtilities.h',
     3879            'platform/graphics/opentype/OpenTypeVerticalData.cpp',
     3880            'platform/graphics/opentype/OpenTypeVerticalData.h',
    38783881            'platform/graphics/openvg/EGLDisplayOpenVG.cpp',
    38793882            'platform/graphics/openvg/EGLDisplayOpenVG.h',
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r124397 r126907  
    107107
    108108#if ENABLE(OPENTYPE_VERTICAL)
     109#if USE(SKIA)
     110    typedef uint32_t FontFileKey;
     111#else
    109112    typedef AtomicString FontFileKey;
     113#endif
    110114    OpenTypeVerticalData* getVerticalData(const FontFileKey&, const FontPlatformData&);
    111115#endif
  • trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp

    r126837 r126907  
    3030#include "GlyphPageTreeNode.h"
    3131
     32#include "OpenTypeVerticalData.h"
    3233#include "PlatformString.h"
    3334#include "SegmentedFontData.h"
     
    131132        return additionalFontData->fillSVGGlyphPage(pageToFill, offset, length, buffer, bufferLength, fontData);
    132133#endif
    133     return pageToFill->fill(offset, length, buffer, bufferLength, fontData);
     134    bool hasGlyphs = pageToFill->fill(offset, length, buffer, bufferLength, fontData);
     135#if ENABLE(OPENTYPE_VERTICAL)
     136    if (hasGlyphs && fontData->verticalData())
     137        fontData->verticalData()->substituteWithVerticalGlyphs(fontData, pageToFill, offset, length);
     138#endif
     139    return hasGlyphs;
    134140}
    135141
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp

    r125766 r126907  
    3333#include "Font.h"
    3434#include "FontCache.h"
     35#include "OpenTypeVerticalData.h"
    3536
    3637#include <wtf/MathExtras.h>
     
    5051    , m_isTextOrientationFallback(isTextOrientationFallback)
    5152    , m_isBrokenIdeographFallback(false)
     53#if ENABLE(OPENTYPE_VERTICAL)
     54    , m_verticalData(0)
     55#endif
    5256    , m_hasVerticalGlyphs(false)
    5357{
     
    5559    platformGlyphInit();
    5660    platformCharWidthInit();
     61#if ENABLE(OPENTYPE_VERTICAL)
     62    if (platformData.orientation() == Vertical && !isTextOrientationFallback) {
     63        m_verticalData = platformData.verticalData();
     64        m_hasVerticalGlyphs = m_verticalData && m_verticalData->hasVerticalMetrics();
     65    }
     66#endif
    5767}
    5868
     
    6575    , m_isTextOrientationFallback(false)
    6676    , m_isBrokenIdeographFallback(false)
     77#if ENABLE(OPENTYPE_VERTICAL)
     78    , m_verticalData(0)
     79#endif
    6780    , m_hasVerticalGlyphs(false)
    6881{
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r126456 r126907  
    8989    const FontPlatformData& platformData() const { return m_platformData; }
    9090#if ENABLE(OPENTYPE_VERTICAL)
    91     const OpenTypeVerticalData* verticalData() const { return 0; } // FIXME: implement
     91    const OpenTypeVerticalData* verticalData() const { return m_verticalData; }
    9292#endif
    9393
     
    230230    mutable OwnPtr<GlyphMetricsMap<FloatRect> > m_glyphToBoundsMap;
    231231    mutable GlyphMetricsMap<float> m_glyphToWidthMap;
     232#if ENABLE(OPENTYPE_VERTICAL)
     233    const OpenTypeVerticalData* m_verticalData;
     234#endif
    232235
    233236    bool m_treatAsFixedPitch;
     
    318321    if (m_fontData)
    319322        width = m_fontData->widthForSVGGlyph(glyph, m_platformData.size());
     323#if ENABLE(OPENTYPE_VERTICAL)
     324    else if (m_verticalData)
     325#if USE(CG) || USE(CAIRO) || PLATFORM(WX) || USE(SKIA_ON_MAC_CHROMIUM)
     326        width = m_verticalData->advanceHeight(this, glyph) + m_syntheticBoldOffset;
     327#else
     328        width = m_verticalData->advanceHeight(this, glyph);
     329#endif
     330#endif
    320331    else
    321332        width = platformWidthForGlyph(glyph);
  • trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

    r113345 r126907  
    391391    // the arrays of characters and advances.
    392392    const int kMaxBufferLength = 256;
    393     Vector<WORD, kMaxBufferLength> glyphs;
    394393    Vector<int, kMaxBufferLength> advances;
    395394    int glyphIndex = 0;  // The starting glyph of the current chunk.
    396395
     396    float horizontalOffset = point.x(); // The floating point offset of the left side of the current glyph.
     397#if ENABLE(OPENTYPE_VERTICAL)
     398    const OpenTypeVerticalData* verticalData = font->verticalData();
     399    if (verticalData) {
     400        Vector<FloatPoint, kMaxBufferLength> translations;
     401        Vector<GOFFSET, kMaxBufferLength> offsets;
     402
     403        // Skia doesn't have matrix for glyph coordinate space, so we rotate back the CTM.
     404        AffineTransform savedMatrix = graphicsContext->getCTM();
     405        graphicsContext->concatCTM(AffineTransform(0, -1, 1, 0, point.x(), point.y()));
     406        graphicsContext->concatCTM(AffineTransform(1, 0, 0, 1, -point.x(), -point.y()));
     407
     408        const FontMetrics& metrics = font->fontMetrics();
     409        SkScalar verticalOriginX = SkFloatToScalar(point.x() + metrics.floatAscent() - metrics.floatAscent(IdeographicBaseline));
     410        while (glyphIndex < numGlyphs) {
     411            // How many chars will be in this chunk?
     412            int curLen = std::min(kMaxBufferLength, numGlyphs - glyphIndex);
     413
     414            const Glyph* glyphs = glyphBuffer.glyphs(from + glyphIndex);
     415            translations.resize(curLen);
     416            verticalData->getVerticalTranslationsForGlyphs(font, &glyphs[0], curLen, reinterpret_cast<float*>(&translations[0]));
     417            // To position glyphs vertically, we use offsets instead of advances.
     418            advances.resize(curLen);
     419            advances.fill(0);
     420            offsets.resize(curLen);
     421            float currentWidth = 0;
     422            for (int i = 0; i < curLen; ++i, ++glyphIndex) {
     423                offsets[i].du = lroundf(translations[i].x());
     424                offsets[i].dv = -lroundf(currentWidth - translations[i].y());
     425                currentWidth += glyphBuffer.advanceAt(from + glyphIndex);
     426            }
     427            SkPoint origin;
     428            origin.set(verticalOriginX, SkFloatToScalar(point.y() + horizontalOffset - point.x()));
     429            horizontalOffset += currentWidth;
     430            paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], &offsets[0], &origin);
     431        }
     432
     433        graphicsContext->setCTM(savedMatrix);
     434        return;
     435    }
     436#endif
     437
    397438    // In order to round all offsets to the correct pixel boundary, this code keeps track of the absolute position
    398439    // of each glyph in floating point units and rounds to integer advances at the last possible moment.
    399440
    400     float horizontalOffset = point.x(); // The floating point offset of the left side of the current glyph.
    401441    int lastHorizontalOffsetRounded = lroundf(horizontalOffset); // The rounded offset of the left side of the last glyph rendered.
     442    Vector<WORD, kMaxBufferLength> glyphs;
    402443    while (glyphIndex < numGlyphs) {
    403444        // How many chars will be in this chunk?
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp

    r126312 r126907  
    192192}
    193193
     194#if ENABLE(OPENTYPE_VERTICAL)
     195const OpenTypeVerticalData* FontPlatformData::verticalData() const
     196{
     197    SkFontID id = typeface()->uniqueID();
     198    return fontCache()->getVerticalData(id, *this);
     199}
     200
     201PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
     202{
     203    HWndDC hdc(0);
     204    HGDIOBJ oldFont = SelectObject(hdc, hfont());
     205
     206    DWORD size = GetFontData(hdc, table, 0, 0, 0);
     207    RefPtr<SharedBuffer> buffer;
     208    if (size != GDI_ERROR) {
     209        buffer = SharedBuffer::create(size);
     210        DWORD result = GetFontData(hdc, table, 0, (PVOID)buffer->data(), size);
     211        ASSERT(result == size);
     212    }
     213
     214    SelectObject(hdc, oldFont);
     215    return buffer.release();
     216}
     217#endif
     218
    194219#ifndef NDEBUG
    195220String FontPlatformData::description() const
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h

    r126312 r126907  
    3636
    3737#include "FontOrientation.h"
     38#include "SharedBuffer.h"
    3839#include "SkTypeface.h"
    3940#include <wtf/Forward.h>
     
    5455
    5556class FontDescription;
     57#if ENABLE(OPENTYPE_VERTICAL)
     58class OpenTypeVerticalData;
     59#endif
    5660
    5761class FontPlatformData {
     
    9296        return m_font == other.m_font && m_size == other.m_size && m_orientation == other.m_orientation;
    9397    }
     98
     99#if ENABLE(OPENTYPE_VERTICAL)
     100    const OpenTypeVerticalData* verticalData() const;
     101    PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
     102#endif
    94103
    95104#ifndef NDEBUG
Note: See TracChangeset for help on using the changeset viewer.