git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1638047 13f79535-47bb-0310-9956-ffa450edef68pull/28/head
</xsd:sequence> | </xsd:sequence> | ||||
<xsd:attribute name="metrics-url" type="xsd:anyURI" use="optional"/> | <xsd:attribute name="metrics-url" type="xsd:anyURI" use="optional"/> | ||||
<xsd:attribute name="embed-url" type="xsd:anyURI" use="optional"/> | <xsd:attribute name="embed-url" type="xsd:anyURI" use="optional"/> | ||||
<xsd:attribute name="embed-url-afm" type="xsd:anyURI" use="optional"/> | |||||
<xsd:attribute name="embed-url-pfm" type="xsd:anyURI" use="optional"/> | |||||
<xsd:attribute name="sub-font" type="xsd:string" use="optional"/> | <xsd:attribute name="sub-font" type="xsd:string" use="optional"/> | ||||
<xsd:attribute name="embedding-mode" use="optional"> | <xsd:attribute name="embedding-mode" use="optional"> | ||||
<xsd:simpleType> | <xsd:simpleType> |
strict); | strict); | ||||
continue; | continue; | ||||
} | } | ||||
Font font = new Font(fontCfg.getAttribute("metrics-url", null), embed, fontCfg.getAttribute( | |||||
"embed-url-afm", null), fontCfg.getAttribute("embed-url-pfm", null), | |||||
fontCfg.getAttribute("sub-font", null), | |||||
fontCfg.getAttributeAsBoolean("kerning", true), fontCfg.getAttributeAsBoolean( | |||||
"advanced", true), fontCfg.getAttribute("encoding-mode", | |||||
EncodingMode.AUTO.getName()), fontCfg.getAttribute("embedding-mode", | |||||
EncodingMode.AUTO.getName())); | |||||
Font font = new Font(fontCfg.getAttribute("metrics-url", null), embed, | |||||
fontCfg.getAttribute("sub-font", null), fontCfg.getAttributeAsBoolean( | |||||
"kerning", true), fontCfg.getAttributeAsBoolean("advanced", true), | |||||
fontCfg.getAttribute("encoding-mode", EncodingMode.AUTO.getName()), | |||||
fontCfg.getAttribute("embedding-mode", EncodingMode.AUTO.getName())); | |||||
instance.fonts.add(font); | instance.fonts.add(font); | ||||
boolean hasTriplets = false; | boolean hasTriplets = false; | ||||
for (Configuration tripletCfg : fontCfg.getChildren("font-triplet")) { | for (Configuration tripletCfg : fontCfg.getChildren("font-triplet")) { | ||||
private final String embedUri; | private final String embedUri; | ||||
private String afm; | |||||
private String pfm; | |||||
private final String subFont; | private final String subFont; | ||||
private final boolean kerning; | private final boolean kerning; | ||||
return Collections.unmodifiableList(tripletList); | return Collections.unmodifiableList(tripletList); | ||||
} | } | ||||
private Font(String metrics, String embed, String afm, String pfm, String subFont, boolean kerning, | |||||
private Font(String metrics, String embed, String subFont, boolean kerning, | |||||
boolean advanced, String encodingMode, String embeddingMode) { | boolean advanced, String encodingMode, String embeddingMode) { | ||||
this.metrics = metrics; | this.metrics = metrics; | ||||
this.embedUri = embed; | this.embedUri = embed; | ||||
this.afm = afm; | |||||
this.pfm = pfm; | |||||
this.subFont = subFont; | this.subFont = subFont; | ||||
this.kerning = kerning; | this.kerning = kerning; | ||||
this.advanced = advanced; | this.advanced = advanced; | ||||
public String getEmbeddingMode() { | public String getEmbeddingMode() { | ||||
return embeddingMode; | return embeddingMode; | ||||
} | } | ||||
public String getAfm() { | |||||
return afm; | |||||
} | |||||
public String getPfm() { | |||||
return pfm; | |||||
} | |||||
} | } | ||||
} | } |
throws FOPException, URISyntaxException { | throws FOPException, URISyntaxException { | ||||
String embed = font.getEmbedURI(); | String embed = font.getEmbedURI(); | ||||
String metrics = font.getMetrics(); | String metrics = font.getMetrics(); | ||||
String afm = font.getAfm(); | |||||
String pfm = font.getPfm(); | |||||
URI embedUri = InternalResourceResolver.cleanURI(embed); | |||||
String subFont = font.getSubFont(); | |||||
URI metricsUri = metrics == null ? null : InternalResourceResolver.cleanURI(metrics); | URI metricsUri = metrics == null ? null : InternalResourceResolver.cleanURI(metrics); | ||||
URI afmUri = (afm == null) ? null : InternalResourceResolver.cleanURI(afm); | |||||
URI pfmUri = (pfm == null) ? null : InternalResourceResolver.cleanURI(pfm); | |||||
FontUris fontUris = (afmUri != null || pfmUri != null) ? new FontUris(embedUri, metricsUri, afmUri, | |||||
pfmUri) : new FontUris(embedUri, metricsUri); | |||||
URI embedUri = InternalResourceResolver.cleanURI(embed); | |||||
String subFont = font.getSubFont(); | |||||
List<FontTriplet> tripletList = font.getTripletList(); | List<FontTriplet> tripletList = font.getTripletList(); | ||||
// no font triplet info | // no font triplet info | ||||
} | } | ||||
EncodingMode encodingMode = EncodingMode.getValue(font.getEncodingMode()); | EncodingMode encodingMode = EncodingMode.getValue(font.getEncodingMode()); | ||||
EmbeddingMode embeddingMode = EmbeddingMode.getValue(font.getEmbeddingMode()); | EmbeddingMode embeddingMode = EmbeddingMode.getValue(font.getEmbeddingMode()); | ||||
EmbedFontInfo embedFontInfo = new EmbedFontInfo(fontUris, font.isKerning(), font.isAdvanced(), | |||||
tripletList, subFont, encodingMode, embeddingMode); | |||||
EmbedFontInfo embedFontInfo = new EmbedFontInfo(metricsUri, font.isKerning(), | |||||
font.isAdvanced(), tripletList, embedUri, subFont, encodingMode, embeddingMode); | |||||
if (fontCache != null) { | if (fontCache != null) { | ||||
if (!fontCache.containsFont(embedFontInfo)) { | if (!fontCache.containsFont(embedFontInfo)) { | ||||
fontCache.addFont(embedFontInfo, resourceResolver); | fontCache.addFont(embedFontInfo, resourceResolver); |
/** Serialization Version UID */ | /** Serialization Version UID */ | ||||
private static final long serialVersionUID = 8755432068669997369L; | private static final long serialVersionUID = 8755432068669997369L; | ||||
protected final URI metricsURI; | |||||
protected final URI embedURI; | |||||
/** false, to disable kerning */ | /** false, to disable kerning */ | ||||
protected final boolean kerning; | protected final boolean kerning; | ||||
/** false, to disable advanced typographic features */ | /** false, to disable advanced typographic features */ | ||||
private transient boolean embedded = true; | private transient boolean embedded = true; | ||||
private FontUris fontUris; | |||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* @param metricsURI the URI of the XML resource containing font metrics | * @param metricsURI the URI of the XML resource containing font metrics | ||||
* @param subFontName the sub-fontname used for TrueType Collections (null otherwise) | * @param subFontName the sub-fontname used for TrueType Collections (null otherwise) | ||||
* @param encodingMode the encoding mode to use for this font | * @param encodingMode the encoding mode to use for this font | ||||
*/ | */ | ||||
public EmbedFontInfo(FontUris fontUris, boolean kerning, boolean advanced, | |||||
List<FontTriplet> fontTriplets, String subFontName, | |||||
public EmbedFontInfo(URI metricsURI, boolean kerning, boolean advanced, | |||||
List<FontTriplet> fontTriplets, URI embedURI, String subFontName, | |||||
EncodingMode encodingMode, EmbeddingMode embeddingMode) { | EncodingMode encodingMode, EmbeddingMode embeddingMode) { | ||||
this.metricsURI = metricsURI; | |||||
this.embedURI = embedURI; | |||||
this.kerning = kerning; | this.kerning = kerning; | ||||
this.advanced = advanced; | this.advanced = advanced; | ||||
this.fontTriplets = fontTriplets; | this.fontTriplets = fontTriplets; | ||||
this.subFontName = subFontName; | this.subFontName = subFontName; | ||||
this.encodingMode = encodingMode; | this.encodingMode = encodingMode; | ||||
this.embeddingMode = embeddingMode; | this.embeddingMode = embeddingMode; | ||||
this.fontUris = fontUris; | |||||
} | |||||
/** | |||||
<<<<<<< HEAD | |||||
======= | |||||
* Main constructor | |||||
* @param metricsURI the URI of the XML resource containing font metrics | |||||
* @param kerning True if kerning should be enabled | |||||
* @param fontTriplets List of font triplets to associate with this font | |||||
* @param embedURI Path to the embeddable font file (may be null) | |||||
* @param subFontName the sub-fontname used for TrueType Collections (null otherwise) | |||||
*/ | |||||
public EmbedFontInfo(FontUris fontUris, boolean kerning, boolean advanced, | |||||
List<FontTriplet> fontTriplets, String subFontName) { | |||||
this(fontUris, kerning, advanced, fontTriplets, subFontName, EncodingMode.AUTO, | |||||
EmbeddingMode.AUTO); | |||||
} | } | ||||
/** | /** | ||||
>>>>>>> 9c3c942... added uris for afm and pfm font files | |||||
* Returns the URI of the metrics XML resource | * Returns the URI of the metrics XML resource | ||||
* | * | ||||
* @return the metrics file path | * @return the metrics file path | ||||
*/ | */ | ||||
public URI getMetricsURI() { | public URI getMetricsURI() { | ||||
return fontUris.getMetrics(); | |||||
return metricsURI; | |||||
} | } | ||||
/** | /** | ||||
* @return the font resource URI | * @return the font resource URI | ||||
*/ | */ | ||||
public URI getEmbedURI() { | public URI getEmbedURI() { | ||||
return fontUris.getEmbed(); | |||||
return embedURI; | |||||
} | } | ||||
/** | /** | ||||
* @return true if the font is embedded, false if it is referenced. | * @return true if the font is embedded, false if it is referenced. | ||||
*/ | */ | ||||
public boolean isEmbedded() { | public boolean isEmbedded() { | ||||
if (fontUris.getEmbed() == null) { | |||||
if (embedURI == null) { | |||||
return false; | return false; | ||||
} else { | } else { | ||||
return this.embedded; | return this.embedded; | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public String toString() { | public String toString() { | ||||
return "metrics-uri=" + fontUris.getMetrics() + ", embed-uri=" + fontUris.getEmbed() | |||||
return "metrics-uri=" + metricsURI + ", embed-uri=" + embedURI | |||||
+ ", kerning=" + kerning | + ", kerning=" + kerning | ||||
+ ", advanced=" + advanced | + ", advanced=" + advanced | ||||
+ ", enc-mode=" + encodingMode | + ", enc-mode=" + encodingMode | ||||
+ (isEmbedded() ? "" : ", NOT embedded"); | + (isEmbedded() ? "" : ", NOT embedded"); | ||||
} | } | ||||
public FontUris getFontUris() { | |||||
return fontUris; | |||||
} | |||||
} | } |
* @return the newly loaded font | * @return the newly loaded font | ||||
* @throws IOException In case of an I/O error | * @throws IOException In case of an I/O error | ||||
*/ | */ | ||||
public static CustomFont loadFont(FontUris fontUris, String subFontName, | |||||
public static CustomFont loadFont(URI fontFileURI, String subFontName, | |||||
boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode, | boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode, | ||||
boolean useKerning, boolean useAdvanced, InternalResourceResolver resourceResolver) throws IOException { | boolean useKerning, boolean useAdvanced, InternalResourceResolver resourceResolver) throws IOException { | ||||
boolean type1 = isType1(fontUris.getEmbed()); | |||||
boolean type1 = isType1(fontFileURI); | |||||
FontLoader loader; | FontLoader loader; | ||||
if (type1) { | if (type1) { | ||||
if (encodingMode == EncodingMode.CID) { | if (encodingMode == EncodingMode.CID) { | ||||
throw new IllegalArgumentException( | throw new IllegalArgumentException( | ||||
"CID encoding mode not supported for Type 1 fonts"); | "CID encoding mode not supported for Type 1 fonts"); | ||||
} | } | ||||
loader = new Type1FontLoader(fontUris, embedded, embeddingMode, useKerning, | |||||
loader = new Type1FontLoader(fontFileURI, embedded, embeddingMode, useKerning, | |||||
resourceResolver); | resourceResolver); | ||||
} else { | } else { | ||||
loader = new OFFontLoader(fontUris.getEmbed(), subFontName, embedded, embeddingMode, | |||||
loader = new OFFontLoader(fontFileURI, subFontName, embedded, embeddingMode, | |||||
encodingMode, useKerning, useAdvanced, resourceResolver); | encodingMode, useKerning, useAdvanced, resourceResolver); | ||||
} | } | ||||
return loader.getFont(); | return loader.getFont(); |
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||||
* contributor license agreements. See the NOTICE file distributed with | |||||
* this work for additional information regarding copyright ownership. | |||||
* The ASF licenses this file to You 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. | |||||
*/ | |||||
/* $Id$ */ | |||||
package org.apache.fop.fonts; | |||||
import java.io.Serializable; | |||||
import java.net.URI; | |||||
public class FontUris implements Serializable { | |||||
private static final long serialVersionUID = 8571060588775532701L; | |||||
private final URI embed; | |||||
private final URI metrics; | |||||
private final URI afm; | |||||
private final URI pfm; | |||||
public FontUris(URI embed, URI metrics, URI afm, URI pfm) { | |||||
this.embed = embed; | |||||
this.metrics = metrics; | |||||
this.afm = afm; | |||||
this.pfm = pfm; | |||||
} | |||||
public FontUris(URI embed, URI metrics) { | |||||
this.embed = embed; | |||||
this.metrics = metrics; | |||||
this.afm = null; | |||||
this.pfm = null; | |||||
} | |||||
public URI getEmbed() { | |||||
return embed; | |||||
} | |||||
public URI getMetrics() { | |||||
return metrics; | |||||
} | |||||
public URI getAfm() { | |||||
return afm; | |||||
} | |||||
public URI getPfm() { | |||||
return pfm; | |||||
} | |||||
} | |||||
private static Log log = LogFactory.getLog(LazyFont.class); | private static Log log = LogFactory.getLog(LazyFont.class); | ||||
private final FontUris fontUris; | |||||
private final URI metricsURI; | |||||
private final URI fontEmbedURI; | |||||
private final boolean useKerning; | private final boolean useKerning; | ||||
private final boolean useAdvanced; | private final boolean useAdvanced; | ||||
private final EncodingMode encodingMode; | private final EncodingMode encodingMode; | ||||
*/ | */ | ||||
public LazyFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver, | public LazyFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver, | ||||
boolean useComplexScripts) { | boolean useComplexScripts) { | ||||
this.fontUris = fontInfo.getFontUris(); | |||||
this.metricsURI = fontInfo.getMetricsURI(); | |||||
this.fontEmbedURI = fontInfo.getEmbedURI(); | |||||
this.useKerning = fontInfo.getKerning(); | this.useKerning = fontInfo.getKerning(); | ||||
if (resourceResolver != null) { | if (resourceResolver != null) { | ||||
this.useAdvanced = useComplexScripts; | this.useAdvanced = useComplexScripts; | ||||
public String toString() { | public String toString() { | ||||
StringBuffer sbuf = new StringBuffer(super.toString()); | StringBuffer sbuf = new StringBuffer(super.toString()); | ||||
sbuf.append('{'); | sbuf.append('{'); | ||||
sbuf.append("metrics-url=" + fontUris.getMetrics()); | |||||
sbuf.append(",embed-url=" + fontUris.getEmbed()); | |||||
sbuf.append("metrics-url=" + metricsURI); | |||||
sbuf.append(",embed-url=" + fontEmbedURI); | |||||
sbuf.append(",kerning=" + useKerning); | sbuf.append(",kerning=" + useKerning); | ||||
sbuf.append(",advanced=" + useAdvanced); | sbuf.append(",advanced=" + useAdvanced); | ||||
sbuf.append('}'); | sbuf.append('}'); | ||||
private void load(boolean fail) { | private void load(boolean fail) { | ||||
if (!isMetricsLoaded) { | if (!isMetricsLoaded) { | ||||
try { | try { | ||||
if (fontUris.getMetrics() != null) { | |||||
if (metricsURI != null) { | |||||
/**@todo Possible thread problem here */ | /**@todo Possible thread problem here */ | ||||
FontReader reader = null; | FontReader reader = null; | ||||
InputStream in = resourceResolver.getResource(fontUris.getMetrics()); | |||||
InputStream in = resourceResolver.getResource(metricsURI); | |||||
InputSource src = new InputSource(in); | InputSource src = new InputSource(in); | ||||
src.setSystemId(fontUris.getMetrics().toASCIIString()); | |||||
src.setSystemId(metricsURI.toASCIIString()); | |||||
reader = new FontReader(src, resourceResolver); | reader = new FontReader(src, resourceResolver); | ||||
reader.setKerningEnabled(useKerning); | reader.setKerningEnabled(useKerning); | ||||
reader.setAdvancedEnabled(useAdvanced); | reader.setAdvancedEnabled(useAdvanced); | ||||
if (this.embedded) { | if (this.embedded) { | ||||
reader.setFontEmbedURI(fontUris.getEmbed()); | |||||
reader.setFontEmbedURI(fontEmbedURI); | |||||
} | } | ||||
realFont = reader.getFont(); | realFont = reader.getFont(); | ||||
} else { | } else { | ||||
if (fontUris.getEmbed() == null) { | |||||
if (fontEmbedURI == null) { | |||||
throw new RuntimeException("Cannot load font. No font URIs available."); | throw new RuntimeException("Cannot load font. No font URIs available."); | ||||
} | } | ||||
realFont = FontLoader.loadFont(fontUris, subFontName, embedded, | |||||
realFont = FontLoader.loadFont(fontEmbedURI, subFontName, embedded, | |||||
embeddingMode, encodingMode, useKerning, useAdvanced, resourceResolver); | embeddingMode, encodingMode, useKerning, useAdvanced, resourceResolver); | ||||
} | } | ||||
if (realFont instanceof FontDescriptor) { | if (realFont instanceof FontDescriptor) { | ||||
realFontDescriptor = (FontDescriptor) realFont; | realFontDescriptor = (FontDescriptor) realFont; | ||||
} | } | ||||
} catch (FOPException fopex) { | } catch (FOPException fopex) { | ||||
log.error("Failed to read font metrics file " + fontUris.getMetrics(), fopex); | |||||
log.error("Failed to read font metrics file " + metricsURI, fopex); | |||||
if (fail) { | if (fail) { | ||||
throw new RuntimeException(fopex); | throw new RuntimeException(fopex); | ||||
} | } | ||||
} catch (IOException ioex) { | } catch (IOException ioex) { | ||||
log.error("Failed to read font metrics file " + fontUris.getMetrics(), ioex); | |||||
log.error("Failed to read font metrics file " + metricsURI, ioex); | |||||
if (fail) { | if (fail) { | ||||
throw new RuntimeException(ioex); | throw new RuntimeException(ioex); | ||||
} | } | ||||
} | } | ||||
return realFont.isMultiByte(); | return realFont.isMultiByte(); | ||||
} | } | ||||
} | } | ||||
import org.apache.fop.fonts.FontEventListener; | import org.apache.fop.fonts.FontEventListener; | ||||
import org.apache.fop.fonts.FontLoader; | import org.apache.fop.fonts.FontLoader; | ||||
import org.apache.fop.fonts.FontTriplet; | import org.apache.fop.fonts.FontTriplet; | ||||
import org.apache.fop.fonts.FontUris; | |||||
import org.apache.fop.fonts.FontUtil; | import org.apache.fop.fonts.FontUtil; | ||||
import org.apache.fop.fonts.MultiByteFont; | import org.apache.fop.fonts.MultiByteFont; | ||||
import org.apache.fop.fonts.truetype.FontFileReader; | import org.apache.fop.fonts.truetype.FontFileReader; | ||||
*/ | */ | ||||
private EmbedFontInfo getFontInfoFromCustomFont(URI fontUri, CustomFont customFont, | private EmbedFontInfo getFontInfoFromCustomFont(URI fontUri, CustomFont customFont, | ||||
FontCache fontCache, InternalResourceResolver resourceResolver) { | FontCache fontCache, InternalResourceResolver resourceResolver) { | ||||
FontUris fontUris = new FontUris(fontUri, null); | |||||
List<FontTriplet> fontTripletList = new java.util.ArrayList<FontTriplet>(); | List<FontTriplet> fontTripletList = new java.util.ArrayList<FontTriplet>(); | ||||
generateTripletsFromFont(customFont, fontTripletList); | generateTripletsFromFont(customFont, fontTripletList); | ||||
String subFontName = null; | String subFontName = null; | ||||
if (customFont instanceof MultiByteFont) { | if (customFont instanceof MultiByteFont) { | ||||
subFontName = ((MultiByteFont) customFont).getTTCName(); | subFontName = ((MultiByteFont) customFont).getTTCName(); | ||||
} | } | ||||
EmbedFontInfo fontInfo = new EmbedFontInfo(fontUris, customFont.isKerningEnabled(), | |||||
customFont.isAdvancedEnabled(), fontTripletList, subFontName, | |||||
EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(), | |||||
customFont.isAdvancedEnabled(), fontTripletList, fontUri, subFontName, | |||||
EncodingMode.AUTO, EmbeddingMode.AUTO); | EncodingMode.AUTO, EmbeddingMode.AUTO); | ||||
fontInfo.setPostScriptName(customFont.getFontName()); | fontInfo.setPostScriptName(customFont.getFontName()); | ||||
if (fontCache != null) { | if (fontCache != null) { | ||||
} else { | } else { | ||||
// The normal case | // The normal case | ||||
try { | try { | ||||
FontUris fontUris = new FontUris(fontURI, null); | |||||
customFont = FontLoader.loadFont(fontUris, null, true, EmbeddingMode.AUTO, EncodingMode.AUTO, | |||||
useKerning, useAdvanced, resourceResolver); | |||||
customFont = FontLoader.loadFont(fontURI, null, true, EmbeddingMode.AUTO, | |||||
EncodingMode.AUTO, useKerning, useAdvanced, resourceResolver); | |||||
if (this.eventListener != null) { | if (this.eventListener != null) { | ||||
customFont.setEventListener(this.eventListener); | customFont.setEventListener(this.eventListener); | ||||
} | } |
import java.awt.geom.RectangularShape; | import java.awt.geom.RectangularShape; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.net.URI; | |||||
import java.net.URISyntaxException; | import java.net.URISyntaxException; | ||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.fop.fonts.EmbeddingMode; | import org.apache.fop.fonts.EmbeddingMode; | ||||
import org.apache.fop.fonts.FontLoader; | import org.apache.fop.fonts.FontLoader; | ||||
import org.apache.fop.fonts.FontType; | import org.apache.fop.fonts.FontType; | ||||
import org.apache.fop.fonts.FontUris; | |||||
import org.apache.fop.fonts.SingleByteEncoding; | import org.apache.fop.fonts.SingleByteEncoding; | ||||
import org.apache.fop.fonts.SingleByteFont; | import org.apache.fop.fonts.SingleByteFont; | ||||
private EmbeddingMode embeddingMode; | private EmbeddingMode embeddingMode; | ||||
private final FontUris fontUris; | |||||
/** | /** | ||||
* Constructs a new Type 1 font loader. | * Constructs a new Type 1 font loader. | ||||
* @param fontFileURI the URI to the PFB file of a Type 1 font | * @param fontFileURI the URI to the PFB file of a Type 1 font | ||||
* @param resourceResolver the font resolver used to resolve URIs | * @param resourceResolver the font resolver used to resolve URIs | ||||
* @throws IOException In case of an I/O error | * @throws IOException In case of an I/O error | ||||
*/ | */ | ||||
public Type1FontLoader(FontUris fontUris, boolean embedded, EmbeddingMode embeddingMode, | |||||
public Type1FontLoader(URI fontFileURI, boolean embedded, EmbeddingMode embeddingMode, | |||||
boolean useKerning, InternalResourceResolver resourceResolver) throws IOException { | boolean useKerning, InternalResourceResolver resourceResolver) throws IOException { | ||||
super(fontUris.getEmbed(), embedded, useKerning, true, resourceResolver); | |||||
super(fontFileURI, embedded, useKerning, true, resourceResolver); | |||||
this.embeddingMode = embeddingMode; | this.embeddingMode = embeddingMode; | ||||
this.fontUris = fontUris; | |||||
} | } | ||||
private String getPFMURI(String pfbURI) { | private String getPFMURI(String pfbURI) { | ||||
InputStream afmIn = null; | InputStream afmIn = null; | ||||
String fontFileStr = fontFileURI.toASCIIString(); | String fontFileStr = fontFileURI.toASCIIString(); | ||||
String partialAfmUri = fontFileStr.substring(0, fontFileStr.length() - 4); | String partialAfmUri = fontFileStr.substring(0, fontFileStr.length() - 4); | ||||
String afmUri = (fontUris.getAfm() != null) ? fontUris.getAfm().toASCIIString() : null; | |||||
if (afmUri == null) { | |||||
for (String afmExtension : AFM_EXTENSIONS) { | |||||
try { | |||||
afmUri = partialAfmUri + afmExtension; | |||||
afmIn = resourceResolver.getResource(afmUri); | |||||
if (afmIn != null) { | |||||
break; | |||||
} | |||||
} catch (IOException ioe) { | |||||
// Ignore, AFM probably not available under the URI | |||||
} catch (URISyntaxException e) { | |||||
// Ignore, AFM probably not available under the URI | |||||
} | |||||
} | |||||
} else { | |||||
String afmUri = null; | |||||
for (String afmExtension : AFM_EXTENSIONS) { | |||||
try { | try { | ||||
afmUri = partialAfmUri + afmExtension; | |||||
afmIn = resourceResolver.getResource(afmUri); | afmIn = resourceResolver.getResource(afmUri); | ||||
if (afmIn != null) { | |||||
break; | |||||
} | |||||
} catch (IOException ioe) { | |||||
// Ignore, AFM probably not available under the URI | |||||
} catch (URISyntaxException e) { | } catch (URISyntaxException e) { | ||||
throw new IOException(e); | |||||
// Ignore, AFM probably not available under the URI | |||||
} | } | ||||
} | } | ||||
if (afmIn != null) { | if (afmIn != null) { | ||||
} | } | ||||
} | } | ||||
String pfmUri = (fontUris.getPfm() == null) ? getPFMURI(fontFileStr) : fontUris.getPfm() | |||||
.toASCIIString(); | |||||
String pfmUri = getPFMURI(fontFileStr); | |||||
InputStream pfmIn = null; | InputStream pfmIn = null; | ||||
try { | try { | ||||
pfmIn = resourceResolver.getResource(pfmUri); | pfmIn = resourceResolver.getResource(pfmUri); |
import org.apache.fop.fonts.FontInfo; | import org.apache.fop.fonts.FontInfo; | ||||
import org.apache.fop.fonts.FontLoader; | import org.apache.fop.fonts.FontLoader; | ||||
import org.apache.fop.fonts.FontTriplet; | import org.apache.fop.fonts.FontTriplet; | ||||
import org.apache.fop.fonts.FontUris; | |||||
import org.apache.fop.fonts.LazyFont; | import org.apache.fop.fonts.LazyFont; | ||||
/** | /** | ||||
InputStream fontSource = resourceResolver.getResource(fontURI); | InputStream fontSource = resourceResolver.getResource(fontURI); | ||||
font = new CustomFontMetricsMapper(fontMetrics, fontSource); | font = new CustomFontMetricsMapper(fontMetrics, fontSource); | ||||
} else { | } else { | ||||
FontUris fontUris = new FontUris(fontURI, null); | |||||
CustomFont fontMetrics = FontLoader.loadFont(fontUris, null, true, | |||||
CustomFont fontMetrics = FontLoader.loadFont(fontURI, null, true, | |||||
configFontInfo.getEmbeddingMode(), configFontInfo.getEncodingMode(), | configFontInfo.getEmbeddingMode(), configFontInfo.getEncodingMode(), | ||||
configFontInfo.getKerning(), configFontInfo.getAdvanced(), resourceResolver); | |||||
configFontInfo.getKerning(), configFontInfo.getAdvanced(), | |||||
resourceResolver); | |||||
font = new CustomFontMetricsMapper(fontMetrics); | font = new CustomFontMetricsMapper(fontMetrics); | ||||
} | } | ||||
@Before | @Before | ||||
public void setUp() throws Exception { | public void setUp() throws Exception { | ||||
File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf"); | File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf"); | ||||
FontUris fontUris = new FontUris(file.toURI(), null); | |||||
font = FontLoader.loadFont(fontUris, "", true, EmbeddingMode.AUTO, EncodingMode.AUTO, | |||||
font = FontLoader.loadFont(file.toURI(), "", true, EmbeddingMode.AUTO, EncodingMode.AUTO, | |||||
false, false, resolver); | false, false, resolver); | ||||
} | } | ||||
public void setUp() { | public void setUp() { | ||||
List<FontTriplet> triplets = new ArrayList<FontTriplet>(); | List<FontTriplet> triplets = new ArrayList<FontTriplet>(); | ||||
triplets.add(triplet); | triplets.add(triplet); | ||||
FontUris fontUris = new FontUris(embedURI, metricsURI); | |||||
sut = new EmbedFontInfo(fontUris, kerning, useAdvanced, triplets, subFontName, encMode, embedMode); | |||||
sut = new EmbedFontInfo(metricsURI, kerning, useAdvanced, triplets, embedURI, subFontName, | |||||
encMode, embedMode); | |||||
} | } | ||||
@Test | @Test | ||||
@Test | @Test | ||||
public void testQuirkyBoundaryCasesIsEmbedded() { | public void testQuirkyBoundaryCasesIsEmbedded() { | ||||
FontUris fontUris = new FontUris(null, metricsURI); | |||||
sut = new EmbedFontInfo(fontUris, kerning, useAdvanced, sut.getFontTriplets(), subFontName, encMode, | |||||
embedMode); | |||||
sut = new EmbedFontInfo(metricsURI, kerning, useAdvanced, sut.getFontTriplets(), null, | |||||
subFontName, encMode, embedMode); | |||||
sut.setEmbedded(true); | sut.setEmbedded(true); | ||||
assertFalse(sut.isEmbedded()); | assertFalse(sut.isEmbedded()); | ||||