OSDN Git Service

Declarative downloadable fonts
authorClara Bayarri <clarabayarri@google.com>
Fri, 27 Jan 2017 20:15:45 +0000 (20:15 +0000)
committerClara Bayarri <clarabayarri@google.com>
Tue, 14 Feb 2017 13:32:41 +0000 (13:32 +0000)
commit4b5a4d221f377686a730182a3bffb8c6f190e313
treee681c202c0231976720d4ff64b9fcfb78e6a559c
parent0bb700914cb84b53a93252e5904826c104b8d65b
Declarative downloadable fonts

Implement support for downloadable font requests in xml. Given the
xml fonts feature in O, this adds support to not only declare
local font files as font resources, but also Downloadable fonts
from a fonts provider.

A provider returns a font family (of one or more files) given a
query, so the new attributes are added to the font-family tag.

Additionally, add support to pre-declare downloadable font resources
in the Android Manifest. These will then be fetched at app startup
time so they are available to use from the Typeface cache asap.

When retrieving downloadable fonts via resources, the cache is
checked to see if the font is already there and is used, otherwise
a request is sent to the provider and the default font is returned
as we need a result synchronously.

To do this, the developer declares an additional fonts xml resource
file with the list of fonts to preload and links it in the manifest
with a meta-data tag.

E.g.:

res/font/mydownloadedfont.xml

<font-family xmlns:android="http://schemas.android.com/apk/res/android"
        android:fontProviderAuthority="com.example.test.fontprovider"
        android:fontProviderQuery="myrequestedfont">
</font-family>

res/font/preloaded_fonts.xml

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <font android:font="@font/mydownloadedfont" />
</font-family>

and in the AndroidManifest.xml

<meta-data android:name="preloaded_fonts"
    android:resource="@font/preloaded_fonts" />

Bug: 3466050034658116
Test: WIP, need to add more
Change-Id: I1d92555e115e241bf23b59e6f5c6cca6c7361de7
14 files changed:
api/current.txt
api/system-current.txt
api/test-current.txt
core/java/android/app/ActivityThread.java
core/java/android/content/pm/ApplicationInfo.java
core/java/android/content/res/FontResourcesParser.java
core/java/android/content/res/Resources.java
core/java/android/content/res/ResourcesImpl.java
core/java/android/text/FontConfig.java
core/res/res/values/attrs.xml
core/res/res/values/public.xml
core/tests/coretests/res/font/samplexmldownloadedfont.xml [new file with mode: 0644]
core/tests/coretests/src/android/content/res/FontResourcesParserTest.java
graphics/java/android/graphics/Typeface.java