diff options
| author | 2017-04-05 10:04:45 +0000 | |
|---|---|---|
| committer | 2017-04-05 10:04:52 +0000 | |
| commit | b4e3b344faa6c18b6dc0c6f1dfd989bd6d30e587 (patch) | |
| tree | 2c619ee45d30a7cc5109ae44f6bbf426a3fbd5bc | |
| parent | 24bac614986e0fe8892c5ef36e4b6e516fd01d0b (diff) | |
| parent | fe04aa840e0682e9813e1ac4958772f898eb02ca (diff) | |
Merge "Pass weight/italic pair instead of style." into oc-dev
| -rw-r--r-- | api/current.txt | 3 | ||||
| -rw-r--r-- | api/removed.txt | 4 | ||||
| -rw-r--r-- | api/system-current.txt | 3 | ||||
| -rw-r--r-- | api/system-removed.txt | 4 | ||||
| -rw-r--r-- | api/test-current.txt | 3 | ||||
| -rw-r--r-- | api/test-removed.txt | 4 | ||||
| -rw-r--r-- | core/java/android/provider/FontsContract.java | 46 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/provider/FontsContractTest.java | 33 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/provider/TestFontsProvider.java | 8 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Typeface.java | 8 | ||||
| -rw-r--r-- | graphics/java/android/graphics/fonts/FontResult.java | 27 |
11 files changed, 98 insertions, 45 deletions
diff --git a/api/current.txt b/api/current.txt index e640e30cae33..3c90844a987f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -34520,14 +34520,15 @@ package android.provider { public static final class FontsContract.Columns implements android.provider.BaseColumns { ctor public FontsContract.Columns(); + field public static final java.lang.String ITALIC = "font_italic"; field public static final java.lang.String RESULT_CODE = "result_code"; field public static final int RESULT_CODE_FONT_NOT_FOUND = 1; // 0x1 field public static final int RESULT_CODE_FONT_UNAVAILABLE = 2; // 0x2 field public static final int RESULT_CODE_MALFORMED_QUERY = 3; // 0x3 field public static final int RESULT_CODE_OK = 0; // 0x0 - field public static final java.lang.String STYLE = "font_style"; field public static final java.lang.String TTC_INDEX = "font_ttc_index"; field public static final java.lang.String VARIATION_SETTINGS = "font_variation_settings"; + field public static final java.lang.String WEIGHT = "font_weight"; } public final deprecated class LiveFolders implements android.provider.BaseColumns { diff --git a/api/removed.txt b/api/removed.txt index 42b2ae61e5cf..d20c08cf7a8f 100644 --- a/api/removed.txt +++ b/api/removed.txt @@ -296,6 +296,10 @@ package android.provider { field public static final deprecated java.lang.String TIMESTAMP = "timestamp"; } + public static final class FontsContract.Columns implements android.provider.BaseColumns { + field public static final java.lang.String STYLE = "font_style"; + } + public static final class Settings.Global extends android.provider.Settings.NameValueTable { field public static final deprecated java.lang.String CONTACT_METADATA_SYNC = "contact_metadata_sync"; } diff --git a/api/system-current.txt b/api/system-current.txt index fa2a69ece6f7..6a14b1594ba7 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -37460,14 +37460,15 @@ package android.provider { public static final class FontsContract.Columns implements android.provider.BaseColumns { ctor public FontsContract.Columns(); + field public static final java.lang.String ITALIC = "font_italic"; field public static final java.lang.String RESULT_CODE = "result_code"; field public static final int RESULT_CODE_FONT_NOT_FOUND = 1; // 0x1 field public static final int RESULT_CODE_FONT_UNAVAILABLE = 2; // 0x2 field public static final int RESULT_CODE_MALFORMED_QUERY = 3; // 0x3 field public static final int RESULT_CODE_OK = 0; // 0x0 - field public static final java.lang.String STYLE = "font_style"; field public static final java.lang.String TTC_INDEX = "font_ttc_index"; field public static final java.lang.String VARIATION_SETTINGS = "font_variation_settings"; + field public static final java.lang.String WEIGHT = "font_weight"; } public final deprecated class LiveFolders implements android.provider.BaseColumns { diff --git a/api/system-removed.txt b/api/system-removed.txt index 1bafe96c1e6e..1effe9cead69 100644 --- a/api/system-removed.txt +++ b/api/system-removed.txt @@ -290,6 +290,10 @@ package android.provider { field public static final deprecated java.lang.String TIMESTAMP = "timestamp"; } + public static final class FontsContract.Columns implements android.provider.BaseColumns { + field public static final java.lang.String STYLE = "font_style"; + } + public static final class Settings.Global extends android.provider.Settings.NameValueTable { field public static final deprecated java.lang.String CONTACT_METADATA_SYNC = "contact_metadata_sync"; } diff --git a/api/test-current.txt b/api/test-current.txt index 795342fdc763..c5dc584634a0 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -34660,14 +34660,15 @@ package android.provider { public static final class FontsContract.Columns implements android.provider.BaseColumns { ctor public FontsContract.Columns(); + field public static final java.lang.String ITALIC = "font_italic"; field public static final java.lang.String RESULT_CODE = "result_code"; field public static final int RESULT_CODE_FONT_NOT_FOUND = 1; // 0x1 field public static final int RESULT_CODE_FONT_UNAVAILABLE = 2; // 0x2 field public static final int RESULT_CODE_MALFORMED_QUERY = 3; // 0x3 field public static final int RESULT_CODE_OK = 0; // 0x0 - field public static final java.lang.String STYLE = "font_style"; field public static final java.lang.String TTC_INDEX = "font_ttc_index"; field public static final java.lang.String VARIATION_SETTINGS = "font_variation_settings"; + field public static final java.lang.String WEIGHT = "font_weight"; } public final deprecated class LiveFolders implements android.provider.BaseColumns { diff --git a/api/test-removed.txt b/api/test-removed.txt index 42b2ae61e5cf..d20c08cf7a8f 100644 --- a/api/test-removed.txt +++ b/api/test-removed.txt @@ -296,6 +296,10 @@ package android.provider { field public static final deprecated java.lang.String TIMESTAMP = "timestamp"; } + public static final class FontsContract.Columns implements android.provider.BaseColumns { + field public static final java.lang.String STYLE = "font_style"; + } + public static final class Settings.Global extends android.provider.Settings.NameValueTable { field public static final deprecated java.lang.String CONTACT_METADATA_SYNC = "contact_metadata_sync"; } diff --git a/core/java/android/provider/FontsContract.java b/core/java/android/provider/FontsContract.java index fd9d4db9842e..4deb4ab69059 100644 --- a/core/java/android/provider/FontsContract.java +++ b/core/java/android/provider/FontsContract.java @@ -72,15 +72,28 @@ public class FontsContract { */ public static final String VARIATION_SETTINGS = "font_variation_settings"; /** - * Constant used to request data from a font provider. The cursor returned from the query - * should have this column populated with the int style for the resulting font. This should - * be one of {@link android.graphics.Typeface#NORMAL}, - * {@link android.graphics.Typeface#BOLD}, {@link android.graphics.Typeface#ITALIC} or - * {@link android.graphics.Typeface#BOLD_ITALIC} + * DO NOT USE THIS COLUMN. + * This column is kept for preventing demo apps. + * TODO: Remove once nobody uses this column. + * @hide + * @removed */ public static final String STYLE = "font_style"; /** * Constant used to request data from a font provider. The cursor returned from the query + * should have this column populated with the int weight for the resulting font. This value + * should be between 100 and 900. The most common values are 400 for regular weight and 700 + * for bold weight. + */ + public static final String WEIGHT = "font_weight"; + /** + * Constant used to request data from a font provider. The cursor returned from the query + * should have this column populated with the int italic for the resulting font. This should + * be 0 for regular style and 1 for italic. + */ + public static final String ITALIC = "font_italic"; + /** + * Constant used to request data from a font provider. The cursor returned from the query * should have this column populated to indicate the result status of the * query. This will be checked before any other data in the cursor. Possible values are * {@link #RESULT_CODE_OK}, {@link #RESULT_CODE_FONT_NOT_FOUND}, @@ -274,7 +287,7 @@ public class FontsContract { .build(); try (Cursor cursor = mContext.getContentResolver().query(uri, new String[] { Columns._ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.STYLE, - Columns.RESULT_CODE }, + Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null);) { // TODO: Should we restrict the amount of fonts that can be returned? // TODO: Write documentation explaining that all results should be from the same family. @@ -285,6 +298,8 @@ public class FontsContract { final int idColumnIndex = cursor.getColumnIndexOrThrow(Columns._ID); final int ttcIndexColumnIndex = cursor.getColumnIndex(Columns.TTC_INDEX); final int vsColumnIndex = cursor.getColumnIndex(Columns.VARIATION_SETTINGS); + final int weightColumnIndex = cursor.getColumnIndex(Columns.WEIGHT); + final int italicColumnIndex = cursor.getColumnIndex(Columns.ITALIC); final int styleColumnIndex = cursor.getColumnIndex(Columns.STYLE); while (cursor.moveToNext()) { resultCode = resultCodeColumnIndex != -1 @@ -313,9 +328,22 @@ public class FontsContract { ? cursor.getInt(ttcIndexColumnIndex) : 0; final String variationSettings = vsColumnIndex != -1 ? cursor.getString(vsColumnIndex) : null; - final int style = styleColumnIndex != -1 - ? cursor.getInt(styleColumnIndex) : Typeface.NORMAL; - result.add(new FontResult(pfd, ttcIndex, variationSettings, style)); + // TODO: Stop using STYLE column and enforce WEIGHT/ITALIC column. + int weight; + boolean italic; + if (weightColumnIndex != -1 && italicColumnIndex != -1) { + weight = cursor.getInt(weightColumnIndex); + italic = cursor.getInt(italicColumnIndex) == 1; + } else if (styleColumnIndex != -1) { + final int style = cursor.getInt(styleColumnIndex); + weight = (style & Typeface.BOLD) != 0 ? 700 : 400; + italic = (style & Typeface.ITALIC) != 0; + } else { + weight = 400; + italic = false; + } + result.add( + new FontResult(pfd, ttcIndex, variationSettings, weight, italic)); } catch (FileNotFoundException e) { Log.e(TAG, "FileNotFoundException raised when interacting with content " + "provider " + authority, e); diff --git a/core/tests/coretests/src/android/provider/FontsContractTest.java b/core/tests/coretests/src/android/provider/FontsContractTest.java index 6820e92866a2..1dd3ef6f012e 100644 --- a/core/tests/coretests/src/android/provider/FontsContractTest.java +++ b/core/tests/coretests/src/android/provider/FontsContractTest.java @@ -94,7 +94,8 @@ public class FontsContractTest extends ProviderTestCase2<TestFontsProvider> { FontResult fontResult = resultList.get(0); assertEquals(TestFontsProvider.TTC_INDEX, fontResult.getTtcIndex()); assertEquals(TestFontsProvider.VARIATION_SETTINGS, fontResult.getFontVariationSettings()); - assertEquals(TestFontsProvider.STYLE, fontResult.getStyle()); + assertEquals(TestFontsProvider.NORMAL_WEIGHT, fontResult.getWeight()); + assertEquals(TestFontsProvider.ITALIC, fontResult.getItalic()); assertNotNull(fontResult.getFileDescriptor()); } @@ -115,7 +116,8 @@ public class FontsContractTest extends ProviderTestCase2<TestFontsProvider> { FontResult fontResult = resultList.get(0); assertEquals(0, fontResult.getTtcIndex()); assertNull(fontResult.getFontVariationSettings()); - assertEquals(Typeface.NORMAL, fontResult.getStyle()); + assertEquals(400, fontResult.getWeight()); + assertFalse(fontResult.getItalic()); assertNotNull(fontResult.getFileDescriptor()); } @@ -146,10 +148,10 @@ public class FontsContractTest extends ProviderTestCase2<TestFontsProvider> { public void testGetFontFromProvider_resultFontNotFoundSecondRow() { MatrixCursor cursor = new MatrixCursor(new String[] { FontsContract.Columns._ID, FontsContract.Columns.TTC_INDEX, FontsContract.Columns.VARIATION_SETTINGS, - FontsContract.Columns.STYLE, FontsContract.Columns.RESULT_CODE }); - cursor.addRow(new Object[] { 1, 0, null, Typeface.NORMAL, - FontsContract.Columns.RESULT_CODE_OK}); - cursor.addRow(new Object[] { 1, 0, null, Typeface.NORMAL, + FontsContract.Columns.WEIGHT, FontsContract.Columns.ITALIC, + FontsContract.Columns.RESULT_CODE }); + cursor.addRow(new Object[] { 1, 0, null, 400, 0, FontsContract.Columns.RESULT_CODE_OK}); + cursor.addRow(new Object[] { 1, 0, null, 400, 0, FontsContract.Columns.RESULT_CODE_FONT_NOT_FOUND}); mProvider.setCustomCursor(cursor); mContract.getFontFromProvider(request, mResultReceiver, TestFontsProvider.AUTHORITY); @@ -160,13 +162,12 @@ public class FontsContractTest extends ProviderTestCase2<TestFontsProvider> { public void testGetFontFromProvider_resultFontNotFoundOtherRow() { MatrixCursor cursor = new MatrixCursor(new String[] { FontsContract.Columns._ID, FontsContract.Columns.TTC_INDEX, FontsContract.Columns.VARIATION_SETTINGS, - FontsContract.Columns.STYLE, FontsContract.Columns.RESULT_CODE }); - cursor.addRow(new Object[] { 1, 0, null, Typeface.NORMAL, - FontsContract.Columns.RESULT_CODE_OK}); - cursor.addRow(new Object[] { 1, 0, null, Typeface.NORMAL, + FontsContract.Columns.WEIGHT, FontsContract.Columns.ITALIC, + FontsContract.Columns.RESULT_CODE }); + cursor.addRow(new Object[] { 1, 0, null, 400, 0, FontsContract.Columns.RESULT_CODE_OK}); + cursor.addRow(new Object[] { 1, 0, null, 400, 0, FontsContract.Columns.RESULT_CODE_FONT_NOT_FOUND}); - cursor.addRow(new Object[] { 1, 0, null, Typeface.NORMAL, - FontsContract.Columns.RESULT_CODE_OK}); + cursor.addRow(new Object[] { 1, 0, null, 400, 0, FontsContract.Columns.RESULT_CODE_OK}); mProvider.setCustomCursor(cursor); mContract.getFontFromProvider(request, mResultReceiver, TestFontsProvider.AUTHORITY); @@ -176,10 +177,10 @@ public class FontsContractTest extends ProviderTestCase2<TestFontsProvider> { public void testGetFontFromProvider_resultCodeIsNegativeNumber() { MatrixCursor cursor = new MatrixCursor(new String[] { FontsContract.Columns._ID, FontsContract.Columns.TTC_INDEX, FontsContract.Columns.VARIATION_SETTINGS, - FontsContract.Columns.STYLE, FontsContract.Columns.RESULT_CODE }); - cursor.addRow(new Object[] { 1, 0, null, Typeface.NORMAL, - FontsContract.Columns.RESULT_CODE_OK}); - cursor.addRow(new Object[] { 1, 0, null, Typeface.NORMAL, -5}); + FontsContract.Columns.WEIGHT, FontsContract.Columns.ITALIC, + FontsContract.Columns.RESULT_CODE }); + cursor.addRow(new Object[] { 1, 0, null, 400, 0, FontsContract.Columns.RESULT_CODE_OK}); + cursor.addRow(new Object[] { 1, 0, null, 400, 0, -5}); mProvider.setCustomCursor(cursor); mContract.getFontFromProvider(request, mResultReceiver, TestFontsProvider.AUTHORITY); diff --git a/core/tests/coretests/src/android/provider/TestFontsProvider.java b/core/tests/coretests/src/android/provider/TestFontsProvider.java index 13f53182a42e..46906dfa1284 100644 --- a/core/tests/coretests/src/android/provider/TestFontsProvider.java +++ b/core/tests/coretests/src/android/provider/TestFontsProvider.java @@ -37,7 +37,8 @@ public class TestFontsProvider extends ContentProvider { static final String AUTHORITY = "android.provider.TestFontsProvider"; static final int TTC_INDEX = 2; static final String VARIATION_SETTINGS = "'wdth' 1"; - static final int STYLE = Typeface.BOLD; + static final int NORMAL_WEIGHT = 400; + static final boolean ITALIC = false; private ParcelFileDescriptor mPfd; private boolean mReturnAllFields = true; @@ -81,8 +82,9 @@ public class TestFontsProvider extends ContentProvider { if (mReturnAllFields) { cursor = new MatrixCursor(new String[] { FontsContract.Columns._ID, FontsContract.Columns.TTC_INDEX, FontsContract.Columns.VARIATION_SETTINGS, - FontsContract.Columns.STYLE, FontsContract.Columns.RESULT_CODE }); - cursor.addRow(new Object[] { 1, TTC_INDEX, VARIATION_SETTINGS, STYLE, mResultCode }); + FontsContract.Columns.WEIGHT, FontsContract.Columns.ITALIC, + FontsContract.Columns.RESULT_CODE }); + cursor.addRow(new Object[] { 1, TTC_INDEX, VARIATION_SETTINGS, 400, 0, mResultCode }); } else { cursor = new MatrixCursor(new String[] { FontsContract.Columns._ID }); cursor.addRow(new Object[] { 1 }); diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index 560d29f1934d..5afe5e9f14e9 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -357,8 +357,8 @@ public class Typeface { long fontSize = fileChannel.size(); ByteBuffer fontBuffer = fileChannel.map( FileChannel.MapMode.READ_ONLY, 0, fontSize); - int style = result.getStyle(); - int weight = (style & BOLD) != 0 ? 700 : 400; + int weight = result.getWeight(); + int italic = result.getItalic() ? Builder.ITALIC : Builder.NORMAL; FontVariationAxis[] axes = null; try { axes = FontVariationAxis.fromFontVariationSettings( @@ -366,8 +366,8 @@ public class Typeface { } catch (FontVariationAxis.InvalidFormatException e) { // TODO: Nice to pass FontVariationAxis[] directly instead of string. } - if (!fontFamily.addFontFromBuffer(fontBuffer, result.getTtcIndex(), axes, weight, - (style & ITALIC) == 0 ? Builder.NORMAL : Builder.ITALIC)) { + if (!fontFamily.addFontFromBuffer(fontBuffer, result.getTtcIndex(), + axes, weight, italic)) { Log.e(TAG, "Error creating font " + request.getQuery()); callback.onTypefaceRequestFailed( FontRequestCallback.FAIL_REASON_FONT_LOAD_ERROR); diff --git a/graphics/java/android/graphics/fonts/FontResult.java b/graphics/java/android/graphics/fonts/FontResult.java index 3ef99fdd62b7..20e736eb1fc3 100644 --- a/graphics/java/android/graphics/fonts/FontResult.java +++ b/graphics/java/android/graphics/fonts/FontResult.java @@ -35,7 +35,8 @@ public final class FontResult implements Parcelable { private final ParcelFileDescriptor mFileDescriptor; private final int mTtcIndex; private final String mFontVariationSettings; - private final int mStyle; + private final int mWeight; + private final boolean mItalic; /** * Creates a FontResult with all the information needed about a provided font. @@ -45,16 +46,16 @@ public final class FontResult implements Parcelable { * will fail to load in the client application. * @param ttcIndex If providing a TTC_INDEX file, the index to point to. Otherwise, 0. * @param fontVariationSettings If providing a variation font, the settings for it. May be null. - * @param style One of {@link android.graphics.Typeface#NORMAL}, - * {@link android.graphics.Typeface#BOLD}, {@link android.graphics.Typeface#ITALIC} - * or {@link android.graphics.Typeface#BOLD_ITALIC} + * @param weight An integer that indicates the font weight. + * @param italic A boolean that indicates the font is italic style or not. */ public FontResult(@NonNull ParcelFileDescriptor fileDescriptor, int ttcIndex, - @Nullable String fontVariationSettings, int style) { + @Nullable String fontVariationSettings, int weight, boolean italic) { mFileDescriptor = Preconditions.checkNotNull(fileDescriptor); mTtcIndex = ttcIndex; mFontVariationSettings = fontVariationSettings; - mStyle = style; + mWeight = weight; + mItalic = italic; } public ParcelFileDescriptor getFileDescriptor() { @@ -69,8 +70,12 @@ public final class FontResult implements Parcelable { return mFontVariationSettings; } - public int getStyle() { - return mStyle; + public int getWeight() { + return mWeight; + } + + public boolean getItalic() { + return mItalic; } @Override @@ -83,14 +88,16 @@ public final class FontResult implements Parcelable { dest.writeParcelable(mFileDescriptor, flags); dest.writeInt(mTtcIndex); dest.writeString(mFontVariationSettings); - dest.writeInt(mStyle); + dest.writeInt(mWeight); + dest.writeBoolean(mItalic); } private FontResult(Parcel in) { mFileDescriptor = in.readParcelable(null); mTtcIndex = in.readInt(); mFontVariationSettings = in.readString(); - mStyle = in.readInt(); + mWeight = in.readInt(); + mItalic = in.readBoolean(); } public static final Parcelable.Creator<FontResult> CREATOR = |