[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

zimmermann at webkit.org zimmermann at webkit.org
Wed Dec 22 14:00:13 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 036d7ff4edf417c90cc06bf75ed20f7142267802
Author: zimmermann at webkit.org <zimmermann at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Oct 1 09:11:21 2010 +0000

    2010-10-01  Nikolas Zimmermann  <nzimmermann at rim.com>
    
            Reviewed by Dirk Schulze.
    
            Add SVGTextMetrics/SVGTextFragment/SVGTextChunk primitives used by the new layout engine
            https://bugs.webkit.org/show_bug.cgi?id=46964
    
            The new SVG text layout engine will use these new classes.
            1) SVGTextMetrics is used to measure either single glyphs (which may span multiple characters, when ligatures are defined) or a range of characters.
    
               -> In "single glyph" mode, it returns the width/height of the glyph, the length of the glyph (> 1, when ligatures are used) and a "Glyph" object
                  describing the glyph (name of glyph, when used together with SVG Fonts and the unicode string the glyph describes).
               -> In "range of characters" mode, it returns the width/height of the range, and its length.
    
               All measurements are done using the regular Font::floatWidth() methods, this class just encapsulates its usage for the SVG text layout engine.
    
            2) SVGTextFragment describes a fragment of text, living in a SVGInlineTextBox, which can be measured/rendered in one shot.
               It contains all necessary information to render the fragment (x/y/width/height, offset into characters() buffer for the first char of the fragment,
               length, and an arbitary transformation, holding information about rotations/scale/glyph-orientation etc.)
    
               In future the SVGTextLayoutEngine will generate SVGTextFragment objects for each SVGInlineTextBox. When painting no more measurements have to
               be performed as SVGTextFragment contains all necessary information to render text / select text etc.
    
            3) SVGTextChunk describes a SVG text chunk, which may span multiple text boxes (and in turn text fragments).
    
               Quotes from SVG spec:
               Each absolute position adjustment defines a new "text chunk". Absolute position adjustments impact text layout in the following ways:
                * Ligatures only occur when a set of characters which might map to a ligature are all in the same text chunk.
                * Each text chunk represents a separate block of text for alignment due to "text-anchor" property values.
                * Reordering of characters due to bidirectionality only occurs within a text chunk. Reordering does not happen across text chunks.
    
                An absolute position adjustment occurs in the following circumstances:
                * At the start of a <text> element
                * At the start of each <textPath> element
                * For each character within a <text>, <tspan>, <tref> and <altGlyph> element which has an "x" or "y" attribute value assigned to it explicitly
    
                After the line-layout finishes, each "text chunk" is altered according to the textLength and text-anchor processing rules
                (eg. for text-anchor="middle" moving the whole text chunk by -fragmentWidth/2, for horizontal text).
    
                SVGTextChunk is just a simple helper class, that encapsulates measuring/altering a text chunk.
    
            Doesn't affect any tests, as these classes aren't used so far.
    
            * Android.mk: Add SVGTextMetrics.*, SVGTextFragment.h, SVGTextChunk.* to build.
            * CMakeLists.txt: Ditto.
            * GNUmakefile.am: Ditto.
            * WebCore.gypi: Ditto.
            * WebCore.pro: Ditto.
            * WebCore.vcproj/WebCore.vcproj: Ditto.
            * WebCore.xcodeproj/project.pbxproj: Ditto.
            * rendering/svg/SVGTextChunk.cpp: Added.
            * rendering/svg/SVGTextChunk.h: Added.
            * rendering/svg/SVGTextFragment.h: Added.
            * rendering/svg/SVGTextMetrics.cpp: Added.
            * rendering/svg/SVGTextMetrics.h: Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68873 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index bef9a85..1653a57 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -712,8 +712,10 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	rendering/RenderSVGTextPath.cpp \
 	rendering/RenderSVGTransformableContainer.cpp \
 	rendering/RenderSVGViewportContainer.cpp \
+	rendering/svg/SVGTextChunk.cpp \
 	rendering/svg/SVGTextLayoutAttributes.cpp \
