Title: [174269] trunk/Source/WebCore
Revision
174269
Author
[email protected]
Date
2014-10-03 09:57:10 -0700 (Fri, 03 Oct 2014)

Log Message

TextRun::length() should return an unsigned
https://bugs.webkit.org/show_bug.cgi?id=137354

Patch by Myles C. Maxfield <[email protected]> on 2014-10-03
Reviewed by Antti Koivisto.

Currently, the m_len instance variable that backs the TextRun::length() function is
an unsigned, but the length() function implicitly casts that to an int when
returning it. This patch makes the function return an unsigned, and makes the
do any casting if necessary.

No new tests because there is no behavior change.

* platform/graphics/Font.cpp:
(WebCore::Font::drawText): Cast result to int.
(WebCore::Font::drawEmphasisMarks): Ditto.
(WebCore::Font::adjustSelectionRectForText): Ditto.
(WebCore::computeUnderlineType): Update internal type to be unsigned.
* platform/graphics/GlyphBuffer.h:
(WebCore::GlyphBuffer::add): Update sentinel value to be unsigned.
(WebCore::GlyphBuffer::saveOffsetsInString): Ditto.
* platform/graphics/GraphicsContext.cpp: Update internal type to be unsigned.
* platform/graphics/TextRun.h:
(WebCore::TextRun::length): Update return type.
(WebCore::TextRun::charactersLength): Ditto.
* platform/graphics/WidthIterator.cpp:
(WebCore::WidthIterator::advanceInternal): Cast result to int.
* rendering/svg/SVGTextMetricsBuilder.cpp:
(WebCore::SVGTextMetricsBuilder::currentCharacterStartsSurrogatePair): Remove
unnecessary casts.
(WebCore::SVGTextMetricsBuilder::advance): Ditto.
* svg/SVGFontData.cpp:
(WebCore::SVGFontData::applySVGGlyphSelection): Cast result to int.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174268 => 174269)


--- trunk/Source/WebCore/ChangeLog	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/ChangeLog	2014-10-03 16:57:10 UTC (rev 174269)
@@ -1,3 +1,38 @@
+2014-10-03  Myles C. Maxfield  <[email protected]>
+
+        TextRun::length() should return an unsigned
+        https://bugs.webkit.org/show_bug.cgi?id=137354
+
+        Reviewed by Antti Koivisto.
+
+        Currently, the m_len instance variable that backs the TextRun::length() function is
+        an unsigned, but the length() function implicitly casts that to an int when
+        returning it. This patch makes the function return an unsigned, and makes the
+        do any casting if necessary.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::drawText): Cast result to int.
+        (WebCore::Font::drawEmphasisMarks): Ditto.
+        (WebCore::Font::adjustSelectionRectForText): Ditto.
+        (WebCore::computeUnderlineType): Update internal type to be unsigned.
+        * platform/graphics/GlyphBuffer.h:
+        (WebCore::GlyphBuffer::add): Update sentinel value to be unsigned.
+        (WebCore::GlyphBuffer::saveOffsetsInString): Ditto.
+        * platform/graphics/GraphicsContext.cpp: Update internal type to be unsigned.
+        * platform/graphics/TextRun.h:
+        (WebCore::TextRun::length): Update return type.
+        (WebCore::TextRun::charactersLength): Ditto.
+        * platform/graphics/WidthIterator.cpp:
+        (WebCore::WidthIterator::advanceInternal): Cast result to int.
+        * rendering/svg/SVGTextMetricsBuilder.cpp:
+        (WebCore::SVGTextMetricsBuilder::currentCharacterStartsSurrogatePair): Remove
+        unnecessary casts.
+        (WebCore::SVGTextMetricsBuilder::advance): Ditto.
+        * svg/SVGFontData.cpp:
+        (WebCore::SVGFontData::applySVGGlyphSelection): Cast result to int.
+
 2014-10-03  Gyuyoung Kim  <[email protected]>
 
         [EFL] Fix build break since r174231 and r174256

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (174268 => 174269)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2014-10-03 16:57:10 UTC (rev 174269)
@@ -341,7 +341,7 @@
 
     CodePath codePathToUse = codePath(run);
     // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
-    if (codePathToUse != Complex && typesettingFeatures() && (from || to != run.length()) && !isDrawnWithSVGFont(run))
+    if (codePathToUse != Complex && typesettingFeatures() && (from || static_cast<unsigned>(to) != run.length()) && !isDrawnWithSVGFont(run))
         codePathToUse = Complex;
 
     if (codePathToUse != Complex)
