From 64f3807faa5664f00a8ce825980579049d8c384a Mon Sep 17 00:00:00 2001 From: EDragoev Date: Sat, 18 Mar 2023 22:11:17 -0400 Subject: [PATCH] More cleanup and code refactoring --- com/pdfjet/SVGImage.java | 19 +++++++------------ run-graalvm-native-image.sh | 3 +++ run-java-1.5.sh | 9 +++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100755 run-java-1.5.sh diff --git a/com/pdfjet/SVGImage.java b/com/pdfjet/SVGImage.java index 304ddc9f..80fd19d6 100644 --- a/com/pdfjet/SVGImage.java +++ b/com/pdfjet/SVGImage.java @@ -25,7 +25,9 @@ of this software and associated documentation files (the "Software"), to deal import java.io.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** @@ -44,6 +46,8 @@ public class SVGImage { private String actualText = Single.space; private String altDescription = Single.space; + private ColorMap colorMap = null; + /** * Used to embed SVG images in the PDF document. * @@ -51,6 +55,7 @@ public class SVGImage { * @throws Exception if exception occurred. */ public SVGImage(InputStream stream) throws Exception { + colorMap = new ColorMap(); paths = new ArrayList(); SVGPath path = null; StringBuilder buf = new StringBuilder(); @@ -98,10 +103,10 @@ public SVGImage(InputStream stream) throws Exception { if (buf.toString().equals("none")) { path.fill = Color.transparent; } else { - path.fill = mapColorNameToValue(buf.toString()); + path.fill = colorMap.getColor(buf.toString()); } } else if (param.equals("stroke")) { - path.stroke = mapColorNameToValue(buf.toString()); + path.stroke = colorMap.getColor(buf.toString()); } else if (param.equals("stroke-width")) { try { path.strokeWidth = Float.valueOf(buf.toString()); @@ -126,16 +131,6 @@ public SVGImage(InputStream stream) throws Exception { } } - private int mapColorNameToValue(String colorName) { - // int color = Color.black; - // try { - // color = (int) Color.class.getDeclaredField(colorName).get(Integer.class); - // } catch (Exception e) { - // } - // return color; - return (new ColorMap()).getColor(colorName); - } - /** * Sets the location of this SVG on the page. * diff --git a/run-graalvm-native-image.sh b/run-graalvm-native-image.sh index d3ae31e9..33d803cd 100755 --- a/run-graalvm-native-image.sh +++ b/run-graalvm-native-image.sh @@ -5,3 +5,6 @@ echo "Main-Class: examples.Example_$1" > manifest.txt rm manifest.txt rm *.exe.build_artifacts.txt rm com/pdfjet/*.class + +./Example_$1.exe +evince Example_$1.pdf diff --git a/run-java-1.5.sh b/run-java-1.5.sh new file mode 100755 index 00000000..da270459 --- /dev/null +++ b/run-java-1.5.sh @@ -0,0 +1,9 @@ +# Compile and package the library. +/opt/jdk1.5.0_22/bin/javac -O -encoding utf-8 -Xlint com/pdfjet/*.java -d out/production +/opt/jdk1.5.0_22/bin/jar cf PDFjet.jar -C out/production . + +# Compile and run the Example_?? program. +/opt/jdk1.5.0_22/bin/javac -encoding utf-8 -Xlint -cp PDFjet.jar examples/Example_$1.java +/opt/jdk1.5.0_22/bin/java -cp .:PDFjet.jar examples.Example_$1 + +mupdf Example_$1.pdf