Skip to content

Commit

Permalink
More cleanup and code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
edragoev1 committed Mar 19, 2023
1 parent 3a5bda3 commit 64f3807
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
19 changes: 7 additions & 12 deletions com/pdfjet/SVGImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -44,13 +46,16 @@ 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.
*
* @param stream the input stream.
* @throws Exception if exception occurred.
*/
public SVGImage(InputStream stream) throws Exception {
colorMap = new ColorMap();
paths = new ArrayList<SVGPath>();
SVGPath path = null;
StringBuilder buf = new StringBuilder();
Expand Down Expand Up @@ -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());
Expand All @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions run-graalvm-native-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions run-java-1.5.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 64f3807

Please sign in to comment.