@@ -42,9 +42,11 @@ This file is part of the iText (R) project.
42
42
43
43
import java .io .IOException ;
44
44
import java .util .List ;
45
+ import org .junit .jupiter .api .Assertions ;
45
46
import org .junit .jupiter .api .BeforeAll ;
46
47
import org .junit .jupiter .api .BeforeEach ;
47
48
import org .junit .jupiter .api .Tag ;
49
+ import org .junit .jupiter .api .Test ;
48
50
import org .junit .jupiter .params .ParameterizedTest ;
49
51
import org .junit .jupiter .params .provider .MethodSource ;
50
52
@@ -185,6 +187,7 @@ public void trueTypeFontWithDifferencesTest(PdfUAConformance pdfUAConformance) t
185
187
});
186
188
187
189
// TODO DEVSIX-9017 Support PDF/UA rules for fonts.
190
+ // TODO DEVSIX-9004 Support Character encodings related rules in UA-2
188
191
framework .assertOnlyVeraPdfFail ("trueTypeFontWithDifferencesTest" , pdfUAConformance );
189
192
}
190
193
@@ -230,4 +233,98 @@ public void type1EmbeddedFontTest(PdfUAConformance pdfUAConformance) throws IOEx
230
233
});
231
234
framework .assertBothValid ("type1EmbeddedFontTest" , pdfUAConformance );
232
235
}
236
+
237
+ @ Test
238
+ // TODO DEVSIX-9076 NPE when cmap of True Type Font doesn't contain Microsoft Unicode or Macintosh Roman encodings
239
+ public void nonSymbolicTtfWithChangedCmapTest () {
240
+ Assertions .assertThrows (NullPointerException .class ,
241
+ () -> PdfFontFactory .createFont (FONT_FOLDER + "FreeSans_changed_cmap.ttf" , PdfEncodings .MACROMAN ,
242
+ EmbeddingStrategy .FORCE_EMBEDDED ));
243
+ }
244
+
245
+ @ ParameterizedTest
246
+ @ MethodSource ("data" )
247
+ public void nonSymbolicTtfWithValidEncodingTest (PdfUAConformance pdfUAConformance ) throws IOException {
248
+ framework .addBeforeGenerationHook (pdfDoc -> {
249
+ Document document = new Document (pdfDoc );
250
+ PdfFont font ;
251
+ try {
252
+ font = PdfFontFactory .createFont (FONT , PdfEncodings .MACROMAN , EmbeddingStrategy .FORCE_EMBEDDED );
253
+ } catch (IOException e ) {
254
+ throw new RuntimeException ();
255
+ }
256
+ document .setFont (font );
257
+
258
+ Paragraph paragraph = new Paragraph ("ABC" );
259
+ document .add (paragraph );
260
+ });
261
+ framework .assertBothValid ("nonSymbolicTtfWithIncompatibleEncoding" , pdfUAConformance );
262
+ }
263
+
264
+ @ ParameterizedTest
265
+ @ MethodSource ("data" )
266
+ public void nonSymbolicTtfWithIncompatibleEncodingTest (PdfUAConformance pdfUAConformance ) throws IOException {
267
+ framework .addBeforeGenerationHook (pdfDoc -> {
268
+ Document document = new Document (pdfDoc );
269
+ PdfFont font ;
270
+ try {
271
+ font = PdfFontFactory .createFont (FONT , PdfEncodings .UTF8 , EmbeddingStrategy .FORCE_EMBEDDED );
272
+ } catch (IOException e ) {
273
+ throw new RuntimeException ();
274
+ }
275
+ document .setFont (font );
276
+
277
+ Paragraph paragraph = new Paragraph ("ABC" );
278
+ document .add (paragraph );
279
+ });
280
+ // TODO DEVSIX-9004 Support Character encodings related rules in UA-2
281
+ framework .assertOnlyVeraPdfFail ("nonSymbolicTtfWithIncompatibleEncoding" , pdfUAConformance );
282
+ }
283
+
284
+ @ ParameterizedTest
285
+ @ MethodSource ("data" )
286
+ public void symbolicTtfTest (PdfUAConformance pdfUAConformance ) throws IOException {
287
+ framework .addBeforeGenerationHook (pdfDoc -> {
288
+ Document document = new Document (pdfDoc );
289
+ PdfFont font ;
290
+ try {
291
+ font = PdfFontFactory .createFont (FONT_FOLDER + "Symbols1.ttf" );
292
+ } catch (IOException e ) {
293
+ throw new RuntimeException ();
294
+ }
295
+ document .setFont (font );
296
+
297
+ Paragraph paragraph = new Paragraph ("ABC" );
298
+ document .add (paragraph );
299
+ });
300
+ framework .assertBothValid ("symbolicTtf" , pdfUAConformance );
301
+ }
302
+
303
+ @ ParameterizedTest
304
+ @ MethodSource ("data" )
305
+ public void symbolicTtfWithEncodingTest (PdfUAConformance pdfUAConformance ) throws IOException {
306
+ framework .addBeforeGenerationHook (pdfDoc -> {
307
+ Document document = new Document (pdfDoc );
308
+ PdfFont font ;
309
+ try {
310
+ // if we specify encoding, symbolic font is treated as non-symbolic
311
+ font = PdfFontFactory .createFont (FONT_FOLDER + "Symbols1.ttf" , PdfEncodings .MACROMAN , EmbeddingStrategy .FORCE_EMBEDDED );
312
+ } catch (IOException e ) {
313
+ throw new RuntimeException ();
314
+ }
315
+ document .setFont (font );
316
+
317
+ Paragraph paragraph = new Paragraph ("ABC" );
318
+ document .add (paragraph );
319
+ });
320
+ framework .assertBothValid ("symbolicTtfWithEncoding" , pdfUAConformance );
321
+ }
322
+
323
+ @ Test
324
+ // TODO DEVSIX-9076 NPE when cmap of True Type Font doesn't contain Microsoft Unicode or Macintosh Roman encodings
325
+ public void symbolicTtfWithChangedCmapTest () {
326
+ Assertions .assertThrows (NullPointerException .class ,
327
+ () -> PdfFontFactory .createFont (FONT_FOLDER + "Symbols1_changed_cmap.ttf" ,
328
+ EmbeddingStrategy .FORCE_EMBEDDED ));
329
+ }
233
330
}
0 commit comments