xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sstei...@apache.org
Subject svn commit: r1618887 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: pdf/PDFDocument.java pdf/PDFFactory.java pdf/PDFResourceContext.java pdf/PDFResources.java svg/PDFGraphics2D.java
Date Tue, 19 Aug 2014 15:24:45 GMT
Author: ssteiner
Date: Tue Aug 19 15:24:45 2014
New Revision: 1618887

URL: http://svn.apache.org/r1618887
Log:
FOP-2406: Error when image next to pdf

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java?rev=1618887&r1=1618886&r2=1618887&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java Tue Aug 19 15:24:45
2014
@@ -402,6 +402,19 @@ public class PDFDocument {
     }
 
     /**
+     * Registers a {@link PDFObject} in this PDF document at end.
+     * The object is assigned a new object number.
+     *
+     * @param obj {@link PDFObject} to add
+     * @return the added {@link PDFObject} added (with its object number set)
+     */
+    <T extends PDFObject> T registerTrailerObject(T obj) {
+        assignObjectNumber(obj);
+        addTrailerObject(obj);
+        return obj;
+    }
+
+    /**
      * Assigns the {@link PDFObject} an object number,
      * and sets the parent of the {@link PDFObject} to this document.
      *
@@ -827,7 +840,7 @@ public class PDFDocument {
         PDFImageXObject xObject = (PDFImageXObject)this.xObjectsMap.get(key);
         if (xObject != null) {
             if (res != null) {
-                res.getPDFResources().addXObject(xObject);
+                res.addXObject(xObject);
             }
             return xObject;
         }
@@ -839,7 +852,7 @@ public class PDFDocument {
         registerObject(xObject);
         this.resources.addXObject(xObject);
         if (res != null) {
-            res.getPDFResources().addXObject(xObject);
+            res.addXObject(xObject);
         }
         this.xObjectsMap.put(key, xObject);
         return xObject;
@@ -867,7 +880,7 @@ public class PDFDocument {
         PDFFormXObject xObject = (PDFFormXObject)xObjectsMap.get(key);
         if (xObject != null) {
             if (res != null) {
-                res.getPDFResources().addXObject(xObject);
+                res.addXObject(xObject);
             }
             return xObject;
         }
@@ -879,7 +892,7 @@ public class PDFDocument {
         registerObject(xObject);
         this.resources.addXObject(xObject);
         if (res != null) {
-            res.getPDFResources().addXObject(xObject);
+            res.addXObject(xObject);
         }
         this.xObjectsMap.put(key, xObject);
         return xObject;
@@ -1092,6 +1105,9 @@ public class PDFDocument {
 
     public void setMergeFontsEnabled(boolean mergeFontsEnabled) {
         this.mergeFontsEnabled = mergeFontsEnabled;
+        if (mergeFontsEnabled) {
+            getResources().createFontsAsObj();
+        }
     }
 
     private interface TrailerOutputHelper {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java?rev=1618887&r1=1618886&r2=1618887&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java Tue Aug 19 15:24:45
2014
@@ -303,9 +303,7 @@ public class PDFFactory {
 
         // add this shading to resources
         if (res != null) {
-            res.getPDFResources().addShading(shading);
-        } else {
-            getDocument().getResources().addShading(shading);
+            res.addShading(shading);
         }
         return shading;
     }
@@ -348,9 +346,7 @@ public class PDFFactory {
         }
 
         if (res != null) {
-            res.getPDFResources().addPattern(pattern);
-        } else {
-            getDocument().getResources().addPattern(pattern);
+            res.addPattern(pattern);
         }
 
         return (pattern);
@@ -365,9 +361,7 @@ public class PDFFactory {
         }
 
         if (res != null) {
-            res.getPDFResources().addPattern(pattern);
-        } else {
-            getDocument().getResources().addPattern(pattern);
+            res.addPattern(pattern);
         }
         return pattern;
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java?rev=1618887&r1=1618886&r2=1618887&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java Tue Aug 19 15:24:45
2014
@@ -19,6 +19,9 @@
 
 package org.apache.fop.pdf;
 
+import java.util.LinkedHashSet;
+import java.util.Set;
+
 /**
  * The PDF resource context.
  *
@@ -34,6 +37,10 @@ package org.apache.fop.pdf;
  * only the object ID of the parent, rather than the parent itself.
  */
 public class PDFResourceContext extends PDFDictionary {
+    private Set<PDFXObject> xObjects = new LinkedHashSet<PDFXObject>();
+    private Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
+    private Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
+    private Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
 
     /**
      * Creates a new ResourceContext.
@@ -45,6 +52,16 @@ public class PDFResourceContext extends 
 
         /* set fields using parameters */
         put("Resources", resources);
+
+        resources.addContext(this);
+    }
+
+    public void addXObject(PDFXObject xObject) {
+        xObjects.add(xObject);
+    }
+
+    public Set<PDFXObject> getXObjects() {
+        return xObjects;
     }
 
     /**
@@ -85,7 +102,11 @@ public class PDFResourceContext extends 
      * @param gstate the GState to add
      */
     public void addGState(PDFGState gstate) {
-        getPDFResources().addGState(gstate);
+        gstates.add(gstate);
+    }
+
+    public Set<PDFGState> getGStates() {
+        return gstates;
     }
 
     /**
@@ -94,7 +115,18 @@ public class PDFResourceContext extends 
      * @param shading the shading to add
      */
     public void addShading(PDFShading shading) {
-        getPDFResources().addShading(shading);
+        shadings.add(shading);
+    }
+
+    public Set<PDFShading> getShadings() {
+        return shadings;
     }
 
