summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp')
-rw-r--r--Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp87
1 files changed, 41 insertions, 46 deletions
diff --git a/Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp b/Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp
index 1dbb01fd9..2c068b9c3 100644
--- a/Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp
+++ b/Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp
@@ -18,10 +18,10 @@
*/
#include "config.h"
-
-#if ENABLE(SVG)
#include "SVGTextLayoutAttributesBuilder.h"
+#include "RenderChildIterator.h"
+#include "RenderSVGInline.h"
#include "RenderSVGInlineText.h"
#include "RenderSVGText.h"
#include "SVGTextPositioningElement.h"
@@ -35,7 +35,7 @@ SVGTextLayoutAttributesBuilder::SVGTextLayoutAttributesBuilder()
void SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRenderer(RenderSVGInlineText& text)
{
- RenderSVGText* textRoot = RenderSVGText::locateRenderSVGTextAncestor(&text);
+ auto* textRoot = RenderSVGText::locateRenderSVGTextAncestor(text);
if (!textRoot)
return;
@@ -43,82 +43,79 @@ void SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRenderer(Render
m_characterDataMap.clear();
m_textLength = 0;
- const UChar* lastCharacter = 0;
- collectTextPositioningElements(textRoot, lastCharacter);
+ bool lastCharacterWasSpace = true;
+ collectTextPositioningElements(*textRoot, lastCharacterWasSpace);
if (!m_textLength)
return;
- buildCharacterDataMap(textRoot);
+ buildCharacterDataMap(*textRoot);
}
- m_metricsBuilder.buildMetricsAndLayoutAttributes(textRoot, &text, m_characterDataMap);
+ m_metricsBuilder.buildMetricsAndLayoutAttributes(*textRoot, &text, m_characterDataMap);
}
-bool SVGTextLayoutAttributesBuilder::buildLayoutAttributesForForSubtree(RenderSVGText* textRoot)
+bool SVGTextLayoutAttributesBuilder::buildLayoutAttributesForForSubtree(RenderSVGText& textRoot)
{
- ASSERT(textRoot);
-
m_characterDataMap.clear();
if (m_textPositions.isEmpty()) {
m_textLength = 0;
- const UChar* lastCharacter = 0;
- collectTextPositioningElements(textRoot, lastCharacter);
+ bool lastCharacterWasSpace = true;
+ collectTextPositioningElements(textRoot, lastCharacterWasSpace);
}
if (!m_textLength)
return false;
buildCharacterDataMap(textRoot);
- m_metricsBuilder.buildMetricsAndLayoutAttributes(textRoot, 0, m_characterDataMap);
+ m_metricsBuilder.buildMetricsAndLayoutAttributes(textRoot, nullptr, m_characterDataMap);
return true;
}
-void SVGTextLayoutAttributesBuilder::rebuildMetricsForTextRenderer(RenderSVGInlineText* text)
+void SVGTextLayoutAttributesBuilder::rebuildMetricsForTextRenderer(RenderSVGInlineText& text)
{
- ASSERT(text);
m_metricsBuilder.measureTextRenderer(text);
}
-static inline void processRenderSVGInlineText(RenderSVGInlineText* text, unsigned& atCharacter, const UChar*& lastCharacter)
+static inline void processRenderSVGInlineText(const RenderSVGInlineText& text, unsigned& atCharacter, bool& lastCharacterWasSpace)
{
- if (text->style().whiteSpace() == PRE) {
- atCharacter += text->textLength();
+ if (text.style().whiteSpace() == PRE) {
+ atCharacter += text.textLength();
return;
}
- const UChar* characters = text->deprecatedCharacters();
- unsigned textLength = text->textLength();
- for (unsigned textPosition = 0; textPosition < textLength; ++textPosition) {
- const UChar* currentCharacter = characters + textPosition;
- if (*currentCharacter == ' ' && (!lastCharacter || *lastCharacter == ' '))
+ for (unsigned textPosition = 0, textLength = text.textLength(); textPosition < textLength; ++textPosition) {
+ const UChar currentCharacter = text[textPosition];
+ if (currentCharacter == ' ' && lastCharacterWasSpace)
continue;
- lastCharacter = currentCharacter;
+ lastCharacterWasSpace = currentCharacter == ' ';
++atCharacter;
}
}
-void SVGTextLayoutAttributesBuilder::collectTextPositioningElements(RenderObject* start, const UChar*& lastCharacter)
+void SVGTextLayoutAttributesBuilder::collectTextPositioningElements(RenderBoxModelObject& start, bool& lastCharacterWasSpace)
{
- ASSERT(!start->isSVGText() || m_textPositions.isEmpty());
+ ASSERT(!is<RenderSVGText>(start) || m_textPositions.isEmpty());
- for (RenderObject* child = start->firstChildSlow(); child; child = child->nextSibling()) {
- if (child->isSVGInlineText()) {
- processRenderSVGInlineText(toRenderSVGInlineText(child), m_textLength, lastCharacter);
+ for (auto& child : childrenOfType<RenderObject>(start)) {
+ if (is<RenderSVGInlineText>(child)) {
+ processRenderSVGInlineText(downcast<RenderSVGInlineText>(child), m_textLength, lastCharacterWasSpace);
continue;
}
- if (!child->isSVGInline())
+ if (!is<RenderSVGInline>(child))
continue;
- SVGTextPositioningElement* element = SVGTextPositioningElement::elementFromRenderer(child);
+ auto& inlineChild = downcast<RenderSVGInline>(child);
+ SVGTextPositioningElement* element = SVGTextPositioningElement::elementFromRenderer(inlineChild);
+
unsigned atPosition = m_textPositions.size();
if (element)
m_textPositions.append(TextPosition(element, m_textLength));
- collectTextPositioningElements(child, lastCharacter);
+ collectTextPositioningElements(inlineChild, lastCharacterWasSpace);
if (!element)
continue;
@@ -130,7 +127,7 @@ void SVGTextLayoutAttributesBuilder::collectTextPositioningElements(RenderObject
}
}
-void SVGTextLayoutAttributesBuilder::buildCharacterDataMap(RenderSVGText* textRoot)
+void SVGTextLayoutAttributesBuilder::buildCharacterDataMap(RenderSVGText& textRoot)
{
SVGTextPositioningElement* outermostTextElement = SVGTextPositioningElement::elementFromRenderer(textRoot);
ASSERT(outermostTextElement);
@@ -160,7 +157,7 @@ void SVGTextLayoutAttributesBuilder::buildCharacterDataMap(RenderSVGText* textRo
fillCharacterDataMap(m_textPositions[i]);
}
-static inline void updateCharacterData(unsigned i, float& lastRotation, SVGCharacterData& data, const SVGLengthContext& lengthContext, const SVGLengthList* xList, const SVGLengthList* yList, const SVGLengthList* dxList, const SVGLengthList* dyList, const SVGNumberList* rotateList)
+static inline void updateCharacterData(unsigned i, float& lastRotation, SVGCharacterData& data, const SVGLengthContext& lengthContext, const SVGLengthListValues* xList, const SVGLengthListValues* yList, const SVGLengthListValues* dxList, const SVGLengthListValues* dyList, const SVGNumberListValues* rotateList)
{
if (xList)
data.x = xList->at(i).value(lengthContext);
@@ -178,11 +175,11 @@ static inline void updateCharacterData(unsigned i, float& lastRotation, SVGChara
void SVGTextLayoutAttributesBuilder::fillCharacterDataMap(const TextPosition& position)
{
- const SVGLengthList& xList = position.element->x();
- const SVGLengthList& yList = position.element->y();
- const SVGLengthList& dxList = position.element->dx();
- const SVGLengthList& dyList = position.element->dy();
- const SVGNumberList& rotateList = position.element->rotate();
+ const auto& xList = position.element->x();
+ const auto& yList = position.element->y();
+ const auto& dxList = position.element->dx();
+ const auto& dyList = position.element->dy();
+ const auto& rotateList = position.element->rotate();
unsigned xListSize = xList.size();
unsigned yListSize = yList.size();
@@ -195,11 +192,11 @@ void SVGTextLayoutAttributesBuilder::fillCharacterDataMap(const TextPosition& po
float lastRotation = SVGTextLayoutAttributes::emptyValue();
SVGLengthContext lengthContext(position.element);
for (unsigned i = 0; i < position.length; ++i) {
- const SVGLengthList* xListPtr = i < xListSize ? &xList : 0;
- const SVGLengthList* yListPtr = i < yListSize ? &yList : 0;
- const SVGLengthList* dxListPtr = i < dxListSize ? &dxList : 0;
- const SVGLengthList* dyListPtr = i < dyListSize ? &dyList : 0;
- const SVGNumberList* rotateListPtr = i < rotateListSize ? &rotateList : 0;
+ const SVGLengthListValues* xListPtr = i < xListSize ? &xList : 0;
+ const SVGLengthListValues* yListPtr = i < yListSize ? &yList : 0;
+ const SVGLengthListValues* dxListPtr = i < dxListSize ? &dxList : 0;
+ const SVGLengthListValues* dyListPtr = i < dyListSize ? &dyList : 0;
+ const SVGNumberListValues* rotateListPtr = i < rotateListSize ? &rotateList : 0;
if (!xListPtr && !yListPtr && !dxListPtr && !dyListPtr && !rotateListPtr)
break;
@@ -232,5 +229,3 @@ void SVGTextLayoutAttributesBuilder::fillCharacterDataMap(const TextPosition& po
}
}
-
-#endif // ENABLE(SVG)