Support hyphenation frequency in Minikin.
Three hyphenation frequencies are now supported: kHyphenationFrequency_None, which turns off both automatic hyphenation and soft hyphens. kHyphenationFrequency_Normal, which has aconservative amount of hyphenation useful as a conservative default. kHyphenationFrequency_Full, which has a typographic-quality amount of hyphenation useful for running text and tight screens. Bug: 21038249 Change-Id: I2800f718c887c9389a1a059d7ec07d7fa2ca1dee
This commit is contained in:
@@ -36,6 +36,12 @@ enum BreakStrategy {
|
||||
kBreakStrategy_Balanced = 2
|
||||
};
|
||||
|
||||
enum HyphenationFrequency {
|
||||
kHyphenationFrequency_None = 0,
|
||||
kHyphenationFrequency_Normal = 1,
|
||||
kHyphenationFrequency_Full = 2
|
||||
};
|
||||
|
||||
// TODO: want to generalize to be able to handle array of line widths
|
||||
class LineWidths {
|
||||
public:
|
||||
@@ -142,6 +148,12 @@ class LineBreaker {
|
||||
|
||||
void setStrategy(BreakStrategy strategy) { mStrategy = strategy; }
|
||||
|
||||
HyphenationFrequency getHyphenationFrequency() const { return mHyphenationFrequency; }
|
||||
|
||||
void setHyphenationFrequency(HyphenationFrequency frequency) {
|
||||
mHyphenationFrequency = frequency;
|
||||
}
|
||||
|
||||
// TODO: this class is actually fairly close to being general and not tied to using
|
||||
// Minikin to do the shaping of the strings. The main thing that would need to be changed
|
||||
// is having some kind of callback (or virtual class, or maybe even template), which could
|
||||
@@ -218,6 +230,7 @@ class LineBreaker {
|
||||
|
||||
// layout parameters
|
||||
BreakStrategy mStrategy = kBreakStrategy_Greedy;
|
||||
HyphenationFrequency mHyphenationFrequency = kHyphenationFrequency_Normal;
|
||||
LineWidths mLineWidths;
|
||||
TabStops mTabStops;
|
||||
|
||||
|
||||
@@ -113,6 +113,9 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa
|
||||
|
||||
// a heuristic that seems to perform well
|
||||
hyphenPenalty = 0.5 * paint->size * paint->scaleX * mLineWidths.getLineWidth(0);
|
||||
if (mHyphenationFrequency == kHyphenationFrequency_Normal) {
|
||||
hyphenPenalty *= 4.0; // TODO: Replace with a better value after some testing
|
||||
}
|
||||
}
|
||||
|
||||
size_t current = (size_t)mBreakIterator->current();
|
||||
@@ -140,7 +143,9 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa
|
||||
// Override ICU's treatment of soft hyphen as a break opportunity, because we want it
|
||||
// to be a hyphen break, with penalty and drawing behavior.
|
||||
if (c != CHAR_SOFT_HYPHEN) {
|
||||
if (paint != nullptr && mHyphenator != nullptr && wordEnd > lastBreak) {
|
||||
if (paint != nullptr && mHyphenator != nullptr &&
|
||||
mHyphenationFrequency != kHyphenationFrequency_None &&
|
||||
wordEnd > lastBreak) {
|
||||
mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak);
|
||||
#if VERBOSE_DEBUG
|
||||
std::string hyphenatedString;
|
||||
@@ -426,6 +431,7 @@ void LineBreaker::finish() {
|
||||
mFlags.shrink_to_fit();
|
||||
}
|
||||
mStrategy = kBreakStrategy_Greedy;
|
||||
mHyphenationFrequency = kHyphenationFrequency_Normal;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
Reference in New Issue
Block a user