Methods Summary |
---|
public static com.sun.perseus.model.FontFace | getDefaultFontFace()
if (defaultFontFace == null) {
loadDefaultFontFace();
}
return defaultFontFace;
|
public static com.sun.perseus.model.FontFace[] | getInitialFontFaces()
if (initialFontFaces == null) {
loadInitialFontFaces();
}
return initialFontFaces;
|
static void | loadDefaultFontFace()Loads the default font face. This assumes that the font face file
has not been loaded already. If the load of the font face fails, the
application throws an error.
try {
InputStream is =
ResourceHandler.getDefaultFontResource();
if (is == null) {
throw new Exception
(Messages.formatMessage
(Messages.ERROR_CANNOT_LOAD_RESOURCE,
new Object[] {"Default Font"}));
}
ModelNode svg = loadSVGFontResource(is);
// Now, get the FontFace from the tree.
// svg -> font -> font-face
defaultFontFace = (FontFace)
svg.getFirstChildNode().getFirstChildNode();
} catch (Exception e) {
// Do not tolerate any error as this is critical for the operation
// of the toolkit.
e.printStackTrace();
throw new Error();
}
|
static void | loadInitialFontFaces()Loads the initial font faces. This assumes that the font face file
has not been loaded already. If the load of the font face fails, the
application throws an error.
try {
InputStream is =
ResourceHandler.getInitialFontResource();
if (is == null) {
throw new Exception
(Messages.formatMessage
(Messages.ERROR_CANNOT_LOAD_RESOURCE,
new Object[] {"Initial Font"}));
}
ModelNode svg = loadSVGFontResource(is);
// Now, get the FontFace from the tree.
// vp -> svg -> font[i] -> font-face
// Count the font children
int n = 0;
ModelNode c = svg.getFirstChildNode();
while (c != null) {
n++;
c = c.getNextSiblingNode();
}
initialFontFaces = new FontFace[n];
ModelNode font = svg.getFirstChildNode();
for (int i = 0; i < initialFontFaces.length; i++) {
initialFontFaces[i] = (FontFace) font.getFirstChildNode();
font = font.getNextSiblingNode();
}
} catch (Exception e) {
// Do not tolerate any error as this is critical for the operation
// of the toolkit.
e.printStackTrace();
throw new Error();
}
|
protected static com.sun.perseus.model.ModelNode | loadSVGFontResource(java.io.InputStream is)Helper method: loads an SVG Font resource file
// We use JAXP to get a SAX 2 Parser
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
SAXParser parser = factory.newSAXParser();
// Configure a ModelBuilder to turn an SVG document
// into a ModelNode tree
DocumentNode root = new DocumentNode();
UpdateAdapter ul = new UpdateAdapter();
root.setUpdateListener(ul);
ModelBuilder modelBuilder = new ModelBuilder(null, root);
ul.loadStarting(root, is);
try {
parser.parse(is, modelBuilder);
} finally {
try {
is.close();
} catch (IOException ioe) {
}
int n = modelBuilder.entityStreams.size();
for (int i = 0; i < n; i++) {
Reader r = (Reader) modelBuilder.entityStreams.elementAt(i);
try {
r.close();
} catch (IOException ioe) {
// Do nothing: this means the stream was
// closed by the SAX parser.
}
}
}
if (!ul.loadSuccess()) {
throw new Exception
(Messages.formatMessage
(Messages.ERROR_CANNOT_LOAD_RESOURCE,
new Object[] {"SVG System Font Resource"}));
}
// trace(modelBuilder.getModelRoot(), "");
return modelBuilder.getModelRoot().getFirstChildNode();
|