[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:47 UTC 2010


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

    2010-10-01  Nikolas Zimmermann  <nzimmermann at rim.com>
    
            Reviewed by Dirk Schulze.
    
            Add two new helper files for the new SVGTextLayoutEngine
            https://bugs.webkit.org/show_bug.cgi?id=46972
    
            Refactor code from SVGTextLayoutUtilities into two seperated classes.
            SVGTextLayoutUtilities will be removed, as soon as the main clss SVGTextLayoutEngine lands and gets used.
    
            Doesn't affect any functionality yet, as the new classes are not used so far.
    
            * Android.mk:
            * CMakeLists.txt:
            * GNUmakefile.am:
            * WebCore.gypi:
            * WebCore.vcproj/WebCore.vcproj:
            * WebCore.xcodeproj/project.pbxproj:
            * rendering/svg/SVGTextFragment.h:
            * rendering/svg/SVGTextLayoutEngineBaseline.cpp: Added.
            (WebCore::SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline):
            (WebCore::SVGTextLayoutEngineBaseline::calculateBaselineShift):
            (WebCore::SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline):
            (WebCore::SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift):
            (WebCore::SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle):
            (WebCore::glyphOrientationIsMultiplyOf180Degrees):
            (WebCore::SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation):
            * rendering/svg/SVGTextLayoutEngineBaseline.h: Added.
            * rendering/svg/SVGTextLayoutEngineSpacing.cpp: Added.
            (WebCore::SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing):
            (WebCore::SVGTextLayoutEngineSpacing::calculateSVGKerning):
            (WebCore::SVGTextLayoutEngineSpacing::calculateCSSKerningAndSpacing):
            * rendering/svg/SVGTextLayoutEngineSpacing.h: Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68878 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index dd25a47..f9dc842 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -718,6 +718,8 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	rendering/svg/SVGTextChunk.cpp \
 	rendering/svg/SVGTextLayoutAttributes.cpp \
 	rendering/svg/SVGTextLayoutAttributesBuilder.cpp \
+	rendering/svg/SVGTextLayoutEngineBaseline.cpp \
+	rendering/svg/SVGTextLayoutEngineSpacing.cpp \
 	rendering/svg/SVGTextMetrics.cpp \
 	rendering/svg/SVGTextQuery.cpp
 endif
diff --git a/WebCore/CMakeLists.txt b/WebCore/CMakeLists.txt
index b54bd0b..410d59b 100644
--- a/WebCore/CMakeLists.txt
+++ b/WebCore/CMakeLists.txt
@@ -1708,6 +1708,8 @@ IF (ENABLE_SVG)
         rendering/svg/SVGTextChunk.cpp
         rendering/svg/SVGTextLayoutAttributes.cpp
         rendering/svg/SVGTextLayoutAttributesBuilder.cpp
+        rendering/svg/SVGTextLayoutBaseline.cpp
+        rendering/svg/SVGTextLayoutSpacing.cpp
         rendering/svg/SVGTextMetrics.cpp
         rendering/svg/SVGTextQuery.cpp
         svg/ColorDistance.cpp
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index e7578c2..5d838a5 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,5 +1,39 @@
 2010-10-01  Nikolas Zimmermann  <nzimmermann at rim.com>
 
+        Reviewed by Dirk Schulze.
+
+        Add two new helper files for the new SVGTextLayoutEngine
+        https://bugs.webkit.org/show_bug.cgi?id=46972
+
+        Refactor code from SVGTextLayoutUtilities into two seperated classes.
+        SVGTextLayoutUtilities will be removed, as soon as the main clss SVGTextLayoutEngine lands and gets used.
+
+        Doesn't affect any functionality yet, as the new classes are not used so far.
+
+        * Android.mk:
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/svg/SVGTextFragment.h:
+        * rendering/svg/SVGTextLayoutEngineBaseline.cpp: Added.
+        (WebCore::SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline):
+        (WebCore::SVGTextLayoutEngineBaseline::calculateBaselineShift):
+        (WebCore::SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline):
+        (WebCore::SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift):
+        (WebCore::SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle):
+        (WebCore::glyphOrientationIsMultiplyOf180Degrees):
+        (WebCore::SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation):
+        * rendering/svg/SVGTextLayoutEngineBaseline.h: Added.
+        * rendering/svg/SVGTextLayoutEngineSpacing.cpp: Added.
+        (WebCore::SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing):
+        (WebCore::SVGTextLayoutEngineSpacing::calculateSVGKerning):
+        (WebCore::SVGTextLayoutEngineSpacing::calculateCSSKerningAndSpacing):
+        * rendering/svg/SVGTextLayoutEngineSpacing.h: Added.
+
+2010-10-01  Nikolas Zimmermann  <nzimmermann at rim.com>
+
         Reviewed by Andreas Kling.
 
         Rename SVGTextLayoutBuilder to SVGTextLayoutAttributesBuilder
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index e46d7a9..a743983 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -2816,6 +2816,10 @@ webcore_sources += \
 	WebCore/rendering/svg/SVGTextLayoutAttributes.h \
 	WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp \
 	WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.h \
+	WebCore/rendering/svg/SVGTextLayoutEngineBaseline.cpp \
+	WebCore/rendering/svg/SVGTextLayoutEngineBaseline.h \
+	WebCore/rendering/svg/SVGTextLayoutEngineSpacing.cpp \
+	WebCore/rendering/svg/SVGTextLayoutEngineSpacing.h \
 	WebCore/rendering/svg/SVGTextMetrics.cpp \
 	WebCore/rendering/svg/SVGTextMetrics.h \
 	WebCore/rendering/svg/SVGTextQuery.cpp \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index f346dab..e9aef7b 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3458,6 +3458,10 @@
             'rendering/svg/SVGTextLayoutAttributes.h',
             'rendering/svg/SVGTextLayoutAttributesBuilder.cpp',
             'rendering/svg/SVGTextLayoutAttributesBuilder.h',
+            'rendering/svg/SVGTextLayoutEngineBaseline.cpp',
+            'rendering/svg/SVGTextLayoutEngineBaseline.h',
+            'rendering/svg/SVGTextLayoutEngineSpacing.cpp',
+            'rendering/svg/SVGTextLayoutEngineSpacing.h',
             'rendering/svg/SVGTextMetrics.cpp',
             'rendering/svg/SVGTextMetrics.h',
             'rendering/svg/SVGTextQuery.cpp',
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index 7a75d37..2c8d9b4 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -33486,6 +33486,22 @@
 					>
 				</File>
 				<File
+					RelativePath="..\rendering\svg\SVGTextLayoutEngineBaseline.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\rendering\svg\SVGTextLayoutEngineBaseline.h"
+					>
+				</File>
+				<File
+					RelativePath="..\rendering\svg\SVGTextLayoutEngineSpacing.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\rendering\svg\SVGTextLayoutEngineSpacing.h"
+					>
+				</File>
+				<File
 					RelativePath="..\rendering\svg\SVGTextMetrics.cpp"
 					>
 				</File>
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 9c38c01..9000726 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -64,6 +64,10 @@
 		080AEC820ED8708B00DF4CCE /* WMLIntrinsicEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 080AEC7E0ED8708B00DF4CCE /* WMLIntrinsicEvent.h */; };
 		080AEC830ED8708B00DF4CCE /* WMLIntrinsicEventHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 080AEC7F0ED8708B00DF4CCE /* WMLIntrinsicEventHandler.cpp */; };
 		080AEC840ED8708B00DF4CCE /* WMLIntrinsicEventHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 080AEC800ED8708B00DF4CCE /* WMLIntrinsicEventHandler.h */; };
