[FOray-commit] SF.net SVN: foray: [10450] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2008-03-19 18:58:33
|
Revision: 10450
http://foray.svn.sourceforge.net/foray/?rev=10450&view=rev
Author: victormote
Date: 2008-03-19 11:58:35 -0700 (Wed, 19 Mar 2008)
Log Message:
-----------
Rename font-related classes starting with "FOray" to instead end with "4a". This better distinguishes our classes from our modules and cleans up some naming in testing classes.
Modified Paths:
--------------
trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java
trunk/foray/foray-font/src/java/org/foray/font/FSTrueTypeFont.java
trunk/foray/foray-font/src/java/org/foray/font/FSType1Font.java
trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java
trunk/foray/foray-font/src/java/org/foray/font/FontSelector.java
trunk/foray/foray-font/src/java/org/foray/font/FontSelectorCBC.java
trunk/foray/foray-font/src/java/org/foray/font/FontSelectorFactory.java
trunk/foray/foray-font/src/java/org/foray/font/FreeStandingFont.java
trunk/foray/foray-font/src/java/org/foray/font/RegisteredFont.java
trunk/foray/foray-font/src/java/org/foray/font/RegisteredFontDesc.java
trunk/foray/foray-font/src/java/org/foray/font/RegisteredFontFamily.java
trunk/foray/foray-font/src/java/org/foray/font/Subset.java
trunk/foray/foray-font/src/java/org/foray/font/SystemFont.java
trunk/foray/foray-font/src/java/org/foray/font/output/FOrayFontOutput.java
trunk/foray/foray-font/src/java/org/foray/font/output/FOrayFontOutputFactory.java
trunk/foray/foray-font/src/java/org/foray/font/output/FOrayFontPDF.java
trunk/foray/foray-font/src/java/org/foray/font/output/FOrayFontPDFFactory.java
trunk/foray/foray-font/src/java/org/foray/font/output/FOrayFontPS.java
trunk/foray/foray-font/src/java/org/foray/font/output/FOrayFontPSFactory.java
trunk/foray/foray-font/src/javatest/org/foray/font/TestFontServer.java
Added Paths:
-----------
trunk/foray/foray-font/src/java/org/foray/font/ConsumerFont4a.java
trunk/foray/foray-font/src/java/org/foray/font/Font4a.java
trunk/foray/foray-font/src/java/org/foray/font/FontConsumer4a.java
trunk/foray/foray-font/src/java/org/foray/font/FontServer4a.java
trunk/foray/foray-font/src/java/org/foray/font/FontUse4a.java
Removed Paths:
-------------
trunk/foray/foray-font/src/java/org/foray/font/FOrayConsumerFont.java
trunk/foray/foray-font/src/java/org/foray/font/FOrayFont.java
trunk/foray/foray-font/src/java/org/foray/font/FOrayFontConsumer.java
trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java
trunk/foray/foray-font/src/java/org/foray/font/FOrayFontUse.java
Modified: trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java
===================================================================
--- trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2008-03-19 18:14:02 UTC (rev 10449)
+++ trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2008-03-19 18:58:35 UTC (rev 10450)
@@ -34,7 +34,7 @@
import org.foray.core.FOrayException;
import org.foray.core.FOraySession;
import org.foray.core.SessionConfig;
-import org.foray.font.FOrayFontServer;
+import org.foray.font.FontServer4a;
import org.foray.fotree.FOrayFOTreeServer;
import org.foray.graphic.GraphicServer4a;
import org.foray.pioneer.PioneerFactory;
@@ -134,7 +134,7 @@
public static FontServer makeFontServer(final Log logger,
final SessionConfig configuration) throws FOrayException {
final EntityResolver entityResolver = makeEntityResolver(configuration);
- final FOrayFontServer forayFontServer = new FOrayFontServer(logger);
+ final FontServer4a forayFontServer = new FontServer4a(logger);
forayFontServer.setBaseFontURL(
configuration.optionFontBaseDirectory());
forayFontServer.setBaseURL(configuration.optionBaseDirectory());
Copied: trunk/foray/foray-font/src/java/org/foray/font/ConsumerFont4a.java (from rev 9957, trunk/foray/foray-font/src/java/org/foray/font/FOrayConsumerFont.java)
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/ConsumerFont4a.java (rev 0)
+++ trunk/foray/foray-font/src/java/org/foray/font/ConsumerFont4a.java 2008-03-19 18:58:35 UTC (rev 10450)
@@ -0,0 +1,313 @@
+/*
+ * Copyright 2006 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font;
+
+import org.foray.ps.encode.EncodingStandard;
+import org.foray.ps.encode.EncodingSymbol;
+import org.foray.ps.encode.EncodingVector;
+import org.foray.ps.encode.EncodingZapfDingbats;
+
+import org.axsl.ps.Encoding;
+
+import org.apache.commons.logging.Log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>A ConsumerFont represents a Font as used by a specific FontConsumer.
+ * The key fields are therefore a Font and a FontConsumer.
+ * The main responsibilities of this class are:</p>
+ * <ul>
+ * <li>To supply a FontUse with the proper encoding when it is requested by
+ * a FontConsumer.</li>
+ * <li>To handle subsetting.</li>
+ * </ul>
+ *
+ */
+public class ConsumerFont4a {
+
+ /** The parent Font instance. */
+ private Font4a font;
+
+ /** The parent FontConsumer instance. */
+ private FontConsumer4a consumer;
+
+ /** The Subset instance. This is null if subsetting is not being used. */;
+ private Subset subset = null;
+
+ /** List of all child FontUse instances. */
+ private List<FontUse4a> fontUses = new ArrayList<FontUse4a>(1);
+
+ /**
+ * Constructor.
+ * @param font The parent font.
+ * @param consumer The parent font consumer.
+ */
+ public ConsumerFont4a(final Font4a font,
+ final FontConsumer4a consumer) {
+ this.font = font;
+ this.consumer = consumer;
+ if (this.font.isSubsettable()) {
+ this.subset = new Subset(this);
+ }
+ }
+
+ /**
+ * Returns the parent font.
+ * @return The font.
+ */
+ public Font4a getFOrayFont() {
+ return this.font;
+ }
+
+ /**
+ * Returns the font cast as a free-standing font.
+ * @return The font cast as a free-standing font if it is one, or null
+ * otherwise.
+ */
+ public FreeStandingFont getFreeStandingFont() {
+ if (this.font instanceof FreeStandingFont) {
+ return (FreeStandingFont) this.font;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the font cast as a system font.
+ * @return The font cast as a system font if it is one, or null otherwise.
+ */
+ public SystemFont getSystemFont() {
+ if (this.font instanceof SystemFont) {
+ return (SystemFont) this.font;
+ }
+ return null;
+ }
+
+ /**
+ * Return the parent font consumer.
+ * @return The font consumer.
+ */
+ public FontConsumer4a getFontConsumer() {
+ return this.consumer;
+ }
+
+ /**
+ * Return the subset information for this font.
+ * @return The subset.
+ */
+ public Subset getSubset() {
+ return this.subset;
+ }
+
+ /**
+ * Indicates whether this font is being subsetted.
+ * @return True iff this font is being subsetted.
+ */
+ public boolean subSetting() {
+ return this.subset != null;
+ }
+
+ /**
+ * Return the logger.
+ * @return The logger.
+ */
+ public Log getLogger() {
+ return this.consumer.getLogger();
+ }
+
+ /**
+ * Return the font server.
+ * @return The font server.
+ */
+ public FontServer4a getFOrayFontServer() {
+ return this.consumer.getFontServer();
+ }
+
+ /**
+ * Optimize the information about this font in preparation for output.
+ */
+ protected void optimize() {
+ if (this.subset != null) {
+ this.subset.sortUsedGlyphs();
+ }
+ }
+
+ /**
+ * Return the collection of child font uses.
+ * @return The child font uses.
+ */
+ public List<FontUse4a> getFontUses() {
+ return this.fontUses;
+ }
+
+ /**
+ * Select a font use based on the registered font description and a Unicode
+ * code point.
+ * @param rfd The font description that should be used for the selection.
+ * @param codePoint The Unicode code point that should be encodable by the
+ * returned font use.
+ * @return The best font use.
+ */
+ public FontUse4a selectFontUse(final RegisteredFontDesc rfd,
+ final int codePoint) {
+ if (rfd == null) {
+ return null;
+ }
+ FontUse4a fontUse = null;
+ final SystemFont sf = getSystemFont();
+ /* Check existing FontUse instances. */
+ for (int i = 0; i < this.fontUses.size() && fontUse == null; i++) {
+ final FontUse4a trialFontUse = this.fontUses.get(i);
+ if (trialFontUse.getRegisteredFontDesc() != rfd) {
+ continue;
+ }
+ if (sf != null) {
+ if (! sf.glyphAvailable(codePoint)) {
+ continue;
+ }
+ } else {
+ final org.axsl.ps.Encoding encoding =
+ trialFontUse.getEncoding();
+ if (! encoding.canEncode(codePoint)) {
+ continue;
+ }
+ }
+ fontUse = trialFontUse;
+ }
+ if (fontUse != null) {
+ return fontUse;
+ }
+ /* If none already exists, create one. */
+ if (sf != null) {
+ /* We don't care about encodings for SystemFonts. */
+ fontUse = new FontUse4a(this, rfd, null);
+ } else {
+ final Encoding encoding = findEncoding(rfd, codePoint);
+ if (encoding == null) {
+ /* We can't encode this character.
+ * Return null so that the upstream font selection routines can
+ * try another font family. */
+ return null;
+ }
+ fontUse = new FontUse4a(this, rfd, encoding);
+ }
+ this.fontUses.add(fontUse);
+ return fontUse;
+ }
+
+ /**
+ * Returns the described FontUse instance, creating it if necessary.
+ * @param rfd The description for which the font use should be retrieved
+ * or created.
+ * @param encoding The encoding for which the font use should be retrieved
+ * or created.
+ * @return The selected or created font use.
+ */
+ public FontUse4a getFontUse(final RegisteredFontDesc rfd,
+ final Encoding encoding) {
+ for (int i = 0; i < this.fontUses.size(); i++) {
+ final FontUse4a fontUse = this.fontUses.get(i);
+ if (fontUse.getRegisteredFontDesc() != rfd) {
+ continue;
+ }
+ if (fontUse.getEncoding() != encoding) {
+ continue;
+ }
+ return fontUse;
+ }
+ return new FontUse4a(this, rfd, encoding);
+ }
+
+ /**
+ * Find the encoding that should be used for the seletion of a font use.
+ * @param rfd The font description.
+ * @param codePoint The Unicode code point.
+ * @return The appropriate encoding.
+ */
+ public Encoding findEncoding(final RegisteredFontDesc rfd,
+ final int codePoint) {
+ switch (this.consumer.getEncodingLatitude()) {
+ case FontConsumer4a.ENCODING_SPECIFIED_ONLY: {
+ return rfd.getEncoding();
+ }
+ case FontConsumer4a.ENCODING_INTERNAL_ONLY: {
+ return this.font.getInternalEncoding();
+ }
+ case FontConsumer4a.ENCODING_ANY: {
+ return getBestEncoding(codePoint);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Finds the best encoding to use for a given Unicode code point.
+ * @param codePoint The Unicode code point to be tested.
+ * @return The best encoding to use for the code point.
+ */
+ private Encoding getBestEncoding(final int codePoint) {
+ Encoding trialEncoding = null;
+ final Encoding internalEncoding = this.font.getInternalEncoding();
+ if (! (internalEncoding instanceof EncodingVector)) {
+ /* CMap encodings should be able to handle any character in the
+ * font's character set. */
+ return internalEncoding;
+ }
+ if (internalEncoding instanceof EncodingSymbol
+ || internalEncoding instanceof EncodingZapfDingbats) {
+ /* The specialized encodings cover their entire character set. */
+ return internalEncoding;
+ }
+ if (internalEncoding instanceof EncodingStandard) {
+ /* Try WinAnsiEncoding. */
+ trialEncoding = EncodingVector.getPredefinedEncoding(
+ "WinAnsiEncoding");
+ if (trialEncoding.canEncode(codePoint)) {
+ return trialEncoding;
+ }
+ /* Try the Central European encoding. */
+ trialEncoding = EncodingVector.getPredefinedEncoding("CEEncoding");
+ if (trialEncoding.canEncode(codePoint)) {
+ return trialEncoding;
+ }
+ /* Try the FOray catch-all encoding. */
+ trialEncoding = EncodingVector.getPredefinedEncoding(
+ "FOrayLatinExtraEncoding");
+ if (trialEncoding.canEncode(codePoint)) {
+ return trialEncoding;
+ }
+ }
+ if (internalEncoding.canEncode(codePoint)) {
+ return internalEncoding;
+ }
+ return null;
+ }
+
+}
Deleted: trunk/foray/foray-font/src/java/org/foray/font/FOrayConsumerFont.java
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/FOrayConsumerFont.java 2008-03-19 18:14:02 UTC (rev 10449)
+++ trunk/foray/foray-font/src/java/org/foray/font/FOrayConsumerFont.java 2008-03-19 18:58:35 UTC (rev 10450)
@@ -1,313 +0,0 @@
-/*
- * Copyright 2006 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font;
-
-import org.foray.ps.encode.EncodingStandard;
-import org.foray.ps.encode.EncodingSymbol;
-import org.foray.ps.encode.EncodingVector;
-import org.foray.ps.encode.EncodingZapfDingbats;
-
-import org.axsl.ps.Encoding;
-
-import org.apache.commons.logging.Log;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * <p>A ConsumerFont represents a Font as used by a specific FontConsumer.
- * The key fields are therefore a Font and a FontConsumer.
- * The main responsibilities of this class are:</p>
- * <ul>
- * <li>To supply a FontUse with the proper encoding when it is requested by
- * a FontConsumer.</li>
- * <li>To handle subsetting.</li>
- * </ul>
- *
- */
-public class FOrayConsumerFont {
-
- /** The parent Font instance. */
- private FOrayFont font;
-
- /** The parent FontConsumer instance. */
- private FOrayFontConsumer consumer;
-
- /** The Subset instance. This is null if subsetting is not being used. */;
- private Subset subset = null;
-
- /** List of all child FontUse instances. */
- private List<FOrayFontUse> fontUses = new ArrayList<FOrayFontUse>(1);
-
- /**
- * Constructor.
- * @param font The parent font.
- * @param consumer The parent font consumer.
- */
- public FOrayConsumerFont(final FOrayFont font,
- final FOrayFontConsumer consumer) {
- this.font = font;
- this.consumer = consumer;
- if (this.font.isSubsettable()) {
- this.subset = new Subset(this);
- }
- }
-
- /**
- * Returns the parent font.
- * @return The font.
- */
- public FOrayFont getFOrayFont() {
- return this.font;
- }
-
- /**
- * Returns the font cast as a free-standing font.
- * @return The font cast as a free-standing font if it is one, or null
- * otherwise.
- */
- public FreeStandingFont getFreeStandingFont() {
- if (this.font instanceof FreeStandingFont) {
- return (FreeStandingFont) this.font;
- }
- return null;
- }
-
- /**
- * Returns the font cast as a system font.
- * @return The font cast as a system font if it is one, or null otherwise.
- */
- public SystemFont getSystemFont() {
- if (this.font instanceof SystemFont) {
- return (SystemFont) this.font;
- }
- return null;
- }
-
- /**
- * Return the parent font consumer.
- * @return The font consumer.
- */
- public FOrayFontConsumer getFontConsumer() {
- return this.consumer;
- }
-
- /**
- * Return the subset information for this font.
- * @return The subset.
- */
- public Subset getSubset() {
- return this.subset;
- }
-
- /**
- * Indicates whether this font is being subsetted.
- * @return True iff this font is being subsetted.
- */
- public boolean subSetting() {
- return this.subset != null;
- }
-
- /**
- * Return the logger.
- * @return The logger.
- */
- public Log getLogger() {
- return this.consumer.getLogger();
- }
-
- /**
- * Return the font server.
- * @return The font server.
- */
- public FOrayFontServer getFOrayFontServer() {
- return this.consumer.getFontServer();
- }
-
- /**
- * Optimize the information about this font in preparation for output.
- */
- protected void optimize() {
- if (this.subset != null) {
- this.subset.sortUsedGlyphs();
- }
- }
-
- /**
- * Return the collection of child font uses.
- * @return The child font uses.
- */
- public List<FOrayFontUse> getFontUses() {
- return this.fontUses;
- }
-
- /**
- * Select a font use based on the registered font description and a Unicode
- * code point.
- * @param rfd The font description that should be used for the selection.
- * @param codePoint The Unicode code point that should be encodable by the
- * returned font use.
- * @return The best font use.
- */
- public FOrayFontUse selectFontUse(final RegisteredFontDesc rfd,
- final int codePoint) {
- if (rfd == null) {
- return null;
- }
- FOrayFontUse fontUse = null;
- final SystemFont sf = getSystemFont();
- /* Check existing FontUse instances. */
- for (int i = 0; i < this.fontUses.size() && fontUse == null; i++) {
- final FOrayFontUse trialFontUse = this.fontUses.get(i);
- if (trialFontUse.getRegisteredFontDesc() != rfd) {
- continue;
- }
- if (sf != null) {
- if (! sf.glyphAvailable(codePoint)) {
- continue;
- }
- } else {
- final org.axsl.ps.Encoding encoding =
- trialFontUse.getEncoding();
- if (! encoding.canEncode(codePoint)) {
- continue;
- }
- }
- fontUse = trialFontUse;
- }
- if (fontUse != null) {
- return fontUse;
- }
- /* If none already exists, create one. */
- if (sf != null) {
- /* We don't care about encodings for SystemFonts. */
- fontUse = new FOrayFontUse(this, rfd, null);
- } else {
- final Encoding encoding = findEncoding(rfd, codePoint);
- if (encoding == null) {
- /* We can't encode this character.
- * Return null so that the upstream font selection routines can
- * try another font family. */
- return null;
- }
- fontUse = new FOrayFontUse(this, rfd, encoding);
- }
- this.fontUses.add(fontUse);
- return fontUse;
- }
-
- /**
- * Returns the described FontUse instance, creating it if necessary.
- * @param rfd The description for which the font use should be retrieved
- * or created.
- * @param encoding The encoding for which the font use should be retrieved
- * or created.
- * @return The selected or created font use.
- */
- public FOrayFontUse getFontUse(final RegisteredFontDesc rfd,
- final Encoding encoding) {
- for (int i = 0; i < this.fontUses.size(); i++) {
- final FOrayFontUse fontUse = this.fontUses.get(i);
- if (fontUse.getRegisteredFontDesc() != rfd) {
- continue;
- }
- if (fontUse.getEncoding() != encoding) {
- continue;
- }
- return fontUse;
- }
- return new FOrayFontUse(this, rfd, encoding);
- }
-
- /**
- * Find the encoding that should be used for the seletion of a font use.
- * @param rfd The font description.
- * @param codePoint The Unicode code point.
- * @return The appropriate encoding.
- */
- public Encoding findEncoding(final RegisteredFontDesc rfd,
- final int codePoint) {
- switch (this.consumer.getEncodingLatitude()) {
- case FOrayFontConsumer.ENCODING_SPECIFIED_ONLY: {
- return rfd.getEncoding();
- }
- case FOrayFontConsumer.ENCODING_INTERNAL_ONLY: {
- return this.font.getInternalEncoding();
- }
- case FOrayFontConsumer.ENCODING_ANY: {
- return getBestEncoding(codePoint);
- }
- }
- return null;
- }
-
- /**
- * Finds the best encoding to use for a given Unicode code point.
- * @param codePoint The Unicode code point to be tested.
- * @return The best encoding to use for the code point.
- */
- private Encoding getBestEncoding(final int codePoint) {
- Encoding trialEncoding = null;
- final Encoding internalEncoding = this.font.getInternalEncoding();
- if (! (internalEncoding instanceof EncodingVector)) {
- /* CMap encodings should be able to handle any character in the
- * font's character set. */
- return internalEncoding;
- }
- if (internalEncoding instanceof EncodingSymbol
- || internalEncoding instanceof EncodingZapfDingbats) {
- /* The specialized encodings cover their entire character set. */
- return internalEncoding;
- }
- if (internalEncoding instanceof EncodingStandard) {
- /* Try WinAnsiEncoding. */
- trialEncoding = EncodingVector.getPredefinedEncoding(
- "WinAnsiEncoding");
- if (trialEncoding.canEncode(codePoint)) {
- return trialEncoding;
- }
- /* Try the Central European encoding. */
- trialEncoding = EncodingVector.getPredefinedEncoding("CEEncoding");
- if (trialEncoding.canEncode(codePoint)) {
- return trialEncoding;
- }
- /* Try the FOray catch-all encoding. */
- trialEncoding = EncodingVector.getPredefinedEncoding(
- "FOrayLatinExtraEncoding");
- if (trialEncoding.canEncode(codePoint)) {
- return trialEncoding;
- }
- }
- if (internalEncoding.canEncode(codePoint)) {
- return internalEncoding;
- }
- return null;
- }
-
-}
Deleted: trunk/foray/foray-font/src/java/org/foray/font/FOrayFont.java
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/FOrayFont.java 2008-03-19 18:14:02 UTC (rev 10449)
+++ trunk/foray/foray-font/src/java/org/foray/font/FOrayFont.java 2008-03-19 18:58:35 UTC (rev 10450)
@@ -1,558 +0,0 @@
-/*
- * Copyright 2005 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-package org.foray.font;
-
-import org.foray.common.WKConstants;
-import org.foray.font.charset.CharSet;
-import org.foray.font.format.Kerning;
-
-import org.axsl.font.Font;
-
-import org.apache.commons.logging.Log;
-
-/**
- * An implementation of the aXSL {@link FOrayFont} interface.
- */
-public abstract class FOrayFont implements org.axsl.font.Font {
-
- /** Constant indicating the ratio between 3-per-em and em. */
- private static final int FACTOR_3_PER_EM = 3;
-
- /** Constant indicating the ratio between 4-per-em and em. */
- private static final int FACTOR_4_PER_EM = 4;
-
- /** Constant indicating the ratio between 6-per-em and em. */
- private static final int FACTOR_6_PER_EM = 6;
-
- /** Constant indicating the ratio between a thin space and em. */
- private static final int FACTOR_THIN_SPACE = 5;
-
- /** Constant indicating the ratio between a hair space and em. */
- private static final int FACTOR_HAIR_SPACE = 10;
-
- /** Constant indicating the default line-height factor. */
- private static final float DEFAULT_LINE_HEIGHT_FACTOR = 1.2F;
-
- /** Constant indicating the default strikeout position. */
- private static final float DEFAULT_STRIKEOUT_POSITION = .375F;
-
- /** Constant for the default strikout size. The computation is equal to
- * 102 / 2048, which factors come from the OpenType manual, Section "OS/2
- * table", for the definition of "yStrikeoutSize", where this ratio is
- * suggested. */
- private static final float DEFAULT_STRIKEOUT_SIZE = 0.0498046875F;
-
- /** Constant for the default underline position. */
- private static final float DEFAULT_UNDERLINE_POSITION = .10F;
-
- /** Constant for the default overline position. */
- private static final float DEFAULT_OVERLINE_POSITION = .10F;
-
- /** Constant for the default hanging baseline position. */
- private static final float DEFAULT_HANGING_BASELINE_POSITION = .3F;
-
- /** Constant used to compute subscript baseline shift amounts. */
- private static final float SUBSCRIPT_SHIFT_FACTOR = .6666666666666666667f;
-
- /** Constant used to compute superscript baseline shift amounts. */
- private static final float SUPERSCRIPT_SHIFT_FACTOR = .6666666666666666667f;
-
- /**
- * The RegisteredFont that is attached to this Font instance.
- */
- private RegisteredFont registeredFont = null;
-
- /**
- * Constructor.
- * @param rf The parent registered font.
- */
- protected FOrayFont(final RegisteredFont rf) {
- this.registeredFont = rf;
- }
-
- /**
- * {@inheritDoc}
- */
- public abstract int getAscender(int fontSize);
-
- /**
- * {@inheritDoc}
- */
- public abstract int getDescender(int fontSize);
-
- /**
- * {@inheritDoc}
- */
- public abstract int getCapHeight(int fontSize);
-
- /**
- * {@inheritDoc}
- */
- public abstract int getXHeight(int fontSize);
-
- /**
- * Return the width of one em.
- * @param fontSize The font size, in millipoints, at which the em width is
- * desired.
- * @return The width of one em at <code>fontSize</code>.
- */
- private int getEmWidth(final int fontSize) {
- return fontSize;
- }
-
- /**
- * Return the width of one en.
- * @param fontSize The font size, in millipoints, at which the en width is
- * desired.
- * @return The width of one en at <code>fontSize</code>.
- */
- private int getEnWidth(final int fontSize) {
- return Math.round(fontSize / 2);
- }
-
- /**
- * {@inheritDoc}
- */
- public abstract int width(int c, int fontSize);
-
- /**
- * {@inheritDoc}
- */
- public int widthEstimate(final int c, final int fontSize) {
- switch (c) {
- case '\u0009': // horizontal tab
- case '\n': // linefeed
- case '\r': // carriage-return
- case '\u00A0': // non-breaking space
- return width(' ', fontSize);
- case '\u2000': //en quad
- return getEnWidth(fontSize);
- case '\u2001': //em quad
- return getEmWidth(fontSize);
- case '\u2002': //en space
- return getEnWidth(fontSize);
- case '\u2003': //em space
- return getEmWidth(fontSize);
- case '\u2004': //3-per-em space
- return Math.round(getEmWidth(fontSize) / FOrayFont.FACTOR_3_PER_EM);
- case '\u2005': //4-per-em space
- return Math.round(getEmWidth(fontSize) / FOrayFont.FACTOR_4_PER_EM);
- case '\u2006': //6-per-em space
- return Math.round(getEmWidth(fontSize) / FOrayFont.FACTOR_6_PER_EM);
- case '\u2007': //figure space
- return width(' ', fontSize);
- case '\u2008': //punctuation space
- return width('.', fontSize);
- case '\u2009': //thin space (1/5 em)
- return Math.round(getEmWidth(fontSize)
- / FOrayFont.FACTOR_THIN_SPACE);
- case '\u200A': //hair space
- return Math.round(getEmWidth(fontSize)
- / FOrayFont.FACTOR_HAIR_SPACE);
- case '\u200B': //zero width space
- return 0;
- case '\u202F': //narrow no-break space
- return Math.round(width(' ', fontSize) / 2);
- case '\u3000': //ideographic space
- return width(' ', fontSize) * 2;
- default:
- return Integer.MIN_VALUE;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public int width(final CharSequence word, final int fontSize,
- final int letterSpacing, final int wordSpacing, final boolean kern) {
- if (word == null) {
- return 0;
- }
- int width = 0;
- for (int i = 0; i < word.length(); i++) {
- // Add the width of the character itself.
- final int charWidth = width(word.charAt(i), fontSize);
- if (charWidth == Integer.MIN_VALUE) {
- width += widthUndefinedGlyph(fontSize);
- } else {
- width += charWidth;
- }
- // Add any kerning.
- if (kern
- && i < word.length() - 1) {
- final int kerning = kern(word.charAt(i), word.charAt(i + 1));
- /* Kerning is computed in 1/1000 of a text-space unit, regardless of how the value
- * is stored internally in the font. Therefore, we just need to adjust for the
- * font-size. */
- width += Math.round(kerning * fontSize / WKConstants.MILLIPOINTS_PER_POINT);
- }
- // Add any word-spacing
- if (word.charAt(i) == ' ') {
- width += wordSpacing;
- }
- }
- /*
- * Letter-spacing should only be added between the characters.
- * It cannot be added before or after the String without making
- * assumptions about the String's context.
- * At least as far as PDF is concerned, when letter spacing is set, it
- * applies to all characters, including whitespace.
- * We will handle it the same way here.
- * TODO: Characters like combining diacriticals should almost
- * certainly not be letter-spaced.
- */
- width += (word.length() - 1) * letterSpacing;
- return width;
- }
-
- /**
- * {@inheritDoc}
- */
- public abstract boolean isEmbeddable();
-
- /**
- * {@inheritDoc}
- */
- public abstract boolean isSubsettable();
-
- /**
- * {@inheritDoc}
- */
- public abstract java.awt.Font getAwtFont(int fontSize);
-
- /**
- * {@inheritDoc}
- */
- public abstract boolean usableInPostScriptOutput();
-
- /**
- * {@inheritDoc}
- */
- public abstract org.axsl.ps.Encoding getInternalEncoding();
-
- /**
- * {@inheritDoc}
- */
- public abstract Font.Format getFontFormat();
-
- /**
- * Returns the kerning for this font.
- * @return The kerning for this font.
- */
- protected abstract Kerning getKerning();
-
- /**
- * Reports whether the font actually contains any kerning information.
- * @return True if the font has kerning information, false otherwise.
- */
- public boolean kerningAvailable() {
- if (getKerning() == null) {
- return false;
- }
- if (getKerning().isEmpty()) {
- return false;
- }
- return true;
- }
-
- /**
- * Reports whether kerning information should be used for this font.
- * @return True if both 1) kerning is available for this font, and 2) the
- * font configuration has kerning="yes" for this font; false otherwise.
- */
- public abstract boolean kerningActive();
-
- /**
- * {@inheritDoc}
- */
- public int kern(final int char1, final int char2) {
- if (getKerning() == null) {
- return 0;
- }
- final int rawKerning = getKerning().kern(char1, char2);
- if (WKConstants.MILLIPOINTS_PER_POINT == this.getUnitsPerTextSpaceUnit()) {
- /* Avoid the potential loss of precision. */
- return rawKerning;
- }
- return Math.round(rawKerning * WKConstants.MILLIPOINTS_PER_POINT
- / this.getUnitsPerTextSpaceUnit());
- }
-
-
- /**
- * Returns the width of the undefined or missing glyph.
- * @param fontSize The font size at which the width should be computed.
- * @return The width, in millipoints, of the undefined glyph at the
- * specified point size.
- */
- public abstract int widthUndefinedGlyph(int fontSize);
-
- /**
- * Reports on the availability of a glyph in this font, without regard to
- * encoding issues.
- * @param c The Unicode code point to be tested.
- * @return True iff this font can paint a glyph for <em>c</em>.
- */
- public abstract boolean glyphAvailable(int c);
-
- /**
- * {@inheritDoc}
- */
- public abstract float getItalicAngle();
-
- /**
- * {@inheritDoc}
- */
- public abstract int getStemV();
-
- /**
- * {@inheritDoc}
- */
- public abstract int getDefaultWidth();
-
- /**
- * {@inheritDoc}
- */
- public abstract boolean isPdfStandardFont();
-
- /**
- * Return the parent registered font.
- * @return The registered font.
- */
- public RegisteredFont getRegisteredFont() {
- return this.registeredFont;
- }
-
- /**
- * Return the logger.
- * @return The logger.
- */
- public Log getLogger() {
- return this.registeredFont.getLogger();
- }
-
- /**
- * Returns the number of glyphs in this font.
- * @return The number of glyphs in this font.
- */
- public abstract int getNumGlyphs();
-
- /**
- * Returns the character set used by this font.
- * @return The character set for this font.
- */
- public abstract CharSet getCharSet();
-
- /**
- * {@inheritDoc}
- */
- public float normalLineHeightFactor(
- final Font.LineHeightAlgorithm algorithm) {
- switch (algorithm) {
- case DEFAULT:
- default: {
- return FOrayFont.DEFAULT_LINE_HEIGHT_FACTOR;
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public int baselineOffset(final Font.WritingMode writingMode,
- final Baseline baselineType, final int fontSize) {
- final int baseline = extractBaseline(writingMode, baselineType,
- fontSize);
- if (baseline == Integer.MIN_VALUE) {
- return estimateBaseline(writingMode, baselineType, fontSize);
- }
- return baseline;
- }
-
- /**
- * Returns the font's explicit definition of the baseline, if possible.
- * @param writingMode Same as for
- * {@link #baselineOffset(Font.WritingMode, Baseline, int)}.
- * @param baselineType Same as for
- * {@link #baselineOffset(Font.WritingMode, Baseline, int)}.
- * @param fontSize Same as for
- * {@link #baselineOffset(Font.WritingMode, Baseline, int)}.
- * @return The extracted Baseline, as described for
- * {@link #baselineOffset(Font.WritingMode, Baseline, int)}, if it exists.
- * Otherwise, returns {@link Integer#MIN_VALUE}.
- */
- public abstract int extractBaseline(Font.WritingMode writingMode,
- Baseline baselineType, int fontSize);
-
- /**
- * Provides reasonable estimates of the various baseline values for the
- * font, based on other font metrics.
- * @param writingMode Same as for
- * {@link #baselineOffset(Font.WritingMode, Baseline, int)}.
- * @param baselineType Same as for
- * {@link #baselineOffset(Font.WritingMode, Baseline, int)}.
- * @param fontSize Same as for
- * {@link #baselineOffset(Font.WritingMode, Baseline, int)}.
- * @return The estimated value of the baseline.
- */
- public int estimateBaseline(final Font.WritingMode writingMode,
- final Font.Baseline baselineType, final int fontSize) {
- switch(baselineType) {
- case ALPHABETIC: {
- return fontSize + this.getDescender(fontSize);
- }
- case MATH: {
- /* For now, estimate this as the middle. */
- return fontSize / 2;
- }
- case HANGING: {
- return Math.round(fontSize
- * FOrayFont.DEFAULT_HANGING_BASELINE_POSITION);
- }
- case IDEO_BOTTOM_LEFT: {
- /* TODO: This needs to comply with the Note under "text-after-edge"
- * at Section 7.14 of XSL-FO 1.1. */
- return fontSize;
- }
- case IDEO_TOP_RIGHT: {
- /* TODO: This needs to comply with the Note under "text-before-edge"
- * at Section 7.14 of XSL-FO 1.1. */
- return 0;
- }
- case ICF_BOTTOM_LEFT: {
- return fontSize;
- }
- case ICF_TOP_RIGHT: {
- return - this.getAscender(fontSize);
- }
- }
- return 0;
- }
-
- /**
- * {@inheritDoc}
- */
- public Baseline baseline(final String script) {
- /* TODO: Fix this. */
- return Baseline.ALPHABETIC;
- }
-
- /**
- * Returns the estimate of the appropriate underline size, in millipoints.
- * @param fontSize The font size for which the underline size should be computed.
- * @return The estimated underline size.
- */
- public int getEstimatedUnderlineSize(final int fontSize) {
- /* Until we learn better, make this the same size as the strikeout. */
- return strikeoutSize(fontSize);
- }
-
- /**
- * Returns the estimate of the appropriate underline position, in millipoints.
- * @param fontSize The font size for which the underline position should be computed.
- * @return The estimated underline position.
- */
- public int getEstimatedUnderlinePosition(final int fontSize) {
- final int estimate = - Math.round(fontSize * FOrayFont.DEFAULT_UNDERLINE_POSITION);
- return estimate;
- }
-
- /**
- * Returns the estimate of the appropriate overline thickness, in millipoints.
- * @param fontSize The font size for which the overline thickness should be computed.
- * @return The estimated overline thickness.
- */
- public int getEstimatedOverlineSize(final int fontSize) {
- /* Until we learn better, make this the same size as the strikeout. */
- return strikeoutSize(fontSize);
- }
-
- /**
- * Returns the estimate of the appropriate overline position, in millipoints.
- * @param fontSize The font size for which the overline position should be computed.
- * @return The estimated overline position.
- */
- public int getEstimatedOverlinePosition(final int fontSize) {
- final int estimate = Math.round(getAscender(fontSize)
- + (fontSize * FOrayFont.DEFAULT_OVERLINE_POSITION));
- return estimate;
- }
-
- /**
- * Returns the estimate of the appropriate strikeout size, in millipoints.
- * @param fontSize The font size for which the strikeout size should be computed.
- * @return The estimated strikeout size.
- */
- protected int getEstimatedStrikeoutSize(final int fontSize) {
- final int estimate = Math.round(fontSize * FOrayFont.DEFAULT_STRIKEOUT_SIZE);
- return estimate;
- }
-
- /**
- * Returns the estimate of the appropriate strikeout position, in millipoints.
- * @param fontSize The font size for which the strikeout position should be computed.
- * @return The estimated strikeout position.
- */
- protected int getEstimatedStrikeoutPosition(final int fontSize) {
- final int estimate = Math.round(getAscender(fontSize)
- * FOrayFont.DEFAULT_STRIKEOUT_POSITION);
- return estimate;
- }
-
- /**
- * {@inheritDoc}
- */
- public int subscriptShift(final int fontSize) {
- /* TODO: Where possible, replace this heuristic with data from the
- * font itself. */
- final int ascender = getAscender(fontSize);
- final int shift = Math.round(ascender * FOrayFont.SUBSCRIPT_SHIFT_FACTOR);
- return shift;
- }
-
- /**
- * {@inheritDoc}
- */
- public int superscriptShift(final int fontSize) {
- /* TODO: Where possible, replace this heuristic with data from the
- * font itself. */
- final int ascender = getAscender(fontSize);
- final int shift = Math.round(ascender * -1 * FOrayFont.SUPERSCRIPT_SHIFT_FACTOR);
- return shift;
- }
-
- /**
- * Returns the units per text-space unit that is used in this font for internal font
- * measurements.
- * For PostScript Type 1 fonts, this is 1000.
- * For TrueType fonts, it is usually 2048, but can be specified in the font itself.
- * @return The units per text-space unit used by this font.
- */
- public abstract int getUnitsPerTextSpaceUnit();
-
-}
Deleted: trunk/foray/foray-font/src/java/org/foray/font/FOrayFontConsumer.java
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/FOrayFontConsumer.java 2008-03-19 18:14:02 UTC (rev 10449)
+++ trunk/foray/foray-font/src/java/org/foray/font/FOrayFontConsumer.java 2008-03-19 18:58:35 UTC (rev 10450)
@@ -1,651 +0,0 @@
-/*
- * Copyright 2005 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font;
-
-import org.foray.font.format.Panose;
-
-import org.axsl.font.Font;
-import org.axsl.font.FontConsumer;
-import org.axsl.font.FontException;
-import org.axsl.font.FontUse;
-import org.axsl.ps.Encoding;
-
-import org.apache.commons.logging.Log;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * An implementation of the aXSL {@link FontConsumer} interface.
- * Instances are obtained by using the FOrayFontConsumer constructor(s).
- * FOrayFontConsumer instances can then be used to obtain implementations of
- * FontUse and Font which provide direct services to the client application.
- */
-public class FOrayFontConsumer implements FontConsumer {
-
- /**
- * Constant indicating that only a font's internal encoding should be
- * used during the font selection process.
- */
- public static final byte ENCODING_INTERNAL_ONLY = 1;
-
- /**
- * Constant indicating that only the encoding specified in the
- * {@link RegisteredFontDesc} (from the font-configuration) should be used
- * during the font selection process.
- */
- public static final byte ENCODING_SPECIFIED_ONLY = 2;
-
- /**
- * Constant indicating that the font selection process is free to use any
- * encoding that it can, including creating new ones, to make its full
- * complement of glyphs available during the font selection process.
- */
- public static final byte ENCODING_ANY = 3;
-
- /** Array of possible encoding latitude options. */
- private static final byte[] VALID_ENCODING_LATITUDES = {
- FOrayFontConsumer.ENCODING_INTERNAL_ONLY,
- FOrayFontConsumer.ENCODING_SPECIFIED_ONLY,
- FOrayFontConsumer.ENCODING_ANY
- };
-
- /** The server that should be used to by this FontConsumer. */
- private FOrayFontServer server;
-
- /**
- * The logger that should be used by this FontConsumer.
- * If null, the server's logger will be used.
- */
- private Log logger;
-
- /** Set to true if the FontConsumer can use free-standing fonts. */
- private boolean usesFreeStandingFonts;
-
- /** Set to true if the FontConsumer can use system fonts. */
- private boolean usesSystemFonts;
-
- /**
- * Set to true if FreeStandingFonts should be selected where possible,
- * false if SystemFont should be selected where possible.
- * In cases where usesFreeStandingFonts and usesSystemFonts are both set to
- * true, this breaks the tie.
- */
- private boolean prefersFreeStandingFonts;
-
- /**
- * Collection of fonts used by this FontConsumer.
- * The key is the Font instance, and the value is the related ConsumerFont
- * instance.
- */
- private Map<FOrayFont, FOrayConsumerFont> usedFonts
- = new HashMap<FOrayFont, FOrayConsumerFont>();
-
- /** The encoding latitude for this consumer. */
- private byte encodingLatitude = FOrayFontConsumer.ENCODING_ANY;
-
- /** The FontSelection instance to be used for font-selection-strategy =
- * "character-by-character". */
- private FontSelector fontSelectorCBC;
-
- /** The FontSelection instance to be used for font-selection-strategy =
- * "auto". */
- private FontSelector fontSelectorAuto;
-
- /** The font selector to be used by this consumer. */
- private String fontSelectorAutoType = "default";
-
- /**
- * Constructor.
- * @param server The FOrayFontServer instance serving this FontConsumer.
- */
- public FOrayFontConsumer(final FOrayFontServer server) {
- this.server = server;
- this.usesFreeStandingFonts = true;
- this.usesSystemFonts = true;
- this.prefersFreeStandingFonts = true;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setFontSources(final int[] fontSources) {
- if (fontSources == null
- || fontSources.length < 1) {
- return;
- }
- if (fontSources[0] == FONT_SOURCE_SYSTEM) {
- this.prefersFreeStandingFonts = false;
- } else {
- this.prefersFreeStandingFonts = true;
- }
- for (int i = 0; i < fontSources.length; i++) {
- if (fontSources[i] == FONT_SOURCE_FREE_STANDING) {
- this.usesFreeStandingFonts = true;
- break;
- }
- if (fontSources[i] == FONT_SOURCE_SYSTEM) {
- this.usesSystemFonts = true;
- break;
- }
- }
- }
-
- /**
- * Use this method to set a logger for this font consumer. This will
- * override the logger used by FOrayFontServer.
- * @param logger The new logger.
- */
- public void setLogger(final Log logger) {
- this.logger = logger;
- }
-
- /**
- * Provides the font system with the Log implementation which
- * should be used to log messages.
- * @return Commons Log implementation which should be used to log
- * messages for this FontConsumer.
- */
- public Log getLogger() {
- if (this.logger != null) {
- return this.logger;
- }
- return this.server.getLogger();
- }
-
- /**
- * Indicates whether this consumer can use free-standing fonts or not.
- * @return True iff this consumer can use free-standing fonts.
- */
- public boolean isUsingFreeStandingFonts() {
- return this.usesFreeStandingFonts;
- }
-
- /**
- * Indicates whether this consumer can use system fonts or not.
- * @return True iff this consumer can use system fonts.
- */
- public boolean isUsingSystemFonts() {
- return this.usesSystemFonts;
- }
-
- /**
- * Indicates whether free-standing fonts are preferred over system fonts.
- * @return True iff free-standing fonts are preferred over system fonts.
- */
- public boolean preferFreeStandingFonts() {
- return this.prefersFreeStandingFonts;
- }
-
- /**
- * Returns the parent font server instance.
- * @return The parent font server instance.
- */
- public FOrayFontServer getFontServer() {
- return this.server;
- }
-
- /**
- * Returns the font selector for a given strategy.
- * @param strategy The font-selection strategy for which a selector is
- * desired.
- * @return The appropriate font selector for the strategy.
- */
- private FontSelector getFontSelector(
- final Font.SelectionStrategy strategy) {
- switch (strategy) {
- case CHARACTER_BY_CHARACTER: {
- return this.getFontSelectorCBC();
- }
- case AUTO: {
- return this.getFontSelectorAuto();
- }
- }
- /* This indicates invalid input. */
- return this.getFontSelectorCBC();
- }
-
- /**
- * Returns the "auto" font selector type for this consumer.
- * @return The "auto" font selector type for this consumer.
- */
- public String getFontSelectorAutoType() {
- return this.fontSelectorAutoType;
- }
-
- /**
- * Sets the "auto" font selector type for this consumer.
- * @param newFontSelectorAutoType The new "auto" font selector type for this
- * consumer.
- */
- public void setFontSelectorAutoType(final String newFontSelectorAutoType) {
- if (this.fontSelectorAuto == null) {
- /* Fails silently if the "auto" FontSelector has already been
- * created. */
- this.fontSelectorAutoType = newFontSelectorAutoType;
- }
- }
-
- /**
- * Returns the character-by-character font selector for this consumer.
- * @return The character-by-character font selector for this consumer.
- */
- public FontSelector getFontSelectorCBC() {
- if (this.fontSelectorCBC == null) {
- this.fontSelectorCBC = new FontSelectorCBC(this);
- }
- return this.fontSelectorCBC;
- }
-
- /**
- * Returns the "auto" font selector for this consumer.
- * @return The "auto" font selector for this consumer.
- */
- public FontSelector getFontSelectorAuto() {
- if (this.fontSelectorAuto == null) {
- this.fontSelectorAuto = this.getFontServer().makeFontSelector(this);
- }
- return this.fontSelectorAuto;
- }
-
- /**
- * {@inheritDoc}
- */
- public org.axsl.font.FontUse selectFontXsl(
- final Font.SelectionStrategy selectionStrategy,
- final String [] familyList, final Font.Style style,
- final Font.Weight weight, final Font.Variant variant,
- final Font.Stretch stretch, final int size, final int codePoint)
- throws FontException {
- final FontSelector selector = getFontSelector(selectionStrategy);
- final RegisteredFontDesc fontDescSelected = selector.selectFont(
- familyList, style, weight, variant, stretch, size, codePoint);
- if (fontDescSelected == null) {
- final StringBuilder builder = new StringBuilder();
- for (int i = 0; i < familyList.length; i++) {
- builder.append(familyList[i] + ", ");
- }
- builder.append(style.toString() + ", ");
- builder.append(weight.toString() + ", ");
- builder.append(variant.toString() + ", ");
- builder.append(stretch.toString() + ", ");
- builder.append("U+" + Integer.toHexString(codePoint).toUpperCase());
- this.getLogger().warn("Suitable font not found for: "
- + builder.toString());
- }
- return getFontUse(fontDescSelected, codePoint);
- }
-
- /**
- * For a given RegisteredFontDesc instance known to be able to encode a
- * given Unicode codepoint, return a FontUse that will do exactly that.
- * @param fontDescSelected The font description which is known to be able to
- * encode <code>codepoint</code>.
- * @param codePoint The codepoint to be encoded.
- * @return The FontUse that should be used.
- * @throws FontException For errors in font selection.
- */
- private org.axsl.font.FontUse getFontUse(
- final RegisteredFontDesc fontDescSelected, final int codePoint)
- throws FontException {
- FOrayFont fontSelected = null;
- if (fontDescSelected != null) {
- fontSelected = whichUse(fontDescSelected,
- codePoint);
- }
- if (fontSelected == null) {
- /* None of the requested font-family items can provide a suitable
- * font. */
- final FOrayFontUse fontUse = getDefaultFontUse();
- if (fontUse == null) {
- throw new FontException("Unable to provide even a default "
- + "font.");
- }
- return fontUse;
- }
- if (fontSelected == null) {
- return null;
- }
- final FOrayConsumerFont consumerFont = registerFontUse(fontSelected);
- /* Selection of the actual FontUse is delegated to consumerFont. */
- final FOrayFontUse fontUse = consumerFont.selectFontUse(
- fontDescSelected, codePoint);
- return fontUse;
- }
-
- /**
- * Return a default font. We don't care what it can encode.
- * @return A default font.
- */
- protected FOrayFontUse getDefaultFontUse() {
- final RegisteredFontDesc fontDescSelected = selectDefaultFont();
- if (fontDescSelected == null) {
- return null;
- }
- FOrayFont fontSelected = null;
- if (isUsingFreeStandingFonts()) {
- fontSelected = fontDescSelected.getRegisteredFont()
- .getFreeStandingFont();
- } else {
- fontSelected = fontDescSelected.getRegisteredFont()
- .getSystemFont();
- }
- final FOrayConsumerFont consumerFont = registerFontUse(fontSelected);
- return consumerFont.getFontUse(fontDescSelected,
- fontSelected.getInternalEncoding());
- }
-
- /**
- * <p>Since {@link RegisteredFont} and {@link RegisteredFontDesc} instances
- * can encapsulate either a FreeStandingFont or a SystemFont, or both,
- * this method selects which one should be used, based on the FontConsumer
- * instances parameters.</p>
- *
- * <p>In cases where both a FreeStandingFont and a SystemFont are available,
- * and either can be selected, this method also breaks the tie, again using
- * a FontConsumer parameter.
- * Although each has access to the other's methods for things that it
- * does not natively know, there are still potential differences between
- * the two (especially font metrics), and an application needs to be able
- * to select which one it prefers.
- * @param rfd The RegisteredFontDesc instance which points to the usable
- * font.
- * @param codePoint The Unicode code point that should be tested to ensure
- * that it can be encoded.
- * @return The FontUse instance dictated by the parameters of consumer.
- */
- protected FOrayFont whichUse(final RegisteredFontDesc rfd,
- final int codePoint) {
- final RegisteredFont rf = rfd.getRegisteredFont();
-
- /* Avoid instantiating the non-preferred manifestation if it won't be
- * used anyway. */
- FreeStandingFont fsf = null;
- SystemFont sf = null;
-
- if (preferFreeStandingFonts()) {
- /* Consumer prefers FreeStandingFont. */
- fsf = eligibleFreeStandingFont(rfd, codePoint);
- if (fsf != null) {
- /* It is available. */
- return fsf;
- }
- return eligibleSystemFont(rf, codePoint);
- } else {
- /* Consumer prefers SystemFont. */
- sf = eligibleSystemFont(rf, codePoint);
- if (sf != null) {
- /* It is available. */
- return sf;
- }
- return eligibleFreeStandingFont(rfd, codePoint);
- }
- }
-
- /**
- * For a given registered font description, returns the free-standing font
- * for that description, if it is eligible for selection.
- * @param rfd The registered font description to be tested.
- * @param codePoint The Unicode code point that must be encodable for the
- * tested font to be eligible.
- * @return The {@link FreeStandingFont} instance, if it exists and is
- * eligible, or null otherwise.
- */
- private FreeStandingFont eligibleFreeStandingFont(
- final RegisteredFontDesc rfd, final int codePoint) {
- if (! isUsingFreeStandingFonts()) {
- return null;
- }
- final FreeStandingFont fsf =
- rfd.getRegisteredFont().getFreeStandingFont();
- if (fsf == null) {
- return null;
- }
- final FOrayConsumerFont consumerFont =...
[truncated message content] |