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
This commit is contained in:
Raph Levien
2015-04-14 18:29:39 -07:00
parent c76f4113d7
commit 201d894701
2 changed files with 21 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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.