@@ -30,6 +30,8 @@ You should have received a copy of the GNU Affero General Public License
3030using iText . Kernel . Pdf ;
3131using iText . Kernel . Pdf . Canvas ;
3232using iText . Kernel . Utils ;
33+ using iText . Layout ;
34+ using iText . Layout . Element ;
3335using iText . Pdfa . Exceptions ;
3436using iText . Test ;
3537using iText . Test . Pdfa ;
@@ -211,60 +213,68 @@ public virtual void CidFontCheckTest3() {
211213 [ NUnit . Framework . Test ]
212214 public virtual void SymbolicTtfCharEncodingsPdfA1Test01 ( ) {
213215 // encoding must not be specified
214- CreateDocumentWithFont ( "symbolicTtfCharEncodingsPdfA1Test01.pdf" , "Symbols1.ttf" , "" , PdfAConformanceLevel
215- . PDF_A_1B , null ) ;
216+ // Here we produced valid pdfa files in the past by silently removing not valid symbols
217+ // But right now we check for used glyphs which don't exist in the font and throw exception
218+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
219+ "symbolicTtfCharEncodingsPdfA1Test01.pdf" , "Symbols1.ttf" , "" , PdfAConformanceLevel . PDF_A_1B ) ) ;
220+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
221+ , e . Message ) ;
216222 }
217223
218224 [ NUnit . Framework . Test ]
219225 public virtual void SymbolicTtfCharEncodingsPdfA1Test02 ( ) {
220- // TODO: DEVSIX-2975 Using only shipped fonts in font provider can result in pdf with no-def glyph and not conforming PDF/A document
221- String expectedVeraPdfWarning = "VeraPDF verification failed. See verification results: " + UrlUtil . GetNormalizedFileUriString
222- ( DESTINATION_FOLDER + "symbolicTtfCharEncodingsPdfA1Test02.xml" ) ;
223226 // if you specify encoding, symbolic font is treated as non-symbolic
224- CreateDocumentWithFont ( "symbolicTtfCharEncodingsPdfA1Test02.pdf" , "Symbols1.ttf" , PdfEncodings . MACROMAN , PdfAConformanceLevel
225- . PDF_A_1B , expectedVeraPdfWarning ) ;
227+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
228+ "symbolicTtfCharEncodingsPdfA1Test02.pdf" , "Symbols1.ttf" , PdfEncodings . MACROMAN , PdfAConformanceLevel
229+ . PDF_A_1B ) ) ;
230+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
231+ , e . Message ) ;
226232 }
227233
228234 [ NUnit . Framework . Test ]
229235 public virtual void SymbolicTtfCharEncodingsPdfA1Test03 ( ) {
230236 // if you specify encoding, symbolic font is treated as non-symbolic
231237 Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
232238 "symbolicTtfCharEncodingsPdfA1Test03.pdf" , "Symbols1.ttf" , "ISO-8859-1" , PdfAConformanceLevel . PDF_A_1B
233- , null ) ) ;
234- NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . ALL_NON_SYMBOLIC_TRUE_TYPE_FONT_SHALL_SPECIFY_MAC_ROMAN_OR_WIN_ANSI_ENCODING_AS_THE_ENCODING_ENTRY
239+ ) ) ;
240+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
235241 , e . Message ) ;
236242 }
237243
238244 [ NUnit . Framework . Test ]
239245 public virtual void SymbolicTtfCharEncodingsPdfA1Test04 ( ) {
240- // TODO: DEVSIX-2975 Using only shipped fonts in font provider can result in pdf with no-def glyph and not conforming PDF/A document
241- String expectedVeraPdfWarning = "VeraPDF verification failed. See verification results: " + UrlUtil . GetNormalizedFileUriString
242- ( DESTINATION_FOLDER + "symbolicTtfCharEncodingsPdfA1Test04.xml" ) ;
243- // emulate behaviour with default WinAnsi, which was present in 7.1
244- CreateDocumentWithFont ( "symbolicTtfCharEncodingsPdfA1Test04.pdf" , "Symbols1.ttf" , PdfEncodings . WINANSI , PdfAConformanceLevel
245- . PDF_A_1B , expectedVeraPdfWarning ) ;
246+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
247+ "symbolicTtfCharEncodingsPdfA1Test04.pdf" , "Symbols1.ttf" , PdfEncodings . WINANSI , PdfAConformanceLevel .
248+ PDF_A_1B ) ) ;
249+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
250+ , e . Message ) ;
246251 }
247252
248253 [ NUnit . Framework . Test ]
249254 public virtual void SymbolicTtfCharEncodingsPdfA1Test05 ( ) {
250255 // Identity-H behaviour should be the same as the default one, starting from 7.2
251- CreateDocumentWithFont ( "symbolicTtfCharEncodingsPdfA1Test05.pdf" , "Symbols1.ttf" , PdfEncodings . IDENTITY_H ,
252- PdfAConformanceLevel . PDF_A_1B , null ) ;
256+ // Here we produced valid pdfa files in the past by silently removing not valid symbols
257+ // But right now we check for used glyphs which don't exist in the font and throw exception
258+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
259+ "symbolicTtfCharEncodingsPdfA1Test05.pdf" , "Symbols1.ttf" , PdfEncodings . IDENTITY_H , PdfAConformanceLevel
260+ . PDF_A_1B ) ) ;
261+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
262+ , e . Message ) ;
253263 }
254264
255265 [ NUnit . Framework . Test ]
256266 public virtual void NonSymbolicTtfCharEncodingsPdfA1Test01 ( ) {
257267 // encoding must be either winansi or macroman, by default winansi is used
258268 CreateDocumentWithFont ( "nonSymbolicTtfCharEncodingsPdfA1Test01.pdf" , "FreeSans.ttf" , PdfEncodings . WINANSI ,
259- PdfAConformanceLevel . PDF_A_1B , null ) ;
269+ PdfAConformanceLevel . PDF_A_1B ) ;
260270 }
261271
262272 [ NUnit . Framework . Test ]
263273 public virtual void NonSymbolicTtfCharEncodingsPdfA1Test02 ( ) {
264274 // encoding must be either winansi or macroman, by default winansi is used
265275 Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
266276 "nonSymbolicTtfCharEncodingsPdfA1Test02.pdf" , "FreeSans.ttf" , "ISO-8859-1" , PdfAConformanceLevel . PDF_A_2B
267- , null ) ) ;
277+ ) ) ;
268278 NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . ALL_NON_SYMBOLIC_TRUE_TYPE_FONT_SHALL_SPECIFY_MAC_ROMAN_ENCODING_OR_WIN_ANSI_ENCODING
269279 , e . Message ) ;
270280 }
@@ -280,24 +290,16 @@ public virtual void NotdefInTrueTypeFontTest() {
280290 PdfFont font = PdfFontFactory . CreateFont ( SOURCE_FOLDER + "FreeSans.ttf" , "# simple 32 0020 00C5 1987" , PdfFontFactory . EmbeddingStrategy
281291 . PREFER_EMBEDDED ) ;
282292 PdfCanvas canvas = new PdfCanvas ( doc . AddNewPage ( ) ) ;
283- canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 786 ) . SetFontAndSize ( font , 36 ) . ShowText ( "\u00C5 \u1987 " ) . EndText
284- ( ) . RestoreState ( ) ;
285- font = PdfFontFactory . CreateFont ( SOURCE_FOLDER + "FreeSans.ttf" , PdfEncodings . WINANSI , PdfFontFactory . EmbeddingStrategy
286- . PREFER_EMBEDDED ) ;
287- canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 756 ) . SetFontAndSize ( font , 36 ) . ShowText ( "\u1987 " ) . EndText ( ) . RestoreState
288- ( ) ;
289- Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => doc . Close ( ) ) ;
290- NUnit . Framework . Assert . AreEqual ( PdfAConformanceException . ALL_NON_SYMBOLIC_TRUE_TYPE_FONT_SHALL_SPECIFY_MAC_ROMAN_ENCODING_OR_WIN_ANSI_ENCODING
293+ canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 786 ) . SetFontAndSize ( font , 36 ) ;
294+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => canvas . ShowText ( "\u00C5 \u1987 "
295+ ) ) ;
296+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
291297 , e . Message ) ;
292298 }
293299
294300 [ NUnit . Framework . Test ]
295301 public virtual void NotdefFontTest2 ( ) {
296- // TODO: DEVSIX-2975 Using only shipped fonts in font provider can result in pdf with no-def glyph and not conforming PDF/A document
297302 String outPdf = DESTINATION_FOLDER + "notdefFontTest2.pdf" ;
298- String cmpPdf = SOURCE_FOLDER + "cmp/PdfAFontTest/notdefFontTest2.pdf" ;
299- String expectedVeraPdfWarning = "VeraPDF verification failed. See verification results: " + UrlUtil . GetNormalizedFileUriString
300- ( DESTINATION_FOLDER + "notdefFontTest2.xml" ) ;
301303 PdfWriter writer = new PdfWriter ( outPdf , new WriterProperties ( ) . SetPdfVersion ( PdfVersion . PDF_2_0 ) ) ;
302304 Stream @is = new FileStream ( SOURCE_FOLDER + "sRGB Color Space Profile.icm" , FileMode . Open , FileAccess . Read
303305 ) ;
@@ -306,10 +308,50 @@ public virtual void NotdefFontTest2() {
306308 PdfFont font = PdfFontFactory . CreateFont ( SOURCE_FOLDER + "NotoSans-Regular.ttf" , "" , PdfFontFactory . EmbeddingStrategy
307309 . PREFER_EMBEDDED ) ;
308310 PdfCanvas canvas = new PdfCanvas ( doc . AddNewPage ( ) ) ;
309- canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 786 ) . SetFontAndSize ( font , 36 ) . ShowText ( "\u898B \u7A4D \u3082 \u308A "
310- ) . EndText ( ) . RestoreState ( ) ;
311- doc . Close ( ) ;
312- CompareResult ( outPdf , cmpPdf , expectedVeraPdfWarning ) ;
311+ canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 786 ) . SetFontAndSize ( font , 36 ) ;
312+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => canvas . ShowText ( "\u898B \u7A4D \u3082 \u308A "
313+ ) ) ;
314+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
315+ , e . Message ) ;
316+ }
317+
318+ [ NUnit . Framework . Test ]
319+ public virtual void GlyphLineWithUndefinedGlyphsTest ( ) {
320+ String outPdf = DESTINATION_FOLDER + "glyphLineWithUndefinedGlyphs.pdf" ;
321+ Stream icm = new FileStream ( SOURCE_FOLDER + "sRGB Color Space Profile.icm" , FileMode . Open , FileAccess . Read
322+ ) ;
323+ Document document = new Document ( new PdfADocument ( new PdfWriter ( outPdf , new WriterProperties ( ) . SetPdfVersion
324+ ( PdfVersion . PDF_2_0 ) ) , PdfAConformanceLevel . PDF_A_4 , new PdfOutputIntent ( "Custom" , "" , "http://www.color.org"
325+ , "sRGB ICC preference" , icm ) ) ) ;
326+ PdfFont font = PdfFontFactory . CreateFont ( SOURCE_FOLDER + "NotoSans-Regular.ttf" , "" , PdfFontFactory . EmbeddingStrategy
327+ . PREFER_EMBEDDED ) ;
328+ Paragraph p = new Paragraph ( "\u898B \u7A4D \u3082 \u308A " ) ;
329+ p . SetFont ( font ) ;
330+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => document . Add ( p ) ) ;
331+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
332+ , e . Message ) ;
333+ }
334+
335+ [ NUnit . Framework . Test ]
336+ public virtual void PdfArrayWithUndefinedGlyphsTest ( ) {
337+ String outPdf = DESTINATION_FOLDER + "pdfArrayWithUndefinedGlyphs.pdf" ;
338+ PdfWriter writer = new PdfWriter ( outPdf , new WriterProperties ( ) . SetPdfVersion ( PdfVersion . PDF_2_0 ) ) ;
339+ Stream @is = new FileStream ( SOURCE_FOLDER + "sRGB Color Space Profile.icm" , FileMode . Open , FileAccess . Read
340+ ) ;
341+ PdfDocument doc = new PdfADocument ( writer , PdfAConformanceLevel . PDF_A_4 , new PdfOutputIntent ( "Custom" , "" ,
342+ "http://www.color.org" , "sRGB IEC61966-2.1" , @is ) ) ;
343+ PdfFont font = PdfFontFactory . CreateFont ( SOURCE_FOLDER + "NotoSans-Regular.ttf" , "" , PdfFontFactory . EmbeddingStrategy
344+ . PREFER_EMBEDDED ) ;
345+ PdfCanvas canvas = new PdfCanvas ( doc . AddNewPage ( ) ) ;
346+ canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 786 ) . SetFontAndSize ( font , 36 ) ;
347+ PdfArray pdfArray = new PdfArray ( ) ;
348+ pdfArray . Add ( new PdfString ( "ABC" ) ) ;
349+ pdfArray . Add ( new PdfNumber ( 1 ) ) ;
350+ pdfArray . Add ( new PdfString ( "\u898B \u7A4D \u3082 \u308A " ) ) ;
351+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => canvas . ShowText ( pdfArray
352+ ) ) ;
353+ NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . EMBEDDED_FONTS_SHALL_DEFINE_ALL_REFERENCED_GLYPHS
354+ , e . Message ) ;
313355 }
314356
315357 [ NUnit . Framework . Test ]
@@ -565,7 +607,7 @@ public virtual void CheckPdfA4WoffTest() {
565607 }
566608
567609 private void CreateDocumentWithFont ( String outFileName , String fontFileName , String encoding , PdfAConformanceLevel
568- conformanceLevel , String expectedVeraPdfWarning ) {
610+ conformanceLevel ) {
569611 String outPdf = DESTINATION_FOLDER + outFileName ;
570612 String cmpPdf = SOURCE_FOLDER + "cmp/PdfAFontTest/cmp_" + outFileName ;
571613 PdfWriter writer = new PdfWriter ( outPdf ) ;
@@ -580,7 +622,7 @@ private void CreateDocumentWithFont(String outFileName, String fontFileName, Str
580622 canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 700 ) . SetFontAndSize ( font , 12 ) . ShowText ( "Hello World" ) . EndText (
581623 ) . RestoreState ( ) ;
582624 doc . Close ( ) ;
583- CompareResult ( outPdf , cmpPdf , expectedVeraPdfWarning ) ;
625+ CompareResult ( outPdf , cmpPdf , null ) ;
584626 }
585627
586628 private void CompareResult ( String outPdf , String cmpPdf , String expectedVeraPdfWarning ) {
0 commit comments