169 Commits

Author SHA1 Message Date
Seigo Nonaka
bbdd73ec07 Support Variation Selector in font selection.
This CL contains the following changes:
- Add a variation selector argument into getFamilyForChar to be able to
  select fonts which support variation selector.
- In case no fonts support the codepoint and variation selector pair,
  add a fallback rule which selects font family with ignoring variation
  selector.
- Change FontCollection::itemize to not change the font family
  immediately preceding a variation selector.
- Introduce unit tests for variation selectors.

With this CL, TextView can render the variation selectors correctly.

Bug: 11256006
Change-Id: I22ce0e9eadc941f84e3a9b23462f194e51dd7180
2015-10-20 12:34:40 +09:00
Roozbeh Pournader
786eac9c7f am e8264e06: (-s ours) Complete half-done cherry-picking of Android.mk. DO NOT MERGE
* commit 'e8264e065f0edd58a9fa04bbdd777f2af2794789':
  Complete half-done cherry-picking of Android.mk. DO NOT MERGE
2015-10-15 03:21:50 +00:00
Roozbeh Pournader
e8264e065f Complete half-done cherry-picking of Android.mk. DO NOT MERGE
The previous commit, 6e2cccdc518f8d3424c84ae6fbe0e87ae3c3f66a, was
incompletely cherry-picked. This adds the missing parts.

Bug: 24570591
Change-Id: I1097c60587fb8a88cfe6b8ffed5b1689d9bdd429
2015-10-14 19:37:47 -07:00
Raph Levien
8925a8c30a am e5e7aa0e: Explicitly set utf-8 encoding for hyb file verification
* commit 'e5e7aa0e8031f6f1c0ed370f70e49778f3570527':
  Explicitly set utf-8 encoding for hyb file verification
2015-10-15 01:56:15 +00:00
Raph Levien
ed833cff3b am 6e2cccdc: (-s ours) Binary format for hyphenation patterns
* commit '6e2cccdc518f8d3424c84ae6fbe0e87ae3c3f66a':
  Binary format for hyphenation patterns
2015-10-15 01:56:14 +00:00
Raph Levien
e5e7aa0e80 Explicitly set utf-8 encoding for hyb file verification
Not all platforms default to UTF-8 encoding, so we set it explicitly.
This patch should fix build breakages resulting from failed verification
of binary hyb files for hyphenation patterns.

Bug: 24570591
Change-Id: I65ac4536d3436586c2633e2b57554fc6ff16d3a8
(cherry picked from commit 138b93f094584212dd6978a1822d078f93574022)
2015-10-14 16:32:17 -07:00
Raph Levien
6e2cccdc51 Binary format for hyphenation patterns
In the current state, hyphenation in all languages than Sanskrit seems
to work (case-folding edge cases). Thus, we just disable Sanskrit.
Packed tries are implemented, but not the finite state machine
(space/speed tradeoff).

This commit contains a throw-away test app, which runs on the host.
I think I want to replace it with unit tests, but I'm including it in
the CL because it's useful during development.

Bug: 21562869
Bug: 21826930
Bug: 23317038
Bug: 23317904
Bug: 24570591
Change-Id: I7479a565a4a062fa319651c2c14c0fa18c5ceaea
(cherry picked from commit f0be43de02a1e07308d3d95408349c3c7f973430)
2015-10-14 16:26:37 -07:00
Seigo Nonaka
0f2a025d13 Introduce FontFamily::hasVariationSelector
This CL introduces new method hasVariationSelector into FontFamily but it
is not used in production code. So no behavior changes are expected.

This CL contains the following changes:
- Introduce hasVariationSelector which returns true if the corresponding
  font has a glyph for a code point and variation selector pair.
- Introduce purgeHbFontCache since hb_face_t won't be released by
  keeping hb_font_t.
- Introduce unit tests with self-built font.

