173 Commits

Author SHA1 Message Date
Seigo Nonaka
6f9966ea7c Introduce multiple language based font fallback.
The motivation of this CL is enhance the font fallback score design
to support multiple language font fallback.

This CL contains following changes:
- Break language based font score into two: script-based score and
  primary-language-based score.
- The primary-language-based score is 0 if the script-based score is 0.
  If the script-based score is not 0 and the primary language is the
  as same as the requested one, the font gets an extra score of 1.
- The language score gets a higher multiplier for languages higher in
  the locale list.

Bug: 25122318
Bug: 26168983
Change-Id: Ib999997a88e6977e341f4c325e2a1b41a59db2d5
2016-01-15 14:35:14 +09:00
Raph Levien
6638e05ac2 Tailor grapheme boundaries so sequence emoji are one grapheme
Make it so it's not possible to position the cursor inside an emoji
formed by a sequence including zero-width joiners.

Bug: 25368653
Change-Id: I67ec0874cd1505f3c82ab91492ffc3d39a52fae6
2016-01-13 12:52:38 -08:00
Raph Levien
73abbd5934 Reject fonts with invalid ranges in cmap
A corrupt or malicious font may have a negative size in its cmap
range, which in turn could lead to memory corruption. This patch
detects the case and rejects the font, and also includes an assertion
in the sparse bit set implementation if we missed any such case.

External issue:
https://code.google.com/p/android/issues/detail?id=192618

Bug: 26413177
Change-Id: Icc0c80e4ef389abba0964495b89aa0fae3e9f4b2
2016-01-07 13:38:42 -08:00
Andreas Gampe
a5706e4ef9 Minikin: Disable sanitizer on x86 am: 72c026822d
am: 0497c013f6

* commit '0497c013f640324550ff731bc088bb62fbb6882a':
  Minikin: Disable sanitizer on x86
2016-01-07 04:47:52 +00:00
Andreas Gampe
0497c013f6 Minikin: Disable sanitizer on x86
am: 72c026822d

* commit '72c026822d32550b10bb62949644c10826d7658e':
  Minikin: Disable sanitizer on x86
2016-01-07 04:45:20 +00:00
Andreas Gampe
72c026822d Minikin: Disable sanitizer on x86
Disable unsigned-integer-overflow sanitizer on x86, as it crashes.

Bug: 25884483
Bug: 26432628
Change-Id: Ia658ed56a6c81660a36edf71f7116118056aa917
2016-01-06 20:28:52 -08:00
Dan Austin
97944f2856 Enable integer sanitization in libminikin am: 7087da2519
am: cf6ebc1ebc

* commit 'cf6ebc1ebcc9137c12e221799f3b20436d2984c1':
  Enable integer sanitization in libminikin
2016-01-06 20:44:58 +00:00
Dan Austin
cf6ebc1ebc Enable integer sanitization in libminikin
am: 7087da2519

* commit '7087da2519f0aa303e5941e7d8cfbe2a73e696a2':
  Enable integer sanitization in libminikin
2016-01-06 20:42:47 +00:00
Dan Austin
7087da2519 Enable integer sanitization in libminikin
Enable signed and unsigned integer sanitization in libminikin.

Bug: 25884483
Change-Id: I98905827174d16138d20bb443fe2e1d7228ea1a3
2016-01-06 12:30:12 -08:00
Dan Austin
728ae8d629 Revert "Enable integer sanitization in libminikin." am: 342cd45a5e
am: 5255614d23

* commit '5255614d230d241432c7f86c4ce3582a8cb71545':
  Revert "Enable integer sanitization in libminikin."
2016-01-06 18:38:18 +00:00
Dan Austin
5255614d23 Revert "Enable integer sanitization in libminikin."
am: 342cd45a5e

* commit '342cd45a5e5779e81155515d36cd500bfd975fdf':
  Revert "Enable integer sanitization in libminikin."
2016-01-06 18:36:33 +00:00
Dan Austin
342cd45a5e Revert "Enable integer sanitization in libminikin."
This reverts commit 9c13a3dc96d16976c45417bdc34e0fc5670815b9.

Change-Id: Iecd1f61a5fdf5955d871a920cb243553857d46ff
2016-01-06 18:31:38 +00:00
Dan Austin
679f147eda Enable integer sanitization in libminikin. am: 9c13a3dc96
am: ebe371670e

* commit 'ebe371670e760b5318db6a02e10775e4a4ed7b96':
  Enable integer sanitization in libminikin.
2016-01-06 17:08:33 +00:00
Dan Austin
ebe371670e Enable integer sanitization in libminikin.
am: 9c13a3dc96

