[FOray-commit] SF.net SVN: foray: [8257] trunk/foray/foray-font/src/java/org/foray/font
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-09-30 18:10:55
|
Revision: 8257
http://svn.sourceforge.net/foray/?rev=8257&view=rev
Author: victormote
Date: 2006-09-30 11:10:51 -0700 (Sat, 30 Sep 2006)
Log Message:
-----------
Make the SystemFont constructor private, to prevent a SystemFont from being created in a non-graphical environment.
Modified Paths:
--------------
trunk/foray/foray-font/src/java/org/foray/font/RegisteredFont.java
trunk/foray/foray-font/src/java/org/foray/font/SystemFont.java
Modified: trunk/foray/foray-font/src/java/org/foray/font/RegisteredFont.java
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/RegisteredFont.java 2006-09-30 18:09:59 UTC (rev 8256)
+++ trunk/foray/foray-font/src/java/org/foray/font/RegisteredFont.java 2006-09-30 18:10:51 UTC (rev 8257)
@@ -221,14 +221,7 @@
return;
}
this.systemFontCreationCompleted = true;
-
- try {
- this.systemFont = new SystemFont(this);
- } catch (final FontException e) {
- /* This basically means that the SystemFont is unusable, so make
- * sure we don't try to use it. */
- this.systemFont = null;
- }
+ this.systemFont = SystemFont.makeSystemFont(this);
}
/**
Modified: trunk/foray/foray-font/src/java/org/foray/font/SystemFont.java
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/SystemFont.java 2006-09-30 18:09:59 UTC (rev 8256)
+++ trunk/foray/foray-font/src/java/org/foray/font/SystemFont.java 2006-09-30 18:10:51 UTC (rev 8257)
@@ -28,6 +28,7 @@
package org.foray.font;
+import org.foray.common.Environment;
import org.foray.common.WKConstants;
import org.foray.font.charset.CharSet;
import org.foray.font.format.FontFileReader;
@@ -47,7 +48,7 @@
/**
* Handles interface of system (AWT) fonts to the client application.
*/
-class SystemFont extends org.foray.font.FOrayFont {
+final class SystemFont extends org.foray.font.FOrayFont {
/** The logical font families used by AWT Fonts. */
public static final String[] LOGICAL_FONT_FAMILIES = {
@@ -75,17 +76,39 @@
private FontMetrics lastMetrics = null;
/**
- * Constructs a new SystemFont.
+ * Private constructor.
+ * To obtain a SystemFont instance, use
+ * {@link #makeSystemFont(RegisteredFont)}.
* @param rf The parent RegisteredFont instance.
* @throws FontException For error creating font.
*/
- public SystemFont(final RegisteredFont rf) throws FontException {
+ private SystemFont(final RegisteredFont rf) throws FontException {
super(rf);
final Font newFont = createFont();
this.lastMetrics = getGraphics().getFontMetrics(newFont);
}
/**
+ * Factory method that creates a new SystemFont instance.
+ * @param rf The parent RegisteredFont instance.
+ * @return The new SystemFont instance.
+ */
+ public static SystemFont makeSystemFont(final RegisteredFont rf) {
+ /* Don't allow the SystemFont to be created unless we are running in a
+ * graphical environment. Trying to create AWT fonts in a non-graphical
+ * environment will result in a runtime Error and will crash the
+ * system. */
+ if (! Environment.isGraphicalEnvironment()) {
+ return null;
+ }
+ try {
+ return new SystemFont(rf);
+ } catch (final FontException e) {
+ return null;
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
public int getAscender(final int fontSize) {
@@ -234,7 +257,7 @@
/**
* {@inheritDoc}
*/
- public final Kerning getKerning() {
+ public Kerning getKerning() {
final FreeStandingFont relatedFSFont =
this.freeStandingFontManifestation();
if (relatedFSFont == null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|