This patch adds plumbing to TextView and StaticLayout to control the
frequency of automatic hyphenation used in laying out paragraphs.
Bug: 21038249
Change-Id: Ib45de190eb0a1ed738e69fd61f2b39561b11aec7
Previous getWordEnd and getWordStart functions would return a boundary
rather than a word end / start boundary in some cases. This behavior is
most evident when moving between short lines -- the handle would go to
the next boundary rather than the word end on the next line (and the
start handle would go to the word end rather than the word start on
the prev line).
This CL ensures that word or punctuation boundaries are returned and moves
most of the punctuation boundary logic into WordIterator since it makes
a bit more sense there.
Bug: 21030788
Change-Id: I96c6aff7f2c213aa3c4f66ac87ca913ca16fd347
This treats punctuation as "words", so groups of punctuation will be
selected together, i.e. "Hmm... yay!!!" would be treated as four words:
Hmm-...-yay-!!!
Bug: 19950062
Change-Id: Ic9514c524092734fad1abdf19a736bfa1406157b
When returning a StaticLayout.Builder object to the pool, it is
important to clear everything out. If not, then the object may have
stale state from a previous layout operation. This was causing CTS
test failures and probably other mischief.
Bug: 20636917
Change-Id: I76fb20076ee954fcb476131a8fbe8833d72fbc0d
The typeface in a TypefaceSpan can be the null string. This patch
fixes the string comparison to not throw a NullPointerException.
Bug: 20849738
Change-Id: Ied049305794966bcbca00cfd11fe97a91b685d79
Expose the new Builder pattern for creating StaticLayout. This allows
access to a number of features that have been available to TextView
through a hidden constructor. Some of these features have existed
for a while (mostly maxLines), while others are new (breakStrategy,
indents).
The builder is cleaner and has a better upgrade path than the old
pattern of lots of constructors with varying numbers of arguments.
Bug: 20190561
Change-Id: Ia3cd124825ab0cb469d22d1fc576ad26454545b8
This patch moves the Paint parameter from being an option set from
setPaint to being a required field passed into the obtain() method
of StaticLayout.Builder. Thus, it is now possible to get a valid
StaticLayout object just doing .build() on the Builder; all other
fields are optional.
This is in preparation for exposing the builder publicly, but that
is to be a separate CL.
Bug: 20190561
Change-Id: Iefd7800203004e565d068b0c76502cf7cf52d91f
In support of layout of paragraphs to non-rectangular regions, add
arrays for left and right indents to TextView, along with supporting
StaticLayout builder setters.
Bug: 20182243
Change-Id: I015bcef8f258c89001fcf8a54c179d2dfc0d7943
1. The algorithms no longer consider directional embeddings and
overrides as strong characters.
2. The algorithms are updated to Unicode 7.0, and consider the
directional isolates in determining the direction of input.
3. Codepoints are used instead of code units for looking up bidi
properties.
4. The bidi direction of unassigned characters is considered.
Bug: 20142480
Change-Id: I9be161c112b8f23565ed8961bb7d44ced234f67a
Ctrl+Backspace deletes preceding one word and Ctrl+ForwardDelete delets
following one word.
Used Chrome's implementation/behvior as a reference.
Bug: 17810742
Change-Id: I7b2ca515b2f017e457f7104ec7b8e7473ca4e081
The paint of a layout may be reused with other things (in particular,
it can be passed to a BoringLayout), so make sure the hyphenEdit is
zeroed out after use.
Change-Id: If58c5588af9642c3ba827acefea7895e814daab9
If SpanSet.init() is called several times in a row with different
values, it is possible to change "numberOfSpans" in a way that
will prevent SpanSet.recycle() from nulling out all the spans.
This can lead to memory leaks of large objects through spans
references. User @piwai reported this leak:
com.squareup.marketfont.MarketSpan
`-[1] of array android.text.style.CharacterStyle[]
`-spans of object android.text.SpanSet
`-mCharacterStyleSpanSet of object android.text.TextLine
`-[1] of array android.text.TextLine[]
`-sCached of class android.text.TextLine
The MarketSpan instance is kept alive through a recycled TextLine
which itself contains a SpanSet.
Change-Id: Idfb2233ca16895dbe735c312662eaf0b4a2ecd65
Loading hyphenation data on demand can cause UI jank (and can be a
strict mode violation). This patch explicitly loads the data at
Zygote init time. It also chooses /system/usr/hyphen-data as the path
for this data.
Bug: 20060770
Change-Id: Idac68e3971f8638f1d70960594bf6c1050bb23d6
This patch adds plumbing to TextView to control the strategy used
for breaking paragraphs into lines.
The default for TextView is "quality", while the default for EditText
is "simple", largely to avoid too much re-layout when editing.
StaticLayout now has a builder which provides access to more
functionality and is also cleaner than the old mechanism of having
lots of constructors with varying numbers of arguments. This patch
changes TextView to use that builder, and also contains cleanups
of the Builder within StaticLayout.
Change-Id: Iee3cf3a05a3e51ba0834554e4a3ec606e9cabca5
This reverts commit 5a6eeb3cbe and
fixes the underlying issue (needed to @hide getHyphen() for subclasses
of Layout, not just the base class), and layoutlib changes for
checkbuild.
Change-Id: I7a2b5f20ae014ea8e224d8c4079cf9131e17e1c1
This patch plumbs up hyphens computed in Minikin's LineBreaker,
records them in a new column in StaticLayout, and draws them.
DynamicLayout mirrors the new column, and TextLine is also changed to
make sure the hyphen is only drawn for the last run in a line.
There is a rather primitive mechanism for loading hyphenation
patterns, for testing only at this point.
Change-Id: Ib208568c0f6cff12cf834047500ec1da9ea9f430
This patch moves the calculation of line breaks for StaticLayout into
the new LineBreaker class provided by Minikin. This specific patch
should preserve existing functionality, but perhaps performance is
better, and the movement opens the door to much more sophisticated
line-breaking.
Change-Id: Iafccb9da4e3559bbeaeb2c7c85f86ddfd8ae2fa1
Previously, after the first paragraph, the the detected bidi
direction of the text in the last paragraph was used, nstead of the
detected bidi direction of the current one.
Bug: 12027356
Change-Id: I51622a3156f1e321f53f7ca1855bc37aa6f77319
Use span properties to detect:
* Composing text - don't record undo operations
* Completing a composition - record an insert undo operation
* Canceling a composition - don't record
Save the composition state on parcel/unparcel.
Stop using begin/end batch edit to try to detect when a TextWatcher
is modifying the text. IMEs trigger multiple InputFilter passes in
a single batch edit. Use SpannableStringBuilder to determine when
we're in a TextWatcher callback because it is the authority on that
state.
Fix a bug in undo manager where it doesn't forget undos correctly if
there are more than one in the stack.
Bug: 19332904
Change-Id: Iaa9b0b2a7bf6683302cc85e7616e5d5fcc9fa202
The comparator's equal implementation doesn't satisfy the constraints
of an equals method, namely being reflexive. Use the standard Object
implementation instead.
Bug: 19797138
Change-Id: I74f888e99533e1945aab7ab10fe8ee3ded6388f4
We want to move text measurement into native code, mostly so that
alternate measurement for hyphens can be performant. This patch begins
that migration, in the main StaticLayout case, but still surfaces the
widths array to Java (for ellipsis calculation), and also includes a
hack (used mostly for testing) for computing widths in Java and sending
them down to native code when TextPaint is subclassed.
Change-Id: I476c9e8b3aa8e4e3552eb18f66c4bcd5683f3a72
The "moreChars" predicate (which is used in ellipsis computation) was
slightly incorrect, sometimes being computed as false when the line
break is at the end of a paragraph but not the end of the buffer.
This patch makes the behavior consistent with shipping versions.
Bug: 19676414
Change-Id: I72e16794e895c2eb765b21feaf59fcdccc4857f1
This patch adds a native C++ Builder object for StaticLayout to
complement the Java one introduced in a previous patch.
The Builder object contains state used in constructing a layout, as well
as temporary buffers, to avoid having to allocate such. In particular,
it holds a break iterator, so avoids the cost of constructing that in
the common case of a single locale.
Change-Id: I1125103b7ccf00b8674c1586c3ea8d5d915fdd5b