* commit '9c13a3dc96d16976c45417bdc34e0fc5670815b9':
  Enable integer sanitization in libminikin.
2016-01-06 17:06:22 +00:00
Seigo Nonaka
7564b7fd5b Merge "Fix race condition in Paint.hasGlyph()" 2016-01-06 06:00:38 +00:00
Seigo Nonaka
a6f5c46836 Fix race condition in Paint.hasGlyph()
The caller of FontFamily::hasVariationSelector needs to acquire the
lock before calling it, but FontCollection::hasVariationSelector
didn't acquire the lock. This caused a race condition.
This CL fixes this race condition.

Also, it turned out that assertMinikinLocked didn't assert even on
eng or userdebug device. This CL enables assertion on eng and userdebug
device since this assertion must be treated as bug.

BUG: 26323806

Change-Id: I9c4b1e1f09c6793e387fbdb8bb654cc0a13c65d5
2016-01-06 03:21:37 +00:00
Dan Austin
9c13a3dc96 Enable integer sanitization in libminikin.
Enable signed and unsigned integer sanitization in libminikin.

Bug: 25884483
Change-Id: I53abf6affea8e2bb3a5abd381a9f19003a306b36
2016-01-05 17:36:31 -08:00
Roozbeh Pournader
b5aba20c13 Merge "Replace Qaae script with Zsye" 2016-01-05 21:54:29 +00:00
Seigo Nonaka
d337652233 Replace Qaae script with Zsye
The emoji variant script "Zsye" is registered in ISO 15924.

Bug: 26226285
Change-Id: Ibc2bc740d57c48f99b6f66b1ad7595bfa8c3cff4
2016-01-05 05:05:57 +00:00
Seigo Nonaka
198b46f1fe Save all kind of script tags into FontLanguage.
This is 2nd attempt of I8df992a6851021903478972601a9a5c9424b100c.

The main purpose of this CL is expanding FontLanguage to be able to
save full script tag. Previously, FontLangauge kept only limited script
tags. With this CL, FontLanguage keeps all script tags.

This CL contains the following changes:
- FontLanguage changes:
-- Moved to private directory not to be instantiated outside of Minikin.
-- Removed bool(), bits(), FontLanguage(uint32_t) methods which are no
   longer used.
-- Change the FontLanguage internal data structure.
-- Introduces script match logic.

- FontLanguages changes:
-- Moved to private directory not to be instantiated outside of Minikin.
-- This is now std::vector<FontLanguage>

- FontLanguageListCache changes:
-- Now FontLanguageListCache::getId through
   FontStyle::registerLanguageList is the only way to instantiate the
   FontLanguage.
-- Normalize input to be BCP47 compliant identifier by ICU.

Bug: 26168983
Change-Id: I431b3f361a7635497c05b85e8ecbeb48d9aef63e
2016-01-05 14:00:32 +09:00
Bart Sears
6c4c098cbd Revert "Save all kind of script tags into FontLanguage."
This reverts commit 5e995fb850c2b32631914c3815dfb421855fba9b.

Change-Id: I761e0e41906742fbe3d3ac34170af3101e18042a
2015-12-22 09:06:03 +00:00
Seigo Nonaka
5e995fb850 Save all kind of script tags into FontLanguage.
The main purpose of this CL is expanding FontLanguage to be able to
save full script tag. Previously, FontLangauge kept only limited script
tags. With this CL, FontLanguage keeps all script tags.

This CL contains the following changes:
- FontLanguage changes:
-- Moved to private directory not to be instantiated outside of Minikin.
-- Removed bool(), bits(), FontLanguage(uint32_t) methods which are no
   longer used.
-- Change the FontLanguage internal data structure.
-- Introduces script match logic.

- FontLanguages changes:
-- Moved to private directory not to be instantiated outside of Minikin.
-- This is now std::vector<FontLanguage>

- FontLanguageListCache changes:
-- Now FontLanguageListCache::getId through
   FontStyle::registerLanguageList is the only way to instantiate the
   FontLanguage.
-- Normalize input to be BCP47 compliant identifier by ICU.

Bug: 26168983
Change-Id: I8df992a6851021903478972601a9a5c9424b100c
2015-12-22 09:34:04 +09:00
Dan Austin
1f0d794737 Refactored unsigned long negations am: 1bbe03d215
am: b9f27a2509

* commit 'b9f27a2509241a0f2dfcf6921958dab4b14fbc42':
  Refactored unsigned long negations
2015-12-14 09:30:20 -08:00
Dan Austin
b9f27a2509 Refactored unsigned long negations
am: 1bbe03d215

