| 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 #ifndef TextPainter_h | 5 #ifndef TextPainter_h |
| 6 #define TextPainter_h | 6 #define TextPainter_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/line/FloatToLayoutUnit.h" | |
| 10 #include "core/style/ComputedStyleConstants.h" | 9 #include "core/style/ComputedStyleConstants.h" |
| 11 #include "platform/fonts/TextBlob.h" | 10 #include "platform/fonts/TextBlob.h" |
| 12 #include "platform/geometry/FloatPoint.h" | 11 #include "platform/geometry/FloatPoint.h" |
| 13 #include "platform/geometry/FloatRect.h" | 12 #include "platform/geometry/FloatRect.h" |
| 13 #include "platform/geometry/LayoutRect.h" |
| 14 #include "platform/graphics/Color.h" | 14 #include "platform/graphics/Color.h" |
| 15 #include "platform/transforms/AffineTransform.h" | 15 #include "platform/transforms/AffineTransform.h" |
| 16 #include "wtf/text/AtomicString.h" | 16 #include "wtf/text/AtomicString.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 class Font; | 20 class Font; |
| 21 class GraphicsContext; | 21 class GraphicsContext; |
| 22 class GraphicsContextStateSaver; | 22 class GraphicsContextStateSaver; |
| 23 class LayoutTextCombine; | 23 class LayoutTextCombine; |
| 24 class LayoutObject; | 24 class LayoutObject; |
| 25 class ComputedStyle; | 25 class ComputedStyle; |
| 26 class ShadowList; | 26 class ShadowList; |
| 27 class TextRun; | 27 class TextRun; |
| 28 struct TextRunPaintInfo; | 28 struct TextRunPaintInfo; |
| 29 | 29 |
| 30 class CORE_EXPORT TextPainter { | 30 class CORE_EXPORT TextPainter { |
| 31 public: | 31 public: |
| 32 struct Style; | 32 struct Style; |
| 33 | 33 |
| 34 TextPainter(GraphicsContext*, const Font&, const TextRun&, const FloatPoint&
textOrigin, const FloatRect& textBounds, bool horizontal); | 34 TextPainter(GraphicsContext*, const Font&, const TextRun&, const LayoutPoint
& textOrigin, const LayoutRect& textBounds, bool horizontal); |
| 35 ~TextPainter(); | 35 ~TextPainter(); |
| 36 | 36 |
| 37 void setEmphasisMark(const AtomicString&, TextEmphasisPosition); | 37 void setEmphasisMark(const AtomicString&, TextEmphasisPosition); |
| 38 void setCombinedText(LayoutTextCombine* combinedText) { m_combinedText = com
binedText; } | 38 void setCombinedText(LayoutTextCombine* combinedText) { m_combinedText = com
binedText; } |
| 39 | 39 |
| 40 static void updateGraphicsContext(GraphicsContext*, const Style&, bool horiz
ontal, GraphicsContextStateSaver&); | 40 static void updateGraphicsContext(GraphicsContext*, const Style&, bool horiz
ontal, GraphicsContextStateSaver&); |
| 41 | 41 |
| 42 void paint(int startOffset, int endOffset, int length, const Style&, TextBlo
bPtr* cachedTextBlob = 0); | 42 void paint(int startOffset, int endOffset, int length, const Style&, TextBlo
bPtr* cachedTextBlob = 0); |
| 43 | 43 |
| 44 struct Style { | 44 struct Style { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 && emphasisMarkColor == other.emphasisMarkColor | 57 && emphasisMarkColor == other.emphasisMarkColor |
| 58 && strokeWidth == other.strokeWidth | 58 && strokeWidth == other.strokeWidth |
| 59 && shadow == other.shadow; | 59 && shadow == other.shadow; |
| 60 } | 60 } |
| 61 bool operator!=(const Style& other) { return !(*this == other); } | 61 bool operator!=(const Style& other) { return !(*this == other); } |
| 62 }; | 62 }; |
| 63 static Style textPaintingStyle(LayoutObject&, const ComputedStyle&, bool for
ceBlackText, bool isPrinting); | 63 static Style textPaintingStyle(LayoutObject&, const ComputedStyle&, bool for
ceBlackText, bool isPrinting); |
| 64 static Style selectionPaintingStyle(LayoutObject&, bool haveSelection, bool
forceBlackText, bool isPrinting, const Style& textStyle); | 64 static Style selectionPaintingStyle(LayoutObject&, bool haveSelection, bool
forceBlackText, bool isPrinting, const Style& textStyle); |
| 65 | 65 |
| 66 enum RotationDirection { Counterclockwise, Clockwise }; | 66 enum RotationDirection { Counterclockwise, Clockwise }; |
| 67 static AffineTransform rotation(const FloatRectWillBeLayoutRect& boxRect, Ro
tationDirection); | 67 static AffineTransform rotation(const LayoutRect& boxRect, RotationDirection
); |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 void updateGraphicsContext(const Style& style, GraphicsContextStateSaver& sa
ver) | 70 void updateGraphicsContext(const Style& style, GraphicsContextStateSaver& sa
ver) |
| 71 { | 71 { |
| 72 updateGraphicsContext(m_graphicsContext, style, m_horizontal, saver); | 72 updateGraphicsContext(m_graphicsContext, style, m_horizontal, saver); |
| 73 } | 73 } |
| 74 | 74 |
| 75 enum PaintInternalStep { PaintText, PaintEmphasisMark }; | 75 enum PaintInternalStep { PaintText, PaintEmphasisMark }; |
| 76 | 76 |
| 77 template <PaintInternalStep step> | 77 template <PaintInternalStep step> |
| 78 void paintInternalRun(TextRunPaintInfo&, int from, int to); | 78 void paintInternalRun(TextRunPaintInfo&, int from, int to); |
| 79 | 79 |
| 80 template <PaintInternalStep step> | 80 template <PaintInternalStep step> |
| 81 void paintInternal(int startOffset, int endOffset, int truncationPoint, Text
BlobPtr* cachedTextBlob = 0); | 81 void paintInternal(int startOffset, int endOffset, int truncationPoint, Text
BlobPtr* cachedTextBlob = 0); |
| 82 | 82 |
| 83 void paintEmphasisMarkForCombinedText(); | 83 void paintEmphasisMarkForCombinedText(); |
| 84 | 84 |
| 85 GraphicsContext* m_graphicsContext; | 85 GraphicsContext* m_graphicsContext; |
| 86 const Font& m_font; | 86 const Font& m_font; |
| 87 const TextRun& m_run; | 87 const TextRun& m_run; |
| 88 FloatPoint m_textOrigin; | 88 LayoutPoint m_textOrigin; |
| 89 FloatRect m_textBounds; | 89 LayoutRect m_textBounds; |
| 90 bool m_horizontal; | 90 bool m_horizontal; |
| 91 AtomicString m_emphasisMark; | 91 AtomicString m_emphasisMark; |
| 92 int m_emphasisMarkOffset; | 92 int m_emphasisMarkOffset; |
| 93 LayoutTextCombine* m_combinedText; | 93 LayoutTextCombine* m_combinedText; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 inline AffineTransform TextPainter::rotation(const FloatRectWillBeLayoutRect& bo
xRect, RotationDirection rotationDirection) | 96 inline AffineTransform TextPainter::rotation(const LayoutRect& boxRect, Rotation
Direction rotationDirection) |
| 97 { | 97 { |
| 98 // Why this matrix is correct: consider the case of a clockwise rotation. | 98 // Why this matrix is correct: consider the case of a clockwise rotation. |
| 99 | 99 |
| 100 // Let the corner points that define |boxRect| be ABCD, where A is top-left
and B is bottom-left. | 100 // Let the corner points that define |boxRect| be ABCD, where A is top-left
and B is bottom-left. |
| 101 | 101 |
| 102 // 1. We want B to end up at the same pixel position after rotation as A is
before rotation. | 102 // 1. We want B to end up at the same pixel position after rotation as A is
before rotation. |
| 103 // 2. Before rotation, B is at (x(), maxY()) | 103 // 2. Before rotation, B is at (x(), maxY()) |
| 104 // 3. Rotating clockwise by 90 degrees places B at the coordinates (-maxY(),
x()). | 104 // 3. Rotating clockwise by 90 degrees places B at the coordinates (-maxY(),
x()). |
| 105 // 4. Point A before rotation is at (x(), y()) | 105 // 4. Point A before rotation is at (x(), y()) |
| 106 // 5. Therefore the translation from (3) to (4) is (x(), y()) - (-maxY(), x(
)) = (x() + maxY(), y() - x()) | 106 // 5. Therefore the translation from (3) to (4) is (x(), y()) - (-maxY(), x(
)) = (x() + maxY(), y() - x()) |
| 107 | 107 |
| 108 // A similar argument derives the counter-clockwise case. | 108 // A similar argument derives the counter-clockwise case. |
| 109 return rotationDirection == Clockwise ? AffineTransform(0, 1, -1, 0, boxRect
.x() + boxRect.maxY(), boxRect.y() - boxRect.x()) | 109 return rotationDirection == Clockwise ? AffineTransform(0, 1, -1, 0, boxRect
.x() + boxRect.maxY(), boxRect.y() - boxRect.x()) |
| 110 : AffineTransform(0, -1, 1, 0, boxRect.x() - boxRect.y(), boxRect.x() +
boxRect.maxY()); | 110 : AffineTransform(0, -1, 1, 0, boxRect.x() - boxRect.y(), boxRect.x() +
boxRect.maxY()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace blink | 113 } // namespace blink |
| 114 | 114 |
| 115 #endif // TextPainter_h | 115 #endif // TextPainter_h |
| OLD | NEW |