Changeset 166640 in webkit


Ignore:
Timestamp:
Apr 2, 2014 6:01:34 AM (10 years ago)
Author:
fred.wang@free.fr
Message:

Operator stretching: read the Open Type MATH table
https://bugs.webkit.org/show_bug.cgi?id=130324

Reviewed by Chris Fleizach.

Source/WebCore:

We parse and expose some data from the OpenType MATH table that will be
be relevant for at least the MathML operator stretching (bug 130322):
math constants, italic corrections and size variants / glyph assembly.
This will be tested when the MathML code uses the data.

  • WebCore.xcodeproj/project.pbxproj: Add OpenTypeTypes.h to the Mac build.
  • platform/graphics/opentype/OpenTypeMathData.cpp: We implement the low-level parsing of the MATH table.

(WebCore::OpenType::MathItalicsCorrectionInfo::getItalicCorrection):
(WebCore::OpenType::MathGlyphInfo::mathItalicsCorrectionInfo):
(WebCore::OpenType::GlyphAssembly::getAssemblyParts):
(WebCore::OpenType::MathGlyphConstruction::getSizeVariants):
(WebCore::OpenType::MathGlyphConstruction::getAssemblyParts):
(WebCore::OpenType::MathVariants::mathGlyphConstruction):
(WebCore::OpenType::MATHTable::mathConstants):
(WebCore::OpenType::MATHTable::mathGlyphInfo):
(WebCore::OpenType::MATHTable::mathVariants):
(WebCore::OpenTypeMathData::OpenTypeMathData): We load the MATH table.
(WebCore::OpenTypeMathData::getMathConstant): We add a function to get values from the MathConstant subtable.
(WebCore::OpenTypeMathData::getItalicCorrection): We add a function to get italic correction from the MathGlyphInfo subtable.
(WebCore::OpenTypeMathData::getMathVariants): We add a function to get size variants / glyph assembly from the MathVariants subtable.

  • platform/graphics/opentype/OpenTypeMathData.h: We expose three new functions to get math data.
  • platform/graphics/opentype/OpenTypeTypes.h: We share the coverage tables that are common to vertical and math data.

(WebCore::OpenType::TableWithCoverage::getCoverageIndex): We add a function to get the coverage index from a given glyph.

  • platform/graphics/opentype/OpenTypeVerticalData.cpp: We move the coverage tables to OpenTypeTypes.h.