* commit '1bbe03d215c9452bc9917111e63f19160cc5f56a':
  Refactored unsigned long negations
2015-12-14 09:12:42 -08:00
Dan Austin
1bbe03d215 Refactored unsigned long negations
Replaced two instances of negating an unsigned long, which was
resulting in aborts from unsigned integer sanitization with the
equivalent logical not-add 1.

Bug: 25884483
Change-Id: Ic7498e0af638dcd438ce69803021d3cdc3acd4f6
2015-12-11 16:33:23 -08:00
Seigo Nonaka
43bb9743ca Remove script matching score from the font selection fallback.
Removing the extra score of 2 for the script matching from the font
fallback score calculation.  If the two langauges have different
scripts, we should treat them as different languages.

Change-Id: Ie0d6f27bd1086248895935a7bd01b5d404044ad0
2015-12-10 18:41:03 -08:00
Seigo Nonaka
6d9dcd2cf3 Introduce FontLanguageListCache.
FontLanguageListCache is an intentionally leaky singleton and its
internal cache won't be purged.

BUG: 25122318

Change-Id: I272097e979fe44b83fd86822235350e12eda8f51
2015-12-08 18:49:18 -08:00
Seigo Nonaka
a47969c90a Merge "Select emoji font based on variation selectors." 2015-12-08 21:29:42 +00:00
Raph Levien
8921cfe226 Avoid integer overflows in parsing fonts am: 6299a6ba13 am: 998293f985 am: ffadd191a0 am: d56908571d
am: 7aec64b909

* commit '7aec64b9099d0b5bbbe766a2c29b9f09f0939a4c':
  Avoid integer overflows in parsing fonts
2015-12-08 11:36:58 -08:00
Raph Levien
7aec64b909 Avoid integer overflows in parsing fonts am: 6299a6ba13 am: 998293f985 am: ffadd191a0
am: d56908571d

* commit 'd56908571d3dc28686a198484d1cc8a399276d86':
  Avoid integer overflows in parsing fonts
2015-12-08 19:33:14 +00:00
Raph Levien
d56908571d Avoid integer overflows in parsing fonts am: 6299a6ba13 am: 998293f985
am: ffadd191a0

* commit 'ffadd191a041f16c52b693d8dc0c42b3b9f01b2b':
  Avoid integer overflows in parsing fonts
2015-12-08 11:29:31 -08:00
Raph Levien
ffadd191a0 Avoid integer overflows in parsing fonts am: 6299a6ba13
am: 998293f985

* commit '998293f985dc6c23f90b160f3bc647807c76d3fe':
  Avoid integer overflows in parsing fonts
2015-12-08 19:22:49 +00:00
Raph Levien
998293f985 Avoid integer overflows in parsing fonts
am: 6299a6ba13

* commit '6299a6ba13906c695f7a4f6748f7bc5856a110e5':
  Avoid integer overflows in parsing fonts
2015-12-08 19:17:40 +00:00
Seigo Nonaka
369d2d44cb Select emoji font based on variation selectors.
If U+FE0E is appended to the emoji code point, the glyph should have a
text presentation.
On the other hand, if U+FE0F is appended to the emoji code point, the
glyph should have an emoji presentation.

Bug: 11256006
Change-Id: I5187d44500b13a138e7ffbcf2c72e2da06374c8c
2015-12-07 16:49:16 -08:00
Raph Levien
6299a6ba13 Avoid integer overflows in parsing fonts
A malformed TTF can cause size calculations to overflow. This patch
checks the maximum reasonable value so that the total size fits in 32
bits. It also adds some explicit casting to avoid possible technical
undefined behavior when parsing sized unsigned values.

Bug: 25645298
Change-Id: Id4716132041a6f4f1fbb73ec4e445391cf7d9616
(cherry picked from commit 183c9ec2800baa2ce099ee260c6cbc6121cf1274)
2015-12-07 17:58:12 +00:00
Raph Levien
183c9ec280 Avoid integer overflows in parsing fonts
A malformed TTF can cause size calculations to overflow. This patch
checks the maximum reasonable value so that the total size fits in 32
bits. It also adds some explicit casting to avoid possible technical
undefined behavior when parsing sized unsigned values.

