소스 검색

FOP-2552: TrueType in AFP adding extra slash to end of font uri

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1720357 13f79535-47bb-0310-9956-ffa450edef68
pull/39/head
Simon Steiner 8 년 전
부모
커밋
ac9a778882

+ 1
- 0
src/foschema/fop-configuration.xsd 파일 보기

<xsd:attribute name="embed-url-afm" type="xsd:anyURI" use="optional"/> <xsd:attribute name="embed-url-afm" type="xsd:anyURI" use="optional"/>
<xsd:attribute name="embed-url-pfm" type="xsd:anyURI" use="optional"/> <xsd:attribute name="embed-url-pfm" type="xsd:anyURI" use="optional"/>
<xsd:attribute name="sub-font" type="xsd:string" use="optional"/> <xsd:attribute name="sub-font" type="xsd:string" use="optional"/>
<xsd:attribute name="name" type="xsd:string" use="optional"/>
<xsd:attribute name="embedding-mode" use="optional"> <xsd:attribute name="embedding-mode" use="optional">
<xsd:simpleType> <xsd:simpleType>
<xsd:restriction base="xsd:string"> <xsd:restriction base="xsd:string">

+ 3
- 7
src/java/org/apache/fop/afp/AFPResourceManager.java 파일 보기

AFPResourceAccessor accessor = charSet.getResourceAccessor(); AFPResourceAccessor accessor = charSet.getResourceAccessor();
if (afpFont.getFontType() == FontType.TRUETYPE) { if (afpFont.getFontType() == FontType.TRUETYPE) {


createIncludedResource(afpFont.getFontName(), accessor.resolveURI("."), accessor,
createIncludedResource(afpFont.getFontName(),
((AFPFontConfig.AFPTrueTypeFont) afpFont).getUri(), accessor,
ResourceObject.TYPE_OBJECT_CONTAINER, true, ResourceObject.TYPE_OBJECT_CONTAINER, true,
((AFPFontConfig.AFPTrueTypeFont) afpFont).getTTC()); ((AFPFontConfig.AFPTrueTypeFont) afpFont).getTTC());
} else { } else {
ActiveEnvironmentGroup.setupTruetypeMDR(res, false); ActiveEnvironmentGroup.setupTruetypeMDR(res, false);


ObjectContainer oc = factory.createObjectContainer(); ObjectContainer oc = factory.createObjectContainer();
InputStream is;
try {
is = accessor.createInputStream(new URI("."));
} catch (URISyntaxException e) {
throw new IOException(e);
}
InputStream is = accessor.createInputStream(uri);


if (ttc != null) { if (ttc != null) {
oc.setData(extractTTC(ttc, is)); oc.setData(extractTTC(ttc, is));

+ 19
- 11
src/java/org/apache/fop/render/afp/AFPFontConfig.java 파일 보기

static final class TrueTypeFontConfig extends AFPFontConfigData { static final class TrueTypeFontConfig extends AFPFontConfigData {
private String characterset; private String characterset;
private String subfont; private String subfont;
private String fontUri;


private TrueTypeFontConfig(List<FontTriplet> triplets, String type, String codePage, private TrueTypeFontConfig(List<FontTriplet> triplets, String type, String codePage,
String encoding, String characterset, String name, String subfont, String encoding, String characterset, String name, String subfont,
boolean embeddable, String uri) { boolean embeddable, String uri) {
super(triplets, type, codePage, encoding, name, embeddable, uri);
super(triplets, type, codePage, encoding, name, embeddable, null);
this.characterset = characterset; this.characterset = characterset;
this.subfont = subfont; this.subfont = subfont;
this.fontUri = uri;
} }


@Override @Override
AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, AFPEventProducer eventProducer) AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, AFPEventProducer eventProducer)
throws IOException { throws IOException {
Typeface tf;
try { try {
tf = new LazyFont(new EmbedFontInfo(
new FontUris(new URI(uri), null)
Typeface tf = new LazyFont(new EmbedFontInfo(
new FontUris(new URI(fontUri), null)
, false, true, null, subfont), resourceResolver, false).getRealFont(); , false, true, null, subfont), resourceResolver, false).getRealFont();

AFPResourceAccessor accessor = getAccessor(resourceResolver);
CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().build(characterset,
super.codePage, super.encoding, tf, accessor, eventProducer);
OutlineFont font = new AFPTrueTypeFont(super.name, super.embeddable, characterSet,
eventProducer, subfont, new URI(fontUri));
return getFontInfo(font, this);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new IOException(e); throw new IOException(e);
} }
AFPResourceAccessor accessor = getAccessor(resourceResolver);
CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().build(characterset, super.codePage,
super.encoding, tf, accessor, eventProducer);
OutlineFont font = new AFPTrueTypeFont(super.name, super.embeddable, characterSet,
eventProducer, subfont);
return getFontInfo(font, this);
} }
} }


public static class AFPTrueTypeFont extends OutlineFont { public static class AFPTrueTypeFont extends OutlineFont {
private String ttc; private String ttc;
private URI uri;
public AFPTrueTypeFont(String name, boolean embeddable, CharacterSet charSet, AFPEventProducer eventProducer, public AFPTrueTypeFont(String name, boolean embeddable, CharacterSet charSet, AFPEventProducer eventProducer,
String ttc) {
String ttc, URI uri) {
super(name, embeddable, charSet, eventProducer); super(name, embeddable, charSet, eventProducer);
this.ttc = ttc; this.ttc = ttc;
this.uri = uri;
} }


public FontType getFontType() { public FontType getFontType() {
public String getTTC() { public String getTTC() {
return ttc; return ttc;
} }

public URI getUri() {
return uri;
}
} }


static final class OutlineFontConfig extends AFPFontConfigData { static final class OutlineFontConfig extends AFPFontConfigData {

+ 31
- 3
test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java 파일 보기

import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;


import javax.xml.transform.Result; import javax.xml.transform.Result;
import javax.xml.transform.Source; import javax.xml.transform.Source;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;


import org.apache.xmlgraphics.io.Resource;
import org.apache.xmlgraphics.io.ResourceResolver;

import org.apache.fop.afp.AFPPaintingState; import org.apache.fop.afp.AFPPaintingState;
import org.apache.fop.afp.AFPResourceManager; import org.apache.fop.afp.AFPResourceManager;
import org.apache.fop.afp.DataStream; import org.apache.fop.afp.DataStream;
import org.apache.fop.afp.Factory; import org.apache.fop.afp.Factory;
import org.apache.fop.afp.fonts.FopCharacterSet; import org.apache.fop.afp.fonts.FopCharacterSet;
import org.apache.fop.afp.modca.PageObject; import org.apache.fop.afp.modca.PageObject;
import org.apache.fop.apps.EnvironmentalProfileFactory;
import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop; import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopConfParser; import org.apache.fop.apps.FopConfParser;
import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryBuilder; import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.fonts.EmbeddingMode; import org.apache.fop.fonts.EmbeddingMode;
import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet; import org.apache.fop.fonts.FontTriplet;
import junit.framework.Assert; import junit.framework.Assert;


public class AFPTrueTypeTestCase { public class AFPTrueTypeTestCase {
private String font;

@Test @Test
public void testAFPTrueType() throws IOException, SAXException, TransformerException {
public void testAFPTrueType() throws IOException, SAXException, TransformerException, URISyntaxException {
String fopxconf = "<fop version=\"1.0\">\n" String fopxconf = "<fop version=\"1.0\">\n"
+ " <renderers>\n" + " <renderers>\n"
+ " <renderer mime=\"application/x-afp\">\n" + " <renderer mime=\"application/x-afp\">\n"
+ "</fo:root>"; + "</fo:root>";


FopFactoryBuilder confBuilder = new FopConfParser( FopFactoryBuilder confBuilder = new FopConfParser(
new ByteArrayInputStream(fopxconf.getBytes()), new File(".").toURI()).getFopFactoryBuilder();
new ByteArrayInputStream(fopxconf.getBytes()),
EnvironmentalProfileFactory.createRestrictedIO(new URI("."),
new MyResourceResolver())).getFopFactoryBuilder();
FopFactory fopFactory = confBuilder.build(); FopFactory fopFactory = confBuilder.build();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ "END DOCUMENT DOC00001\n"; + "END DOCUMENT DOC00001\n";


Assert.assertEquals(sb.toString(), format); Assert.assertEquals(sb.toString(), format);
Assert.assertEquals("test/resources/fonts/ttf/DejaVuLGCSerif.ttf", font);
}

class MyResourceResolver implements ResourceResolver {
private ResourceResolver defaultResourceResolver = ResourceResolverFactory.createDefaultResourceResolver();
public Resource getResource(URI uri) throws IOException {
if (!"tmp".equals(uri.getScheme())) {
font = uri.getPath();
uri = new File(".", uri.getPath()).toURI();
}
return defaultResourceResolver.getResource(uri);
}

public OutputStream getOutputStream(URI uri) throws IOException {
return defaultResourceResolver.getOutputStream(uri);
}
} }


@Test @Test
MultiByteFont font = new MultiByteFont(null, EmbeddingMode.AUTO); MultiByteFont font = new MultiByteFont(null, EmbeddingMode.AUTO);
font.setWidthArray(new int[100]); font.setWidthArray(new int[100]);
f.addMetrics("any", new AFPFontConfig.AFPTrueTypeFont("", true, f.addMetrics("any", new AFPFontConfig.AFPTrueTypeFont("", true,
new FopCharacterSet("", "UTF-16BE", "", font, null, null), null, null));
new FopCharacterSet("", "UTF-16BE", "", font, null, null), null, null, null));
return f; return f;
} }
} }

Loading…
취소
저장