提交 dc7bc6e3 编写于 作者: R Raph Levien

Add margins array to line widths object

In order to support layout in non-rectangular regions, the LineWidths
object needs to accept an arbitrary array of margins. This is
implemented in addition to the existing firstWidthLineCount/restWidth
mechanism for convenience, though using only arrays would have the
same expressive power.

Bug: 20182243
Change-Id: Iea96bca1a92012314ac27e617c67f306c1f1b2f2
上级 5cdad92c
......@@ -44,17 +44,29 @@ class LineWidths {
mFirstWidthLineCount = firstWidthLineCount;
mRestWidth = restWidth;
}
void setMargins(const std::vector<float>& margins) {
mMargins = margins;
}
bool isConstant() const {
// technically mFirstWidthLineCount == 0 would count too, but doesn't actually happen
return mRestWidth == mFirstWidth;
return mRestWidth == mFirstWidth && mMargins.empty();
}
float getLineWidth(int line) const {
return (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth;
float width = (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth;
if (!mMargins.empty()) {
if ((size_t)line < mMargins.size()) {
width -= mMargins[line];
} else {
width -= mMargins.back();
}
}
return width;
}
private:
float mFirstWidth;
int mFirstWidthLineCount;
float mRestWidth;
std::vector<float> mMargins;
};
class TabStops {
......@@ -120,6 +132,8 @@ class LineBreaker {
void setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth);
void setMargins(const std::vector<float>& margins);
void setTabStops(const int* stops, size_t nStops, int tabWidth) {
mTabStops.set(stops, nStops, tabWidth);
}
......
......@@ -78,6 +78,11 @@ void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float
mLineWidths.setWidths(firstWidth, firstWidthLineCount, restWidth);
}
void LineBreaker::setMargins(const std::vector<float>& margins) {
mLineWidths.setMargins(margins);
}
// This function determines whether a character is a space that disappears at end of line.
// It is the Unicode set: [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]]
// Note: all such characters are in the BMP, so it's ok to use code units for this.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册