Changeset 178578 in webkit


Ignore:
Timestamp:
Jan 16, 2015, 8:07:46 AM (10 years ago)
Author:
Antti Koivisto
Message:

Correct naming for FontCascade implementation files
https://bugs.webkit.org/show_bug.cgi?id=140544

Reviewed by Zalan Bujtas.

Also reduce their number.

Merge FontFastPath.cpp into FontCascade.cpp
Merge FontMac.mm and FontComplexTextMac.cpp into FontCascadeCocoa.mm

  • CMakeLists.txt:
  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::getEmphasisMarkGlyphData):
(WebCore::FontCascade::emphasisMarkAscent):
(WebCore::FontCascade::emphasisMarkDescent):
(WebCore::FontCascade::emphasisMarkHeight):
(WebCore::FontCascade::getGlyphsAndAdvancesForSimpleText):
(WebCore::FontCascade::drawSimpleText):
(WebCore::FontCascade::drawEmphasisMarksForSimpleText):
(WebCore::FontCascade::drawGlyphBuffer):
(WebCore::offsetToMiddleOfGlyph):
(WebCore::offsetToMiddleOfGlyphAtIndex):
(WebCore::FontCascade::drawEmphasisMarks):
(WebCore::FontCascade::floatWidthForSimpleText):
(WebCore::FontCascade::adjustSelectionRectForSimpleText):
(WebCore::FontCascade::offsetForPositionForSimpleText):

  • platform/graphics/FontFastPath.cpp: Removed.
  • platform/graphics/cocoa/FontCascadeCocoa.mm: Copied from Source/WebCore/platform/graphics/mac/FontMac.mm.

