diff --git a/pdfbox-validation-model/src/main/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGState.java b/pdfbox-validation-model/src/main/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGState.java index bd57580b..4e05242a 100644 --- a/pdfbox-validation-model/src/main/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGState.java +++ b/pdfbox-validation-model/src/main/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGState.java @@ -52,10 +52,6 @@ public class PBoxPDExtGState extends PBoxPDResource implements PDExtGState { public static final String HALFTONE = "HT"; public static final String LINK_BM = "bm"; - private final String tr; - private final String tr2; - private final String sMask; - private final String BM; private final Double ca; private final Double CA; @@ -63,35 +59,11 @@ public class PBoxPDExtGState extends PBoxPDResource implements PDExtGState { public PBoxPDExtGState(PDExtendedGraphicsState state, PDFAFlavour flavour) { super(state, EXT_G_STATE_TYPE); - this.tr = PBoxPDExtGState.getStringProperty(state, COSName.TR); - this.tr2 = PBoxPDExtGState.getStringProperty(state, COSName.getPDFName("TR2")); - this.sMask = PBoxPDExtGState.getStringProperty(state, COSName.SMASK); - this.BM = PBoxPDExtGState.getStringProperty(state, COSName.BM); this.ca = PBoxPDExtGState.getDoubleProperty(state, COSName.CA_NS); this.CA = PBoxPDExtGState.getDoubleProperty(state, COSName.CA); this.flavour = flavour; } - @Override - public String getTR() { - return this.tr; - } - - @Override - public String getTR2() { - return this.tr2; - } - - @Override - public String getSMask() { - return this.sMask; - } - - @Override - public String getBM() { - return this.BM; - } - @Override public Double getca() { return this.ca; @@ -102,24 +74,49 @@ public Double getCA() { return this.CA; } + @Override + public String getTR2NameValue() { + return getNameKeyStringValue((COSDictionary)simplePDObject.getCOSObject(), COSName.getPDFName("TR2")); + } + + @Override + public Boolean getcontainsTR() { + return ((COSDictionary)simplePDObject.getCOSObject()).containsKey(COSName.TR); + } + + @Override + public Boolean getcontainsTR2() { + return ((COSDictionary)simplePDObject.getCOSObject()).containsKey(COSName.getPDFName("TR2")); + } + @Override public Boolean getcontainsHTP() { - COSBase pageObject = this.simplePDObject.getCOSObject(); - return pageObject != null && pageObject instanceof COSDictionary && - ((COSDictionary) pageObject).containsKey(COSName.getPDFName("HTP")); + return ((COSDictionary)simplePDObject.getCOSObject()).containsKey(COSName.getPDFName("HTP")); } @Override public Boolean getcontainsHTO() { - COSBase pageObject = this.simplePDObject.getCOSObject(); - return pageObject != null && pageObject instanceof COSDictionary && - ((COSDictionary) pageObject).containsKey(COSName.getPDFName("HTO")); + return ((COSDictionary)simplePDObject.getCOSObject()).containsKey(COSName.getPDFName("HTO")); } - private static String getStringProperty(PDExtendedGraphicsState state, COSName key) { - COSBase base = state.getCOSObject().getDictionaryObject(key); - return base == null ? null : base instanceof COSName ? - ((COSName) base).getName() : base.toString(); + @Override + public String getSMaskNameValue() { + return getNameKeyStringValue((COSDictionary)simplePDObject.getCOSObject(), COSName.SMASK); + } + + @Override + public Boolean getcontainsSMask() { + return ((COSDictionary)simplePDObject.getCOSObject()).containsKey(COSName.SMASK); + } + + @Override + public String getBMNameValue() { + return getNameKeyStringValue((COSDictionary)simplePDObject.getCOSObject(), COSName.BM); + } + + private static String getNameKeyStringValue(COSDictionary dictionary, COSName key) { + COSBase base = dictionary.getDictionaryObject(key); + return base instanceof COSName ? ((COSName) base).getName() : null; } private static Double getDoubleProperty(PDExtendedGraphicsState state, COSName key) { diff --git a/pdfbox-validation-model/src/test/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGStateTest.java b/pdfbox-validation-model/src/test/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGStateTest.java index 30b98ebf..b0e5f056 100644 --- a/pdfbox-validation-model/src/test/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGStateTest.java +++ b/pdfbox-validation-model/src/test/java/org/verapdf/model/impl/pb/pd/PBoxPDExtGStateTest.java @@ -54,22 +54,22 @@ public static void setUp() throws URISyntaxException, IOException { @Test public void testTRMethod() { - Assert.assertNull(((PBoxPDExtGState) actual).getTR()); + Assert.assertFalse(((PBoxPDExtGState) actual).getcontainsTR()); } @Test public void testTR2Method() { - Assert.assertNull(((PBoxPDExtGState) actual).getTR2()); + Assert.assertFalse(((PBoxPDExtGState) actual).getcontainsTR2()); } @Test public void testSMaskMethod() { - Assert.assertNull(((PBoxPDExtGState) actual).getSMask()); + Assert.assertFalse(((PBoxPDExtGState) actual).getcontainsSMask()); } @Test public void testBMMethod() { - Assert.assertEquals("Screen", ((PBoxPDExtGState) actual).getBM()); + Assert.assertEquals("Screen", ((PBoxPDExtGState) actual).getBMNameValue()); } @Test