summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2015-04-14 18:29:39 -0700
committerRaph Levien <raph@google.com>2015-04-15 19:12:41 -0700
commitdc7bc6e39e1ef6b713b927baf24db8b4f02f1a3f (patch)
tree019e56fbd9674cae60e20493cc0303bb08995376
parent5cdad92c300a65cab89b172e952186f0c5870657 (diff)
downloadandroid_frameworks_minikin-dc7bc6e39e1ef6b713b927baf24db8b4f02f1a3f.tar.gz
android_frameworks_minikin-dc7bc6e39e1ef6b713b927baf24db8b4f02f1a3f.tar.bz2
android_frameworks_minikin-dc7bc6e39e1ef6b713b927baf24db8b4f02f1a3f.zip
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
-rw-r--r--include/minikin/LineBreaker.h18
-rw-r--r--libs/minikin/LineBreaker.cpp5
2 files changed, 21 insertions, 2 deletions
diff --git a/include/minikin/LineBreaker.h b/include/minikin/LineBreaker.h
index 92e72e2..eb501e7 100644
--- a/include/minikin/LineBreaker.h
+++ b/include/minikin/LineBreaker.h
@@ -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);
}
diff --git a/libs/minikin/LineBreaker.cpp b/libs/minikin/LineBreaker.cpp
index f7f3fb3..9298f77 100644
--- a/libs/minikin/LineBreaker.cpp
+++ b/libs/minikin/LineBreaker.cpp
@@ -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.