[libbluray-devel] BDGraphics: lazy init font metrics.
hpi1
git at videolan.org
Fri Nov 21 11:01:41 CET 2014
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Nov 20 10:28:32 2014 +0200| [dc1c2a0b6b7b15633cc2e3aafc95b252ad0a9a3c] | committer: hpi1
BDGraphics: lazy init font metrics.
Avoid loading fonts unless those are actually used.
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=dc1c2a0b6b7b15633cc2e3aafc95b252ad0a9a3c
---
src/libbluray/bdj/java/java/awt/BDGraphicsBase.java | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
index bc06f43..e6a1dc7 100644
--- a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
@@ -111,7 +111,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
font = DEFAULT_FONT;
}
}
- fontMetrics = BDFontMetrics.getFontMetrics(font);
+ fontMetrics = null;
composite = AlphaComposite.SrcOver;
setupClip();
@@ -141,7 +141,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
font = DEFAULT_FONT;
}
}
- fontMetrics = BDFontMetrics.getFontMetrics(font);
+ fontMetrics = null;
composite = AlphaComposite.SrcOver;
setupClip();
@@ -159,7 +159,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
public void setFont(Font font) {
if (font != null && !font.equals(this.font)) {
this.font = font;
- fontMetrics = BDFontMetrics.getFontMetrics(font);
+ fontMetrics = null;
}
}
@@ -168,6 +168,9 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
}
public FontMetrics getFontMetrics() {
+ if (font != null && fontMetrics == null) {
+ fontMetrics = BDFontMetrics.getFontMetrics(font);
+ }
return fontMetrics;
}
@@ -1115,8 +1118,11 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
/** Draws the given string. */
public void drawString(String string, int x, int y) {
+ getFontMetrics();
if (fontMetrics != null) {
fontMetrics.drawString((BDGraphics)this, string, x, y, foreground.getRGB());
+ } else {
+ logger.error("drawString skipped: no font metrics. string=\"" + string + "\"");
}
}
More information about the libbluray-devel
mailing list