summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java19
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java13
2 files changed, 29 insertions, 3 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java b/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java
index 88ebd1f..154851b 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java
@@ -16,6 +16,9 @@
package android.graphics;
+import com.android.ide.common.rendering.api.LayoutLog;
+import com.android.layoutlib.bridge.Bridge;
+
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Toolkit;
@@ -58,6 +61,8 @@ public class BidiRenderer {
private final Graphics2D mGraphics;
private final Paint_Delegate mPaint;
private char[] mText;
+ // This List can contain nulls. A null font implies that the we weren't able to load the font
+ // properly. So, if we encounter a situation where we try to use that font, log a warning.
private List<Font> mFonts;
// Bounds of the text drawn so far.
private RectF mBounds;
@@ -169,6 +174,10 @@ public class BidiRenderer {
// fonts to check which one can draw it.
int charCount = Character.isHighSurrogate(mText[start]) ? 2 : 1;
for (Font font : mFonts) {
+ if (font == null) {
+ logFontWarning();
+ continue;
+ }
canDisplayUpTo = font.canDisplayUpTo(mText, start, start + charCount);
if (canDisplayUpTo == -1) {
render(start, start+charCount, font, flag, advances, advancesIndex, draw);
@@ -191,6 +200,12 @@ public class BidiRenderer {
}
}
+ private static void logFontWarning() {
+ Bridge.getLog().fidelityWarning(LayoutLog.TAG_BROKEN,
+ "Some fonts could not be loaded. The rendering may not be perfect. " +
+ "Try running the IDE with JRE 7.", null, null);
+ }
+
/**
* Renders the text to the right of the bounds with the given font.
* @param font The font to render the text with.
@@ -266,6 +281,10 @@ public class BidiRenderer {
private static void setScriptFont(char[] text, ScriptRun run,
List<Font> fonts) {
for (Font font : fonts) {
+ if (font == null) {
+ logFontWarning();
+ continue;
+ }
if (font.canDisplayUpTo(text, run.start, run.limit) == -1) {
run.font = font;
return;
diff --git a/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java
index 30b0ce5..de3307f 100644
--- a/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java
@@ -24,6 +24,7 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import android.content.res.AssetManager;
import java.awt.Font;
+import java.awt.FontFormatException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -152,14 +153,20 @@ public class FontFamily_Delegate {
try {
return Font.createFont(Font.TRUETYPE_FONT, f);
} catch (Exception e) {
+ if (path.endsWith(".otf") && e instanceof FontFormatException) {
+ // If we aren't able to load an Open Type font, don't log a warning just yet.
+ // We wait for a case where font is being used. Only then we try to log the
+ // warning.
+ return null;
+ }
Bridge.getLog().fidelityWarning(LayoutLog.TAG_BROKEN,
String.format("Unable to load font %1$s", relativePath),
- e /*throwable*/, null /*data*/);
+ e, null);
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
"Only platform fonts located in " + SYSTEM_FONTS + "can be loaded.",
- null /*throwable*/, null /*data*/);
+ null, null);
}
return null;
@@ -206,7 +213,7 @@ public class FontFamily_Delegate {
@LayoutlibDelegate
/*package*/ static boolean nAddFontFromAsset(long nativeFamily, AssetManager mgr, String path) {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
- "FontFamily.addFontFromAsset is not supported.", null /*throwable*/, null /*data*/);
+ "FontFamily.addFontFromAsset is not supported.", null, null);
return false;
}