+		080E49251255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 080E49211255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.cpp */; };
+		080E49261255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h in Headers */ = {isa = PBXBuildFile; fileRef = 080E49221255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h */; };
+		080E49271255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 080E49231255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.cpp */; };
+		080E49281255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.h in Headers */ = {isa = PBXBuildFile; fileRef = 080E49241255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.h */; };
 		080FAE1A0EEEBDA800AACDE9 /* WMLTemplateElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 080FAE180EEEBDA800AACDE9 /* WMLTemplateElement.cpp */; };
 		080FAE1B0EEEBDA800AACDE9 /* WMLTemplateElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 080FAE190EEEBDA800AACDE9 /* WMLTemplateElement.h */; };
 		081093DB1255F0E700ED9D29 /* SVGTextLayoutAttributesBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 081093D91255F0E700ED9D29 /* SVGTextLayoutAttributesBuilder.cpp */; };
@@ -6007,6 +6011,10 @@
 		080AEC7E0ED8708B00DF4CCE /* WMLIntrinsicEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLIntrinsicEvent.h; sourceTree = "<group>"; };
 		080AEC7F0ED8708B00DF4CCE /* WMLIntrinsicEventHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WMLIntrinsicEventHandler.cpp; sourceTree = "<group>"; };
 		080AEC800ED8708B00DF4CCE /* WMLIntrinsicEventHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLIntrinsicEventHandler.h; sourceTree = "<group>"; };
+		080E49211255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextLayoutEngineBaseline.cpp; sourceTree = "<group>"; };
+		080E49221255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextLayoutEngineBaseline.h; sourceTree = "<group>"; };
+		080E49231255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextLayoutEngineSpacing.cpp; sourceTree = "<group>"; };
+		080E49241255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextLayoutEngineSpacing.h; sourceTree = "<group>"; };
 		080FAE180EEEBDA800AACDE9 /* WMLTemplateElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WMLTemplateElement.cpp; sourceTree = "<group>"; };
 		080FAE190EEEBDA800AACDE9 /* WMLTemplateElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLTemplateElement.h; sourceTree = "<group>"; };
 		081093D91255F0E700ED9D29 /* SVGTextLayoutAttributesBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextLayoutAttributesBuilder.cpp; sourceTree = "<group>"; };
@@ -11661,6 +11669,10 @@
 				088C2F7612390080003D65CE /* SVGTextLayoutAttributes.h */,
 				081093D91255F0E700ED9D29 /* SVGTextLayoutAttributesBuilder.cpp */,
 				081093DA1255F0E700ED9D29 /* SVGTextLayoutAttributesBuilder.h */,
