Skip to content

Commit

Permalink
Update methods for PBoxPDExtGState
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Jul 9, 2024
1 parent c216e7b commit f6f623a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,18 @@ 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;

private final PDFAFlavour flavour;

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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6f623a

Please sign in to comment.