From 1250aa860e3ee9dbb086dd4bdd60ccca4a53c9bb Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 23 Feb 2018 17:20:43 -0800 Subject: [PATCH] Put line feed to the test case ascent10em-descent10em.ttf covers U+000A but must not be included as the line spaceing. Bug: 73625594 Test: bit FrameworksCoreTests:android.text. Test: atest CtsWidgetTestCases:EditTextTest CtsWidgetTestCases:TextViewFadingEdgeTest FrameworksCoreTests:TextViewFallbackLineSpacingTest FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest CtsTextTestCases Change-Id: I5cccd596d660c1f3ee34b0b81a44a7e4b64f3d01 --- .../assets/fonts/ascent10em-descent10em.ttf | Bin 0 -> 1776 bytes .../assets/fonts/ascent10em-descent10em.ttx | 181 ++++++++++++++++++ .../src/android/text/StaticLayoutTest.java | 41 +++- 3 files changed, 218 insertions(+), 4 deletions(-) create mode 100644 core/tests/coretests/assets/fonts/ascent10em-descent10em.ttf create mode 100644 core/tests/coretests/assets/fonts/ascent10em-descent10em.ttx diff --git a/core/tests/coretests/assets/fonts/ascent10em-descent10em.ttf b/core/tests/coretests/assets/fonts/ascent10em-descent10em.ttf new file mode 100644 index 0000000000000000000000000000000000000000..47ab623b43e8b2083035ee568a1dca527a1b7ffc GIT binary patch literal 1776 zcmai#zi(4l6vw~Mb`n4hg$35D2#Hhz(?$po?Lf*8ktT|({2;VL%ZuaK5BV3iQzuMF zEQpD}16AtOszbYVVCcYrs;KJNp<|Ii9o^5l_r1n8RJ^Bm&+l`;_ndQWMUsx_f%0;t z)pK*Tsp^6h&7!?iZp3ZPXbJfV^7(3gZyU-J{c3Bi5^o*(c|Q;PE#HM2iqpsc_#OUF zzEibEZ#VxJoT5i8ll4|PHVOF`mdQrE+h$*r53#sr+^E#|AAT0{PZZj%Zg23T=5T#( zb{ST_C*Q42fBpU^uaytkU%b3x@%rtDjgv;xXG*!0Bj)t6{lBH)kJd5`KatmD{==4x z&*xUC!h{ax9_MbOTnse&N^{W}bDGFJ$Fi?4ZY=8xHJ;A9!6iKd!!ukxg6LK5CwMo6 z%q)4lrT0|OEOZhYaTYQR2FRWc{u#UqInW$DQ~HwVsBjq77GK~aoj?kFPDgb=8e_4Yfl{|s;Z_Qm}k*`0G-o^`bZby*05Bd^J=nRhnNKF zR3f&5&S@3h4wka_``r87g)ftFRk0d)*1hcpo=vnXNL6C$SUV#=na9~NpCxv+{7rRP zZT}sQr$W3VV}`L!#&Rl+#+NBp!#IvdB5@)L90*8N)lxP>ql2jvIRS{COSc zim9FhM~iqvWY_|l1m0dSG3!v&Gs>QCa=_?9}pAjOmF*g}5GChrc21qc>D0Rb`dz zV%)E>?@$1Whl^`L>>op3Zi(%Kcvkn;++^<@gnwXLg(xSZAQ0dfB8= zG#hxV=_V7q4t3hVZ-sYW%g775?z5E8IHtdZ_L`4a@VxC%(hXMg{{p&*)qJcD74U}H zu{pFZw|zZAH$q*L|GI3I9q->NQQ6cO9k0iB+MR4dyX;_hEAi7+Cc?UCec6FleXc4o z-@tXyhn_hf)d7jsH@g8=X^Y(&tC-D+dG@ec*RAU2`|kb~ncN<4TbFf?x9{H~c@A!7 n(VwV_HOymntGj5HsO?ocvP@5|>uh>M{r`zH_}>0E-hBQAq&E=O literal 0 HcmV?d00001 diff --git a/core/tests/coretests/assets/fonts/ascent10em-descent10em.ttx b/core/tests/coretests/assets/fonts/ascent10em-descent10em.ttx new file mode 100644 index 0000000000000..55402770746e4 --- /dev/null +++ b/core/tests/coretests/assets/fonts/ascent10em-descent10em.ttx @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Copyright (C) 2017 The Android Open Source Project + + + Sample Font + + + Regular + + + Sample Font + + + SampleFont-Regular + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + http://www.apache.org/licenses/LICENSE-2.0 + + + + + + + + + + + + + + + + diff --git a/core/tests/coretests/src/android/text/StaticLayoutTest.java b/core/tests/coretests/src/android/text/StaticLayoutTest.java index d817278330d4d..25217125bbf4d 100644 --- a/core/tests/coretests/src/android/text/StaticLayoutTest.java +++ b/core/tests/coretests/src/android/text/StaticLayoutTest.java @@ -822,6 +822,9 @@ public class StaticLayoutTest { + " " + " ascent3em-descent4em.ttf" + " " + + " " + + " ascent10em-descent10em.ttf" + + " " + ""; try (FontFallbackSetup setup = @@ -833,7 +836,7 @@ public class StaticLayoutTest { assertEquals(2 * textSize, paint.descent(), 0.0f); final int paraWidth = 5 * textSize; - final String text = "aaaaa aabaa aaaaa"; // This should result in three lines. + final String text = "aaaaa\naabaa\naaaaa\n"; // This should result in three lines. // Old line spacing. All lines should get their ascent and descents from the first font. StaticLayout layout = StaticLayout.Builder @@ -841,13 +844,17 @@ public class StaticLayoutTest { .setIncludePad(false) .setUseLineSpacingFromFallbacks(false) .build(); - assertEquals(3, layout.getLineCount()); + assertEquals(4, layout.getLineCount()); assertEquals(-textSize, layout.getLineAscent(0)); assertEquals(2 * textSize, layout.getLineDescent(0)); assertEquals(-textSize, layout.getLineAscent(1)); assertEquals(2 * textSize, layout.getLineDescent(1)); assertEquals(-textSize, layout.getLineAscent(2)); assertEquals(2 * textSize, layout.getLineDescent(2)); + // The last empty line spacing should be the default line spacing. + // Maybe good to be a previous line spacing? + assertEquals(-textSize, layout.getLineAscent(3)); + assertEquals(2 * textSize, layout.getLineDescent(3)); // New line spacing. The second line has a 'b', so it needs more ascent and descent. layout = StaticLayout.Builder @@ -855,26 +862,52 @@ public class StaticLayoutTest { .setIncludePad(false) .setUseLineSpacingFromFallbacks(true) .build(); - assertEquals(3, layout.getLineCount()); + assertEquals(4, layout.getLineCount()); assertEquals(-textSize, layout.getLineAscent(0)); assertEquals(2 * textSize, layout.getLineDescent(0)); assertEquals(-3 * textSize, layout.getLineAscent(1)); assertEquals(4 * textSize, layout.getLineDescent(1)); assertEquals(-textSize, layout.getLineAscent(2)); assertEquals(2 * textSize, layout.getLineDescent(2)); + assertEquals(-textSize, layout.getLineAscent(3)); + assertEquals(2 * textSize, layout.getLineDescent(3)); // The default is the old line spacing, for backward compatibility. layout = StaticLayout.Builder .obtain(text, 0, text.length(), paint, paraWidth) .setIncludePad(false) .build(); - assertEquals(3, layout.getLineCount()); + assertEquals(4, layout.getLineCount()); assertEquals(-textSize, layout.getLineAscent(0)); assertEquals(2 * textSize, layout.getLineDescent(0)); assertEquals(-textSize, layout.getLineAscent(1)); assertEquals(2 * textSize, layout.getLineDescent(1)); assertEquals(-textSize, layout.getLineAscent(2)); assertEquals(2 * textSize, layout.getLineDescent(2)); + assertEquals(-textSize, layout.getLineAscent(3)); + assertEquals(2 * textSize, layout.getLineDescent(3)); + + layout = StaticLayout.Builder + .obtain("\n", 0, 1, paint, textSize) + .setIncludePad(false) + .setUseLineSpacingFromFallbacks(false) + .build(); + assertEquals(2, layout.getLineCount()); + assertEquals(-textSize, layout.getLineAscent(0)); + assertEquals(2 * textSize, layout.getLineDescent(0)); + assertEquals(-textSize, layout.getLineAscent(1)); + assertEquals(2 * textSize, layout.getLineDescent(1)); + + layout = StaticLayout.Builder + .obtain("\n", 0, 1, paint, textSize) + .setIncludePad(false) + .setUseLineSpacingFromFallbacks(true) + .build(); + assertEquals(2, layout.getLineCount()); + assertEquals(-textSize, layout.getLineAscent(0)); + assertEquals(2 * textSize, layout.getLineDescent(0)); + assertEquals(-textSize, layout.getLineAscent(1)); + assertEquals(2 * textSize, layout.getLineDescent(1)); } }