Skip to content

Commit

Permalink
PDF/UA-2. Update regular table checking
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Oct 25, 2023
1 parent 32ce058 commit 63029a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ public static GFPDStructElem createTypedStructElem(PDStructElem structElemDictio
public static StructureType getStructureElementStandardStructureType(PDStructElem pdStructElem) {
if (StaticContainers.getFlavour() != null && (StaticContainers.getFlavour().getPart() ==
PDFAFlavour.Specification.ISO_19005_4 || StaticContainers.getFlavour().getPart() ==
PDFAFlavour.Specification.ISO_14289_2 || StaticContainers.getFlavour().getPart() ==
PDFAFlavour.Specification.WCAG_2_1)) {
StructureType defaultStructureType = pdStructElem.getDefaultStructureType();
if (defaultStructureType != null) {
return defaultStructureType;
}
}
if (StaticContainers.getFlavour() == null || StaticContainers.getFlavour().getPart() !=
PDFAFlavour.Specification.ISO_19005_4) {
if (StaticContainers.getFlavour() == null || (StaticContainers.getFlavour().getPart() !=
PDFAFlavour.Specification.ISO_19005_4 && StaticContainers.getFlavour().getPart() !=
PDFAFlavour.Specification.ISO_14289_2)) {
StructureType type = pdStructElem.getStructureType();
if (type != null) {
return StructureType.createStructureType(ASAtom.getASAtom(StaticResources.getRoleMapHelper().getStandardType(type.getType())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
*/
package org.verapdf.gf.model.impl.pd.gfse;

import org.verapdf.gf.model.impl.containers.StaticContainers;
import org.verapdf.gf.model.impl.pd.GFPDStructElem;
import org.verapdf.model.selayer.SETable;
import org.verapdf.model.pdlayer.PDStructElem;
import org.verapdf.pdfa.flavours.PDFAFlavour;
import org.verapdf.tools.TaggedPDFConstants;

import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.*;

public class GFSETable extends GFPDStructElem implements SETable {

Expand All @@ -55,7 +54,8 @@ public Boolean getuseHeadersAndIdOrScope() {
}

private void checkTable() {
List<GFPDStructElem> listTR = getTR();
List<Integer> rowGroupingsIndexes = new LinkedList<>();
List<GFPDStructElem> listTR = getTR(rowGroupingsIndexes);
int numberOfRows = listTR.size();
this.rowSpan = (long)numberOfRows;
if (numberOfRows == 0) {
Expand All @@ -65,7 +65,7 @@ private void checkTable() {
int numberOfColumns = getNumberOfColumns(listTR.get(0));
this.columnSpan = (long)numberOfColumns;
GFSETableCell[][] cells = new GFSETableCell[numberOfRows][numberOfColumns];
if (!checkRegular(listTR, cells, numberOfRows, numberOfColumns)) {
if (!checkRegular(listTR, cells, numberOfRows, numberOfColumns, rowGroupingsIndexes)) {
useHeadersAndIdOrScope = true;
return;
}
Expand Down Expand Up @@ -98,7 +98,7 @@ private boolean hasScope(GFSETableCell[][] cells, int numberOfRows, int numberOf
}

private boolean checkRegular(List<GFPDStructElem> listTR, GFSETableCell[][] cells,
int numberOfRows, int numberOfColumns) {
int numberOfRows, int numberOfColumns, List<Integer> rowGroupingsIndexes) {
for (int rowNumber = 0; rowNumber < numberOfRows; rowNumber++) {
int columnNumber = 0;
for (PDStructElem elem : listTR.get(rowNumber).getStructuralSignificanceChildren()) {
Expand All @@ -120,6 +120,14 @@ private boolean checkRegular(List<GFPDStructElem> listTR, GFSETableCell[][] cell
this.numberOfColumnWithWrongRowSpan = (long)columnNumber;
return false;
}
if (StaticContainers.getFlavour() == PDFAFlavour.PDFUA_2) {
for (Integer rowGroupsIndex : rowGroupingsIndexes) {
if (rowNumber + rowSpan > rowGroupsIndex && rowNumber < rowGroupsIndex) {
this.numberOfColumnWithWrongRowSpan = (long)columnNumber;
return false;
}
}
}
if (!checkRegular(cells, cell, rowSpan, colSpan, rowNumber, columnNumber)) {
return false;
}
Expand Down Expand Up @@ -230,19 +238,21 @@ private boolean hasScope(GFSETableCell cell, int rowNumber, int columnNumber, St
return false;
}

private List<GFPDStructElem> getTR() {
private List<GFPDStructElem> getTR(List<Integer> rowGroupingsIndexes) {
List<GFPDStructElem> listTR = new LinkedList<>();
for (GFPDStructElem elem : getStructuralSignificanceChildren()) {
String type = elem.getstandardType();
if (TaggedPDFConstants.TR.equals(type)) {
listTR.add(elem);
} else if (TaggedPDFConstants.THEAD.equals(type) || TaggedPDFConstants.TBODY.equals(type) ||
TaggedPDFConstants.TFOOT.equals(type)) {
rowGroupingsIndexes.add(listTR.size());
for (GFPDStructElem child : elem.getStructuralSignificanceChildren()) {
if (TaggedPDFConstants.TR.equals(child.getstandardType())) {
listTR.add(child);
}
}
rowGroupingsIndexes.add(listTR.size());
}
}
return listTR;
Expand Down

0 comments on commit 63029a1

Please sign in to comment.