@@ -22,19 +22,22 @@ This file is part of the iText (R) project.
22
22
*/
23
23
package com .itextpdf .layout .font ;
24
24
25
+ import com .itextpdf .commons .utils .FileUtil ;
25
26
import com .itextpdf .io .font .FontCache ;
26
27
import com .itextpdf .io .font .FontProgram ;
27
28
import com .itextpdf .io .font .FontProgramFactory ;
28
29
import com .itextpdf .io .font .PdfEncodings ;
29
30
import com .itextpdf .io .font .Type1Font ;
30
31
import com .itextpdf .io .font .constants .StandardFonts ;
31
- import com .itextpdf .commons .utils .FileUtil ;
32
32
import com .itextpdf .kernel .exceptions .PdfException ;
33
33
import com .itextpdf .kernel .font .PdfFont ;
34
34
import com .itextpdf .kernel .font .PdfFontFactory ;
35
35
import com .itextpdf .kernel .font .PdfFontFactory .EmbeddingStrategy ;
36
36
import com .itextpdf .kernel .pdf .PdfDocument ;
37
37
import com .itextpdf .layout .exceptions .LayoutExceptionMessageConstant ;
38
+ import com .itextpdf .layout .font .selectorstrategy .FirstMatchFontSelectorStrategy .FirstMathFontSelectorStrategyFactory ;
39
+ import com .itextpdf .layout .font .selectorstrategy .IFontSelectorStrategy ;
40
+ import com .itextpdf .layout .font .selectorstrategy .IFontSelectorStrategyFactory ;
38
41
39
42
import java .io .IOException ;
40
43
import java .util .ArrayList ;
@@ -53,7 +56,7 @@ This file is part of the iText (R) project.
53
56
* <p>
54
57
* It is allowed to use only one {@link FontProvider} per document. If additional fonts per element needed,
55
58
* another instance of {@link FontSet} can be used. For more details see {@link com.itextpdf.layout.properties.Property#FONT_SET},
56
- * {@link #getPdfFont(FontInfo, FontSet)}, {@link #getStrategy(String, List, FontCharacteristics, FontSet)}.
59
+ * {@link #getPdfFont(FontInfo, FontSet)}, {@link #createFontSelectorStrategy( List, FontCharacteristics, FontSet)}.
57
60
* <p>
58
61
* Note, FontProvider does not close created {@link FontProgram}s, because of possible conflicts with {@link FontCache}.
59
62
*/
@@ -69,6 +72,8 @@ public class FontProvider {
69
72
protected final String defaultFontFamily ;
70
73
protected final Map <FontInfo , PdfFont > pdfFonts ;
71
74
75
+ private IFontSelectorStrategyFactory fontSelectorStrategyFactory ;
76
+
72
77
/**
73
78
* Creates a new instance of FontProvider.
74
79
*
@@ -105,6 +110,7 @@ public FontProvider(FontSet fontSet, String defaultFontFamily) {
105
110
pdfFonts = new HashMap <>();
106
111
fontSelectorCache = new FontSelectorCache (this .fontSet );
107
112
this .defaultFontFamily = defaultFontFamily ;
113
+ this .fontSelectorStrategyFactory = new FirstMathFontSelectorStrategyFactory ();
108
114
}
109
115
110
116
/**
@@ -364,7 +370,9 @@ public boolean getDefaultEmbeddingFlag() {
364
370
* font selector strategy instance and will not be otherwise preserved in font provider.
365
371
*
366
372
* @return {@link FontSelectorStrategy} instance.
373
+ * @deprecated use {@link #createFontSelectorStrategy(List, FontCharacteristics, FontSet)}
367
374
*/
375
+ @ Deprecated
368
376
public FontSelectorStrategy getStrategy (String text , List <String > fontFamilies , FontCharacteristics fc , FontSet additionalFonts ) {
369
377
return new ComplexFontSelectorStrategy (text , getFontSelector (fontFamilies , fc , additionalFonts ), this , additionalFonts );
370
378
}
@@ -379,7 +387,9 @@ public FontSelectorStrategy getStrategy(String text, List<String> fontFamilies,
379
387
* @param fc instance of {@link FontCharacteristics} to create {@link FontSelector} for sequences of glyphs.
380
388
*
381
389
* @return {@link FontSelectorStrategy} instance.
390
+ * @deprecated use {@link #createFontSelectorStrategy(List, FontCharacteristics, FontSet)}
382
391
*/
392
+ @ Deprecated
383
393
public FontSelectorStrategy getStrategy (String text , List <String > fontFamilies , FontCharacteristics fc ) {
384
394
return getStrategy (text , fontFamilies , fc , null );
385
395
}
@@ -393,11 +403,44 @@ public FontSelectorStrategy getStrategy(String text, List<String> fontFamilies,
393
403
* @param fontFamilies target font families to create {@link FontSelector} for sequences of glyphs.
394
404
*
395
405
* @return {@link FontSelectorStrategy} instance.
406
+ * @deprecated use {@link #createFontSelectorStrategy(List, FontCharacteristics, FontSet)}
396
407
*/
408
+ @ Deprecated
397
409
public FontSelectorStrategy getStrategy (String text , List <String > fontFamilies ) {
398
410
return getStrategy (text , fontFamilies , null );
399
411
}
400
412
413
+ /**
414
+ * Sets factory which will be used in {@link #createFontSelectorStrategy(List, FontCharacteristics, FontSet)}
415
+ * method.
416
+ *
417
+ * @param factory the factory which will be used to create font selector strategies
418
+ */
419
+ public void setFontSelectorStrategyFactory (IFontSelectorStrategyFactory factory ) {
420
+ this .fontSelectorStrategyFactory = factory ;
421
+ }
422
+
423
+ /**
424
+ * Creates the {@link IFontSelectorStrategy} to split text into sequences of glyphs, already tied
425
+ * to the fonts which contain them. The fonts can be taken from the added fonts to the font provider and
426
+ * are chosen based on font-families list and desired font characteristics.
427
+ *
428
+ * @param fontFamilies target font families to create {@link FontSelector} for sequences of glyphs.
429
+ * @param fc instance of {@link FontCharacteristics} to create {@link FontSelector} for sequences of glyphs.
430
+ * @param additionalFonts set which provides fonts additionally to the fonts added to font provider.
431
+ * Combined set of font provider fonts and additional fonts is used when choosing
432
+ * a single font for a sequence of glyphs. Additional fonts will only be used for the given
433
+ * font selector strategy instance and will not be otherwise preserved in font provider.
434
+ *
435
+ * @return {@link IFontSelectorStrategy} instance
436
+ */
437
+ public IFontSelectorStrategy createFontSelectorStrategy (List <String > fontFamilies ,
438
+ FontCharacteristics fc , FontSet additionalFonts ) {
439
+
440
+ final FontSelector fontSelector = getFontSelector (fontFamilies , fc , additionalFonts );
441
+ return fontSelectorStrategyFactory .createFontSelectorStrategy (this , fontSelector , additionalFonts );
442
+ }
443
+
401
444
/**
402
445
* Create {@link FontSelector} or get from cache.
403
446
*
0 commit comments