Change-Id: I659a6d03d9ec446b409e1fba2758452abb9f44fa
2015-10-12 18:53:45 +09:00
Keisuke Kuroyanagi
7c8ac67a90 Merge "Refactoring: Introduce helper class to iterate runs." 2015-10-01 20:11:50 +00:00
Raph Levien
741694870a Merge "Explicitly set utf-8 encoding for hyb file verification" 2015-10-01 06:36:47 +00:00
Raph Levien
138b93f094 Explicitly set utf-8 encoding for hyb file verification
Not all platforms default to UTF-8 encoding, so we set it explicitly.
This patch should fix build breakages resulting from failed verification
of binary hyb files for hyphenation patterns.

Change-Id: I65ac4536d3436586c2633e2b57554fc6ff16d3a8
2015-09-30 23:26:54 -07:00
Raph Levien
6ac8ca4ce7 Merge "Binary format for hyphenation patterns" 2015-10-01 04:53:44 +00:00
Raph Levien
f0be43de02 Binary format for hyphenation patterns
In the current state, hyphenation in all languages than Sanskrit seems
to work (case-folding edge cases). Thus, we just disable Sanskrit.
Packed tries are implemented, but not the finite state machine
(space/speed tradeoff).

This commit contains a throw-away test app, which runs on the host.
I think I want to replace it with unit tests, but I'm including it in
the CL because it's useful during development.

Bug: 21562869
Bug: 21826930
Bug: 23317038
Bug: 23317904

Change-Id: I7479a565a4a062fa319651c2c14c0fa18c5ceaea
2015-09-30 21:37:31 -07:00
Seigo Nonaka
fb0d396929 Extract hb_face_t object cache mechanism from Layout.cpp.
This CL does following things:
- Extract hb_face_t object cache mechanism from Layout.cpp to be able to
  use it from other cpp file, especially from FontFamily.cpp.
  To address Bug 11256006 and Bug 17759267, need to touch
  hb_face_t from FontFamily.
- Make hb_face_t cache mechanism thread-safe.
- Add unit tests for HbFaceCache test cases.

Bug: 11256006
Bug: 17759267
Change-Id: Ic183634ef34326793bd9a32167236611d0af34d6
2015-09-30 17:36:44 +09:00
Seigo Nonaka
2ea397d74c Merge "Introduce unit tests for FontCollection::itemize." 2015-09-30 03:33:13 +00:00
Keisuke Kuroyanagi
6292e1a966 Refactoring: Introduce helper class to iterate runs.
This doesn't change current behavior. It's a preparation
for the following CLs.

Bug: 22408712
Change-Id: Ic018422254aa3904655f499194caad74f0c0fc5d
2015-09-29 16:05:15 -07:00
Seigo Nonaka
1c2bd209d1 Introduce unit tests for FontCollection::itemize.
Introduced tests depend on installed font list in running device.
I verified these test passed  on Nexus 5(hammerhead), Nexus 6(shamu)
and Nexus 9(volantis).

Bug: 11256006
Bug: 17759267
Change-Id: I6f806370e17f6c6d3dad8df0cb70bb475a827873
2015-09-18 15:40:51 +09:00
Seigo Nonaka
2a79f59e73 Resolve glyph ID by HarfBuzz function.
Currently codepoint to glyph ID resolution is done through MinikinFont
interface. To support variation selector, use HarfBuzz API instead of
calling this interface since one of its implementation Skia doesn't
support variation selector.

On the other hand, we don't want to get glyph horizontal advance values
by HarfBuzz since HarfBuzz doesn't return correct values when the hinting
is active.

Thus, use ot_font as a parent font and override
glyph_h_advance/glyph_h_origin functions as is.

With this change, MinikinFont::GetGlyph is no longer necessary but not
removing in this CL for easy reverting since removing interface requires
multi-repository commit.

This is a base work of b/11256006 and this patch doesn't provide any
user visible changes.

Bug: 11256006
Change-Id: I061172c0b674bb649ce8bc013ffecf38708bdc41
2015-09-11 16:44:37 +09:00
Seigo Nonaka
4e3adc6fb2 Update word breaker to be aware tone mark and variation selector.
This CL does:
1. Move the getNextWordBreak/getPrevWordBreak function to a separate source file.
2. Adding "ForCache" suffix for function name for making clear these function is
   for layout cache.
