| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 if (emphasisMark.isNull()) { | 47 if (emphasisMark.isNull()) { |
| 48 m_emphasisMarkOffset = 0; | 48 m_emphasisMarkOffset = 0; |
| 49 } else if (position == TextEmphasisPositionOver) { | 49 } else if (position == TextEmphasisPositionOver) { |
| 50 m_emphasisMarkOffset = -m_font.getFontMetrics().ascent() - m_font.emphas
isMarkDescent(emphasisMark); | 50 m_emphasisMarkOffset = -m_font.getFontMetrics().ascent() - m_font.emphas
isMarkDescent(emphasisMark); |
| 51 } else { | 51 } else { |
| 52 ASSERT(position == TextEmphasisPositionUnder); | 52 ASSERT(position == TextEmphasisPositionUnder); |
| 53 m_emphasisMarkOffset = m_font.getFontMetrics().descent() + m_font.emphas
isMarkAscent(emphasisMark); | 53 m_emphasisMarkOffset = m_font.getFontMetrics().descent() + m_font.emphas
isMarkAscent(emphasisMark); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 void TextPainter::paint(int startOffset, int endOffset, int length, const Style&
textStyle, TextBlobPtr* cachedTextBlob) | 57 void TextPainter::paint(unsigned startOffset, unsigned endOffset, unsigned lengt
h, const Style& textStyle, TextBlobPtr* cachedTextBlob) |
| 58 { | 58 { |
| 59 GraphicsContextStateSaver stateSaver(m_graphicsContext, false); | 59 GraphicsContextStateSaver stateSaver(m_graphicsContext, false); |
| 60 updateGraphicsContext(textStyle, stateSaver); | 60 updateGraphicsContext(textStyle, stateSaver); |
| 61 if (m_combinedText) { | 61 if (m_combinedText) { |
| 62 m_graphicsContext.save(); | 62 m_graphicsContext.save(); |
| 63 m_combinedText->transformToInlineCoordinates(m_graphicsContext, m_textBo
unds); | 63 m_combinedText->transformToInlineCoordinates(m_graphicsContext, m_textBo
unds); |
| 64 paintInternal<PaintText>(startOffset, endOffset, length, cachedTextBlob)
; | 64 paintInternal<PaintText>(startOffset, endOffset, length, cachedTextBlob)
; |
| 65 m_graphicsContext.restore(); | 65 m_graphicsContext.restore(); |
| 66 } else { | 66 } else { |
| 67 paintInternal<PaintText>(startOffset, endOffset, length, cachedTextBlob)
; | 67 paintInternal<PaintText>(startOffset, endOffset, length, cachedTextBlob)
; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 176 |
| 177 // Text shadows are disabled when printing. http://crbug.com/258321 | 177 // Text shadows are disabled when printing. http://crbug.com/258321 |
| 178 if (isPrinting) | 178 if (isPrinting) |
| 179 selectionStyle.shadow = 0; | 179 selectionStyle.shadow = 0; |
| 180 } | 180 } |
| 181 | 181 |
| 182 return selectionStyle; | 182 return selectionStyle; |
| 183 } | 183 } |
| 184 | 184 |
| 185 template <TextPainter::PaintInternalStep step> | 185 template <TextPainter::PaintInternalStep step> |
| 186 void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, int from,
int to) | 186 void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, unsigned
from, unsigned to) |
| 187 { | 187 { |
| 188 ASSERT(from <= textRunPaintInfo.run.length()); | 188 ASSERT(from <= textRunPaintInfo.run.length()); |
| 189 ASSERT(to <= textRunPaintInfo.run.length()); | 189 ASSERT(to <= textRunPaintInfo.run.length()); |
| 190 | 190 |
| 191 textRunPaintInfo.from = from; | 191 textRunPaintInfo.from = from; |
| 192 textRunPaintInfo.to = to; | 192 textRunPaintInfo.to = to; |
| 193 | 193 |
| 194 if (step == PaintEmphasisMark) { | 194 if (step == PaintEmphasisMark) { |
| 195 m_graphicsContext.drawEmphasisMarks(m_font, textRunPaintInfo, m_emphasis
Mark, | 195 m_graphicsContext.drawEmphasisMarks(m_font, textRunPaintInfo, m_emphasis
Mark, |
| 196 FloatPoint(m_textOrigin) + IntSize(0, m_emphasisMarkOffset)); | 196 FloatPoint(m_textOrigin) + IntSize(0, m_emphasisMarkOffset)); |
| 197 } else { | 197 } else { |
| 198 ASSERT(step == PaintText); | 198 ASSERT(step == PaintText); |
| 199 m_graphicsContext.drawText(m_font, textRunPaintInfo, FloatPoint(m_textOr
igin)); | 199 m_graphicsContext.drawText(m_font, textRunPaintInfo, FloatPoint(m_textOr
igin)); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 template <TextPainter::PaintInternalStep Step> | 203 template <TextPainter::PaintInternalStep Step> |
| 204 void TextPainter::paintInternal(int startOffset, int endOffset, int truncationPo
int, TextBlobPtr* cachedTextBlob) | 204 void TextPainter::paintInternal(unsigned startOffset, unsigned endOffset, unsign
ed truncationPoint, TextBlobPtr* cachedTextBlob) |
| 205 { | 205 { |
| 206 TextRunPaintInfo textRunPaintInfo(m_run); | 206 TextRunPaintInfo textRunPaintInfo(m_run); |
| 207 textRunPaintInfo.bounds = FloatRect(m_textBounds); | 207 textRunPaintInfo.bounds = FloatRect(m_textBounds); |
| 208 if (startOffset <= endOffset) { | 208 if (startOffset <= endOffset) { |
| 209 // FIXME: We should be able to use cachedTextBlob in more cases. | 209 // FIXME: We should be able to use cachedTextBlob in more cases. |
| 210 textRunPaintInfo.cachedTextBlob = cachedTextBlob; | 210 textRunPaintInfo.cachedTextBlob = cachedTextBlob; |
| 211 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset); | 211 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset); |
| 212 } else { | 212 } else { |
| 213 if (endOffset > 0) | 213 if (endOffset > 0) |
| 214 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset); | 214 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset); |
| 215 if (startOffset < truncationPoint) | 215 if (startOffset < truncationPoint) |
| 216 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoin
t); | 216 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoin
t); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 void TextPainter::paintEmphasisMarkForCombinedText() | 220 void TextPainter::paintEmphasisMarkForCombinedText() |
| 221 { | 221 { |
| 222 ASSERT(m_combinedText); | 222 ASSERT(m_combinedText); |
| 223 TextRun placeholderTextRun(&ideographicFullStopCharacter, 1); | 223 TextRun placeholderTextRun(&ideographicFullStopCharacter, 1); |
| 224 FloatPoint emphasisMarkTextOrigin(m_textBounds.x().toFloat(), m_textBounds.y
().toFloat() + m_font.getFontMetrics().ascent() + m_emphasisMarkOffset); | 224 FloatPoint emphasisMarkTextOrigin(m_textBounds.x().toFloat(), m_textBounds.y
().toFloat() + m_font.getFontMetrics().ascent() + m_emphasisMarkOffset); |
| 225 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); | 225 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); |
| 226 textRunPaintInfo.bounds = FloatRect(m_textBounds); | 226 textRunPaintInfo.bounds = FloatRect(m_textBounds); |
| 227 m_graphicsContext.concatCTM(rotation(m_textBounds, Clockwise)); | 227 m_graphicsContext.concatCTM(rotation(m_textBounds, Clockwise)); |
| 228 m_graphicsContext.drawEmphasisMarks(m_combinedText->originalFont(), textRunP
aintInfo, m_emphasisMark, emphasisMarkTextOrigin); | 228 m_graphicsContext.drawEmphasisMarks(m_combinedText->originalFont(), textRunP
aintInfo, m_emphasisMark, emphasisMarkTextOrigin); |
| 229 m_graphicsContext.concatCTM(rotation(m_textBounds, Counterclockwise)); | 229 m_graphicsContext.concatCTM(rotation(m_textBounds, Counterclockwise)); |
| 230 } | 230 } |
| 231 | 231 |
| 232 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |