[libbluray-devel] BD-J: use AWT default font from BDJO

hpi1 git at videolan.org
Fri Nov 14 14:09:06 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Nov 13 15:11:06 2014 +0200| [e11b61087a08a0ffca9f2746931685acab611bac] | committer: hpi1

BD-J: use AWT default font from BDJO

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=e11b61087a08a0ffca9f2746931685acab611bac
---

 .../bdj/java-j2se/org/dvb/ui/FontFactory.java      |   15 ++++++++++++++
 .../bdj/java/java/awt/BDGraphicsBase.java          |   21 ++++++++++++++++----
 src/libbluray/bdj/java/java/awt/BDRootWindow.java  |   20 +++++++++++++++++++
 src/libbluray/bdj/java/org/videolan/BDJLoader.java |    1 +
 .../bdj/java/org/videolan/GUIManager.java          |    1 +
 5 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java b/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java
index be58fd2..d6389c2 100644
--- a/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java
+++ b/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java
@@ -43,6 +43,7 @@ public class FontFactory {
 
     public static synchronized void unloadDiscFonts() {
         fonts = null;
+        fontIds = null;
     }
 
     private static synchronized void readDiscFonts() throws FontFormatException, IOException {
@@ -53,6 +54,7 @@ public class FontFactory {
         FontIndexData fontIndexData[] = FontIndex.parseIndex(path);
 
         fonts = new HashMap(fontIndexData.length);
+        fontIds = new HashMap(fontIndexData.length);
         for (int i = 0; i < fontIndexData.length; i++) {
             FontIndexData data = fontIndexData[i];
             try {
@@ -65,6 +67,7 @@ public class FontFactory {
                 font = font.deriveFont(data.getStyle(), data.getMaxSize());
 
                 fonts.put(data.getName(), font);
+                fontIds.put(data.getFileName().substring(0, 5), font);
 
             } catch (IOException ex) {
                 logger.error("Failed reading font " + data.getName() + " from " + data.getFileName() + ": " + ex);
@@ -113,6 +116,17 @@ public class FontFactory {
         }
     }
 
+    public Font createFont(String fontId) {
+        Font font = null;
+        synchronized (FontFactory.class) {
+            font = (Font)fontIds.get(fontId);
+        }
+        if (font != null) {
+            return font.deriveFont(0, 12);
+        }
+        return null;
+    }
+
     public Font createFont(String name, int style, int size)
             throws FontNotAvailableException, FontFormatException, IOException {
         logger.info("Creating font: " + name + " " + style + " " + size);
@@ -138,6 +152,7 @@ public class FontFactory {
     private Font urlFont = null;
 
     private static Map fonts = null;
+    private static Map fontIds = null;
 
     private static final Logger logger = Logger.getLogger(FontFactory.class.getName());
 }
diff --git a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
index cea0993..bc06f43 100644
--- a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
@@ -34,6 +34,7 @@ import org.dvb.ui.DVBBufferedImage;
 
 import sun.awt.ConstrainableGraphics;
 
+import org.videolan.GUIManager;
 import org.videolan.Logger;
 
 abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphics {
@@ -103,9 +104,15 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
             foreground = DEFAULT_COLOR;
         if (background == null)
             background = DEFAULT_COLOR;
-        if (font == null)
-            font = DEFAULT_FONT;
+
+        if (font == null) {
+            font = GUIManager.getInstance().getDefaultFont();
+            if (font == null) {
+                font = DEFAULT_FONT;
+            }
+        }
         fontMetrics = BDFontMetrics.getFontMetrics(font);
+
         composite = AlphaComposite.SrcOver;
         setupClip();
     }
@@ -127,9 +134,15 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
             foreground = DEFAULT_COLOR;
         if (background == null)
             background = new Color(0, 0, 0, 0);
-        if (font == null)
-            font = DEFAULT_FONT;
+
+        if (font == null) {
+            font = GUIManager.getInstance().getDefaultFont();
+            if (font == null) {
+                font = DEFAULT_FONT;
+            }
+        }
         fontMetrics = BDFontMetrics.getFontMetrics(font);
+
         composite = AlphaComposite.SrcOver;
         setupClip();
     }
diff --git a/src/libbluray/bdj/java/java/awt/BDRootWindow.java b/src/libbluray/bdj/java/java/awt/BDRootWindow.java
index e9010a3..ecea4bd 100644
--- a/src/libbluray/bdj/java/java/awt/BDRootWindow.java
+++ b/src/libbluray/bdj/java/java/awt/BDRootWindow.java
@@ -39,6 +39,25 @@ public class BDRootWindow extends Frame {
         return dirty;
     }
 
+    public Font getDefaultFont() {
+        return defaultFont;
+    }
+
+    public void setDefaultFont(String fontId) {
+        if (fontId == null || fontId.equals("*****")) {
+            defaultFont = null;
+        } else {
+            try {
+                defaultFont = (new org.dvb.ui.FontFactory()).createFont(fontId);
+            } catch (Exception ex) {
+                logger.error("Failed setting default font " + fontId + ".otf: " + ex);
+            }
+        }
+        logger.info("setting default font to " + fontId + ".otf (" + defaultFont + ")");
+        setFont(defaultFont);
+    }
+
+
     public void setBounds(int x, int y, int width, int height) {
         if (!isVisible()) {
             if ((width > 0) && (height > 0)) {
@@ -182,6 +201,7 @@ public class BDRootWindow extends Frame {
     private Timer timer = new Timer();
     private TimerTask timerTask = null;
     private boolean overlay_open = false;
+    private Font defaultFont = null;
 
     private static final Logger logger = Logger.getLogger(BDRootWindow.class.getName());
 
diff --git a/src/libbluray/bdj/java/org/videolan/BDJLoader.java b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
index e2f4a16..87f749e 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJLoader.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
@@ -161,6 +161,7 @@ public class BDJLoader {
             GUIManager gui = GUIManager.createInstance();
             TerminalInfo terminfo = bdjo.getTerminalInfo();
             GraphicsResolution res = terminfo.getResolution();
+            gui.setDefaultFont(terminfo.getDefaultFont());
             gui.setResizable(true);
             gui.setSize(res.getWidth(), res.getHeight());
             gui.setVisible(true);
diff --git a/src/libbluray/bdj/java/org/videolan/GUIManager.java b/src/libbluray/bdj/java/org/videolan/GUIManager.java
index c4a56b5..0c7f578 100644
--- a/src/libbluray/bdj/java/org/videolan/GUIManager.java
+++ b/src/libbluray/bdj/java/org/videolan/GUIManager.java
@@ -35,6 +35,7 @@ public class GUIManager extends BDRootWindow {
             instance = new GUIManager();
         } else {
             instance.clearOverlay();
+            instance.setDefaultFont(null);
         }
         return instance;
     }



More information about the libbluray-devel mailing list