Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update methods for PBoxPDExtGState #351

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading