Title: [88613] trunk/Source/WebCore
Revision
88613
Author
[email protected]
Date
2011-06-12 05:40:40 -0700 (Sun, 12 Jun 2011)

Log Message

2011-06-11  Nikolas Zimmermann  <[email protected]>

        Reviewed by Dirk Schulze.

        Add TextRun charactersLength member
        https://bugs.webkit.org/show_bug.cgi?id=62501

        Preparation patch 2: Propagate the maximum length of the characters buffer the TextRun operates on, even when we're only measuring a substring.
        For example: In RenderText when we're measuring 'len' characters starting from "text()->characters() + start", there's a portion
        of "textLength() - start" characters that we're not processing. In order to support ligatures when integrating SVG Fonts
        within the GlyphPage concept, we need this extra information, to lookup ligatures even when single chars are measured.
        If a font defines an eg "ffl" ligature, and we're measuring the "f" of "ffl", it shall looukp the "ffl" glyph from the font,
        and skip the next two characters (this will be done in WidthIterator).

        This doesn't yet affect any test, the new SVG Fonts code is not merged yet, this is the preparaion patch 2.

        * platform/graphics/Font.h: Add yet-unused "const TextRun&" parameter to drawGlyphBuffer/drawEmphasisMarks.
        * platform/graphics/FontFastPath.cpp: Ditto. This parameter will be used to looukp the TextRunRenderingContext in a follow-up patch.
        (WebCore::Font::drawSimpleText):
        (WebCore::Font::drawEmphasisMarksForSimpleText):
        (WebCore::Font::drawGlyphBuffer):
        (WebCore::Font::drawEmphasisMarks):
        * platform/graphics/TextRun.h: Add "int m_charactersLength", similar to "int m_len". It denotes the maximum length of the characters buffer
                                       that we're holding. It defaults to the passed "len" value, but is overriden by explicit setCharactersLength calls.
        (WebCore::TextRun::TextRun):
        (WebCore::TextRun::charactersLength):
        (WebCore::TextRun::setCharactersLength):
        * platform/graphics/mac/FontComplexTextMac.cpp: Pass TextRun do drawGlyphBuffer/drawEmphasisMarks.
        (WebCore::Font::drawComplexText):
        (WebCore::Font::drawEmphasisMarksForComplexText):
        * platform/graphics/win/FontWin.cpp: Ditto.
        (WebCore::Font::drawComplexText):
        (WebCore::Font::drawEmphasisMarksForComplexText):
        * platform/graphics/wx/FontWx.cpp: Ditto.
        (WebCore::Font::drawComplexText):
        (WebCore::Font::drawEmphasisMarksForComplexText):
        * rendering/InlineTextBox.cpp: Call setCharactersLength on the processed TextRun.
        (WebCore::InlineTextBox::constructTextRun):
        * rendering/RenderBlockLineLayout.cpp: Ditto.
        (WebCore::textWidth):
        (WebCore::tryHyphenating):
        * rendering/RenderText.cpp: Ditto.
        (WebCore::RenderText::widthFromCache):
        (WebCore::RenderText::computePreferredLogicalWidths):
        (WebCore::RenderText::width):
        * rendering/svg/SVGInlineTextBox.cpp: Ditto.
        (WebCore::SVGInlineTextBox::constructTextRun):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (88612 => 88613)


