Some TrueType fonts have multiple font family names which we haven't extracted so far. All these names are now exposed as a Set of Strings. An example: Futura Book BT has two font families: Futura (Mac platform) and Futura Bk BT (Windows platform). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@593245 13f79535-47bb-0310-9956-ffa450edef68tags/fop-0_95beta
@@ -39,6 +39,7 @@ package org.apache.fop.fonts.base14; | |||
<xsl:if test="count(kerning) > 0"> | |||
import java.util.Map; | |||
</xsl:if> | |||
import java.util.Set; | |||
import org.apache.fop.fonts.FontType; | |||
import org.apache.fop.fonts.Typeface; | |||
import org.apache.fop.fonts.CodePointMapping; | |||
@@ -46,7 +47,7 @@ import org.apache.fop.fonts.CodePointMapping; | |||
public class <xsl:value-of select="class-name"/> extends Typeface { | |||
private final static String fontName = "<xsl:value-of select="font-name"/>"; | |||
private final static String fullName = "<xsl:value-of select="full-name"/>"; | |||
private final static String familyName = "<xsl:value-of select="family-name"/>"; | |||
private final static Set familyNames; | |||
private final static String encoding = <xsl:choose><xsl:when test="$encoding != $native-encoding">"<xsl:value-of select="$encoding"/>"</xsl:when><xsl:otherwise>null</xsl:otherwise></xsl:choose>; | |||
private final static int capHeight = <xsl:value-of select="cap-height"/>; | |||
private final static int xHeight = <xsl:value-of select="x-height"/>; | |||
@@ -72,6 +73,8 @@ public class <xsl:value-of select="class-name"/> extends Typeface { | |||
Map pairs; | |||
<xsl:apply-templates select="kerning"/> | |||
</xsl:if> | |||
familyNames = new java.util.HashSet(); | |||
familyNames.add("<xsl:value-of select="family-name"/>"); | |||
} | |||
public <xsl:value-of select="class-name"/>() { | |||
@@ -98,8 +101,8 @@ public class <xsl:value-of select="class-name"/> extends Typeface { | |||
return fullName; | |||
} | |||
public String getFamilyName() { | |||
return familyName; | |||
public Set getFamilyNames() { | |||
return familyNames; | |||
} | |||
public FontType getFontType() { |
@@ -20,7 +20,9 @@ | |||
package org.apache.fop.fonts; | |||
import java.io.IOException; | |||
import java.util.Collections; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import javax.xml.transform.Source; | |||
@@ -32,7 +34,7 @@ public abstract class CustomFont extends Typeface | |||
private String fontName = null; | |||
private String fullName = null; | |||
private String familyName = null; | |||
private Set familyNames = null; //Set<String> | |||
private String fontSubName = null; | |||
private String embedFileName = null; | |||
private String embedResourceName = null; | |||
@@ -71,11 +73,11 @@ public abstract class CustomFont extends Typeface | |||
} | |||
/** | |||
* Return the font family. | |||
* @return the font family | |||
* Returns the font family names. | |||
* @return the font family names (a Set of Strings) | |||
*/ | |||
public String getFamilyName() { | |||
return familyName; | |||
public Set getFamilyNames() { | |||
return Collections.unmodifiableSet(this.familyNames); | |||
} | |||
/** | |||
@@ -280,8 +282,8 @@ public abstract class CustomFont extends Typeface | |||
} | |||
/** {@inheritDoc} */ | |||
public void setFamilyName(String name) { | |||
this.familyName = name; | |||
public void setFamilyNames(Set names) { | |||
this.familyNames = new java.util.HashSet(names); | |||
} | |||
/** |
@@ -20,6 +20,7 @@ | |||
package org.apache.fop.fonts; | |||
import java.util.Map; | |||
import java.util.Set; | |||
/** | |||
@@ -40,10 +41,10 @@ public interface FontMetrics { | |||
String getFullName(); | |||
/** | |||
* Returns the font's family name (Example: "Helvetica"). | |||
* @return the font's family name | |||
* Returns the font's family names as a Set of Strings (Example: "Helvetica"). | |||
* @return the font's family names (a Set of Strings) | |||
*/ | |||
String getFamilyName(); | |||
Set getFamilyNames(); | |||
/** | |||
* Returns the font name for font embedding (may include a prefix, Example: "1E28bcArialMT"). |
@@ -23,6 +23,7 @@ package org.apache.fop.fonts; | |||
import java.io.IOException; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import javax.xml.parsers.SAXParserFactory; | |||
@@ -229,7 +230,9 @@ public class FontReader extends DefaultHandler { | |||
} else if ("full-name".equals(localName)) { | |||
multiFont.setFullName(content); | |||
} else if ("family-name".equals(localName)) { | |||
multiFont.setFamilyName(content); | |||
Set s = new java.util.HashSet(); | |||
s.add(content); | |||
multiFont.setFamilyNames(s); | |||
} else if ("ttc-name".equals(localName) && isCID) { | |||
multiFont.setTTCName(content); | |||
} else if ("encoding".equals(localName)) { |
@@ -22,6 +22,7 @@ import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.net.URL; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.stream.StreamSource; | |||
@@ -208,9 +209,9 @@ public class LazyFont extends Typeface implements FontDescriptor { | |||
} | |||
/** {@inheritDoc} */ | |||
public String getFamilyName() { | |||
public Set getFamilyNames() { | |||
load(true); | |||
return realFont.getFamilyName(); | |||
return realFont.getFamilyNames(); | |||
} | |||
/** |
@@ -20,6 +20,7 @@ | |||
package org.apache.fop.fonts; | |||
import java.util.Map; | |||
import java.util.Set; | |||
/** | |||
@@ -41,10 +42,10 @@ public interface MutableFont { | |||
void setFullName(String name); | |||
/** | |||
* Sets the font's family name (Example: "Helvetica"). | |||
* @param name the font's family name | |||
* Sets the font's family names (Example: "Helvetica"). | |||
* @param name the font's family names (a Set of Strings) | |||
*/ | |||
void setFamilyName(String name); | |||
void setFamilyNames(Set names); | |||
/** | |||
* Sets the path to the embeddable font file. |
@@ -22,6 +22,7 @@ package org.apache.fop.fonts.apps; | |||
import java.io.IOException; | |||
import java.util.Iterator; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import javax.xml.parsers.DocumentBuilderFactory; | |||
@@ -209,7 +210,7 @@ public class TTFReader extends AbstractFontReader { | |||
if (!supported) { | |||
return null; | |||
} | |||
log.info("Font Family: " + ttfFile.getFamilyName()); | |||
log.info("Font Family: " + ttfFile.getFamilyNames()); | |||
if (ttfFile.isCFF()) { | |||
throw new UnsupportedOperationException( | |||
"OpenType fonts with CFF data are not supported, yet"); | |||
@@ -271,10 +272,12 @@ public class TTFReader extends AbstractFontReader { | |||
root.appendChild(el); | |||
el.appendChild(doc.createTextNode(ttf.getFullName())); | |||
} | |||
if (ttf.getFamilyName() != null) { | |||
Set familyNames = ttf.getFamilyNames(); | |||
if (familyNames.size() > 0) { | |||
String familyName = (String)familyNames.iterator().next(); | |||
el = doc.createElement("family-name"); | |||
root.appendChild(el); | |||
el.appendChild(doc.createTextNode(ttf.getFamilyName())); | |||
el.appendChild(doc.createTextNode(familyName)); | |||
} | |||
el = doc.createElement("embed"); |
@@ -22,7 +22,9 @@ package org.apache.fop.fonts.autodetect; | |||
import java.io.IOException; | |||
import java.net.URL; | |||
import java.util.Collection; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Set; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
@@ -52,6 +54,13 @@ public class FontInfoFinder { | |||
* @param triplet Collection that will take the generated triplets | |||
*/ | |||
private void generateTripletsFromFont(CustomFont customFont, Collection triplets) { | |||
if (log.isTraceEnabled()) { | |||
log.trace("Font: " + customFont.getFullName() | |||
+ ", family: " + customFont.getFamilyNames() | |||
+ ", PS: " + customFont.getFontName() | |||
+ ", EmbedName: " + customFont.getEmbedFontName()); | |||
} | |||
// default style and weight triplet vales (fallback) | |||
String strippedName = customFont.getStrippedFontName(); | |||
String subName = customFont.getFontSubName(); | |||
@@ -70,9 +79,13 @@ public class FontInfoFinder { | |||
if (!fullName.equals(strippedName)) { | |||
triplets.add(new FontTriplet(strippedName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)); | |||
} | |||
String familyName = customFont.getFamilyName(); | |||
if (!fullName.equals(familyName)) { | |||
triplets.add(new FontTriplet(familyName, style, weight)); | |||
Set familyNames = customFont.getFamilyNames(); | |||
Iterator iter = familyNames.iterator(); | |||
while (iter.hasNext()) { | |||
String familyName = (String)iter.next(); | |||
if (!fullName.equals(familyName)) { | |||
triplets.add(new FontTriplet(familyName, style, weight)); | |||
} | |||
} | |||
} | |||
@@ -23,6 +23,7 @@ import java.io.IOException; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
@@ -77,7 +78,7 @@ public class TTFFile { | |||
private String postScriptName = ""; | |||
private String fullName = ""; | |||
private String notice = ""; | |||
private String familyName = ""; | |||
private Set familyNames = new java.util.HashSet(); //Set<String> | |||
private String subFamilyName = ""; | |||
private long italicAngle = 0; | |||
@@ -537,35 +538,20 @@ public class TTFFile { | |||
cmaps.add(tce); | |||
} | |||
/** | |||
* Returns the Windows name of the font. | |||
* @return String The Windows name | |||
*/ | |||
public String getWindowsName() { | |||
return familyName + "," + subFamilyName; | |||
} | |||
/** | |||
* Returns the PostScript name of the font. | |||
* @return String The PostScript name | |||
*/ | |||
public String getPostScriptName() { | |||
return postScriptName; | |||
/* | |||
if ("Regular".equals(subFamilyName) || "Roman".equals(subFamilyName)) { | |||
return familyName; | |||
} else { | |||
return familyName + "," + subFamilyName; | |||
} | |||
*/ | |||
} | |||
/** | |||
* Returns the font family name of the font. | |||
* @return String The family name | |||
* Returns the font family names of the font. | |||
* @return Set The family names (a Set of Strings) | |||
*/ | |||
public String getFamilyName() { | |||
return familyName; | |||
public Set getFamilyNames() { | |||
return familyNames; | |||
} | |||
/** | |||
@@ -1117,8 +1103,7 @@ public class TTFFile { | |||
int l = in.readTTFUShort(); | |||
if (((platformID == 1 || platformID == 3) | |||
&& (encodingID == 0 || encodingID == 1)) | |||
&& (k == 1 || k == 2 || k == 0 || k == 4 || k == 6)) { | |||
&& (encodingID == 0 || encodingID == 1))) { | |||
in.seekSet(j + in.readTTFUShort()); | |||
String txt = in.readTTFString(l); | |||
@@ -1130,26 +1115,30 @@ public class TTFFile { | |||
} | |||
switch (k) { | |||
case 0: | |||
notice = txt; | |||
if (notice.length() == 0) { | |||
notice = txt; | |||
} | |||
break; | |||
case 1: | |||
familyName = txt; | |||
case 1: //Font Family Name | |||
case 16: //Preferred Family | |||
familyNames.add(txt); | |||
break; | |||
case 2: | |||
subFamilyName = txt; | |||
if (subFamilyName.length() == 0) { | |||
subFamilyName = txt; | |||
} | |||
break; | |||
case 4: | |||
fullName = txt; | |||
if (fullName.length() == 0) { | |||
fullName = txt; | |||
} | |||
break; | |||
case 6: | |||
postScriptName = txt; | |||
if (postScriptName.length() == 0) { | |||
postScriptName = txt; | |||
} | |||
break; | |||
} | |||
if (!notice.equals("") | |||
&& !fullName.equals("") | |||
&& !postScriptName.equals("") | |||
&& !familyName.equals("") | |||
&& !subFamilyName.equals("")) { | |||
default: | |||
break; | |||
} | |||
} | |||
@@ -1452,7 +1441,7 @@ public class TTFFile { | |||
// Reset names | |||
notice = ""; | |||
fullName = ""; | |||
familyName = ""; | |||
familyNames.clear(); | |||
postScriptName = ""; | |||
subFamilyName = ""; | |||
} | |||
@@ -1485,7 +1474,7 @@ public class TTFFile { | |||
public void printStuff() { | |||
System.out.println("Font name: " + postScriptName); | |||
System.out.println("Full name: " + fullName); | |||
System.out.println("Family name: " + familyName); | |||
System.out.println("Family name: " + familyNames); | |||
System.out.println("Subfamily name: " + subFamilyName); | |||
System.out.println("Notice: " + notice); | |||
System.out.println("xHeight: " + (int)convertTTFUnit2PDFUnit(xHeight)); |
@@ -68,7 +68,7 @@ public class TTFFontLoader extends FontLoader { | |||
returnFont.setFontName(ttf.getPostScriptName()); | |||
returnFont.setFullName(ttf.getFullName()); | |||
returnFont.setFamilyName(ttf.getFamilyName()); | |||
returnFont.setFamilyNames(ttf.getFamilyNames()); | |||
returnFont.setFontSubFamilyName(ttf.getSubFamilyName()); | |||
//multiFont.setTTCName(ttcName) | |||
returnFont.setCapHeight(ttf.getCapHeight()); |
@@ -21,6 +21,7 @@ package org.apache.fop.fonts.type1; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.Set; | |||
import org.apache.fop.fonts.FontLoader; | |||
import org.apache.fop.fonts.FontResolver; | |||
@@ -63,7 +64,9 @@ public class Type1FontLoader extends FontLoader { | |||
fullName = fullName.replace('-', ' '); //Hack! Try to emulate full name | |||
returnFont.setFullName(fullName); //should be afm.getFullName()!! | |||
//TODO not accurate: we need FullName from the AFM file but we don't have an AFM parser | |||
returnFont.setFamilyName(pfm.getWindowsName()); //should be afm.getFamilyName()!! | |||
Set names = new java.util.HashSet(); | |||
names.add(pfm.getWindowsName()); //should be afm.getFamilyName()!! | |||
returnFont.setFamilyNames(names); | |||
returnFont.setCapHeight(pfm.getCapHeight()); | |||
returnFont.setXHeight(pfm.getXHeight()); | |||
returnFont.setAscender(pfm.getLowerCaseAscent()); |
@@ -19,6 +19,7 @@ | |||
package org.apache.fop.render.afp.fonts; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import org.apache.fop.fonts.FontType; | |||
import org.apache.fop.fonts.Typeface; | |||
@@ -59,8 +60,10 @@ public abstract class AFPFont extends Typeface { | |||
} | |||
/** {@inheritDoc} */ | |||
public String getFamilyName() { | |||
return getFamilyName(); | |||
public Set getFamilyNames() { | |||
Set s = new java.util.HashSet(); | |||
s.add(this.name); | |||
return s; | |||
} | |||
/** |
@@ -22,6 +22,7 @@ package org.apache.fop.render.java2d; | |||
// Java | |||
import java.awt.Graphics2D; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import org.apache.fop.fonts.FontMetrics; | |||
import org.apache.fop.fonts.FontType; | |||
@@ -87,8 +88,10 @@ public class FontMetricsMapper extends Typeface implements FontMetrics { | |||
} | |||
/** {@inheritDoc} */ | |||
public String getFamilyName() { | |||
return getFontName(); | |||
public Set getFamilyNames() { | |||
Set s = new java.util.HashSet(); | |||
s.add(this.family); | |||
return s; | |||
} | |||
/** |
@@ -222,6 +222,15 @@ public class FontSetup { | |||
continue; //skip | |||
} | |||
if (log.isTraceEnabled()) { | |||
log.trace("AWT Font: " + f.getFontName() | |||
+ ", family: " + f.getFamily() | |||
+ ", PS: " + f.getPSName() | |||
+ ", Name: " + f.getName() | |||
+ ", Angle: " + f.getItalicAngle() | |||
+ ", Style: " + f.getStyle()); | |||
} | |||
String searchName = FontUtil.stripWhiteSpace(f.getFontName()).toLowerCase(); | |||
String guessedStyle = FontUtil.guessStyle(searchName); | |||
int guessedWeight = FontUtil.guessWeight(searchName); |