]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2608: Improve OTF to Type1 full embedding
authorSimon Steiner <ssteiner@apache.org>
Thu, 19 May 2016 15:13:24 +0000 (15:13 +0000)
committerSimon Steiner <ssteiner@apache.org>
Thu, 19 May 2016 15:13:24 +0000 (15:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1744593 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java
fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java
fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java
fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java
fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java
fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java
fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml

index c73d8bbc0e6b7c98a1c737b396d02d6470e4d8fb..e823f3b160d4b1d1a336374d4913047df8b256ee 100644 (file)
@@ -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());
index e8078a7968a4ba90732114555e8ec33748abd5c5..56ee5601cfcc1a96805771c30b46714d80e36606 100644 (file)
@@ -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);
index 419a3fcd2c5fcf161c3feba643716a3f7f522147..a1ac8d32f4f1584f51a83587de2e435a3d3901ee 100644 (file)
@@ -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);
 }
index c6aaef662d76ecc9ebb0a54074cfe0d7606ee7f2..02ab1eaa57b26cf454c7e5b401662f4f34f3da96 100644 (file)
@@ -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);
 }
index 469f66b121551197efabd112c8c7e70ba1ba49ad..ae619d9e20fab61d84657df501c1bccb31d4c0e2 100644 (file)
@@ -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");
index af9921c4da44a8717ef0e3d470cfeda316eae9bb..74389e9adfdfb98581514c5ef053d27573ef7b63 100644 (file)
@@ -155,6 +155,9 @@ public final class FontListMain {
                 // ignore
             }
 
+            public void fontType1MaxGlyphs(Object source, String fontName) {
+                //ignore
+            }
         };
 
         FontListGenerator listGenerator = new FontListGenerator();
index d7ce27e7aeb12e54cd5876b476237e2bb717b77b..8cd4e7372caa100992062803e2b80546f8223fc1 100644 (file)
@@ -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>