From da245e469b3efb795832430d79e971b161fbe53a Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 31 Oct 2007 16:39:04 +0000 Subject: [PATCH] Some fonts have spaces in their names (ex. "Arial Unicode MS"). This change modifies font auto-detection so both "ArialUnicodeMS" (as before) and "Arial Unicode MS" (new) are registered for a font. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@590736 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fonts/CustomFont.java | 12 ++++++++++- .../fop/fonts/autodetect/FontInfoFinder.java | 20 +++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java index 4ad24b08b..916597746 100644 --- a/src/java/org/apache/fop/fonts/CustomFont.java +++ b/src/java/org/apache/fop/fonts/CustomFont.java @@ -21,6 +21,7 @@ package org.apache.fop.fonts; import java.io.IOException; import java.util.Map; + import javax.xml.transform.Source; /** @@ -60,6 +61,16 @@ public abstract class CustomFont extends Typeface } /** + * Return the font family. + * @return the font family + */ + public String getFontFamily() { + return fontName; + } + + /** + * Returns the font family name stripped of whitespace. + * @return the stripped font family * @see FontUtil#stripWhiteSpace(String) */ public String getStrippedFontName() { @@ -243,7 +254,6 @@ public abstract class CustomFont extends Typeface } } - /* ---- MutableFont interface ---- */ /** diff --git a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java index 0f7cf0de9..bb7e00505 100644 --- a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java +++ b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java @@ -22,6 +22,7 @@ package org.apache.fop.fonts.autodetect; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; +import java.util.Collection; import java.net.URL; import java.util.List; @@ -51,17 +52,17 @@ public class FontInfoFinder { private static final String[] BOLD_WORDS = {"bold", "black", "heavy", "ultra", "super"}; /** - * Attempts to determine FontTriplet from a given CustomFont. + * Attempts to determine FontTriplets from a given CustomFont. * It seems to be fairly accurate but will probably require some tweaking over time * * @param customFont CustomFont - * @return newly created font triplet + * @param triplet Collection that will take the generated triplets */ - private FontTriplet tripletFromFont(CustomFont customFont) { + private void generateTripletsFromFont(CustomFont customFont, Collection triplets) { // default style and weight triplet vales (fallback) - String name = customFont.getStrippedFontName(); + String strippedName = customFont.getStrippedFontName(); String subName = customFont.getFontSubName(); - String searchName = name.toLowerCase(); + String searchName = strippedName.toLowerCase(); if (subName != null) { searchName += subName.toLowerCase(); } @@ -87,7 +88,11 @@ public class FontInfoFinder { break; } } - return new FontTriplet(name, style, weight); + triplets.add(new FontTriplet(strippedName, style, weight)); + String familyName = customFont.getFontFamily(); + if (!strippedName.equals(familyName)) { + triplets.add(new FontTriplet(familyName, style, weight)); + } } /** @@ -99,9 +104,8 @@ public class FontInfoFinder { */ private EmbedFontInfo fontInfoFromCustomFont( URL fontUrl, CustomFont customFont, FontCache fontCache) { - FontTriplet fontTriplet = tripletFromFont(customFont); List fontTripletList = new java.util.ArrayList(); - fontTripletList.add(fontTriplet); + generateTripletsFromFont(customFont, fontTripletList); String embedUrl; embedUrl = fontUrl.toExternalForm(); EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(), -- 2.39.5