| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #include "core/layout/svg/LayoutSVGTextPath.h" | 20 #include "core/layout/svg/LayoutSVGTextPath.h" |
| 21 | 21 |
| 22 #include "core/layout/svg/SVGLayoutSupport.h" | 22 #include "core/layout/svg/SVGLayoutSupport.h" |
| 23 #include "core/svg/SVGPathElement.h" | 23 #include "core/svg/SVGPathElement.h" |
| 24 #include "core/svg/SVGTextPathElement.h" | 24 #include "core/svg/SVGTextPathElement.h" |
| 25 #include "platform/graphics/Path.h" | 25 #include "platform/graphics/Path.h" |
| 26 | 26 |
| 27 namespace blink { | 27 namespace blink { |
| 28 | 28 |
| 29 TreeScope& treeScopeForIdResolution(const SVGElement& element) |
| 30 { |
| 31 if (SVGElement* correspondingElement = element.correspondingElement()) |
| 32 return correspondingElement->treeScope(); |
| 33 return element.treeScope(); |
| 34 } |
| 35 |
| 29 PathPositionMapper::PathPositionMapper(const Path& path) | 36 PathPositionMapper::PathPositionMapper(const Path& path) |
| 30 : m_positionCalculator(path) | 37 : m_positionCalculator(path) |
| 31 , m_pathLength(path.length()) | 38 , m_pathLength(path.length()) |
| 32 { | 39 { |
| 33 } | 40 } |
| 34 | 41 |
| 35 PathPositionMapper::PositionType PathPositionMapper::pointAndNormalAtLength( | 42 PathPositionMapper::PositionType PathPositionMapper::pointAndNormalAtLength( |
| 36 float length, FloatPoint& point, float& angle) | 43 float length, FloatPoint& point, float& angle) |
| 37 { | 44 { |
| 38 if (length < 0) | 45 if (length < 0) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 if (child->isText()) | 61 if (child->isText()) |
| 55 return SVGLayoutSupport::isLayoutableTextNode(child); | 62 return SVGLayoutSupport::isLayoutableTextNode(child); |
| 56 | 63 |
| 57 return child->isSVGInline() && !child->isSVGTextPath(); | 64 return child->isSVGInline() && !child->isSVGTextPath(); |
| 58 } | 65 } |
| 59 | 66 |
| 60 PassOwnPtr<PathPositionMapper> LayoutSVGTextPath::layoutPath() const | 67 PassOwnPtr<PathPositionMapper> LayoutSVGTextPath::layoutPath() const |
| 61 { | 68 { |
| 62 const SVGTextPathElement& textPathElement = toSVGTextPathElement(*node()); | 69 const SVGTextPathElement& textPathElement = toSVGTextPathElement(*node()); |
| 63 Element* targetElement = SVGURIReference::targetElementFromIRIString( | 70 Element* targetElement = SVGURIReference::targetElementFromIRIString( |
| 64 textPathElement.hrefString(), textPathElement.treeScope()); | 71 textPathElement.hrefString(), treeScopeForIdResolution(textPathElement))
; |
| 72 |
| 65 if (!isSVGPathElement(targetElement)) | 73 if (!isSVGPathElement(targetElement)) |
| 66 return nullptr; | 74 return nullptr; |
| 67 | 75 |
| 68 SVGPathElement& pathElement = toSVGPathElement(*targetElement); | 76 SVGPathElement& pathElement = toSVGPathElement(*targetElement); |
| 69 Path pathData = pathElement.asPath(); | 77 Path pathData = pathElement.asPath(); |
| 70 if (pathData.isEmpty()) | 78 if (pathData.isEmpty()) |
| 71 return nullptr; | 79 return nullptr; |
| 72 | 80 |
| 73 // Spec: The transform attribute on the referenced 'path' element represent
s a | 81 // Spec: The transform attribute on the referenced 'path' element represent
s a |
| 74 // supplemental transformation relative to the current user coordinate syste
m for | 82 // supplemental transformation relative to the current user coordinate syste
m for |
| 75 // the current 'text' element, including any adjustments to the current user
coordinate | 83 // the current 'text' element, including any adjustments to the current user
coordinate |
| 76 // system due to a possible transform attribute on the current 'text' elemen
t. | 84 // system due to a possible transform attribute on the current 'text' elemen
t. |
| 77 // http://www.w3.org/TR/SVG/text.html#TextPathElement | 85 // http://www.w3.org/TR/SVG/text.html#TextPathElement |
| 78 pathData.transform(pathElement.calculateAnimatedLocalTransform()); | 86 pathData.transform(pathElement.calculateAnimatedLocalTransform()); |
| 79 | 87 |
| 80 return PathPositionMapper::create(pathData); | 88 return PathPositionMapper::create(pathData); |
| 81 } | 89 } |
| 82 | 90 |
| 83 float LayoutSVGTextPath::calculateStartOffset(float pathLength) const | 91 float LayoutSVGTextPath::calculateStartOffset(float pathLength) const |
| 84 { | 92 { |
| 85 const SVGLength& startOffset = *toSVGTextPathElement(node())->startOffset()-
>currentValue(); | 93 const SVGLength& startOffset = *toSVGTextPathElement(node())->startOffset()-
>currentValue(); |
| 86 float textPathStartOffset = startOffset.valueAsPercentage(); | 94 float textPathStartOffset = startOffset.valueAsPercentage(); |
| 87 if (startOffset.typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Perce
ntage) | 95 if (startOffset.typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Perce
ntage) |
| 88 textPathStartOffset *= pathLength; | 96 textPathStartOffset *= pathLength; |
| 89 | 97 |
| 90 return textPathStartOffset; | 98 return textPathStartOffset; |
| 91 } | 99 } |
| 92 | 100 |
| 93 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |