Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support several flavours #643

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/main/java/org/verapdf/parser/PDFFlavour.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.verapdf.parser;

import java.util.List;

public enum PDFFlavour {
NO_FLAVOUR(Specification.NO_STANDARD),
PDFA_1_A(Specification.ISO_19005_1),
Expand Down Expand Up @@ -73,11 +75,29 @@ public enum PDFSpecification {
ISO_32000_1_7,
ISO_32000_2_0
}

public static boolean isFlavourPDFSpecification(List<PDFFlavour> flavours, PDFSpecification pdfSpecification) {
for (PDFFlavour flavour : flavours) {
if (isFlavourPDFSpecification(flavour, pdfSpecification)) {
return true;
}
}
return false;
}

public static boolean isFlavourPDFSpecification(PDFFlavour flavour, PDFSpecification pdfSpecification) {
return flavour != null && flavour.getSpecification().getPdfSpecification() == pdfSpecification;
}

public static boolean isFlavourFamily(List<PDFFlavour> flavours, SpecificationFamily specificationFamily) {
for (PDFFlavour flavour : flavours) {
if (isFlavourFamily(flavour, specificationFamily)) {
return true;
}
}
return false;
}

public static boolean isFlavourFamily(PDFFlavour flavour, SpecificationFamily specificationFamily) {
return flavour != null && flavour.getSpecification().getFamily() == specificationFamily;
}
Expand All @@ -86,10 +106,28 @@ public static boolean isFlavour(PDFFlavour currentFlavour, PDFFlavour flavour) {
return currentFlavour != null && currentFlavour == flavour;
}

public static boolean isFlavourPart(List<PDFFlavour> flavours, Specification specificationPart) {
for (PDFFlavour flavour : flavours) {
if (isFlavourPart(flavour, specificationPart)) {
return true;
}
}
return false;
}

public static boolean isFlavourPart(PDFFlavour flavour, Specification specificationPart) {
return flavour != null && flavour.getSpecification() == specificationPart;
}

public static boolean isPDFUA2RelatedFlavour(List<PDFFlavour> flavours) {
for (PDFFlavour flavour : flavours) {
if (isPDFUA2RelatedFlavour(flavour)) {
return true;
}
}
return false;
}

public static boolean isPDFUA2RelatedFlavour(PDFFlavour flavour) {
return isFlavour(flavour, PDFFlavour.PDFUA_2) || isFlavourPart(flavour, Specification.WTPDF_1_0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.verapdf.tools.StaticResources;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CharacterCollections {
Expand Down Expand Up @@ -138,7 +139,7 @@ public class CharacterCollections {
public static CIDSystemInfo getCIDSystemInfo(String cmapName) {
CIDSystemInfo[] cidSystemInfos = map.get(cmapName);
if (cidSystemInfos != null) {
PDFFlavour flavour = StaticResources.getFlavour();
List<PDFFlavour> flavour = StaticResources.getFlavour();
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.PDF_REFERENCE_1_4)) {
return cidSystemInfos[0];
} else if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/verapdf/pd/structure/PDStructElem.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.verapdf.tools.TaggedPDFHelper;
import org.verapdf.tools.TaggedPDFRoleMapHelper;

import java.util.List;

/**
* @author Maksim Bezrukov
*/
Expand Down Expand Up @@ -126,7 +128,7 @@ public static StructureType getStructureElementStandardStructureType(PDStructEle
}

public static StructureType getStructureTypeStandardStructureType(StructureType type) {
PDFFlavour flavour = StaticResources.getFlavour();
List<PDFFlavour> flavour = StaticResources.getFlavour();
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
StructureType defaultStructureType = PDStructElem.getDefaultStructureType(type);
if (defaultStructureType != null) {
Expand All @@ -153,7 +155,7 @@ public static String getStructureElementStandardType(PDStructElem pdStructElem)
}

public static boolean isStandardStructureType(StructureType type) {
PDFFlavour flavour = StaticResources.getFlavour();
List<PDFFlavour> flavour = StaticResources.getFlavour();
boolean isStandard = false;
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
isStandard = TaggedPDFHelper.isStandardType(type);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/verapdf/tools/StaticResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -45,7 +47,7 @@ public class StaticResources {

private static final Logger LOGGER = Logger.getLogger(StaticResources.class.getCanonicalName());

private static final ThreadLocal<PDFFlavour> flavour = new ThreadLocal<>();
private static final ThreadLocal<List<PDFFlavour>> flavour = new ThreadLocal<>();
private static final ThreadLocal<PDDocument> document = new ThreadLocal<>();

private static final ThreadLocal<TaggedPDFRoleMapHelper> roleMapHelper = new ThreadLocal<>();
Expand Down Expand Up @@ -149,7 +151,7 @@ public static void clear() {
StaticResources.cMapCache.set(new HashMap<>());
StaticResources.structureNameSpaceCache.set(new HashMap<>());
StaticResources.cachedFonts.set(new HashMap<>());
StaticResources.flavour.set(null);
StaticResources.flavour.set(new LinkedList<>());
StaticResources.document.set(null);
StaticResources.setPassword(null);
StaticResources.roleMapHelper.set(null);
Expand Down Expand Up @@ -185,11 +187,11 @@ public static void setCachedFonts(Map<String, FontProgram> cachedFonts) {
StaticResources.cachedFonts.set(cachedFonts);
}

public static PDFFlavour getFlavour() {
public static List<PDFFlavour> getFlavour() {
return flavour.get();
}

public static void setFlavour(PDFFlavour flavour) {
public static void setFlavour(List<PDFFlavour> flavour) {
StaticResources.flavour.set(flavour);
}

Expand Down
Loading