Pass weight/italic pair instead of style.
Typeface.NORMAL/BOLD/ITALIC/ITALIC_BOLD is used for specifying relative
from current Typeface. For example
Typeface face = Typeface.create("serif");
Typeface thickerFace = Typeface.create(face, Typeface.BOLD);
Typeface moreThickerFace = Typeface.create(tickerFace, Typface.BOLD);
For the purpose of providing font information, we should use weight/italic
value instead of style in Typeface.
The Columns.STYLE field was kept for preventing runtime crash of demo
apps.
Test: Manually
Change-Id: I732e8ee04a66f61321fc0a98dbfb8fdc0a4dd7a4
This commit is contained in:
@@ -34410,14 +34410,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 {
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -37319,14 +37319,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 {
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -34550,14 +34550,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 {
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -72,13 +72,26 @@ 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
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user