--- trunk/Source/WebCore/ChangeLog	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/ChangeLog	2011-06-12 12:40:40 UTC (rev 88613)
@@ -1,3 +1,51 @@
+2011-06-11  Nikolas Zimmermann  <[email protected]>
+
+        Reviewed by Dirk Schulze.
+
+        Add TextRun charactersLength member
+        https://bugs.webkit.org/show_bug.cgi?id=62501
+
+        Preparation patch 2: Propagate the maximum length of the characters buffer the TextRun operates on, even when we're only measuring a substring.
+        For example: In RenderText when we're measuring 'len' characters starting from "text()->characters() + start", there's a portion
+        of "textLength() - start" characters that we're not processing. In order to support ligatures when integrating SVG Fonts
+        within the GlyphPage concept, we need this extra information, to lookup ligatures even when single chars are measured.
+        If a font defines an eg "ffl" ligature, and we're measuring the "f" of "ffl", it shall looukp the "ffl" glyph from the font,
+        and skip the next two characters (this will be done in WidthIterator).
+
+        This doesn't yet affect any test, the new SVG Fonts code is not merged yet, this is the preparaion patch 2.
+
+        * platform/graphics/Font.h: Add yet-unused "const TextRun&" parameter to drawGlyphBuffer/drawEmphasisMarks.
+        * platform/graphics/FontFastPath.cpp: Ditto. This parameter will be used to looukp the TextRunRenderingContext in a follow-up patch.
+        (WebCore::Font::drawSimpleText):
+        (WebCore::Font::drawEmphasisMarksForSimpleText):
+        (WebCore::Font::drawGlyphBuffer):
+        (WebCore::Font::drawEmphasisMarks):
+        * platform/graphics/TextRun.h: Add "int m_charactersLength", similar to "int m_len". It denotes the maximum length of the characters buffer
+                                       that we're holding. It defaults to the passed "len" value, but is overriden by explicit setCharactersLength calls.
+        (WebCore::TextRun::TextRun):
+        (WebCore::TextRun::charactersLength):
+        (WebCore::TextRun::setCharactersLength):
+        * platform/graphics/mac/FontComplexTextMac.cpp: Pass TextRun do drawGlyphBuffer/drawEmphasisMarks.
+        (WebCore::Font::drawComplexText):
+        (WebCore::Font::drawEmphasisMarksForComplexText):
+        * platform/graphics/win/FontWin.cpp: Ditto.
+        (WebCore::Font::drawComplexText):
+        (WebCore::Font::drawEmphasisMarksForComplexText):
+        * platform/graphics/wx/FontWx.cpp: Ditto.
+        (WebCore::Font::drawComplexText):
+        (WebCore::Font::drawEmphasisMarksForComplexText):
+        * rendering/InlineTextBox.cpp: Call setCharactersLength on the processed TextRun.
+        (WebCore::InlineTextBox::constructTextRun):
+        * rendering/RenderBlockLineLayout.cpp: Ditto.
+        (WebCore::textWidth):
+        (WebCore::tryHyphenating):
+        * rendering/RenderText.cpp: Ditto.
+        (WebCore::RenderText::widthFromCache):
+        (WebCore::RenderText::computePreferredLogicalWidths):
+        (WebCore::RenderText::width):
+        * rendering/svg/SVGInlineTextBox.cpp: Ditto.
+        (WebCore::SVGInlineTextBox::constructTextRun):
+
 2011-06-12  Robert Hogan  <[email protected]>
 
         Reviewed by Andreas Kling.

Modified: trunk/Source/WebCore/platform/graphics/Font.h (88612 => 88613)


--- trunk/Source/WebCore/platform/graphics/Font.h	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2011-06-12 12:40:40 UTC (rev 88613)
@@ -163,8 +163,8 @@
     void drawSimpleText(GraphicsContext*, const TextRun&, const FloatPoint&, int from, int to) const;
     void drawEmphasisMarksForSimpleText(GraphicsContext*, const TextRun&, const AtomicString& mark, const FloatPoint&, int from, int to) const;
     void drawGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