3. Introduce unit tests for them.

Bug: 11256006
Change-Id: I4138751a4570915f1a0d6c8921f89700f8ec7f35
2015-08-29 08:02:44 +09:00
Raph Levien
d8dd94b81e Add basic unit tests for Minikin
Initial unit tests for Minikin functionality. Also fixes an incorrect
Hangul case (uncovered in testing), and improves handling of broken
UTF-16.

Change-Id: I69b441d8e3b19ed06abcc56f13271abadf3d1010
2015-08-19 15:00:25 -07:00
Roozbeh Pournader
2967a13420 Clean up use of printf() in Layout.cpp.
Reported externally at https://code.google.com/p/android/issues/detail?id=167715.
Bug: 21498085

Change-Id: I73f22de03b0151ce31a6b3070d051a2a701b33d2
2015-08-11 17:46:18 -07:00
Roozbeh Pournader
71ec970553 Support three-letter language codes in FontLanguage.
Also handle the case of weird language code that we don't understand
properly better, by treating them not equal to each other.

Change-Id: Iaccb251fa38d700932f6eadac254d3d1fa09b3ea
2015-08-07 22:16:25 -07:00
Roozbeh Pournader
c02138bf55 Gold plate grapheme cluster breaks.
This tailors Unicode's Grapheme_Cluster_Break property to better
classify characters currently with the Control property value.

Also adds support for rule GB9b of UAX #29, needed since there are
now characters we are tailoring to be Prepend. The rule was
previously ommited in our implementation because there was no
characters in the Prepend class.

Bug: 15653110
Change-Id: If10da88df0980f7d676c8c0b950eda5fb8dbe741
2015-08-06 14:28:38 -07:00
Raph Levien
90a09c3f36 Improve fallback where explicit variant is not given
In computing scores for which fallback font to choose, a match of a
variant given explicitly in the xml config file scores higher than a
family with no explicit variant. One consequence is that U+2010
HYPHEN is chosen from the Naskh Arabic font in the fallback case.

This patch scores families with no variants as a match (effectively
the same as if the xml file specified both variants). Thus, it will
choose the first matching font (Roboto), which is a better choice.

This patch also revises the list of "sticky" characters to include
various hyphens, so Arabic (and potentially other scripts) text that
includes hyphens can access the script-specific variants matched to
the underlying text.

Bug: 22824219
Change-Id: I6ec1043037f89cad50ca99ac24c473395546bcdf
2015-07-29 14:36:33 -07:00
Raph Levien
5ba60b1c25 Merge "Revert "Allow clusters to start with zero-width characters"" into mnc-dev 2015-07-21 16:55:08 +00:00
Raph Levien
542572394d Revert "Allow clusters to start with zero-width characters"
This reverts commit 3e0fc64da064b8c4156daf53242b8eeb47830f64.

Bug: 22589743
Bug: 22121742
Change-Id: I7b482ffb8a0ee174ddc804aa890de45bdbd758e3
2015-07-21 16:08:08 +00:00
Raph Levien
e9ec9a1d1b Consistently apply break opportunities in text spans
It's essential not to apply a break opportunity within a replacement
span, otherwise things can happen such as displaying the span twice.
The old code tested this case based on zero-width characters.
However, this test was both imprecise, and also in some cases read
uninitialized values from the mCharWidths array, which in turn led
to inconsistent line breaking of the same text.

This patch applies all line break opportunities (as identified by
ICU) within text (as opposed to replacement spans), and also applies
break opportunities at the beginning and end of replacement spans,
but avoids breaks within a replacement span.

Bug: 20138621
Change-Id: I36baeb44d6808356649e1bb69ca57f093fc8c723
2015-07-20 15:37:54 -07:00
Roozbeh Pournader
cdd19dadd1 Use ICU to lowercase words to hyphenate.
Previously, the standard C tolower() function was used, which
didn't support any characters beyond the basic ASCII letters.

