Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/SVGTextLayoutAttributesBuilder.cpp

Issue 1861013003: Separate metrics update and layout attribute resolving (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify-layoutattr-invalidation
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
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/SVGTextLayoutAttributesBuilder.h" 20 #include "core/layout/svg/SVGTextLayoutAttributesBuilder.h"
21 21
22 #include "core/layout/svg/LayoutSVGInline.h" 22 #include "core/layout/svg/LayoutSVGInline.h"
23 #include "core/layout/svg/LayoutSVGInlineText.h" 23 #include "core/layout/svg/LayoutSVGInlineText.h"
24 #include "core/layout/svg/LayoutSVGText.h" 24 #include "core/layout/svg/LayoutSVGText.h"
25 #include "core/layout/svg/SVGTextMetricsBuilder.h"
26 #include "core/svg/SVGTextPositioningElement.h" 25 #include "core/svg/SVGTextPositioningElement.h"
27 26
28 namespace blink { 27 namespace blink {
29 28
29 namespace {
30
31 void updateLayoutAttributes(LayoutSVGInlineText& text, unsigned& valueListPositi on, const SVGCharacterDataMap& allCharactersMap)
32 {
33 SVGTextLayoutAttributes& attributes = *text.layoutAttributes();
34 attributes.clear();
35
36 const Vector<SVGTextMetrics>& metricsList = text.metricsList();
37 auto metricsEnd = metricsList.end();
38 unsigned surrogatePairCharacters = 0;
39 unsigned skippedWhitespace = 0;
40 unsigned currentPosition = 0;
41 for (auto metrics = metricsList.begin(); metrics != metricsEnd; currentPosit ion += metrics->length(), ++metrics) {
42 if (metrics->isEmpty()) {
43 skippedWhitespace++;
44 continue;
45 }
46
47 unsigned currentValueListPosition = valueListPosition - skippedWhitespac e - surrogatePairCharacters + currentPosition + 1;
48 auto it = allCharactersMap.find(currentValueListPosition);
49 if (it != allCharactersMap.end())
50 attributes.characterDataMap().set(currentPosition + 1, it->value);
51
52 // At the moment, only surrogates will be length == 2 (or even > 1).
53 if (metrics->length() == 2)
54 surrogatePairCharacters++;
55 }
56
57 // TODO(fs): currentPosition ought to always equal text.textLength() here.
58 valueListPosition += currentPosition - skippedWhitespace;
59 }
60
61 } // namespace
62
30 SVGTextLayoutAttributesBuilder::SVGTextLayoutAttributesBuilder() 63 SVGTextLayoutAttributesBuilder::SVGTextLayoutAttributesBuilder()
31 : m_textLength(0) 64 : m_textLength(0)
32 { 65 {
33 } 66 }
34 67
35 bool SVGTextLayoutAttributesBuilder::buildLayoutAttributesForForSubtree(LayoutSV GText& textRoot) 68 void SVGTextLayoutAttributesBuilder::buildLayoutAttributes(LayoutSVGText& textRo ot) const
69 {
70 unsigned valueListPosition = 0;
71 LayoutObject* child = textRoot.firstChild();
72 while (child) {
73 if (child->isSVGInlineText()) {
74 updateLayoutAttributes(toLayoutSVGInlineText(*child), valueListPosit ion, m_characterDataMap);
75 } else if (child->isSVGInline()) {
76 // Visit children of text content elements.
77 if (LayoutObject* inlineChild = toLayoutSVGInline(child)->firstChild ()) {
78 child = inlineChild;
79 continue;
80 }
81 }
82 child = child->nextInPreOrderAfterChildren(&textRoot);
83 }
84 }
85
86 void SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRoot(LayoutSVGT ext& textRoot)
36 { 87 {
37 m_characterDataMap.clear(); 88 m_characterDataMap.clear();
38 89
39 if (m_textPositions.isEmpty()) { 90 if (m_textPositions.isEmpty()) {
40 m_textLength = 0; 91 m_textLength = 0;
41 UChar lastCharacter = ' '; 92 UChar lastCharacter = ' ';
42 collectTextPositioningElements(textRoot, lastCharacter); 93 collectTextPositioningElements(textRoot, lastCharacter);
43 } 94 }
44 95
45 if (!m_textLength) 96 if (!m_textLength)
46 return false; 97 return;
47 98
48 buildCharacterDataMap(textRoot); 99 buildCharacterDataMap(textRoot);
49 SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(textRoot, m_character DataMap); 100 buildLayoutAttributes(textRoot);
50 return true;
51 }
52
53 void SVGTextLayoutAttributesBuilder::rebuildMetricsForTextLayoutObject(LayoutSVG Text& textRoot, LayoutSVGInlineText& text)
54 {
55 SVGTextMetricsBuilder::measureTextLayoutObject(textRoot, text);
56 } 101 }
57 102
58 static inline void processLayoutSVGInlineText(LayoutSVGInlineText* text, unsigne d& atCharacter, UChar& lastCharacter) 103 static inline void processLayoutSVGInlineText(LayoutSVGInlineText* text, unsigne d& atCharacter, UChar& lastCharacter)
59 { 104 {
60 if (text->style()->whiteSpace() == PRE) { 105 if (text->style()->whiteSpace() == PRE) {
61 atCharacter += text->textLength(); 106 atCharacter += text->textLength();
62 return; 107 return;
63 } 108 }
64 109
65 unsigned textLength = text->textLength(); 110 unsigned textLength = text->textLength();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 attrLists.updateCharacterData(i, data); 262 attrLists.updateCharacterData(i, data);
218 } 263 }
219 } 264 }
220 265
221 DEFINE_TRACE(SVGTextLayoutAttributesBuilder::TextPosition) 266 DEFINE_TRACE(SVGTextLayoutAttributesBuilder::TextPosition)
222 { 267 {
223 visitor->trace(element); 268 visitor->trace(element);
224 } 269 }
225 270
226 } // namespace blink 271 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698