1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.text.cts; 18 19 import static org.junit.Assert.assertTrue; 20 21 import android.content.Context; 22 import android.content.res.Resources; 23 import android.graphics.Bitmap; 24 import android.support.test.InstrumentationRegistry; 25 import android.support.test.annotation.UiThreadTest; 26 import android.support.test.filters.SmallTest; 27 import android.support.test.runner.AndroidJUnit4; 28 import android.text.TextUtils; 29 import android.widget.TextView; 30 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 import java.util.Locale; 35 36 @SmallTest 37 @RunWith(AndroidJUnit4.class) 38 public class MyanmarTest { 39 /** 40 * Tests Unicode composition semantics. 41 */ 42 @UiThreadTest 43 @Test 44 public void testCompositionSemantics() { 45 boolean isMyanmarSupported = false; 46 final String[] localeNames = Resources.getSystem().getStringArray( 47 Resources.getSystem().getIdentifier("supported_locales", "array", "android")); 48 for (String localeName : localeNames) { 49 if (TextUtils.equals("my", Locale.forLanguageTag(localeName).getLanguage())) { 50 isMyanmarSupported = true; 51 break; 52 } 53 } 54 if (!isMyanmarSupported) { 55 // Ignoring since no Myanmar font guarantee if Myanmar is not listed in supported 56 // locales. 57 return; 58 } 59 60 Context context = InstrumentationRegistry.getTargetContext(); 61 String textA = "\u1019\u102d\u102f"; 62 String textB = "\u1019\u102f\u102d"; // wrong order for Unicode 63 64 CaptureTextView cviewA = new CaptureTextView(context); 65 Bitmap bitmapA = cviewA.capture(textA); 66 CaptureTextView cviewB = new CaptureTextView(context); 67 Bitmap bitmapB = cviewB.capture(textB); 68 if (bitmapA.sameAs(bitmapB)) { 69 // if textA and textB render identically, test against replacement characters 70 String textC = "\ufffd\ufffd\ufffd"; // replacement characters are acceptable 71 CaptureTextView cviewC = new CaptureTextView(context); 72 Bitmap bitmapC = cviewC.capture(textC); 73 if (!bitmapA.sameAs(bitmapC)) { 74 // ...or against blank/empty glyphs 75 Bitmap bitmapD = Bitmap.createBitmap(bitmapC.getWidth(), bitmapC.getHeight(), 76 bitmapC.getConfig()); 77 assertTrue(bitmapA.sameAs(bitmapD)); 78 } 79 } 80 } 81 82 private static class CaptureTextView extends TextView { 83 84 CaptureTextView(Context context) { 85 super(context); 86 } 87 88 Bitmap capture(String text) { 89 setText(text); 90 91 invalidate(); 92 93 setDrawingCacheEnabled(true); 94 measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 95 MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 96 layout(0, 0, 200,200); 97 98 Bitmap bitmap = Bitmap.createBitmap(getDrawingCache()); 99 setDrawingCacheEnabled(false); 100 return bitmap; 101 } 102 103 } 104 } 105