1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LineLayoutSVGInlineText_h
#define LineLayoutSVGInlineText_h
#include "core/layout/api/LineLayoutText.h"
#include "core/layout/svg/LayoutSVGInlineText.h"
namespace blink {
class LineLayoutSVGInlineText : public LineLayoutText {
public:
explicit LineLayoutSVGInlineText(LayoutSVGInlineText* layoutSVGInlineText)
: LineLayoutText(layoutSVGInlineText) {}
explicit LineLayoutSVGInlineText(const LineLayoutItem& item)
: LineLayoutText(item) {
SECURITY_DCHECK(!item || item.isSVGInlineText());
}
explicit LineLayoutSVGInlineText(std::nullptr_t) : LineLayoutText(nullptr) {}
LineLayoutSVGInlineText() {}
const Vector<SVGTextMetrics>& metricsList() const {
return toSVGInlineText()->metricsList();
}
SVGCharacterDataMap& characterDataMap() {
return toSVGInlineText()->characterDataMap();
}
bool characterStartsNewTextChunk(int position) const {
return toSVGInlineText()->characterStartsNewTextChunk(position);
}
float scalingFactor() const { return toSVGInlineText()->scalingFactor(); }
const Font& scaledFont() const { return toSVGInlineText()->scaledFont(); }
private:
LayoutSVGInlineText* toSVGInlineText() {
return toLayoutSVGInlineText(layoutObject());
}
const LayoutSVGInlineText* toSVGInlineText() const {
return toLayoutSVGInlineText(layoutObject());
}
};
class SVGInlineTextMetricsIterator {
DISALLOW_NEW();
public:
SVGInlineTextMetricsIterator() { reset(LineLayoutSVGInlineText()); }
explicit SVGInlineTextMetricsIterator(
LineLayoutSVGInlineText textLineLayout) {
reset(textLineLayout);
}
void advanceToTextStart(LineLayoutSVGInlineText textLineLayout,
unsigned startCharacterOffset) {
ASSERT(textLineLayout);
if (!m_textLineLayout || m_textLineLayout != textLineLayout) {
reset(textLineLayout);
ASSERT(!metricsList().isEmpty());
}
if (m_characterOffset == startCharacterOffset)
return;
// TODO(fs): We could walk backwards through the metrics list in these
// cases.
if (m_characterOffset > startCharacterOffset)
reset(textLineLayout);
while (m_characterOffset < startCharacterOffset)
next();
ASSERT(m_characterOffset == startCharacterOffset);
}
void next() {
m_characterOffset += metrics().length();
ASSERT(m_characterOffset <= m_textLineLayout.length());
ASSERT(m_metricsListOffset < metricsList().size());
++m_metricsListOffset;
}
const SVGTextMetrics& metrics() const {
ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size());
return metricsList()[m_metricsListOffset];
}
const Vector<SVGTextMetrics>& metricsList() const {
return m_textLineLayout.metricsList();
}
unsigned metricsListOffset() const { return m_metricsListOffset; }
unsigned characterOffset() const { return m_characterOffset; }
bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); }
private:
void reset(LineLayoutSVGInlineText textLineLayout) {
m_textLineLayout = textLineLayout;
m_characterOffset = 0;
m_metricsListOffset = 0;
}
LineLayoutSVGInlineText m_textLineLayout;
unsigned m_metricsListOffset;
unsigned m_characterOffset;
};
} // namespace blink
#endif // LineLayoutSVGInlineText_h
|