Skip to content

Commit

Permalink
Merge/1.3 in 1.4 (#1121)
Browse files Browse the repository at this point in the history
Pick enhancements from 1.3 into 1.4

- Shandra's IndirectObjects
- Lonzak's ECDSA fixes
- Many @OVERRIDES
- Javadoc
- Cleanups
  • Loading branch information
asturio authored Mar 29, 2024
1 parent a31c615 commit 4f7d9d9
Show file tree
Hide file tree
Showing 21 changed files with 909 additions and 634 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
name: OpenPDF checkstyle
on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]
on: [ push, pull_request ]

jobs:
checkstyle_job:
runs-on: ubuntu-latest
name: Checkstyle job
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
uses: actions/checkout@v4
- name: Run check style
uses: dbelyaev/action-checkstyle@v1.2.1
uses: dbelyaev/action-checkstyle@v1
with:
checkstyle_config: 'checkstyle.xml'
reporter: 'github-pr-check'
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/codacy-coverage-reporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Codacy Coverage Reporter

on: [ push ]

jobs:
codacy-coverage-reporter:
runs-on: ubuntu-latest
name: codacy-coverage-reporter
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21

- name: Create coverage reports
run: mvn -B verify --file pom.xml

- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: ./openpdf/target/site/jacoco/jacoco.xml, ./pdf-toolbox/target/site/jacoco/jacoco.xml, ./openpdf-fonts-extra/target/site/jacoco/jacoco.xml
44 changes: 8 additions & 36 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,25 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: OpenPDF maven build
on:
push:
branches: [ '*' ]
pull_request:
branches: [ master, 1.3-java8, 1.4-java11 ]
on: [ push, pull_request ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# Java 11 in this branch 1.4-java11
java: [ 11 ]
name: Java ${{matrix.java}}
name: Build with Java 11
steps:
- uses: actions/checkout@v4.1.1
- name: Setup java
uses: actions/setup-java@v4
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{matrix.java}}
java-version: 11

- name: Check maven version
run: mvn -v; echo "** ls **"; pwd && ls -l
- name: Build with Maven
run: mvn -B install --file pom.xml

