Revision: 11830
http://sourceforge.net/p/foray/code/11830
Author: victormote
Date: 2021-01-19 03:10:34 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Combing methods for simplicity and clarity, in preparation for refactoring API.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-18 20:43:30 UTC (rev 11829)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-19 03:10:34 UTC (rev 11830)
@@ -75,47 +75,21 @@
final GraphicOutputContext outputContext,
final FontConsumer fontConsumer, final boolean strokeText,
final boolean commentsEnabled) throws GraphicException {
- SVGDocument doc = null;
- doc = this.svg.getSvgDocument();
- final PdfGraphics2D graphics = getPDFContent4SVG(fontConsumer, doc,
- strokeText, outputContext, output);
- if (graphics == null) {
- throw new GraphicException("Unable to convert to PDF: "
- + this.svg.getUrl().toExternalForm());
- }
- graphics.dispose();
- if (graphics.ioErrorFound()) {
- throw new GraphicException("I/O error(s) while converting to PDF: "
- + this.svg.getUrl().toExternalForm());
- }
- }
-
- /**
- * Convert an SVG document to a PdfGraphics2D.
- * @param fontConsumer The font consumer.
- * @param svgDocument The SVG document.
- * @param strokeSVGText Indicates whether text should be stroked.
- * @param pdfContext The PDF context in which this content is being written.
- * @return The PdfGraphics2D instance for the SVG.
- * @param outputStream The output stream to which this processor writes its
- * PDF output.
- */
- public PdfGraphics2D getPDFContent4SVG(final FontConsumer fontConsumer,
- final SVGDocument svgDocument,
- final boolean strokeSVGText, final GraphicOutputContext pdfContext,
- final OutputStream outputStream) {
/* If not running in a graphical environment, log an error message
* and skip the SVG. */
if (! Environment.isGraphicalEnvironment()) {
this.svg.getLogger().error("Unable to get Graphical Environment "
+ "required to process SVG. Skipping.");
- return null;
+ return;
}
+
+ final SVGDocument svgDocument = this.svg.getSvgDocument();
+
final BatikUaDocument userAgent = new BatikUaDocument(new AffineTransform());
BridgeContext ctx = new BridgeContext(userAgent);
GVTBuilder builder = new GVTBuilder();
TextPainter textPainter = null;
- if (strokeSVGText) {
+ if (strokeText) {
textPainter = new StrokingTextPainter();
} else {
textPainter = new PdfTextPainter(fontConsumer);
@@ -129,12 +103,16 @@
ctx = null;
builder = null;
- final PdfGraphics2D graphics;
- graphics = new PdfGraphics2D(true, fontConsumer, pdfContext, outputStream);
+ final PdfGraphics2D graphics = new PdfGraphics2D(strokeText, fontConsumer, outputContext, output);
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
root.paint(graphics);
- return graphics;
+
+ graphics.dispose();
+ if (graphics.ioErrorFound()) {
+ throw new GraphicException("I/O error(s) while converting to PDF: "
+ + this.svg.getUrl().toExternalForm());
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|