OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 LineLayoutSVGInlineText_h | 5 #ifndef LineLayoutSVGInlineText_h |
6 #define LineLayoutSVGInlineText_h | 6 #define LineLayoutSVGInlineText_h |
7 | 7 |
8 #include "core/layout/api/LineLayoutText.h" | 8 #include "core/layout/api/LineLayoutText.h" |
9 #include "core/layout/svg/LayoutSVGInlineText.h" | 9 #include "core/layout/svg/LayoutSVGInlineText.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 { | 51 { |
52 return toLayoutSVGInlineText(layoutObject()); | 52 return toLayoutSVGInlineText(layoutObject()); |
53 } | 53 } |
54 | 54 |
55 const LayoutSVGInlineText* toSVGInlineText() const | 55 const LayoutSVGInlineText* toSVGInlineText() const |
56 { | 56 { |
57 return toLayoutSVGInlineText(layoutObject()); | 57 return toLayoutSVGInlineText(layoutObject()); |
58 } | 58 } |
59 }; | 59 }; |
60 | 60 |
| 61 class SVGInlineTextMetricsIterator { |
| 62 DISALLOW_NEW(); |
| 63 public: |
| 64 SVGInlineTextMetricsIterator() { reset(nullptr); } |
| 65 |
| 66 void advanceToTextStart(LineLayoutSVGInlineText* textLineLayout, unsigned st
artCharacterOffset) |
| 67 { |
| 68 ASSERT(textLineLayout); |
| 69 if (m_textLineLayout != textLineLayout) { |
| 70 reset(textLineLayout); |
| 71 ASSERT(!metricsList().isEmpty()); |
| 72 } |
| 73 |
| 74 if (m_characterOffset == startCharacterOffset) |
| 75 return; |
| 76 |
| 77 // TODO(fs): We could walk backwards through the metrics list in these c
ases. |
| 78 if (m_characterOffset > startCharacterOffset) |
| 79 reset(textLineLayout); |
| 80 |
| 81 while (m_characterOffset < startCharacterOffset) |
| 82 next(); |
| 83 } |
| 84 |
| 85 void next() |
| 86 { |
| 87 m_characterOffset += metrics().length(); |
| 88 ++m_metricsListOffset; |
| 89 } |
| 90 |
| 91 const SVGTextMetrics& metrics() const |
| 92 { |
| 93 ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size()); |
| 94 return metricsList()[m_metricsListOffset]; |
| 95 } |
| 96 const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout-
>layoutAttributes()->textMetricsValues(); } |
| 97 unsigned metricsListOffset() const { return m_metricsListOffset; } |
| 98 unsigned characterOffset() const { return m_characterOffset; } |
| 99 bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); } |
| 100 |
| 101 private: |
| 102 void reset(LineLayoutSVGInlineText* textLineLayout) |
| 103 { |
| 104 m_textLineLayout = textLineLayout; |
| 105 m_characterOffset = 0; |
| 106 m_metricsListOffset = 0; |
| 107 } |
| 108 |
| 109 LineLayoutSVGInlineText* m_textLineLayout; |
| 110 unsigned m_metricsListOffset; |
| 111 unsigned m_characterOffset; |
| 112 }; |
| 113 |
61 } // namespace blink | 114 } // namespace blink |
62 | 115 |
63 #endif // LineLayoutSVGInlineText_h | 116 #endif // LineLayoutSVGInlineText_h |
OLD | NEW |