OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef TextPainter_h |
| 6 #define TextPainter_h |
| 7 |
| 8 #include "core/rendering/style/RenderStyleConstants.h" |
| 9 #include "platform/geometry/FloatPoint.h" |
| 10 #include "platform/geometry/FloatRect.h" |
| 11 #include "platform/graphics/Color.h" |
| 12 #include "wtf/text/AtomicString.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 class Font; |
| 17 class GraphicsContext; |
| 18 class GraphicsContextStateSaver; |
| 19 class RenderCombineText; |
| 20 class ShadowList; |
| 21 class TextRun; |
| 22 struct TextRunPaintInfo; |
| 23 |
| 24 class TextPainter { |
| 25 public: |
| 26 struct Style; |
| 27 |
| 28 TextPainter(GraphicsContext*, const Font&, const TextRun&, const FloatPoint&
textOrigin, const FloatRect& textBounds, bool horizontal); |
| 29 ~TextPainter(); |
| 30 |
| 31 void setEmphasisMark(const AtomicString&, TextEmphasisPosition); |
| 32 void setCombinedText(RenderCombineText* combinedText) { m_combinedText = com
binedText; } |
| 33 |
| 34 static void updateGraphicsContext(GraphicsContext*, const Style&, bool horiz
ontal, GraphicsContextStateSaver&); |
| 35 |
| 36 void paint(int startOffset, int endOffset, int length, const Style&); |
| 37 |
| 38 struct Style { |
| 39 Color fillColor; |
| 40 Color strokeColor; |
| 41 Color emphasisMarkColor; |
| 42 float strokeWidth; |
| 43 const ShadowList* shadow; |
| 44 |
| 45 bool operator==(const Style& other) |
| 46 { |
| 47 return fillColor == other.fillColor |
| 48 && strokeColor == other.strokeColor |
| 49 && emphasisMarkColor == other.emphasisMarkColor |
| 50 && strokeWidth == other.strokeWidth |
| 51 && shadow == other.shadow; |
| 52 } |
| 53 bool operator!=(const Style& other) { return !(*this == other); } |
| 54 }; |
| 55 |
| 56 private: |
| 57 void updateGraphicsContext(const Style& style, GraphicsContextStateSaver& sa
ver) |
| 58 { |
| 59 updateGraphicsContext(m_graphicsContext, style, m_horizontal, saver); |
| 60 } |
| 61 |
| 62 enum PaintInternalStep { PaintText, PaintEmphasisMark }; |
| 63 |
| 64 template <PaintInternalStep step> |
| 65 void paintInternalRun(TextRunPaintInfo&, int from, int to); |
| 66 |
| 67 template <PaintInternalStep step> |
| 68 void paintInternal(int startOffset, int endOffset, int truncationPoint); |
| 69 |
| 70 void paintEmphasisMarkForCombinedText(); |
| 71 |
| 72 GraphicsContext* m_graphicsContext; |
| 73 const Font& m_font; |
| 74 const TextRun& m_run; |
| 75 FloatPoint m_textOrigin; |
| 76 FloatRect m_textBounds; |
| 77 bool m_horizontal; |
| 78 AtomicString m_emphasisMark; |
| 79 int m_emphasisMarkOffset; |
| 80 RenderCombineText* m_combinedText; |
| 81 }; |
| 82 |
| 83 } // namespace blink |
| 84 |
| 85 #endif // TextPainter_h |
OLD | NEW |