-	rendering/svg/SVGTextLayoutBuilder.cpp
+	rendering/svg/SVGTextLayoutBuilder.cpp \
+	rendering/svg/SVGTextMetrics.cpp
 endif
 
 LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
diff --git a/WebCore/CMakeLists.txt b/WebCore/CMakeLists.txt
index 5c4df82..33e82a5 100644
--- a/WebCore/CMakeLists.txt
+++ b/WebCore/CMakeLists.txt
@@ -1706,8 +1706,10 @@ IF (ENABLE_SVG)
         rendering/SVGTextQuery.cpp
         rendering/style/SVGRenderStyle.cpp
         rendering/style/SVGRenderStyleDefs.cpp
+        rendering/svg/SVGTextChunk.cpp
         rendering/svg/SVGTextLayoutAttributes.cpp
         rendering/svg/SVGTextLayoutBuilder.cpp
+        rendering/svg/SVGTextMetrics.cpp
         svg/ColorDistance.cpp
         svg/SVGAElement.cpp
         svg/SVGAltGlyphElement.cpp
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index c261b41..91f50a9 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,59 @@
+2010-10-01  Nikolas Zimmermann  <nzimmermann at rim.com>
+
+        Reviewed by Dirk Schulze.
+
+        Add SVGTextMetrics/SVGTextFragment/SVGTextChunk primitives used by the new layout engine
+        https://bugs.webkit.org/show_bug.cgi?id=46964
+
+        The new SVG text layout engine will use these new classes.
+        1) SVGTextMetrics is used to measure either single glyphs (which may span multiple characters, when ligatures are defined) or a range of characters.
+           
+           -> In "single glyph" mode, it returns the width/height of the glyph, the length of the glyph (> 1, when ligatures are used) and a "Glyph" object
+              describing the glyph (name of glyph, when used together with SVG Fonts and the unicode string the glyph describes).
+           -> In "range of characters" mode, it returns the width/height of the range, and its length.
+
+           All measurements are done using the regular Font::floatWidth() methods, this class just encapsulates its usage for the SVG text layout engine.
+
+        2) SVGTextFragment describes a fragment of text, living in a SVGInlineTextBox, which can be measured/rendered in one shot.
+           It contains all necessary information to render the fragment (x/y/width/height, offset into characters() buffer for the first char of the fragment,
+           length, and an arbitary transformation, holding information about rotations/scale/glyph-orientation etc.)
+
+           In future the SVGTextLayoutEngine will generate SVGTextFragment objects for each SVGInlineTextBox. When painting no more measurements have to
+           be performed as SVGTextFragment contains all necessary information to render text / select text etc.
+
+        3) SVGTextChunk describes a SVG text chunk, which may span multiple text boxes (and in turn text fragments).
+
+           Quotes from SVG spec:
+           Each absolute position adjustment defines a new "text chunk". Absolute position adjustments impact text layout in the following ways:
+            * Ligatures only occur when a set of characters which might map to a ligature are all in the same text chunk.
+            * Each text chunk represents a separate block of text for alignment due to "text-anchor" property values.
+            * Reordering of characters due to bidirectionality only occurs within a text chunk. Reordering does not happen across text chunks.
+
+            An absolute position adjustment occurs in the following circumstances:
+            * At the start of a <text> element
+            * At the start of each <textPath> element
+            * For each character within a <text>, <tspan>, <tref> and <altGlyph> element which has an "x" or "y" attribute value assigned to it explicitly
+
+            After the line-layout finishes, each "text chunk" is altered according to the textLength and text-anchor processing rules
+            (eg. for text-anchor="middle" moving the whole text chunk by -fragmentWidth/2, for horizontal text).
+
+            SVGTextChunk is just a simple helper class, that encapsulates measuring/altering a text chunk.
+
+        Doesn't affect any tests, as these classes aren't used so far.
+
+        * Android.mk: Add SVGTextMetrics.*, SVGTextFragment.h, SVGTextChunk.* to build.
+        * CMakeLists.txt: Ditto.
+        * GNUmakefile.am: Ditto.
+        * WebCore.gypi: Ditto.
+        * WebCore.pro: Ditto.
+        * WebCore.vcproj/WebCore.vcproj: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+        * rendering/svg/SVGTextChunk.cpp: Added.
+        * rendering/svg/SVGTextChunk.h: Added.
+        * rendering/svg/SVGTextFragment.h: Added.
+        * rendering/svg/SVGTextMetrics.cpp: Added.
+        * rendering/svg/SVGTextMetrics.h: Added.
+
 2010-10-01  Vincent Scheib  <scheib at chromium.org>
 
         Reviewed by James Robinson.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 5118f63..11f338b 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -2809,10 +2809,15 @@ webcore_sources += \
 	WebCore/rendering/SVGRootInlineBox.h \
 	WebCore/rendering/SVGShadowTreeElements.cpp \
 	WebCore/rendering/SVGShadowTreeElements.h \
