133 Commits

Author SHA1 Message Date
Gary Qian
09d3505e3b Switch to using minikin letter spacing.
Change-Id: I0e0908eea3f79bf0a6a5eb9842956d4077bb9dd3
2017-07-21 12:08:17 -07:00
Gary Qian
ba43d1e989 Take letter spacing into account when linebreaking and initial implementation of GetRectsForRange().
Change-Id: Id7fa1b5b60c988cb73ba182241b3d8b3c998e07c
2017-07-10 14:31:11 -07:00
Gary Qian
56e4048b17 Fix Minikin to allow proper compilation in Hyphenator.
Change-Id: I2aeb3d5e494ce941dcc8baec2f0bacd15c163094
2017-06-09 12:27:25 -07:00
Chinmay Garde
79f20a8886 Update libTXT sources and tests from initial prototype.
This separates libTXT tests and Minikin tests and accounts for building
with an older version of ICU. Once ICU has been updated, the workarounds
for emoji handling will be removed.

Change-Id: Ic184e653a2561629b01f98aeb4f6fb88aebbfa88
2017-06-02 14:45:16 -07:00
Adam Barth
cdbb8b0c9d Add Paragraph class from prototype
Change-Id: Id38e4261c4d6f8fa99f405d9b21bdd9e259a9384
2017-05-11 09:25:35 -07:00
Adam Barth
a02c2f97e6 Add SkFontMgr backend for FontCollection
Change-Id: Ic58127bb696f87254633b01706c26c4ae862f9be
2017-05-10 11:52:41 -07:00
Seigo Nonaka
97ee89d605 Reduce heap memory in minikin.
This patch reduces about 73 kB memory.
The original SparseBitSet could contain full 32bit integers, but all of
that is not necessary for Unicode code points. By reducing the supported
range to up to Unicode maximum, U+10FFFF, we can save extra memory.

SparseBitSet holds 256-bit sliced pages and indices of them.
Previously, we needed to hold up to 2^24-1 pages for keeping 32-bit
integers.

This CL limits the number of pages to 2^16-1 (65535), so that
SparseBitSet only supports 24-bit integers now, but this is sufficient
for keeping all Unicode code points. With this change, we can change the
index integer type from uint32_t to uint16_t.

Bug: 37357593
Test: minikin_tests passes
Change-Id: I462cc27927752c942ac5da0bf303a5afb81b87a3
2017-04-14 22:54:27 +00:00
Seigo Nonaka
cc8f7117d3 Support cmap tables with platform ID == 0
Some fonts don't have cmap subtables of Microsoft Platform ID (3) and
only have cmap subtables of Unicode Platform ID (0).

Bug: 32505843
Test: minikin_unittest passed
Test: android.graphics.cts.TypefaceTest passed
Change-Id: I24aa49860790c0ae8d8e578efd728b95ec0f93ae
2017-04-03 14:57:19 -07:00
Roozbeh Pournader
d01462f7a1 Override the bidi properties of new emojis
Test: new Minikin tests are added, and pass
Bug: 32952475
Change-Id: Ibcae60d18d0cd5efd7556aaf58a716b6b59c8ee0
2017-04-02 15:30:21 -07:00
Roozbeh Pournader
7708c89648 Remove unused classes and methods
Removed Bitmap and MinikinFontFreeType classes, as well
as the Layout::draw() method.

The code was there for debugging purposes and for potential
third-party users. We no longer support third-party uses of
Minikin, since we don't know of any.

Test: mmma -j frameworks/minikin builds with no errors
Change-Id: Iddc9e8d35334053bd5255bccf3dbe5ba1eecf814
2017-03-30 17:52:56 -07:00
Seigo Nonaka
6a5534a437 Remove unused functions.
This CL is essentially reverting following changes:
- "Serialize and deserialize supported axes."
  I4086fb887e13f872390b533584bce6f1d5598ea0
- "Make SparseBitSet serializable."
  I0463138adcf234739bb3ce1cdadf382021921f3e

Bug: 36232655
Test: N/A
Change-Id: I25c701e1805e92b01034142147a9925f86533819
2017-03-22 16:00:35 -07:00
TreeHugger Robot
ad55a59727 Merge "Expose supportedAxes to frameworks/base" 2017-03-20 17:37:07 +00:00
TreeHugger Robot
61bb3fbc81 Merge "Refactor WordBreaker" 2017-03-16 21:20:15 +00:00
Roozbeh Pournader
f3399b503e Refactor WordBreaker
Refactor WordBreaker to make it ready for more complex behavior.

