diff options
author | Simon Steiner <ssteiner@apache.org> | 2023-08-01 15:21:50 +0100 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2023-08-01 15:22:11 +0100 |
commit | c49a080dc64d39ece4a0aba6f3ad20af56a4ac25 (patch) | |
tree | 612de519f6d79541f45038231729b24e8c13db92 /fop-core | |
parent | 76d37582a6e3b29697d694af7a85f1b87b7d9dbb (diff) | |
download | xmlgraphics-fop-c49a080dc64d39ece4a0aba6f3ad20af56a4ac25.tar.gz xmlgraphics-fop-c49a080dc64d39ece4a0aba6f3ad20af56a4ac25.zip |
FOP-2920: Cleanup passing event broadcaster
Diffstat (limited to 'fop-core')
8 files changed, 29 insertions, 27 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java index 5ebbb47d1..40370f705 100644 --- a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java +++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java @@ -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; + } } diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFResources.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFResources.java index 29e20193e..f98263fcb 100644 --- a/fop-core/src/main/java/org/apache/fop/pdf/PDFResources.java +++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFResources.java @@ -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)); } } } diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java index 02c532c1c..4158d0f2a 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java @@ -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(); diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java index 345cc424f..32fdc6e32 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java @@ -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()); diff --git a/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java index 656a68fa3..ab03355b7 100644 --- a/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -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); diff --git a/fop-core/src/main/java/org/apache/fop/svg/PDFGraphics2D.java b/fop-core/src/main/java/org/apache/fop/svg/PDFGraphics2D.java index d06c11fa7..cf8701522 100644 --- a/fop-core/src/main/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/fop-core/src/main/java/org/apache/fop/svg/PDFGraphics2D.java @@ -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, diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java index e1e38fcf6..14745cdee 100644 --- a/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java @@ -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()); diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFToUnicodeCMapTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFToUnicodeCMapTestCase.java index 746943119..67af746db 100644 --- a/fop-core/src/test/java/org/apache/fop/pdf/PDFToUnicodeCMapTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFToUnicodeCMapTestCase.java @@ -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() { |