-    void drawGlyphBuffer(GraphicsContext*, const GlyphBuffer&, const FloatPoint&) const;
-    void drawEmphasisMarks(GraphicsContext* context, const GlyphBuffer&, const AtomicString&, const FloatPoint&) const;
+    void drawGlyphBuffer(GraphicsContext*, const TextRun&, const GlyphBuffer&, const FloatPoint&) const;
+    void drawEmphasisMarks(GraphicsContext*, const TextRun&, const GlyphBuffer&, const AtomicString&, const FloatPoint&) const;
     float floatWidthForSimpleText(const TextRun&, GlyphBuffer*, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
     int offsetForPositionForSimpleText(const TextRun&, float position, bool includePartialGlyphs) const;
     FloatRect selectionRectForSimpleText(const TextRun&, const FloatPoint&, int h, int from, int to) const;

Modified: trunk/Source/WebCore/platform/graphics/FontFastPath.cpp (88612 => 88613)


--- trunk/Source/WebCore/platform/graphics/FontFastPath.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/platform/graphics/FontFastPath.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -362,7 +362,7 @@
         return;
 
     FloatPoint startPoint(startX, point.y());
-    drawGlyphBuffer(context, glyphBuffer, startPoint);
+    drawGlyphBuffer(context, run, glyphBuffer, startPoint);
 }
 
 void Font::drawEmphasisMarksForSimpleText(GraphicsContext* context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
@@ -373,10 +373,10 @@
     if (glyphBuffer.isEmpty())
         return;
 
-    drawEmphasisMarks(context, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
+    drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
 }
 
-void Font::drawGlyphBuffer(GraphicsContext* context, const GlyphBuffer& glyphBuffer, const FloatPoint& point) const
+void Font::drawGlyphBuffer(GraphicsContext* context, const TextRun&, const GlyphBuffer& glyphBuffer, const FloatPoint& point) const
 {   
     // Draw each contiguous run of glyphs that use the same font data.
     const SimpleFontData* fontData = glyphBuffer.fontDataAt(0);
@@ -418,7 +418,7 @@
     return offsetToMiddleOfGlyph(glyphBuffer.fontDataAt(i), glyphBuffer.glyphAt(i));
 }
 
-void Font::drawEmphasisMarks(GraphicsContext* context, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) const
+void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) const
 {
     GlyphData markGlyphData;
     if (!getEmphasisMarkGlyphData(mark, markGlyphData))
@@ -444,7 +444,7 @@
     }
     markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spaceGlyph, markFontData, 0);
 
-    drawGlyphBuffer(context, markBuffer, startPoint);
+    drawGlyphBuffer(context, run, markBuffer, startPoint);
 }
 
 float Font::floatWidthForSimpleText(const TextRun& run, GlyphBuffer* glyphBuffer, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const

Modified: trunk/Source/WebCore/platform/graphics/TextRun.h (88612 => 88613)


--- trunk/Source/WebCore/platform/graphics/TextRun.h	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/platform/graphics/TextRun.h	2011-06-12 12:40:40 UTC (rev 88613)
@@ -48,6 +48,7 @@
 
     TextRun(const UChar* c, int len, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false)
         : m_characters(c)
+        , m_charactersLength(len)
         , m_len(len)
         , m_xpos(xpos)
         , m_expansion(expansion)
@@ -64,6 +65,7 @@
 
     TextRun(const String& s, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false)
         : m_characters(s.characters())
+        , m_charactersLength(s.length())
         , m_len(s.length())
         , m_xpos(xpos)
         , m_expansion(expansion)
@@ -83,8 +85,10 @@
 
     const UChar* characters() const { return m_characters; }
     int length() const { return m_len; }
+    int charactersLength() const { return m_charactersLength; }
 
     void setText(const UChar* c, int len) { m_characters = c; m_len = len; }
+    void setCharactersLength(int charactersLength) { m_charactersLength = charactersLength; }
 
 #if ENABLE(SVG)
     float horizontalGlyphStretch() const { return m_horizontalGlyphStretch; }
@@ -127,6 +131,7 @@
 
 private:
     const UChar* m_characters;
+    int m_charactersLength; // Marks the end of the m_characters buffer. Default equals to m_len.
     int m_len;
 
     // m_xpos is the x position relative to the left start of the text line, not relative to the left

Modified: trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp (88612 => 88613)


--- trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -93,7 +93,7 @@
 
     // Draw the glyph buffer now at the starting point returned in startX.
     FloatPoint startPoint(startX, point.y());
-    drawGlyphBuffer(context, glyphBuffer, startPoint);
+    drawGlyphBuffer(context, run, glyphBuffer, startPoint);
 }
 
 void Font::drawEmphasisMarksForComplexText(GraphicsContext* context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
@@ -104,7 +104,7 @@
     if (glyphBuffer.isEmpty())
         return;
 
-    drawEmphasisMarks(context, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
+    drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
 }
 
 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const

Modified: trunk/Source/WebCore/platform/graphics/win/FontWin.cpp (88612 => 88613)


--- trunk/Source/WebCore/platform/graphics/win/FontWin.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/platform/graphics/win/FontWin.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -108,7 +108,7 @@
 
     // Draw the glyph buffer now at the starting point returned in startX.
     FloatPoint startPoint(startX, point.y());
-    drawGlyphBuffer(context, glyphBuffer, startPoint);
+    drawGlyphBuffer(context, run, glyphBuffer, startPoint);
 }
 
 void Font::drawEmphasisMarksForComplexText(GraphicsContext* context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
@@ -119,7 +119,7 @@
     if (glyphBuffer.isEmpty())
         return;
 
-    drawEmphasisMarks(context, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
+    drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
 }
 
 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const

Modified: trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp (88612 => 88613)


--- trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -150,7 +150,7 @@
 
     // Draw the glyph buffer now at the starting point returned in startX.
     FloatPoint startPoint(startX, point.y());
-    drawGlyphBuffer(context, glyphBuffer, startPoint);
+    drawGlyphBuffer(context, run, glyphBuffer, startPoint);
 #else
     notImplemented();
 #endif
@@ -164,7 +164,7 @@
     if (glyphBuffer.isEmpty())
         return;
 
-    drawEmphasisMarks(context, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
+    drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
 }
 
 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*) const

Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (88612 => 88613)