Test: existing unit tests continue to pass
Change-Id: Ife758f3e2cf48922ab56109e6c5d3cffa3673feb
2017-03-16 12:23:08 -07:00
TreeHugger Robot
4b613e361b Merge "Serialize and deserialize supported axes." 2017-03-15 23:30:30 +00:00
TreeHugger Robot
c044fd4ed7 Merge "In greedy line breaking, repeat breaks until the line fits" 2017-03-15 22:29:13 +00:00
Seigo Nonaka
ca8ac8a924 Serialize and deserialize supported axes.
To avoid reading font files during FontFamily construction, serialize
and deserialize supported axes and cmap coverage at the same time.

Bug: 36232655
Test: ran minikin_tests
Change-Id: I4086fb887e13f872390b533584bce6f1d5598ea0
2017-03-15 14:18:13 -07:00
Roozbeh Pournader
d2aaf3394a In greedy line breaking, repeat breaks until the line fits
Previously, in greedy line breaking, when a line overflowed, we found
the best line breaking candidate before it and broke the line there.
But we didn't check to see if the remaining part now fits in a line.

With this change, we now repeat checking for overflows, and break
again until we have no breaking opportunity or the remaining text now
fits in a line.

Also found an issue with greedy line breaking and keeping the
hyphenation edit for the next line which is now fixed.

Test: Manual. The issue reported in the bug is now fixed.
Bug: 34185255
Bug: https://code.google.com/p/android/issues/detail?id=231437
Bug: 33560754
Change-Id: I93bdd341e4f8e1257710e453e4938f224cb2a1ff
2017-03-15 13:52:21 -07:00
TreeHugger Robot
fde7453c82 Merge "Break grapheme clusters after viramas if they end a cluster" 2017-03-15 19:53:12 +00:00
Seigo Nonaka
3165aebe3b Do not keep FontCollection reference in Layout.
LayoutCache only keeps result of layout and can live after
FontCollection is destructed by GC.

This kind of failure will be captured by minikin_stress_tests in the
subsequent CL (I1bf4ba43e6e97cd04e7d6dd42d388dd17ce64c7b)

Test: ran minikin_tests
Bug: 36223724
Change-Id: I639b73c0f1041549158c43212a901c82df4b02db
2017-03-15 15:17:43 +00:00
Seigo Nonaka
8d9c9d7f20 Expose supportedAxes to frameworks/base
The list of supportedAxes are necessary for returning value of
setFontVariationSettings.

Bug: 35764323
Test: ran TextViewTest and PaintTest in cts
Change-Id: I52f244146ea0ce335df02c841f89285be2ed746e
2017-03-15 14:32:08 +00:00
Roozbeh Pournader
f4c0bd2e1b Break grapheme clusters after viramas if they end a cluster
Previously, we stayed on the conservative side and disallowed any
grapheme breaks (and thus cursoring) where a virama was followed by a
letter, since we did not know if the virama would be forming a
cluster with the letter or not. This created problems with Indic
languages with infrequent conjuncts, such as Tamil.

Now we use the information in calculated advances to find if a
cluster is formed. If there is no cluster, we break the grapheme and
allow cursoring after the virama.

Test: Unit tests added to GraphemeBreakTests and MeasurementTests.
Test: Also manually tested Tamil sequences.
Bug: 35721792
Change-Id: Ib159edb94b3ad6f693f0d3dad016b332b2cef447
2017-03-14 21:41:49 -07:00
Seigo Nonaka
44914ce013 Revert "Use std::mutex instead of android::Mutex"
This reverts commit 0eac702718a070e8ee226e63b5f540510b425e9a.

Bug: 36208043
Test: N/A

Change-Id: I165ab7a0718ea50a8034adb6277809e271fd762c
2017-03-14 10:48:42 -07:00
TreeHugger Robot
aed4ec33ad Merge "Make SparseBitSet serializable." 2017-03-13 23:07:04 +00:00
Seigo Nonaka
ff9a6740ed Make SparseBitSet serializable.
To share the calculated coverage information across the processes, make
SparseBitSet serializable.

Bug: 34042446
Test: minikin_tests passes
Change-Id: I0463138adcf234739bb3ce1cdadf382021921f3e
2017-03-13 14:07:55 -07:00
Seigo Nonaka
0eac702718 Use std::mutex instead of android::Mutex
This CL includes:
- Stop using utils/Mutex and use std::mutex instead.
- Stop using utils/Singleton.