codacy-coverage-reporter:
runs-on: ubuntu-latest
name: Java 17 and codacy-coverage-reporter
steps:
- uses: actions/[email protected]
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Build with Maven
run: mvn -B verify --file pom.xml
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
# or
# api-token: ${{ secrets.CODACY_API_TOKEN }}
coverage-reports: ./openpdf/target/site/jacoco/jacoco.xml,./pdf-toolbox/target/site/jacoco/jacoco.xml,./openpdf-fonts-extra/target/site/jacoco/jacoco.xml
# or a comma-separated list for multiple reports
# coverage-reports: <PATH_TO_REPORT>, <PATH_TO_REPORT>
run: mvn -B install --file pom.xml
2 changes: 1 addition & 1 deletion changelogs/1.3.32.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
* Bump com.ibm.icu:icu4j from 73.2 to 74.1 (#976)
* Bump org.pitest:pitest-junit5-plugin from 1.2.0 to 1.2.1 (#975)
* Bump org.apache.maven.plugins:maven-clean-plugin from 3.3.1 to 3.3.2
* Bump org.apache.maven.plugins:maven-checkstyle-plugin (#978)
* Bump org.apache.maven.plugins:maven-checkstyle-plugin (#978)
846 changes: 469 additions & 377 deletions config/eclipse-java-openpdf-style.xml

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions openpdf/src/main/java/com/lowagie/text/ExceptionConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class ExceptionConverter extends RuntimeException {
*/
public ExceptionConverter(Exception ex) {
this.ex = ex;
prefix = (ex instanceof RuntimeException) ? "" : "ExceptionConverter: ";
this.prefix = (ex instanceof RuntimeException) ? "" : "ExceptionConverter: ";
}

/**
Expand All @@ -113,39 +113,43 @@ public static final RuntimeException convertException(Exception ex) {
* @return the original exception
*/
public Exception getException() {
return ex;
return this.ex;
}

/**
* We print the message of the checked exception
*
* @return message of the original exception
*/
@Override
public String getMessage() {
return ex.getMessage();
return this.ex.getMessage();
}

/**
* and make sure we also produce a localized version
*
* @return localized version of the message
*/
@Override
public String getLocalizedMessage() {
return ex.getLocalizedMessage();
return this.ex.getLocalizedMessage();
}

/**
* The toString() is changed to be prefixed with ExceptionConverter
*
* @return String version of the exception
*/
@Override
public String toString() {
return prefix + ex;
return this.prefix + this.ex;
}

/**
* we have to override this as well
*/
@Override
public void printStackTrace() {
printStackTrace(System.err);
}
Expand All @@ -155,10 +159,11 @@ public void printStackTrace() {
*
* @param printStream printStream
*/
@Override
public void printStackTrace(java.io.PrintStream printStream) {
synchronized (printStream) {
printStream.print(prefix);
ex.printStackTrace(printStream);
printStream.print(this.prefix);
this.ex.printStackTrace(printStream);
}
}

Expand All @@ -167,10 +172,11 @@ public void printStackTrace(java.io.PrintStream printStream) {
*
* @param printWriter printWriter
*/
@Override
public void printStackTrace(java.io.PrintWriter printWriter) {
synchronized (printWriter) {
printWriter.print(prefix);
ex.printStackTrace(printWriter);
printWriter.print(this.prefix);
this.ex.printStackTrace(printWriter);
}
}

Expand All @@ -180,6 +186,7 @@ public void printStackTrace(java.io.PrintWriter printWriter) {
*
* @return a Throwable
*/
@Override
public synchronized Throwable fillInStackTrace() {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ public static HyphenationEvent getHyphenation(String s) {
return new HyphenationAuto(lang, country, leftMin, rightMin);
}

@Deprecated
/**
* This method isn't used by iText, but you can use it to analyze the value of a style attribute inside a HashMap.
* The different elements of the style attribute are added to the HashMap as key-value pairs.
*
* @param h a Map that should have at least a key named style. After this method is invoked, more keys could be
* added.
*/
// this method is nor called anywhere. But it is public so theoretically it could be called by consumers of OpenPdf, but why?
public static void insertStyle(Map<String, String> h) {
String style = h.get("style");
Expand Down
36 changes: 17 additions & 19 deletions openpdf/src/main/java/com/lowagie/text/pdf/AcroFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static Object[] splitDAelements(String da) {
}
break;
case "g":
if (stack.size() >= 1) {
if (!stack.isEmpty()) {
float gray = Float.parseFloat(stack.get(stack.size() - 1));
if (gray != 0) {
ret[DA_COLOR] = new GrayColor(gray);
Expand Down Expand Up @@ -283,7 +283,7 @@ void fill() {
return;
}
PdfArray arrfds = (PdfArray) PdfReader.getPdfObjectRelease(top.get(PdfName.FIELDS));
if (arrfds == null || arrfds.size() == 0) {
if (arrfds == null || arrfds.isEmpty()) {
return;
}
for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
Expand Down Expand Up @@ -344,7 +344,7 @@ void fill() {
annot = null;
}
}
if (name.length() > 0) {
if (!name.isEmpty()) {
name = name.substring(0, name.length() - 1);
}
Item item = fields.get(name);
Expand Down Expand Up @@ -466,21 +466,20 @@ public String[] getAppearanceStates(String fieldName) {
* @return String[] of appearance names or null if the field can not be found
*/
public String[] getAppearanceNames(String fieldName, int idx) {
Item fd = (Item) this.fields.get(fieldName);
Item fd = this.fields.get(fieldName);
if (fd == null) {
return null;
}
ArrayList<String> names = new ArrayList<String>();
ArrayList<String> names = new ArrayList<>();

PdfDictionary dic = fd.getWidget(idx);
dic = dic.getAsDict(PdfName.AP);
if (dic != null) {
dic = dic.getAsDict(PdfName.N);
if (dic != null) {

Iterator it = dic.getKeys().iterator();
while (it.hasNext()) {
String name = PdfName.decodeName(((PdfName) it.next()).toString());
for (PdfName pdfName : dic.getKeys()) {
String name = PdfName.decodeName(pdfName.toString());
if (!names.contains(name)) {
names.add(name);
}
Expand Down Expand Up @@ -799,7 +798,6 @@ public void decodeGenericDictionary(PdfDictionary merged, BaseField tx) throws D
}
//flags
PdfNumber nfl = merged.getAsNumber(PdfName.F);
flags = 0;
tx.setVisibility(BaseField.VISIBLE_BUT_DOES_NOT_PRINT);
if (nfl != null) {
flags = nfl.intValue();
Expand Down Expand Up @@ -870,7 +868,7 @@ PdfAppearance getAppearance(PdfDictionary merged, String[] values, String fieldN
topFirst = 0;
String text = (values.length > 0) ? values[0] : null;

TextField tx = null;
TextField tx;
if (fieldCache == null || !fieldCache.containsKey(fieldName)) {
tx = new TextField(writer, null, null);
tx.setExtraMargin(extraMarginLeft, extraMarginTop);
Expand Down Expand Up @@ -1055,7 +1053,7 @@ public String getField(String name) {
}
PdfArray opts = item.getValue(0).getAsArray(PdfName.OPT);
if (opts != null) {
int idx = 0;
int idx;
try {
idx = Integer.parseInt(value);
PdfString ps = opts.getAsString(idx);
Expand All @@ -1072,7 +1070,7 @@ public String getField(String name) {
} else if (v instanceof PdfName) {
return PdfName.decodeName(v.toString());
} else if (v instanceof PdfArray) {
return ((PdfArray) v).toString();
return v.toString();
} else {
return "";
}
Expand All @@ -1097,10 +1095,6 @@ public String[] getListSelection(String name) {
if (item == null) {
return ret;
}
//PdfName type = (PdfName)PdfReader.getPdfObject(((PdfDictionary)item.merged.get(0)).get(PdfName.FT));
//if (!PdfName.CH.equals(type)) {
// return ret;
//}
PdfArray values = item.getMerged(0).getAsArray(PdfName.I);
if (values == null) {
return ret;
Expand Down Expand Up @@ -1320,7 +1314,7 @@ public Object getFieldProperty(String field, String name, int idx) {
throw new RuntimeException("No reader has been supplied to this AcroFields instance!");
}
try {
Item item = (Item) this.fields.get(field);
Item item = this.fields.get(field);
if (item == null) {
return false;
}
Expand Down Expand Up @@ -2225,7 +2219,7 @@ public HashMap<String, SignatureType> getSignatureTypes() {
}

PdfArray ref = v.getAsArray(PdfName.REFERENCE);
if (ref == null || ref.size() == 0) {
if (ref == null || ref.isEmpty()) {
this.sigTypes.put(entry.getKey(), SignatureType.APPROVAL);
} else {

Expand Down Expand Up @@ -2859,7 +2853,7 @@ public Item(PdfIndirectReference ref) {
*/
public void writeToAll(PdfName key, PdfObject value, int writeFlags) {
int i;
PdfDictionary curDict = null;
PdfDictionary curDict;
if ((writeFlags & WRITE_MERGED) != 0) {
for (i = 0; i < merged.size(); ++i) {
curDict = getMerged(i);
Expand Down Expand Up @@ -3102,6 +3096,7 @@ private RevisionStream(RandomAccessFileOrArray raf, int length) {
this.length = length;
}

@Override
public int read() throws IOException {
int n = read(b);
if (n != 1) {
Expand All @@ -3110,6 +3105,7 @@ public int read() throws IOException {
return b[0] & 0xff;
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
Expand All @@ -3129,6 +3125,7 @@ public int read(byte[] b, int off, int len) throws IOException {
return elen;
}

@Override
public void close() throws IOException {
if (!closed) {
raf.close();
Expand All @@ -3139,6 +3136,7 @@ public void close() throws IOException {

private static class SorterComparator implements Comparator<Object[]> {

@Override
public int compare(Object[] o1, Object[] o2) {
int n1 = ((int[]) o1[1])[0];
int n2 = ((int[]) o2[1])[0];
Expand Down
Loading

0 comments on commit 4f7d9d9

Please sign in to comment.