+	WebCore/rendering/svg/SVGTextChunk.cpp \
+	WebCore/rendering/svg/SVGTextChunk.h \
+	WebCore/rendering/svg/SVGTextFragment.h \
 	WebCore/rendering/svg/SVGTextLayoutAttributes.cpp \
 	WebCore/rendering/svg/SVGTextLayoutAttributes.h \
 	WebCore/rendering/svg/SVGTextLayoutBuilder.cpp \
 	WebCore/rendering/svg/SVGTextLayoutBuilder.h \
+	WebCore/rendering/svg/SVGTextMetrics.cpp \
+	WebCore/rendering/svg/SVGTextMetrics.h \
 	WebCore/rendering/SVGTextChunkLayoutInfo.cpp \
 	WebCore/rendering/SVGTextChunkLayoutInfo.h \
 	WebCore/rendering/SVGTextLayoutUtilities.cpp \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index e46491f..35c9a17 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3435,10 +3435,15 @@
             'rendering/style/StyleTransformData.h',
             'rendering/style/StyleVisualData.cpp',
             'rendering/style/StyleVisualData.h',
+            'rendering/svg/SVGTextChunk.cpp',
+            'rendering/svg/SVGTextChunk.h',
+            'rendering/svg/SVGTextFragment.h',
             'rendering/svg/SVGTextLayoutAttributes.cpp',
             'rendering/svg/SVGTextLayoutAttributes.h',
             'rendering/svg/SVGTextLayoutBuilder.cpp',
             'rendering/svg/SVGTextLayoutBuilder.h',
+            'rendering/svg/SVGTextMetrics.cpp',
+            'rendering/svg/SVGTextMetrics.h',
             'rendering/AutoTableLayout.cpp',
             'rendering/AutoTableLayout.h',
             'rendering/BidiRun.cpp',
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index b6eaf8b..d0ff087 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -2294,8 +2294,11 @@ HEADERS += \
     rendering/style/StyleVisualData.h \
     rendering/style/SVGRenderStyleDefs.h \
     rendering/style/SVGRenderStyle.h \
+    rendering/svg/SVGTextChunk.h \
+    rendering/svg/SVGTextFragment.h \
     rendering/svg/SVGTextLayoutAttributes.h \
     rendering/svg/SVGTextLayoutBuilder.h \
+    rendering/svg/SVGTextMetrics.h \
     rendering/SVGCharacterData.h \
     rendering/SVGCharacterLayoutInfo.h \
     rendering/SVGImageBufferTools.h \