Test: minikin_tests passed
Change-Id: Ib3f75b83397a546472bb5f91e066e44506e78263
2017-03-13 14:03:05 -07:00
Seigo Nonaka
684ac0b636 Reduce memory usage of FontCollection.
This is 2nd attempt at I9e01d237c9adcb05e200932401cb1a4780049f86.

The previous CL was reverted because 8-bit integers were too small to
store the indices of mFamilyVec. This CL changes it to 16-bit integers
since size_t is still unnecessary large.

Theoretically, 32-bit integers are necessary for the indices of
mFamilyVec since the size of mFamilyVec can be 0x10EE01. However, in
practice, 16-bit integers are enough for the indices of mFamilyVec.
The length of mFamilyVec for the system fonts is 2084. Even if the
developers load their own very large fonts, it can only increase the
number of elements in mFamilyVec to at most 0x10FF.

As the result, memory usage of the FontCollections for the system fonts
decreases as follows.
64-bit process: before: 398,264 bytes, after: 282,568 bytes (-115,696 bytes)
32-bit process: before: 199,132 bytes, after: 149,548 bytes (-49,584 bytes)

Bug: 33562608
Test: Verified Emoji and CJK characters are present.
Test: android.text.cts.EmojiTest passed
Test: Minikin unit tests passed
Change-Id: I6796fd55ac30fe30528a212ebf6097b1d672e2f8
2017-03-13 06:35:53 -07:00
Roozbeh Pournader
068c7ba2ea Customizable min suffix/prefix length for hyphenation in Minikin
With this change, different languages can have a different minimum
length for suffix and prefixes when hyphenating. Previously, the
defaults used for English, 2 and 3, were used for every language.

Bug: 35712376
Test: Minikin unit tests were updated and the pass
Change-Id: Iffaf11c6b208c57d28d45b17246e177572dc1210
2017-03-06 16:12:53 -08:00
Roozbeh Pournader
319073941e Correct hyphenation for various complex cases
This adds better support for Arabic script languages, Armenian,
Catalan, Hebrew, Kannada, Malayalam, Polish, Tamil, and Telugu by
adding various hyphenation types and edits appropriate for the
locales.

For Arabic script languages, soft hyphens act transparently with
regard to joining: If a line is broken at a soft hyphen where the two
characters around the soft hyphen were joining each other before,
they will continue to appear joining if the line is broken at the
soft hyphen and a hyphen glyph is inserted.  This is needed for
Central Asian languages such as Uighur.

For Armenian, U+058A ARMENIAN HYPHEN is used for line breaks caused
by either automatic hyphenation or soft hyphens.

For Catalan, nonstandard line breaks are implemented for "l·l", which
hyphenates as "l-/l".

For Polish, when there is a line break at a hyphen, the hyphen is
repeated at the next line.

For the South Indic languages, when breaks happen due to soft breaks
or automatic hyphenation, no visible hyphen is inserted, although a
penalty is added.

For Hebrew, support for using U+05BE HEBREW PUNCTUATION MAQAF has
been implemented, but it's turned off pending confirmation of
desirability.

Also, hard hyphens, which previously had no penalty added for
breaking the line after them, now have the same penalty as an
automatic or soft break, with the difference that no hyphen is
inserted when they break.

Finally, some bugs have been fixed with hyphenating multiscript and
multi-font words.

Bug: 19950445
Bug: 19955011
Bug: 25623243
Bug: 26154469
Bug: 26154471
Bug: 33387871
Bug: 33560754
Bug: 33752592
Bug: 33754204
Test: Unit tests added, plus thorough manual testing
Change-Id: Iaccf776ce8d1d434ee8b1c534ff3659d80fdc338
2017-03-02 15:26:13 -08:00
Seigo Nonaka
a619860872 Remove MinikinRefCounted and use shared_ptr instead
Let's use shared_ptr since manual ref counting can be a bug-prone and
using the global mutex inside destructor is not useful for some time.

To remove raw pointer manipulation, needed to change Layout
constructors. Layout is no longer copyable and need to pass
FontCollection to constructor.

