Plus other internal cleanup git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1350538 13f79535-47bb-0310-9956-ffa450edef68pull/26/head
import org.apache.fop.afp.modca.ResourceObject; | import org.apache.fop.afp.modca.ResourceObject; | ||||
import org.apache.fop.afp.util.AFPResourceAccessor; | import org.apache.fop.afp.util.AFPResourceAccessor; | ||||
import org.apache.fop.afp.util.AFPResourceUtil; | import org.apache.fop.afp.util.AFPResourceUtil; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
* Manages the creation and storage of document resources | * Manages the creation and storage of document resources | ||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
*/ | */ | ||||
public AFPResourceManager(URIResolverWrapper uriResolverWrapper) { | |||||
public AFPResourceManager(InternalResourceResolver resourceResolver) { | |||||
this.factory = new Factory(); | this.factory = new Factory(); | ||||
this.streamer = new AFPStreamer(factory, uriResolverWrapper); | |||||
this.streamer = new AFPStreamer(factory, resourceResolver); | |||||
this.dataObjectFactory = new AFPDataObjectFactory(factory); | this.dataObjectFactory = new AFPDataObjectFactory(factory); | ||||
} | } | ||||
import org.apache.fop.afp.modca.ResourceGroup; | import org.apache.fop.afp.modca.ResourceGroup; | ||||
import org.apache.fop.afp.modca.StreamedResourceGroup; | import org.apache.fop.afp.modca.StreamedResourceGroup; | ||||
import org.apache.fop.apps.io.TempResourceURIGenerator; | import org.apache.fop.apps.io.TempResourceURIGenerator; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
* Manages the streaming of the AFP output | * Manages the streaming of the AFP output | ||||
private final Factory factory; | private final Factory factory; | ||||
private final URIResolverWrapper uriResolverWrapper; | |||||
private final InternalResourceResolver resourceResolver; | |||||
/** A mapping of external resource destinations to resource groups */ | /** A mapping of external resource destinations to resource groups */ | ||||
private final Map<URI, ResourceGroup> pathResourceGroupMap = new HashMap<URI, ResourceGroup>(); | private final Map<URI, ResourceGroup> pathResourceGroupMap = new HashMap<URI, ResourceGroup>(); | ||||
* Main constructor | * Main constructor | ||||
* | * | ||||
* @param factory a factory | * @param factory a factory | ||||
* @param resourceResolver resource resolver | |||||
*/ | */ | ||||
public AFPStreamer(Factory factory, URIResolverWrapper uriResolverWrapper) { | |||||
public AFPStreamer(Factory factory, InternalResourceResolver resourceResolver) { | |||||
this.factory = factory; | this.factory = factory; | ||||
this.uriResolverWrapper = uriResolverWrapper; | |||||
this.resourceResolver = resourceResolver; | |||||
this.tempUri = TEMP_URI_GENERATOR.generate(); | this.tempUri = TEMP_URI_GENERATOR.generate(); | ||||
defaultResourceGroupUri = URI.create(DEFAULT_EXTERNAL_RESOURCE_FILENAME); | defaultResourceGroupUri = URI.create(DEFAULT_EXTERNAL_RESOURCE_FILENAME); | ||||
* @throws IOException thrown if an I/O exception of some sort has occurred | * @throws IOException thrown if an I/O exception of some sort has occurred | ||||
*/ | */ | ||||
public DataStream createDataStream(AFPPaintingState paintingState) throws IOException { | public DataStream createDataStream(AFPPaintingState paintingState) throws IOException { | ||||
this.tempOutputStream = new BufferedOutputStream(uriResolverWrapper.resolveOut(tempUri)); | |||||
this.tempOutputStream = new BufferedOutputStream(resourceResolver.getOutputStream(tempUri)); | |||||
this.dataStream = factory.createDataStream(paintingState, tempOutputStream); | this.dataStream = factory.createDataStream(paintingState, tempOutputStream); | ||||
return dataStream; | return dataStream; | ||||
} | } | ||||
if (resourceGroup == null) { | if (resourceGroup == null) { | ||||
OutputStream os = null; | OutputStream os = null; | ||||
try { | try { | ||||
os = new BufferedOutputStream(uriResolverWrapper.resolveOut(uri)); | |||||
os = new BufferedOutputStream(resourceResolver.getOutputStream(uri)); | |||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
LOG.error("Failed to create/open external resource group for uri '" | LOG.error("Failed to create/open external resource group for uri '" | ||||
+ uri + "'"); | + uri + "'"); | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void writeToStream(OutputStream os) throws IOException { | public void writeToStream(OutputStream os) throws IOException { | ||||
tempOutputStream.close(); | tempOutputStream.close(); | ||||
InputStream tempInputStream = uriResolverWrapper.resolveIn(tempUri); | |||||
InputStream tempInputStream = resourceResolver.getResource(tempUri); | |||||
IOUtils.copy(tempInputStream, os); | IOUtils.copy(tempInputStream, os); | ||||
//TODO this should notify the stream provider that it is safe to delete the temp data | //TODO this should notify the stream provider that it is safe to delete the temp data | ||||
tempInputStream.close(); | tempInputStream.close(); |
import java.net.URI; | import java.net.URI; | ||||
import java.net.URISyntaxException; | import java.net.URISyntaxException; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
* Defines an interface through which external resource objects can be accessed. | * Defines an interface through which external resource objects can be accessed. | ||||
*/ | */ | ||||
public final class AFPResourceAccessor { | public final class AFPResourceAccessor { | ||||
private final URIResolverWrapper resolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private final String baseURI; | private final String baseURI; | ||||
/** | /** | ||||
* Constructor for resource to be accessed via the {@link FOUserAgent}. This contructor | * Constructor for resource to be accessed via the {@link FOUserAgent}. This contructor | ||||
* can take two base URIs: the category base URI is the one to use when differentiating between | |||||
* normal resources (ex. images) and font resources. So, if fonts need to be accessed, you can | |||||
* set the {@link org.apache.fop.fonts.FontManager}'s base URI instead of the one on the | |||||
* {@link org.apache.fop.apps.FopFactory}. | |||||
* @param userAgent the FO user agent | |||||
* @param categoryBaseURI the category base URI (may be null) | |||||
* takes a base URI for resolving font resource URIs. So, if fonts need to be accessed, you can | |||||
* set the {@link FontManager}'s base URI instead of the one on the {@link FopFactory}. | |||||
* | |||||
* @param InternalResourceResolver resource resolver | |||||
* @param baseURI the custom base URI to resolve relative URIs against (may be null) | * @param baseURI the custom base URI to resolve relative URIs against (may be null) | ||||
*/ | */ | ||||
public AFPResourceAccessor(URIResolverWrapper resolver, String baseURI) { | |||||
this.resolver = resolver; | |||||
public AFPResourceAccessor(InternalResourceResolver resourceResolver, String baseURI) { | |||||
this.resourceResolver = resourceResolver; | |||||
this.baseURI = baseURI; | this.baseURI = baseURI; | ||||
} | } | ||||
public AFPResourceAccessor(URIResolverWrapper resolver) { | |||||
this.resolver = resolver; | |||||
this.baseURI = null; | |||||
/** | |||||
* Constructor for resource to be accessed via the {@link FOUserAgent}. | |||||
* | |||||
* @param InternalResourceResolver resource resolver | |||||
*/ | |||||
public AFPResourceAccessor(InternalResourceResolver resourceResolver) { | |||||
this(resourceResolver, null); | |||||
} | } | ||||
private URI getResourceURI(URI uri) { | private URI getResourceURI(URI uri) { | ||||
return uri; | return uri; | ||||
} | } | ||||
try { | try { | ||||
URI baseURI = URIResolverWrapper.getBaseURI(this.baseURI); | |||||
URI baseURI = InternalResourceResolver.getBaseURI(this.baseURI); | |||||
return baseURI.resolve(uri); | return baseURI.resolve(uri); | ||||
} catch (URISyntaxException use) { | } catch (URISyntaxException use) { | ||||
return uri; | return uri; | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public InputStream createInputStream(URI uri) throws IOException { | public InputStream createInputStream(URI uri) throws IOException { | ||||
return resolver.resolveIn(getResourceURI(uri)); | |||||
return resourceResolver.getResource(getResourceURI(uri)); | |||||
} | } | ||||
} | } |
import java.net.URI; | import java.net.URI; | ||||
import org.apache.fop.apps.io.ResourceResolver; | import org.apache.fop.apps.io.ResourceResolver; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.FontCacheManager; | import org.apache.fop.fonts.FontCacheManager; | ||||
import org.apache.fop.fonts.FontCacheManagerFactory; | import org.apache.fop.fonts.FontCacheManagerFactory; | ||||
import org.apache.fop.fonts.FontDetector; | import org.apache.fop.fonts.FontDetector; | ||||
private static FontManager createFontManager(URI defaultBaseUri, ResourceResolver resourceResolver, | private static FontManager createFontManager(URI defaultBaseUri, ResourceResolver resourceResolver, | ||||
FontDetector fontDetector, FontCacheManager fontCacheManager) { | FontDetector fontDetector, FontCacheManager fontCacheManager) { | ||||
return new FontManager(new URIResolverWrapper(defaultBaseUri, resourceResolver), fontDetector, | |||||
return new FontManager(new InternalResourceResolver(defaultBaseUri, resourceResolver), fontDetector, | |||||
fontCacheManager); | fontCacheManager); | ||||
} | } | ||||
} | } |
import org.apache.fop.accessibility.Accessibility; | import org.apache.fop.accessibility.Accessibility; | ||||
import org.apache.fop.accessibility.DummyStructureTreeEventHandler; | import org.apache.fop.accessibility.DummyStructureTreeEventHandler; | ||||
import org.apache.fop.accessibility.StructureTreeEventHandler; | import org.apache.fop.accessibility.StructureTreeEventHandler; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.events.DefaultEventBroadcaster; | import org.apache.fop.events.DefaultEventBroadcaster; | ||||
import org.apache.fop.events.Event; | import org.apache.fop.events.Event; | ||||
import org.apache.fop.events.EventBroadcaster; | import org.apache.fop.events.EventBroadcaster; | ||||
private final FopFactory factory; | private final FopFactory factory; | ||||
private final URIResolverWrapper newUriResolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private float targetResolution = FopFactoryConfig.DEFAULT_TARGET_RESOLUTION; | private float targetResolution = FopFactoryConfig.DEFAULT_TARGET_RESOLUTION; | ||||
private Map rendererOptions = new java.util.HashMap(); | private Map rendererOptions = new java.util.HashMap(); | ||||
* Main constructor. <b>This constructor should not be called directly. Please use the | * Main constructor. <b>This constructor should not be called directly. Please use the | ||||
* methods from FopFactory to construct FOUserAgent instances!</b> | * methods from FopFactory to construct FOUserAgent instances!</b> | ||||
* @param factory the factory that provides environment-level information | * @param factory the factory that provides environment-level information | ||||
* @param resourceResolver the resolver used to acquire resources | |||||
* @see org.apache.fop.apps.FopFactory | * @see org.apache.fop.apps.FopFactory | ||||
*/ | */ | ||||
FOUserAgent(FopFactory factory, URIResolverWrapper uriResolver) { | |||||
FOUserAgent(FopFactory factory, InternalResourceResolver resourceResolver) { | |||||
this.factory = factory; | this.factory = factory; | ||||
this.newUriResolver = uriResolver; | |||||
this.resourceResolver = resourceResolver; | |||||
setTargetResolution(factory.getTargetResolution()); | setTargetResolution(factory.getTargetResolution()); | ||||
setAccessibility(factory.isAccessibilityEnabled()); | setAccessibility(factory.isAccessibilityEnabled()); | ||||
} | } | ||||
/** | /** | ||||
* Returns the URI Resolver. | |||||
* Returns the resource resolver. | |||||
* | * | ||||
* @return the URI resolver | |||||
* @return the resource resolver | |||||
*/ | */ | ||||
public URIResolverWrapper getNewURIResolver() { | |||||
return newUriResolver; | |||||
public InternalResourceResolver getResourceResolver() { | |||||
return resourceResolver; | |||||
} | } | ||||
// ---------------------------------------------- rendering-run dependent stuff | // ---------------------------------------------- rendering-run dependent stuff | ||||
// TODO: What do we want to do when resources aren't found??? | // TODO: What do we want to do when resources aren't found??? | ||||
try { | try { | ||||
// Have to do this so we can resolve data URIs | // Have to do this so we can resolve data URIs | ||||
Source src = new StreamSource(newUriResolver.resolveIn(uri)); | |||||
Source src = new StreamSource(resourceResolver.getResource(uri)); | |||||
src.setSystemId(uri); | src.setSystemId(uri); | ||||
return src; | return src; | ||||
} catch (URISyntaxException use) { | } catch (URISyntaxException use) { |
import org.apache.fop.apps.io.ResourceResolver; | import org.apache.fop.apps.io.ResourceResolver; | ||||
import org.apache.fop.apps.io.ResourceResolverFactory; | import org.apache.fop.apps.io.ResourceResolverFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.FontManagerConfigurator; | import org.apache.fop.fonts.FontManagerConfigurator; | ||||
import org.apache.fop.hyphenation.HyphenationTreeCache; | import org.apache.fop.hyphenation.HyphenationTreeCache; | ||||
import org.apache.fop.util.LogUtil; | import org.apache.fop.util.LogUtil; | ||||
* | * | ||||
* @param fopConfStream the fop conf input stream | * @param fopConfStream the fop conf input stream | ||||
* @param defaultBaseURI the default base URI | * @param defaultBaseURI the default base URI | ||||
* @param resolver the URI resolver | |||||
* @param resourceResolver the URI resolver | |||||
* @throws SAXException if a SAX error was thrown parsing the FOP conf | * @throws SAXException if a SAX error was thrown parsing the FOP conf | ||||
* @throws IOException if an I/O error is thrown while parsing the FOP conf | * @throws IOException if an I/O error is thrown while parsing the FOP conf | ||||
*/ | */ | ||||
public FopConfParser(InputStream fopConfStream, URI defaultBaseURI, | public FopConfParser(InputStream fopConfStream, URI defaultBaseURI, | ||||
ResourceResolver resolver) throws SAXException, IOException { | |||||
this(fopConfStream, EnvironmentalProfileFactory.createDefault(defaultBaseURI, resolver)); | |||||
ResourceResolver resourceResolver) throws SAXException, IOException { | |||||
this(fopConfStream, EnvironmentalProfileFactory.createDefault(defaultBaseURI, resourceResolver)); | |||||
} | } | ||||
/** | /** | ||||
* Constructor that parses the FOP conf and uses the URI resolver given. | * Constructor that parses the FOP conf and uses the URI resolver given. | ||||
* | * | ||||
* @param fopConfFile the FOP conf file | * @param fopConfFile the FOP conf file | ||||
* @param resolver the URI resolver | |||||
* @param resourceResolver the URI resolver | |||||
* @throws SAXException if a SAX error was thrown parsing the FOP conf | * @throws SAXException if a SAX error was thrown parsing the FOP conf | ||||
* @throws IOException if an I/O error is thrown while parsing the FOP conf | * @throws IOException if an I/O error is thrown while parsing the FOP conf | ||||
*/ | */ | ||||
public FopConfParser(File fopConfFile, ResourceResolver resolver) | |||||
public FopConfParser(File fopConfFile, ResourceResolver resourceResolver) | |||||
throws SAXException, IOException { | throws SAXException, IOException { | ||||
this(new FileInputStream(fopConfFile), | this(new FileInputStream(fopConfFile), | ||||
fopConfFile.getAbsoluteFile().getParentFile().toURI(), resolver); | |||||
fopConfFile.getAbsoluteFile().getParentFile().toURI(), resourceResolver); | |||||
} | } | ||||
private void configure(final URI defaultBaseURI, final ResourceResolver resolver, | |||||
private void configure(final URI defaultBaseURI, final ResourceResolver resourceResolver, | |||||
Configuration cfg) throws FOPException { | Configuration cfg) throws FOPException { | ||||
if (log.isDebugEnabled()) { | if (log.isDebugEnabled()) { | ||||
log.debug("Initializing FopFactory Configuration"); | log.debug("Initializing FopFactory Configuration"); | ||||
// base definitions for relative path resolution | // base definitions for relative path resolution | ||||
if (cfg.getChild("base", false) != null) { | if (cfg.getChild("base", false) != null) { | ||||
try { | try { | ||||
URI confUri = URIResolverWrapper.getBaseURI(cfg.getChild("base").getValue(null)); | |||||
URI confUri = InternalResourceResolver.getBaseURI(cfg.getChild("base").getValue(null)); | |||||
fopFactoryBuilder.setBaseURI(defaultBaseURI.resolve(confUri)); | fopFactoryBuilder.setBaseURI(defaultBaseURI.resolve(confUri)); | ||||
} catch (URISyntaxException use) { | } catch (URISyntaxException use) { | ||||
LogUtil.handleException(log, use, strict); | LogUtil.handleException(log, use, strict); | ||||
} | } | ||||
// configure font manager | // configure font manager | ||||
new FontManagerConfigurator(cfg, fopFactoryBuilder.getBaseUri(), resolver).configure( | |||||
new FontManagerConfigurator(cfg, fopFactoryBuilder.getBaseUri(), resourceResolver).configure( | |||||
fopFactoryBuilder.getFontManager(), strict); | fopFactoryBuilder.getFontManager(), strict); | ||||
// configure image loader framework | // configure image loader framework |
import org.apache.xmlgraphics.image.loader.ImageManager; | import org.apache.xmlgraphics.image.loader.ImageManager; | ||||
import org.apache.xmlgraphics.util.UnitConv; | import org.apache.xmlgraphics.util.UnitConv; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fo.ElementMapping; | import org.apache.fop.fo.ElementMapping; | ||||
import org.apache.fop.fo.ElementMappingRegistry; | import org.apache.fop.fo.ElementMappingRegistry; | ||||
import org.apache.fop.fonts.FontManager; | import org.apache.fop.fonts.FontManager; | ||||
private final FopFactoryConfig config; | private final FopFactoryConfig config; | ||||
private final URIResolverWrapper uriResolverWrapper; | |||||
private final InternalResourceResolver resolver; | |||||
private final Map<String, RendererConfig> rendererConfig; | private final Map<String, RendererConfig> rendererConfig; | ||||
private FopFactory(FopFactoryConfig config) { | private FopFactory(FopFactoryConfig config) { | ||||
this.config = config; | this.config = config; | ||||
this.uriResolverWrapper = new URIResolverWrapper(config.getBaseURI(), config.getNewURIResolver()); | |||||
this.resolver = new InternalResourceResolver(config.getBaseURI(), config.getResourceResolver()); | |||||
this.elementMappingRegistry = new ElementMappingRegistry(this); | this.elementMappingRegistry = new ElementMappingRegistry(this); | ||||
this.colorSpaceCache = new ColorSpaceCache(uriResolverWrapper); | |||||
this.colorSpaceCache = new ColorSpaceCache(resolver); | |||||
this.rendererFactory = new RendererFactory(config.preferRenderer()); | this.rendererFactory = new RendererFactory(config.preferRenderer()); | ||||
this.xmlHandlers = new XMLHandlerRegistry(); | this.xmlHandlers = new XMLHandlerRegistry(); | ||||
this.imageHandlers = new ImageHandlerRegistry(); | this.imageHandlers = new ImageHandlerRegistry(); | ||||
* @throws FOPException | * @throws FOPException | ||||
*/ | */ | ||||
public FOUserAgent newFOUserAgent() { | public FOUserAgent newFOUserAgent() { | ||||
FOUserAgent userAgent = new FOUserAgent(this, uriResolverWrapper); | |||||
FOUserAgent userAgent = new FOUserAgent(this, resolver); | |||||
return userAgent; | return userAgent; | ||||
} | } | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Set; | import java.util.Set; | ||||
import javax.xml.transform.URIResolver; | |||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
import org.apache.xmlgraphics.image.loader.ImageContext; | import org.apache.xmlgraphics.image.loader.ImageContext; | ||||
* A builder class for {@link FopFactory} which can be used for setting configuration. | * A builder class for {@link FopFactory} which can be used for setting configuration. | ||||
* | * | ||||
* @param defaultBaseURI the default base URI for resolving URIs against | * @param defaultBaseURI the default base URI for resolving URIs against | ||||
* @param uriResolver the URI resolver | |||||
* @param resourceResolver the URI resolver | |||||
*/ | */ | ||||
public FopFactoryBuilder(URI defaultBaseURI, ResourceResolver uriResolver) { | |||||
this(EnvironmentalProfileFactory.createDefault(defaultBaseURI, uriResolver)); | |||||
public FopFactoryBuilder(URI defaultBaseURI, ResourceResolver resourceResolver) { | |||||
this(EnvironmentalProfileFactory.createDefault(defaultBaseURI, resourceResolver)); | |||||
} | } | ||||
/** | /** | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* Sets the URI resolver to be used for controlling FOP's file access. | |||||
* | |||||
* @param resolver the URI resolver | |||||
* @return <code>this</code> | |||||
* @deprecated this URIResolver will be phased out in favour of a unified URI resolution | |||||
* mechanism | |||||
*/ | |||||
public FopFactoryBuilder setURIResolver(URIResolver resolver) { | |||||
fopFactoryConfigBuilder.setURIResolver(resolver); | |||||
return this; | |||||
} | |||||
/** | /** | ||||
* Sets the base URI, this will be used for resolving all URIs given to FOP. | * Sets the base URI, this will be used for resolving all URIs given to FOP. | ||||
* | * | ||||
private Set<String> ignoredNamespaces = new HashSet<String>(); | private Set<String> ignoredNamespaces = new HashSet<String>(); | ||||
private URIResolver resolver; | |||||
private Configuration cfg; | private Configuration cfg; | ||||
private boolean preferRenderer; | private boolean preferRenderer; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public ResourceResolver getNewURIResolver() { | |||||
public ResourceResolver getResourceResolver() { | |||||
return enviro.getResourceResolver(); | return enviro.getResourceResolver(); | ||||
} | } | ||||
/** {@inheritDoc} */ | |||||
public URIResolver getURIResolver() { | |||||
return resolver; | |||||
} | |||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public URI getBaseURI() { | public URI getBaseURI() { | ||||
return baseURI; | return baseURI; | ||||
void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker); | void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker); | ||||
void setURIResolver(URIResolver resolver); | |||||
void setBaseURI(URI baseURI); | void setBaseURI(URI baseURI); | ||||
void setStrictFOValidation(boolean validateStrictly); | void setStrictFOValidation(boolean validateStrictly); | ||||
} | } | ||||
public void setURIResolver(URIResolver resolver) { | |||||
throwIllegalStateException(); | |||||
} | |||||
public void setBaseURI(URI baseURI) { | public void setBaseURI(URI baseURI) { | ||||
throwIllegalStateException(); | throwIllegalStateException(); | ||||
} | } | ||||
public void setHyphenationBaseURI(URI hyphenationBase) { | |||||
throwIllegalStateException(); | |||||
} | |||||
public void setStrictFOValidation(boolean validateStrictly) { | public void setStrictFOValidation(boolean validateStrictly) { | ||||
throwIllegalStateException(); | throwIllegalStateException(); | ||||
} | } | ||||
config.layoutManagerMaker = lmMaker; | config.layoutManagerMaker = lmMaker; | ||||
} | } | ||||
public void setURIResolver(URIResolver resolver) { | |||||
config.resolver = resolver; | |||||
} | |||||
public void setBaseURI(URI baseURI) { | public void setBaseURI(URI baseURI) { | ||||
config.baseURI = baseURI; | config.baseURI = baseURI; | ||||
} | } |
* | * | ||||
* @return the URI resolver | * @return the URI resolver | ||||
*/ | */ | ||||
ResourceResolver getNewURIResolver(); | |||||
ResourceResolver getResourceResolver(); | |||||
/** | /** | ||||
* The base URI from which URIs are resolved against. | * The base URI from which URIs are resolved against. |
return new TempAwareResourceResolver(tempResourceResolver, defaultResourceResolver); | return new TempAwareResourceResolver(tempResourceResolver, defaultResourceResolver); | ||||
} | } | ||||
public static URIResolverWrapper createDefaultWrapper() { | |||||
public static InternalResourceResolver createDefaultWrapper() { | |||||
// Not sure if this is the right place for this, but I don't have any better ideas as of yet | // Not sure if this is the right place for this, but I don't have any better ideas as of yet | ||||
URI thisUri = new File(".").getAbsoluteFile().toURI(); | URI thisUri = new File(".").getAbsoluteFile().toURI(); | ||||
return new URIResolverWrapper(thisUri, new DefaultResourceResolver()); | |||||
return new InternalResourceResolver(thisUri, new DefaultResourceResolver()); | |||||
} | } | ||||
public static SchemaAwareResourceResolverBuilder createSchemaAwareResourceResolverBuilder( | public static SchemaAwareResourceResolverBuilder createSchemaAwareResourceResolverBuilder( |
// load page from cache | // load page from cache | ||||
URI tempURI = pageMap.get(pageViewport); | URI tempURI = pageMap.get(pageViewport); | ||||
log.debug("Loading page from: " + tempURI); | log.debug("Loading page from: " + tempURI); | ||||
InputStream inStream = renderer.getUserAgent().getNewURIResolver().resolveIn(tempURI); | |||||
InputStream inStream = renderer.getUserAgent().getResourceResolver().getResource(tempURI); | |||||
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(inStream)); | ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(inStream)); | ||||
try { | try { | ||||
pageViewport.loadPage(in); | pageViewport.loadPage(in); | ||||
ObjectOutputStream tempstream; | ObjectOutputStream tempstream; | ||||
String fname = "fop-page-" + page.getPageIndex() + ".ser"; | String fname = "fop-page-" + page.getPageIndex() + ".ser"; | ||||
URI tempURI = tempBaseURI.resolve(fname); | URI tempURI = tempBaseURI.resolve(fname); | ||||
OutputStream outStream = renderer.getUserAgent().getNewURIResolver().resolveOut(tempURI); | |||||
OutputStream outStream = renderer.getUserAgent().getResourceResolver().getOutputStream(tempURI); | |||||
tempstream = new ObjectOutputStream(new BufferedOutputStream(outStream)); | tempstream = new ObjectOutputStream(new BufferedOutputStream(outStream)); | ||||
try { | try { | ||||
page.savePage(tempstream); | page.savePage(tempstream); |
/* if width and height are zero, get the bounds of the content. */ | /* if width and height are zero, get the bounds of the content. */ | ||||
try { | try { | ||||
URI baseUri = getUserAgent().getNewURIResolver().getBaseURI(); | |||||
URI baseUri = getUserAgent().getResourceResolver().getBaseURI(); | |||||
if (baseUri != null) { | if (baseUri != null) { | ||||
SVGOMDocument svgdoc = (SVGOMDocument)doc; | SVGOMDocument svgdoc = (SVGOMDocument)doc; | ||||
svgdoc.setURLObject(baseUri.toURL()); | svgdoc.setURLObject(baseUri.toURL()); |
package org.apache.fop.fonts; | package org.apache.fop.fonts; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
//Java | //Java | ||||
protected int[] width = null; | protected int[] width = null; | ||||
/** | /** | ||||
* @param resolver the URI resolver for controlling file access | |||||
* @param resourceResolver the URI resolver for controlling file access | |||||
*/ | */ | ||||
public CIDFont(URIResolverWrapper resolver) { | |||||
super(resolver); | |||||
public CIDFont(InternalResourceResolver resourceResolver) { | |||||
super(resourceResolver); | |||||
} | } | ||||
// ---- Required ---- | // ---- Required ---- |
import java.util.Map; | import java.util.Map; | ||||
import java.util.Set; | import java.util.Set; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
private String fontSubName; | private String fontSubName; | ||||
private URI embedFileURI; | private URI embedFileURI; | ||||
private String embedResourceName; | private String embedResourceName; | ||||
private final URIResolverWrapper resolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private int capHeight; | private int capHeight; | ||||
private int xHeight; | private int xHeight; | ||||
private boolean useAdvanced = true; | private boolean useAdvanced = true; | ||||
/** | /** | ||||
* @param resolver the URI resolver for controlling file access | |||||
* @param resourceResolver the URI resource resolver for controlling file access | |||||
*/ | */ | ||||
public CustomFont(URIResolverWrapper resolver) { | |||||
this.resolver = resolver; | |||||
public CustomFont(InternalResourceResolver resourceResolver) { | |||||
this.resourceResolver = resourceResolver; | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
* @throws IOException if embedFileName is not null but Source is not found | * @throws IOException if embedFileName is not null but Source is not found | ||||
*/ | */ | ||||
public InputStream getInputStream() throws IOException { | public InputStream getInputStream() throws IOException { | ||||
return resolver.resolveIn(embedFileURI); | |||||
return resourceResolver.getResource(embedFileURI); | |||||
} | } | ||||
/** | /** |
import java.util.List; | import java.util.List; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
* Sets up a set of custom (embedded) fonts | * Sets up a set of custom (embedded) fonts | ||||
public class CustomFontCollection implements FontCollection { | public class CustomFontCollection implements FontCollection { | ||||
private final List<EmbedFontInfo> embedFontInfoList; | private final List<EmbedFontInfo> embedFontInfoList; | ||||
private final URIResolverWrapper uriResolver; | |||||
private final InternalResourceResolver uriResolver; | |||||
private final boolean useComplexScripts; | private final boolean useComplexScripts; | ||||
/** | /** | ||||
* @param customFonts the list of custom fonts | * @param customFonts the list of custom fonts | ||||
* @param useComplexScriptFeatures true if complex script features enabled | * @param useComplexScriptFeatures true if complex script features enabled | ||||
*/ | */ | ||||
public CustomFontCollection(URIResolverWrapper fontResolver, | |||||
public CustomFontCollection(InternalResourceResolver fontResolver, | |||||
List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) { | List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) { | ||||
this.uriResolver = fontResolver; | this.uriResolver = fontResolver; | ||||
this.embedFontInfoList = customFonts; | this.embedFontInfoList = customFonts; |
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.DefaultFontConfig.Directory; | import org.apache.fop.fonts.DefaultFontConfig.Directory; | ||||
import org.apache.fop.fonts.autodetect.FontFileFinder; | import org.apache.fop.fonts.autodetect.FontFileFinder; | ||||
import org.apache.fop.fonts.autodetect.FontInfoFinder; | import org.apache.fop.fonts.autodetect.FontInfoFinder; | ||||
protected static Log log = LogFactory.getLog(DefaultFontConfigurator.class); | protected static Log log = LogFactory.getLog(DefaultFontConfigurator.class); | ||||
private final FontManager fontManager; | private final FontManager fontManager; | ||||
private final URIResolverWrapper uriResolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private final FontEventListener listener; | private final FontEventListener listener; | ||||
private final boolean strict; | private final boolean strict; | ||||
*/ | */ | ||||
public DefaultFontConfigurator(FontManager fontManager, FontEventListener listener, boolean strict) { | public DefaultFontConfigurator(FontManager fontManager, FontEventListener listener, boolean strict) { | ||||
this.fontManager = fontManager; | this.fontManager = fontManager; | ||||
this.uriResolver = fontManager.getURIResolver(); | |||||
this.resourceResolver = fontManager.getResourceResolver(); | |||||
this.listener = listener; | this.listener = listener; | ||||
this.strict = strict; | this.strict = strict; | ||||
} | } | ||||
log.debug("Starting font configuration..."); | log.debug("Starting font configuration..."); | ||||
start = System.currentTimeMillis(); | start = System.currentTimeMillis(); | ||||
} | } | ||||
FontAdder fontAdder = new FontAdder(fontManager, uriResolver, listener); | |||||
FontAdder fontAdder = new FontAdder(fontManager, resourceResolver, listener); | |||||
// native o/s search (autodetect) configuration | // native o/s search (autodetect) configuration | ||||
fontManager.autoDetectFonts(adobeFontInfoConfig.isAutoDetectFonts(), fontAdder, strict, | fontManager.autoDetectFonts(adobeFontInfoConfig.isAutoDetectFonts(), fontAdder, strict, | ||||
listener, fontInfoList); | listener, fontInfoList); | ||||
String embed = font.getEmbedURI(); | String embed = font.getEmbedURI(); | ||||
String metrics = font.getMetrics(); | String metrics = font.getMetrics(); | ||||
String subFont = font.getSubFont(); | String subFont = font.getSubFont(); | ||||
URI metricsUri = metrics == null ? null : URIResolverWrapper.cleanURI(metrics); | |||||
URI embedUri = URIResolverWrapper.cleanURI(embed); | |||||
URI metricsUri = metrics == null ? null : InternalResourceResolver.cleanURI(metrics); | |||||
URI embedUri = InternalResourceResolver.cleanURI(embed); | |||||
List<FontTriplet> tripletList = font.getTripletList(); | List<FontTriplet> tripletList = font.getTripletList(); | ||||
// no font triplet info | // no font triplet info | ||||
if (tripletList.size() == 0) { | if (tripletList.size() == 0) { | ||||
//TODO: could be problematic!! | //TODO: could be problematic!! | ||||
URI fontUri = uriResolver.getBaseURI().resolve(embedUri); | |||||
URI fontUri = resourceResolver.resolveFromBase(embedUri); | |||||
if (fontUri != null) { | if (fontUri != null) { | ||||
FontInfoFinder finder = new FontInfoFinder(); | FontInfoFinder finder = new FontInfoFinder(); | ||||
finder.setEventListener(listener); | finder.setEventListener(listener); | ||||
EmbedFontInfo[] infos = finder.find(fontUri, uriResolver, fontCache); | |||||
EmbedFontInfo[] infos = finder.find(fontUri, resourceResolver, fontCache); | |||||
return infos[0]; //When subFont is set, only one font is returned | return infos[0]; //When subFont is set, only one font is returned | ||||
} else { | } else { | ||||
return null; | return null; | ||||
font.isAdvanced(), tripletList, embedUri, subFont, encodingMode); | font.isAdvanced(), tripletList, embedUri, subFont, encodingMode); | ||||
if (fontCache != null) { | if (fontCache != null) { | ||||
if (!fontCache.containsFont(embedFontInfo)) { | if (!fontCache.containsFont(embedFontInfo)) { | ||||
fontCache.addFont(embedFontInfo, uriResolver); | |||||
fontCache.addFont(embedFontInfo, resourceResolver); | |||||
} | } | ||||
} | } | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.autodetect.FontInfoFinder; | import org.apache.fop.fonts.autodetect.FontInfoFinder; | ||||
/** | /** | ||||
*/ | */ | ||||
public class FontAdder { | public class FontAdder { | ||||
private final FontEventListener listener; | private final FontEventListener listener; | ||||
private final URIResolverWrapper resolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private final FontManager manager; | private final FontManager manager; | ||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* @param manager a font manager | * @param manager a font manager | ||||
* @param resolver a font resolver | |||||
* @param resourceResolver a font resolver | |||||
* @param listener a font event handler | * @param listener a font event handler | ||||
*/ | */ | ||||
public FontAdder(FontManager manager, URIResolverWrapper resolver, FontEventListener listener) { | |||||
public FontAdder(FontManager manager, InternalResourceResolver resourceResolver, | |||||
FontEventListener listener) { | |||||
this.manager = manager; | this.manager = manager; | ||||
this.resolver = resolver; | |||||
this.resourceResolver = resourceResolver; | |||||
this.listener = listener; | this.listener = listener; | ||||
} | } | ||||
finder.setEventListener(listener); | finder.setEventListener(listener); | ||||
for (URL fontURL : fontURLList) { | for (URL fontURL : fontURLList) { | ||||
EmbedFontInfo[] embedFontInfos = finder.find(fontURL.toURI(), resolver, cache); | |||||
EmbedFontInfo[] embedFontInfos = finder.find(fontURL.toURI(), resourceResolver, cache); | |||||
if (embedFontInfos == null) { | if (embedFontInfos == null) { | ||||
continue; | continue; | ||||
} | } |
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.util.LogUtil; | import org.apache.fop.util.LogUtil; | ||||
/** | /** | ||||
* @param fontInfo | * @param fontInfo | ||||
* font info | * font info | ||||
*/ | */ | ||||
public void addFont(EmbedFontInfo fontInfo, URIResolverWrapper resolver) { | |||||
public void addFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver) { | |||||
String cacheKey = getCacheKey(fontInfo); | String cacheKey = getCacheKey(fontInfo); | ||||
synchronized (changeLock) { | synchronized (changeLock) { | ||||
CachedFontFile cachedFontFile; | CachedFontFile cachedFontFile; | ||||
} | } | ||||
} else { | } else { | ||||
// try and determine modified date | // try and determine modified date | ||||
// TODO: This could be problematic?!!?!?! | |||||
URI fontUri = resolver.getBaseURI().resolve(fontInfo.getEmbedURI()); | |||||
URI fontUri = resourceResolver.resolveFromBase(fontInfo.getEmbedURI()); | |||||
File fontFile = new File(fontUri); | File fontFile = new File(fontUri); | ||||
long lastModified = (fontFile != null ? fontFile.lastModified() : -1); | long lastModified = (fontFile != null ? fontFile.lastModified() : -1); | ||||
cachedFontFile = new CachedFontFile(lastModified); | cachedFontFile = new CachedFontFile(lastModified); |
// search in font base if it is defined and | // search in font base if it is defined and | ||||
// is a directory but don't recurse | // is a directory but don't recurse | ||||
FontFileFinder fontFileFinder = new FontFileFinder(eventListener); | FontFileFinder fontFileFinder = new FontFileFinder(eventListener); | ||||
URI fontBaseURI = fontManager.getURIResolver().getBaseURI(); | |||||
if (fontBaseURI != null) { | |||||
File fontBase = FileUtils.toFile(fontBaseURI.toURL()); | |||||
if (fontBase != null) { | |||||
List<URL> fontURLList = fontFileFinder.find(fontBase.getAbsolutePath()); | |||||
fontAdder.add(fontURLList, fontInfoList); | |||||
//Can only use the font base URL if it's a file URL | |||||
} | |||||
URI fontBaseURI = fontManager.getResourceResolver().getBaseURI(); | |||||
File fontBase = FileUtils.toFile(fontBaseURI.toURL()); | |||||
if (fontBase != null) { | |||||
List<URL> fontURLList = fontFileFinder.find(fontBase.getAbsolutePath()); | |||||
fontAdder.add(fontURLList, fontInfoList); | |||||
//Can only use the font base URL if it's a file URL | |||||
} | } | ||||
// native o/s font directory finding | // native o/s font directory finding |
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.truetype.TTFFontLoader; | import org.apache.fop.fonts.truetype.TTFFontLoader; | ||||
import org.apache.fop.fonts.type1.Type1FontLoader; | import org.apache.fop.fonts.type1.Type1FontLoader; | ||||
/** URI representing the font file */ | /** URI representing the font file */ | ||||
protected final URI fontFileURI; | protected final URI fontFileURI; | ||||
/** the FontResolver to use for font URI resolution */ | |||||
protected final URIResolverWrapper resolver; | |||||
/** the resource resolver to use for font URI resolution */ | |||||
protected final InternalResourceResolver resourceResolver; | |||||
/** the loaded font */ | /** the loaded font */ | ||||
protected CustomFont returnFont; | protected CustomFont returnFont; | ||||
* @param useKerning indicates whether kerning information shall be loaded if available | * @param useKerning indicates whether kerning information shall be loaded if available | ||||
* @param useAdvanced indicates whether advanced typographic information shall be loaded if | * @param useAdvanced indicates whether advanced typographic information shall be loaded if | ||||
* available | * available | ||||
* @param resolver the font resolver used to resolve URIs | |||||
* @param resourceResolver the font resolver used to resolve URIs | |||||
*/ | */ | ||||
public FontLoader(URI fontFileURI, boolean embedded, boolean useKerning, | public FontLoader(URI fontFileURI, boolean embedded, boolean useKerning, | ||||
boolean useAdvanced, URIResolverWrapper resolver) { | |||||
boolean useAdvanced, InternalResourceResolver resourceResolver) { | |||||
this.fontFileURI = fontFileURI; | this.fontFileURI = fontFileURI; | ||||
this.embedded = embedded; | this.embedded = embedded; | ||||
this.useKerning = useKerning; | this.useKerning = useKerning; | ||||
this.useAdvanced = useAdvanced; | this.useAdvanced = useAdvanced; | ||||
this.resolver = resolver; | |||||
this.resourceResolver = resourceResolver; | |||||
} | } | ||||
private static boolean isType1(URI fontURI) { | private static boolean isType1(URI fontURI) { | ||||
* @param useKerning indicates whether kerning information should be loaded if available | * @param useKerning indicates whether kerning information should be loaded if available | ||||
* @param useAdvanced indicates whether advanced typographic information shall be loaded if | * @param useAdvanced indicates whether advanced typographic information shall be loaded if | ||||
* available | * available | ||||
* @param resolver the font resolver to use when resolving URIs | |||||
* @param resourceResolver the font resolver to use when resolving URIs | |||||
* @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(URI fontFileURI, String subFontName, | public static CustomFont loadFont(URI fontFileURI, String subFontName, | ||||
boolean embedded, EncodingMode encodingMode, boolean useKerning, | boolean embedded, EncodingMode encodingMode, boolean useKerning, | ||||
boolean useAdvanced, URIResolverWrapper resolver) throws IOException { | |||||
boolean useAdvanced, InternalResourceResolver resourceResolver) throws IOException { | |||||
boolean type1 = isType1(fontFileURI); | boolean type1 = isType1(fontFileURI); | ||||
FontLoader loader; | FontLoader loader; | ||||
if (type1) { | if (type1) { | ||||
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(fontFileURI, embedded, useKerning, resolver); | |||||
loader = new Type1FontLoader(fontFileURI, embedded, useKerning, resourceResolver); | |||||
} else { | } else { | ||||
loader = new TTFFontLoader(fontFileURI, subFontName, | loader = new TTFFontLoader(fontFileURI, subFontName, | ||||
embedded, encodingMode, useKerning, useAdvanced, resolver); | |||||
embedded, encodingMode, useKerning, useAdvanced, resourceResolver); | |||||
} | } | ||||
return loader.getFont(); | return loader.getFont(); | ||||
} | } |
import java.util.List; | import java.util.List; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.FontTriplet.Matcher; | import org.apache.fop.fonts.FontTriplet.Matcher; | ||||
import org.apache.fop.fonts.substitute.FontSubstitutions; | import org.apache.fop.fonts.substitute.FontSubstitutions; | ||||
*/ | */ | ||||
public class FontManager { | public class FontManager { | ||||
/** The base URL for all font URL resolutions. */ | |||||
private URIResolverWrapper uriResolver; | |||||
/** The resource resolver */ | |||||
private InternalResourceResolver resourceResolver; | |||||
private final FontDetector fontDetector; | private final FontDetector fontDetector; | ||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* | * | ||||
* @param uriResolver the URI resolver | |||||
* @param resourceResolver the URI resolver | |||||
* @param fontDetector the font detector | * @param fontDetector the font detector | ||||
* @param fontCacheManager the font cache manager | * @param fontCacheManager the font cache manager | ||||
*/ | */ | ||||
public FontManager(URIResolverWrapper uriResolver, FontDetector fontDetector, | |||||
public FontManager(InternalResourceResolver resourceResolver, FontDetector fontDetector, | |||||
FontCacheManager fontCacheManager) { | FontCacheManager fontCacheManager) { | ||||
this.uriResolver = uriResolver; | |||||
this.resourceResolver = resourceResolver; | |||||
this.fontDetector = fontDetector; | this.fontDetector = fontDetector; | ||||
this.fontCacheManager = fontCacheManager; | this.fontCacheManager = fontCacheManager; | ||||
} | } | ||||
/** | /** | ||||
* Sets the font URI resolver | |||||
* @param uriResolver font base URI | |||||
* Sets the font resource resolver | |||||
* @param resourceResolver resource resolver | |||||
*/ | */ | ||||
public void setFontURIResolver(URIResolverWrapper uriResolver) { | |||||
this.uriResolver = uriResolver; | |||||
public void setResourceResolver(InternalResourceResolver resourceResolver) { | |||||
this.resourceResolver = resourceResolver; | |||||
} | } | ||||
public URIResolverWrapper getURIResolver() { | |||||
return this.uriResolver; | |||||
public InternalResourceResolver getResourceResolver() { | |||||
return this.resourceResolver; | |||||
} | } | ||||
/** @return true if kerning on base 14 fonts is enabled */ | /** @return true if kerning on base 14 fonts is enabled */ |
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.ResourceResolver; | import org.apache.fop.apps.io.ResourceResolver; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.substitute.FontSubstitutions; | import org.apache.fop.fonts.substitute.FontSubstitutions; | ||||
import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator; | import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator; | ||||
import org.apache.fop.util.LogUtil; | import org.apache.fop.util.LogUtil; | ||||
private final URI defaultBaseUri; | private final URI defaultBaseUri; | ||||
private final ResourceResolver uriResolver; | |||||
private final ResourceResolver resourceResolver; | |||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* @param cfg the font manager configuration object | * @param cfg the font manager configuration object | ||||
* @param defaultBaseUri the default URI base to use for URI resolution | * @param defaultBaseUri the default URI base to use for URI resolution | ||||
* @param resolver the URI resolver | |||||
* @param resourceResolver the resource resolver | |||||
*/ | */ | ||||
public FontManagerConfigurator(Configuration cfg, URI defaultBaseUri, | public FontManagerConfigurator(Configuration cfg, URI defaultBaseUri, | ||||
ResourceResolver resolver) { | |||||
ResourceResolver resourceResolver) { | |||||
this.cfg = cfg; | this.cfg = cfg; | ||||
this.defaultBaseUri = defaultBaseUri; | this.defaultBaseUri = defaultBaseUri; | ||||
this.uriResolver = resolver; | |||||
this.resourceResolver = resourceResolver; | |||||
} | } | ||||
/** | /** | ||||
} | } | ||||
if (cfg.getChild("font-base", false) != null) { | if (cfg.getChild("font-base", false) != null) { | ||||
try { | try { | ||||
URI fontBase = URIResolverWrapper.getBaseURI(cfg.getChild("font-base").getValue( | |||||
URI fontBase = InternalResourceResolver.getBaseURI(cfg.getChild("font-base").getValue( | |||||
null)); | null)); | ||||
fontManager.setFontURIResolver(new URIResolverWrapper( | |||||
defaultBaseUri.resolve(fontBase), uriResolver)); | |||||
fontManager.setResourceResolver(new InternalResourceResolver( | |||||
defaultBaseUri.resolve(fontBase), resourceResolver)); | |||||
} catch (URISyntaxException use) { | } catch (URISyntaxException use) { | ||||
LogUtil.handleException(log, use, true); | LogUtil.handleException(log, use, true); | ||||
} | } | ||||
} else { | } else { | ||||
fontManager.setFontURIResolver(new URIResolverWrapper(defaultBaseUri, uriResolver)); | |||||
fontManager.setResourceResolver(new InternalResourceResolver(defaultBaseUri, resourceResolver)); | |||||
} | } | ||||
// [GA] permit configuration control over base14 kerning; without this, | // [GA] permit configuration control over base14 kerning; without this, |
import org.xml.sax.helpers.DefaultHandler; | import org.xml.sax.helpers.DefaultHandler; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.apps.TTFReader; | import org.apache.fop.fonts.apps.TTFReader; | ||||
/** | /** | ||||
private CustomFont returnFont; | private CustomFont returnFont; | ||||
private MultiByteFont multiFont; | private MultiByteFont multiFont; | ||||
private SingleByteFont singleFont; | private SingleByteFont singleFont; | ||||
private final URIResolverWrapper resolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private StringBuffer text = new StringBuffer(); | private StringBuffer text = new StringBuffer(); | ||||
private List<Integer> cidWidths; | private List<Integer> cidWidths; | ||||
* @param source Source of the font metric file | * @param source Source of the font metric file | ||||
* @throws FOPException if loading the font fails | * @throws FOPException if loading the font fails | ||||
*/ | */ | ||||
public FontReader(InputSource source, URIResolverWrapper resolver) throws FOPException { | |||||
this.resolver = resolver; | |||||
public FontReader(InputSource source, InternalResourceResolver resourceResolver) throws FOPException { | |||||
this.resourceResolver = resourceResolver; | |||||
createFont(source); | createFont(source); | ||||
} | } | ||||
throws SAXException { | throws SAXException { | ||||
if (localName.equals("font-metrics")) { | if (localName.equals("font-metrics")) { | ||||
if ("TYPE0".equals(attributes.getValue("type"))) { | if ("TYPE0".equals(attributes.getValue("type"))) { | ||||
multiFont = new MultiByteFont(resolver); | |||||
multiFont = new MultiByteFont(resourceResolver); | |||||
returnFont = multiFont; | returnFont = multiFont; | ||||
isCID = true; | isCID = true; | ||||
TTFReader.checkMetricsVersion(attributes); | TTFReader.checkMetricsVersion(attributes); | ||||
} else if ("TRUETYPE".equals(attributes.getValue("type"))) { | } else if ("TRUETYPE".equals(attributes.getValue("type"))) { | ||||
singleFont = new SingleByteFont(resolver); | |||||
singleFont = new SingleByteFont(resourceResolver); | |||||
singleFont.setFontType(FontType.TRUETYPE); | singleFont.setFontType(FontType.TRUETYPE); | ||||
returnFont = singleFont; | returnFont = singleFont; | ||||
isCID = false; | isCID = false; | ||||
TTFReader.checkMetricsVersion(attributes); | TTFReader.checkMetricsVersion(attributes); | ||||
} else { | } else { | ||||
singleFont = new SingleByteFont(resolver); | |||||
singleFont = new SingleByteFont(resourceResolver); | |||||
singleFont.setFontType(FontType.TYPE1); | singleFont.setFontType(FontType.TYPE1); | ||||
returnFont = singleFont; | returnFont = singleFont; | ||||
isCID = false; | isCID = false; | ||||
} | } | ||||
} else if ("embed".equals(localName)) { | } else if ("embed".equals(localName)) { | ||||
try { | try { | ||||
returnFont.setEmbedURI(URIResolverWrapper.cleanURI(attributes.getValue("file"))); | |||||
returnFont.setEmbedURI(InternalResourceResolver.cleanURI(attributes.getValue("file"))); | |||||
} catch (URISyntaxException e) { | } catch (URISyntaxException e) { | ||||
// TODO: dunno what to do here?!?! | // TODO: dunno what to do here?!?! | ||||
} | } |
// FOP (base 14 fonts) | // FOP (base 14 fonts) | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.base14.Courier; | import org.apache.fop.fonts.base14.Courier; | ||||
import org.apache.fop.fonts.base14.CourierBold; | import org.apache.fop.fonts.base14.CourierBold; | ||||
import org.apache.fop.fonts.base14.CourierBoldOblique; | import org.apache.fop.fonts.base14.CourierBoldOblique; | ||||
* | * | ||||
* @param fontInfo the font info object to set up | * @param fontInfo the font info object to set up | ||||
* @param embedFontInfoList a list of EmbedFontInfo objects | * @param embedFontInfoList a list of EmbedFontInfo objects | ||||
* @param resolver the font resolver | |||||
* @param resourceResolver the font resolver | |||||
* @param base14Kerning true if base14 kerning applies | * @param base14Kerning true if base14 kerning applies | ||||
*/ | */ | ||||
public static void setup(FontInfo fontInfo, List embedFontInfoList, | public static void setup(FontInfo fontInfo, List embedFontInfoList, | ||||
URIResolverWrapper resolver, boolean base14Kerning) { | |||||
InternalResourceResolver resourceResolver, boolean base14Kerning) { | |||||
fontInfo.addMetrics("F1", new Helvetica(base14Kerning)); | fontInfo.addMetrics("F1", new Helvetica(base14Kerning)); | ||||
fontInfo.addMetrics("F2", new HelveticaOblique(base14Kerning)); | fontInfo.addMetrics("F2", new HelveticaOblique(base14Kerning)); | ||||
fontInfo.addMetrics("F3", new HelveticaBold(base14Kerning)); | fontInfo.addMetrics("F3", new HelveticaBold(base14Kerning)); | ||||
final int startNum = 15; | final int startNum = 15; | ||||
/* Add configured fonts */ | /* Add configured fonts */ | ||||
addConfiguredFonts(fontInfo, embedFontInfoList, startNum, resolver, base14Kerning); | |||||
addConfiguredFonts(fontInfo, embedFontInfoList, startNum, resourceResolver, base14Kerning); | |||||
} | } | ||||
/** | /** | ||||
* @param fontInfo the font info to set up | * @param fontInfo the font info to set up | ||||
* @param embedFontInfoList a list of EmbedFontInfo objects | * @param embedFontInfoList a list of EmbedFontInfo objects | ||||
* @param num starting index for internal font numbering | * @param num starting index for internal font numbering | ||||
* @param resolver the font resolver | |||||
* @param resourceResolver the font resolver | |||||
*/ | */ | ||||
private static void addConfiguredFonts(FontInfo fontInfo, | private static void addConfiguredFonts(FontInfo fontInfo, | ||||
List<EmbedFontInfo> embedFontInfoList, int num, URIResolverWrapper resolver, | |||||
List<EmbedFontInfo> embedFontInfoList, int num, InternalResourceResolver resourceResolver, | |||||
boolean base14Kerning) { | boolean base14Kerning) { | ||||
if (embedFontInfoList == null) { | if (embedFontInfoList == null) { | ||||
return; //No fonts to process | return; //No fonts to process | ||||
} | } | ||||
assert resolver != null; | |||||
assert resourceResolver != null; | |||||
String internalName = null; | String internalName = null; | ||||
internalName = "F" + num; | internalName = "F" + num; | ||||
num++; | num++; | ||||
LazyFont font = new LazyFont(embedFontInfo, resolver, false); | |||||
LazyFont font = new LazyFont(embedFontInfo, resourceResolver, false); | |||||
fontInfo.addMetrics(internalName, font); | fontInfo.addMetrics(internalName, font); | ||||
List<FontTriplet> triplets = embedFontInfo.getFontTriplets(); | List<FontTriplet> triplets = embedFontInfo.getFontTriplets(); |
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.complexscripts.fonts.Positionable; | import org.apache.fop.complexscripts.fonts.Positionable; | ||||
import org.apache.fop.complexscripts.fonts.Substitutable; | import org.apache.fop.complexscripts.fonts.Substitutable; | ||||
private final EncodingMode encodingMode; | private final EncodingMode encodingMode; | ||||
private final boolean embedded; | private final boolean embedded; | ||||
private final String subFontName; | private final String subFontName; | ||||
private final URIResolverWrapper resolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private boolean isMetricsLoaded; | private boolean isMetricsLoaded; | ||||
private Typeface realFont; | private Typeface realFont; | ||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* @param fontInfo the font info to embed | * @param fontInfo the font info to embed | ||||
* @param resolver the font resolver to handle font URIs | |||||
* @param resourceResolver the font resolver to handle font URIs | |||||
*/ | */ | ||||
public LazyFont(EmbedFontInfo fontInfo, URIResolverWrapper resolver, boolean useComplexScripts) { | |||||
public LazyFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver, | |||||
boolean useComplexScripts) { | |||||
this.metricsURI = fontInfo.getMetricsURI(); | this.metricsURI = fontInfo.getMetricsURI(); | ||||
this.fontEmbedURI = fontInfo.getEmbedURI(); | this.fontEmbedURI = fontInfo.getEmbedURI(); | ||||
this.useKerning = fontInfo.getKerning(); | this.useKerning = fontInfo.getKerning(); | ||||
if (resolver != null) { | |||||
if (resourceResolver != null) { | |||||
this.useAdvanced = useComplexScripts; | this.useAdvanced = useComplexScripts; | ||||
} else { | } else { | ||||
this.useAdvanced = fontInfo.getAdvanced(); | this.useAdvanced = fontInfo.getAdvanced(); | ||||
: EncodingMode.AUTO; | : EncodingMode.AUTO; | ||||
this.subFontName = fontInfo.getSubFontName(); | this.subFontName = fontInfo.getSubFontName(); | ||||
this.embedded = fontInfo.isEmbedded(); | this.embedded = fontInfo.isEmbedded(); | ||||
this.resolver = resolver; | |||||
this.resourceResolver = resourceResolver; | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
if (metricsURI != null) { | if (metricsURI != null) { | ||||
/**@todo Possible thread problem here */ | /**@todo Possible thread problem here */ | ||||
FontReader reader = null; | FontReader reader = null; | ||||
InputStream in = resolver.resolveIn(metricsURI); | |||||
InputStream in = resourceResolver.getResource(metricsURI); | |||||
InputSource src = new InputSource(in); | InputSource src = new InputSource(in); | ||||
src.setSystemId(metricsURI.toASCIIString()); | src.setSystemId(metricsURI.toASCIIString()); | ||||
reader = new FontReader(src, resolver); | |||||
reader = new FontReader(src, resourceResolver); | |||||
reader.setKerningEnabled(useKerning); | reader.setKerningEnabled(useKerning); | ||||
reader.setAdvancedEnabled(useAdvanced); | reader.setAdvancedEnabled(useAdvanced); | ||||
if (this.embedded) { | if (this.embedded) { | ||||
throw new RuntimeException("Cannot load font. No font URIs available."); | throw new RuntimeException("Cannot load font. No font URIs available."); | ||||
} | } | ||||
realFont = FontLoader.loadFont(fontEmbedURI, this.subFontName, | realFont = FontLoader.loadFont(fontEmbedURI, this.subFontName, | ||||
this.embedded, this.encodingMode, useKerning, useAdvanced, resolver); | |||||
this.embedded, this.encodingMode, useKerning, useAdvanced, resourceResolver); | |||||
} | } | ||||
if (realFont instanceof FontDescriptor) { | if (realFont instanceof FontDescriptor) { | ||||
realFontDescriptor = (FontDescriptor) realFont; | realFontDescriptor = (FontDescriptor) realFont; |
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.complexscripts.fonts.GlyphDefinitionTable; | import org.apache.fop.complexscripts.fonts.GlyphDefinitionTable; | ||||
import org.apache.fop.complexscripts.fonts.GlyphPositioningTable; | import org.apache.fop.complexscripts.fonts.GlyphPositioningTable; | ||||
import org.apache.fop.complexscripts.fonts.GlyphSubstitutionTable; | import org.apache.fop.complexscripts.fonts.GlyphSubstitutionTable; | ||||
private int lastUnmapped; | private int lastUnmapped; | ||||
/** | /** | ||||
* @param resolver the URI resolver for controlling file access | |||||
* @param resourceResolver the resource resolver for accessing the font | |||||
*/ | */ | ||||
public MultiByteFont(URIResolverWrapper resolver) { | |||||
super(resolver); | |||||
public MultiByteFont(InternalResourceResolver resourceResolver) { | |||||
super(resourceResolver); | |||||
subset.setupFirstGlyph(); | subset.setupFirstGlyph(); | ||||
setFontType(FontType.TYPE0); | setFontType(FontType.TYPE0); | ||||
} | } |
import org.apache.xmlgraphics.fonts.Glyphs; | import org.apache.xmlgraphics.fonts.Glyphs; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
* Generic SingleByte font | * Generic SingleByte font | ||||
/** | /** | ||||
* @param resolver the URI resolver for controlling file access | |||||
* @param resourceResolver the URI resolver for controlling file access | |||||
*/ | */ | ||||
public SingleByteFont(URIResolverWrapper resolver) { | |||||
super(resolver); | |||||
public SingleByteFont(InternalResourceResolver resourceResolver) { | |||||
super(resourceResolver); | |||||
setEncoding(CodePointMapping.WIN_ANSI_ENCODING); | setEncoding(CodePointMapping.WIN_ANSI_ENCODING); | ||||
} | } | ||||
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.CustomFont; | import org.apache.fop.fonts.CustomFont; | ||||
import org.apache.fop.fonts.EmbedFontInfo; | import org.apache.fop.fonts.EmbedFontInfo; | ||||
import org.apache.fop.fonts.EncodingMode; | import org.apache.fop.fonts.EncodingMode; | ||||
return style; | return style; | ||||
} | } | ||||
/** | |||||
* Attempts to determine FontInfo from a given custom font | |||||
* @param fontUri the font URI | |||||
* @param customFont the custom font | |||||
* @param fontCache font cache (may be null) | |||||
* @return FontInfo from the given custom font | |||||
*/ | |||||
private EmbedFontInfo getFontInfoFromCustomFont(URI fontUri, CustomFont customFont, | private EmbedFontInfo getFontInfoFromCustomFont(URI fontUri, CustomFont customFont, | ||||
FontCache fontCache, URIResolverWrapper resolver) { | |||||
FontCache fontCache, InternalResourceResolver resourceResolver) { | |||||
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; | ||||
customFont.isAdvancedEnabled(), fontTripletList, fontUri, subFontName); | customFont.isAdvancedEnabled(), fontTripletList, fontUri, subFontName); | ||||
fontInfo.setPostScriptName(customFont.getFontName()); | fontInfo.setPostScriptName(customFont.getFontName()); | ||||
if (fontCache != null) { | if (fontCache != null) { | ||||
fontCache.addFont(fontInfo, resolver); | |||||
fontCache.addFont(fontInfo, resourceResolver); | |||||
} | } | ||||
return fontInfo; | return fontInfo; | ||||
} | } | ||||
* Attempts to determine EmbedFontInfo from a given font file. | * Attempts to determine EmbedFontInfo from a given font file. | ||||
* | * | ||||
* @param fontURI the URI of the font resource | * @param fontURI the URI of the font resource | ||||
* @param resolver font resolver used to resolve font | |||||
* @param resourceResolver font resolver used to resolve font | |||||
* @param fontCache font cache (may be null) | * @param fontCache font cache (may be null) | ||||
* @return an array of newly created embed font info. Generally, this array | * @return an array of newly created embed font info. Generally, this array | ||||
* will have only one entry, unless the fontUrl is a TrueType Collection | * will have only one entry, unless the fontUrl is a TrueType Collection | ||||
*/ | */ | ||||
public EmbedFontInfo[] find(URI fontURI, URIResolverWrapper resolver, FontCache fontCache) { | |||||
URI embedUri = resolver.getBaseURI().resolve(fontURI); | |||||
public EmbedFontInfo[] find(URI fontURI, InternalResourceResolver resourceResolver, FontCache fontCache) { | |||||
URI embedUri = resourceResolver.resolveFromBase(fontURI); | |||||
String embedStr = embedUri.toASCIIString(); | String embedStr = embedUri.toASCIIString(); | ||||
boolean useKerning = true; | boolean useKerning = true; | ||||
boolean useAdvanced = true; | boolean useAdvanced = true; | ||||
List<String> ttcNames = null; | List<String> ttcNames = null; | ||||
InputStream in = null; | InputStream in = null; | ||||
try { | try { | ||||
in = resolver.resolveIn(fontURI); | |||||
in = resourceResolver.getResource(fontURI); | |||||
TTFFile ttf = new TTFFile(false, false); | TTFFile ttf = new TTFFile(false, false); | ||||
FontFileReader reader = new FontFileReader(in); | FontFileReader reader = new FontFileReader(in); | ||||
ttcNames = ttf.getTTCnames(reader); | ttcNames = ttf.getTTCnames(reader); | ||||
} | } | ||||
try { | try { | ||||
TTFFontLoader ttfLoader = new TTFFontLoader(fontURI, fontName, true, | TTFFontLoader ttfLoader = new TTFFontLoader(fontURI, fontName, true, | ||||
EncodingMode.AUTO, useKerning, useAdvanced, resolver); | |||||
EncodingMode.AUTO, useKerning, useAdvanced, resourceResolver); | |||||
customFont = ttfLoader.getFont(); | customFont = ttfLoader.getFont(); | ||||
if (this.eventListener != null) { | if (this.eventListener != null) { | ||||
customFont.setEventListener(this.eventListener); | customFont.setEventListener(this.eventListener); | ||||
continue; | continue; | ||||
} | } | ||||
EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache, | EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache, | ||||
resolver); | |||||
resourceResolver); | |||||
if (fi != null) { | if (fi != null) { | ||||
embedFontInfoList.add(fi); | embedFontInfoList.add(fi); | ||||
} | } | ||||
// The normal case | // The normal case | ||||
try { | try { | ||||
customFont = FontLoader.loadFont(fontURI, null, true, EncodingMode.AUTO, | customFont = FontLoader.loadFont(fontURI, null, true, EncodingMode.AUTO, | ||||
useKerning, useAdvanced, resolver); | |||||
useKerning, useAdvanced, resourceResolver); | |||||
if (this.eventListener != null) { | if (this.eventListener != null) { | ||||
customFont.setEventListener(this.eventListener); | customFont.setEventListener(this.eventListener); | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache, resolver); | |||||
EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache, resourceResolver); | |||||
if (fi != null) { | if (fi != null) { | ||||
return new EmbedFontInfo[] {fi}; | return new EmbedFontInfo[] {fi}; | ||||
} else { | } else { |
import org.apache.xmlgraphics.fonts.Glyphs; | import org.apache.xmlgraphics.fonts.Glyphs; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.BFEntry; | import org.apache.fop.fonts.BFEntry; | ||||
import org.apache.fop.fonts.CIDFontType; | import org.apache.fop.fonts.CIDFontType; | ||||
import org.apache.fop.fonts.EncodingMode; | import org.apache.fop.fonts.EncodingMode; | ||||
/** | /** | ||||
* Default constructor | * Default constructor | ||||
* @param fontFileURI the URI representing the font file | * @param fontFileURI the URI representing the font file | ||||
* @param resolver the FontResolver for font URI resolution | |||||
* @param resourceResolver the resource resolver for font URI resolution | |||||
*/ | */ | ||||
public TTFFontLoader(URI fontFileURI, URIResolverWrapper resolver) { | |||||
this(fontFileURI, null, true, EncodingMode.AUTO, true, true, resolver); | |||||
public TTFFontLoader(URI fontFileURI, InternalResourceResolver resourceResolver) { | |||||
this(fontFileURI, null, true, EncodingMode.AUTO, true, true, resourceResolver); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public TTFFontLoader(URI fontFileURI, String subFontName, | public TTFFontLoader(URI fontFileURI, String subFontName, | ||||
boolean embedded, EncodingMode encodingMode, boolean useKerning, | boolean embedded, EncodingMode encodingMode, boolean useKerning, | ||||
boolean useAdvanced, URIResolverWrapper resolver) { | |||||
boolean useAdvanced, InternalResourceResolver resolver) { | |||||
super(fontFileURI, embedded, useKerning, useAdvanced, resolver); | super(fontFileURI, embedded, useKerning, useAdvanced, resolver); | ||||
this.subFontName = subFontName; | this.subFontName = subFontName; | ||||
this.encodingMode = encodingMode; | this.encodingMode = encodingMode; | ||||
* @throws IOException if an I/O error occurs | * @throws IOException if an I/O error occurs | ||||
*/ | */ | ||||
private void read(String ttcFontName) throws IOException { | private void read(String ttcFontName) throws IOException { | ||||
InputStream in = resolver.resolveIn(this.fontFileURI); | |||||
InputStream in = resourceResolver.getResource(this.fontFileURI); | |||||
try { | try { | ||||
TTFFile ttf = new TTFFile(useKerning, useAdvanced); | TTFFile ttf = new TTFFile(useKerning, useAdvanced); | ||||
FontFileReader reader = new FontFileReader(in); | FontFileReader reader = new FontFileReader(in); | ||||
} | } | ||||
if (isCid) { | if (isCid) { | ||||
multiFont = new MultiByteFont(resolver); | |||||
multiFont = new MultiByteFont(resourceResolver); | |||||
returnFont = multiFont; | returnFont = multiFont; | ||||
multiFont.setTTCName(ttcFontName); | multiFont.setTTCName(ttcFontName); | ||||
} else { | } else { | ||||
singleFont = new SingleByteFont(resolver); | |||||
singleFont = new SingleByteFont(resourceResolver); | |||||
returnFont = singleFont; | returnFont = singleFont; | ||||
} | } | ||||
import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.CodePointMapping; | import org.apache.fop.fonts.CodePointMapping; | ||||
import org.apache.fop.fonts.FontLoader; | import org.apache.fop.fonts.FontLoader; | ||||
import org.apache.fop.fonts.FontType; | import org.apache.fop.fonts.FontType; | ||||
* @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 embedded indicates whether the font is embedded or referenced | * @param embedded indicates whether the font is embedded or referenced | ||||
* @param useKerning indicates whether to load kerning information if available | * @param useKerning indicates whether to load kerning information if available | ||||
* @param resolver 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(URI fontFileURI, boolean embedded, boolean useKerning, | public Type1FontLoader(URI fontFileURI, boolean embedded, boolean useKerning, | ||||
URIResolverWrapper resolver) throws IOException { | |||||
super(fontFileURI, embedded, useKerning, true, resolver); | |||||
InternalResourceResolver resourceResolver) throws IOException { | |||||
super(fontFileURI, embedded, useKerning, true, resourceResolver); | |||||
} | } | ||||
private String getPFMURI(String pfbURI) { | private String getPFMURI(String pfbURI) { | ||||
for (int i = 0; i < AFM_EXTENSIONS.length; i++) { | for (int i = 0; i < AFM_EXTENSIONS.length; i++) { | ||||
try { | try { | ||||
afmUri = partialAfmUri + AFM_EXTENSIONS[i]; | afmUri = partialAfmUri + AFM_EXTENSIONS[i]; | ||||
afmIn = resolver.resolveIn(afmUri); | |||||
afmIn = resourceResolver.getResource(afmUri); | |||||
if (afmIn != null) { | if (afmIn != null) { | ||||
break; | break; | ||||
} | } | ||||
String pfmUri = getPFMURI(fontFileStr); | String pfmUri = getPFMURI(fontFileStr); | ||||
InputStream pfmIn = null; | InputStream pfmIn = null; | ||||
try { | try { | ||||
pfmIn = resolver.resolveIn(pfmUri); | |||||
pfmIn = resourceResolver.getResource(pfmUri); | |||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
// Ignore, PFM probably not available under the URI | // Ignore, PFM probably not available under the URI | ||||
} catch (URISyntaxException e) { | } catch (URISyntaxException e) { | ||||
if (afm == null && pfm == null) { | if (afm == null && pfm == null) { | ||||
throw new IllegalArgumentException("Need at least an AFM or a PFM!"); | throw new IllegalArgumentException("Need at least an AFM or a PFM!"); | ||||
} | } | ||||
singleFont = new SingleByteFont(resolver); | |||||
singleFont = new SingleByteFont(resourceResolver); | |||||
singleFont.setFontType(FontType.TYPE1); | singleFont.setFontType(FontType.TYPE1); | ||||
if (this.embedded) { | if (this.embedded) { | ||||
singleFont.setEmbedURI(this.fontFileURI); | singleFont.setEmbedURI(this.fontFileURI); |
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
* <p>This class is the main entry point to the hyphenation package. | * <p>This class is the main entry point to the hyphenation package. | ||||
* The hyphenation trees are cached. | * The hyphenation trees are cached. | ||||
* @param lang the language | * @param lang the language | ||||
* @param country the country (may be null or "none") | * @param country the country (may be null or "none") | ||||
* @param resolver resolver to find the hyphenation files | |||||
* @param resourceResolver resolver to find the hyphenation files | |||||
* @param hyphPatNames the map with user-configured hyphenation pattern file names | * @param hyphPatNames the map with user-configured hyphenation pattern file names | ||||
* @return the hyphenation tree | * @return the hyphenation tree | ||||
*/ | */ | ||||
public static HyphenationTree getHyphenationTree(String lang, | public static HyphenationTree getHyphenationTree(String lang, | ||||
String country, URIResolverWrapper resolver, Map hyphPatNames) { | |||||
String country, InternalResourceResolver resourceResolver, Map hyphPatNames) { | |||||
String llccKey = HyphenationTreeCache.constructLlccKey(lang, country); | String llccKey = HyphenationTreeCache.constructLlccKey(lang, country); | ||||
HyphenationTreeCache cache = getHyphenationTreeCache(); | HyphenationTreeCache cache = getHyphenationTreeCache(); | ||||
return null; | return null; | ||||
} | } | ||||
HyphenationTree hTree = getHyphenationTree2(lang, country, resolver, hyphPatNames); | |||||
HyphenationTree hTree = getHyphenationTree2(lang, country, resourceResolver, hyphPatNames); | |||||
// fallback to lang only | // fallback to lang only | ||||
if (hTree == null && country != null && !country.equals("none")) { | if (hTree == null && country != null && !country.equals("none")) { | ||||
String llKey = HyphenationTreeCache.constructLlccKey(lang, null); | String llKey = HyphenationTreeCache.constructLlccKey(lang, null); | ||||
if (!cache.isMissing(llKey)) { | if (!cache.isMissing(llKey)) { | ||||
hTree = getHyphenationTree2(lang, null, resolver, hyphPatNames); | |||||
hTree = getHyphenationTree2(lang, null, resourceResolver, hyphPatNames); | |||||
if (hTree != null && log.isDebugEnabled()) { | if (hTree != null && log.isDebugEnabled()) { | ||||
log.debug("Couldn't find hyphenation pattern " | log.debug("Couldn't find hyphenation pattern " | ||||
+ "for lang=\"" + lang + "\",country=\"" + country + "\"." | + "for lang=\"" + lang + "\",country=\"" + country + "\"." | ||||
* The hyphenation trees are cached. | * The hyphenation trees are cached. | ||||
* @param lang the language | * @param lang the language | ||||
* @param country the country (may be null or "none") | * @param country the country (may be null or "none") | ||||
* @param resolver resolver to find the hyphenation files | |||||
* @param resourceResolver resource resolver to find the hyphenation files | |||||
* @param hyphPatNames the map with user-configured hyphenation pattern file names | * @param hyphPatNames the map with user-configured hyphenation pattern file names | ||||
* @return the hyphenation tree | * @return the hyphenation tree | ||||
*/ | */ | ||||
public static HyphenationTree getHyphenationTree2(String lang, | public static HyphenationTree getHyphenationTree2(String lang, | ||||
String country, URIResolverWrapper resolver, Map hyphPatNames) { | |||||
String country, InternalResourceResolver resourceResolver, Map hyphPatNames) { | |||||
String llccKey = HyphenationTreeCache.constructLlccKey(lang, country); | String llccKey = HyphenationTreeCache.constructLlccKey(lang, country); | ||||
HyphenationTreeCache cache = getHyphenationTreeCache(); | HyphenationTreeCache cache = getHyphenationTreeCache(); | ||||
key = llccKey; | key = llccKey; | ||||
} | } | ||||
if (resolver != null) { | |||||
hTree = getUserHyphenationTree(key, resolver); | |||||
if (resourceResolver != null) { | |||||
hTree = getUserHyphenationTree(key, resourceResolver); | |||||
} | } | ||||
if (hTree == null) { | if (hTree == null) { | ||||
hTree = getFopHyphenationTree(key); | hTree = getFopHyphenationTree(key); | ||||
* Load tree from serialized file or xml file | * Load tree from serialized file or xml file | ||||
* using configuration settings | * using configuration settings | ||||
* @param key language key for the requested hyphenation file | * @param key language key for the requested hyphenation file | ||||
* @param resolver resolver to find the hyphenation files | |||||
* @param resourceResolver resource resolver to find the hyphenation files | |||||
* @return the requested HypenationTree or null if it is not available | * @return the requested HypenationTree or null if it is not available | ||||
*/ | */ | ||||
public static HyphenationTree getUserHyphenationTree(String key, | public static HyphenationTree getUserHyphenationTree(String key, | ||||
URIResolverWrapper resolver) { | |||||
InternalResourceResolver resourceResolver) { | |||||
HyphenationTree hTree = null; | HyphenationTree hTree = null; | ||||
// I use here the following convention. The file name specified in | // I use here the following convention. The file name specified in | ||||
// the configuration is taken as the base name. First we try | // the configuration is taken as the base name. First we try | ||||
// first try serialized object | // first try serialized object | ||||
String name = key + ".hyp"; | String name = key + ".hyp"; | ||||
try { | try { | ||||
InputStream in = getHyphenationTreeStream(name, resolver); | |||||
InputStream in = getHyphenationTreeStream(name, resourceResolver); | |||||
try { | try { | ||||
hTree = readHyphenationTree(in); | hTree = readHyphenationTree(in); | ||||
} finally { | } finally { | ||||
name = key + ".xml"; | name = key + ".xml"; | ||||
hTree = new HyphenationTree(); | hTree = new HyphenationTree(); | ||||
try { | try { | ||||
InputStream in = getHyphenationTreeStream(name, resolver); | |||||
InputStream in = getHyphenationTreeStream(name, resourceResolver); | |||||
try { | try { | ||||
InputSource src = new InputSource(in); | InputSource src = new InputSource(in); | ||||
src.setSystemId(name); | src.setSystemId(name); | ||||
} | } | ||||
} | } | ||||
private static InputStream getHyphenationTreeStream(String name, URIResolverWrapper resolver) | |||||
throws IOException { | |||||
private static InputStream getHyphenationTreeStream(String name, | |||||
InternalResourceResolver resourceResolver) throws IOException { | |||||
try { | try { | ||||
return new BufferedInputStream(resolver.resolveIn(name)); | |||||
return new BufferedInputStream(resourceResolver.getResource(name)); | |||||
} catch (URISyntaxException use) { | } catch (URISyntaxException use) { | ||||
log.debug("An exception was thrown while attempting to load " + name, use); | log.debug("An exception was thrown while attempting to load " + name, use); | ||||
} | } | ||||
* Hyphenates a word. | * Hyphenates a word. | ||||
* @param lang the language | * @param lang the language | ||||
* @param country the optional country code (may be null or "none") | * @param country the optional country code (may be null or "none") | ||||
* @param resolver resolver to find the hyphenation files | |||||
* @param resourceResolver resource resolver to find the hyphenation files | |||||
* @param hyphPatNames the map with user-configured hyphenation pattern file names | * @param hyphPatNames the map with user-configured hyphenation pattern file names | ||||
* @param word the word to hyphenate | * @param word the word to hyphenate | ||||
* @param leftMin the minimum number of characters before the hyphenation point | * @param leftMin the minimum number of characters before the hyphenation point | ||||
* @return the hyphenation result | * @return the hyphenation result | ||||
*/ | */ | ||||
public static Hyphenation hyphenate(String lang, String country, | public static Hyphenation hyphenate(String lang, String country, | ||||
URIResolverWrapper resolver, Map hyphPatNames, String word, int leftMin, int rightMin) { | |||||
HyphenationTree hTree = getHyphenationTree(lang, country, resolver, hyphPatNames); | |||||
InternalResourceResolver resourceResolver, Map hyphPatNames, String word, int leftMin, | |||||
int rightMin) { | |||||
HyphenationTree hTree = getHyphenationTree(lang, country, resourceResolver, hyphPatNames); | |||||
if (hTree == null) { | if (hTree == null) { | ||||
return null; | return null; | ||||
} | } |
// on an inline or wrapper below the block level. | // on an inline or wrapper below the block level. | ||||
Hyphenation hyph = Hyphenator.hyphenate(hyphenationProperties.language.getString(), | Hyphenation hyph = Hyphenator.hyphenate(hyphenationProperties.language.getString(), | ||||
hyphenationProperties.country.getString(), | hyphenationProperties.country.getString(), | ||||
getFObj().getUserAgent().getNewURIResolver(), | |||||
getFObj().getUserAgent().getResourceResolver(), | |||||
getFObj().getUserAgent().getHyphPatNames(), | getFObj().getUserAgent().getHyphPatNames(), | ||||
sbChars.toString(), | sbChars.toString(), | ||||
hyphenationProperties.hyphenationRemainCharacterCount.getValue(), | hyphenationProperties.hyphenationRemainCharacterCount.getValue(), |
FontManager fontManager = userAgent.getFontManager(); | FontManager fontManager = userAgent.getFontManager(); | ||||
FontCollection[] fontCollections = new FontCollection[] { | FontCollection[] fontCollections = new FontCollection[] { | ||||
new Base14FontCollection(fontManager.isBase14KerningEnabled()), | new Base14FontCollection(fontManager.isBase14KerningEnabled()), | ||||
new CustomFontCollection(fontManager.getURIResolver(), getFontList(), | |||||
new CustomFontCollection(fontManager.getResourceResolver(), getFontList(), | |||||
userAgent.isComplexScriptFeaturesEnabled()) | userAgent.isComplexScriptFeaturesEnabled()) | ||||
}; | }; | ||||
fontManager.setup(getFontInfo(), fontCollections); | fontManager.setup(getFontInfo(), fontCollections); |
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.FOUserAgent; | import org.apache.fop.apps.FOUserAgent; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.CustomFontCollection; | import org.apache.fop.fonts.CustomFontCollection; | ||||
import org.apache.fop.fonts.DefaultFontConfigurator; | import org.apache.fop.fonts.DefaultFontConfigurator; | ||||
import org.apache.fop.fonts.EmbedFontInfo; | import org.apache.fop.fonts.EmbedFontInfo; | ||||
public void setupFontInfo(String mimeType, FontInfo fontInfo) throws FOPException { | public void setupFontInfo(String mimeType, FontInfo fontInfo) throws FOPException { | ||||
FontManager fontManager = userAgent.getFontManager(); | FontManager fontManager = userAgent.getFontManager(); | ||||
List<FontCollection> fontCollections = getDefaultFontCollection(); | List<FontCollection> fontCollections = getDefaultFontCollection(); | ||||
fontCollections.add(getCustomFontCollection(fontManager.getURIResolver(), mimeType)); | |||||
fontCollections.add(getCustomFontCollection(fontManager.getResourceResolver(), mimeType)); | |||||
fontManager.setup(fontInfo, fontCollections.toArray(new FontCollection[fontCollections.size()])); | fontManager.setup(fontInfo, fontCollections.toArray(new FontCollection[fontCollections.size()])); | ||||
} | } | ||||
protected abstract List<FontCollection> getDefaultFontCollection(); | protected abstract List<FontCollection> getDefaultFontCollection(); | ||||
protected FontCollection getCustomFontCollection(URIResolverWrapper uriResolverWrapper, String mimeType) | |||||
protected FontCollection getCustomFontCollection(InternalResourceResolver resolver, String mimeType) | |||||
throws FOPException { | throws FOPException { | ||||
List<EmbedFontInfo> fontList; | List<EmbedFontInfo> fontList; | ||||
if (rendererConfigParser == null) { | if (rendererConfigParser == null) { | ||||
} else { | } else { | ||||
fontList = fontInfoConfigurator.configure(getRendererConfig(mimeType).getFontInfoConfig()); | fontList = fontInfoConfigurator.configure(getRendererConfig(mimeType).getFontInfoConfig()); | ||||
} | } | ||||
return createCollectionFromFontList(uriResolverWrapper, fontList); | |||||
return createCollectionFromFontList(resolver, fontList); | |||||
} | } | ||||
protected FontCollection createCollectionFromFontList(URIResolverWrapper uriResolverWrapper, | |||||
protected FontCollection createCollectionFromFontList(InternalResourceResolver resolver, | |||||
List<EmbedFontInfo> fontList) { | List<EmbedFontInfo> fontList) { | ||||
return new CustomFontCollection(uriResolverWrapper, fontList, | |||||
return new CustomFontCollection(resolver, fontList, | |||||
userAgent.isComplexScriptFeaturesEnabled()); | userAgent.isComplexScriptFeaturesEnabled()); | ||||
} | } | ||||
*/ | */ | ||||
public AFPDocumentHandler(IFContext context) { | public AFPDocumentHandler(IFContext context) { | ||||
super(context); | super(context); | ||||
this.resourceManager = new AFPResourceManager(context.getUserAgent().getNewURIResolver()); | |||||
this.resourceManager = new AFPResourceManager(context.getUserAgent().getResourceResolver()); | |||||
this.paintingState = new AFPPaintingState(); | this.paintingState = new AFPPaintingState(); | ||||
this.unitConv = paintingState.getUnitConverter(); | this.unitConv = paintingState.getUnitConverter(); | ||||
} | } | ||||
} else if (extension instanceof AFPIncludeFormMap) { | } else if (extension instanceof AFPIncludeFormMap) { | ||||
AFPIncludeFormMap formMap = (AFPIncludeFormMap)extension; | AFPIncludeFormMap formMap = (AFPIncludeFormMap)extension; | ||||
AFPResourceAccessor accessor = new AFPResourceAccessor( | AFPResourceAccessor accessor = new AFPResourceAccessor( | ||||
getUserAgent().getNewURIResolver()); | |||||
getUserAgent().getResourceResolver()); | |||||
try { | try { | ||||
getResourceManager().createIncludedResource(formMap.getName(), | getResourceManager().createIncludedResource(formMap.getName(), | ||||
formMap.getSrc(), accessor, | formMap.getSrc(), accessor, |
import org.apache.fop.afp.fonts.RasterFont; | import org.apache.fop.afp.fonts.RasterFont; | ||||
import org.apache.fop.afp.util.AFPResourceAccessor; | import org.apache.fop.afp.util.AFPResourceAccessor; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.events.EventProducer; | import org.apache.fop.events.EventProducer; | ||||
import org.apache.fop.fonts.FontConfig; | import org.apache.fop.fonts.FontConfig; | ||||
import org.apache.fop.fonts.FontManager; | import org.apache.fop.fonts.FontManager; | ||||
return font != null ? new AFPFontInfo(font, config.triplets) : null; | return font != null ? new AFPFontInfo(font, config.triplets) : null; | ||||
} | } | ||||
abstract AFPFontInfo getFontInfo(URIResolverWrapper resolver, AFPEventProducer eventProducer) | |||||
throws IOException; | |||||
abstract AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, | |||||
AFPEventProducer eventProducer) throws IOException; | |||||
AFPResourceAccessor getAccessor(URIResolverWrapper resolver) { | |||||
return new AFPResourceAccessor(resolver, uri); | |||||
AFPResourceAccessor getAccessor(InternalResourceResolver resourceResolver) { | |||||
return new AFPResourceAccessor(resourceResolver, uri); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
AFPFontInfo getFontInfo(URIResolverWrapper resolver, AFPEventProducer eventProducer) | |||||
AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, AFPEventProducer eventProducer) | |||||
throws IOException { | throws IOException { | ||||
AFPResourceAccessor accessor = getAccessor(resolver); | |||||
AFPResourceAccessor accessor = getAccessor(resourceResolver); | |||||
CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().buildDBCS( | CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().buildDBCS( | ||||
characterset, super.codePage, super.encoding, charsetType, accessor, eventProducer); | characterset, super.codePage, super.encoding, charsetType, accessor, eventProducer); | ||||
return getFontInfo(new DoubleByteFont(super.codePage, super.embeddable, characterSet), | return getFontInfo(new DoubleByteFont(super.codePage, super.embeddable, characterSet), | ||||
} | } | ||||
@Override | @Override | ||||
AFPFontInfo getFontInfo(URIResolverWrapper resolver, AFPEventProducer eventProducer) | |||||
AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, AFPEventProducer eventProducer) | |||||
throws IOException { | throws IOException { | ||||
CharacterSet characterSet = null; | CharacterSet characterSet = null; | ||||
if (base14 != null) { | if (base14 != null) { | ||||
LOG.error(msg); | LOG.error(msg); | ||||
} | } | ||||
} else { | } else { | ||||
AFPResourceAccessor accessor = getAccessor(resolver); | |||||
AFPResourceAccessor accessor = getAccessor(resourceResolver); | |||||
characterSet = CharacterSetBuilder.getSingleByteInstance().buildSBCS( | characterSet = CharacterSetBuilder.getSingleByteInstance().buildSBCS( | ||||
characterset, super.codePage, super.encoding, accessor, eventProducer); | characterset, super.codePage, super.encoding, accessor, eventProducer); | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
AFPFontInfo getFontInfo(URIResolverWrapper resolver, AFPEventProducer eventProducer) | |||||
AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, AFPEventProducer eventProducer) | |||||
throws IOException { | throws IOException { | ||||
RasterFont rasterFont = new RasterFont(super.name, super.embeddable); | RasterFont rasterFont = new RasterFont(super.name, super.embeddable); | ||||
for (RasterCharactersetData charset : charsets) { | for (RasterCharactersetData charset : charsets) { | ||||
LOG.error(msg); | LOG.error(msg); | ||||
} | } | ||||
} else { | } else { | ||||
AFPResourceAccessor accessor = getAccessor(resolver); | |||||
AFPResourceAccessor accessor = getAccessor(resourceResolver); | |||||
rasterFont.addCharacterSet(charset.size, | rasterFont.addCharacterSet(charset.size, | ||||
CharacterSetBuilder.getSingleByteInstance().buildSBCS(charset.characterset, | CharacterSetBuilder.getSingleByteInstance().buildSBCS(charset.characterset, | ||||
super.codePage, super.encoding, accessor, eventProducer)); | super.codePage, super.encoding, accessor, eventProducer)); |
//Do we need to embed an external page segment? | //Do we need to embed an external page segment? | ||||
if (pageSegment.getURI() != null) { | if (pageSegment.getURI() != null) { | ||||
AFPResourceAccessor accessor = new AFPResourceAccessor( | AFPResourceAccessor accessor = new AFPResourceAccessor( | ||||
documentHandler.getUserAgent().getNewURIResolver()); | |||||
documentHandler.getUserAgent().getResourceResolver()); | |||||
try { | try { | ||||
URI resourceUri = new URI(pageSegment.getURI()); | URI resourceUri = new URI(pageSegment.getURI()); | ||||
documentHandler.getResourceManager().createIncludedResourceFromExternal( | documentHandler.getResourceManager().createIncludedResourceFromExternal( |
import org.apache.fop.afp.fonts.AFPFontInfo; | import org.apache.fop.afp.fonts.AFPFontInfo; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.FOUserAgent; | import org.apache.fop.apps.FOUserAgent; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.FontCollection; | import org.apache.fop.fonts.FontCollection; | ||||
import org.apache.fop.render.PrintRendererConfigurator; | import org.apache.fop.render.PrintRendererConfigurator; | ||||
import org.apache.fop.render.RendererConfig.RendererConfigParser; | import org.apache.fop.render.RendererConfig.RendererConfigParser; | ||||
} | } | ||||
@Override | @Override | ||||
protected FontCollection getCustomFontCollection(URIResolverWrapper uriResolverWrapper, | |||||
protected FontCollection getCustomFontCollection(InternalResourceResolver uriResolverWrapper, | |||||
String mimeType) throws FOPException { | String mimeType) throws FOPException { | ||||
AFPRendererConfig config = (AFPRendererConfig) getRendererConfig(mimeType); | AFPRendererConfig config = (AFPRendererConfig) getRendererConfig(mimeType); | ||||
if (config != null) { | if (config != null) { | ||||
throws FOPException, IOException { | throws FOPException, IOException { | ||||
List<AFPFontInfo> afpFonts = new ArrayList<AFPFontInfo>(); | List<AFPFontInfo> afpFonts = new ArrayList<AFPFontInfo>(); | ||||
for (AFPFontConfigData config : fontConfig.getFontConfig()) { | for (AFPFontConfigData config : fontConfig.getFontConfig()) { | ||||
afpFonts.add(config.getFontInfo(userAgent.getFontManager().getURIResolver(), | |||||
afpFonts.add(config.getFontInfo(userAgent.getFontManager().getResourceResolver(), | |||||
eventProducer)); | eventProducer)); | ||||
} | } | ||||
return afpFonts; | return afpFonts; |
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.FOUserAgent; | import org.apache.fop.apps.FOUserAgent; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.EmbedFontInfo; | import org.apache.fop.fonts.EmbedFontInfo; | ||||
import org.apache.fop.fonts.FontCollection; | import org.apache.fop.fonts.FontCollection; | ||||
import org.apache.fop.render.RendererConfig.RendererConfigParser; | import org.apache.fop.render.RendererConfig.RendererConfigParser; | ||||
} | } | ||||
@Override | @Override | ||||
protected FontCollection createCollectionFromFontList(URIResolverWrapper uriResolverWrapper, | |||||
protected FontCollection createCollectionFromFontList(InternalResourceResolver resourceResolver, | |||||
List<EmbedFontInfo> fontList) { | List<EmbedFontInfo> fontList) { | ||||
return new ConfiguredFontCollection(uriResolverWrapper, fontList, userAgent.isComplexScriptFeaturesEnabled()); | |||||
return new ConfiguredFontCollection(resourceResolver, fontList, userAgent.isComplexScriptFeaturesEnabled()); | |||||
} | } | ||||
@Override | @Override |
} | } | ||||
try { | try { | ||||
URI resultURI = URI.create(streamResult.getSystemId()); | URI resultURI = URI.create(streamResult.getSystemId()); | ||||
out = new BufferedOutputStream(getUserAgent().getNewURIResolver().resolveOut(resultURI)); | |||||
out = new BufferedOutputStream(getUserAgent().getResourceResolver().getOutputStream(resultURI)); | |||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
throw new IFException("I/O error while opening output stream" , ioe); | throw new IFException("I/O error while opening output stream" , ioe); | ||||
} | } |
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.CustomFont; | import org.apache.fop.fonts.CustomFont; | ||||
import org.apache.fop.fonts.EmbedFontInfo; | import org.apache.fop.fonts.EmbedFontInfo; | ||||
import org.apache.fop.fonts.EncodingMode; | import org.apache.fop.fonts.EncodingMode; | ||||
private static Log log = LogFactory.getLog(ConfiguredFontCollection.class); | private static Log log = LogFactory.getLog(ConfiguredFontCollection.class); | ||||
private final URIResolverWrapper uriResolver; | |||||
private final InternalResourceResolver resourceResolver; | |||||
private final List<EmbedFontInfo> embedFontInfoList; | private final List<EmbedFontInfo> embedFontInfoList; | ||||
private final boolean useComplexScripts; | private final boolean useComplexScripts; | ||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* @param uriResolver a font resolver | |||||
* @param resourceResolver a font resolver | |||||
* @param customFonts the list of custom fonts | * @param customFonts the list of custom fonts | ||||
* @param useComplexScriptFeatures true if complex script features enabled | * @param useComplexScriptFeatures true if complex script features enabled | ||||
*/ | */ | ||||
public ConfiguredFontCollection(URIResolverWrapper uriResolver, | |||||
public ConfiguredFontCollection(InternalResourceResolver resourceResolver, | |||||
List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) { | List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) { | ||||
this.uriResolver = uriResolver; | |||||
this.resourceResolver = resourceResolver; | |||||
this.embedFontInfoList = customFonts; | this.embedFontInfoList = customFonts; | ||||
this.useComplexScripts = useComplexScriptFeatures; | this.useComplexScripts = useComplexScriptFeatures; | ||||
} | } | ||||
// If the user specified an XML-based metrics file, we'll use it | // If the user specified an XML-based metrics file, we'll use it | ||||
// Otherwise, calculate metrics directly from the font file. | // Otherwise, calculate metrics directly from the font file. | ||||
if (metricsURI != null) { | if (metricsURI != null) { | ||||
LazyFont fontMetrics = new LazyFont(configFontInfo, uriResolver, useComplexScripts); | |||||
InputStream fontSource = uriResolver.resolveIn(fontURI); | |||||
LazyFont fontMetrics = new LazyFont(configFontInfo, resourceResolver, useComplexScripts); | |||||
InputStream fontSource = resourceResolver.getResource(fontURI); | |||||
font = new CustomFontMetricsMapper(fontMetrics, fontSource); | font = new CustomFontMetricsMapper(fontMetrics, fontSource); | ||||
} else { | } else { | ||||
CustomFont fontMetrics = FontLoader.loadFont( | CustomFont fontMetrics = FontLoader.loadFont( | ||||
fontURI, null, true, EncodingMode.AUTO, | fontURI, null, true, EncodingMode.AUTO, | ||||
configFontInfo.getKerning(), | configFontInfo.getKerning(), | ||||
configFontInfo.getAdvanced(), uriResolver); | |||||
configFontInfo.getAdvanced(), resourceResolver); | |||||
font = new CustomFontMetricsMapper(fontMetrics); | font = new CustomFontMetricsMapper(fontMetrics); | ||||
} | } | ||||
FontCollection[] fontCollections = new FontCollection[] { | FontCollection[] fontCollections = new FontCollection[] { | ||||
new Base14FontCollection(java2DFontMetrics), | new Base14FontCollection(java2DFontMetrics), | ||||
new InstalledFontCollection(java2DFontMetrics), | new InstalledFontCollection(java2DFontMetrics), | ||||
new ConfiguredFontCollection(fontManager.getURIResolver(), getFontList(), | |||||
new ConfiguredFontCollection(fontManager.getResourceResolver(), getFontList(), | |||||
userAgent.isComplexScriptFeaturesEnabled()) | userAgent.isComplexScriptFeaturesEnabled()) | ||||
}; | }; | ||||
fontManager.setup(getFontInfo(), fontCollections); | fontManager.setup(getFontInfo(), fontCollections); |
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.FOUserAgent; | import org.apache.fop.apps.FOUserAgent; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.EmbedFontInfo; | import org.apache.fop.fonts.EmbedFontInfo; | ||||
import org.apache.fop.fonts.FontCollection; | import org.apache.fop.fonts.FontCollection; | ||||
import org.apache.fop.render.PrintRendererConfigurator; | import org.apache.fop.render.PrintRendererConfigurator; | ||||
} | } | ||||
@Override | @Override | ||||
protected FontCollection createCollectionFromFontList(URIResolverWrapper uriResolverWrapper, | |||||
protected FontCollection createCollectionFromFontList(InternalResourceResolver resourceResolver, | |||||
List<EmbedFontInfo> fontList) { | List<EmbedFontInfo> fontList) { | ||||
return new ConfiguredFontCollection(uriResolverWrapper, fontList, | |||||
return new ConfiguredFontCollection(resourceResolver, fontList, | |||||
userAgent.isComplexScriptFeaturesEnabled()); | userAgent.isComplexScriptFeaturesEnabled()); | ||||
} | } | ||||
final OutputStream out; | final OutputStream out; | ||||
if (psUtil.isOptimizeResources()) { | if (psUtil.isOptimizeResources()) { | ||||
tempURI = TEMP_URI_GENERATOR.generate(); | tempURI = TEMP_URI_GENERATOR.generate(); | ||||
out = new BufferedOutputStream(getUserAgent().getNewURIResolver().resolveOut(tempURI)); | |||||
out = new BufferedOutputStream(getUserAgent().getResourceResolver().getOutputStream(tempURI)); | |||||
} else { | } else { | ||||
out = this.outputStream; | out = this.outputStream; | ||||
} | } | ||||
log.debug("Processing PostScript resources..."); | log.debug("Processing PostScript resources..."); | ||||
long startTime = System.currentTimeMillis(); | long startTime = System.currentTimeMillis(); | ||||
ResourceTracker resTracker = gen.getResourceTracker(); | ResourceTracker resTracker = gen.getResourceTracker(); | ||||
InputStream in = new BufferedInputStream(getUserAgent().getNewURIResolver().resolveIn(tempURI)); | |||||
InputStream in = new BufferedInputStream(getUserAgent().getResourceResolver().getResource(tempURI)); | |||||
try { | try { | ||||
try { | try { | ||||
ResourceHandler handler = new ResourceHandler(getUserAgent(), this.fontInfo, | ResourceHandler handler = new ResourceHandler(getUserAgent(), this.fontInfo, |
bDefer = true; | bDefer = true; | ||||
boolean base14Kerning = false; | boolean base14Kerning = false; | ||||
FontSetup.setup(fontInfo, null, userAgent.getNewURIResolver(), base14Kerning); | |||||
FontSetup.setup(fontInfo, null, userAgent.getResourceResolver(), base14Kerning); | |||||
} | } | ||||
/** | /** |
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.io.ResourceResolverFactory; | import org.apache.fop.apps.io.ResourceResolverFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.DefaultFontConfig; | import org.apache.fop.fonts.DefaultFontConfig; | ||||
import org.apache.fop.fonts.DefaultFontConfigurator; | import org.apache.fop.fonts.DefaultFontConfigurator; | ||||
import org.apache.fop.fonts.EmbedFontInfo; | import org.apache.fop.fonts.EmbedFontInfo; | ||||
FontInfo fontInfo = new FontInfo(); | FontInfo fontInfo = new FontInfo(); | ||||
final boolean strict = false; | final boolean strict = false; | ||||
if (cfg != null) { | if (cfg != null) { | ||||
URIResolverWrapper resolver = ResourceResolverFactory.createDefaultWrapper(); | |||||
InternalResourceResolver resourceResolver = ResourceResolverFactory.createDefaultWrapper(); | |||||
//TODO The following could be optimized by retaining the FontManager somewhere | //TODO The following could be optimized by retaining the FontManager somewhere | ||||
FontManager fontManager = new FontManager(resolver, FontDetectorFactory.createDefault(), | |||||
FontManager fontManager = new FontManager(resourceResolver, FontDetectorFactory.createDefault(), | |||||
FontCacheManagerFactory.createDefault()); | FontCacheManagerFactory.createDefault()); | ||||
//TODO Make use of fontBaseURL, font substitution and referencing configuration | //TODO Make use of fontBaseURL, font substitution and referencing configuration | ||||
= new DefaultFontConfigurator(fontManager, listener, strict); | = new DefaultFontConfigurator(fontManager, listener, strict); | ||||
List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fontInfoConfig); | List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fontInfoConfig); | ||||
fontManager.saveCache(); | fontManager.saveCache(); | ||||
FontSetup.setup(fontInfo, fontInfoList, resolver, useComplexScriptFeatures); | |||||
FontSetup.setup(fontInfo, fontInfoList, resourceResolver, useComplexScriptFeatures); | |||||
} else { | } else { | ||||
FontSetup.setup(fontInfo, useComplexScriptFeatures); | FontSetup.setup(fontInfo, useComplexScriptFeatures); | ||||
} | } |
import org.apache.xmlgraphics.java2d.color.ICCColorSpaceWithIntent; | import org.apache.xmlgraphics.java2d.color.ICCColorSpaceWithIntent; | ||||
import org.apache.xmlgraphics.java2d.color.RenderingIntent; | import org.apache.xmlgraphics.java2d.color.RenderingIntent; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
/** | /** | ||||
* Map with cached ICC based ColorSpace objects. | * Map with cached ICC based ColorSpace objects. | ||||
/** logger instance */ | /** logger instance */ | ||||
private static Log log = LogFactory.getLog(ColorSpaceCache.class); | private static Log log = LogFactory.getLog(ColorSpaceCache.class); | ||||
private URIResolverWrapper resolver; | |||||
private InternalResourceResolver resourceResolver; | |||||
private Map<String, ColorSpace> colorSpaceMap = Collections.synchronizedMap(new HashMap<String, ColorSpace>()); | private Map<String, ColorSpace> colorSpaceMap = Collections.synchronizedMap(new HashMap<String, ColorSpace>()); | ||||
/** | /** | ||||
* Default constructor | * Default constructor | ||||
* @param resolver uri resolver | |||||
* @param resourceResolver uri resolver | |||||
*/ | */ | ||||
public ColorSpaceCache(URIResolverWrapper resolver) { | |||||
this.resolver = resolver; | |||||
public ColorSpaceCache(InternalResourceResolver resourceResolver) { | |||||
this.resourceResolver = resourceResolver; | |||||
} | } | ||||
/** | /** | ||||
ICC_Profile iccProfile = null; | ICC_Profile iccProfile = null; | ||||
// First attempt to use the FOP URI resolver to locate the ICC | // First attempt to use the FOP URI resolver to locate the ICC | ||||
// profile | // profile | ||||
InputStream stream = resolver.resolveIn(iccProfileSrc); | |||||
InputStream stream = resourceResolver.getResource(iccProfileSrc); | |||||
if (stream != null) { | if (stream != null) { | ||||
// FOP URI resolver found ICC profile - create ICC profile | // FOP URI resolver found ICC profile - create ICC profile | ||||
// from the Source | // from the Source |
super(ua); | super(ua); | ||||
outStream = os; | outStream = os; | ||||
boolean base14Kerning = false; //TODO - FIXME | boolean base14Kerning = false; //TODO - FIXME | ||||
FontSetup.setup(fontInfo, null, ua.getNewURIResolver(), base14Kerning); | |||||
FontSetup.setup(fontInfo, null, ua.getResourceResolver(), base14Kerning); | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ |
@Test | @Test | ||||
public void getBaseURI() throws URISyntaxException { | public void getBaseURI() throws URISyntaxException { | ||||
assertEquals(URIResolverWrapper.getBaseURI("x/y/z/"), new URI("x/y/z/")); | |||||
assertEquals(URIResolverWrapper.getBaseURI("x/y/z"), new URI("x/y/z/")); | |||||
assertEquals(InternalResourceResolver.getBaseURI("x/y/z/"), new URI("x/y/z/")); | |||||
assertEquals(InternalResourceResolver.getBaseURI("x/y/z"), new URI("x/y/z/")); | |||||
} | } | ||||
@Test | @Test | ||||
String[] uris = new String[] {".", "path/to/resource", "path\\to\\resource", | String[] uris = new String[] {".", "path/to/resource", "path\\to\\resource", | ||||
"bad resource name"}; | "bad resource name"}; | ||||
for (String uri : uris) { | for (String uri : uris) { | ||||
assertEquals(URIResolverWrapper.cleanURI(uri), cleanURI(uri)); | |||||
assertEquals(InternalResourceResolver.cleanURI(uri), cleanURI(uri)); | |||||
} | } | ||||
assertNull(URIResolverWrapper.cleanURI(null)); | |||||
assertNull(InternalResourceResolver.cleanURI(null)); | |||||
} | } | ||||
private void test(String uriStr, URI uri, URI expected) throws IOException, URISyntaxException { | private void test(String uriStr, URI uri, URI expected) throws IOException, URISyntaxException { | ||||
ResourceResolver resolver = mock(ResourceResolver.class); | ResourceResolver resolver = mock(ResourceResolver.class); | ||||
URIResolverWrapper sut = new URIResolverWrapper(base, resolver); | |||||
sut.resolveIn(uriStr); | |||||
InternalResourceResolver sut = new InternalResourceResolver(base, resolver); | |||||
sut.getResource(uriStr); | |||||
verify(resolver).getResource(eq(expected)); | verify(resolver).getResource(eq(expected)); | ||||
resolver = mock(ResourceResolver.class); | resolver = mock(ResourceResolver.class); | ||||
sut = new URIResolverWrapper(base, resolver); | |||||
sut.resolveIn(uri); | |||||
sut = new InternalResourceResolver(base, resolver); | |||||
sut.getResource(uri); | |||||
verify(resolver).getResource(eq(expected)); | verify(resolver).getResource(eq(expected)); | ||||
} | } | ||||
FontManager fontManager = ua.getFontManager(); | FontManager fontManager = ua.getFontManager(); | ||||
FontCollection[] fontCollections = new FontCollection[] { | FontCollection[] fontCollections = new FontCollection[] { | ||||
new Base14FontCollection(fontManager.isBase14KerningEnabled()), | new Base14FontCollection(fontManager.isBase14KerningEnabled()), | ||||
new CustomFontCollection(fontManager.getURIResolver(), renderer.getFontList(), | |||||
new CustomFontCollection(fontManager.getResourceResolver(), renderer.getFontList(), | |||||
ua.isComplexScriptFeaturesEnabled()) | ua.isComplexScriptFeaturesEnabled()) | ||||
}; | }; | ||||
fontManager.setup(fontInfo, fontCollections); | fontManager.setup(fontInfo, fontCollections); |
import org.junit.Test; | import org.junit.Test; | ||||
import org.apache.fop.apps.io.ResourceResolverFactory; | import org.apache.fop.apps.io.ResourceResolverFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
*/ | */ | ||||
public class DejaVuLGCSerifTestCase { | public class DejaVuLGCSerifTestCase { | ||||
private URIResolverWrapper resolver = new URIResolverWrapper(new File(".").toURI(), | |||||
private InternalResourceResolver resolver = new InternalResourceResolver(new File(".").toURI(), | |||||
ResourceResolverFactory.createDefaultResourceResolver()); | ResourceResolverFactory.createDefaultResourceResolver()); | ||||
private CustomFont font; | private CustomFont font; | ||||
String actualBase = "../../resources/fonts/ttf/"; | String actualBase = "../../resources/fonts/ttf/"; | ||||
FontManager fontManager = setBaseAndGetManager(actualBase); | FontManager fontManager = setBaseAndGetManager(actualBase); | ||||
URI expectedURI = baseURI.resolve(actualBase); | URI expectedURI = baseURI.resolve(actualBase); | ||||
assertEquals(expectedURI, fontManager.getURIResolver().getBaseURI()); | |||||
assertEquals(expectedURI, fontManager.getResourceResolver().getBaseURI()); | |||||
} | } | ||||
@Test | @Test | ||||
public void currentRelativeFontBaseTest() { | public void currentRelativeFontBaseTest() { | ||||
String actualBase = "."; | String actualBase = "."; | ||||
FontManager fontManager = setBaseAndGetManager(actualBase); | FontManager fontManager = setBaseAndGetManager(actualBase); | ||||
assertEquals(baseURI, fontManager.getURIResolver().getBaseURI()); | |||||
assertEquals(baseURI, fontManager.getResourceResolver().getBaseURI()); | |||||
} | } | ||||
/** | /** | ||||
String actualBase = "non-existing-dir/"; | String actualBase = "non-existing-dir/"; | ||||
FontManager fontManager = setBaseAndGetManager(actualBase); | FontManager fontManager = setBaseAndGetManager(actualBase); | ||||
assertEquals(baseURI.resolve("non-existing-dir/"), | assertEquals(baseURI.resolve("non-existing-dir/"), | ||||
fontManager.getURIResolver().getBaseURI()); | |||||
fontManager.getResourceResolver().getBaseURI()); | |||||
} | } | ||||
/** | /** | ||||
builder.setBaseURI(actualBase); | builder.setBaseURI(actualBase); | ||||
FontManager fontManager = getManager(); | FontManager fontManager = getManager(); | ||||
assertEquals(baseURI.resolve(actualBase), | assertEquals(baseURI.resolve(actualBase), | ||||
fontManager.getURIResolver().getBaseURI()); | |||||
fontManager.getResourceResolver().getBaseURI()); | |||||
} | } | ||||
@Test | @Test | ||||
public void absoluteBaseURI() { | public void absoluteBaseURI() { | ||||
String absoluteBase = "test:///absolute/"; | String absoluteBase = "test:///absolute/"; | ||||
FontManager fontManager = setBaseAndGetManager(absoluteBase); | FontManager fontManager = setBaseAndGetManager(absoluteBase); | ||||
assertEquals(URI.create(absoluteBase), fontManager.getURIResolver().getBaseURI()); | |||||
assertEquals(URI.create(absoluteBase), fontManager.getResourceResolver().getBaseURI()); | |||||
} | } | ||||
} | } |
import org.junit.Test; | import org.junit.Test; | ||||
import org.apache.fop.apps.io.ResourceResolverFactory; | import org.apache.fop.apps.io.ResourceResolverFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.EncodingMode; | import org.apache.fop.fonts.EncodingMode; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
boolean useComplexScriptFeatures = false; | boolean useComplexScriptFeatures = false; | ||||
File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf"); | File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf"); | ||||
URI absoluteFilePath = file.toURI(); | URI absoluteFilePath = file.toURI(); | ||||
URIResolverWrapper resolver = ResourceResolverFactory.createDefaultWrapper(); | |||||
InternalResourceResolver resolver = ResourceResolverFactory.createDefaultWrapper(); | |||||
String fontName = "Deja Vu"; | String fontName = "Deja Vu"; | ||||
boolean embedded = false; | boolean embedded = false; | ||||
boolean useKerning = true; | boolean useKerning = true; |
return delegate.getLayoutManagerMakerOverride(); | return delegate.getLayoutManagerMakerOverride(); | ||||
} | } | ||||
public ResourceResolver getNewURIResolver() { | |||||
return delegate.getNewURIResolver(); | |||||
public ResourceResolver getResourceResolver() { | |||||
return delegate.getResourceResolver(); | |||||
} | } | ||||
public URI getBaseURI() { | public URI getBaseURI() { |
import org.junit.Test; | import org.junit.Test; | ||||
import org.apache.fop.apps.io.ResourceResolverFactory; | import org.apache.fop.apps.io.ResourceResolverFactory; | ||||
import org.apache.fop.apps.io.URIResolverWrapper; | |||||
import org.apache.fop.apps.io.InternalResourceResolver; | |||||
import org.apache.fop.fonts.CIDSubset; | import org.apache.fop.fonts.CIDSubset; | ||||
import org.apache.fop.fonts.MultiByteFont; | import org.apache.fop.fonts.MultiByteFont; | ||||
@Test | @Test | ||||
public void testSubsetFontNamePrefix() { | public void testSubsetFontNamePrefix() { | ||||
class MockedFont extends MultiByteFont { | class MockedFont extends MultiByteFont { | ||||
public MockedFont(URIResolverWrapper resolver) { | |||||
public MockedFont(InternalResourceResolver resolver) { | |||||
super(resolver); | super(resolver); | ||||
} | } | ||||