summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2015-06-24 12:59:18 -0700
committerRaph Levien <raph@google.com>2015-06-24 14:08:45 -0700
commita6f8bf6f530f80b00a7cc64605667dd1d75a971c (patch)
tree15410762859d520ce274cf29e01abf232415ead6
parent0d2dbb55c90cc540aad264577c756103660ddff5 (diff)
downloadandroid_frameworks_minikin-a6f8bf6f530f80b00a7cc64605667dd1d75a971c.tar.gz
android_frameworks_minikin-a6f8bf6f530f80b00a7cc64605667dd1d75a971c.tar.bz2
android_frameworks_minikin-a6f8bf6f530f80b00a7cc64605667dd1d75a971c.zip
Separate additional penalty for last line with hyphen
A recent change added a penalty for a hyphen at the last line break, which is visually undesirable. However, the penalty was assessed to "widthScore", which broke the assumption (used for another optimization) that widthScore increases monotonically. This patch separates the penalty into a different parameter, restoring the validity of the monotonicity assumption. Bug: 22066119 Change-Id: I6a47a350ef3ceee2f00ee430d6954d0c307227f0
-rw-r--r--libs/minikin/LineBreaker.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/libs/minikin/LineBreaker.cpp b/libs/minikin/LineBreaker.cpp
index 8275a6c..162d14b 100644
--- a/libs/minikin/LineBreaker.cpp
+++ b/libs/minikin/LineBreaker.cpp
@@ -353,12 +353,17 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) {
float delta = mCandidates[j].preBreak - leftEdge;
// compute width score for line
+
+ // Note: the "bestHope" optimization makes the assumption that, when delta is
+ // non-negative, widthScore will increase monotonically as successive candidate
+ // breaks are considered.
float widthScore = 0.0f;
+ float additionalPenalty = 0.0f;
if (delta < 0) {
widthScore = SCORE_OVERFULL;
} else if (atEnd && mStrategy != kBreakStrategy_Balanced) {
// increase penalty for hyphen on last line
- widthScore = LAST_LINE_PENALTY_MULTIPLIER * mCandidates[j].penalty;
+ additionalPenalty = LAST_LINE_PENALTY_MULTIPLIER * mCandidates[j].penalty;
} else {
widthScore = delta * delta;
}
@@ -369,7 +374,7 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) {
bestHope = widthScore;
}
- float score = jScore + widthScore;
+ float score = jScore + widthScore + additionalPenalty;
if (score <= best) {
best = score;
bestPrev = j;
@@ -378,6 +383,9 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) {
mCandidates[i].score = best + mCandidates[i].penalty + mLinePenalty;
mCandidates[i].prev = bestPrev;
mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1;
+#ifdef VERBOSE_DEBUG
+ ALOGD("break %d: score=%g, prev=%d", i, mCandidates[i].score, mCandidates[i].prev);
+#endif
}
finishBreaksOptimal();
}