(WebCore::FontCascade::drawGlyphs):
(WebCore::FontCascade::adjustSelectionRectForComplexText):
(WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
(WebCore::FontCascade::drawComplexText):
(WebCore::FontCascade::drawEmphasisMarksForComplexText):
(WebCore::FontCascade::floatWidthForComplexText):
(WebCore::FontCascade::offsetForPositionForComplexText):
(WebCore::FontCascade::fontDataForCombiningCharacterSequence):

  • platform/graphics/mac/FontComplexTextMac.cpp: Removed.
  • platform/graphics/mac/FontMac.mm: Removed.
Location:
trunk/Source/WebCore
Files:
2 deleted
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r178510 r178578  
    20532053    platform/graphics/FontCascade.cpp
    20542054    platform/graphics/FontDescription.cpp
    2055     platform/graphics/FontFastPath.cpp
    20562055    platform/graphics/FontFeatureSettings.cpp
    20572056    platform/graphics/FontGenericFamilies.cpp
  • trunk/Source/WebCore/ChangeLog

    r178577 r178578  
     12015-01-16  Antti Koivisto  <antti@apple.com>
     2
     3        Correct naming for FontCascade implementation files
     4        https://bugs.webkit.org/show_bug.cgi?id=140544
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Also reduce their number.
     9
     10        Merge FontFastPath.cpp into FontCascade.cpp
     11        Merge FontMac.mm and FontComplexTextMac.cpp into FontCascadeCocoa.mm
     12
     13        * CMakeLists.txt:
     14        * WebCore.vcxproj/WebCore.vcxproj:
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * platform/graphics/FontCascade.cpp:
     17        (WebCore::FontCascade::getEmphasisMarkGlyphData):
     18        (WebCore::FontCascade::emphasisMarkAscent):
     19        (WebCore::FontCascade::emphasisMarkDescent):
     20        (WebCore::FontCascade::emphasisMarkHeight):
     21        (WebCore::FontCascade::getGlyphsAndAdvancesForSimpleText):
     22        (WebCore::FontCascade::drawSimpleText):
     23        (WebCore::FontCascade::drawEmphasisMarksForSimpleText):
     24        (WebCore::FontCascade::drawGlyphBuffer):
     25        (WebCore::offsetToMiddleOfGlyph):
     26        (WebCore::offsetToMiddleOfGlyphAtIndex):
     27        (WebCore::FontCascade::drawEmphasisMarks):
     28        (WebCore::FontCascade::floatWidthForSimpleText):
     29        (WebCore::FontCascade::adjustSelectionRectForSimpleText):
     30        (WebCore::FontCascade::offsetForPositionForSimpleText):
     31        * platform/graphics/FontFastPath.cpp: Removed.
     32        * platform/graphics/cocoa/FontCascadeCocoa.mm: Copied from Source/WebCore/platform/graphics/mac/FontMac.mm.
     33        (WebCore::FontCascade::drawGlyphs):
     34        (WebCore::FontCascade::adjustSelectionRectForComplexText):
     35        (WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
     36        (WebCore::FontCascade::drawComplexText):
     37        (WebCore::FontCascade::drawEmphasisMarksForComplexText):
     38        (WebCore::FontCascade::floatWidthForComplexText):
     39        (WebCore::FontCascade::offsetForPositionForComplexText):
     40        (WebCore::FontCascade::fontDataForCombiningCharacterSequence):
     41        * platform/graphics/mac/FontComplexTextMac.cpp: Removed.
     42        * platform/graphics/mac/FontMac.mm: Removed.
     43
    1442014-11-26  Sergio Villar Senin  <svillar@igalia.com>
    245
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r178545 r178578  
    79847984    <ClCompile Include="..\platform\graphics\FontGenericFamilies.cpp" />
    79857985    <ClCompile Include="..\platform\graphics\FontGlyphs.cpp" />
    7986     <ClCompile Include="..\platform\graphics\FontFastPath.cpp" />
    79877986    <ClCompile Include="..\platform\graphics\FontFeatureSettings.cpp" />
    79887987    <ClCompile Include="..\platform\graphics\FontPlatformData.cpp" />
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r178545 r178578  
    13881388                37ACCF690DA414E70089E602 /* FontDescription.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37ACCE620DA2AA960089E602 /* FontDescription.cpp */; };
    13891389                37BAAE581980D1DD005DFE71 /* ProtectionSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = 37BAAE571980D1DD005DFE71 /* ProtectionSpace.h */; settings = {ATTRIBUTES = (Private, ); }; };
    1390                 37C2360B1097EDED00EF9F72 /* FontComplexTextMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C2360A1097EDED00EF9F72 /* FontComplexTextMac.cpp */; };
    13911390                37C236101097EE7700EF9F72 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C2360E1097EE7700EF9F72 /* ComplexTextController.cpp */; };
    13921391                37C236111097EE7700EF9F72 /* ComplexTextController.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C2360F1097EE7700EF9F72 /* ComplexTextController.h */; };
     
    23402339                724ED3311A3A8B2300F5F13C /* JSEXTBlendMinMax.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 724ED32F1A3A8B2300F5F13C /* JSEXTBlendMinMax.cpp */; };
    23412340                724ED3321A3A8B2300F5F13C /* JSEXTBlendMinMax.h in Headers */ = {isa = PBXBuildFile; fileRef = 724ED3301A3A8B2300F5F13C /* JSEXTBlendMinMax.h */; };
    2342                 72626E020EF022FE00A07E20 /* FontFastPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 72626E010EF022FE00A07E20 /* FontFastPath.cpp */; };
    23432341                727AFED41A2EA6AE000442E8 /* EXTsRGB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 727AFED11A2EA6A0000442E8 /* EXTsRGB.cpp */; };
    23442342                72E417631A2E8D2F004C562A /* JSEXTsRGB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 72E417611A2E8D2F004C562A /* JSEXTsRGB.cpp */; };
     
    46714669                B2AFFC7E0D00A5C10030074D /* FontCustomPlatformData.h in Headers */ = {isa = PBXBuildFile; fileRef = B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */; };
    46724670                B2AFFC7F0D00A5C10030074D /* SimpleFontDataMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2AFFC770D00A5C10030074D /* SimpleFontDataMac.mm */; };
    4673                 B2AFFC800D00A5C10030074D /* FontMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2AFFC780D00A5C10030074D /* FontMac.mm */; };
     4671                B2AFFC800D00A5C10030074D /* FontCascadeCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2AFFC780D00A5C10030074D /* FontCascadeCocoa.mm */; };
    46744672                B2AFFC830D00A5C10030074D /* GlyphPageMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2AFFC7B0D00A5C10030074D /* GlyphPageMac.cpp */; };
    46754673                B2AFFC970D00A5DF0030074D /* TextBoundaries.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2AFFC8C0D00A5DF0030074D /* TextBoundaries.mm */; };
     
    84318429                37ACCE620DA2AA960089E602 /* FontDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontDescription.cpp; sourceTree = "<group>"; };
    84328430                37BAAE571980D1DD005DFE71 /* ProtectionSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtectionSpace.h; sourceTree = "<group>"; };
    8433                 37C2360A1097EDED00EF9F72 /* FontComplexTextMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontComplexTextMac.cpp; sourceTree = "<group>"; };
    84348431                37C2360E1097EE7700EF9F72 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; };
    84358432                37C2360F1097EE7700EF9F72 /* ComplexTextController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComplexTextController.h; sourceTree = "<group>"; };
     
    94789475                724ED32F1A3A8B2300F5F13C /* JSEXTBlendMinMax.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSEXTBlendMinMax.cpp; sourceTree = "<group>"; };
    94799476                724ED3301A3A8B2300F5F13C /* JSEXTBlendMinMax.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEXTBlendMinMax.h; sourceTree = "<group>"; };
    9480                 72626E010EF022FE00A07E20 /* FontFastPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFastPath.cpp; sourceTree = "<group>"; };
    94819477                727AFED11A2EA6A0000442E8 /* EXTsRGB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = EXTsRGB.cpp; path = canvas/EXTsRGB.cpp; sourceTree = "<group>"; };
    94829478                727AFED21A2EA6A0000442E8 /* EXTsRGB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EXTsRGB.h; path = canvas/EXTsRGB.h; sourceTree = "<group>"; };
     
    1204512041                B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FontCustomPlatformData.h; sourceTree = "<group>"; };
    1204612042                B2AFFC770D00A5C10030074D /* SimpleFontDataMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = SimpleFontDataMac.mm; sourceTree = "<group>"; };
    12047                 B2AFFC780D00A5C10030074D /* FontMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = FontMac.mm; sourceTree = "<group>"; };
     12043                B2AFFC780D00A5C10030074D /* FontCascadeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = FontCascadeCocoa.mm; sourceTree = "<group>"; };
    1204812044                B2AFFC7B0D00A5C10030074D /* GlyphPageMac.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = GlyphPageMac.cpp; sourceTree = "<group>"; };
    1204912045                B2AFFC850D00A5DF0030074D /* character-sets.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = "character-sets.txt"; sourceTree = "<group>"; };
     
    2036320359                                B275354D0B053814002CE64F /* FloatSizeMac.mm */,
    2036420360                                B2AFFC740D00A5C10030074D /* FontCacheMac.mm */,
    20365                                 37C2360A1097EDED00EF9F72 /* FontComplexTextMac.cpp */,
    2036620361                                B2AFFC750D00A5C10030074D /* FontCustomPlatformData.cpp */,
    2036720362                                B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */,
    20368                                 B2AFFC780D00A5C10030074D /* FontMac.mm */,
    2036920363                                B2AFFC7B0D00A5C10030074D /* GlyphPageMac.cpp */,
    2037020364                                49FFBF1C11C8550E006A7118 /* GraphicsContext3DMac.mm */,
     
    2044720441                                37ACCE620DA2AA960089E602 /* FontDescription.cpp */,
    2044820442                                B2C3DA550D006CD600EF6F26 /* FontDescription.h */,
    20449                                 72626E010EF022FE00A07E20 /* FontFastPath.cpp */,
    2045020443                                4A6E9FC513C17D570046A7F8 /* FontFeatureSettings.cpp */,
    2045120444                                4A6E9FC613C17D570046A7F8 /* FontFeatureSettings.h */,
     
    2071520708                        isa = PBXGroup;
    2071620709                        children = (
     20710                                B2AFFC780D00A5C10030074D /* FontCascadeCocoa.mm */,
    2071720711                                B5320D6A122A24E9002D1440 /* FontPlatformDataCocoa.mm */,
    2071820712                                2D0B4AA918DA1CCD00434DE1 /* IOSurface.h */,
     
    2782127815                                3727DFD5142AAE4500D449CB /* FontCacheIOS.mm in Sources */,
    2782227816                                B2AFFC7C0D00A5C10030074D /* FontCacheMac.mm in Sources */,
    27823                                 37C2360B1097EDED00EF9F72 /* FontComplexTextMac.cpp in Sources */,
    2782427817                                B2AFFC7D0D00A5C10030074D /* FontCustomPlatformData.cpp in Sources */,
    2782527818                                37ACCF690DA414E70089E602 /* FontDescription.cpp in Sources */,
    27826                                 72626E020EF022FE00A07E20 /* FontFastPath.cpp in Sources */,
    2782727819                                4A6E9FC713C17D570046A7F8 /* FontFeatureSettings.cpp in Sources */,
    2782827820                                E44EE3A817577EBD00EEE8CF /* FontGenericFamilies.cpp in Sources */,
    2782927821                                B2C3DA670D006CD600EF6F26 /* FontGlyphs.cpp in Sources */,
    2783027822                                FD96C9971982FBDF0086E156 /* FontLoader.cpp in Sources */,
    27831                                 B2AFFC800D00A5C10030074D /* FontMac.mm in Sources */,
     27823                                B2AFFC800D00A5C10030074D /* FontCascadeCocoa.mm in Sources */,
    2783227824                                84B62685133138F90095A489 /* FontPlatformData.cpp in Sources */,
    2783327825                                B5320D6C122A24E9002D1440 /* FontPlatformDataCocoa.mm in Sources */,
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r178510 r178578  
    11401140}
    11411141
    1142 }
     1142// FIXME: This function may not work if the emphasis mark uses a complex script, but none of the
     1143// standard emphasis marks do so.
     1144bool FontCascade::getEmphasisMarkGlyphData(const AtomicString& mark, GlyphData& glyphData) const
     1145{
     1146    if (mark.isEmpty())
     1147        return false;
     1148
     1149    UChar32 character = mark[0];
     1150
     1151    if (U16_IS_SURROGATE(character)) {
     1152        if (!U16_IS_SURROGATE_LEAD(character))
     1153            return false;
     1154
     1155        if (mark.length() < 2)
     1156            return false;
     1157
     1158        UChar low = mark[1];
     1159        if (!U16_IS_TRAIL(low))
     1160            return false;
     1161
     1162        character = U16_GET_SUPPLEMENTARY(character, low);
     1163    }
     1164
     1165    glyphData = glyphDataForCharacter(character, false, EmphasisMarkVariant);
     1166    return true;
     1167}
     1168
     1169int FontCascade::emphasisMarkAscent(const AtomicString& mark) const
     1170{
     1171    GlyphData markGlyphData;
     1172    if (!getEmphasisMarkGlyphData(mark, markGlyphData))
     1173        return 0;
     1174
     1175    const SimpleFontData* markFontData = markGlyphData.fontData;
     1176    ASSERT(markFontData);
     1177    if (!markFontData)
     1178        return 0;
     1179
     1180    return markFontData->fontMetrics().ascent();
     1181}
     1182
     1183int FontCascade::emphasisMarkDescent(const AtomicString& mark) const
     1184{
     1185    GlyphData markGlyphData;
     1186    if (!getEmphasisMarkGlyphData(mark, markGlyphData))
     1187        return 0;
     1188
     1189    const SimpleFontData* markFontData = markGlyphData.fontData;
     1190    ASSERT(markFontData);
     1191    if (!markFontData)
     1192        return 0;
     1193
     1194    return markFontData->fontMetrics().descent();
     1195}
     1196
     1197int FontCascade::emphasisMarkHeight(const AtomicString& mark) const
     1198{
     1199    GlyphData markGlyphData;
     1200    if (!getEmphasisMarkGlyphData(mark, markGlyphData))
     1201        return 0;
     1202
     1203    const SimpleFontData* markFontData = markGlyphData.fontData;
     1204    ASSERT(markFontData);
     1205    if (!markFontData)
     1206        return 0;
     1207
     1208    return markFontData->fontMetrics().height();
     1209}
     1210
     1211float FontCascade::getGlyphsAndAdvancesForSimpleText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
     1212{
     1213    float initialAdvance;
     1214
     1215    WidthIterator it(this, run, 0, false, forTextEmphasis);
     1216    // FIXME: Using separate glyph buffers for the prefix and the suffix is incorrect when kerning or
     1217    // ligatures are enabled.
     1218    GlyphBuffer localGlyphBuffer;
     1219    it.advance(from, &localGlyphBuffer);
     1220    float beforeWidth = it.m_runWidthSoFar;
     1221    it.advance(to, &glyphBuffer);
     1222
     1223    if (glyphBuffer.isEmpty())
     1224        return 0;
     1225
     1226    float afterWidth = it.m_runWidthSoFar;
     1227
     1228    if (run.rtl()) {
     1229        float finalRoundingWidth = it.m_finalRoundingWidth;
     1230        it.advance(run.length(), &localGlyphBuffer);
     1231        initialAdvance = finalRoundingWidth + it.m_runWidthSoFar - afterWidth;
     1232    } else
     1233        initialAdvance = beforeWidth;
     1234
     1235    if (run.rtl())
     1236        glyphBuffer.reverse(0, glyphBuffer.size());
     1237
     1238    return initialAdvance;
     1239}
     1240
     1241float FontCascade::drawSimpleText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const
     1242{
     1243    // This glyph buffer holds our glyphs+advances+font data for each glyph.
     1244    GlyphBuffer glyphBuffer;
     1245
     1246    float startX = point.x() + getGlyphsAndAdvancesForSimpleText(run, from, to, glyphBuffer);
     1247
     1248    if (glyphBuffer.isEmpty())
     1249        return 0;
     1250
     1251    FloatPoint startPoint(startX, point.y());
     1252    drawGlyphBuffer(context, run, glyphBuffer, startPoint);
     1253
     1254    return startPoint.x() - startX;
     1255}
     1256
     1257void FontCascade::drawEmphasisMarksForSimpleText(GraphicsContext* context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
     1258{
     1259    GlyphBuffer glyphBuffer;
     1260    float initialAdvance = getGlyphsAndAdvancesForSimpleText(run, from, to, glyphBuffer, ForTextEmphasis);
     1261
     1262    if (glyphBuffer.isEmpty())
     1263        return;
     1264
     1265    drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
     1266}
     1267
     1268void FontCascade::drawGlyphBuffer(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, FloatPoint& point) const
     1269{
     1270#if !ENABLE(SVG_FONTS)
     1271    UNUSED_PARAM(run);
     1272#endif
     1273
     1274    // Draw each contiguous run of glyphs that use the same font data.
     1275    const SimpleFontData* fontData = glyphBuffer.fontDataAt(0);
     1276    FloatSize offset = glyphBuffer.offsetAt(0);
     1277    FloatPoint startPoint(point.x(), point.y() - glyphBuffer.initialAdvance().height());
     1278    float nextX = startPoint.x() + glyphBuffer.advanceAt(0).width();
     1279    float nextY = startPoint.y() + glyphBuffer.advanceAt(0).height();
     1280    int lastFrom = 0;
     1281    int nextGlyph = 1;
     1282#if ENABLE(SVG_FONTS)
     1283    TextRun::RenderingContext* renderingContext = run.renderingContext();
     1284#endif
     1285    while (nextGlyph < glyphBuffer.size()) {
     1286        const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph);
     1287        FloatSize nextOffset = glyphBuffer.offsetAt(nextGlyph);
     1288
     1289        if (nextFontData != fontData || nextOffset != offset) {
     1290#if ENABLE(SVG_FONTS)
     1291            if (renderingContext && fontData->isSVGFont())
     1292                renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     1293            else
     1294#endif
     1295                drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     1296
     1297            lastFrom = nextGlyph;
     1298            fontData = nextFontData;
     1299            offset = nextOffset;
     1300            startPoint.setX(nextX);
     1301            startPoint.setY(nextY);
     1302        }
     1303        nextX += glyphBuffer.advanceAt(nextGlyph).width();
     1304        nextY += glyphBuffer.advanceAt(nextGlyph).height();
     1305        nextGlyph++;
     1306    }
     1307
     1308#if ENABLE(SVG_FONTS)
     1309    if (renderingContext && fontData->isSVGFont())
     1310        renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     1311    else
     1312#endif
     1313    {
     1314        drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     1315        point.setX(nextX);
     1316    }
     1317}
     1318
     1319inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph glyph)
     1320{
     1321    if (fontData->platformData().orientation() == Horizontal) {
     1322        FloatRect bounds = fontData->boundsForGlyph(glyph);
     1323        return bounds.x() + bounds.width() / 2;
     1324    }
     1325    // FIXME: Use glyph bounds once they make sense for vertical fonts.
     1326    return fontData->widthForGlyph(glyph) / 2;
     1327}
     1328
     1329inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer& glyphBuffer, size_t i)
     1330{
     1331    return offsetToMiddleOfGlyph(glyphBuffer.fontDataAt(i), glyphBuffer.glyphAt(i));
     1332}
     1333
     1334void FontCascade::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) const
     1335{
     1336    GlyphData markGlyphData;
     1337    if (!getEmphasisMarkGlyphData(mark, markGlyphData))
     1338        return;
     1339
     1340    const SimpleFontData* markFontData = markGlyphData.fontData;
     1341    ASSERT(markFontData);
     1342    if (!markFontData)
     1343        return;
     1344
     1345    Glyph markGlyph = markGlyphData.glyph;
     1346    Glyph spaceGlyph = markFontData->spaceGlyph();
     1347
     1348    float middleOfLastGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, 0);
     1349    FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph(markFontData, markGlyph), point.y());
     1350
     1351    GlyphBuffer markBuffer;
     1352    for (int i = 0; i + 1 < glyphBuffer.size(); ++i) {
     1353        float middleOfNextGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, i + 1);
     1354        float advance = glyphBuffer.advanceAt(i).width() - middleOfLastGlyph + middleOfNextGlyph;
     1355        markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFontData, advance);
     1356        middleOfLastGlyph = middleOfNextGlyph;
     1357    }
     1358    markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spaceGlyph, markFontData, 0);
     1359
     1360    drawGlyphBuffer(context, run, markBuffer, startPoint);
     1361}
     1362
     1363float FontCascade::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
     1364{
     1365    WidthIterator it(this, run, fallbackFonts, glyphOverflow);
     1366    GlyphBuffer glyphBuffer;
     1367    it.advance(run.length(), (typesettingFeatures() & (Kerning | Ligatures)) ? &glyphBuffer : 0);
     1368
     1369    if (glyphOverflow) {
     1370        glyphOverflow->top = std::max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent()));
     1371        glyphOverflow->bottom = std::max<int>(glyphOverflow->bottom, ceilf(it.maxGlyphBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().descent()));
     1372        glyphOverflow->left = ceilf(it.firstGlyphOverflow());
     1373        glyphOverflow->right = ceilf(it.lastGlyphOverflow());
     1374    }
     1375
     1376    return it.m_runWidthSoFar;
     1377}
     1378
     1379void FontCascade::adjustSelectionRectForSimpleText(const TextRun& run, LayoutRect& selectionRect, int from, int to) const
     1380{
     1381    GlyphBuffer glyphBuffer;
     1382    WidthIterator it(this, run);
     1383    it.advance(from, &glyphBuffer);
     1384    float beforeWidth = it.m_runWidthSoFar;
     1385    it.advance(to, &glyphBuffer);
     1386    float afterWidth = it.m_runWidthSoFar;
     1387    float totalWidth = -1;
     1388
     1389    if (run.rtl()) {
     1390        it.advance(run.length(), &glyphBuffer);
     1391        totalWidth = it.m_runWidthSoFar;
     1392        selectionRect.move(totalWidth - afterWidth, 0);
     1393    } else
     1394        selectionRect.move(beforeWidth, 0);
     1395    selectionRect.setWidth(afterWidth - beforeWidth);
     1396}
     1397
     1398int FontCascade::offsetForPositionForSimpleText(const TextRun& run, float x, bool includePartialGlyphs) const
     1399{
     1400    float delta = x;
     1401
     1402    WidthIterator it(this, run);
     1403    GlyphBuffer localGlyphBuffer;
     1404    unsigned offset;
     1405    if (run.rtl()) {
     1406        delta -= floatWidthForSimpleText(run);
     1407        while (1) {
     1408            offset = it.m_currentCharacter;
     1409            float w;
     1410            if (!it.advanceOneCharacter(w, localGlyphBuffer))
     1411                break;
     1412            delta += w;
     1413            if (includePartialGlyphs) {
     1414                if (delta - w / 2 >= 0)
     1415                    break;
     1416            } else {
     1417                if (delta >= 0)
     1418                    break;
     1419            }
     1420        }
     1421    } else {
     1422        while (1) {
     1423            offset = it.m_currentCharacter;
     1424            float w;
     1425            if (!it.advanceOneCharacter(w, localGlyphBuffer))
     1426                break;
     1427            delta -= w;
     1428            if (includePartialGlyphs) {
     1429                if (delta + w / 2 <= 0)
     1430                    break;
     1431            } else {
     1432                if (delta <= 0)
     1433                    break;
     1434            }
     1435        }
     1436    }
     1437
     1438    return offset;
     1439}
     1440
     1441
     1442}
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm

    r178510 r178578  
    2424#import "FontCascade.h"
    2525
     26#import "ComplexTextController.h"
    2627#import "CoreGraphicsSPI.h"
    2728#import "CoreTextSPI.h"
     
    2930#import "GlyphBuffer.h"
    3031#import "GraphicsContext.h"
     32#import "LayoutRect.h"
    3133#import "Logging.h"
    3234#import "SimpleFontData.h"
     
    207209    bool changeFontSmoothing;
    208210   
    209     switch(fontDescription().fontSmoothing()) {
     211    switch (fontDescription().fontSmoothing()) {
    210212    case Antialiased: {
    211213        context->setShouldAntialias(true);
     
    603605}
    604606
    605 }
     607void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, int from, int to) const
     608{
     609    ComplexTextController controller(this, run);
     610    controller.advance(from);
     611    float beforeWidth = controller.runWidthSoFar();
     612    controller.advance(to);
     613    float afterWidth = controller.runWidthSoFar();
     614
     615    if (run.rtl())
     616        selectionRect.move(controller.totalWidth() - afterWidth, 0);
     617    else
     618        selectionRect.move(beforeWidth, 0);
     619    selectionRect.setWidth(afterWidth - beforeWidth);
     620}
     621
     622float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
     623{
     624    float initialAdvance;
     625
     626    ComplexTextController controller(this, run, false, 0, forTextEmphasis);
     627    controller.advance(from);
     628    float beforeWidth = controller.runWidthSoFar();
     629    controller.advance(to, &glyphBuffer);
     630
     631    if (glyphBuffer.isEmpty())
     632        return 0;
     633
     634    float afterWidth = controller.runWidthSoFar();
     635
     636    if (run.rtl()) {
     637        initialAdvance = controller.totalWidth() + controller.finalRoundingWidth() - afterWidth;
     638        glyphBuffer.reverse(0, glyphBuffer.size());
     639    } else
     640        initialAdvance = beforeWidth;
     641
     642    return initialAdvance;
     643}
     644
     645float FontCascade::drawComplexText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const
     646{
     647    // This glyph buffer holds our glyphs + advances + font data for each glyph.
     648    GlyphBuffer glyphBuffer;
     649
     650    float startX = point.x() + getGlyphsAndAdvancesForComplexText(run, from, to, glyphBuffer);
     651
     652    // We couldn't generate any glyphs for the run. Give up.
     653    if (glyphBuffer.isEmpty())
     654        return 0;
     655
     656    // Draw the glyph buffer now at the starting point returned in startX.
     657    FloatPoint startPoint(startX, point.y());
     658    drawGlyphBuffer(context, run, glyphBuffer, startPoint);
     659
     660    return startPoint.x() - startX;
     661}
     662
     663void FontCascade::drawEmphasisMarksForComplexText(GraphicsContext* context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
     664{
     665    GlyphBuffer glyphBuffer;
     666    float initialAdvance = getGlyphsAndAdvancesForComplexText(run, from, to, glyphBuffer, ForTextEmphasis);
     667
     668    if (glyphBuffer.isEmpty())
     669        return;
     670
     671    drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
     672}
     673
     674float FontCascade::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
     675{
     676    ComplexTextController controller(this, run, true, fallbackFonts);
     677    if (glyphOverflow) {
     678        glyphOverflow->top = std::max<int>(glyphOverflow->top, ceilf(-controller.minGlyphBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent()));
     679        glyphOverflow->bottom = std::max<int>(glyphOverflow->bottom, ceilf(controller.maxGlyphBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().descent()));
     680        glyphOverflow->left = std::max<int>(0, ceilf(-controller.minGlyphBoundingBoxX()));
     681        glyphOverflow->right = std::max<int>(0, ceilf(controller.maxGlyphBoundingBoxX() - controller.totalWidth()));
     682    }
     683    return controller.totalWidth();
     684}
     685
     686int FontCascade::offsetForPositionForComplexText(const TextRun& run, float x, bool includePartialGlyphs) const
     687{
     688    ComplexTextController controller(this, run);
     689    return controller.offsetForPosition(x, includePartialGlyphs);
     690}
     691
     692const SimpleFontData* FontCascade::fontDataForCombiningCharacterSequence(const UChar* characters, size_t length, FontDataVariant variant) const
     693{
     694    UChar32 baseCharacter;
     695    size_t baseCharacterLength = 0;
     696    U16_NEXT(characters, baseCharacterLength, length, baseCharacter);
     697
     698    GlyphData baseCharacterGlyphData = glyphDataForCharacter(baseCharacter, false, variant);
     699
     700    if (!baseCharacterGlyphData.glyph)
     701        return 0;
     702
     703    if (length == baseCharacterLength)
     704        return baseCharacterGlyphData.fontData;
     705
     706    bool triedBaseCharacterFontData = false;
     707
     708    for (unsigned i = 0; !fallbackRangesAt(i).isNull(); ++i) {
     709        const SimpleFontData* simpleFontData = fallbackRangesAt(i).fontDataForCharacter(baseCharacter);
     710        if (!simpleFontData)
     711            continue;
     712#if PLATFORM(IOS)
     713        if (baseCharacter >= 0x0600 && baseCharacter <= 0x06ff && simpleFontData->shouldNotBeUsedForArabic())
     714            continue;
     715#endif
     716        if (variant == NormalVariant) {
     717            if (simpleFontData->platformData().orientation() == Vertical) {
     718                if (isCJKIdeographOrSymbol(baseCharacter) && !simpleFontData->hasVerticalGlyphs()) {
     719                    variant = BrokenIdeographVariant;
     720                    simpleFontData = simpleFontData->brokenIdeographFontData().get();
     721                } else if (m_fontDescription.nonCJKGlyphOrientation() == NonCJKGlyphOrientationVerticalRight) {
     722                    SimpleFontData* verticalRightFontData = simpleFontData->verticalRightOrientationFontData().get();
     723                    Glyph verticalRightGlyph = verticalRightFontData->glyphForCharacter(baseCharacter);
     724                    if (verticalRightGlyph == baseCharacterGlyphData.glyph)
     725                        simpleFontData = verticalRightFontData;
     726                } else {
     727                    SimpleFontData* uprightFontData = simpleFontData->uprightOrientationFontData().get();
     728                    Glyph uprightGlyph = uprightFontData->glyphForCharacter(baseCharacter);
     729                    if (uprightGlyph != baseCharacterGlyphData.glyph)
     730                        simpleFontData = uprightFontData;
     731                }
     732            }
     733        } else {
     734            if (const SimpleFontData* variantFontData = simpleFontData->variantFontData(m_fontDescription, variant).get())
     735                simpleFontData = variantFontData;
     736        }
     737
     738        if (simpleFontData == baseCharacterGlyphData.fontData)
     739            triedBaseCharacterFontData = true;
     740
     741        if (simpleFontData->canRenderCombiningCharacterSequence(characters, length))
     742            return simpleFontData;
     743    }
     744
     745    if (!triedBaseCharacterFontData && baseCharacterGlyphData.fontData && baseCharacterGlyphData.fontData->canRenderCombiningCharacterSequence(characters, length))
     746        return baseCharacterGlyphData.fontData;
     747
     748    return SimpleFontData::systemFallback();
     749}
     750
     751}
Note: See TracChangeset for help on using the changeset viewer.