summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge/src/android
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-08-03 17:11:33 -0700
committerXavier Ducrohet <xav@android.com>2011-10-04 18:24:30 -0700
commit14094097329b3bdcbf26392141111d74c8b89718 (patch)
tree9a41ea4a27d5bb311916b66c0f756055f97c78cf /tools/layoutlib/bridge/src/android
parent178006a0e05b41b4c4de93aec30368a9102ca140 (diff)
downloadframeworks_base-14094097329b3bdcbf26392141111d74c8b89718.zip
frameworks_base-14094097329b3bdcbf26392141111d74c8b89718.tar.gz
frameworks_base-14094097329b3bdcbf26392141111d74c8b89718.tar.bz2
Layoutlib: Typeface support for loading fonts manually.
If the font being loaded is a system font, then we can find the font file and manually load it. Change-Id: I95473b1f1b88df64316b77c41ed05d4d09ab61ed
Diffstat (limited to 'tools/layoutlib/bridge/src/android')
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
index dd14355..2414d70 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
@@ -25,6 +25,7 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import android.content.res.AssetManager;
import java.awt.Font;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -43,6 +44,8 @@ import java.util.List;
*/
public final class Typeface_Delegate {
+ private static final String SYSTEM_FONTS = "/system/fonts/";
+
// ---- delegate manager ----
private static final DelegateManager<Typeface_Delegate> sManager =
new DelegateManager<Typeface_Delegate>(Typeface_Delegate.class);
@@ -143,9 +146,31 @@ public final class Typeface_Delegate {
@LayoutlibDelegate
/*package*/ static synchronized int nativeCreateFromFile(String path) {
- Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
- "Typeface.createFromFile() is not supported.", null /*throwable*/, null /*data*/);
- return 0;
+ if (path.startsWith(SYSTEM_FONTS) ) {
+ String relativePath = path.substring(SYSTEM_FONTS.length());
+ File f = new File(sFontLoader.getOsFontsLocation(), relativePath);
+
+ try {
+ Font font = Font.createFont(Font.TRUETYPE_FONT, f);
+ if (font != null) {
+ Typeface_Delegate newDelegate = new Typeface_Delegate(font);
+ return sManager.addNewDelegate(newDelegate);
+ }
+ } catch (Exception e) {
+ Bridge.getLog().fidelityWarning(LayoutLog.TAG_BROKEN,
+ String.format("Unable to load font %1$s", relativePath),
+ null /*throwable*/, null /*data*/);
+ }
+ } else {
+ Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
+ "Typeface.createFromFile() can only work with platform fonts located in " +
+ SYSTEM_FONTS,
+ null /*throwable*/, null /*data*/);
+ }
+
+
+ // return a copy of the base font
+ return nativeCreate(null, 0);
}
@LayoutlibDelegate
@@ -175,6 +200,16 @@ public final class Typeface_Delegate {
mStyle = style;
}
+ private Typeface_Delegate(Font font) {
+ mFamily = font.getFamily();
+ mStyle = Typeface.NORMAL;
+
+ mFonts = sFontLoader.getFallbackFonts(mStyle);
+
+ // insert the font glyph first.
+ mFonts.add(0, font);
+ }
+
private void init() {
mFonts = sFontLoader.getFont(mFamily, mStyle);
}