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

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

Issue 1826263002: Always create a BidiRun in SVGTextMetricsBuilder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010-2012. 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
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 , m_fontScalingFactor(m_text.scalingFactor()) 120 , m_fontScalingFactor(m_text.scalingFactor())
121 , m_cachedFontHeight(m_text.scaledFont().getFontMetrics().floatHeight() / m_ fontScalingFactor) 121 , m_cachedFontHeight(m_text.scaledFont().getFontMetrics().floatHeight() / m_ fontScalingFactor)
122 , m_run(constructTextRun(m_text, 0, m_text.textLength(), m_text.styleRef().d irection())) 122 , m_run(constructTextRun(m_text, 0, m_text.textLength(), m_text.styleRef().d irection()))
123 , m_bidiRun(nullptr) 123 , m_bidiRun(nullptr)
124 { 124 {
125 setupBidiRuns(); 125 setupBidiRuns();
126 } 126 }
127 127
128 SVGTextMetricsCalculator::~SVGTextMetricsCalculator() 128 SVGTextMetricsCalculator::~SVGTextMetricsCalculator()
129 { 129 {
130 if (m_bidiRun) 130 m_bidiResolver.runs().deleteRuns();
131 m_bidiResolver.runs().deleteRuns();
132 } 131 }
133 132
134 void SVGTextMetricsCalculator::setupBidiRuns() 133 void SVGTextMetricsCalculator::setupBidiRuns()
135 { 134 {
136 if (isOverride(m_text.styleRef().unicodeBidi()))
137 return;
138 BidiStatus status(LTR, false);
139 status.last = status.lastStrong = WTF::Unicode::OtherNeutral;
140 m_bidiResolver.setStatus(status);
141 m_bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&m_run, 0)) ;
142 const bool hardLineBreak = false;
143 const bool reorderRuns = false;
144 m_bidiResolver.createBidiRunsForLine(TextRunIterator(&m_run, m_run.length()) , NoVisualOverride, hardLineBreak, reorderRuns);
145 BidiRunList<BidiCharacterRun>& bidiRuns = m_bidiResolver.runs(); 135 BidiRunList<BidiCharacterRun>& bidiRuns = m_bidiResolver.runs();
136 bool bidiOverride = isOverride(m_text.styleRef().unicodeBidi());
137 BidiStatus status(LTR, bidiOverride);
138 if (m_run.is8Bit() || bidiOverride) {
139 WTF::Unicode::CharDirection direction = WTF::Unicode::LeftToRight;
140 // If BiDi override is in effect, use the specified direction.
141 if (bidiOverride && !m_text.styleRef().isLeftToRightDirection())
142 direction = WTF::Unicode::RightToLeft;
143 bidiRuns.addRun(new BidiCharacterRun(0, m_run.charactersLength(), status .context.get(), direction));
144 } else {
145 status.last = status.lastStrong = WTF::Unicode::OtherNeutral;
146 m_bidiResolver.setStatus(status);
147 m_bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&m_run, 0));
148 const bool hardLineBreak = false;
149 const bool reorderRuns = false;
150 m_bidiResolver.createBidiRunsForLine(TextRunIterator(&m_run, m_run.lengt h()), NoVisualOverride, hardLineBreak, reorderRuns);
151 }
146 m_bidiRun = bidiRuns.firstRun(); 152 m_bidiRun = bidiRuns.firstRun();
147 } 153 }
148 154
149 bool SVGTextMetricsCalculator::advancePosition() 155 bool SVGTextMetricsCalculator::advancePosition()
150 { 156 {
151 m_currentPosition += currentCharacterStartsSurrogatePair() ? 2 : 1; 157 m_currentPosition += currentCharacterStartsSurrogatePair() ? 2 : 1;
152 return m_currentPosition < characterCount(); 158 return m_currentPosition < characterCount();
153 } 159 }
154 160
155 unsigned SVGTextMetricsCalculator::updateSubrunRangesForCurrentPosition() 161 unsigned SVGTextMetricsCalculator::updateSubrunRangesForCurrentPosition()
156 { 162 {
157 if (m_bidiRun) { 163 ASSERT(m_bidiRun);
158 if (m_currentPosition >= static_cast<unsigned>(m_bidiRun->stop())) { 164 if (m_currentPosition >= static_cast<unsigned>(m_bidiRun->stop())) {
159 m_bidiRun = m_bidiRun->next(); 165 m_bidiRun = m_bidiRun->next();
160 // Ensure new subrange ranges are computed below. 166 // Ensure new subrange ranges are computed below.
161 m_subrunRanges.clear(); 167 m_subrunRanges.clear();
162 }
163 ASSERT(m_bidiRun);
164 ASSERT(static_cast<int>(m_currentPosition) < m_bidiRun->stop());
165 } 168 }
169 ASSERT(m_bidiRun);
170 ASSERT(static_cast<int>(m_currentPosition) < m_bidiRun->stop());
166 171
167 unsigned positionInRun = m_bidiRun ? m_currentPosition - m_bidiRun->start() : m_currentPosition; 172 unsigned positionInRun = m_currentPosition - m_bidiRun->start();
168 if (positionInRun >= m_subrunRanges.size()) { 173 if (positionInRun >= m_subrunRanges.size()) {
169 unsigned subrunStart = m_bidiRun ? m_bidiRun->start() : 0; 174 TextRun subRun = constructTextRun(m_text,
170 unsigned subrunEnd = m_bidiRun ? m_bidiRun->stop() : m_run.charactersLen gth(); 175 m_bidiRun->start(), m_bidiRun->stop() - m_bidiRun->start(), m_bidiRu n->direction());
171 TextDirection subrunDirection = m_bidiRun ? m_bidiRun->direction() : m_t ext.styleRef().direction();
172 TextRun subRun = constructTextRun(m_text, subrunStart, subrunEnd - subru nStart, subrunDirection);
173 m_subrunRanges = m_text.scaledFont().individualCharacterRanges(subRun); 176 m_subrunRanges = m_text.scaledFont().individualCharacterRanges(subRun);
174 177
175 // TODO(pdr): We only have per-glyph data so we need to synthesize per- 178 // TODO(pdr): We only have per-glyph data so we need to synthesize per-
176 // grapheme data. E.g., if 'fi' is shaped into a single glyph, we do not 179 // grapheme data. E.g., if 'fi' is shaped into a single glyph, we do not
177 // know the 'i' position. The code below synthesizes an average glyph 180 // know the 'i' position. The code below synthesizes an average glyph
178 // width when characters share a position. This will incorrectly split 181 // width when characters share a position. This will incorrectly split
179 // combining diacritics. See: https://crbug.com/473476. 182 // combining diacritics. See: https://crbug.com/473476.
180 unsigned distributeCount = 0; 183 unsigned distributeCount = 0;
181 for (int rangeIndex = static_cast<int>(m_subrunRanges.size()) - 1; range Index >= 0; --rangeIndex) { 184 for (int rangeIndex = static_cast<int>(m_subrunRanges.size()) - 1; range Index >= 0; --rangeIndex) {
182 CharacterRange& currentRange = m_subrunRanges[rangeIndex]; 185 CharacterRange& currentRange = m_subrunRanges[rangeIndex];
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 walkTree(textRoot, text); 327 walkTree(textRoot, text);
325 } 328 }
326 329
327 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(LayoutSVGText* textR oot, LayoutSVGInlineText* stopAtText, SVGCharacterDataMap& allCharactersMap) 330 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(LayoutSVGText* textR oot, LayoutSVGInlineText* stopAtText, SVGCharacterDataMap& allCharactersMap)
328 { 331 {
329 ASSERT(textRoot); 332 ASSERT(textRoot);
330 walkTree(textRoot, stopAtText, &allCharactersMap); 333 walkTree(textRoot, stopAtText, &allCharactersMap);
331 } 334 }
332 335
333 } // namespace blink 336 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698