@@ -360,7 +360,7 @@
 
     CodePath codePathToUse = codePath(run);
     // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
-    if (codePathToUse != Complex && typesettingFeatures() && (from || to != run.length()) && !isDrawnWithSVGFont(run))
+    if (codePathToUse != Complex && typesettingFeatures() && (from || static_cast<unsigned>(to) != run.length()) && !isDrawnWithSVGFont(run))
         codePathToUse = Complex;
 
     if (codePathToUse != Complex)
@@ -513,7 +513,7 @@
 
     CodePath codePathToUse = codePath(run);
     // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
-    if (codePathToUse != Complex && typesettingFeatures() && (from || to != run.length()) && !isDrawnWithSVGFont(run))
+    if (codePathToUse != Complex && typesettingFeatures() && (from || static_cast<unsigned>(to) != run.length()) && !isDrawnWithSVGFont(run))
         codePathToUse = Complex;
 
     if (codePathToUse != Complex)
@@ -1059,9 +1059,9 @@
     // In general, we want to skip descenders. However, skipping descenders on CJK characters leads to undesirable renderings,
     // so we want to draw through CJK characters (on a character-by-character basis).
     UChar32 baseCharacter;
-    int offsetInString = glyphBuffer.offsetInString(index);
+    unsigned offsetInString = glyphBuffer.offsetInString(index);
 
-    if (offsetInString == GlyphBuffer::kNoOffset) {
+    if (offsetInString == GlyphBuffer::noOffset) {
         // We have no idea which character spawned this glyph. Bail.
         return GlyphToPathTranslator::GlyphUnderlineType::DrawOverGlyph;
     }

Modified: trunk/Source/WebCore/platform/graphics/GlyphBuffer.h (174268 => 174269)


--- trunk/Source/WebCore/platform/graphics/GlyphBuffer.h	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/platform/graphics/GlyphBuffer.h	2014-10-03 16:57:10 UTC (rev 174269)
@@ -32,6 +32,7 @@
 
 #include "FloatSize.h"
 #include "Glyph.h"
+#include <climits>
 #include <wtf/Vector.h>
 
 #if USE(CG)
@@ -124,8 +125,8 @@
 #endif
     }
     
-    static const int kNoOffset = -1;
-    void add(Glyph glyph, const SimpleFontData* font, float width, int offsetInString = kNoOffset, const FloatSize* offset = 0)
+    static const unsigned noOffset = UINT_MAX;
+    void add(Glyph glyph, const SimpleFontData* font, float width, unsigned offsetInString = noOffset, const FloatSize* offset = 0)
     {
         m_fontData.append(font);
 
@@ -153,12 +154,12 @@
         UNUSED_PARAM(offset);
 #endif
         
-        if (offsetInString != kNoOffset && m_offsetsInString)
+        if (offsetInString != noOffset && m_offsetsInString)
             m_offsetsInString->append(offsetInString);
     }
     
 #if !USE(WINGDI)
-    void add(Glyph glyph, const SimpleFontData* font, GlyphBufferAdvance advance, int offsetInString = kNoOffset)
+    void add(Glyph glyph, const SimpleFontData* font, GlyphBufferAdvance advance, unsigned offsetInString = noOffset)
     {
         m_fontData.append(font);
 #if USE(CAIRO)
@@ -171,7 +172,7 @@
 
         m_advances.append(advance);
         
-        if (offsetInString != kNoOffset && m_offsetsInString)
+        if (offsetInString != noOffset && m_offsetsInString)
             m_offsetsInString->append(offsetInString);
     }
 #endif
@@ -191,9 +192,10 @@
     
     void saveOffsetsInString()
     {
-        m_offsetsInString.reset(new Vector<int, 2048>());
+        m_offsetsInString.reset(new Vector<unsigned, 2048>());
     }
