diff options
7 files changed, 34 insertions, 6 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java b/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java index c73d8bbc0..e823f3b16 100644 --- a/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java +++ b/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java @@ -52,7 +52,7 @@ public class CFFToType1Font extends MultiByteFont { 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()); diff --git a/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java b/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java index e8078a796..56ee5601c 100644 --- a/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java +++ b/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java @@ -66,6 +66,10 @@ public class FontEventAdapter implements FontEventListener { 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); diff --git a/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java b/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java index 419a3fcd2..a1ac8d32f 100644 --- a/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java +++ b/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java @@ -61,4 +61,6 @@ public interface FontEventListener { * @param fontFamily the family name of the font that is being stroked */ void svgTextStrokedAsShapes(Object source, String fontFamily); + + void fontType1MaxGlyphs(Object source, String fontName); } diff --git a/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java b/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java index c6aaef662..02ab1eaa5 100644 --- a/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java +++ b/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java @@ -86,4 +86,12 @@ public interface FontEventProducer extends EventProducer { * @event.severity WARN */ void svgTextStrokedAsShapes(Object source, String fontFamily); + + /** + * A method to warn the user that the font has too many glyphs + * @param source + * @param fontName + * @event.severity ERROR + */ + void fontType1MaxGlyphs(Object source, String fontName); } diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java b/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java index 469f66b12..ae619d9e2 100644 --- a/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java +++ b/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java @@ -28,6 +28,8 @@ import org.apache.fontbox.cff.CFFType1Font; 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 @@ -35,9 +37,11 @@ import org.apache.fontbox.cff.Type1FontUtil; */ 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; } /** @@ -108,13 +112,19 @@ public final class Type1FontFormatter { 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"); diff --git a/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java b/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java index af9921c4d..74389e9ad 100644 --- a/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java +++ b/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java @@ -155,6 +155,9 @@ public final class FontListMain { // ignore } + public void fontType1MaxGlyphs(Object source, String fontName) { + //ignore + } }; FontListGenerator listGenerator = new FontListGenerator(); diff --git a/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml b/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml index d7ce27e7a..8cd4e7372 100644 --- a/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml +++ b/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml @@ -22,4 +22,5 @@ <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> |