-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from danfickle/better_java2d
Java2D - Ability to add fonts via code and manual test harness.
- Loading branch information
Showing
24 changed files
with
827 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
openhtmltopdf-core/src/main/java/com/openhtmltopdf/outputdevice/helper/AddedFont.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.openhtmltopdf.outputdevice.helper; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
|
||
import com.openhtmltopdf.extend.FSSupplier; | ||
import com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle; | ||
|
||
public class AddedFont { | ||
public final FSSupplier<InputStream> supplier; | ||
public final File fontFile; | ||
public final Integer weight; | ||
public final String family; | ||
public final boolean subset; | ||
public final FontStyle style; | ||
public final Object pdfontSupplier; // Bit of a hack, not type-safe! | ||
|
||
public AddedFont(FSSupplier<InputStream> supplier, File fontFile, Integer weight, String family, boolean subset, | ||
FontStyle style) { | ||
this.supplier = supplier; | ||
this.fontFile = fontFile; | ||
this.pdfontSupplier = null; | ||
this.weight = weight; | ||
this.family = family; | ||
this.subset = subset; | ||
this.style = style; | ||
} | ||
|
||
public AddedFont(Object pdfontSupplier, Integer weight, String family, boolean subset, FontStyle style) { | ||
this.supplier = null; | ||
this.fontFile = null; | ||
this.pdfontSupplier = pdfontSupplier; | ||
this.weight = weight; | ||
this.family = family; | ||
this.subset = subset; | ||
this.style = style; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/j2d/Java2DVisualTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.openhtmltopdf.testcases.j2d; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.openhtmltopdf.visualtest.Java2DVisualTester; | ||
import com.openhtmltopdf.visualtest.Java2DVisualTester.Java2DBuilderConfig; | ||
import com.openhtmltopdf.visualtest.TestSupport; | ||
|
||
public class Java2DVisualTest { | ||
private final Java2DVisualTester vtester; | ||
private final List<String> failed = new ArrayList<>(); | ||
|
||
private Java2DVisualTest() throws IOException { | ||
File outputDirectory = new File("target/test/visual-tests/test-output/j2d"); | ||
TestSupport.makeFontFiles(); | ||
vtester = new Java2DVisualTester( | ||
"/visualtest/j2d/html/", /* Resource path. */ | ||
"/visualtest/j2d/expected/", /* Expected resource path */ | ||
outputDirectory | ||
); | ||
} | ||
|
||
private void run(String resource, Java2DBuilderConfig config) throws IOException { | ||
if (!vtester.runTest(resource, config)) { | ||
failed.add(resource); | ||
} | ||
} | ||
|
||
private void run(String resource) throws IOException { | ||
run(resource, (builder) -> {}); | ||
} | ||
|
||
private void runAllTests() throws IOException { | ||
run("simple-blocks"); | ||
run("simple-text"); | ||
|
||
|
||
// If you add a test here, please remember to also | ||
// add it to runOneTest (commented out). | ||
} | ||
|
||
private void runOneTest() throws IOException { | ||
// run("simple-blocks"); | ||
// run("simple-text"); | ||
|
||
// If you add a test here, please remember to also add | ||
// it to runAllTests. | ||
} | ||
|
||
// These are not automated tests due to the slight differences between JDK versions | ||
// for Java2D output. Rather they are manual tests meant to be run before a release. | ||
public static void main(String[] args) throws Exception { | ||
Java2DVisualTest test = new Java2DVisualTest(); | ||
|
||
test.runOneTest(); | ||
test.runAllTests(); | ||
|
||
System.out.println("The failed tests were:"); | ||
System.out.println(test.failed); | ||
} | ||
} |
Oops, something went wrong.