Bug: 28119474
Test: minikin_tests passed
Test: hwui_unit_tests passed
Test: No performance regression in minikin_perftest.
Change-Id: I8824593206ecba74cbc9731e298f045e1ae442a3
2017-02-24 17:11:32 +09:00
Seigo Nonaka
3fcf3634db Call hb_font_set_variation if font variations are provided.
Test: None
Change-Id: I203d9ba7e1a1fcfdb10cd6a711d9a35136cbddd6
2017-02-22 10:56:04 +09:00
Seigo Nonaka
77a29ed5ec Introduce createCollectionWithVariation.
This is 2nd attempt of I08e9b74192f8af1d045f1276498fa4e60d73863e.
The original CL was reverted due to conflicting with another CL submitted
before.

Here is the original commit message of reverted change.

This lays the groundwork for variation settings support.
Since we should regard different variations of a font as different fonts, we
need to create new typefaces. To reuse the same instance of MinikinFont, as
much as possible, FontFamily::createFamilyWithVariation now reuses an
existence instance, while incrementing the reference count.

Test: minikin_tests
Bug: 33062398
Change-Id: Ib25bf1bb5a5191e15a6523954146521464c91906
2017-01-31 13:19:56 +09:00
Seigo Nonaka
0afb39eaed Remove FontFamily.addFont and make FontFamily immutable.
This is 2nd attempt of 0470cdb3e41f0ae603f6a3e89efabdc196424652
The difference is adding clearElementsEithLock to Font class which
is necessary to delete Fonts object outside of minikin. This method
should be removed once http://b/28119474 is fixed.

Here is original commit message of reverted change.

This lays the groundwork for making SparseBitSet serializable.
FontFamily.addFont is only used when the FontFamily is constructed.
Thus, instead of calling FontFamily.addFont multiple time, passes
Font list to the constructor. By this change, FontFamily can be
immutable now.

By making FontFamily immutable, We can create FontFamily with
pre-calculated SparseBitSet.

Bug: 34042446
Bug: 28119474
Bug: 34378805
Test: minikin_tests has passed
Change-Id: Ice433931196f5ae79a1a7ee0c98020f914aeb5f2
2017-01-20 17:59:42 +09:00
Siyamed Sinir
92c0eb1f83 Revert "Remove FontFamily.addFont and make FontFamily immutable."
This reverts commit 0470cdb3e41f0ae603f6a3e89efabdc196424652.

Bug: 34378805
Change-Id: I8f1ee00b365c8b17c6140e9e286fbea082e31364
2017-01-20 02:01:21 +00:00
Siyamed Sinir
8a4ee2d1b4 Merge "Revert "Introduce createCollectionWithVariation."" 2017-01-20 01:59:54 +00:00
Siyamed Sinir
df0cbf3bc0 Revert "Introduce createCollectionWithVariation."
This reverts commit ed8318e4e860e7e542fa5143c399c3d1328bc25e.

Bug: 34378805
Change-Id: I22b683f774813724f220b1b8584ab188f3cf4fa7
2017-01-20 01:13:24 +00:00
Siyamed Sinir
10bf33801b Merge "Revert "Reduce memory usage of FontCollection."" 2017-01-12 20:19:57 +00:00
Siyamed Sinir
defcd9d9c2 Revert "Reduce memory usage of FontCollection."
This reverts commit 41ef8b376f4616ba13e13096f7c03a4caa0c695a.

Test: Manually tested
Bug: 34247671
Change-Id: I0510009b2deac784770f26059681b1980800abc8
2017-01-12 20:13:11 +00:00
Seigo Nonaka
ed8318e4e8 Introduce createCollectionWithVariation.
This lays the groundwork for variation settings support.
Since we should regard different variations of a font as different fonts, we
need to create new typefaces. To reuse the same instance of MinikinFont, as
much as possible, FontFamily::createFamilyWithVariation now reuses an
existence instance, while incrementing the reference count.

Test: minikin_tests
Bug: 33062398
Change-Id: I08e9b74192f8af1d045f1276498fa4e60d73863e
2017-01-12 18:26:46 +09:00
TreeHugger Robot
d2cca3e411 Merge "Remove FontFamily.addFont and make FontFamily immutable." 2017-01-12 07:43:53 +00:00
Seigo Nonaka
2d7e0faa4f Merge "Reduce memory usage of FontCollection." 2017-01-12 06:02:58 +00:00
Seigo Nonaka
0470cdb3e4 Remove FontFamily.addFont and make FontFamily immutable.
This lays the groundwork for making SparseBitSet serializable.
FontFamily.addFont is only used when the FontFamily is constructed.
Thus, instead of calling FontFamily.addFont multiple time, passes
Font list to the constructor. By this change, FontFamily can be
immutable now.

