Merge "Pass weight/italic pair instead of style." into oc-dev
diff --git a/api/current.txt b/api/current.txt
index e640e30..3c90844 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -34520,14 +34520,15 @@
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 42b2ae6..d20c08c 100644
--- a/api/removed.txt
+++ b/api/removed.txt
@@ -296,6 +296,10 @@
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 fa2a69e..6a14b15 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -37460,14 +37460,15 @@
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 1bafe96..1effe9c 100644
--- a/api/system-removed.txt
+++ b/api/system-removed.txt
@@ -290,6 +290,10 @@
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 795342f..c5dc584 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -34660,14 +34660,15 @@
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 42b2ae6..d20c08c 100644
--- a/api/test-removed.txt
+++ b/api/test-removed.txt
@@ -296,6 +296,10 @@
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 fd9d4db..4deb4ab 100644
--- a/core/java/android/provider/FontsContract.java
+++ b/core/java/android/provider/FontsContract.java
@@ -72,15 +72,28 @@
*/
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 @@
.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 @@
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 @@
? 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 6820e92..1dd3ef6 100644
--- a/core/tests/coretests/src/android/provider/FontsContractTest.java
+++ b/core/tests/coretests/src/android/provider/FontsContractTest.java
@@ -94,7 +94,8 @@
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 @@
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 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 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 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 13f5318..46906df 100644
--- a/core/tests/coretests/src/android/provider/TestFontsProvider.java
+++ b/core/tests/coretests/src/android/provider/TestFontsProvider.java
@@ -37,7 +37,8 @@
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 @@
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 560d29f..5afe5e9 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -357,8 +357,8 @@
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 @@
} 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 3ef99fd..20e736e 100644
--- a/graphics/java/android/graphics/fonts/FontResult.java
+++ b/graphics/java/android/graphics/fonts/FontResult.java
@@ -35,7 +35,8 @@
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 @@
* 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 @@
return mFontVariationSettings;
}
- public int getStyle() {
- return mStyle;
+ public int getWeight() {
+ return mWeight;
+ }
+
+ public boolean getItalic() {
+ return mItalic;
}
@Override
@@ -83,14 +88,16 @@
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 =