From d73ab088dc4ee30a3ed7de2e7b742659c0703ada Mon Sep 17 00:00:00 2001 From: Maxim Date: Thu, 24 Oct 2024 22:46:55 +0300 Subject: [PATCH] Update logs for operator parser --- .../factory/operators/OperatorFactory.java | 5 ++-- .../factory/operators/OperatorParser.java | 29 ++++++++++++------- .../gf/model/impl/pd/GFPDContentStream.java | 18 +++++++----- .../verapdf/gf/model/impl/pd/GFPDPage.java | 4 +-- .../impl/pd/GFPDSemanticContentStream.java | 13 +++++---- .../gf/model/impl/pd/font/GFPDType3Font.java | 4 ++- .../gf/model/impl/pd/images/GFPDXForm.java | 4 +-- .../impl/pd/patterns/GFPDTilingPattern.java | 2 +- 8 files changed, 47 insertions(+), 32 deletions(-) diff --git a/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorFactory.java b/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorFactory.java index 6a6e1c88c..bd6cfb5d0 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorFactory.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorFactory.java @@ -21,6 +21,7 @@ package org.verapdf.gf.model.factory.operators; import org.verapdf.cos.COSBase; +import org.verapdf.cos.COSKey; import org.verapdf.cos.COSObject; import org.verapdf.gf.model.impl.pd.util.PDResourcesHandler; import org.verapdf.gf.model.tools.TransparencyBehaviour; @@ -99,10 +100,10 @@ public boolean isLastParsedContainsTransparency() { public List operatorsFromTokens(List rawTokens, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, StructureElementAccessObject structureElementAccessObject, COSObject parentStructElem, - List parentsTags, boolean isRealContent) { + List parentsTags, boolean isRealContent, COSKey parentObjectKey) { this.isLastParsedContainsTransparency = false; OperatorParser parser = new OperatorParser(inheritedGraphicState, structureElementAccessObject, resourcesHandler, - parentStructElem, parentsTags, isRealContent); + parentStructElem, parentsTags, isRealContent, parentObjectKey); List result = new ArrayList<>(); List arguments = new ArrayList<>(); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java b/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java index b9c16f032..694bf36ec 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java @@ -98,13 +98,14 @@ class OperatorParser { private final List parentsTags; private final boolean isRealContent; - + private final COSKey parentObjectKey; + private boolean insideText = false; OperatorParser(GraphicState inheritedGraphicState, StructureElementAccessObject structureElementAccessObject, PDResourcesHandler resourcesHandler, COSObject parentStructElem, - List parentsTags, boolean isRealContent) { + List parentsTags, boolean isRealContent, COSKey parentObjectKey) { if (inheritedGraphicState == null) { this.graphicState = new GraphicState(resourcesHandler); } else { @@ -115,6 +116,7 @@ class OperatorParser { this.parentStructElem = parentStructElem; this.parentsTags = parentsTags; this.isRealContent = isRealContent; + this.parentObjectKey = parentObjectKey; } public TransparencyGraphicsState getTransparencyGraphicState() { @@ -173,11 +175,11 @@ void parseOperator(List processedOperators, Long mcid = bdcOp.getMCID(); if (mcid != null) { if (mcidSet.contains(mcid)) { - LOGGER.log(Level.WARNING, "Content stream contains duplicate MCID - " + mcid); + LOGGER.log(Level.WARNING, getErrorMessage("Duplicate MCID - " + mcid)); } mcidSet.add(mcid); if (getCurrentMCID() != null) { - LOGGER.log(Level.WARNING, "Content stream contains nested MCID - " + mcid); + LOGGER.log(Level.WARNING, getErrorMessage("Nested MCID - " + mcid)); } } processedOperators.add(bdcOp); @@ -189,7 +191,7 @@ void parseOperator(List processedOperators, if (!this.markedContentStack.empty()) { this.markedContentStack.pop(); } else { - LOGGER.log(Level.WARNING, "Operator (EMC) not inside marked content"); + LOGGER.log(Level.WARNING, getErrorMessage("Operator (EMC) not inside marked content")); } break; case Operators.MP: @@ -499,13 +501,13 @@ void parseOperator(List processedOperators, // SPECIAL GS case Operators.CM_CONCAT: if (insideText) { - LOGGER.log(Level.WARNING, "Special graphics state operator (cm) inside Text object"); + LOGGER.log(Level.WARNING, getErrorMessage("Special graphics state operator (cm) inside Text object")); } processedOperators.add(new GFOp_cm(arguments)); break; case Operators.Q_GRESTORE: if (insideText) { - LOGGER.log(Level.WARNING, "Special graphics state operator (Q) inside Text object"); + LOGGER.log(Level.WARNING, getErrorMessage("Special graphics state operator (Q) inside Text object")); } if (!graphicStateStack.isEmpty()) { this.graphicState.copyProperties(this.graphicStateStack.pop()); @@ -517,7 +519,7 @@ void parseOperator(List processedOperators, break; case Operators.Q_GSAVE: if (insideText) { - LOGGER.log(Level.WARNING, "Special graphics state operator (q) inside Text object"); + LOGGER.log(Level.WARNING, getErrorMessage("Special graphics state operator (q) inside Text object")); } this.graphicStateStack.push(this.graphicState.clone()); this.transparencyGraphicStateStack.push(this.transparencyGraphicState.clone()); @@ -623,7 +625,7 @@ private static void processInlineImage(List } } - private static RenderingMode getRenderingMode(List arguments) { + private RenderingMode getRenderingMode(List arguments) { if (!arguments.isEmpty()) { COSBase renderingMode = arguments.get(0); if (renderingMode instanceof COSInteger) { @@ -631,7 +633,7 @@ private static RenderingMode getRenderingMode(List arguments) { if (mode != null) { return mode; } - LOGGER.log(Level.WARNING, "Wrong argument of Tr operator in stream"); + LOGGER.log(Level.WARNING, getErrorMessage("Wrong argument of Tr operator")); } } return RenderingMode.FILL; @@ -729,4 +731,11 @@ private COSObject getParentStructElem(StructureElementAccessObject structureElem } return null; } + + private String getErrorMessage(String errorMessage) { + if (parentObjectKey == null) { + return errorMessage; + } + return "Content stream (object " + parentObjectKey + "): " + errorMessage; + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDContentStream.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDContentStream.java index ea178083b..1db3be790 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDContentStream.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDContentStream.java @@ -69,37 +69,39 @@ public class GFPDContentStream extends GFPDObject implements PDContentStream { private final StructureElementAccessObject structureElementAccessObject; protected COSObject parentStructElem; protected List parentsTags; + private COSKey parentObjectKey; public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, - StructureElementAccessObject structureElementAccessObject) { - this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, CONTENT_STREAM_TYPE); + StructureElementAccessObject structureElementAccessObject, COSKey parentObjectKey) { + this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentObjectKey, CONTENT_STREAM_TYPE); } public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, StructureElementAccessObject structureElementAccessObject, - COSObject parentStructElem, List parentsTags) { + COSObject parentStructElem, List parentsTags, COSKey parentObjectKey) { this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, - parentStructElem, parentsTags, CONTENT_STREAM_TYPE); + parentStructElem, parentsTags, parentObjectKey, CONTENT_STREAM_TYPE); } public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, - StructureElementAccessObject structureElementAccessObject, final String type) { + StructureElementAccessObject structureElementAccessObject, COSKey parentObjectKey, final String type) { super(contentStream, type); this.resourcesHandler = resourcesHandler; this.inheritedGraphicState = inheritedGraphicState; this.structureElementAccessObject = structureElementAccessObject; this.parentsTags = Collections.emptyList(); + this.parentObjectKey = parentObjectKey; } public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, StructureElementAccessObject structureElementAccessObject, - COSObject parentStructElem, List parentsTags, final String type) { - this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, type); + COSObject parentStructElem, List parentsTags, COSKey parentObjectKey, final String type) { + this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentObjectKey, type); this.parentStructElem = getParentStructureElem(structureElementAccessObject); if (this.parentStructElem == null) { this.parentStructElem = parentStructElem; @@ -151,7 +153,7 @@ protected void parseOperators() { OperatorFactory operatorFactory = new OperatorFactory(); List result = operatorFactory.operatorsFromTokens(streamParser.getTokens(), resourcesHandler, inheritedGraphicState, structureElementAccessObject, - parentStructElem, parentsTags, isSemantic()); + parentStructElem, parentsTags, isSemantic(), parentObjectKey); this.containsTransparency = operatorFactory.isLastParsedContainsTransparency(); this.operators = Collections.unmodifiableList(result); } finally { diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDPage.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDPage.java index dc3849f4b..0694f1ce9 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDPage.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDPage.java @@ -245,10 +245,10 @@ private List parseContentStream() { GFPDContentStream pdContentStream; if (!PDFFlavours.isPDFUARelatedFlavour(StaticContainers.getFlavour())) { pdContentStream = new GFPDContentStream(page.getContent(), resourcesHandler, null, - new StructureElementAccessObject(this.simpleCOSObject)); + new StructureElementAccessObject(this.simpleCOSObject), page.getObject().getObjectKey()); } else { pdContentStream = new GFPDSemanticContentStream(page.getContent(), resourcesHandler, null, - new StructureElementAccessObject(this.simpleCOSObject)); + new StructureElementAccessObject(this.simpleCOSObject), page.getObject().getObjectKey()); } this.containsTransparency |= pdContentStream.isContainsTransparency(); pdContentStreams.add(pdContentStream); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDSemanticContentStream.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDSemanticContentStream.java index 0d3851268..4fb7873be 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDSemanticContentStream.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDSemanticContentStream.java @@ -21,6 +21,7 @@ package org.verapdf.gf.model.impl.pd; +import org.verapdf.cos.COSKey; import org.verapdf.cos.COSObject; import org.verapdf.gf.model.factory.operators.GraphicState; import org.verapdf.gf.model.impl.operator.markedcontent.GFOpMarkedContent; @@ -54,23 +55,23 @@ public class GFPDSemanticContentStream extends GFPDContentStream implements PDSe public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, - StructureElementAccessObject structureElementAccessObject) { - super(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, SEMANTIC_CONTENT_STREAM_TYPE); + StructureElementAccessObject structureElementAccessObject, COSKey parentObjectKey) { + super(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentObjectKey, SEMANTIC_CONTENT_STREAM_TYPE); } public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, StructureElementAccessObject structureElementAccessObject, - COSObject parentStructElem, List parentsTags) { + COSObject parentStructElem, List parentsTags, COSKey parentObjectKey) { super(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructElem, - parentsTags, SEMANTIC_CONTENT_STREAM_TYPE); + parentsTags, parentObjectKey, SEMANTIC_CONTENT_STREAM_TYPE); } public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState, StructureElementAccessObject structureElementAccessObject, - COSObject parentStructElem, List parentsTags, String defaultLang, boolean isSignature) { + COSObject parentStructElem, List parentsTags, String defaultLang, boolean isSignature, COSKey parentObjectKey) { this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructElem, - parentsTags); + parentsTags, parentObjectKey); this.defaultLang = defaultLang; this.isSignature = isSignature; } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType3Font.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType3Font.java index b5405caea..329c4f413 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType3Font.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType3Font.java @@ -22,6 +22,7 @@ import org.verapdf.as.ASAtom; import org.verapdf.cos.COSDictionary; +import org.verapdf.cos.COSKey; import org.verapdf.cos.COSObjType; import org.verapdf.cos.COSObject; import org.verapdf.gf.model.factory.operators.GraphicState; @@ -103,6 +104,7 @@ private void parseCharStrings() { COSDictionary charProcDict = ((org.verapdf.pd.font.type3.PDType3Font) this.pdFont).getCharProcDict(); if (charProcDict != null) { + COSKey objectKey = this.pdFont.getKey(ASAtom.CHAR_PROCS).getObjectKey(); Set keySet = charProcDict.getKeySet(); Map map = new HashMap<>(keySet.size()); for (ASAtom glyphName : keySet) { @@ -113,7 +115,7 @@ private void parseCharStrings() { GFPDContentStream contentStream = new GFPDContentStream(charProc, glyphResources == null ? this.resources : glyphResources, inheritedGraphicState, - new StructureElementAccessObject(this.simpleCOSObject)); + new StructureElementAccessObject(this.simpleCOSObject), objectKey); map.put(glyphName.getValue(), contentStream); } else { LOGGER.log(Level.SEVERE, "Invalid entry in the char proc dictionary, dictionary is expected."); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/images/GFPDXForm.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/images/GFPDXForm.java index 4b8fda652..ebd39c7cc 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/images/GFPDXForm.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/images/GFPDXForm.java @@ -206,12 +206,12 @@ private void parseContentStream() { gfContentStream = new GFPDContentStream( (org.verapdf.pd.images.PDXForm) this.simplePDObject, resourcesHandler, this.inheritedGraphicState, new StructureElementAccessObject(this.simpleCOSObject), - parentStructElem, parentsTags); + parentStructElem, parentsTags, simplePDObject.getObject().getObjectKey()); } else { gfContentStream = new GFPDSemanticContentStream( (org.verapdf.pd.images.PDXForm) this.simplePDObject, resourcesHandler, this.inheritedGraphicState, new StructureElementAccessObject(this.simpleCOSObject), - parentStructElem, parentsTags, defaultLang, isSignature); + parentStructElem, parentsTags, defaultLang, isSignature, simplePDObject.getObject().getObjectKey()); } this.contentStreamContainsTransparency = gfContentStream.isContainsTransparency(); List streams = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/patterns/GFPDTilingPattern.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/patterns/GFPDTilingPattern.java index db8378d20..5d9ae4733 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/patterns/GFPDTilingPattern.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/patterns/GFPDTilingPattern.java @@ -99,7 +99,7 @@ public boolean isContainsTransparency() { private void parseContentStream() { org.verapdf.pd.patterns.PDTilingPattern pattern = (org.verapdf.pd.patterns.PDTilingPattern) this.simplePDObject; GFPDContentStream contentStream = new GFPDContentStream(pattern, this.resourcesHandler, inheritedGraphicState, - new StructureElementAccessObject(this.simpleCOSObject)); + new StructureElementAccessObject(this.simpleCOSObject), simplePDObject.getObject().getObjectKey()); this.containsTransparency |= contentStream.isContainsTransparency(); List contentStreams = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); contentStreams.add(contentStream);