@@ -30,6 +30,8 @@ You should have received a copy of the GNU Affero General Public License
30
30
using iText . Kernel . Pdf ;
31
31
using iText . Kernel . Pdf . Canvas ;
32
32
using iText . Kernel . Utils ;
33
+ using iText . Layout ;
34
+ using iText . Layout . Element ;
33
35
using iText . Pdfa . Exceptions ;
34
36
using iText . Test ;
35
37
using iText . Test . Pdfa ;
@@ -211,60 +213,68 @@ public virtual void CidFontCheckTest3() {
211
213
[ NUnit . Framework . Test ]
212
214
public virtual void SymbolicTtfCharEncodingsPdfA1Test01 ( ) {
213
215
// 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 ) ;
216
222
}
217
223
218
224
[ NUnit . Framework . Test ]
219
225
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" ) ;
223
226
// 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 ) ;
226
232
}
227
233
228
234
[ NUnit . Framework . Test ]
229
235
public virtual void SymbolicTtfCharEncodingsPdfA1Test03 ( ) {
230
236
// if you specify encoding, symbolic font is treated as non-symbolic
231
237
Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
232
238
"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
235
241
, e . Message ) ;
236
242
}
237
243
238
244
[ NUnit . Framework . Test ]
239
245
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 ) ;
246
251
}
247
252
248
253
[ NUnit . Framework . Test ]
249
254
public virtual void SymbolicTtfCharEncodingsPdfA1Test05 ( ) {
250
255
// 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 ) ;
253
263
}
254
264
255
265
[ NUnit . Framework . Test ]
256
266
public virtual void NonSymbolicTtfCharEncodingsPdfA1Test01 ( ) {
257
267
// encoding must be either winansi or macroman, by default winansi is used
258
268
CreateDocumentWithFont ( "nonSymbolicTtfCharEncodingsPdfA1Test01.pdf" , "FreeSans.ttf" , PdfEncodings . WINANSI ,
259
- PdfAConformanceLevel . PDF_A_1B , null ) ;
269
+ PdfAConformanceLevel . PDF_A_1B ) ;
260
270
}
261
271
262
272
[ NUnit . Framework . Test ]
263
273
public virtual void NonSymbolicTtfCharEncodingsPdfA1Test02 ( ) {
264
274
// encoding must be either winansi or macroman, by default winansi is used
265
275
Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfAConformanceException ) , ( ) => CreateDocumentWithFont (
266
276
"nonSymbolicTtfCharEncodingsPdfA1Test02.pdf" , "FreeSans.ttf" , "ISO-8859-1" , PdfAConformanceLevel . PDF_A_2B
267
- , null ) ) ;
277
+ ) ) ;
268
278
NUnit . Framework . Assert . AreEqual ( PdfaExceptionMessageConstant . ALL_NON_SYMBOLIC_TRUE_TYPE_FONT_SHALL_SPECIFY_MAC_ROMAN_ENCODING_OR_WIN_ANSI_ENCODING
269
279
, e . Message ) ;
270
280
}
@@ -280,24 +290,16 @@ public virtual void NotdefInTrueTypeFontTest() {
280
290
PdfFont font = PdfFontFactory . CreateFont ( SOURCE_FOLDER + "FreeSans.ttf" , "# simple 32 0020 00C5 1987" , PdfFontFactory . EmbeddingStrategy
281
291
. PREFER_EMBEDDED ) ;
282
292
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
291
297
, e . Message ) ;
292
298
}
293
299
294
300
[ NUnit . Framework . Test ]
295
301
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
297
302
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" ) ;
301
303
PdfWriter writer = new PdfWriter ( outPdf , new WriterProperties ( ) . SetPdfVersion ( PdfVersion . PDF_2_0 ) ) ;
302
304
Stream @is = new FileStream ( SOURCE_FOLDER + "sRGB Color Space Profile.icm" , FileMode . Open , FileAccess . Read
303
305
) ;
@@ -306,10 +308,50 @@ public virtual void NotdefFontTest2() {
306
308
PdfFont font = PdfFontFactory . CreateFont ( SOURCE_FOLDER + "NotoSans-Regular.ttf" , "" , PdfFontFactory . EmbeddingStrategy
307
309
. PREFER_EMBEDDED ) ;
308
310
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 ) ;
313
355
}
314
356
315
357
[ NUnit . Framework . Test ]
@@ -565,7 +607,7 @@ public virtual void CheckPdfA4WoffTest() {
565
607
}
566
608
567
609
private void CreateDocumentWithFont ( String outFileName , String fontFileName , String encoding , PdfAConformanceLevel
568
- conformanceLevel , String expectedVeraPdfWarning ) {
610
+ conformanceLevel ) {
569
611
String outPdf = DESTINATION_FOLDER + outFileName ;
570
612
String cmpPdf = SOURCE_FOLDER + "cmp/PdfAFontTest/cmp_" + outFileName ;
571
613
PdfWriter writer = new PdfWriter ( outPdf ) ;
@@ -580,7 +622,7 @@ private void CreateDocumentWithFont(String outFileName, String fontFileName, Str
580
622
canvas . SaveState ( ) . BeginText ( ) . MoveText ( 36 , 700 ) . SetFontAndSize ( font , 12 ) . ShowText ( "Hello World" ) . EndText (
581
623
) . RestoreState ( ) ;
582
624
doc . Close ( ) ;
583
- CompareResult ( outPdf , cmpPdf , expectedVeraPdfWarning ) ;
625
+ CompareResult ( outPdf , cmpPdf , null ) ;
584
626
}
585
627
586
628
private void CompareResult ( String outPdf , String cmpPdf , String expectedVeraPdfWarning ) {
0 commit comments