Changeset 112642 in webkit


Ignore:
Timestamp:
Mar 29, 2012 8:44:14 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Vertical flow support for OpenType fonts with the least platform dependencies
https://bugs.webkit.org/show_bug.cgi?id=81326

Patch by Koji Ishii <Koji Ishii> on 2012-03-29
Reviewed by Dan Bernstein.

This patch introduces a new class OpenTypeVerticalData to read
vertical font metrics from OpenType fonts.

Currently, WebKit relies on platform APIs to do the work. However,
some platforms such as Windows lack support for all the capabilities
WebKit requires for vertical flow and the text-orientation property
to work correctly. Reading OpenType tables directly also gives
benefits in consistent behavior among the WebKit platforms.

This patch is for any platforms that want to parse OpenType tables
directly, but it's currently included only in CGWin and isn't on any
code path even on CGWin yet. Caller's side change for CGWin and
support for other platforms will be in separate bugs.

No new tests are required. No behavior changes.

  • WebCore.vcproj/WebCore.vcproj: Added OpenTypeTypes.h and OpenTypeVerticalData.h/cpp.
  • platform/SharedBuffer.cpp: Add create(size_t)

(WebCore::SharedBuffer::SharedBuffer):
(WebCore):

  • platform/SharedBuffer.h: Add create(size_t)

(WebCore::SharedBuffer::create):
(SharedBuffer):

  • platform/graphics/FontPlatformData.h: Added openTypeTable().

(WebCore):
(FontPlatformData):

  • platform/graphics/SimpleFontData.h: Added sizePerUnit().

(WebCore::SimpleFontData::sizePerUnit): size() / unitsPerEm() for less multiplication.

  • platform/graphics/opentype/OpenTypeTypes.h: Added OpenType basic type definitions.

(OpenType):
(WebCore::OpenType::BigEndianShort::operator short):
(WebCore::OpenType::BigEndianShort::BigEndianShort):
(BigEndianShort):
(WebCore::OpenType::BigEndianUShort::operator unsigned short):
(WebCore::OpenType::BigEndianUShort::BigEndianUShort):
(BigEndianUShort):
(WebCore::OpenType::BigEndianLong::operator int):
(WebCore::OpenType::BigEndianLong::BigEndianLong):
(BigEndianLong):
(WebCore::OpenType::BigEndianULong::operator unsigned):
(WebCore::OpenType::BigEndianULong::BigEndianULong):
(BigEndianULong):

  • platform/graphics/opentype/OpenTypeVerticalData.cpp: Added.

(OpenType):
(HheaTable):
(VheaTable):
(Entry):
(VORGTable):
(VertOriginYMetrics):
(WebCore::OpenType::VORGTable::requiredSize):
(WebCore):
(WebCore::validatedPtr):
(WebCore::OpenTypeVerticalData::OpenTypeVerticalData):
(WebCore::OpenTypeVerticalData::advanceHeight): Advance height for a glyph.
(WebCore::OpenTypeVerticalData::getVerticalTranslationsForGlyphs): Vertical origin.

  • platform/graphics/opentype/OpenTypeVerticalData.h: Added.

(WebCore):
(OpenTypeVerticalData): A new class to handle vertical flow data in OpenType.
(WebCore::OpenTypeVerticalData::isOpenType):
(WebCore::OpenTypeVerticalData::hasVerticalMetrics):
(WebCore::OpenTypeVerticalData::hasVORG):

  • platform/graphics/win/FontPlatformDataWin.cpp:

(WebCore):
(WebCore::FontPlatformData::openTypeTable): Implemented openTypeTable() for Win32.