--- trunk/Source/WebCore/rendering/InlineTextBox.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -1318,6 +1318,8 @@
     if (textRunNeedsRenderingContext(font))
         run.setRenderingContext(SVGTextRunRenderingContext::create(textRenderer));
 
+    // Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
+    run.setCharactersLength(textRenderer->textLength());
     return run;
 }
 

Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (88612 => 88613)


--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -1574,7 +1574,11 @@
 {
     if (isFixedPitch || (!from && len == text->textLength()) || text->style()->hasTextCombine())
         return text->width(from, len, font, xPos);
+
     TextRun run = RenderBlock::constructTextRun(text, font, text->characters() + from, len, text->style());
+    run.setCharactersLength(text->textLength() - from);
+    ASSERT(run.charactersLength() >= run.length());
+
     run.setAllowTabs(!collapseWhiteSpace);
     run.setXPos(xPos);
     return font.width(run);
@@ -1602,6 +1606,9 @@
         return;
 
     TextRun run = RenderBlock::constructTextRun(text, font, text->characters() + lastSpace, pos - lastSpace, text->style());
+    run.setCharactersLength(text->textLength() - lastSpace);
+    ASSERT(run.charactersLength() >= run.length());
+
     run.setAllowTabs(!collapseWhiteSpace);
     run.setXPos(xPos + lastSpaceWordSpacing);
 

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (88612 => 88613)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -631,6 +631,9 @@
     }
 
     TextRun run = RenderBlock::constructTextRun(const_cast<RenderText*>(this), f, text()->characters() + start, len, style());
+    run.setCharactersLength(textLength() - start);
+    ASSERT(run.charactersLength() >= run.length());
+
     run.setAllowTabs(allowTabs());
     run.setXPos(xPos);
     return f.width(run, fallbackFonts, glyphOverflow);
@@ -918,6 +921,9 @@
                 currMaxWidth = 0;
             } else {
                 TextRun run = RenderBlock::constructTextRun(this, f, txt + i, 1, style());
+                run.setCharactersLength(len - i);
+                ASSERT(run.charactersLength() >= run.length());
+
                 run.setAllowTabs(allowTabs());
                 run.setXPos(leadWidth + currMaxWidth);
 
@@ -1297,6 +1303,9 @@
             w = widthFromCache(f, from, len, xPos, fallbackFonts, glyphOverflow);
     } else {
         TextRun run = RenderBlock::constructTextRun(const_cast<RenderText*>(this), f, text()->characters() + from, len, style());
+        run.setCharactersLength(textLength() - from);
+        ASSERT(run.charactersLength() >= run.length());
+
         run.setAllowTabs(allowTabs());
         run.setXPos(xPos);
         w = f.width(run, fallbackFonts, glyphOverflow);

Modified: trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp (88612 => 88613)


--- trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2011-06-12 11:51:45 UTC (rev 88612)
+++ trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2011-06-12 12:40:40 UTC (rev 88613)
@@ -430,6 +430,10 @@
 
     // We handle letter & word spacing ourselves.
     run.disableSpacing();
+
+    // Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
+    run.setCharactersLength(text->textLength() - fragment.characterOffset);
+    ASSERT(run.charactersLength() >= run.length());
     return run;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to