File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed
itext.tests/itext.io.tests/itext/io/font
itext/itext.io/itext/io/font Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using iText . IO . Font . Otf ;
3
+ using iText . Test ;
4
+
5
+ namespace iText . IO . Font {
6
+ public class FontCacheTest : ExtendedITextTest {
7
+ [ NUnit . Framework . Test ]
8
+ public virtual void ClearFontCacheTest ( ) {
9
+ String fontName = "FreeSans.ttf" ;
10
+ NUnit . Framework . Assert . IsNull ( FontCache . GetFont ( fontName ) ) ;
11
+ FontProgram fontProgram = new FontCacheTest . FontProgramMock ( ) ;
12
+ FontCache . SaveFont ( fontProgram , fontName ) ;
13
+ NUnit . Framework . Assert . AreEqual ( fontProgram , FontCache . GetFont ( fontName ) ) ;
14
+ FontCache . ClearSavedFonts ( ) ;
15
+ NUnit . Framework . Assert . IsNull ( FontCache . GetFont ( fontName ) ) ;
16
+ }
17
+
18
+ private class FontProgramMock : FontProgram {
19
+ public override int GetPdfFontFlags ( ) {
20
+ return 0 ;
21
+ }
22
+
23
+ public override int GetKerning ( Glyph first , Glyph second ) {
24
+ return 0 ;
25
+ }
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -150,6 +150,22 @@ public static CMapCidByte GetCid2Byte(String cmap) {
150
150
return ParseCmap ( cmap , cidByte ) ;
151
151
}
152
152
153
+ /// <summary>
154
+ /// Clears the cache by removing fonts that were added via
155
+ /// <see cref="SaveFont(FontProgram, System.String)"/>
156
+ /// .
157
+ /// <para />
158
+ /// Be aware that in multithreading environment this method call will affect the result of
159
+ /// <see cref="GetFont(System.String)"/>
160
+ /// .
161
+ /// This in its turn affects creation of fonts via factories when
162
+ /// <c>cached</c>
163
+ /// argument is set to true (which is by default).
164
+ /// </summary>
165
+ public static void ClearSavedFonts ( ) {
166
+ fontCache . Clear ( ) ;
167
+ }
168
+
153
169
public static FontProgram GetFont ( String fontName ) {
154
170
return fontCache . Get ( FontCacheKey . Create ( fontName ) ) ;
155
171
}
Original file line number Diff line number Diff line change 1
- 3b0d07f7b864be476b654b2344f46cf01fd20131
1
+ c2b2e7f65cb8c55d184420181403551267812a16
You can’t perform that action at this time.
0 commit comments