if (!(f instanceof CFFType1Font)) {
throw new IOException(getEmbedFileURI() + ": only OTF CFF Type1 font can be converted to Type1");
}
- byte[] t1 = new Type1FontFormatter(cidSet.getGlyphs()).format((CFFType1Font) f);
+ byte[] t1 = new Type1FontFormatter(cidSet.getGlyphs(), eventListener).format((CFFType1Font) f);
PFBData pfb = new PFBParser().parsePFB(new ByteArrayInputStream(t1));
ByteArrayOutputStream s1 = new ByteArrayOutputStream();
s1.write(pfb.getHeaderSegment());
getEventProducer().fontDirectoryNotFound(source, dir);
}
+ public void fontType1MaxGlyphs(Object source, String fontName) {
+ getEventProducer().fontType1MaxGlyphs(source, fontName);
+ }
+
/** {@inheritDoc} */
public void svgTextStrokedAsShapes(Object source, String fontFamily) {
getEventProducer().svgTextStrokedAsShapes(source, fontFamily);
import org.apache.fontbox.cff.DataOutput;
import org.apache.fontbox.cff.Type1FontUtil;
+import org.apache.fop.fonts.FontEventListener;
+
/**
* This class represents a formatter for a given Type1 font.
* author Villu Ruusmann
*/
public final class Type1FontFormatter {
private Map<Integer, Integer> gids;
+ private FontEventListener eventListener;
- public Type1FontFormatter(Map<Integer, Integer> gids) {
+ public Type1FontFormatter(Map<Integer, Integer> gids, FontEventListener eventListener) {
this.gids = gids;
+ this.eventListener = eventListener;
}
/**
output.println("/StrokeWidth " + font.getTopDict().get("StrokeWidth")
+ " def");
- output.println("/Encoding " + gids.size() + " array");
- output.println("0 1 " + (gids.size() - 1) + " {1 index exch /.notdef put} for");
-
+ int max = 0;
+ StringBuilder sb = new StringBuilder();
for (Map.Entry<Integer, Integer> gid : gids.entrySet()) {
String name = font.getCharset().getNameForGID(gid.getKey());
- output.println("dup " + gid.getValue() + " /" + name + " put");
+ sb.append(String.format("dup %d /%s put", gid.getValue(), name)).append('\n');
+ max = Math.max(max, gid.getValue());
+ }
+ if (max > 255) {
+ eventListener.fontType1MaxGlyphs(this, font.getName());
}
+ output.println("/Encoding " + (max + 1) + " array");
+ output.println("0 1 " + max + " {1 index exch /.notdef put} for");
+ output.print(sb.toString());
output.println("readonly def");
output.println("currentdict end");
<message key="glyphNotAvailable">Glyph "{ch}" (0x{ch,hex}[, {ch,glyph-name}]) not available in font "{fontName}".</message>
<message key="fontDirectoryNotFound">The font directory {dir} could not be found.</message>
<message key="svgTextStrokedAsShapes">The SVG text for font {fontFamily} will be stroked as shapes.</message>
+ <message key="fontType1MaxGlyphs">Font "{fontName}" encoding has more than 256 glyphs may cause wrong output, enable font subsetting or disable 'embed-as-type1'.</message>
</catalogue>