| 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 "core/paint/TextPainter.h" | 5 #include "core/paint/TextPainter.h" |
| 6 | 6 |
| 7 #include "core/CSSPropertyNames.h" | 7 #include "core/CSSPropertyNames.h" |
| 8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
| 9 #include "core/layout/LayoutObject.h" | 9 #include "core/layout/LayoutObject.h" |
| 10 #include "core/layout/LayoutTextCombine.h" | 10 #include "core/layout/LayoutTextCombine.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 m_textBounds(textBounds), | 37 m_textBounds(textBounds), |
| 38 m_horizontal(horizontal), | 38 m_horizontal(horizontal), |
| 39 m_emphasisMarkOffset(0), | 39 m_emphasisMarkOffset(0), |
| 40 m_combinedText(0) {} | 40 m_combinedText(0) {} |
| 41 | 41 |
| 42 TextPainter::~TextPainter() {} | 42 TextPainter::~TextPainter() {} |
| 43 | 43 |
| 44 void TextPainter::setEmphasisMark(const AtomicString& emphasisMark, | 44 void TextPainter::setEmphasisMark(const AtomicString& emphasisMark, |
| 45 TextEmphasisPosition position) { | 45 TextEmphasisPosition position) { |
| 46 m_emphasisMark = emphasisMark; | 46 m_emphasisMark = emphasisMark; |
| 47 const SimpleFontData* fontData = m_font.primaryFont(); |
| 48 DCHECK(fontData); |
| 47 | 49 |
| 48 if (emphasisMark.isNull()) { | 50 if (!fontData || emphasisMark.isNull()) { |
| 49 m_emphasisMarkOffset = 0; | 51 m_emphasisMarkOffset = 0; |
| 50 } else if (position == TextEmphasisPositionOver) { | 52 } else if (position == TextEmphasisPositionOver) { |
| 51 m_emphasisMarkOffset = -m_font.getFontMetrics().ascent() - | 53 m_emphasisMarkOffset = -fontData->getFontMetrics().ascent() - |
| 52 m_font.emphasisMarkDescent(emphasisMark); | 54 m_font.emphasisMarkDescent(emphasisMark); |
| 53 } else { | 55 } else { |
| 54 ASSERT(position == TextEmphasisPositionUnder); | 56 ASSERT(position == TextEmphasisPositionUnder); |
| 55 m_emphasisMarkOffset = m_font.getFontMetrics().descent() + | 57 m_emphasisMarkOffset = fontData->getFontMetrics().descent() + |
| 56 m_font.emphasisMarkAscent(emphasisMark); | 58 m_font.emphasisMarkAscent(emphasisMark); |
| 57 } | 59 } |
| 58 } | 60 } |
| 59 | 61 |
| 60 void TextPainter::paint(unsigned startOffset, | 62 void TextPainter::paint(unsigned startOffset, |
| 61 unsigned endOffset, | 63 unsigned endOffset, |
| 62 unsigned length, | 64 unsigned length, |
| 63 const Style& textStyle, | 65 const Style& textStyle, |
| 64 TextBlobPtr* cachedTextBlob) { | 66 TextBlobPtr* cachedTextBlob) { |
| 65 GraphicsContextStateSaver stateSaver(m_graphicsContext, false); | 67 GraphicsContextStateSaver stateSaver(m_graphicsContext, false); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset); | 248 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset); |
| 247 } else { | 249 } else { |
| 248 if (endOffset > 0) | 250 if (endOffset > 0) |
| 249 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset); | 251 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset); |
| 250 if (startOffset < truncationPoint) | 252 if (startOffset < truncationPoint) |
| 251 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoint); | 253 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoint); |
| 252 } | 254 } |
| 253 } | 255 } |
| 254 | 256 |
| 255 void TextPainter::paintEmphasisMarkForCombinedText() { | 257 void TextPainter::paintEmphasisMarkForCombinedText() { |
| 256 ASSERT(m_combinedText); | 258 const SimpleFontData* fontData = m_font.primaryFont(); |
| 259 DCHECK(fontData); |
| 260 if (!fontData) |
| 261 return; |
| 262 |
| 263 DCHECK(m_combinedText); |
| 257 TextRun placeholderTextRun(&ideographicFullStopCharacter, 1); | 264 TextRun placeholderTextRun(&ideographicFullStopCharacter, 1); |
| 258 FloatPoint emphasisMarkTextOrigin(m_textBounds.x().toFloat(), | 265 FloatPoint emphasisMarkTextOrigin(m_textBounds.x().toFloat(), |
| 259 m_textBounds.y().toFloat() + | 266 m_textBounds.y().toFloat() + |
| 260 m_font.getFontMetrics().ascent() + | 267 fontData->getFontMetrics().ascent() + |
| 261 m_emphasisMarkOffset); | 268 m_emphasisMarkOffset); |
| 262 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); | 269 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); |
| 263 textRunPaintInfo.bounds = FloatRect(m_textBounds); | 270 textRunPaintInfo.bounds = FloatRect(m_textBounds); |
| 264 m_graphicsContext.concatCTM(rotation(m_textBounds, Clockwise)); | 271 m_graphicsContext.concatCTM(rotation(m_textBounds, Clockwise)); |
| 265 m_graphicsContext.drawEmphasisMarks(m_combinedText->originalFont(), | 272 m_graphicsContext.drawEmphasisMarks(m_combinedText->originalFont(), |
| 266 textRunPaintInfo, m_emphasisMark, | 273 textRunPaintInfo, m_emphasisMark, |
| 267 emphasisMarkTextOrigin); | 274 emphasisMarkTextOrigin); |
| 268 m_graphicsContext.concatCTM(rotation(m_textBounds, Counterclockwise)); | 275 m_graphicsContext.concatCTM(rotation(m_textBounds, Counterclockwise)); |
| 269 } | 276 } |
| 270 | 277 |
| 271 } // namespace blink | 278 } // namespace blink |
| OLD | NEW |