Skip to content

Commit

Permalink
Merge pull request #108 from jartysiewicz/open-dev-v1
Browse files Browse the repository at this point in the history
ability to run examples from maven
  • Loading branch information
danfickle authored Jul 24, 2017
2 parents 717ff88 + 6a68cc0 commit 2207d2c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
14 changes: 14 additions & 0 deletions openhtmltopdf-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@
<use>false</use>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>com.openhtmltopdf.testcases.TestcaseRunner</mainClass>
<systemProperties>
<systemProperty>
<key>OUT_DIRECTORY</key>
<value>target/examples</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.openhtmltopdf.bidi.support.ICUBidiReorderer;
import com.openhtmltopdf.bidi.support.ICUBidiSplitter;
import com.openhtmltopdf.extend.FSObjectDrawer;
import com.openhtmltopdf.extend.OutputDevice;
import com.openhtmltopdf.extend.OutputDeviceGraphicsDrawer;
import com.openhtmltopdf.java2d.api.BufferedImagePageProcessor;
import com.openhtmltopdf.java2d.api.DefaultPageProcessor;
import com.openhtmltopdf.java2d.api.FSPageOutputStreamSupplier;
import com.openhtmltopdf.java2d.api.Java2DRendererBuilder;
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder.TextDirection;
import com.openhtmltopdf.extend.FSObjectDrawer;
import com.openhtmltopdf.extend.OutputDevice;
import com.openhtmltopdf.extend.OutputDeviceGraphicsDrawer;
import com.openhtmltopdf.render.DefaultObjectDrawerFactory;
import com.openhtmltopdf.render.RenderingContext;
import com.openhtmltopdf.svgsupport.BatikSVGDrawer;
Expand All @@ -25,10 +25,7 @@
import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.logging.Level;

Expand Down Expand Up @@ -207,7 +204,7 @@ public static void runTestCase(String testCaseFile) throws Exception {
byte[] htmlBytes = IOUtils
.toByteArray(TestcaseRunner.class.getResourceAsStream("/testcases/" + testCaseFile + ".html"));
String html = new String(htmlBytes, Charsets.UTF_8);
String outDir = System.getProperty("OUT_DIRECTORY", ".");
String outDir = prepareOutDir();
String testCaseOutputFile = outDir + "/" + testCaseFile + ".pdf";
String testCaseOutputPNGFile = outDir + "/" + testCaseFile + ".png";
FileOutputStream outputStream = new FileOutputStream(testCaseOutputFile);
Expand All @@ -217,6 +214,18 @@ public static void runTestCase(String testCaseFile) throws Exception {
renderPNG(html, testCaseOutputPNGFile);
}

private static String prepareOutDir() {
String outDir = System.getProperty("OUT_DIRECTORY", ".");
File outDirFile = new File(outDir);
if (!outDirFile.exists()) {
boolean created = outDirFile.mkdirs();
if (!created) {
throw new IllegalStateException("Can't create out dir '" + outDir + "'.");
}
}
return outDir;
}

public static class SampleObjectDrawerBinaryTree implements FSObjectDrawer {
int fanout;
int angle;
Expand Down

0 comments on commit 2207d2c

Please sign in to comment.