@@ -218,7 +218,7 @@ public void checkColor(Color color, PdfDictionary currentColorSpaces, Boolean fi
218
218
if (pattern instanceof PdfPattern .Shading ) {
219
219
PdfDictionary shadingDictionary = ((PdfPattern .Shading ) pattern ).getShading ();
220
220
PdfObject colorSpace = shadingDictionary .get (PdfName .ColorSpace );
221
- checkColorSpace (PdfColorSpace .makeColorSpace (colorSpace ), currentColorSpaces , true , true );
221
+ checkColorSpace (PdfColorSpace .makeColorSpace (colorSpace ), contentStream , currentColorSpaces , true , true );
222
222
final PdfDictionary extGStateDict = ((PdfDictionary ) pattern .getPdfObject ()).getAsDictionary (PdfName .ExtGState );
223
223
CanvasGraphicsState gState = new UpdateCanvasGraphicsState (extGStateDict );
224
224
checkExtGState (gState , contentStream );
@@ -230,8 +230,12 @@ public void checkColor(Color color, PdfDictionary currentColorSpaces, Boolean fi
230
230
super .checkColor (color , currentColorSpaces , fill , contentStream );
231
231
}
232
232
233
+ /**
234
+ * {@inheritDoc}
235
+ */
233
236
@ Override
234
- public void checkColorSpace (PdfColorSpace colorSpace , PdfDictionary currentColorSpaces , boolean checkAlternate , Boolean fill ) {
237
+ public void checkColorSpace (PdfColorSpace colorSpace , PdfObject pdfObject , PdfDictionary currentColorSpaces ,
238
+ boolean checkAlternate , Boolean fill ) {
235
239
if (fill != null ) {
236
240
if ((boolean ) fill ) {
237
241
currentFillCsIsIccBasedCMYK = false ;
@@ -245,7 +249,7 @@ public void checkColorSpace(PdfColorSpace colorSpace, PdfDictionary currentColor
245
249
PdfSpecialCs .Separation separation = (PdfSpecialCs .Separation ) colorSpace ;
246
250
checkSeparationCS ((PdfArray ) separation .getPdfObject ());
247
251
if (checkAlternate ) {
248
- checkColorSpace (separation .getBaseCs (), currentColorSpaces , false , fill );
252
+ checkColorSpace (separation .getBaseCs (), pdfObject , currentColorSpaces , false , fill );
249
253
}
250
254
251
255
} else if (colorSpace instanceof PdfSpecialCs .DeviceN ) {
@@ -266,30 +270,30 @@ public void checkColorSpace(PdfColorSpace colorSpace, PdfDictionary currentColor
266
270
}
267
271
268
272
if (checkAlternate ) {
269
- checkColorSpace (deviceN .getBaseCs (), currentColorSpaces , false , fill );
273
+ checkColorSpace (deviceN .getBaseCs (), pdfObject , currentColorSpaces , false , fill );
270
274
}
271
275
272
276
} else if (colorSpace instanceof PdfSpecialCs .Indexed ) {
273
277
if (checkAlternate ) {
274
- checkColorSpace (((PdfSpecialCs .Indexed ) colorSpace ).getBaseCs (), currentColorSpaces , true , fill );
278
+ checkColorSpace (((PdfSpecialCs .Indexed ) colorSpace ).getBaseCs (), pdfObject , currentColorSpaces , true , fill );
275
279
}
276
280
} else if (colorSpace instanceof PdfSpecialCs .UncoloredTilingPattern ) {
277
281
if (checkAlternate ) {
278
- checkColorSpace (((PdfSpecialCs .UncoloredTilingPattern ) colorSpace ).getUnderlyingColorSpace (), currentColorSpaces , true , fill );
282
+ checkColorSpace (((PdfSpecialCs .UncoloredTilingPattern ) colorSpace ).getUnderlyingColorSpace (), pdfObject ,
283
+ currentColorSpaces , true , fill );
279
284
}
280
285
} else {
281
-
282
286
if (colorSpace instanceof PdfDeviceCs .Rgb ) {
283
- if (!checkDefaultCS (currentColorSpaces , fill , PdfName .DefaultRGB , 3 )) {
284
- rgbIsUsed = true ;
287
+ if (!checkDefaultCS (pdfObject , currentColorSpaces , fill , PdfName .DefaultRGB , 3 )) {
288
+ rgbUsedObjects . add ( pdfObject ) ;
285
289
}
286
290
} else if (colorSpace instanceof PdfDeviceCs .Cmyk ) {
287
- if (!checkDefaultCS (currentColorSpaces , fill , PdfName .DefaultCMYK , 4 )) {
288
- cmykIsUsed = true ;
291
+ if (!checkDefaultCS (pdfObject , currentColorSpaces , fill , PdfName .DefaultCMYK , 4 )) {
292
+ cmykUsedObjects . add ( pdfObject ) ;
289
293
}
290
294
} else if (colorSpace instanceof PdfDeviceCs .Gray ) {
291
- if (!checkDefaultCS (currentColorSpaces , fill , PdfName .DefaultGray , 1 )) {
292
- grayIsUsed = true ;
295
+ if (!checkDefaultCS (pdfObject , currentColorSpaces , fill , PdfName .DefaultGray , 1 )) {
296
+ grayUsedObjects . add ( pdfObject ) ;
293
297
}
294
298
}
295
299
}
@@ -544,7 +548,7 @@ protected void checkAppearanceStream(PdfStream appearanceStream) {
544
548
if (isContainsTransparencyGroup (appearanceStream )) {
545
549
this .transparencyObjects .add (appearanceStream );
546
550
}
547
- checkResources (appearanceStream .getAsDictionary (PdfName .Resources ));
551
+ checkResources (appearanceStream .getAsDictionary (PdfName .Resources ), appearanceStream );
548
552
}
549
553
550
554
@ Override
@@ -557,14 +561,14 @@ protected void checkForm(PdfDictionary form) {
557
561
if (form .containsKey (PdfName .XFA )) {
558
562
throw new PdfAConformanceException (PdfaExceptionMessageConstant .THE_INTERACTIVE_FORM_DICTIONARY_SHALL_NOT_CONTAIN_THE_XFA_KEY );
559
563
}
560
- checkResources (form .getAsDictionary (PdfName .DR ));
564
+ checkResources (form .getAsDictionary (PdfName .DR ), form );
561
565
562
566
PdfArray fields = form .getAsArray (PdfName .Fields );
563
567
if (fields != null ) {
564
568
fields = getFormFields (fields );
565
569
for (PdfObject field : fields ) {
566
570
PdfDictionary fieldDic = (PdfDictionary ) field ;
567
- checkResources (fieldDic .getAsDictionary (PdfName .DR ));
571
+ checkResources (fieldDic .getAsDictionary (PdfName .DR ), fieldDic );
568
572
}
569
573
}
570
574
}
@@ -746,7 +750,7 @@ protected void checkPageObject(PdfDictionary pageDict, PdfDictionary pageResourc
746
750
PdfObject cs = pageDict .getAsDictionary (PdfName .Group ).get (PdfName .CS );
747
751
if (cs != null ) {
748
752
PdfDictionary currentColorSpaces = pageResources .getAsDictionary (PdfName .ColorSpace );
749
- checkColorSpace (PdfColorSpace .makeColorSpace (cs ), currentColorSpaces , true , null );
753
+ checkColorSpace (PdfColorSpace .makeColorSpace (cs ), pageDict , currentColorSpaces , true , null );
750
754
}
751
755
}
752
756
}
@@ -803,18 +807,22 @@ protected Set<PdfName> getAllowedNamedActions() {
803
807
return allowedNamedActions ;
804
808
}
805
809
810
+ /**
811
+ * {@inheritDoc}
812
+ */
806
813
@ Override
807
- protected void checkColorsUsages () {
808
- if ((rgbIsUsed || cmykIsUsed || grayIsUsed ) && pdfAOutputIntentColorSpace == null ) {
814
+ protected void checkPageColorsUsages (PdfDictionary pageDict , PdfDictionary pageResources ) {
815
+ if ((rgbIsUsed || cmykIsUsed || grayIsUsed || !rgbUsedObjects .isEmpty () || !cmykUsedObjects .isEmpty () ||
816
+ !grayUsedObjects .isEmpty ()) && pdfAOutputIntentColorSpace == null ) {
809
817
throw new PdfAConformanceException (PdfaExceptionMessageConstant .IF_DEVICE_RGB_CMYK_GRAY_USED_IN_FILE_THAT_FILE_SHALL_CONTAIN_PDFA_OUTPUTINTENT_OR_DEFAULT_RGB_CMYK_GRAY_IN_USAGE_CONTEXT );
810
818
}
811
819
812
- if (rgbIsUsed ) {
820
+ if (rgbIsUsed || ! rgbUsedObjects . isEmpty () ) {
813
821
if (!ICC_COLOR_SPACE_RGB .equals (pdfAOutputIntentColorSpace )) {
814
822
throw new PdfAConformanceException (PdfaExceptionMessageConstant .DEVICERGB_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_RGB_PDFA_OUTPUT_INTENT_OR_DEFAULTRGB_IN_USAGE_CONTEXT );
815
823
}
816
824
}
817
- if (cmykIsUsed ) {
825
+ if (cmykIsUsed || ! cmykUsedObjects . isEmpty () ) {
818
826
if (!ICC_COLOR_SPACE_CMYK .equals (pdfAOutputIntentColorSpace )) {
819
827
throw new PdfAConformanceException (PdfaExceptionMessageConstant .DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT_OR_DEFAULTCMYK_IN_USAGE_CONTEXT );
820
828
}
@@ -826,14 +834,14 @@ protected void checkImage(PdfStream image, PdfDictionary currentColorSpaces) {
826
834
PdfColorSpace colorSpace = null ;
827
835
if (isAlreadyChecked (image )) {
828
836
colorSpace = checkedObjectsColorspace .get (image );
829
- checkColorSpace (colorSpace , currentColorSpaces , true , null );
837
+ checkColorSpace (colorSpace , image , currentColorSpaces , true , null );
830
838
return ;
831
839
}
832
840
833
841
PdfObject colorSpaceObj = image .get (PdfName .ColorSpace );
834
842
if (colorSpaceObj != null ) {
835
843
colorSpace = PdfColorSpace .makeColorSpace (colorSpaceObj );
836
- checkColorSpace (colorSpace , currentColorSpaces , true , null );
844
+ checkColorSpace (colorSpace , image , currentColorSpaces , true , null );
837
845
checkedObjectsColorspace .put (image , colorSpace );
838
846
}
839
847
@@ -900,17 +908,17 @@ protected void checkImage(PdfStream image, PdfDictionary currentColorSpaces) {
900
908
switch (colorSpecBox .getEnumCs ()) {
901
909
case 1 :
902
910
PdfDeviceCs .Gray deviceGrayCs = new PdfDeviceCs .Gray ();
903
- checkColorSpace (deviceGrayCs , currentColorSpaces , true , null );
911
+ checkColorSpace (deviceGrayCs , image , currentColorSpaces , true , null );
904
912
checkedObjectsColorspace .put (image , deviceGrayCs );
905
913
break ;
906
914
case 3 :
907
915
PdfDeviceCs .Rgb deviceRgbCs = new PdfDeviceCs .Rgb ();
908
- checkColorSpace (deviceRgbCs , currentColorSpaces , true , null );
916
+ checkColorSpace (deviceRgbCs , image , currentColorSpaces , true , null );
909
917
checkedObjectsColorspace .put (image , deviceRgbCs );
910
918
break ;
911
919
case 12 :
912
920
PdfDeviceCs .Cmyk deviceCmykCs = new PdfDeviceCs .Cmyk ();
913
- checkColorSpace (deviceCmykCs , currentColorSpaces , true , null );
921
+ checkColorSpace (deviceCmykCs , image , currentColorSpaces , true , null );
914
922
checkedObjectsColorspace .put (image , deviceCmykCs );
915
923
break ;
916
924
}
@@ -972,7 +980,7 @@ protected void checkFormXObject(PdfStream form, PdfStream contentStream) {
972
980
973
981
checkTransparencyGroup (form , contentStream );
974
982
975
- checkResources (form .getAsDictionary (PdfName .Resources ));
983
+ checkResources (form .getAsDictionary (PdfName .Resources ), contentStream != null ? contentStream : form );
976
984
checkContentStream (form );
977
985
}
978
986
@@ -987,7 +995,8 @@ protected void checkTransparencyGroup(PdfStream form, PdfStream contentStream) {
987
995
PdfDictionary resources = form .getAsDictionary (PdfName .Resources );
988
996
if (cs != null && resources != null ) {
989
997
PdfDictionary currentColorSpaces = resources .getAsDictionary (PdfName .ColorSpace );
990
- checkColorSpace (PdfColorSpace .makeColorSpace (cs ), currentColorSpaces , true , null );
998
+ checkColorSpace (PdfColorSpace .makeColorSpace (cs ), contentStream != null ? contentStream : form ,
999
+ currentColorSpaces , true , null );
991
1000
}
992
1001
}
993
1002
}
@@ -1184,7 +1193,8 @@ private void fillOrderRecursively(PdfArray orderArray, Set<PdfObject> order) {
1184
1193
}
1185
1194
}
1186
1195
1187
- private boolean checkDefaultCS (PdfDictionary currentColorSpaces , Boolean fill , PdfName defaultCsName , int numOfComponents ) {
1196
+ private boolean checkDefaultCS (PdfObject pdfObject , PdfDictionary currentColorSpaces , Boolean fill , PdfName defaultCsName ,
1197
+ int numOfComponents ) {
1188
1198
if (currentColorSpaces == null )
1189
1199
return false ;
1190
1200
if (!currentColorSpaces .containsKey (defaultCsName ))
@@ -1198,7 +1208,7 @@ private boolean checkDefaultCS(PdfDictionary currentColorSpaces, Boolean fill, P
1198
1208
if (defaultCs .getNumberOfComponents () != numOfComponents )
1199
1209
throw new PdfAConformanceException (PdfaExceptionMessageConstant .COLOR_SPACE_0_SHALL_HAVE_1_COMPONENTS ).setMessageParams (defaultCsName .getValue (), numOfComponents );
1200
1210
1201
- checkColorSpace (defaultCs , currentColorSpaces , false , fill );
1211
+ checkColorSpace (defaultCs , pdfObject , currentColorSpaces , false , fill );
1202
1212
return true ;
1203
1213
}
1204
1214
0 commit comments