+    public Set<PDFPattern> getPatterns() {
+        return patterns;
+    }
+
+    public void addPattern(PDFPattern pattern) {
+        patterns.add(pattern);
+    }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java?rev=1618887&r1=1618886&r2=1618887&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java Tue Aug 19 15:24:45
2014
@@ -51,32 +51,20 @@ public class PDFResources extends PDFDic
      * Set of XObjects
      */
     protected Set<PDFXObject> xObjects = new LinkedHashSet<PDFXObject>();
-
-    /**
-     * Set of patterns
-     */
-    protected Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
-
-    /**
-     * Set of shadings
-     */
-    protected Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
-
-    /**
-     * Set of ExtGStates
-     */
-    protected Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
-
     /** Map of color spaces (key: color space name) */
     protected Map<PDFName, PDFColorSpace> colorSpaces = new LinkedHashMap<PDFName,
PDFColorSpace>();
 
     /** Map of ICC color spaces (key: ICC profile description) */
     protected Map<String, PDFICCBasedColorSpace> iccColorSpaces = new LinkedHashMap<String,
PDFICCBasedColorSpace>();
 
+    private PDFResources parent;
+    private PDFDictionary fontsObj;
+    private Map<String, PDFDictionary> fontsObjDict = new LinkedHashMap<String,
PDFDictionary>();
+
     /** Named properties */
     protected Map<String, PDFReference> properties = new LinkedHashMap<String, PDFReference>();
 
-    private PDFResources parent;
+    protected Set<PDFResourceContext> contexts = new LinkedHashSet<PDFResourceContext>();
 
     /**
      * create a /Resources object.
@@ -89,6 +77,10 @@ public class PDFResources extends PDFDic
         setObjectNumber(objnum);
     }
 
+    public void addContext(PDFResourceContext c) {
+        contexts.add(c);
+    }
+
     public void setParentResources(PDFResources p) {
         parent = p;
     }
@@ -103,15 +95,22 @@ public class PDFResources extends PDFDic
      * @param font the PDFFont to add
      */
     public void addFont(PDFFont font) {
-        fonts.put(font.getName(), font);
+        addFont(font.getName(), font);
     }
 
     public void addFont(String name, PDFDictionary font) {
-        fonts.put(name, font);
+        if (fontsObj != null) {
+            fontsObj.put(name, font);
+            fontsObjDict.put(name, font);
+        } else {
+            fonts.put(name, font);
+        }
     }
 
-    public Map<String, PDFDictionary> getFonts() {
-        return fonts;
+    public void createFontsAsObj() {
+        fontsObj = new PDFDictionary();
+        getDocument().registerTrailerObject(fontsObj);
+        put("Font", fontsObj);
     }
 
     /**
@@ -122,9 +121,8 @@ public class PDFResources extends PDFDic
      */
    public void addFonts(PDFDocument doc, FontInfo fontInfo) {
         Map<String, Typeface> usedFonts = fontInfo.getUsedFonts();
-        for (Map.Entry<String, Typeface> e : usedFonts.entrySet()) {
-            String f = e.getKey();
-            Typeface font = e.getValue();
+        for (String f : usedFonts.keySet()) {
+            Typeface font = usedFonts.get(f);
 
             //Check if the font actually had any mapping operations. If not, it is an indication
             //that it has never actually been used and therefore doesn't have to be embedded.
@@ -141,34 +139,7 @@ public class PDFResources extends PDFDic
                     f, font.getEmbedFontName(), encoding, font, desc));
             }
         }
