Skip to content

Commit

Permalink
Refactoring flavours. Add WTPDF flavours
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Apr 23, 2024
1 parent 1f77a44 commit 91b3ab1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
65 changes: 51 additions & 14 deletions src/main/java/org/verapdf/parser/PDFFlavour.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public enum PDFFlavour {
PDFA_4_E(Specification.ISO_19005_4),
PDFUA_1(Specification.ISO_14289_1),
PDFUA_2(Specification.ISO_14289_2),
WCAG2_1(Specification.WCAG2_1),
WCAG2_2(Specification.WCAG2_2);
WTPDF_1_0_REUSE(Specification.WTPDF_1_0),
WTPDF_1_0_ACCESSIBILITY(Specification.WTPDF_1_0),
WCAG_2_1(Specification.WCAG_2_1),
WCAG_2_2(Specification.WCAG_2_2);

private final Specification specification;

Expand All @@ -29,31 +31,66 @@ public Specification getSpecification() {
}

public enum Specification {
NO_STANDARD(SpecificationFamily.NONE),
ISO_14289_1(SpecificationFamily.PDF_UA),
ISO_14289_2(SpecificationFamily.PDF_UA),
ISO_19005_1(SpecificationFamily.PDF_A),
ISO_19005_2(SpecificationFamily.PDF_A),
ISO_19005_3(SpecificationFamily.PDF_A),
ISO_19005_4(SpecificationFamily.PDF_A),
WCAG2_1(SpecificationFamily.WCAG),
WCAG2_2(SpecificationFamily.WCAG);
NO_STANDARD(SpecificationFamily.NONE, PDFSpecification.NO_SPECIFICATION),
ISO_14289_1(SpecificationFamily.PDF_UA, PDFSpecification.ISO_32000_1_7),
ISO_14289_2(SpecificationFamily.PDF_UA, PDFSpecification.ISO_32000_2_0),
ISO_19005_1(SpecificationFamily.PDF_A, PDFSpecification.PDF_REFERENCE_1_4),
ISO_19005_2(SpecificationFamily.PDF_A, PDFSpecification.ISO_32000_1_7),
ISO_19005_3(SpecificationFamily.PDF_A, PDFSpecification.ISO_32000_1_7),
ISO_19005_4(SpecificationFamily.PDF_A, PDFSpecification.ISO_32000_2_0),
WTPDF_1_0(SpecificationFamily.WTPDF, PDFSpecification.ISO_32000_2_0),
WCAG_2_1(SpecificationFamily.WCAG, PDFSpecification.ISO_32000_2_0),
WCAG_2_2(SpecificationFamily.WCAG, PDFSpecification.ISO_32000_2_0);

private final SpecificationFamily family;
private final PDFSpecification pdfSpecification;

Specification(final SpecificationFamily family) {
Specification(final SpecificationFamily family, final PDFSpecification pdfSpecification) {
this.family = family;
this.pdfSpecification = pdfSpecification;
}

public SpecificationFamily getFamily() {
return family;
}

public PDFSpecification getPdfSpecification() {
return pdfSpecification;
}
}

public enum SpecificationFamily {
NONE,
PDF_A,
PDF_UA,
WCAG
WCAG,
WTPDF
}

public enum PDFSpecification {
NO_SPECIFICATION,
PDF_REFERENCE_1_4,
ISO_32000_1_7,
ISO_32000_2_0
}

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

public static boolean isFlavourFamily(PDFFlavour flavour, SpecificationFamily specificationFamily) {
return flavour != null && flavour.getSpecification().getFamily() == specificationFamily;
}

public static boolean isFlavour(PDFFlavour currentFlavour, PDFFlavour flavour) {
return currentFlavour != null && currentFlavour == flavour;
}

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

public static boolean isPDFUA2RelatedFlavour(PDFFlavour flavour) {
return isFlavour(flavour, PDFFlavour.PDFUA_2) || isFlavourPart(flavour, Specification.WTPDF_1_0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public static CIDSystemInfo getCIDSystemInfo(String cmapName) {
CIDSystemInfo[] cidSystemInfos = map.get(cmapName);
if (cidSystemInfos != null) {
PDFFlavour flavour = StaticResources.getFlavour();
if (flavour.getSpecification() == PDFFlavour.Specification.ISO_19005_1) {
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.PDF_REFERENCE_1_4)) {
return cidSystemInfos[0];
} else if (flavour.getSpecification() == PDFFlavour.Specification.ISO_19005_4) {
} else if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
return cidSystemInfos[2];
} else {
return cidSystemInfos[1];
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/verapdf/pd/structure/PDStructElem.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,13 @@ public static StructureType getStructureElementStandardStructureType(PDStructEle

public static StructureType getStructureTypeStandardStructureType(StructureType type) {
PDFFlavour flavour = StaticResources.getFlavour();
if (flavour.getSpecification() == PDFFlavour.Specification.ISO_19005_4 || flavour == PDFFlavour.PDFUA_2 ||
flavour.getSpecification().getFamily() == PDFFlavour.SpecificationFamily.WCAG) {
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
StructureType defaultStructureType = PDStructElem.getDefaultStructureType(type);
if (defaultStructureType != null) {
return defaultStructureType;
}
}
if (flavour.getSpecification() != PDFFlavour.Specification.ISO_19005_4 && flavour != PDFFlavour.PDFUA_2) {
if (!PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0) || PDFFlavour.isFlavourFamily(flavour, PDFFlavour.SpecificationFamily.WCAG)) {
if (type != null) {
return StructureType.createStructureType(ASAtom.getASAtom(
StaticResources.getRoleMapHelper().getStandardType(type.getType())));
Expand All @@ -156,11 +155,10 @@ public static String getStructureElementStandardType(PDStructElem pdStructElem)
public static boolean isStandardStructureType(StructureType type) {
PDFFlavour flavour = StaticResources.getFlavour();
boolean isStandard = false;
if (flavour.getSpecification() == PDFFlavour.Specification.ISO_19005_4 || flavour == PDFFlavour.PDFUA_2 ||
flavour.getSpecification().getFamily() == PDFFlavour.SpecificationFamily.WCAG) {
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
isStandard = TaggedPDFHelper.isStandardType(type);
}
if (flavour.getSpecification() != PDFFlavour.Specification.ISO_19005_4 && flavour != PDFFlavour.PDFUA_2) {
if (!PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0) || PDFFlavour.isFlavourFamily(flavour, PDFFlavour.SpecificationFamily.WCAG)) {
if (type != null) {
isStandard |= TaggedPDFRoleMapHelper.isStandardType(type);
}
Expand All @@ -169,7 +167,7 @@ public static boolean isStandardStructureType(StructureType type) {
}

public static boolean isMathStandardType(StructureType standardStructureType) {
return StaticResources.getFlavour() == PDFFlavour.PDFUA_2 && standardStructureType != null &&
return PDFFlavour.isPDFUA2RelatedFlavour(StaticResources.getFlavour()) && standardStructureType != null &&
TaggedPDFConstants.MATH_ML_NAMESPACE.equals(standardStructureType.getNameSpaceURI());
}

Expand Down

0 comments on commit 91b3ab1

Please sign in to comment.