OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/rendering/TextPainter.h" | 6 #include "core/rendering/TextPainter.h" |
7 | 7 |
8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/rendering/InlineTextBox.h" | 10 #include "core/rendering/InlineTextBox.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 165 |
166 // Text shadows are disabled when printing. http://crbug.com/258321 | 166 // Text shadows are disabled when printing. http://crbug.com/258321 |
167 if (isPrinting) | 167 if (isPrinting) |
168 selectionStyle.shadow = 0; | 168 selectionStyle.shadow = 0; |
169 } | 169 } |
170 | 170 |
171 return selectionStyle; | 171 return selectionStyle; |
172 } | 172 } |
173 | 173 |
174 template <TextPainter::PaintInternalStep step> | 174 template <TextPainter::PaintInternalStep step> |
175 void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, int from,
int to, TextBlobPtr* cachedTextBlob) | 175 void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, int from,
int to) |
176 { | 176 { |
177 textRunPaintInfo.from = from; | 177 textRunPaintInfo.from = from; |
178 textRunPaintInfo.to = to; | 178 textRunPaintInfo.to = to; |
179 | 179 |
180 if (step == PaintEmphasisMark) { | 180 if (step == PaintEmphasisMark) { |
181 m_graphicsContext->drawEmphasisMarks(m_font, textRunPaintInfo, m_emphasi
sMark, m_textOrigin + IntSize(0, m_emphasisMarkOffset)); | 181 m_graphicsContext->drawEmphasisMarks(m_font, textRunPaintInfo, m_emphasi
sMark, |
182 return; | 182 m_textOrigin + IntSize(0, m_emphasisMarkOffset)); |
| 183 } else { |
| 184 ASSERT(step == PaintText); |
| 185 m_graphicsContext->drawText(m_font, textRunPaintInfo, m_textOrigin); |
183 } | 186 } |
184 | |
185 ASSERT(step == PaintText); | |
186 | |
187 TextBlobPtr localTextBlob; | |
188 TextBlobPtr& textBlob = cachedTextBlob ? *cachedTextBlob : localTextBlob; | |
189 bool canUseTextBlobs = RuntimeEnabledFeatures::textBlobEnabled(); | |
190 | |
191 if (canUseTextBlobs && !textBlob) | |
192 textBlob = m_font.buildTextBlob(textRunPaintInfo, m_textOrigin, m_graphi
csContext->couldUseLCDRenderedText()); | |
193 | |
194 if (canUseTextBlobs && textBlob) | |
195 m_font.drawTextBlob(m_graphicsContext, textBlob.get(), m_textOrigin.data
()); | |
196 else | |
197 m_graphicsContext->drawText(m_font, textRunPaintInfo, m_textOrigin); | |
198 } | 187 } |
199 | 188 |
200 template <TextPainter::PaintInternalStep Step> | 189 template <TextPainter::PaintInternalStep Step> |
201 void TextPainter::paintInternal(int startOffset, int endOffset, int truncationPo
int, TextBlobPtr* cachedTextBlob) | 190 void TextPainter::paintInternal(int startOffset, int endOffset, int truncationPo
int, TextBlobPtr* cachedTextBlob) |
202 { | 191 { |
203 // FIXME: We should be able to use cachedTextBlob in more cases. | |
204 TextRunPaintInfo textRunPaintInfo(m_run); | 192 TextRunPaintInfo textRunPaintInfo(m_run); |
205 textRunPaintInfo.bounds = m_textBounds; | 193 textRunPaintInfo.bounds = m_textBounds; |
206 if (startOffset <= endOffset) { | 194 if (startOffset <= endOffset) { |
207 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset, cachedT
extBlob); | 195 // FIXME: We should be able to use cachedTextBlob in more cases. |
| 196 textRunPaintInfo.cachedTextBlob = cachedTextBlob; |
| 197 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset); |
208 } else { | 198 } else { |
209 if (endOffset > 0) | 199 if (endOffset > 0) |
210 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset); | 200 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset); |
211 if (startOffset < truncationPoint) | 201 if (startOffset < truncationPoint) |
212 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoin
t); | 202 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoin
t); |
213 } | 203 } |
214 } | 204 } |
215 | 205 |
216 void TextPainter::paintEmphasisMarkForCombinedText() | 206 void TextPainter::paintEmphasisMarkForCombinedText() |
217 { | 207 { |
218 ASSERT(m_combinedText); | 208 ASSERT(m_combinedText); |
219 DEFINE_STATIC_LOCAL(TextRun, placeholderTextRun, (&ideographicFullStop, 1)); | 209 DEFINE_STATIC_LOCAL(TextRun, placeholderTextRun, (&ideographicFullStop, 1)); |
220 FloatPoint emphasisMarkTextOrigin(m_textBounds.x(), m_textBounds.y() + m_fon
t.fontMetrics().ascent() + m_emphasisMarkOffset); | 210 FloatPoint emphasisMarkTextOrigin(m_textBounds.x(), m_textBounds.y() + m_fon
t.fontMetrics().ascent() + m_emphasisMarkOffset); |
221 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); | 211 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); |
222 textRunPaintInfo.bounds = m_textBounds; | 212 textRunPaintInfo.bounds = m_textBounds; |
223 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex
tBox::Clockwise)); | 213 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex
tBox::Clockwise)); |
224 m_graphicsContext->drawEmphasisMarks(m_combinedText->originalFont(), textRun
PaintInfo, m_emphasisMark, emphasisMarkTextOrigin); | 214 m_graphicsContext->drawEmphasisMarks(m_combinedText->originalFont(), textRun
PaintInfo, m_emphasisMark, emphasisMarkTextOrigin); |
225 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex
tBox::Counterclockwise)); | 215 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex
tBox::Counterclockwise)); |
226 } | 216 } |
227 | 217 |
228 } // namespace blink | 218 } // namespace blink |
OLD | NEW |