Diff
Modified: trunk/Source/WebCore/ChangeLog (131467 => 131468)
--- trunk/Source/WebCore/ChangeLog 2012-10-16 16:56:17 UTC (rev 131467)
+++ trunk/Source/WebCore/ChangeLog 2012-10-16 17:08:28 UTC (rev 131468)
@@ -1,3 +1,23 @@
+2012-10-16 Dan Bernstein <[email protected]>
+
+ Code to reverse a GlyphBuffer range is repeated in several places
+ https://bugs.webkit.org/show_bug.cgi?id=99424
+
+ Reviewed by Adele Peterson.
+
+ * platform/graphics/FontFastPath.cpp:
+ (WebCore::Font::getGlyphsAndAdvancesForSimpleText): Replaced for loop with a call to
+ GlyphBuffer::reverse.
+ * platform/graphics/GlyphBuffer.h:
+ (WebCore::GlyphBuffer::reverse): Added. Reverses the given range.
+ (WebCore::GlyphBuffer::swap): Made private.
+ * platform/graphics/WidthIterator.cpp:
+ (WebCore::applyFontTransforms): Replaced for loops with calls to GlyphBuffer::reverse and
+ corrected their bounds.
+ * platform/graphics/mac/FontComplexTextMac.cpp:
+ (WebCore::Font::getGlyphsAndAdvancesForComplexText): Replaced for loop with a call to
+ GlyphBuffer::range.
+
2012-10-16 Nate Chapin <[email protected]>
Re-order CachedRawResource::data() to set m_data earlier
Modified: trunk/Source/WebCore/platform/graphics/FontFastPath.cpp (131467 => 131468)
--- trunk/Source/WebCore/platform/graphics/FontFastPath.cpp 2012-10-16 16:56:17 UTC (rev 131467)
+++ trunk/Source/WebCore/platform/graphics/FontFastPath.cpp 2012-10-16 17:08:28 UTC (rev 131468)
@@ -347,10 +347,8 @@
} else
initialAdvance = beforeWidth;
- if (run.rtl()) {
- for (int i = 0, end = glyphBuffer.size() - 1; i < end; ++i, --end)
- glyphBuffer.swap(i, end);
- }
+ if (run.rtl())
+ glyphBuffer.reverse(0, glyphBuffer.size());
return initialAdvance;
}
Modified: trunk/Source/WebCore/platform/graphics/GlyphBuffer.h (131467 => 131468)
--- trunk/Source/WebCore/platform/graphics/GlyphBuffer.h 2012-10-16 16:56:17 UTC (rev 131467)
+++ trunk/Source/WebCore/platform/graphics/GlyphBuffer.h 2012-10-16 17:08:28 UTC (rev 131468)
@@ -116,27 +116,6 @@
const SimpleFontData* fontDataAt(int index) const { return m_fontData[index]; }
- void swap(int index1, int index2)
- {
- const SimpleFontData* f = m_fontData[index1];
- m_fontData[index1] = m_fontData[index2];
- m_fontData[index2] = f;
-
- GlyphBufferGlyph g = m_glyphs[index1];
- m_glyphs[index1] = m_glyphs[index2];
- m_glyphs[index2] = g;
-
- GlyphBufferAdvance s = m_advances[index1];
- m_advances[index1] = m_advances[index2];
- m_advances[index2] = s;
-
-#if PLATFORM(WIN)
- FloatSize offset = m_offsets[index1];
- m_offsets[index1] = m_offsets[index2];
- m_offsets[index2] = offset;
-#endif
- }
-
Glyph glyphAt(int index) const
{
#if USE(CAIRO) || (PLATFORM(WX) && defined(wxUSE_CAIRO) && wxUSE_CAIRO)
@@ -208,6 +187,12 @@
}
#endif
+ void reverse(int from, int length)
+ {
+ for (int i = from, end = from + length - 1; i < end; ++i, --end)
+ swap(i, end);
+ }
+
void expandLastAdvance(float width)
{
ASSERT(!isEmpty());
@@ -216,6 +201,27 @@
}
private:
+ void swap(int index1, int index2)
+ {
+ const SimpleFontData* f = m_fontData[index1];
+ m_fontData[index1] = m_fontData[index2];
+ m_fontData[index2] = f;
+
+ GlyphBufferGlyph g = m_glyphs[index1];
+ m_glyphs[index1] = m_glyphs[index2];
+ m_glyphs[index2] = g;
+
+ GlyphBufferAdvance s = m_advances[index1];
+ m_advances[index1] = m_advances[index2];
+ m_advances[index2] = s;
+
+#if PLATFORM(WIN)
+ FloatSize offset = m_offsets[index1];
+ m_offsets[index1] = m_offsets[index2];
+ m_offsets[index2] = offset;
+#endif
+ }
+
Vector<const SimpleFontData*, 2048> m_fontData;
Vector<GlyphBufferGlyph, 2048> m_glyphs;
Vector<GlyphBufferAdvance, 2048> m_advances;
Modified: trunk/Source/WebCore/platform/graphics/WidthIterator.cpp (131467 => 131468)
--- trunk/Source/WebCore/platform/graphics/WidthIterator.cpp 2012-10-16 16:56:17 UTC (rev 131467)
+++ trunk/Source/WebCore/platform/graphics/WidthIterator.cpp 2012-10-16 17:08:28 UTC (rev 131468)
@@ -116,17 +116,13 @@
for (int i = lastGlyphCount; i < glyphBufferSize; ++i)
widthDifference -= advances[i].width();
- if (!ltr) {
- for (int i = 0, end = glyphBuffer->size() - 1; i < glyphBuffer->size() / 2; ++i, --end)
- glyphBuffer->swap(i, end);
- }
+ if (!ltr)
+ glyphBuffer->reverse(lastGlyphCount, glyphBufferSize - lastGlyphCount);
fontData->applyTransforms(glyphBuffer->glyphs(lastGlyphCount), advances + lastGlyphCount, glyphBufferSize - lastGlyphCount, typesettingFeatures);
- if (!ltr) {
- for (int i = 0, end = glyphBuffer->size() - 1; i < glyphBuffer->size() / 2; ++i, --end)
- glyphBuffer->swap(i, end);
- }
+ if (!ltr)
+ glyphBuffer->reverse(lastGlyphCount, glyphBufferSize - lastGlyphCount);
for (size_t i = 0; i < charactersTreatedAsSpace.size(); ++i) {
int spaceOffset = charactersTreatedAsSpace[i].first;
Modified: trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp (131467 => 131468)
--- trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp 2012-10-16 16:56:17 UTC (rev 131467)
+++ trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp 2012-10-16 17:08:28 UTC (rev 131468)
@@ -91,8 +91,7 @@
if (run.rtl()) {
initialAdvance = controller.totalWidth() + controller.finalRoundingWidth() - afterWidth;
- for (int i = 0, end = glyphBuffer.size() - 1; i < end; ++i, --end)
- glyphBuffer.swap(i, end);
+ glyphBuffer.reverse(0, glyphBuffer.size());
} else
initialAdvance = beforeWidth;