@@ -3275,8 +3278,10 @@ contains(DEFINES, ENABLE_SVG=1) {
         css/SVGCSSStyleSelector.cpp \
         rendering/style/SVGRenderStyle.cpp \
         rendering/style/SVGRenderStyleDefs.cpp \
+        rendering/svg/SVGTextChunk.cpp \
         rendering/svg/SVGTextLayoutAttributes.cpp \
         rendering/svg/SVGTextLayoutBuilder.cpp \
+        rendering/svg/SVGTextMetrics.cpp \
         rendering/PointerEventsHitRules.cpp \
         svg/SVGDocumentExtensions.cpp \
         svg/SVGImageLoader.cpp \
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index 3d9c403..2bd928f 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -33514,6 +33514,18 @@
 				Name="svg"
 				>
 				<File
+					RelativePath="..\rendering\svg\SVGTextChunk.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\rendering\svg\SVGTextChunk.h"
+					>
+				</File>
+				<File
+					RelativePath="..\rendering\svg\SVGTextFragment.h"
+					>
+				</File>
+				<File
 					RelativePath="..\rendering\svg\SVGTextLayoutAttributes.cpp"
 					>
 				</File>
@@ -33529,6 +33541,14 @@
 					RelativePath="..\rendering\svg\SVGTextLayoutBuilder.h"
 					>
 				</File>
+				<File
+					RelativePath="..\rendering\svg\SVGTextMetrics.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\rendering\svg\SVGTextMetrics.h"
+					>
+				</File>
 			</Filter>
 		</Filter>
 		<Filter
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 0bc4b48..407638b 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -209,6 +209,11 @@
 		08E6A2E90EEE035200AC1206 /* WMLPostfieldElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 08E6A2E70EEE035200AC1206 /* WMLPostfieldElement.h */; };
 		08E6E0F10EFF42BA00029FBF /* WMLFieldSetElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08E6E0EF0EFF42BA00029FBF /* WMLFieldSetElement.cpp */; };
 		08E6E0F20EFF42BA00029FBF /* WMLFieldSetElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 08E6E0F00EFF42BA00029FBF /* WMLFieldSetElement.h */; };