Source/WTF:

  • wtf/Platform.h: enable OPENTYPE_MATH on platforms that can read OpenType tables.
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r166636 r166640  
     12014-04-02  Frédéric Wang  <fred.wang@free.fr>
     2
     3        Operator stretching: read the Open Type MATH table
     4        https://bugs.webkit.org/show_bug.cgi?id=130324
     5
     6        Reviewed by Chris Fleizach.
     7
     8        * wtf/Platform.h: enable OPENTYPE_MATH on platforms that can read OpenType tables.
     9
    1102014-04-02  Alex Christensen  <achristensen@webkit.org>
    211
  • trunk/Source/WTF/wtf/Platform.h

    r166593 r166640  
    10551055#endif
    10561056
     1057#if (OS(DARWIN) && USE(CG)) || USE(FREETYPE) || (PLATFORM(WIN) && (USE(CG) || USE(CAIRO)))
     1058#undef ENABLE_OPENTYPE_MATH
     1059#define ENABLE_OPENTYPE_MATH 1
     1060#endif
     1061
    10571062#endif /* WTF_Platform_h */
  • trunk/Source/WebCore/ChangeLog

    r166634 r166640  
     12014-04-02  Frédéric Wang  <fred.wang@free.fr>
     2
     3        Operator stretching: read the Open Type MATH table
     4        https://bugs.webkit.org/show_bug.cgi?id=130324
     5
     6        Reviewed by Chris Fleizach.
     7
     8        We parse and expose some data from the OpenType MATH table that will be
     9        be relevant for at least the MathML operator stretching (bug 130322):
     10        math constants, italic corrections and size variants / glyph assembly.
     11        This will be tested when the MathML code uses the data.
     12
     13        * WebCore.xcodeproj/project.pbxproj: Add OpenTypeTypes.h to the Mac build.
     14        * platform/graphics/opentype/OpenTypeMathData.cpp: We implement the low-level parsing of the MATH table.
     15        (WebCore::OpenType::MathItalicsCorrectionInfo::getItalicCorrection):
     16        (WebCore::OpenType::MathGlyphInfo::mathItalicsCorrectionInfo):
     17        (WebCore::OpenType::GlyphAssembly::getAssemblyParts):
     18        (WebCore::OpenType::MathGlyphConstruction::getSizeVariants):
     19        (WebCore::OpenType::MathGlyphConstruction::getAssemblyParts):
     20        (WebCore::OpenType::MathVariants::mathGlyphConstruction):
     21        (WebCore::OpenType::MATHTable::mathConstants):
     22        (WebCore::OpenType::MATHTable::mathGlyphInfo):
     23        (WebCore::OpenType::MATHTable::mathVariants):
     24        (WebCore::OpenTypeMathData::OpenTypeMathData): We load the MATH table.
     25        (WebCore::OpenTypeMathData::getMathConstant): We add a function to get values from the MathConstant subtable.
     26        (WebCore::OpenTypeMathData::getItalicCorrection): We add a function to get italic correction from the MathGlyphInfo subtable.
     27        (WebCore::OpenTypeMathData::getMathVariants): We add a function to get size variants / glyph assembly from the MathVariants subtable.
     28        * platform/graphics/opentype/OpenTypeMathData.h: We expose three new functions to get math data.
     29        * platform/graphics/opentype/OpenTypeTypes.h: We share the coverage tables that are common to vertical and math data.
     30        (WebCore::OpenType::TableWithCoverage::getCoverageIndex): We add a function to get the coverage index from a given glyph.
     31        * platform/graphics/opentype/OpenTypeVerticalData.cpp: We move the coverage tables to OpenTypeTypes.h.
     32
    1332014-04-02  Ion Rosca  <rosca@adobe.com>
    234
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r166633 r166640  
    45974597                B2D3DA640D006CD600EF6F27 /* OpenTypeMathData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */; };
    45984598                B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4599                B2D3EA650D006CD600EF6F28 /* OpenTypeTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3EA540D006CD600EF6F28 /* OpenTypeTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
    45994600                B2C3DA660D006CD600EF6F26 /* FontDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = B2C3DA550D006CD600EF6F26 /* FontDescription.h */; settings = {ATTRIBUTES = (Private, ); }; };
    46004601                B2C3DA670D006CD600EF6F26 /* FontGlyphs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2C3DA560D006CD600EF6F26 /* FontGlyphs.cpp */; };
     
    1185311854                B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = opentype/OpenTypeMathData.cpp; sourceTree = "<group>"; };
    1185411855                B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = opentype/OpenTypeMathData.h; sourceTree = "<group>"; };
     11856                B2D3EA540D006CD600EF6F28 /* OpenTypeTypes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = opentype/OpenTypeTypes.h; sourceTree = "<group>"; };
    1185511857                B2C3DA550D006CD600EF6F26 /* FontDescription.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FontDescription.h; sourceTree = "<group>"; };
    1185611858                B2C3DA560D006CD600EF6F26 /* FontGlyphs.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FontGlyphs.cpp; sourceTree = "<group>"; };
     
    2014720149                                B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */,
    2014820150                                B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */,
     20151                                B2D3EA540D006CD600EF6F28 /* OpenTypeTypes.h */,
    2014920152                                CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */,
    2015020153                                CDC61DA0180867D8004B913F /* SourceBufferPrivate.h */,
     
    2549525498                                B2C3DA650D006CD600EF6F26 /* SimpleFontData.h in Headers */,
    2549625499                                B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */,
     25500                                B2D3EA650D006CD600EF6F28 /* OpenTypeTypes.h in Headers */,
    2549725501                                E48944A3180B57D800F165D8 /* SimpleLineLayout.h in Headers */,
    2549825502                                E4E9B11D1814569C003ACCDF /* SimpleLineLayoutFunctions.h in Headers */,
  • trunk/Source/WebCore/platform/graphics/opentype/OpenTypeMathData.cpp

    r166633 r166640  
    2828
    2929#include "FontPlatformData.h"
     30#if ENABLE(OPENTYPE_MATH)
     31#include "OpenTypeTypes.h"
     32#endif
     33#include "SimpleFontData.h"
    3034
    3135using namespace std;
     
    3337namespace WebCore {
    3438
    35 OpenTypeMathData::OpenTypeMathData(const FontPlatformData&)
     39#if ENABLE(OPENTYPE_MATH)
     40namespace OpenType {
     41
     42const uint32_t MATHTag = OT_MAKE_TAG('M', 'A', 'T', 'H');
     43
     44#pragma pack(1)
     45
     46struct MathValueRecord {
     47    OpenType::Int16 value;
     48    OpenType::Offset deviceTableOffset;
     49};
     50
     51struct MathConstants {
     52    OpenType::Int16 intConstants[OpenTypeMathData::ScriptScriptPercentScaleDown - OpenTypeMathData::ScriptPercentScaleDown + 1];
     53    OpenType::UInt16 uIntConstants[OpenTypeMathData::DisplayOperatorMinHeight - OpenTypeMathData::DelimitedSubFormulaMinHeight + 1];
     54    OpenType::MathValueRecord mathValuesConstants[OpenTypeMathData::RadicalKernAfterDegree - OpenTypeMathData::MathLeading + 1];
     55    OpenType::UInt16 radicalDegreeBottomRaisePercent;
     56};
     57
     58struct MathItalicsCorrectionInfo : TableWithCoverage {
     59    OpenType::Offset coverageOffset;
     60    OpenType::UInt16 italicsCorrectionCount;
     61    OpenType::MathValueRecord italicsCorrection[1]; // There are italicsCorrectionCount italic correction values.
     62
     63    int16_t getItalicCorrection(const SharedBuffer& buffer, Glyph glyph) const
     64    {
     65        uint16_t count = uint16_t(italicsCorrectionCount);
     66        if (!isValidEnd(buffer, &italicsCorrection[count]))
     67            return 0;
     68
     69        uint16_t offset = coverageOffset;
     70        if (!offset)
     71            return 0;
     72        const CoverageTable* coverage = validateOffset<CoverageTable>(buffer, offset);
     73        if (!coverage)
     74            return 0;
     75
     76        // We determine the index in the italicsCorrection table.
     77        uint32_t i;
     78        if (!getCoverageIndex(buffer, coverage, glyph, i) || i >= count)
     79            return 0;
     80
     81        return int16_t(italicsCorrection[i].value);
     82    }
     83};
     84
     85struct MathGlyphInfo : TableWithCoverage {
     86    OpenType::Offset mathItalicsCorrectionInfoOffset;
     87    OpenType::Offset mathTopAccentAttachmentOffset;
     88    OpenType::Offset extendedShapeCoverageOffset;
     89    OpenType::Offset mathKernInfoOffset;
     90
     91    const MathItalicsCorrectionInfo* mathItalicsCorrectionInfo(const SharedBuffer& buffer) const
     92    {
     93        uint16_t offset = mathItalicsCorrectionInfoOffset;
     94        if (offset)
     95            return validateOffset<MathItalicsCorrectionInfo>(buffer, offset);
     96        return nullptr;
     97    }
     98};
     99
     100struct GlyphAssembly : TableBase {
     101    OpenType::MathValueRecord italicsCorrection;
     102    OpenType::UInt16 partCount;
     103    struct GlyphPartRecord {
     104        OpenType::GlyphID glyph;
     105        OpenType::UInt16 startConnectorLength;
     106        OpenType::UInt16 endConnectorLength;
     107        OpenType::UInt16 fullAdvance;
     108        OpenType::UInt16 partFlags;
     109    } partRecords[1]; // There are partCount GlyphPartRecord's.
     110
     111    // PartFlags enumeration currently uses only one bit:
     112    // 0x0001 If set, the part can be skipped or repeated.
     113    // 0xFFFE Reserved.
     114    enum {
     115        PartFlagsExtender = 0x01
     116    };
     117
     118    void getAssemblyParts(const SharedBuffer& buffer, Vector<OpenTypeMathData::AssemblyPart>& assemblyParts) const
     119    {
     120        uint16_t count = partCount;
     121        if (!isValidEnd(buffer, &partRecords[count]))
     122            return;
     123        assemblyParts.resize(count);
     124        for (uint16_t i = 0; i < count; i++) {
     125            assemblyParts[i].glyph = partRecords[i].glyph;
     126            uint16_t flag = partRecords[i].partFlags;
     127            assemblyParts[i].isExtender = flag & PartFlagsExtender;
     128        }
     129    }
     130
     131};
     132
     133struct MathGlyphConstruction : TableBase {
     134    OpenType::Offset glyphAssemblyOffset;
     135    OpenType::UInt16 variantCount;
     136    struct MathGlyphVariantRecord {
     137        OpenType::GlyphID variantGlyph;
     138        OpenType::UInt16 advanceMeasurement;
     139    } mathGlyphVariantRecords[1]; // There are variantCount MathGlyphVariantRecord's.
     140
     141    void getSizeVariants(const SharedBuffer& buffer, Vector<Glyph>& variants) const
     142    {
     143        uint16_t count = variantCount;
     144        if (!isValidEnd(buffer, &mathGlyphVariantRecords[count]))
     145            return;
     146        variants.resize(count);
     147        for (uint16_t i = 0; i < count; i++)
     148            variants[i] = mathGlyphVariantRecords[i].variantGlyph;
     149    }
     150
     151    void getAssemblyParts(const SharedBuffer& buffer, Vector<OpenTypeMathData::AssemblyPart>& assemblyParts) const
     152    {
     153        uint16_t offset = glyphAssemblyOffset;
     154        const GlyphAssembly* glyphAssembly = validateOffset<GlyphAssembly>(buffer, offset);
     155        if (glyphAssembly)
     156            glyphAssembly->getAssemblyParts(buffer, assemblyParts);
     157    }
     158};
     159
     160struct MathVariants : TableWithCoverage {
     161    OpenType::UInt16 minConnectorOverlap;
     162    OpenType::Offset verticalGlyphCoverageOffset;
     163    OpenType::Offset horizontalGlyphCoverageOffset;
     164    OpenType::UInt16 verticalGlyphCount;
     165    OpenType::UInt16 horizontalGlyphCount;
     166    OpenType::Offset mathGlyphConstructionsOffset[1]; // There are verticalGlyphCount vertical glyph contructions and horizontalGlyphCount vertical glyph contructions.
     167
     168    const MathGlyphConstruction* mathGlyphConstruction(const SharedBuffer& buffer, Glyph glyph, bool isVertical) const
     169    {
     170        uint32_t count = uint16_t(verticalGlyphCount) + uint16_t(horizontalGlyphCount);
     171        if (!isValidEnd(buffer, &mathGlyphConstructionsOffset[count]))
     172            return nullptr;
     173
     174        // We determine the coverage table for the specified glyph.
     175        uint16_t coverageOffset = isVertical ? verticalGlyphCoverageOffset : horizontalGlyphCoverageOffset;
     176        if (!coverageOffset)
     177            return nullptr;
     178        const CoverageTable* coverage = validateOffset<CoverageTable>(buffer, coverageOffset);
     179        if (!coverage)
     180            return nullptr;
     181
     182        // We determine the index in the mathGlyphConstructionsOffset table.
     183        uint32_t i;
     184        if (!getCoverageIndex(buffer, coverage, glyph, i))
     185            return nullptr;
     186        count = isVertical ? verticalGlyphCount : horizontalGlyphCount;
     187        if (i >= count)
     188            return nullptr;
     189        if (!isVertical)
     190            i += uint16_t(verticalGlyphCount);
     191
     192        return validateOffset<MathGlyphConstruction>(buffer, mathGlyphConstructionsOffset[i]);
     193    }
     194};
     195
     196struct MATHTable : TableBase {
     197    OpenType::Fixed version;
     198    OpenType::Offset mathConstantsOffset;
     199    OpenType::Offset mathGlyphInfoOffset;
     200    OpenType::Offset mathVariantsOffset;
     201
     202    const MathConstants* mathConstants(const SharedBuffer& buffer) const
     203    {
     204        uint16_t offset = mathConstantsOffset;
     205        if (offset)
     206            return validateOffset<MathConstants>(buffer, offset);
     207        return nullptr;
     208    }
     209
     210    const MathGlyphInfo* mathGlyphInfo(const SharedBuffer& buffer) const
     211    {
     212        uint16_t offset = mathGlyphInfoOffset;
     213        if (offset)
     214            return validateOffset<MathGlyphInfo>(buffer, offset);
     215        return nullptr;
     216    }
     217
     218    const MathVariants* mathVariants(const SharedBuffer& buffer) const
     219    {
     220        uint16_t offset = mathVariantsOffset;
     221        if (offset)
     222            return validateOffset<MathVariants>(buffer, offset);
     223        return nullptr;
     224    }
     225};
     226
     227#pragma pack()
     228
     229} // namespace OpenType
     230#endif // ENABLE(OPENTYPE_MATH)
     231
     232OpenTypeMathData::OpenTypeMathData(const FontPlatformData& fontData)
    36233{
    37     // FIXME: We should read the data from the MATH table (https://bugs.webkit.org/show_bug.cgi?id=130324).
     234#if ENABLE(OPENTYPE_MATH)
     235    m_mathBuffer = fontData.openTypeTable(OpenType::MATHTag);
     236    const OpenType::MATHTable* math = OpenType::validateTable<OpenType::MATHTable>(m_mathBuffer);
     237    if (!math) {
     238        m_mathBuffer = nullptr;
     239        return;
     240    }
     241
     242    const OpenType::MathConstants* mathConstants = math->mathConstants(*m_mathBuffer);
     243    if (!mathConstants) {
     244        m_mathBuffer = nullptr;
     245        return;
     246    }
     247
     248    const OpenType::MathVariants* mathVariants = math->mathVariants(*m_mathBuffer);
     249    if (!mathVariants)
     250        m_mathBuffer = nullptr;
     251#else
    38252    m_mathBuffer = nullptr;
     253#endif
    39254}
    40255
     256float OpenTypeMathData::getMathConstant(const SimpleFontData* font, MathConstant constant) const
     257{
     258#if ENABLE(OPENTYPE_MATH)
     259    int32_t value = 0;
     260
     261    const OpenType::MATHTable* math = OpenType::validateTable<OpenType::MATHTable>(m_mathBuffer);
     262    ASSERT(math);
     263    const OpenType::MathConstants* mathConstants = math->mathConstants(*m_mathBuffer);
     264    ASSERT(mathConstants);
     265
     266    if (constant >= 0 && constant <= ScriptScriptPercentScaleDown)
     267        value = int16_t(mathConstants->intConstants[constant]);
     268    else if (constant >= DelimitedSubFormulaMinHeight && constant <= DisplayOperatorMinHeight)
     269        value = uint16_t(mathConstants->uIntConstants[constant - DelimitedSubFormulaMinHeight]);
     270    else if (constant >= MathLeading && constant <= RadicalKernAfterDegree)
     271        value = int16_t(mathConstants->mathValuesConstants[constant - MathLeading].value);
     272    else if (constant == RadicalDegreeBottomRaisePercent)
     273        value = uint16_t(mathConstants->radicalDegreeBottomRaisePercent);
     274
     275    if (constant == ScriptPercentScaleDown || constant == ScriptScriptPercentScaleDown || constant == RadicalDegreeBottomRaisePercent)
     276        return value / 100.0;
     277
     278    return value * font->sizePerUnit();
     279#else
     280    ASSERT_NOT_REACHED();
     281    return 0;
     282#endif
     283}
     284
     285float OpenTypeMathData::getItalicCorrection(const SimpleFontData* font, Glyph glyph) const
     286{
     287#if ENABLE(OPENTYPE_MATH)
     288    const OpenType::MATHTable* math = OpenType::validateTable<OpenType::MATHTable>(m_mathBuffer);
     289    ASSERT(math);
     290    const OpenType::MathGlyphInfo* mathGlyphInfo = math->mathGlyphInfo(*m_mathBuffer);
     291    if (!mathGlyphInfo)
     292        return 0;
     293
     294    const OpenType::MathItalicsCorrectionInfo* mathItalicsCorrectionInfo = mathGlyphInfo->mathItalicsCorrectionInfo(*m_mathBuffer);
     295    if (!mathItalicsCorrectionInfo)
     296        return 0;
     297
     298    return mathItalicsCorrectionInfo->getItalicCorrection(*m_mathBuffer, glyph) * font->sizePerUnit();
     299#else
     300    ASSERT_NOT_REACHED();
     301    return 0;
     302#endif
     303}
     304
     305void OpenTypeMathData::getMathVariants(Glyph glyph, bool isVertical, Vector<Glyph>& sizeVariants, Vector<AssemblyPart>& assemblyParts) const
     306{
     307    sizeVariants.clear();
     308    assemblyParts.clear();
     309#if ENABLE(OPENTYPE_MATH)
     310    const OpenType::MATHTable* math = OpenType::validateTable<OpenType::MATHTable>(m_mathBuffer);
     311    ASSERT(math);
     312    const OpenType::MathVariants* mathVariants = math->mathVariants(*m_mathBuffer);
     313    ASSERT(mathVariants);
     314
     315    const OpenType::MathGlyphConstruction* mathGlyphConstruction = mathVariants->mathGlyphConstruction(*m_mathBuffer, glyph, isVertical);
     316    if (!mathGlyphConstruction)
     317        return;
     318
     319    mathGlyphConstruction->getSizeVariants(*m_mathBuffer, sizeVariants);
     320    mathGlyphConstruction->getAssemblyParts(*m_mathBuffer, assemblyParts);
     321#else
     322    ASSERT_NOT_REACHED();
     323#endif
     324}
     325
    41326} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/opentype/OpenTypeMathData.h

    r166633 r166640  
    2727#define OpenTypeMathData_h
    2828
     29#include "Glyph.h"
    2930#include "SharedBuffer.h"
    3031#include <wtf/PassRefPtr.h>
    3132#include <wtf/RefCounted.h>
     33#include <wtf/Vector.h>
    3234
    3335namespace WebCore {
    3436
     37class SimpleFontData;
    3538class FontPlatformData;
    3639
     
    4447    bool hasMathData() const { return m_mathBuffer; }
    4548
     49    // These constants are defined in the MATH table.
     50    // The implementation of OpenTypeMathData::getMathConstant assumes that they correspond to the indices of the MathContant table.
     51    enum MathConstant {
     52        ScriptPercentScaleDown,
     53        ScriptScriptPercentScaleDown,
     54        DelimitedSubFormulaMinHeight,
     55        DisplayOperatorMinHeight,
     56        MathLeading,
     57        AxisHeight,
     58        AccentBaseHeight,
     59        FlattenedAccentBaseHeight,
     60        SubscriptShiftDown,
     61        SubscriptTopMax,
     62        SubscriptBaselineDropMin,
     63        SuperscriptShiftUp,
     64        SuperscriptShiftUpCramped,
     65        SuperscriptBottomMin,
     66        SuperscriptBaselineDropMax,
     67        SubSuperscriptGapMin,
     68        SuperscriptBottomMaxWithSubscript,
     69        SpaceAfterScript,
     70        UpperLimitGapMin,
     71        UpperLimitBaselineRiseMin,
     72        LowerLimitGapMin,
     73        LowerLimitBaselineDropMin,
     74        StackTopShiftUp,
     75        StackTopDisplayStyleShiftUp,
     76        StackBottomShiftDown,
     77        StackBottomDisplayStyleShiftDown,
     78        StackGapMin,
     79        StackDisplayStyleGapMin,
     80        StretchStackTopShiftUp,
     81        StretchStackBottomShiftDown,
     82        StretchStackGapAboveMin,
     83        StretchStackGapBelowMin,
     84        FractionNumeratorShiftUp,
     85        FractionNumeratorDisplayStyleShiftUp,
     86        FractionDenominatorShiftDown,
     87        FractionDenominatorDisplayStyleShiftDown,
     88        FractionNumeratorGapMin,
     89        FractionNumDisplayStyleGapMin,
     90        FractionRuleThickness,
     91        FractionDenominatorGapMin,
     92        FractionDenomDisplayStyleGapMin,
     93        SkewedFractionHorizontalGap,
     94        SkewedFractionVerticalGap,
     95        OverbarVerticalGap,
     96        OverbarRuleThickness,
     97        OverbarExtraAscender,
     98        UnderbarVerticalGap,
     99        UnderbarRuleThickness,
     100        UnderbarExtraDescender,
     101        RadicalVerticalGap,
     102        RadicalDisplayStyleVerticalGap,
     103        RadicalRuleThickness,
     104        RadicalExtraAscender,
     105        RadicalKernBeforeDegree,
     106        RadicalKernAfterDegree,
     107        RadicalDegreeBottomRaisePercent
     108    };
     109
     110    struct AssemblyPart {
     111        Glyph glyph;
     112        bool isExtender;
     113    };
     114
     115    float getMathConstant(const SimpleFontData*, MathConstant) const;
     116    float getItalicCorrection(const SimpleFontData*, Glyph) const;
     117    void getMathVariants(Glyph, bool isVertical, Vector<Glyph>& sizeVariants, Vector<AssemblyPart>& assemblyParts) const;
     118
    46119private:
    47120    explicit OpenTypeMathData(const FontPlatformData&);
  • trunk/Source/WebCore/platform/graphics/opentype/OpenTypeTypes.h

    r127355 r166640  
    101101};
    102102
     103#if ENABLE(OPENTYPE_VERTICAL) || ENABLE(OPENTYPE_MATH)
     104struct CoverageTable : TableBase {
     105    OpenType::UInt16 coverageFormat;
     106};
     107
     108struct Coverage1Table : CoverageTable {
     109    OpenType::UInt16 glyphCount;
     110    OpenType::GlyphID glyphArray[1];
     111};
     112
     113struct Coverage2Table : CoverageTable {
     114    OpenType::UInt16 rangeCount;
     115    struct RangeRecord {
     116        OpenType::GlyphID start;
     117        OpenType::GlyphID end;
     118        OpenType::UInt16 startCoverageIndex;
     119    } ranges[1];
     120};
     121#endif // ENABLE(OPENTYPE_VERTICAL) || ENABLE(OPENTYPE_MATH)
     122
     123#if ENABLE(OPENTYPE_MATH)
     124struct TableWithCoverage : TableBase {
     125protected:
     126    bool getCoverageIndex(const SharedBuffer& buffer, const CoverageTable* coverage, Glyph glyph, uint32_t& coverageIndex) const
     127    {
     128        switch (coverage->coverageFormat) {
     129        case 1: { // Coverage Format 1
     130            const Coverage1Table* coverage1 = validatePtr<Coverage1Table>(buffer, coverage);
     131            if (!coverage1)
     132                return false;
     133            uint16_t glyphCount = coverage1->glyphCount;
     134            if (!isValidEnd(buffer, &coverage1->glyphArray[glyphCount]))
     135                return false;
     136
     137            // We do a binary search on the glyph indexes.
     138            uint32_t imin = 0, imax = glyphCount;
     139            while (imin < imax) {
     140                uint32_t imid = (imin + imax) >> 1;
     141                uint16_t glyphMid = coverage1->glyphArray[imid];
     142                if (glyphMid == glyph) {
     143                    coverageIndex = imid;
     144                    return true;
     145                }
     146                if (glyphMid < glyph)
     147                    imin = imid + 1;
     148                else
     149                    imax = imid;
     150            }
     151            break;
     152        }
     153        case 2: { // Coverage Format 2
     154            const Coverage2Table* coverage2 = validatePtr<Coverage2Table>(buffer, coverage);
     155            if (!coverage2)
     156                return false;
     157            uint16_t rangeCount = coverage2->rangeCount;
     158            if (!isValidEnd(buffer, &coverage2->ranges[rangeCount]))
     159                return false;
     160
     161            // We do a binary search on the ranges.
     162            uint32_t imin = 0, imax = rangeCount;
     163            while (imin < imax) {
     164                uint32_t imid = (imin + imax) >> 1;
     165                uint16_t rStart = coverage2->ranges[imid].start;
     166                uint16_t rEnd = coverage2->ranges[imid].end;
     167                if (rEnd < glyph)
     168                    imin = imid + 1;
     169                else if (glyph < rStart)
     170                    imax = imid;
     171                else {
     172                    coverageIndex = coverage2->ranges[imid].startCoverageIndex + glyph - rStart;
     173                    return true;
     174                }
     175            }
     176            break;
     177        }
     178        }
     179        return false;
     180    }
     181};
     182#endif
     183
    103184} // namespace OpenType
    104185} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.cpp

    r142810 r166640  
    111111
    112112    size_t requiredSize() const { return sizeof(*this) + sizeof(VertOriginYMetrics) * (numVertOriginYMetrics - 1); }
    113 };
    114 
    115 struct CoverageTable : TableBase {
    116     OpenType::UInt16 coverageFormat;
    117 };
    118 
    119 struct Coverage1Table : CoverageTable {
    120     OpenType::UInt16 glyphCount;
    121     OpenType::GlyphID glyphArray[1];
    122 };
    123 
    124 struct Coverage2Table : CoverageTable {
    125     OpenType::UInt16 rangeCount;
    126     struct RangeRecord {
    127         OpenType::GlyphID start;
    128         OpenType::GlyphID end;
    129         OpenType::UInt16 startCoverageIndex;
    130     } ranges[1];
    131113};
    132114
Note: See TracChangeset for help on using the changeset viewer.