By making FontFamily immutable, We can create FontFamily with
pre-calculated SparseBitSet.

Bug: 34042446
Test: minikin_tests has passed
Change-Id: I2576789fba6cb27687e920e2488e8bedbcf7d36f
2017-01-12 13:27:00 +09:00
Seigo Nonaka
41ef8b376f Reduce memory usage of FontCollection.
Since switching to 64-bit devices, size_t is now a 64-bit integer.
FontCollection::Range uses two size_t integers but they just point to an index
in mFamilies. To reduce the memory usage, this CL changes the size_t integers to
uint8_t.

The maximum size of each integer in Range is the size of FontCollection::mFamilies.
The largest this can go is the system font list plus a user defined family, which
has 91 families. So an 8-bit integer should be enough.

With this change, about 84 KiB of memory will be saved per font collection. Since
eight font collections are created during bootstrap, about 670 KiB of memory will
be saved with this CL.

Bug: 33562608
Test: Ran FontCollection.collectionAllocationSizeTest on a 64-bit device.
      On my Nexus 5X, it changed from 327358 to 241342.

Change-Id: I9e01d237c9adcb05e200932401cb1a4780049f86
2017-01-06 17:27:14 +09:00
Seigo Nonaka
311d94f416 Tune line breaking for justification
Add an "mJustified" for justification, and tune the line breaking to
produce good results. Major differences for fully justified text include:
- Space can be shrunk in justified text.
- Hyphenation should be more aggressive in justified text.

Also adds a penalty for the last line being very short. This is tuned
to be more aggressive for ragged right than for justified text.

This is based on a patch by Raph Levien (raph@google.com).

Bug: 31707212
Test: Manually tested with Icbfab2faa11a6a0b52e6f0a77a9c9b5ef6e191da
Change-Id: If366f82800831ccc247ec07b7bc28ca4c6ae0ed6
2017-01-02 22:51:40 +09:00
Seigo Nonaka
964f053ea4 Clean Up: Removing unused interface GetTable from MinikinFont.
This is 2nd attempt of Ifcd7a348d7fb5af081192899dbcdfc7fb4eebbf9

After Id766ab16a8d342bf7322a90e076e801271d527d4, GetTable is no longer
used in production due to poor performance and it is now only used in
tests. This CL removes GetTable interface from MinikinFont and update
tests code to use new interfaces, GetFontData, GetFontSize and
GetFontIndex.

Bug: 27860101
Test: Manually done
Change-Id: Ib48973ff25cdc61a4c666d28128266df0aaea83e
2016-11-17 17:36:51 +09:00
Seigo Nonaka
6b9c9dec1f Implement word spacing
Add a wordSpacing paint parameter, which will be used for
justification.

Bug: 31707212
Test: ran minikin_tests
Change-Id: I91224ab8ef882ac0c87425c28ab731fead283612
2016-11-16 17:36:26 +09:00
Seigo Nonaka
dc8de001df Revert "Clean Up: Removing unused interface GetTable from MinikinFont."
This reverts commit 7b02f5e95c4386c250f6f83db1ff61b69177140e.

This causes a crash on Android Auto.

Bug: 32374752
Change-Id: Ia2ff77bf9a12351c6949f79ef6fa2d8016e3022d
2016-10-25 00:49:52 +00:00
Seigo Nonaka
7b02f5e95c Clean Up: Removing unused interface GetTable from MinikinFont.
After Id766ab16a8d342bf7322a90e076e801271d527d4, GetTable is no longer
used in production due to poor performance and it is now only used in
tests. This CL removes GetTable interface from MinikinFont and update
tests code to use new interfaces, GetFontData, GetFontSize and
GetFontIndex.

Bug: 27860101
Test: Manually done

Change-Id: Ifcd7a348d7fb5af081192899dbcdfc7fb4eebbf9
2016-10-18 08:16:18 +00:00
Elliott Hughes
88ca7498cc Switch minikin to std::unique_ptr. am: fba88d3b3c am: c5e0585ac7 am: 83bdd0ae73
am: b150a633ba

Change-Id: I56cce90607bce82d337d4da3b4ac5f167c7cc1b4
2016-09-13 01:50:14 +00:00
Elliott Hughes
fba88d3b3c Switch minikin to std::unique_ptr.
Bug: http://b/22403888
Change-Id: I9e18496fcc38ad2e6b922455daa9f2a46778ec55
2016-09-12 15:29:35 -07:00