]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2920: Cleanup passing event broadcaster
authorSimon Steiner <ssteiner@apache.org>
Tue, 1 Aug 2023 14:21:50 +0000 (15:21 +0100)
committerSimon Steiner <ssteiner@apache.org>
Tue, 1 Aug 2023 14:22:11 +0000 (15:22 +0100)
fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
fop-core/src/main/java/org/apache/fop/pdf/PDFResources.java
fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
fop-core/src/main/java/org/apache/fop/svg/PDFGraphics2D.java
fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
fop-core/src/test/java/org/apache/fop/pdf/PDFToUnicodeCMapTestCase.java

index 5ebbb47d1e3e963d2ae2eeff1d6d5002443a2ec3..40370f70518d23c1c53a83ed3ea80c9ca45d6497 100644 (file)
@@ -82,6 +82,7 @@ public class PDFFactory {
 
     private int subsetFontCounter = -1;
     private Map<String, PDFDPart> dparts = new HashMap<String, PDFDPart>();
+    private EventBroadcaster eventBroadcaster;
 
     /**
      * Creates a new PDFFactory.
@@ -931,12 +932,11 @@ public class PDFFactory {
      * @param encoding character encoding scheme used by the font
      * @param metrics additional information about the font
      * @param descriptor additional information about the font
-     * @param eventBroadcaster Event broadcaster.
      * @return the created /Font object
      */
     public PDFFont makeFont(String fontname, String basefont,
                             String encoding, FontMetrics metrics,
-                            FontDescriptor descriptor, EventBroadcaster eventBroadcaster) {
+                            FontDescriptor descriptor) {
         PDFFont preRegisteredfont = getDocument().findFont(fontname);
         if (preRegisteredfont != null) {
             return preRegisteredfont;
@@ -957,7 +957,7 @@ public class PDFFactory {
                     Typeface tf = (Typeface)metrics;
                     mapping = CodePointMapping.getMapping(tf.getEncodingName());
                 }
-                generateToUnicodeCmap(font, mapping, eventBroadcaster);
+                generateToUnicodeCmap(font, mapping);
             }
             return font;
         } else {
@@ -1007,8 +1007,7 @@ public class PDFFactory {
                     }
                 } else {
                     cmap = new PDFToUnicodeCMap(cidMetrics.getCIDSet().getChars(), "fop-ucs-H",
-                        new PDFCIDSystemInfo("Adobe", "Identity", 0), false,
-                                            eventBroadcaster);
+                        new PDFCIDSystemInfo("Adobe", "Identity", 0), false, eventBroadcaster);
                 }
                 getDocument().registerObject(cmap);
                 assert font instanceof PDFFontType0;
@@ -1078,7 +1077,7 @@ public class PDFFactory {
                 if (singleByteFont.isSymbolicFont()) {
                     //no encoding, use the font's encoding
                     if (forceToUnicode) {
-                        generateToUnicodeCmap(nonBase14, mapping, eventBroadcaster);
+                        generateToUnicodeCmap(nonBase14, mapping);
                     }
                 } else if (PDFEncoding.isPredefinedEncoding(mapping.getName())) {
                     font.setEncoding(mapping.getName());
@@ -1108,7 +1107,7 @@ public class PDFFactory {
                         pdfEncoding.setDifferences(differences);
                         font.setEncoding(pdfEncoding);
                         if (mapping.getUnicodeCharMap() != null) {
-                            generateToUnicodeCmap(nonBase14, mapping, eventBroadcaster);
+                            generateToUnicodeCmap(nonBase14, mapping);
                         }
                     }
                 } else {
@@ -1120,7 +1119,7 @@ public class PDFFactory {
                         font.setEncoding((String)pdfEncoding);
                     }
                     if (forceToUnicode) {
-                        generateToUnicodeCmap(nonBase14, mapping, eventBroadcaster);
+                        generateToUnicodeCmap(nonBase14, mapping);
                     }
                 }
 
@@ -1143,7 +1142,7 @@ public class PDFFactory {
                         getDocument().registerObject(addFont);
                         getDocument().getResources().addFont(addFont);
                         if (forceToUnicode) {
-                            generateToUnicodeCmap(addFont, addEncoding, eventBroadcaster);
+                            generateToUnicodeCmap(addFont, addEncoding);
                         }
                     }
                 }
