From 9040d23fc7b6f9350824a5fb8a8c908e7607c48c Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 25 Feb 2021 15:20:02 -0800 Subject: Use correct extension based on file contents. Bug: 180364535 Test: atest com.android.server.graphics.fonts Test: atest ApkVerityTest Test: atest UpdatableSystemFontTest Test: atest FontManagerTest Change-Id: Ia0e0822105868e47e7356a120ce20d8bf5d1e106 --- graphics/java/android/graphics/fonts/FontFileUtil.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'graphics/java') 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); -- cgit v1.2.3-59-g8ed1b