xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sstei...@apache.org
Subject svn commit: r1744593 - in /xmlgraphics/fop/trunk/fop-core/src/main: java/org/apache/fop/fonts/ java/org/apache/fop/render/ps/ java/org/apache/fop/tools/fontlist/ resources/org/apache/fop/fonts/
Date Thu, 19 May 2016 15:13:25 GMT
Author: ssteiner
Date: Thu May 19 15:13:24 2016
New Revision: 1744593

URL: http://svn.apache.org/viewvc?rev=1744593&view=rev
Log:
FOP-2608: Improve OTF to Type1 full embedding

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

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java?rev=1744593&r1=1744592&r2=1744593&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java
(original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java
Thu May 19 15:13:24 2016
@@ -52,7 +52,7 @@ public class CFFToType1Font extends Mult
         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());

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java?rev=1744593&r1=1744592&r2=1744593&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java
(original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java
Thu May 19 15:13:24 2016
@@ -66,6 +66,10 @@ public class FontEventAdapter implements
         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);

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java?rev=1744593&r1=1744592&r2=1744593&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java
(original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java
Thu May 19 15:13:24 2016
@@ -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);
 }

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java?rev=1744593&r1=1744592&r2=1744593&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java
(original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java
Thu May 19 15:13:24 2016
@@ -86,4 +86,12 @@ public interface FontEventProducer exten
      * @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);
 }

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java?rev=1744593&r1=1744592&r2=1744593&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java
(original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java
Thu May 19 15:13:24 2016
@@ -28,6 +28,8 @@ import org.apache.fontbox.cff.CFFType1Fo
 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.Type1FontU
  */
 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");

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java?rev=1744593&r1=1744592&r2=1744593&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java
(original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java
Thu May 19 15:13:24 2016
@@ -155,6 +155,9 @@ public final class FontListMain {
                 // ignore
             }
 
+            public void fontType1MaxGlyphs(Object source, String fontName) {
+                //ignore
+            }
         };
 
         FontListGenerator listGenerator = new FontListGenerator();

Modified: xmlgraphics/fop/trunk/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml?rev=1744593&r1=1744592&r2=1744593&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml
(original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml
Thu May 19 15:13:24 2016
@@ -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>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message