Changeset 166640 in webkit
- Timestamp:
- Apr 2, 2014 6:01:34 AM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r166636 r166640 1 2014-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 1 10 2014-04-02 Alex Christensen <achristensen@webkit.org> 2 11 -
trunk/Source/WTF/wtf/Platform.h
r166593 r166640 1055 1055 #endif 1056 1056 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 1057 1062 #endif /* WTF_Platform_h */ -
trunk/Source/WebCore/ChangeLog
r166634 r166640 1 2014-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 1 33 2014-04-02 Ion Rosca <rosca@adobe.com> 2 34 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r166633 r166640 4597 4597 B2D3DA640D006CD600EF6F27 /* OpenTypeMathData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */; }; 4598 4598 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, ); }; }; 4599 4600 B2C3DA660D006CD600EF6F26 /* FontDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = B2C3DA550D006CD600EF6F26 /* FontDescription.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4600 4601 B2C3DA670D006CD600EF6F26 /* FontGlyphs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2C3DA560D006CD600EF6F26 /* FontGlyphs.cpp */; }; … … 11853 11854 B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = opentype/OpenTypeMathData.cpp; sourceTree = "<group>"; }; 11854 11855 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>"; }; 11855 11857 B2C3DA550D006CD600EF6F26 /* FontDescription.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FontDescription.h; sourceTree = "<group>"; }; 11856 11858 B2C3DA560D006CD600EF6F26 /* FontGlyphs.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FontGlyphs.cpp; sourceTree = "<group>"; }; … … 20147 20149 B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */, 20148 20150 B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */, 20151 B2D3EA540D006CD600EF6F28 /* OpenTypeTypes.h */, 20149 20152 CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */, 20150 20153 CDC61DA0180867D8004B913F /* SourceBufferPrivate.h */, … … 25495 25498 B2C3DA650D006CD600EF6F26 /* SimpleFontData.h in Headers */, 25496 25499 B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */, 25500 B2D3EA650D006CD600EF6F28 /* OpenTypeTypes.h in Headers */, 25497 25501 E48944A3180B57D800F165D8 /* SimpleLineLayout.h in Headers */, 25498 25502 E4E9B11D1814569C003ACCDF /* SimpleLineLayoutFunctions.h in Headers */, -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeMathData.cpp
r166633 r166640 28 28 29 29 #include "FontPlatformData.h" 30 #if ENABLE(OPENTYPE_MATH) 31 #include "OpenTypeTypes.h" 32 #endif 33 #include "SimpleFontData.h" 30 34 31 35 using namespace std; … … 33 37 namespace WebCore { 34 38 35 OpenTypeMathData::OpenTypeMathData(const FontPlatformData&) 39 #if ENABLE(OPENTYPE_MATH) 40 namespace OpenType { 41 42 const uint32_t MATHTag = OT_MAKE_TAG('M', 'A', 'T', 'H'); 43 44 #pragma pack(1) 45 46 struct MathValueRecord { 47 OpenType::Int16 value; 48 OpenType::Offset deviceTableOffset; 49 }; 50 51 struct 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 58 struct 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 85 struct 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 100 struct 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 133 struct 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 160 struct 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 196 struct 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 232 OpenTypeMathData::OpenTypeMathData(const FontPlatformData& fontData) 36 233 { 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 38 252 m_mathBuffer = nullptr; 253 #endif 39 254 } 40 255 256 float 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 285 float 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 305 void 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 41 326 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeMathData.h
r166633 r166640 27 27 #define OpenTypeMathData_h 28 28 29 #include "Glyph.h" 29 30 #include "SharedBuffer.h" 30 31 #include <wtf/PassRefPtr.h> 31 32 #include <wtf/RefCounted.h> 33 #include <wtf/Vector.h> 32 34 33 35 namespace WebCore { 34 36 37 class SimpleFontData; 35 38 class FontPlatformData; 36 39 … … 44 47 bool hasMathData() const { return m_mathBuffer; } 45 48 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 46 119 private: 47 120 explicit OpenTypeMathData(const FontPlatformData&); -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeTypes.h
r127355 r166640 101 101 }; 102 102 103 #if ENABLE(OPENTYPE_VERTICAL) || ENABLE(OPENTYPE_MATH) 104 struct CoverageTable : TableBase { 105 OpenType::UInt16 coverageFormat; 106 }; 107 108 struct Coverage1Table : CoverageTable { 109 OpenType::UInt16 glyphCount; 110 OpenType::GlyphID glyphArray[1]; 111 }; 112 113 struct 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) 124 struct TableWithCoverage : TableBase { 125 protected: 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 103 184 } // namespace OpenType 104 185 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.cpp
r142810 r166640 111 111 112 112 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];131 113 }; 132 114
Note: See TracChangeset
for help on using the changeset viewer.