git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1570362 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.batik.gvt.font.GVTFontFace; | |||||
import org.apache.fop.afp.AFPEventProducer; | import org.apache.fop.afp.AFPEventProducer; | ||||
import org.apache.fop.afp.fonts.DoubleByteFont; | import org.apache.fop.afp.fonts.DoubleByteFont; | ||||
import org.apache.fop.events.EventBroadcaster; | import org.apache.fop.events.EventBroadcaster; | ||||
notifyDBFontRejection(font.getFontName()); | notifyDBFontRejection(font.getFontName()); | ||||
} else { | } else { | ||||
return new FOPGVTFontFamily(fontInfo, fontFamily, | return new FOPGVTFontFamily(fontInfo, fontFamily, | ||||
new FontTriplet(fontFamily, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)); | |||||
new FontTriplet(fontFamily, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL), | |||||
new GVTFontFace(fontFamily)); | |||||
} | } | ||||
} | } |
package org.apache.fop.svg.font; | package org.apache.fop.svg.font; | ||||
import java.io.InputStream; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.batik.bridge.FontFace; | |||||
import org.apache.batik.gvt.font.FontFamilyResolver; | import org.apache.batik.gvt.font.FontFamilyResolver; | ||||
import org.apache.batik.gvt.font.GVTFontFamily; | import org.apache.batik.gvt.font.GVTFontFamily; | ||||
this.resolvers = Arrays.<FontFamilyResolver>asList(resolvers); | this.resolvers = Arrays.<FontFamilyResolver>asList(resolvers); | ||||
} | } | ||||
public String lookup(String familyName) { | |||||
public GVTFontFamily resolve(String familyName) { | |||||
for (FontFamilyResolver resolver : resolvers) { | for (FontFamilyResolver resolver : resolvers) { | ||||
String lookup = resolver.lookup(familyName); | |||||
if (lookup != null) { | |||||
return lookup; | |||||
GVTFontFamily family = resolver.resolve(familyName); | |||||
if (family != null) { | |||||
return family; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public GVTFontFamily resolve(String familyName) { | |||||
public GVTFontFamily resolve(String familyName, FontFace fontFace) { | |||||
for (FontFamilyResolver resolver : resolvers) { | for (FontFamilyResolver resolver : resolvers) { | ||||
GVTFontFamily family = resolver.resolve(familyName); | |||||
GVTFontFamily family = resolver.resolve(familyName, fontFace); | |||||
if (family != null) { | if (family != null) { | ||||
return family; | return family; | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws Exception { | |||||
for (FontFamilyResolver resolver : resolvers) { | |||||
try { | |||||
return resolver.loadFont(in, fontFace); | |||||
} catch (Exception e) { | |||||
// Try the next one | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
public GVTFontFamily getDefault() { | public GVTFontFamily getDefault() { | ||||
return resolve("any"); | return resolve("any"); | ||||
} | } |
package org.apache.fop.svg.font; | package org.apache.fop.svg.font; | ||||
import java.io.InputStream; | |||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.batik.bridge.FontFace; | |||||
import org.apache.batik.gvt.font.GVTFontFace; | |||||
import org.apache.batik.gvt.font.GVTFontFamily; | |||||
import org.apache.fop.fonts.Font; | import org.apache.fop.fonts.Font; | ||||
import org.apache.fop.fonts.FontInfo; | import org.apache.fop.fonts.FontInfo; | ||||
import org.apache.fop.fonts.FontTriplet; | import org.apache.fop.fonts.FontTriplet; | ||||
this.fontInfo = fontInfo; | this.fontInfo = fontInfo; | ||||
} | } | ||||
public String lookup(String familyName) { | |||||
// TODO Auto-generated method stub | |||||
throw new UnsupportedOperationException(); | |||||
public FOPGVTFontFamily resolve(String familyName) { | |||||
return resolve(familyName, new GVTFontFace(familyName)); | |||||
} | } | ||||
public FOPGVTFontFamily resolve(String familyName) { | |||||
public FOPGVTFontFamily resolve(String familyName, FontFace fontFace) { | |||||
return resolve(familyName, (GVTFontFace) FontFace.createFontFace(familyName, fontFace)); | |||||
} | |||||
private FOPGVTFontFamily resolve(String familyName, GVTFontFace fontFace) { | |||||
FOPGVTFontFamily gvtFontFamily = null; | FOPGVTFontFamily gvtFontFamily = null; | ||||
FontTriplet triplet = fontInfo.fontLookup(familyName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); | FontTriplet triplet = fontInfo.fontLookup(familyName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); | ||||
if (fontInfo.hasFont(familyName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)) { | if (fontInfo.hasFont(familyName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)) { | ||||
gvtFontFamily = new FOPGVTFontFamily(fontInfo, familyName, triplet); | |||||
gvtFontFamily = new FOPGVTFontFamily(fontInfo, familyName, triplet, fontFace); | |||||
} | } | ||||
return gvtFontFamily; | return gvtFontFamily; | ||||
} | } | ||||
public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws Exception { | |||||
throw new UnsupportedOperationException("Not implemented"); | |||||
} | |||||
public FOPGVTFontFamily getDefault() { | public FOPGVTFontFamily getDefault() { | ||||
return resolve("any"); | return resolve("any"); | ||||
} | } | ||||
if (font.hasChar(c)) { | if (font.hasChar(c)) { | ||||
String fontFamily = font.getFamilyNames().iterator().next(); | String fontFamily = font.getFamilyNames().iterator().next(); | ||||
return new FOPGVTFontFamily(fontInfo, fontFamily, | return new FOPGVTFontFamily(fontInfo, fontFamily, | ||||
new FontTriplet(fontFamily, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)); | |||||
new FontTriplet(fontFamily, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL), | |||||
new GVTFontFace(fontFamily)); | |||||
} | } | ||||
} | } | ||||
return null; | return null; |
private final String familyName; | private final String familyName; | ||||
public FOPGVTFontFamily(FontInfo fontInfo, String familyName, FontTriplet triplet) { | |||||
private GVTFontFace fontFace; | |||||
public FOPGVTFontFamily(FontInfo fontInfo, String familyName, FontTriplet triplet, GVTFontFace fontFace) { | |||||
this.fontInfo = fontInfo; | this.fontInfo = fontInfo; | ||||
this.fontTriplet = triplet; | this.fontTriplet = triplet; | ||||
this.familyName = familyName; | this.familyName = familyName; | ||||
this.fontFace = fontFace; | |||||
} | } | ||||
public String getFamilyName() { | public String getFamilyName() { | ||||
} | } | ||||
public GVTFontFace getFontFace() { | public GVTFontFace getFontFace() { | ||||
// TODO Auto-generated method stub | |||||
throw new UnsupportedOperationException(); | |||||
return fontFace; | |||||
} | } | ||||
public FOPGVTFont deriveFont(float size, AttributedCharacterIterator aci) { | public FOPGVTFont deriveFont(float size, AttributedCharacterIterator aci) { |
package org.apache.fop.svg.font; | package org.apache.fop.svg.font; | ||||
import java.io.InputStream; | |||||
import org.apache.batik.bridge.FontFace; | |||||
import org.apache.batik.gvt.font.GVTFontFamily; | |||||
public class FilteringFontFamilyResolver implements FOPFontFamilyResolver { | public class FilteringFontFamilyResolver implements FOPFontFamilyResolver { | ||||
this.delegate = delegate; | this.delegate = delegate; | ||||
} | } | ||||
public String lookup(String familyName) { | |||||
return delegate.lookup(familyName); | |||||
} | |||||
public FOPGVTFontFamily resolve(String familyName) { | public FOPGVTFontFamily resolve(String familyName) { | ||||
return delegate.resolve(familyName); | return delegate.resolve(familyName); | ||||
} | } | ||||
public GVTFontFamily resolve(String familyName, FontFace fontFace) { | |||||
return delegate.resolve(familyName, fontFace); | |||||
} | |||||
public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws Exception { | |||||
return delegate.loadFont(in, fontFace); | |||||
} | |||||
public FOPGVTFontFamily getDefault() { | public FOPGVTFontFamily getDefault() { | ||||
return delegate.getDefault(); | return delegate.getDefault(); | ||||
} | } |
@Test | @Test | ||||
public void testDeriveFont() { | public void testDeriveFont() { | ||||
FOPGVTFontFamily family = (FOPGVTFontFamily) resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF); | |||||
FOPGVTFontFamily family = resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF); | |||||
FOPGVTFont font = family.deriveFont(10, Collections.emptyMap()); | FOPGVTFont font = family.deriveFont(10, Collections.emptyMap()); | ||||
assertEquals(10, font.getSize(), 0); | assertEquals(10, font.getSize(), 0); | ||||
assertTrue(font.canDisplay('\u01F6')); | assertTrue(font.canDisplay('\u01F6')); | ||||
@Test | @Test | ||||
@Ignore("FOP metrics don't match AWT, but not sure who is right and who is wrong") | @Ignore("FOP metrics don't match AWT, but not sure who is right and who is wrong") | ||||
public void testLineMetrics() throws FontFormatException, IOException { | public void testLineMetrics() throws FontFormatException, IOException { | ||||
FOPGVTFontFamily family = (FOPGVTFontFamily) resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF); | |||||
FOPGVTFontFamily family = resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF); | |||||
FOPGVTFont font = family.deriveFont(10, Collections.emptyMap()); | FOPGVTFont font = family.deriveFont(10, Collections.emptyMap()); | ||||
GVTLineMetrics fopMetrics = font.getLineMetrics("", null); | GVTLineMetrics fopMetrics = font.getLineMetrics("", null); | ||||
LineMetrics awtMetrics = getAWTLineMetrics(); | LineMetrics awtMetrics = getAWTLineMetrics(); |