summaryrefslogtreecommitdiff
path: root/graphics/java
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-03-12 03:13:56 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-03-12 03:13:56 +0000
commit0b509e9e12e7f75f234eac3dbe591742236f0625 (patch)
treeadf72966600f004dfbb03a98dae9f07a739545f8 /graphics/java
parent70a30dabed155a86bc992109e194e3c9ad713cea (diff)
parent9040d23fc7b6f9350824a5fb8a8c908e7607c48c (diff)
Merge "Use correct extension based on file contents." into sc-dev
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/fonts/FontFileUtil.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/graphics/java/android/graphics/fonts/FontFileUtil.java b/graphics/java/android/graphics/fonts/FontFileUtil.java
index af49619fb840..917eef2ffede 100644
--- a/graphics/java/android/graphics/fonts/FontFileUtil.java
+++ b/graphics/java/android/graphics/fonts/FontFileUtil.java
@@ -183,6 +183,23 @@ public class FontFileUtil {
return nIsPostScriptType1Font(buffer, index);
}
+ /**
+ * Analyze the file content and returns 1 if the font file is an OpenType collection file, 0 if
+ * the font file is a OpenType font file, -1 otherwise.
+ */
+ public static int isCollectionFont(@NonNull ByteBuffer buffer) {
+ ByteBuffer copied = buffer.slice();
+ copied.order(ByteOrder.BIG_ENDIAN);
+ int magicNumber = copied.getInt(0);
+ if (magicNumber == TTC_TAG) {
+ return 1;
+ } else if (magicNumber == SFNT_VERSION_1 || magicNumber == SFNT_VERSION_OTTO) {
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+
@FastNative
private static native long nGetFontRevision(@NonNull ByteBuffer buffer,
@IntRange(from = 0) int index);