+				080E49211255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.cpp */,
+				080E49221255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h */,
+				080E49231255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.cpp */,
+				080E49241255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.h */,
 				08F0BFC01255C53C00075185 /* SVGTextMetrics.cpp */,
 				08F0BFC11255C53C00075185 /* SVGTextMetrics.h */,
 				0854B0121255E4E600B9CDD0 /* SVGTextQuery.cpp */,
@@ -20937,6 +20949,8 @@
 				0854B0231255E4E600B9CDD0 /* SVGRootInlineBox.h in Headers */,
 				0854B0251255E4E600B9CDD0 /* SVGTextQuery.h in Headers */,
 				081093DC1255F0E700ED9D29 /* SVGTextLayoutAttributesBuilder.h in Headers */,
+				080E49261255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h in Headers */,
+				080E49281255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -23463,6 +23477,8 @@
 				0854B0221255E4E600B9CDD0 /* SVGRootInlineBox.cpp in Sources */,
 				0854B0241255E4E600B9CDD0 /* SVGTextQuery.cpp in Sources */,
 				081093DB1255F0E700ED9D29 /* SVGTextLayoutAttributesBuilder.cpp in Sources */,
+				080E49251255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.cpp in Sources */,
+				080E49271255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebCore/rendering/svg/SVGTextFragment.h b/WebCore/rendering/svg/SVGTextFragment.h
index 88163aa..2e520da 100644
--- a/WebCore/rendering/svg/SVGTextFragment.h
+++ b/WebCore/rendering/svg/SVGTextFragment.h
@@ -47,7 +47,7 @@ struct SVGTextFragment {
     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).
+    // as well as orientation related shifts (see SVGTextLayoutEngine, which builds this transformation).
     AffineTransform transform;
 };
 