Location:
trunk/Source/WebCore
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r112641 r112642  
     12012-03-29  Koji Ishii  <kojiishi@gmail.com>
     2
     3
     4        Vertical flow support for OpenType fonts with the least platform dependencies
     5        https://bugs.webkit.org/show_bug.cgi?id=81326
     6
     7        Reviewed by Dan Bernstein.
     8
     9        This patch introduces a new class OpenTypeVerticalData to read
     10        vertical font metrics from OpenType fonts.
     11
     12        Currently, WebKit relies on platform APIs to do the work. However,
     13        some platforms such as Windows lack support for all the capabilities
     14        WebKit requires for vertical flow and the text-orientation property
     15        to work correctly. Reading OpenType tables directly also gives
     16        benefits in consistent behavior among the WebKit platforms.
     17
     18        This patch is for any platforms that want to parse OpenType tables
     19        directly, but it's currently included only in CGWin and isn't on any
     20        code path even on CGWin yet. Caller's side change for CGWin and
     21        support for other platforms will be in separate bugs.
     22
     23        No new tests are required. No behavior changes.
     24
     25        * WebCore.vcproj/WebCore.vcproj: Added OpenTypeTypes.h and OpenTypeVerticalData.h/cpp.
     26        * platform/SharedBuffer.cpp: Add create(size_t)
     27        (WebCore::SharedBuffer::SharedBuffer):
     28        (WebCore):
     29        * platform/SharedBuffer.h: Add create(size_t)
     30        (WebCore::SharedBuffer::create):
     31        (SharedBuffer):
     32        * platform/graphics/FontPlatformData.h: Added openTypeTable().
     33        (WebCore):
     34        (FontPlatformData):
     35        * platform/graphics/SimpleFontData.h: Added sizePerUnit().
     36        (WebCore::SimpleFontData::sizePerUnit): size() / unitsPerEm() for less multiplication.
     37        * platform/graphics/opentype/OpenTypeTypes.h: Added OpenType basic type definitions.
     38        (OpenType):
     39        (WebCore::OpenType::BigEndianShort::operator short):
     40        (WebCore::OpenType::BigEndianShort::BigEndianShort):
     41        (BigEndianShort):
     42        (WebCore::OpenType::BigEndianUShort::operator unsigned short):
     43        (WebCore::OpenType::BigEndianUShort::BigEndianUShort):
     44        (BigEndianUShort):
     45        (WebCore::OpenType::BigEndianLong::operator int):
     46        (WebCore::OpenType::BigEndianLong::BigEndianLong):
     47        (BigEndianLong):
     48        (WebCore::OpenType::BigEndianULong::operator unsigned):
     49        (WebCore::OpenType::BigEndianULong::BigEndianULong):
     50        (BigEndianULong):
     51        * platform/graphics/opentype/OpenTypeVerticalData.cpp: Added.
     52        (OpenType):
     53        (HheaTable):
     54        (VheaTable):
     55        (Entry):
     56        (VORGTable):
     57        (VertOriginYMetrics):
     58        (WebCore::OpenType::VORGTable::requiredSize):
     59        (WebCore):
     60        (WebCore::validatedPtr):
     61        (WebCore::OpenTypeVerticalData::OpenTypeVerticalData):
     62        (WebCore::OpenTypeVerticalData::advanceHeight): Advance height for a glyph.
     63        (WebCore::OpenTypeVerticalData::getVerticalTranslationsForGlyphs): Vertical origin.
     64        * platform/graphics/opentype/OpenTypeVerticalData.h: Added.
     65        (WebCore):
     66        (OpenTypeVerticalData): A new class to handle vertical flow data in OpenType.
     67        (WebCore::OpenTypeVerticalData::isOpenType):
     68        (WebCore::OpenTypeVerticalData::hasVerticalMetrics):
     69        (WebCore::OpenTypeVerticalData::hasVORG):
     70        * platform/graphics/win/FontPlatformDataWin.cpp:
     71        (WebCore):
     72        (WebCore::FontPlatformData::openTypeTable): Implemented openTypeTable() for Win32.
     73
    1742012-03-29  Leo Yang  <leo.yang@torchmobile.com.cn>
    275
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r112490 r112642  
    2926129261                                        </File>
    2926229262                                        <File
     29263                                                RelativePath="..\platform\graphics\opentype\OpenTypeTypes.h"
     29264                                                >
     29265                                        </File>
     29266                                        <File
    2926329267                                                RelativePath="..\platform\graphics\opentype\OpenTypeUtilities.cpp"
    2926429268                                                >
     
    2926629270                                        <File
    2926729271                                                RelativePath="..\platform\graphics\opentype\OpenTypeUtilities.h"
     29272                                                >
     29273                                        </File>
     29274                                        <File
     29275                                                RelativePath="..\platform\graphics\opentype\OpenTypeVerticalData.cpp"
     29276                                                >
     29277                                        </File>
     29278                                        <File
     29279                                                RelativePath="..\platform\graphics\opentype\OpenTypeVerticalData.h"
    2926829280                                                >
    2926929281                                        </File>
  • trunk/Source/WebCore/platform/SharedBuffer.cpp

    r109132 r112642  
    6363}
    6464
     65SharedBuffer::SharedBuffer(size_t size)
     66    : m_size(size)
     67    , m_buffer(size)
     68{
     69}
     70
    6571SharedBuffer::SharedBuffer(const char* data, int size)
    6672    : m_size(0)
  • trunk/Source/WebCore/platform/SharedBuffer.h

    r107648 r112642  
    4949public:
    5050    static PassRefPtr<SharedBuffer> create() { return adoptRef(new SharedBuffer); }
     51    static PassRefPtr<SharedBuffer> create(size_t size) { return adoptRef(new SharedBuffer(size)); }
    5152    static PassRefPtr<SharedBuffer> create(const char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
    5253    static PassRefPtr<SharedBuffer> create(const unsigned char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
     
    116117private:
    117118    SharedBuffer();
     119    SharedBuffer(size_t);
    118120    SharedBuffer(const char*, int);
    119121    SharedBuffer(const unsigned char*, int);
  • trunk/Source/WebCore/platform/graphics/FontPlatformData.h

    r110910 r112642  
    9292
    9393class FontDescription;
     94class SharedBuffer;
    9495
    9596#if OS(DARWIN)
     
    277278    }
    278279
     280#if PLATFORM(WIN) && USE(CG)
     281    PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
     282#endif
    279283
    280284#ifndef NDEBUG
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r104545 r112642  
    119119    FontMetrics& fontMetrics() { return m_fontMetrics; }
    120120    const FontMetrics& fontMetrics() const { return m_fontMetrics; }
     121    float sizePerUnit() const { return platformData().size() / (fontMetrics().unitsPerEm() ? fontMetrics().unitsPerEm() : 1); }
    121122   
    122123    float maxCharWidth() const { return m_maxCharWidth; }
  • trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp

    r105661 r112642  
    2828#include "HWndDC.h"
    2929#include "PlatformString.h"
     30#include "SharedBuffer.h"
    3031#include <wtf/HashMap.h>
    3132#include <wtf/RetainPtr.h>
     
    7576}
    7677
     78#if USE(CG)
     79PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
     80{
     81    HWndDC hdc(0);
     82    HGDIOBJ oldFont = SelectObject(hdc, hfont());
     83
     84    DWORD size = GetFontData(hdc, table, 0, 0, 0);
     85    RefPtr<SharedBuffer> buffer;
     86    if (size != GDI_ERROR) {
     87        buffer = SharedBuffer::create(size);
     88        DWORD result = GetFontData(hdc, table, 0, (PVOID)buffer->data(), size);
     89        ASSERT(result == size);
     90    }
     91
     92    SelectObject(hdc, oldFont);
     93    return buffer.release();
     94}
     95#endif
     96
    7797#ifndef NDEBUG
    7898String FontPlatformData::description() const
Note: See TracChangeset for help on using the changeset viewer.