Bug: 22506121
Change-Id: Ibb81121caa29be44fbb59aa98891e9faafc57592
2015-07-15 16:31:07 -07:00
Roozbeh Pournader
daf62d0eef Add missing hyphen-like characters.
This adds various hyphen-like characters missed in the previous
patch, that should disallow automatic hyphenation of words containing
them.

Bug: 22484266
Change-Id: Ie972cb50384dbe0aa1ab5ec50286b75f9877953a
2015-07-15 10:59:59 -07:00
Roozbeh Pournader
baf6d0a41f Avoid re-hyphenating already-hyphenated phrases.
Previously, automatic hyphenation blindly took almost every line
breaking opportunity as a word break, so words like "low-budget" were
treated as two separate words, "low-", and "budget", each
automatically hyphenated.

This patch makes sure the subwords in already-hyphenated phrases are
not passed to the automatic hyphenator, while keeping the possibility
of a potential line break where a hyphen already exists.

Bug: 22484266
Bug: 22287425
Change-Id: Ie46dbdd70e993d64a9b9cf44b4ae93b21459dbc2
2015-07-14 13:04:49 -07:00
Raph Levien
6c4d167bff Add HyphenEdit to layout cache
We bypass the word layout cache for "complex" cases, which includes
things like OpenType features. We were counting a hyphen edit as such
a case, but the problem is that we measure a _lot_ of these when
doing layout with hyphenation.

This patch adds plumbing for hyphen edits to the layout cache, so
that word fragments with hyphens can be cached as well.

Bug: 22378829

Change-Id: Idba4df4faa14f48a5faccc8a7a7955a36c19ef27
2015-07-09 17:38:58 -07:00
Raph Levien
3e0fc64da0 Allow clusters to start with zero-width characters
The logic in getRunAdvance() assumed that any zero-width character was
part of the preceding cluster, which is valid most of the time. However,
characters such as ZWNBSP (U+FEFF) renders as a zero width glyph
and is also a grapheme cluster boundary. This patch adds a clause to
handle that case.

Bug: 22121742
Change-Id: Iad79a7d988bded1ef05f0fd7905d20669ea22051
2015-06-30 10:15:43 -07:00
Raph Levien
91425f0564 Fix logspam and incorrect cluster offset
An incorrect cluster offset calculation was causing a lot of log
messages to appear. Separately, a confusion between #if and #ifdef was
causing unintended logging of line breaks. This patch fixes both.

Bug: 22178333
Change-Id: I2b3673ed66c784f5082fd127a8dc10bd3df6ed79
2015-06-29 14:21:10 -07:00
Raph Levien
e8721b2d29 Disable letterspacing for connected scripts
The appearance of letterspacing with scripts with cursive connections
is poor, so we simply disable letterspacing for those scripts. There
may be some cases where some form of letterspacing is desirable, but
this gives the highest likelihood that the final result will be good
without requiring additional work from clients.

Bug: 21935803
Change-Id: Ie25266249ac3a2605aa89ef5132e8edbe3a06d35
2015-06-26 11:15:17 -07:00
Raph Levien
a6f8bf6f53 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
2015-06-24 14:08:45 -07:00
Roozbeh Pournader
0d2dbb55c9 Merge "Use ASCII HYPHEN-MINUS when there's no HYPHEN in the font." into mnc-dev 2015-06-12 22:30:03 +00:00
Roozbeh Pournader
f997dd2196 Use ASCII HYPHEN-MINUS when there's no HYPHEN in the font.
Previously, we just assumed the font in use had a U+2010 HYPHEN
character, resulting in a tofu (or an empty space) being shown when
U+2010 was not supported in the font used to render the hyphenated
word.

Now we try to fallback to U+002D HYPHEN-MINUS, which has a very good
chance of being available in at least any Latin font.

We still show a tofu when neither character is supported, to
intentionally alert that something is missing.