@@ -1231,7 +1230,7 @@ public class PDFFactory {
         return additionalEncodings;
     }
 
-    private void generateToUnicodeCmap(PDFFont font, SingleByteEncoding encoding, EventBroadcaster eventBroadcaster) {
+    private void generateToUnicodeCmap(PDFFont font, SingleByteEncoding encoding) {
         PDFCMap cmap = new PDFToUnicodeCMap(encoding.getUnicodeCharMap(),
                 "fop-ucs-H",
                 new PDFCIDSystemInfo("Adobe", "Identity", 0), true, eventBroadcaster);
@@ -1704,4 +1703,8 @@ public class PDFFactory {
         getDocument().registerTrailerObject(pdfdPartRoot);
         return pdfdPartRoot;
     }
+
+    public void setEventBroadcaster(EventBroadcaster eventBroadcaster) {
+        this.eventBroadcaster = eventBroadcaster;
+    }
 }
index 29e20193ee38cdaf10a7c6f26f6defb323d95613..f98263fcbf17b167aea09e8161b276159bf8d664 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Set;
 
 import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
 
-import org.apache.fop.events.EventBroadcaster;
 import org.apache.fop.fonts.FontDescriptor;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.Typeface;
@@ -117,9 +116,8 @@ public class PDFResources extends PDFDictionary {
      *
      * @param doc PDF document to add fonts to
      * @param fontInfo font info object to get font information from
-     * @param eventBroadcaster Event broadcaster.
      */
-   public void addFonts(PDFDocument doc, FontInfo fontInfo, EventBroadcaster eventBroadcaster) {
+   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();
@@ -137,7 +135,7 @@ public class PDFResources extends PDFDictionary {
                     encoding = null; //Symbolic fonts shouldn't specify an encoding value in PDF
                 }
                 addFont(doc.getFactory().makeFont(
-                    f, font.getEmbedFontName(), encoding, font, desc, eventBroadcaster));
+                    f, font.getEmbedFontName(), encoding, font, desc));
             }
         }
    }
index 02c532c1c46969816befd32ba240b6c63c189f51..4158d0f2a673974fcc68fdbb6a03d622e4a6fcd4 100644 (file)
@@ -185,7 +185,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
     /** {@inheritDoc} */
     public void endDocument() throws IFException {
         documentNavigationHandler.registerIncompleteActions();
-        pdfDoc.getResources().addFonts(pdfDoc, fontInfo, getUserAgent().getEventBroadcaster());
+        pdfDoc.getResources().addFonts(pdfDoc, fontInfo);
         try {
             if (pdfDoc.isLinearizationEnabled()) {
                 generator.flushPDFDoc();
index 345cc424f5eeb8071508c31bbc8219997a31585e..32fdc6e32c40b3a7cc942394449f3bbc8d98e182 100644 (file)
@@ -603,6 +603,7 @@ class PDFRenderingUtil {
                     = VersionController.getFixedVersionController(maxPDFVersion);
             this.pdfDoc = new PDFDocument(producer, controller);
         }
+        pdfDoc.getFactory().setEventBroadcaster(userAgent.getEventBroadcaster());
         updateInfo();
         updatePDFProfiles();
         pdfDoc.setFilterMap(rendererConfig.getFilterMap());
index 656a68fa3a3cb6bd2dcdfce9c604f18781b412ef..ab03355b7a2a788f24d35b3006d26728c6622f4f 100644 (file)
@@ -380,7 +380,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
 
         closePage();
         if (fontInfo != null) {
-            pdfDoc.getResources().addFonts(pdfDoc, fontInfo, null);
+            pdfDoc.getResources().addFonts(pdfDoc, fontInfo);
         }
         this.pdfDoc.output(outputStream);
         pdfDoc.outputTrailer(outputStream);
index d06c11fa71668b733dcf36178cc8af39142b4f5f..cf8701522c588cc9b3e510fbce910b7d7f24124e 100644 (file)
@@ -960,7 +960,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
         /** @todo see if pdfDoc and res can be linked here,
         (currently res <> PDFDocument's resources) so addFonts()
         can be moved to PDFDocument class */
-        res.addFonts(pdfDoc, specialFontInfo, null);
+        res.addFonts(pdfDoc, specialFontInfo);
 
         PDFPattern myPat = pdfDoc.getFactory().makePattern(
                                 resourceContext, 1, res, 1, 1, bbox,
index e1e38fcf696c95d6049937e2199c2d9abcd79f97..14745cdee9ab2c20c6fde7ea2ad406eb8b361ace 100644 (file)
@@ -84,10 +84,10 @@ public class PDFFactoryTestCase {
                 thisURI, resolver);
         MockedFont font = new MockedFont(resourceResolver);
 
-        PDFFont pdfDejaVu = pdfFactory.makeFont("DejaVu", "DejaVu", "TTF", font, font, null);
+        PDFFont pdfDejaVu = pdfFactory.makeFont("DejaVu", "DejaVu", "TTF", font, font);
         assertEquals("/EAAAAA+DejaVu", pdfDejaVu.getBaseFont().toString());
 
-        PDFFont pdfArial = pdfFactory.makeFont("Arial", "Arial", "TTF", font, font, null);
+        PDFFont pdfArial = pdfFactory.makeFont("Arial", "Arial", "TTF", font, font);
         assertEquals("/EAAAAB+Arial", pdfArial.getBaseFont().toString());
     }
 
@@ -104,7 +104,7 @@ public class PDFFactoryTestCase {
         sb.addUnencodedCharacter(new NamedCharacter("xyz", String.valueOf((char) 0x2202)), 0, new Rectangle());
         sb.mapChar((char) 0x2202);
         sb.setEncoding(new CodePointMapping("FOPPDFEncoding", new int[0]));
-        PDFFont font = pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb, null);
+        PDFFont font = pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         font.output(bos);
         assertTrue(bos.toString().contains("/BaseFont /EAAAAA+a"));
@@ -134,7 +134,7 @@ public class PDFFactoryTestCase {
                 return new char[]{1};
             }
         });
-        pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb, null);
+        pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         doc.outputTrailer(bos);
         assertTrue(bos.toString().contains("/Differences [1 /a]"));