-    }
-
-    /**
-     * Add a PDFGState to the resources.
-     *
-     * @param gs the PDFGState to add
-     */
-    public void addGState(PDFGState gs) {
-        this.gstates.add(gs);
-    }
-
-    /**
-     * Add a Shading to the resources.
-     *
-     * @param theShading the shading to add
-     */
-    public void addShading(PDFShading theShading) {
-        this.shadings.add(theShading);
-    }
-
-    /**
-     * Add the pattern to the resources.
-     *
-     * @param thePattern the pattern to add
-     */
-    public void addPattern(PDFPattern thePattern) {
-        this.patterns.add(thePattern);
-    }
+   }
 
     /**
      * Add an XObject to the resources.
@@ -239,21 +210,40 @@ public class PDFResources extends PDFDic
     }
 
     private void populateDictionary() {
-        if (!this.fonts.isEmpty() || (parent != null && !parent.getFonts().isEmpty()))
{
+        if (parent != null && parent.fontsObj != null) {
+            put("Font", parent.fontsObj);
+        }
+        if (!this.fonts.isEmpty() || (parent != null && !parent.fonts.isEmpty()))
{
             PDFDictionary dict = new PDFDictionary(this);
             /* construct PDF dictionary of font object references */
             for (Map.Entry<String, PDFDictionary> entry : fonts.entrySet()) {
                 dict.put(entry.getKey(), entry.getValue());
             }
             if (parent != null) {
-                for (Map.Entry<String, PDFDictionary> entry : parent.getFonts().entrySet())
{
+                for (Map.Entry<String, PDFDictionary> entry : parent.fonts.entrySet())
{
+                    dict.put(entry.getKey(), entry.getValue());
+                }
+                for (Map.Entry<String, PDFDictionary> entry : parent.fontsObjDict.entrySet())
{
                     dict.put(entry.getKey(), entry.getValue());
                 }
             }
             put("Font", dict);
         }
 
-        if (!this.shadings.isEmpty()) {
+        Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
+        Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
+        Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
+        for (PDFResourceContext c : contexts) {
+            xObjects.addAll(c.getXObjects());
+            patterns.addAll(c.getPatterns());
+            shadings.addAll(c.getShadings());
+            gstates.addAll(c.getGStates());
+        }
+        if (parent != null) {
+            xObjects.addAll(parent.xObjects);
+        }
+
+        if (!shadings.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
             for (PDFShading shading : shadings) {
                 dict.put(shading.getName(), shading);
@@ -261,7 +251,7 @@ public class PDFResources extends PDFDic
             put("Shading", dict);
         }
 
-        if (!this.patterns.isEmpty()) {
+        if (!patterns.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
             for (PDFPattern pattern : patterns) {
                 dict.put(pattern.getName(), pattern);
@@ -276,15 +266,18 @@ public class PDFResources extends PDFDic
         procset.add(new PDFName("Text"));
         put("ProcSet", procset);
 
-        if (this.xObjects != null && !this.xObjects.isEmpty()) {
-            PDFDictionary dict = new PDFDictionary(this);
+        if (!xObjects.isEmpty()) {
+            PDFDictionary dict = (PDFDictionary) get("XObject");
+            if (dict == null) {
+                dict = new PDFDictionary(this);
+            }
             for (PDFXObject xObject : xObjects) {
                 dict.put(xObject.getName().toString(), xObject);
             }
             put("XObject", dict);
         }
 
-        if (!this.gstates.isEmpty()) {
+        if (!gstates.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
             for (PDFGState gstate : gstates) {
                 dict.put(gstate.getName(), gstate);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java?rev=1618887&r1=1618886&r2=1618887&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java Tue Aug 19 15:24:45
2014
@@ -564,7 +564,7 @@ public class PDFGraphics2D extends Abstr
 
             xObject = addRenderedImage(key, buf);
         } else {
-            resourceContext.getPDFResources().addXObject(xObject);
+            resourceContext.addXObject(xObject);
         }
 
         AffineTransform at = new AffineTransform();
@@ -1025,7 +1025,7 @@ public class PDFGraphics2D extends Abstr
         PDFXObject imageInfo = pdfDoc.getXObject(
             "TempImage:" + pctx.toString());
         if (imageInfo != null) {
-            resourceContext.getPDFResources().addXObject(imageInfo);
+            resourceContext.addXObject(imageInfo);
         } else {
             Raster r = pctx.getRaster(devX, devY, devW, devH);
             WritableRaster wr = (WritableRaster)r;
@@ -1176,7 +1176,7 @@ public class PDFGraphics2D extends Abstr
         if (xObject == null) {
             xObject = addRenderedImage(key, img);
         } else {
-            resourceContext.getPDFResources().addXObject(xObject);
+            resourceContext.addXObject(xObject);
         }
 
         useXObject(xObject, xform, img.getWidth(), img.getHeight());



---------------------------------------------------------------------
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