diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-02-05 16:27:08 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-02-05 16:27:08 +0000 |
commit | 4e27a1c9dd7246dff9d9380755171f179e3fcb8a (patch) | |
tree | 93817887ac0a99f6a3c1b736cae9ce5688eb4bab /src/java/org/apache/fop/afp/util | |
parent | 7fbf442044c42fce773c36cd9aea80694abf007d (diff) | |
download | xmlgraphics-fop-4e27a1c9dd7246dff9d9380755171f179e3fcb8a.tar.gz xmlgraphics-fop-4e27a1c9dd7246dff9d9380755171f179e3fcb8a.zip |
Performance improvements and file-size reductions by introducing letter-spacing and word-spacing attributes in new IF (as mentioned on fop-dev).
Allow to control whether kerning information is loaded from fonts.
Started support for AFP font embedding (incomplete and currently disabled)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@741165 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/afp/util')
3 files changed, 158 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/afp/util/DefaultFOPResourceAccessor.java b/src/java/org/apache/fop/afp/util/DefaultFOPResourceAccessor.java new file mode 100644 index 000000000..55c8eab7d --- /dev/null +++ b/src/java/org/apache/fop/afp/util/DefaultFOPResourceAccessor.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; + +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; + +import org.apache.fop.apps.FOUserAgent; + +/** + * Default implementation of the {@link ResourceAccessor} interface for use inside FOP. + */ +public class DefaultFOPResourceAccessor implements ResourceAccessor { + + private FOUserAgent userAgent; + + /** + * Main constructor. + * @param userAgent the FO user agent + */ + public DefaultFOPResourceAccessor(FOUserAgent userAgent) { + this.userAgent = userAgent; + } + + /** {@inheritDoc} */ + public InputStream createInputStream(URI uri) throws IOException { + Source src = userAgent.resolveURI(uri.toASCIIString()); + if (src == null) { + return null; + } else if (src instanceof StreamSource) { + StreamSource ss = (StreamSource)src; + InputStream in = ss.getInputStream(); + return in; + } else { + return null; + } + } + +} diff --git a/src/java/org/apache/fop/afp/util/ResourceAccessor.java b/src/java/org/apache/fop/afp/util/ResourceAccessor.java new file mode 100644 index 000000000..6b9995c44 --- /dev/null +++ b/src/java/org/apache/fop/afp/util/ResourceAccessor.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; + +/** + * Defines an interface through which external resource objects can be accessed. + */ +public interface ResourceAccessor { + + /** + * Creates a new {@link InputStream} for the given URI that allows read access to an external + * resource. + * @param uri the URI of an external resource. + * @return the new input stream + * @throws IOException if an I/O error occurs while opening the resource + */ + InputStream createInputStream(URI uri) throws IOException; + +} diff --git a/src/java/org/apache/fop/afp/util/SimpleResourceAccessor.java b/src/java/org/apache/fop/afp/util/SimpleResourceAccessor.java new file mode 100644 index 000000000..51772c253 --- /dev/null +++ b/src/java/org/apache/fop/afp/util/SimpleResourceAccessor.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp.util; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +/** + * Simple implementation of the {@link ResourceAccessor} interface for access via files. + */ +public class SimpleResourceAccessor implements ResourceAccessor { + + private URI baseURI; + + /** + * Creates a new simple resource accessor. + * @param basePath the base path to resolve relative URIs to + */ + public SimpleResourceAccessor(File basePath) { + this.baseURI = basePath.toURI(); + } + + /** + * Creates a new simple resource accessor. + * @param basePath the base path to resolve relative URIs to + */ + public SimpleResourceAccessor(String basePath) { + this(new File(basePath)); + } + + /** {@inheritDoc} */ + public InputStream createInputStream(URI uri) throws IOException { + URI resolved = this.baseURI.resolve(uri); + URL url = resolved.toURL(); + return url.openStream(); + } + +} |