-    
+
+    // FIXME: This converts from an unsigned to an int
     int offsetInString(int index) const
     {
         ASSERT(m_offsetsInString);
@@ -226,7 +228,7 @@
     Vector<GlyphBufferGlyph, 2048> m_glyphs;
     Vector<GlyphBufferAdvance, 2048> m_advances;
     GlyphBufferAdvance m_initialAdvance;
-    std::unique_ptr<Vector<int, 2048>> m_offsetsInString;
+    std::unique_ptr<Vector<unsigned, 2048>> m_offsetsInString;
 #if PLATFORM(WIN)
     Vector<FloatSize, 2048> m_offsets;
 #endif

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (174268 => 174269)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2014-10-03 16:57:10 UTC (rev 174269)
@@ -74,7 +74,7 @@
 
 private:
     const TextRun* m_textRun;
-    int m_offset;
+    unsigned m_offset;
 };
 
 class InterpolationQualityMaintainer {

Modified: trunk/Source/WebCore/platform/graphics/TextRun.h (174268 => 174269)


--- trunk/Source/WebCore/platform/graphics/TextRun.h	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/platform/graphics/TextRun.h	2014-10-03 16:57:10 UTC (rev 174269)
@@ -153,10 +153,10 @@
 
     const LChar* characters8() const { ASSERT(is8Bit()); return m_text.characters8(); }
     const UChar* characters16() const { ASSERT(!is8Bit()); return m_text.characters16(); }
-    
+
     bool is8Bit() const { return m_text.is8Bit(); }
-    int length() const { return m_text.length(); }
-    int charactersLength() const { return m_charactersLength; }
+    unsigned length() const { return m_text.length(); }
+    unsigned charactersLength() const { return m_charactersLength; }
     String string() const { return m_text.toString(); }
 
     void setText(const LChar* c, unsigned len) { m_text = StringView(c, len); }

Modified: trunk/Source/WebCore/platform/graphics/WidthIterator.cpp (174268 => 174269)


--- trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2014-10-03 16:57:10 UTC (rev 174269)
@@ -298,8 +298,8 @@
         } else {
             // Check to see if the next character is a "rounding hack character", if so, adjust
             // width so that the total run width will be on an integer boundary.
-            if ((m_run.applyWordRounding() && textIterator.currentCharacter() < m_run.length() && Font::isRoundingHackCharacter(*(textIterator.characters())))
-                || (m_run.applyRunRounding() && textIterator.currentCharacter() >= m_run.length())) {
+            if ((m_run.applyWordRounding() && static_cast<unsigned>(textIterator.currentCharacter()) < m_run.length() && Font::isRoundingHackCharacter(*(textIterator.characters())))
+                || (m_run.applyRunRounding() && static_cast<unsigned>(textIterator.currentCharacter()) >= m_run.length())) {
                 float totalWidth = widthSinceLastRounding + width;
                 widthSinceLastRounding = ceilf(totalWidth);
                 width += widthSinceLastRounding - totalWidth;

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp (174268 => 174269)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp	2014-10-03 16:57:10 UTC (rev 174269)
@@ -254,7 +254,7 @@
     } else
         runCharacters = m_run.characters16();
 
-    for (int i = 0; i < m_run.length(); ++i) {
+    for (unsigned i = 0; i < m_run.length(); ++i) {
         UChar ch = runCharacters[i];
         if (::ublock_getCode(ch) == UBLOCK_COMBINING_DIACRITICAL_MARKS) {
             icu::Normalizer::normalize(icu::UnicodeString(runCharacters,

Modified: trunk/Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp (174268 => 174269)


--- trunk/Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp	2014-10-03 16:57:10 UTC (rev 174269)
@@ -37,13 +37,13 @@
 
 inline bool SVGTextMetricsBuilder::currentCharacterStartsSurrogatePair() const
 {
-    return U16_IS_LEAD(m_run[m_textPosition]) && int(m_textPosition + 1) < m_run.charactersLength() && U16_IS_TRAIL(m_run[m_textPosition + 1]);
+    return U16_IS_LEAD(m_run[m_textPosition]) && (m_textPosition + 1) < m_run.charactersLength() && U16_IS_TRAIL(m_run[m_textPosition + 1]);
 }
 
 bool SVGTextMetricsBuilder::advance()
 {
     m_textPosition += m_currentMetrics.length();
-    if (int(m_textPosition) >= m_run.charactersLength())
+    if (m_textPosition >= m_run.charactersLength())
         return false;
 
     if (m_isComplexText)

Modified: trunk/Source/WebCore/svg/SVGFontData.cpp (174268 => 174269)


--- trunk/Source/WebCore/svg/SVGFontData.cpp	2014-10-03 16:47:06 UTC (rev 174268)
+++ trunk/Source/WebCore/svg/SVGFontData.cpp	2014-10-03 16:57:10 UTC (rev 174269)
@@ -135,7 +135,7 @@
 {
     const TextRun& run = iterator.run();
     Vector<SVGGlyph::ArabicForm>& arabicForms = iterator.arabicForms();
-    ASSERT(run.charactersLength() >= currentCharacter);
+    ASSERT(run.charactersLength() >= static_cast<unsigned>(currentCharacter));
 
     SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement();
     ASSERT(svgFontFaceElement);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to