+		08F0BFC21255C53C00075185 /* SVGTextChunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08F0BFBD1255C53C00075185 /* SVGTextChunk.cpp */; };
+		08F0BFC31255C53C00075185 /* SVGTextChunk.h in Headers */ = {isa = PBXBuildFile; fileRef = 08F0BFBE1255C53C00075185 /* SVGTextChunk.h */; };
+		08F0BFC41255C53C00075185 /* SVGTextFragment.h in Headers */ = {isa = PBXBuildFile; fileRef = 08F0BFBF1255C53C00075185 /* SVGTextFragment.h */; };
+		08F0BFC51255C53C00075185 /* SVGTextMetrics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08F0BFC01255C53C00075185 /* SVGTextMetrics.cpp */; };
+		08F0BFC61255C53C00075185 /* SVGTextMetrics.h in Headers */ = {isa = PBXBuildFile; fileRef = 08F0BFC11255C53C00075185 /* SVGTextMetrics.h */; };
 		08F2F0091213E61700DCEC48 /* RenderImageResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08F2F0071213E61700DCEC48 /* RenderImageResource.cpp */; };
 		08F2F00A1213E61700DCEC48 /* RenderImageResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 08F2F0081213E61700DCEC48 /* RenderImageResource.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0A4844990CA44CB200B7BD48 /* SoftLinking.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A4844980CA44CB200B7BD48 /* SoftLinking.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -6132,6 +6137,11 @@
 		08E6A2E70EEE035200AC1206 /* WMLPostfieldElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLPostfieldElement.h; sourceTree = "<group>"; };
 		08E6E0EF0EFF42BA00029FBF /* WMLFieldSetElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WMLFieldSetElement.cpp; sourceTree = "<group>"; };
 		08E6E0F00EFF42BA00029FBF /* WMLFieldSetElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLFieldSetElement.h; sourceTree = "<group>"; };
+		08F0BFBD1255C53C00075185 /* SVGTextChunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextChunk.cpp; sourceTree = "<group>"; };
+		08F0BFBE1255C53C00075185 /* SVGTextChunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextChunk.h; sourceTree = "<group>"; };
+		08F0BFBF1255C53C00075185 /* SVGTextFragment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextFragment.h; sourceTree = "<group>"; };
+		08F0BFC01255C53C00075185 /* SVGTextMetrics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextMetrics.cpp; sourceTree = "<group>"; };
+		08F0BFC11255C53C00075185 /* SVGTextMetrics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextMetrics.h; sourceTree = "<group>"; };
 		08F2F0071213E61700DCEC48 /* RenderImageResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderImageResource.cpp; sourceTree = "<group>"; };
 		08F2F0081213E61700DCEC48 /* RenderImageResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderImageResource.h; sourceTree = "<group>"; };
 		08FB84B00ECE373300DC064E /* WMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WMLElementFactory.cpp; sourceTree = "<group>"; };
@@ -11628,10 +11638,15 @@
 		088C2F7412390080003D65CE /* svg */ = {
 			isa = PBXGroup;
 			children = (
+				08F0BFBD1255C53C00075185 /* SVGTextChunk.cpp */,
+				08F0BFBE1255C53C00075185 /* SVGTextChunk.h */,
+				08F0BFBF1255C53C00075185 /* SVGTextFragment.h */,
 				088C2F7512390080003D65CE /* SVGTextLayoutAttributes.cpp */,
 				088C2F7612390080003D65CE /* SVGTextLayoutAttributes.h */,
 				088C2F7712390081003D65CE /* SVGTextLayoutBuilder.cpp */,
 				088C2F7812390081003D65CE /* SVGTextLayoutBuilder.h */,
+				08F0BFC01255C53C00075185 /* SVGTextMetrics.cpp */,
+				08F0BFC11255C53C00075185 /* SVGTextMetrics.h */,
 			);
 			path = svg;
 			sourceTree = "<group>";
@@ -20919,6 +20934,9 @@
 				49B69E601254FEED007D57EB /* LoopBlinnConstants.h in Headers */,
 				49B69E641254FEED007D57EB /* LoopBlinnMathUtils.h in Headers */,
 				49B69E661254FEED007D57EB /* LoopBlinnTextureCoords.h in Headers */,
+				08F0BFC31255C53C00075185 /* SVGTextChunk.h in Headers */,
+				08F0BFC41255C53C00075185 /* SVGTextFragment.h in Headers */,
+				08F0BFC61255C53C00075185 /* SVGTextMetrics.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -23443,6 +23461,8 @@
 				49B69E5E1254FEED007D57EB /* LoopBlinnClassifier.cpp in Sources */,
 				49B69E631254FEED007D57EB /* LoopBlinnMathUtils.cpp in Sources */,
 				49B69E651254FEED007D57EB /* LoopBlinnTextureCoords.cpp in Sources */,
+				08F0BFC21255C53C00075185 /* SVGTextChunk.cpp in Sources */,
+				08F0BFC51255C53C00075185 /* SVGTextMetrics.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebCore/rendering/svg/SVGTextChunk.cpp b/WebCore/rendering/svg/SVGTextChunk.cpp
new file mode 100644
index 0000000..a25a584
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextChunk.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "SVGTextChunk.h"
+
+#include "SVGInlineTextBox.h"
+#include "SVGTextFragment.h"
+
+#include <wtf/UnusedParam.h>
+
+namespace WebCore {
+
+// FIXME: Rename to SVGTextChunk, once the new layout engine has landed.
+SVGTextChunkNew::SVGTextChunkNew(bool isVerticalText, ETextAnchor textAnchor, SVGTextContentElement::SVGLengthAdjustType lengthAdjust, float desiredTextLength)
+    : m_isVerticalText(isVerticalText)
+    , m_textAnchor(textAnchor)
+    , m_lengthAdjust(lengthAdjust)
+    , m_desiredTextLength(desiredTextLength)
+{
+}
+
+void SVGTextChunkNew::calculateLength(float& length, unsigned& characters) const
+{
+    SVGTextFragment* lastFragment = 0;
+
+    unsigned boxCount = m_boxes.size();
+    for (unsigned boxPosition = 0; boxPosition < boxCount; ++boxPosition) {
+        SVGInlineTextBox* textBox = m_boxes.at(boxPosition);
+
+        // FIXME: Enable this code, once the new layout engine has landed! This is nonfunctional for now.
+        // Vector<SVGTextFragment>& fragments = textBox->textFragments();
+        Vector<SVGTextFragment> fragments;
+        UNUSED_PARAM(textBox);
+
+        unsigned size = fragments.size();
+        if (!size)
+            continue;
+
+        for (unsigned i = 0; i < size; ++i) {
+            SVGTextFragment& fragment = fragments.at(i);
+            characters += fragment.length;
+
+            if (m_isVerticalText)
+                length += fragment.height;
+            else
+                length += fragment.width;
+
+            if (!lastFragment) {
+                lastFragment = &fragment;
+                continue;
+            }
+
+            // Resepect gap between chunks.
+            if (m_isVerticalText)
+                 length += fragment.y - (lastFragment->y + lastFragment->height);
+            else
+                 length += fragment.x - (lastFragment->x + lastFragment->width);
+
+            lastFragment = &fragment;
+        }
+    }
+}
+
+float SVGTextChunkNew::calculateTextAnchorShift(float length) const
+{
+    switch (m_textAnchor) {
+    case TA_START:
+        return 0;
+    case TA_MIDDLE:
+        return -length / 2;
+    case TA_END:
+        return -length;
+    };
+
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/rendering/svg/SVGTextChunk.h b/WebCore/rendering/svg/SVGTextChunk.h
new file mode 100644
index 0000000..ec00901
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextChunk.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SVGTextChunk_h
+#define SVGTextChunk_h
+
+#if ENABLE(SVG)
+#include "SVGRenderStyleDefs.h"
+#include "SVGTextContentElement.h"
+
+namespace WebCore {
+
+class SVGInlineTextBox;
+
+// A SVGTextChunk describes a range of SVGTextFragments, see the SVG spec definition of a "text chunk".
+// FIXME: Rename to SVGTextChunk, once the new layout engine has landed.
+class SVGTextChunkNew {
+public:
+    SVGTextChunkNew(bool isVerticalText, ETextAnchor, SVGTextContentElement::SVGLengthAdjustType, float desiredTextLength);
+
+    void calculateLength(float& length, unsigned& characters) const;
+    float calculateTextAnchorShift(float length) const;
+
+    bool isVerticalText() const { return m_isVerticalText; }
+    ETextAnchor textAnchor() const { return m_textAnchor; }
+    SVGTextContentElement::SVGLengthAdjustType lengthAdjust() const { return m_lengthAdjust; }
+    float desiredTextLength() const { return m_desiredTextLength; }
+
+    Vector<SVGInlineTextBox*>& boxes() { return m_boxes; }
+    const Vector<SVGInlineTextBox*>& boxes() const { return m_boxes; }
+
+    bool hasDesiredTextLength() const { return m_lengthAdjust != SVGTextContentElement::LENGTHADJUST_UNKNOWN && m_desiredTextLength > 0; } 
+    bool hasTextAnchor() const { return m_textAnchor != TA_START; }
+
+private:
+    // Contains all SVGInlineTextBoxes this chunk spans.
+    Vector<SVGInlineTextBox*> m_boxes;
+
+    // writing-mode specific property.
+    bool m_isVerticalText;
+
+    // text-anchor specific properties.
+    ETextAnchor m_textAnchor;
+
+    // textLength/lengthAdjust specific properties.
+    SVGTextContentElement::SVGLengthAdjustType m_lengthAdjust;
+    float m_desiredTextLength;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif
diff --git a/WebCore/rendering/svg/SVGTextFragment.h b/WebCore/rendering/svg/SVGTextFragment.h
new file mode 100644
index 0000000..88163aa
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextFragment.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SVGTextFragment_h
+#define SVGTextFragment_h
+
+#if ENABLE(SVG)
+#include "AffineTransform.h"
+
+namespace WebCore {
+
+// A SVGTextFragment describes a text fragment of a RenderSVGInlineText which can be rendered at once.
+struct SVGTextFragment {
+    SVGTextFragment()
+        : positionListOffset(0)
+        , length(0)
+        , x(0)
+        , y(0)
+        , width(0)
+        , height(0)
+    {
+    }
+
+    // The first rendered character starts at RenderSVGInlineText::characters() + positionListOffset.
+    unsigned positionListOffset;
+    unsigned length;
+
+    float x;
+    float y;
+    float width;
+    float height;
+
+    // Includes rotation/glyph-orientation-(horizontal|vertical) transforms, lengthAdjust="spacingAndGlyphs" (for textPath only),
+    // as well as orientation related shifts (see SVGCharacterLayoutBuilder, which builds this transformation).
+    AffineTransform transform;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif
diff --git a/WebCore/rendering/svg/SVGTextMetrics.cpp b/WebCore/rendering/svg/SVGTextMetrics.cpp
new file mode 100644
index 0000000..b09f6e8
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextMetrics.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "SVGTextMetrics.h"
+
+#include "RenderSVGInlineText.h"
+
+namespace WebCore {
+
+SVGTextMetrics::SVGTextMetrics()
+    : m_width(0)
+    , m_height(0)
+    , m_length(0)
+{
+}
+
+SVGTextMetrics::SVGTextMetrics(const Font& font, const TextRun& run, unsigned position, unsigned textLength)
+    : m_width(0)
+    , m_height(0)
+    , m_length(0)
+{
+    int extraCharsAvailable = textLength - (position + run.length());
+    int length = 0;
+
+    m_width = font.floatWidth(run, extraCharsAvailable, length, m_glyph.name);
+    m_height = font.height();
+    m_glyph.unicodeString = String(run.characters(), length);
+    m_glyph.isValid = true;
+
+    ASSERT(length >= 0);
+    m_length = static_cast<unsigned>(length);
+}
+
+bool SVGTextMetrics::operator==(const SVGTextMetrics& other)
+{
+    return m_width == other.m_width
+        && m_height == other.m_height
+        && m_length == other.m_length
+        && m_glyph == other.m_glyph;
+}
+
+SVGTextMetrics SVGTextMetrics::emptyMetrics()
+{
+    DEFINE_STATIC_LOCAL(SVGTextMetrics, s_emptyMetrics, ());
+    s_emptyMetrics.m_length = 1;
+    return s_emptyMetrics;
+}
+
+SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text, unsigned position, unsigned length)
+{
+    ASSERT(text);
+    ASSERT(text->style());
+
+    const Font& font = text->style()->font();
+    const UChar* characters = text->characters();
+
+    TextRun run(characters + position, length);
+    run.disableSpacing();
+    run.disableRoundingHacks();
+
+    return SVGTextMetrics(font, run, position, text->textLength());
+}
+
+void SVGTextMetrics::measureAllCharactersIndividually(RenderSVGInlineText* text, Vector<SVGTextMetrics>& allMetrics)
+{
+    ASSERT(text);
+    ASSERT(text->style());
+
+    const Font& font = text->style()->font();
+    const UChar* characters = text->characters();
+    unsigned length = text->textLength();
+
+    TextRun run(0, 0);
+    run.disableSpacing();
+    run.disableRoundingHacks();
+
+    for (unsigned position = 0; position < length; ) {
+        run.setText(characters + position, 1);
+
+        SVGTextMetrics metrics(font, run, position, text->textLength());
+        allMetrics.append(metrics);
+        position += metrics.length();
+    }
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/rendering/svg/SVGTextMetrics.h b/WebCore/rendering/svg/SVGTextMetrics.h
new file mode 100644
index 0000000..ba18589
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextMetrics.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SVGTextMetrics_h
+#define SVGTextMetrics_h
+
+#if ENABLE(SVG)
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Font;
+class RenderSVGInlineText;
+class TextRun;
+
+class SVGTextMetrics {
+public:
+    static SVGTextMetrics emptyMetrics();
+    static SVGTextMetrics measureCharacterRange(RenderSVGInlineText*, unsigned position, unsigned length);
+    static void measureAllCharactersIndividually(RenderSVGInlineText*, Vector<SVGTextMetrics>&);
+
+    bool operator==(const SVGTextMetrics&);
+
+    float width() const { return m_width; }
+    float height() const { return m_height; }
+    unsigned length() const { return m_length; }
+
+    struct Glyph {
+        Glyph()
+            : isValid(false)
+        {
+        }
+
+        bool operator==(const Glyph& other)
+        {
+            return isValid == other.isValid
+                && name == other.name
+                && unicodeString == other.unicodeString;
+        }
+
+        bool isValid;
+        String name;
+        String unicodeString;
+    };
+
+    // Only useful when measuring individual characters, to lookup ligatures.
+    const Glyph& glyph() const { return m_glyph; }
+
+private:
+    SVGTextMetrics();
+    SVGTextMetrics(const Font&, const TextRun&, unsigned position, unsigned textLength);
+
+    float m_width;
+    float m_height;
+    unsigned m_length;
+    Glyph m_glyph;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list