Bug: 25645298
Change-Id: Id4716132041a6f4f1fbb73ec4e445391cf7d9616
2015-11-30 15:08:41 -08:00
Seigo Nonaka
66a34a04ab Merge "Search all families instead of using mRanges for variation sequence." 2015-11-20 05:46:31 +00:00
Seigo Nonaka
fc119c68f5 Search all families instead of using mRanges for variation sequence.
To optimize the font family search, mRanges is used for narrowing down
the search range. However, mRanges is constructed from format 4 or
format 12 entries. So, if the font supports a variation sequence but doesn't
support the base character of the sequence, the font may not be listed in
mRanges.

The proper way to fix this issue is using format 14 subtable information
for mRanges construction. However, this is not a trivial work since currently
we rely on HarfBuzz for variation sequence lookup and it doesn't provide any
API for retrieving coverage information.

Thus, as the quick fix, iterate all font families in font fallback chain if
the variation sequence is specified.

Change-Id: I278da84be8fb8f553590e2e42ed450b7e4a34eca
2015-11-19 17:14:59 +09:00
Seigo Nonaka
80d113bcd4 Introduce FontCollection::hasVariationSelector method.
To implement Paint.hasGlyph(), we need a new method to ask the
FontCollection if it has a glyph for the code point and variation
selector pair.

Bug: 11256006
Change-Id: Ie4185c91bcaa4d01aee6beb97784b1f9d2a88f12
2015-11-19 17:01:46 +09:00
Seigo Nonaka
3dd8757fcf Fix invalid decrement range of KEYCAP handling in itemize.
This issue was introduced by I22ce0e9eadc941f84e3a9b23462f194e51dd7180.
Need to decrement the two utf16 chars in KEYCAP handling.

To add unit tests, this CL also addresses the Bug: 24184208 by
introducing self built fonts since there is no good example in system
installed fonts.

Bug: 24184208
Change-Id: I23fa008adbaced78a3cb96442a6bc8892ab84ce8
2015-11-13 14:39:06 +09:00
Raph Levien
c65e6f1ee0 Suppress linebreaks in emoji ZWJ sequences - DO NOT MERGE
Due to the way emoji ZWJ sequences are defined, the ICU line breaking
algorithm determines that there are valid line breaks inside the
sequence. This patch suppresses these line breaks.

Bug: 25433289
Change-Id: I225ebebc0f4186e4b8f48fee399c4a62b3f0218a
2015-11-03 05:16:31 +00:00
Raph Levien
adaf42f0d3 Accept variation selector in emoji sequences - DO NOT MERGE
This patch basically ignores variation selectors for the purpose of
itemization into font runs. This allows GSUB to be applied when input
sequences contain variation selectors.

Bug: 25368653
Change-Id: I9c1d325ae0cd322c21b7e850d0ec4d73551b2372
2015-10-29 12:30:57 -07:00
Seigo Nonaka
bae3476829 Add -Werror -Wall -Wextra to compiler option.
This is 2nd trial of I30a0914a4633bd93eb60957cdf378770f04d8428

- To suppress noisy unused parameter warnings, comment out unused
  arguments.
- Add -Werror for suppressing further warning.
- Add -Wall -Wextra for safety.
- Use "z" prefix for format string of size_t.

Verified that compile succeeded on all arm,arm64,mips,x86,x86_64.

Change-Id: I7ad208464486b8a35da53929cb1cfe541ed0052f
2015-10-28 04:52:49 +00:00
Bart Sears
b4c7991804 Revert "Add -Werror -Wall -Wextra to compiler option."
This reverts commit 63635cff5861dcaed963c7332eecf51b9d7d920a.

Change-Id: I2b4b10e8afedc85dbe2d07f3e47315652b65cd14
2015-10-28 03:16:55 +00:00
Seigo Nonaka
63635cff58 Add -Werror -Wall -Wextra to compiler option.
- To suppress noisy unused parameter warnings, comment out unused
  arguments.
- Add -Werror for suppressing further warning.
- Add -Wall -Wextra for safety.

Change-Id: I30a0914a4633bd93eb60957cdf378770f04d8428
2015-10-27 21:18:22 +09:00
Roozbeh Pournader
4b723bf22b Basic scaffolding for handling a language list.
The behavior hasn't changed much yet: all languages are ignored for
rendering text, except the very first supported language.

Change-Id: I1695fb985927ae5e28e4f59c1b531e4993af8688
2015-10-22 14:01:50 -07:00
Seigo Nonaka
16da66db74 Merge "Support Variation Selector in font selection." 2015-10-20 03:47:03 +00:00
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
Seigo Nonaka
210dfa01db Remove MinikinFont::GetGlyph interface.
MinikinFont:GetGlyph is no longer used.
No behavior chnages are expected with this CL.

Change-Id: I13398503841ac06f930b04815017d4b33338efa1
2015-10-15 02:54:18 +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