[FOray-commit] SF.net SVN: foray:[12769] trunk/foray/foray-font/src/main/java/org/foray/ font
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-12-03 18:20:09
|
Revision: 12769
http://sourceforge.net/p/foray/code/12769
Author: victormote
Date: 2022-12-03 18:20:05 +0000 (Sat, 03 Dec 2022)
Log Message:
-----------
Register Base14 font-families, fonts, and font descriptions at construction time.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2022-12-03 18:17:25 UTC (rev 12768)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2022-12-03 18:20:05 UTC (rev 12769)
@@ -45,6 +45,7 @@
import org.apache.commons.discovery.tools.DiscoverSingleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -62,6 +63,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -76,6 +78,12 @@
/** Constant indicating the default percentage to be applied when creating faux small-caps. */
private static final int DEFAULT_SMALL_CAPS_SIZE = 80;
+ /** List of font-family aliases for which a default value is provided as the server is created. If an alias with
+ * one of these names is registered, overwriting the existing default value is treated normally instead of as a
+ * warning. */
+ private static final List<String> PREDEFINED_ALIASES = Collections.unmodifiableList(Arrays.asList(
+ "serif", "sans-serif", "monospace"));
+
/**
* Base URL where general resources are located. System resource
* locations can be passed that are relative to this URL.
@@ -151,6 +159,8 @@
/**
* Constructor.
+ * The Base-14 fonts and aliases for "serif", "sans-serif", and "monospaced" are registered to Base-14-Times,
+ * Base
* @param psServer The PostScript server.
*/
public FontServer4a(final PsServer psServer) {
@@ -157,6 +167,8 @@
this.psServer = psServer;
try {
registerBase14Fonts();
+ registerDefaultAliases();
+ registerBase14Descriptions();
} catch (final FontException e) {
throw new IllegalStateException("Unable to register Base-14 fonts", e);
}
@@ -355,11 +367,6 @@
getLogger().debug("Setting up fonts.");
registerAWTFonts();
readFontConfig(fontConfigFile);
- /* Wait until the font configuration has been processed before creating
- * the default families, descriptions, and aliases, as the user may
- * have customized them. */
- registerBase14Descriptions();
- registerDefaultAliases();
this.setupCompleted = true;
if (this.logger.isDebugEnabled()) {
listSystemFonts();
@@ -745,20 +752,21 @@
* Add an alias to a RegisteredFontFamily.
* @param alias The name of the font family alias (e.g. "sans-serif").
* @param realFamily The name of the real font family to which this alias should be associated (e.g. "Helvetica").
- * @throws FontException If the {@code realFamily} does not exist, or if the alias is already registered to another
- * font-family.
*/
- public void registerFontFamilyAlias(final String alias, final String realFamily) throws FontException {
+ public void registerFontFamilyAlias(final String alias, final String realFamily) {
final RegisteredFontFamily rff = this.fontFamilies.get(realFamily);
if (rff == null) {
- throw new FontException("Font family " + realFamily
- + " not found. Can't register alias: " + alias);
+ this.logger.warn("Font family \"{}\" not found. Can't register alias: \"{}\".", realFamily, alias);
}
if (this.fontFamilyAliases.containsKey(alias)) {
- final RegisteredFontFamily family = this.fontFamilyAliases.get(
- alias);
- throw new FontException("Alias " + alias
- + " already registered to family " + family.getName());
+ Level loggingLevel = Level.WARN;
+ if (PREDEFINED_ALIASES.contains(alias)) {
+ /* Treat this as a normal even instead of something for which a warning needs to be logged. */
+ loggingLevel = Level.DEBUG;
+ }
+ final RegisteredFontFamily family = this.fontFamilyAliases.get(alias);
+ this.logger.atLevel(loggingLevel).log("Alias \"{}\" already registered to family \"{}\".", alias,
+ family.getName());
}
this.fontFamilyAliases.put(alias, rff);
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2022-12-03 18:17:25 UTC (rev 12768)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2022-12-03 18:20:05 UTC (rev 12769)
@@ -277,11 +277,7 @@
|| family.equals("")) {
errorMessage("font-family-alias entry invalid. " + "Igcase red.");
} else {
- try {
- this.fontServer.registerFontFamilyAlias(alias, family);
- } catch (final FontException e) {
- errorMessage(e.getMessage());
- }
+ this.fontServer.registerFontFamilyAlias(alias, family);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|