Bug: 20497913
Bug: 21088552
Bug: 21570828
Change-Id: Iff69bbc38836c03495e9124502b5207c39270da2
2015-06-12 15:23:10 -07:00
Raph Levien
17e78fa864 Merge "Increase hyphenation penalty for short last line" into mnc-dev 2015-06-12 21:59:05 +00:00
Keisuke Kuroyanagi
4ea1cc82b0 Fix: getOffsetForAdvance can return worng offset.
searchStart was passed to getRunAdvance, but it can be
different from the start that has been used to initialize
Layout object. As a result, wrong index could be used in
getRunAdvance.

Bug: 21744454
Change-Id: Ibe83cc50ed6f0da2a1532318bc224502be350699
2015-06-10 17:45:46 +09:00
Raph Levien
abae97a39c Increase hyphenation penalty for short last line
Tuning for hyphenation parameters. We discourage hyphenation on the
last line, but offset this penalty by also applying a penalty for
each line, which optimizes for minimizing the number of lines. Thus,
when hyphenation can reduce the number of lines, it increases the
chance they're used.

There's probably more tuning and refinement that can be done, but
testing suggests that the tunable parameters are appropriate.

Bug: 20883322

Change-Id: Ida7eaf8aced109e426694f5a386924a842d29c4b
2015-06-08 15:23:20 -07:00
Raph Levien
73fa6dfd63 Merge "Use context start correctly in getRunAdvance" into mnc-dev 2015-06-01 21:33:48 +00:00
Raph Levien
95af01c57b Use context start correctly in getRunAdvance
We were not taking context start into account when deciding whether
to split a ligature, which was causing inconsistent behavior. This
patch consistently references the widths array relative to the start
of the context.

Bug: 21549197
Change-Id: I7c71e10c1af84354fefe782fc0b87120016e6555
2015-06-01 14:27:00 -07:00
Raph Levien
a019665898 Disable hyphenation for unreasonably long words
Very long words cause O(n^2) behavior. These are unlikely to happen in
real text, but do happen with synthetic strings, so in those cases we
just disable hyphenation.

Bug: 20790394
Change-Id: Idf957dd40b24efe1476f619f17093a48b5bc56f7
2015-06-01 12:46:47 -07:00
Roozbeh Pournader
0dc07c0be3 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
2015-05-12 14:51:36 -07:00
John Reck
8920e81717 Move Bitmap to a different namespace
namespace naming collision. Move minikin's
Bitmap out of android:: and into minikin::

Change-Id: I5ae3925f81b848dc79576429ab55243b96f7fed2
2015-04-27 17:23:29 +00:00
Raph Levien
68ae337aa0 Don't include trailing newline in width for line breaking
In a paragraph with a trailing newline, the width of the newline
character was included in the line width for breaking purposes,
basically as if it were a non-breaking space. This caused a
discrepancy, where Layout.getDesiredWidth() suggested that the text
would fit in a single line, but StaticLayout would break it because of
the added width of the newline character.

The proposed fix is simply to consider newline to be a space that
disappears at the end of a line.

Bug: 20152308
Change-Id: I539574c5b8ea892c8ed6aca6c59e90ccdf74a680
2015-04-22 15:31:29 -07:00
Raph Levien
40beb7744a Add functions for measuring cursor positioning
New functions for computing the correspondence between cursor
position and advance, respecting grapheme boundaries.

Change-Id: I620378d5f64cd74300cd43db522adeb555825dff
2015-04-15 20:19:10 -07:00
Raph Levien
bb86b433f9 Rename "margins" to "indents"
The name "margin" conflicts with another meaning, so we're making the
name in the public api "idents" and the code consistent in naming.

Change-Id: I9170116b4d972e4b25f0f319e78376310288eb41
2015-04-15 19:12:48 -07:00
Raph Levien
dc7bc6e39e 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
2015-04-15 19:12:41 -07:00
Raph Levien
5cdad92c30 Revert "Fix build: Revert "Add hyphenation to line breaking""
This reverts commit 0b25d5ac85533f64764a0d53d5e5d33b46b715fa.
2015-03-30 14:20:18 -07:00