@@ -151,7 +151,7 @@ public class PDFFactoryTestCase {
         sb.setFlags(0);
         sb.setEncoding(new CodePointMapping("FOPPDFEncoding", new int[0]));
         String enc = "MacRomanEncoding";
-        PDFFont font = pdfFactory.makeFont("a", "a", enc, sb, sb, null);
+        PDFFont font = pdfFactory.makeFont("a", "a", enc, sb, sb);
         font.output(new ByteArrayOutputStream());
         assertEquals(((PDFName)font.entries.get("Encoding")).getName(), enc);
     }
@@ -183,7 +183,7 @@ public class PDFFactoryTestCase {
         for (char c = 0; c < 512; c++) {
             sb.mapChar(c);
         }
-        pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb, null);
+        pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         doc.outputTrailer(bos);
 
@@ -217,7 +217,7 @@ public class PDFFactoryTestCase {
         for (char c = 0; c < 512; c++) {
             sb.mapChar(c);
         }
-        pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb, null);
+        pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb);
         PDFFont pdfFont = pdfFactory.getDocument().getFontMap().get("a_1");
         PDFFontDescriptor fontDescriptor = (PDFFontDescriptor) pdfFont.get("FontDescriptor");
         assertNull(fontDescriptor.getCIDSet());
index 746943119f2ee863ab0a33f61234a4589eb08b59..67af746dbe72b7843cef3b1c7be11b161e060e46 100644 (file)
@@ -43,11 +43,11 @@ import org.apache.fop.events.model.EventSeverity;
 
 public class PDFToUnicodeCMapTestCase {
 
-    static final int UNICODE_CHAR_MAP_SIZE = 200;
+    private static final int UNICODE_CHAR_MAP_SIZE = 200;
 
-    static final char[] S_UNICODE_CHAR_MAP = new char[UNICODE_CHAR_MAP_SIZE];
+    private static final char[] S_UNICODE_CHAR_MAP = new char[UNICODE_CHAR_MAP_SIZE];
 
-    EventBroadcaster eventBroadcaster;
+    private EventBroadcaster eventBroadcaster;
 
     @Before
     public void initUnicodeChatMap() {