Skip to content

Commit 8c1586c

Browse files
committed
Change the way of checking transparency on the page
DEVSIX-2721
1 parent 6679ebe commit 8c1586c

File tree

12 files changed

+386
-26
lines changed

12 files changed

+386
-26
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/IsoKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ public enum IsoKey {
5656
RENDERING_INTENT,
5757
STROKE_COLOR,
5858
TAG_STRUCTURE_ELEMENT,
59+
FONT_GLYPHS,
5960
}

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfDocument.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,14 +1425,28 @@ public void checkIsoConformance(Object obj, IsoKey key) {
14251425
/**
14261426
* Checks whether PDF document conforms a specific standard.
14271427
* Shall be override.
1428+
* @deprecated This method will be replaced by {@link #checkIsoConformance(Object, IsoKey, PdfResources, PdfStream) checkIsoConformance} in 7.2 release
14281429
*
14291430
* @param obj an object to conform.
14301431
* @param key type of object to conform.
14311432
* @param resources {@link PdfResources} associated with an object to check.
14321433
*/
1434+
@Deprecated
14331435
public void checkIsoConformance(Object obj, IsoKey key, PdfResources resources) {
14341436
}
14351437

1438+
/**
1439+
* Checks whether PDF document conforms a specific standard.
1440+
* Shall be override.
1441+
*
1442+
* @param obj an object to conform.
1443+
* @param key type of object to conform.
1444+
* @param resources {@link PdfResources} associated with an object to check.
1445+
* @param contentStream current content stream
1446+
*/
1447+
public void checkIsoConformance(Object obj, IsoKey key, PdfResources resources, PdfStream contentStream) {
1448+
}
1449+
14361450
/**
14371451
* Checks whether PDF document conforms a specific standard.
14381452
* Shall be override.

kernel/src/main/java/com/itextpdf/kernel/pdf/canvas/PdfCanvas.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ public PdfCanvas showText(GlyphLine text) {
721721
* @return current canvas.
722722
*/
723723
public PdfCanvas showText(GlyphLine text, Iterator<GlyphLine.GlyphLinePart> iterator) {
724+
document.checkIsoConformance(currentGs, IsoKey.FONT_GLYPHS, null, contentStream);
724725
PdfFont font;
725726
if ((font = currentGs.getFont()) == null) {
726727
throw new PdfException(PdfException.FontAndSizeMustBeSetBeforeWritingAnyText, currentGs);
@@ -890,6 +891,7 @@ private float getWordSpacingAddition(Glyph glyph) {
890891
* @return current canvas.
891892
*/
892893
public PdfCanvas showText(PdfArray textArray) {
894+
document.checkIsoConformance(currentGs, IsoKey.FONT_GLYPHS, null, contentStream);
893895
if (currentGs.getFont() == null)
894896
throw new PdfException(PdfException.FontAndSizeMustBeSetBeforeWritingAnyText, currentGs);
895897
contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("["));
@@ -1643,7 +1645,7 @@ else if (colorSpace.getPdfObject().isIndirect()) {
16431645
}
16441646
contentStream.getOutputStream().writeFloats(colorValue).writeSpace().writeBytes(fill ? scn : SCN);
16451647
}
1646-
document.checkIsoConformance(currentGs, fill ? IsoKey.FILL_COLOR : IsoKey.STROKE_COLOR, resources);
1648+
document.checkIsoConformance(currentGs, fill ? IsoKey.FILL_COLOR : IsoKey.STROKE_COLOR, resources, contentStream);
16471649
return this;
16481650
}
16491651

@@ -2084,7 +2086,7 @@ public PdfCanvas setExtGState(PdfExtGState extGState) {
20842086
currentGs.updateFromExtGState(extGState, document);
20852087
PdfName name = resources.addExtGState(extGState);
20862088
contentStream.getOutputStream().write(name).writeSpace().writeBytes(gs);
2087-
document.checkIsoConformance(currentGs, IsoKey.EXTENDED_GRAPHICS_STATE);
2089+
document.checkIsoConformance(currentGs, IsoKey.EXTENDED_GRAPHICS_STATE, null, contentStream);
20882090
return this;
20892091
}
20902092

@@ -2237,7 +2239,7 @@ public PdfStream getContentStream() {
22372239
* @param f an element of the transformation matrix
22382240
*/
22392241
protected void addInlineImage(PdfImageXObject imageXObject, float a, float b, float c, float d, float e, float f) {
2240-
document.checkIsoConformance(imageXObject.getPdfObject(), IsoKey.INLINE_IMAGE, resources);
2242+
document.checkIsoConformance(imageXObject.getPdfObject(), IsoKey.INLINE_IMAGE, resources, contentStream);
22412243
saveState();
22422244
concatMatrix(a, b, c, d, e, f);
22432245
PdfOutputStream os = contentStream.getOutputStream();
@@ -2445,6 +2447,7 @@ private PdfStream ensureStreamDataIsReadyToBeProcessed(PdfStream stream) {
24452447
* @param text the text to write.
24462448
*/
24472449
private void showTextInt(String text) {
2450+
document.checkIsoConformance(currentGs, IsoKey.FONT_GLYPHS, null, contentStream);
24482451
if (currentGs.getFont() == null)
24492452
throw new PdfException(PdfException.FontAndSizeMustBeSetBeforeWritingAnyText, currentGs);
24502453
currentGs.getFont().writeText(text, contentStream.getOutputStream());

pdfa/src/main/java/com/itextpdf/pdfa/PdfAConformanceException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class PdfAConformanceException extends PdfException {
110110
public static final String IF_DEVICE_RGB_CMYK_GRAY_USED_IN_FILE_THAT_FILE_SHALL_CONTAIN_PDFA_OUTPUTINTENT_OR_DEFAULT_RGB_CMYK_GRAY_IN_USAGE_CONTEXT = "If device rgb cmyk gray used in file that file shall contain pdfa outputintent orDefaultRgb Cmyk Gray in usage context";
111111
public static final String IF_OUTPUTINTENTS_ARRAY_HAS_MORE_THAN_ONE_ENTRY_WITH_DESTOUTPUTPROFILE_KEY_THE_SAME_INDIRECT_OBJECT_SHALL_BE_USED_AS_THE_VALUE_OF_THAT_OBJECT = "If outputintents array has more than one entry with destoutputprofile key the same indirect object shall be used as the value of that object";
112112
public static final String IF_SPECIFIED_RENDERING_SHALL_BE_ONE_OF_THE_FOLLOWING_RELATIVECOLORIMETRIC_ABSOLUTECOLORIMETRIC_PERCEPTUAL_OR_SATURATION = "If specified rendering shall be one of the following relativecolorimetric absolutecolorimetric perceptual or saturation";
113-
public static final String IF_THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_TRANSPARENCY_IS_FORBIDDEN = "If the document does not contain a pdfa outputintent transparency is forbidden";
113+
public static final String THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE = "If the document does not contain a OutputIntent, then page with transparency shall include the dictionary with Group key that include a CS with blending colour space";
114114
public static final String JPEG2000_ENUMERATED_COLOUR_SPACE_19_CIEJAB_SHALL_NOT_BE_USED = "jpeg2000 enumerated colour space 19 (CIEJab) shall not be used";
115115
public static final String LZWDECODE_FILTER_IS_NOT_PERMITTED = "LZWDecode filter is not permitted";
116116
public static final String MIME_TYPE_SHALL_BE_SPECIFIED_USING_THE_SUBTYPE_KEY_OF_THE_FILE_SPECIFICATION_STREAM_DICTIONARY = "Mime type shall be specified using the subtype key of the file specification stream dictionary";
@@ -149,7 +149,9 @@ public class PdfAConformanceException extends PdfException {
149149
public static final String TRANSPARENCY_IS_NOT_ALLOWED_CA_SHALL_BE_EQUAL_TO_1 = "Transparency is not allowed. CA shall be equal to 1";
150150
public static final String VALUE_OF_NAME_ENTRY_SHALL_BE_UNIQUE_AMONG_ALL_OPTIONAL_CONTENT_CONFIGURATION_DICTIONARIES = "Value of name entry shall be unique among all optional content configuration dictionaries";
151151
public static final String WIDGET_ANNOTATION_DICTIONARY_OR_FIELD_DICTIONARY_SHALL_NOT_INCLUDE_A_OR_AA_ENTRY = "Widget annotation dictionary or field dictionary shall not include a or aa entry";
152-
152+
153+
@Deprecated
154+
public static final String IF_THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_TRANSPARENCY_IS_FORBIDDEN = "If the document does not contain a pdfa outputintent transparency is forbidden";
153155
/**
154156
* Creates a PdfAConformanceException.
155157
*

pdfa/src/main/java/com/itextpdf/pdfa/PdfADocument.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,17 @@ public PdfADocument(PdfReader reader, PdfWriter writer, StampingProperties prope
165165

166166
@Override
167167
public void checkIsoConformance(Object obj, IsoKey key) {
168-
checkIsoConformance(obj, key, null);
168+
checkIsoConformance(obj, key, null, null);
169169
}
170170

171171
@Override
172+
@Deprecated
172173
public void checkIsoConformance(Object obj, IsoKey key, PdfResources resources) {
174+
checkIsoConformance(obj, key, resources, null);
175+
}
176+
177+
@Override
178+
public void checkIsoConformance(Object obj, IsoKey key, PdfResources resources, PdfStream contentStream) {
173179
CanvasGraphicsState gState;
174180
PdfDictionary currentColorSpaces = null;
175181
if (resources != null) {
@@ -190,22 +196,25 @@ public void checkIsoConformance(Object obj, IsoKey key, PdfResources resources)
190196
break;
191197
case EXTENDED_GRAPHICS_STATE:
192198
gState = (CanvasGraphicsState) obj;
193-
checker.checkExtGState(gState);
199+
checker.checkExtGState(gState, contentStream);
194200
break;
195201
case FILL_COLOR:
196202
gState = (CanvasGraphicsState) obj;
197-
checker.checkColor(gState.getFillColor(), currentColorSpaces, true);
203+
checker.checkColor(gState.getFillColor(), currentColorSpaces, true, contentStream);
198204
break;
199205
case PAGE:
200206
checker.checkSinglePage((PdfPage) obj);
201207
break;
202208
case STROKE_COLOR:
203209
gState = (CanvasGraphicsState) obj;
204-
checker.checkColor(gState.getStrokeColor(), currentColorSpaces, false);
210+
checker.checkColor(gState.getStrokeColor(), currentColorSpaces, false, contentStream);
205211
break;
206212
case TAG_STRUCTURE_ELEMENT:
207213
checker.checkTagStructureElement((PdfObject) obj);
208214
break;
215+
case FONT_GLYPHS:
216+
checker.checkFontGlyphs(((CanvasGraphicsState) obj).getFont(), contentStream);
217+
break;
209218
}
210219
}
211220

pdfa/src/main/java/com/itextpdf/pdfa/checker/PdfA1Checker.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public void checkColor(Color color, PdfDictionary currentColorSpaces, Boolean fi
134134
checkColorSpace(color.getColorSpace(), currentColorSpaces, true, fill);
135135
}
136136

137+
@Override
138+
public void checkColor(Color color, PdfDictionary currentColorSpaces, Boolean fill, PdfStream stream) {
139+
checkColorSpace(color.getColorSpace(), currentColorSpaces, true, fill);
140+
}
141+
137142
@Override
138143
public void checkColorSpace(PdfColorSpace colorSpace, PdfDictionary currentColorSpaces, boolean checkAlternate, Boolean fill) {
139144
if (colorSpace instanceof PdfSpecialCs.Separation) {
@@ -187,6 +192,11 @@ protected void checkColorsUsages() {
187192

188193
@Override
189194
public void checkExtGState(CanvasGraphicsState extGState) {
195+
checkExtGState(extGState, null);
196+
}
197+
198+
@Override
199+
public void checkExtGState(CanvasGraphicsState extGState, PdfStream contentStream) {
190200
if (extGState.getTransferFunction() != null) {
191201
throw new PdfAConformanceException(PdfAConformanceException.AN_EXTGSTATE_DICTIONARY_SHALL_NOT_CONTAIN_THE_TR_KEY);
192202
}

0 commit comments

Comments
 (0)