diff --git a/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.cpp b/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.cpp
new file mode 100644
index 0000000..7060ac6
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.cpp
@@ -0,0 +1,234 @@
+/*
+ * 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 "SVGTextLayoutEngineBaseline.h"
+
+#include "Font.h"
+#include "RenderObject.h"
+#include "SVGRenderStyle.h"
+#include "SVGTextMetrics.h"
+#include "UnicodeRange.h"
+
+namespace WebCore {
+
+SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font)
+    : m_font(font)
+{
+}
+
+float SVGTextLayoutEngineBaseline::calculateBaselineShift(const SVGRenderStyle* style, SVGElement* lengthContext) const
+{
+    if (style->baselineShift() == BS_LENGTH) {
+        SVGLength baselineShiftValueLength = style->baselineShiftValue();
+        if (baselineShiftValueLength.unitType() == LengthTypePercentage)
+            return baselineShiftValueLength.valueAsPercentage() * m_font.pixelSize();
+
+        return baselineShiftValueLength.value(lengthContext);
+    }
+
+    switch (style->baselineShift()) {
+    case BS_BASELINE:
+        return 0;
+    case BS_SUB:
+        return -m_font.height() / 2;
+    case BS_SUPER:
+        return m_font.height() / 2;
+    default:
+        ASSERT_NOT_REACHED();
+        return 0;
+    }
+}
+
+EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline(bool isVerticalText, const RenderObject* textRenderer) const
+{
+    ASSERT(textRenderer);
+    ASSERT(textRenderer->style());
+    ASSERT(textRenderer->parent());
+    ASSERT(textRenderer->parent()->style());
+
+    const SVGRenderStyle* style = textRenderer->style()->svgStyle();
+    ASSERT(style);
+
+    EDominantBaseline baseline = style->dominantBaseline();
+    if (baseline == DB_AUTO) {
+        if (isVerticalText)
+            baseline = DB_CENTRAL;
+        else
+            baseline = DB_ALPHABETIC;
+    }
+
+    switch (baseline) {
+    case DB_USE_SCRIPT:
+        // FIXME: The dominant-baseline and the baseline-table components are set by determining the predominant script of the character data content.
+        return AB_ALPHABETIC;
+    case DB_NO_CHANGE:
+        return dominantBaselineToAlignmentBaseline(isVerticalText, textRenderer->parent());
+    case DB_RESET_SIZE:
+        return dominantBaselineToAlignmentBaseline(isVerticalText, textRenderer->parent());
+    case DB_IDEOGRAPHIC:
+        return AB_IDEOGRAPHIC;
+    case DB_ALPHABETIC:
+        return AB_ALPHABETIC;
+    case DB_HANGING:
+        return AB_HANGING;
+    case DB_MATHEMATICAL:
+        return AB_MATHEMATICAL;
+    case DB_CENTRAL:
+        return AB_CENTRAL;
+    case DB_MIDDLE:
+        return AB_MIDDLE;
+    case DB_TEXT_AFTER_EDGE:
+        return AB_TEXT_AFTER_EDGE;
+    case DB_TEXT_BEFORE_EDGE:
+        return AB_TEXT_BEFORE_EDGE;
+    default:
+        ASSERT_NOT_REACHED();
+        return AB_AUTO;
+    }
+}
+
+float SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift(bool isVerticalText, const RenderObject* textRenderer) const
+{
+    ASSERT(textRenderer);
+    ASSERT(textRenderer->style());
+    ASSERT(textRenderer->style()->svgStyle());
+    ASSERT(textRenderer->parent());
+
+    const RenderObject* textRendererParent = textRenderer->parent();
+    ASSERT(textRendererParent);
+
+    EAlignmentBaseline baseline = textRenderer->style()->svgStyle()->alignmentBaseline();
+    if (baseline == AB_AUTO) {
+        baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textRendererParent);
+        ASSERT(baseline != AB_AUTO);
+    }
+
+    // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling
+    switch (baseline) {
+    case AB_BASELINE:
+        return dominantBaselineToAlignmentBaseline(isVerticalText, textRendererParent);
+    case AB_BEFORE_EDGE:
+    case AB_TEXT_BEFORE_EDGE:
+        return m_font.ascent();
+    case AB_MIDDLE:
+        return m_font.xHeight() / 2;
+    case AB_CENTRAL:
+        return (m_font.ascent() - m_font.descent()) / 2;
+    case AB_AFTER_EDGE:
+    case AB_TEXT_AFTER_EDGE:
+    case AB_IDEOGRAPHIC:
+        return m_font.descent();
+    case AB_ALPHABETIC:
+        return 0;
+    case AB_HANGING:
+        return m_font.ascent() * 8 / 10.f;
+    case AB_MATHEMATICAL:
+        return m_font.ascent() / 2;
+    default:
+        ASSERT_NOT_REACHED();
+        return 0;
+    }
+}
+
+float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVerticalText, const SVGRenderStyle* style, const UChar& character) const
+{
+    ASSERT(style);
+
+    switch (isVerticalText ? style->glyphOrientationVertical() : style->glyphOrientationHorizontal()) {
+    case GO_AUTO:
+    {
+        // Spec: Fullwidth ideographic and fullwidth Latin text will be set with a glyph-orientation of 0-degrees.
+        // Text which is not fullwidth will be set with a glyph-orientation of 90-degrees.
+        unsigned int unicodeRange = findCharUnicodeRange(character);
+        if (unicodeRange == cRangeSetLatin || unicodeRange == cRangeArabic)
+            return 90;
+
+        return 0;
+    }
+    case GO_90DEG:
+        return 90;
+    case GO_180DEG:
+        return 180;
+    case GO_270DEG:
+        return 270;
+    case GO_0DEG:
+    default:
+        return 0;
+    }
+}
+
+static inline bool glyphOrientationIsMultiplyOf180Degrees(float orientationAngle)
+{
+    return !fabsf(fmodf(orientationAngle, 180));
+}
+
+float SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation(bool isVerticalText, SVGTextMetrics& metrics, float angle, float& xOrientationShift, float& yOrientationShift) const
+{
+    bool orientationIsMultiplyOf180Degrees = glyphOrientationIsMultiplyOf180Degrees(angle);
+
+    // The function is based on spec requirements:
+    //
+    // Spec: If the 'glyph-orientation-horizontal' results in an orientation angle that is not a multiple of
+    // of 180 degrees, then the current text position is incremented according to the vertical metrics of the glyph.
+    //
+    // Spec: If if the 'glyph-orientation-vertical' results in an orientation angle that is not a multiple of
+    // 180 degrees, then the current text position is incremented according to the horizontal metrics of the glyph.
+
+    // Vertical orientation handling.
+    if (isVerticalText) {
+        float ascentMinusDescent = m_font.ascent() - m_font.descent();
+        if (!angle) {
+            xOrientationShift = (ascentMinusDescent - metrics.width()) / 2;
+            yOrientationShift = m_font.ascent();
+        } else if (angle == 180)
+            xOrientationShift = (ascentMinusDescent + metrics.width()) / 2;
+        else if (angle == 270) {
+            yOrientationShift = metrics.width();
+            xOrientationShift = ascentMinusDescent;
+        }
+
+        // Vertical advance calculation.
+        if (angle && !orientationIsMultiplyOf180Degrees)
+            return metrics.width();
+
+        return metrics.height();
+    }
+
+    // Horizontal orientation handling.
+    if (angle == 90)
+        yOrientationShift = -metrics.width();
+    else if (angle == 180) {
+        xOrientationShift = metrics.width();
+        yOrientationShift = -m_font.ascent();
+    } else if (angle == 270)
+        xOrientationShift = metrics.width();
+
+    // Horizontal advance calculation.
+    if (angle && !orientationIsMultiplyOf180Degrees)
+        return metrics.height();
+
+    return metrics.width();
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.h b/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.h
new file mode 100644
index 0000000..d753b39
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.h
@@ -0,0 +1,54 @@
+/*
+ * 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 SVGTextLayoutEngineBaseline_h
+#define SVGTextLayoutEngineBaseline_h
+
+#if ENABLE(SVG)
+#include "SVGRenderStyleDefs.h"
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+class Font;
+class RenderObject;
+class SVGElement;
+class SVGRenderStyle;
+class SVGTextMetrics;
+
+// Helper class used by SVGTextLayoutEngine to handle 'alignment-baseline' / 'dominant-baseline' and 'baseline-shift'.
+class SVGTextLayoutEngineBaseline : public Noncopyable {
+public:
+    SVGTextLayoutEngineBaseline(const Font&);
+
+    float calculateBaselineShift(const SVGRenderStyle*, SVGElement* lengthContext) const;
+    float calculateAlignmentBaselineShift(bool isVerticalText, const RenderObject* textRenderer) const;
+    float calculateGlyphOrientationAngle(bool isVerticalText, const SVGRenderStyle*, const UChar& character) const;
+    float calculateGlyphAdvanceAndOrientation(bool isVerticalText, SVGTextMetrics&, float angle, float& xOrientationShift, float& yOrientationShift) const;
+
+private:
+    EAlignmentBaseline dominantBaselineToAlignmentBaseline(bool isVerticalText, const RenderObject* textRenderer) const;
+
+    const Font& m_font;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif
diff --git a/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.cpp b/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.cpp
new file mode 100644
index 0000000..6c54b67
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.cpp
@@ -0,0 +1,96 @@
+/*
+ * 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 "SVGTextLayoutEngineSpacing.h"
+
+#include "Font.h"
+#include "SVGRenderStyle.h"
+
+#if ENABLE(SVG_FONTS)
+#include "SVGFontElement.h"
+#endif
+
+namespace WebCore {
+
+SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font)
+    : m_font(font)
+    , m_lastCharacter(0)
+{
+}
+
+float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, const SVGTextMetrics::Glyph& currentGlyph)
+{
+#if ENABLE(SVG_FONTS)
+    if (!m_font.isSVGFont()) {
+        m_lastGlyph.isValid = false;
+        return 0;
+    }
+
+    SVGFontElement* svgFont = m_font.svgFont();
+    ASSERT(svgFont);
+
+    float kerning = 0;
+    if (m_lastGlyph.isValid) {
+        if (isVerticalText)
+            kerning = svgFont->verticalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name);
+        else
+            kerning = svgFont->horizontalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name);
+    }
+
+    m_lastGlyph = currentGlyph;
+    m_lastGlyph.isValid = true;
+    kerning *= m_font.size() / m_font.primaryFont()->unitsPerEm();
+    return kerning;
+#else
+    UNUSED_PARAM(isVerticalText);
+    UNUSED_PARAM(currentGlyph);
+    return false;
+#endif
+}
+
+float SVGTextLayoutEngineSpacing::calculateCSSKerningAndSpacing(const SVGRenderStyle* style, SVGElement* lengthContext, const UChar* currentCharacter)
+{
+    float kerning = 0;
+    SVGLength kerningLength = style->kerning();
+    if (kerningLength.unitType() == LengthTypePercentage)
+        kerning = kerningLength.valueAsPercentage() * m_font.pixelSize();
+    else
+        kerning = kerningLength.value(lengthContext);
+
+    const UChar* lastCharacter = m_lastCharacter;
+    m_lastCharacter = currentCharacter;
+
+    if (!kerning && !m_font.letterSpacing() && !m_font.wordSpacing())
+        return 0;
+
+    float spacing = m_font.letterSpacing() + kerning;
+    if (currentCharacter && lastCharacter && m_font.wordSpacing()) {
+        if (Font::treatAsSpace(*currentCharacter) && !Font::treatAsSpace(*lastCharacter))
+            spacing += m_font.wordSpacing();
+    }
+
+    return spacing;
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.h b/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.h
new file mode 100644
index 0000000..0a6d736
--- /dev/null
+++ b/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.h
@@ -0,0 +1,52 @@
+/*
+ * 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 SVGTextLayoutEngineSpacing_h
+#define SVGTextLayoutEngineSpacing_h
+
+#if ENABLE(SVG)
+#include "SVGTextMetrics.h"
+
+namespace WebCore {
+
+class Font;
+class SVGRenderStyle;
+class SVGElement;
+
+// Helper class used by SVGTextLayoutEngine to handle 'kerning' / 'letter-spacing' and 'word-spacing'.
+class SVGTextLayoutEngineSpacing : public Noncopyable {
+public:
+    SVGTextLayoutEngineSpacing(const Font&);
+
+    float calculateSVGKerning(bool isVerticalText, const SVGTextMetrics::Glyph& currentGlyph);
+    float calculateCSSKerningAndSpacing(const SVGRenderStyle*, SVGElement* lengthContext, const UChar* currentCharacter);
+
+private:
+    const Font& m_font;
+    const UChar* m_lastCharacter;
+
+#if ENABLE(SVG_FONTS)
+    SVGTextMetrics::Glyph m_lastGlyph;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list