Fonts 在iText 7中,如何知道字体中是否存在特定字符?
在iText 7中,如何知道字体中是否存在特定字符 在iText 5中,我使用了以下代码Fonts 在iText 7中,如何知道字体中是否存在特定字符?,fonts,character,itext7,Fonts,Character,Itext7,在iText 7中,如何知道字体中是否存在特定字符 在iText 5中,我使用了以下代码 Font font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); BaseFont baseFont = font.getBaseFont(); boolean isExist = baseFont.charExists(ch); 这在iText 7中可能吗?我不确定它是否适用于任何字体,因为我还没有对它们
Font font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
BaseFont baseFont = font.getBaseFont();
boolean isExist = baseFont.charExists(ch);
这在iText 7中可能吗?我不确定它是否适用于任何字体,因为我还没有对它们进行全部测试,但我的第一次尝试是在Pdfont中使用以下方法:
如果字体不包含此Unicode代码点的标志符号,则此方法应返回null。我不确定它是否适用于任何字体,因为我尚未对它们进行全部测试,但我的第一次尝试是在Pdfont中使用以下方法: 如果字体不包含此Unicode代码点的标志符号,则此方法应返回null。当然
File windowsFontDir = new File("C:\\Windows\\Fonts");
for(File fontFile : windowsFontDir.listFiles()) {
try {
PdfFont font = PdfFontFactory.createFont(fontFile.getAbsolutePath());
if(font.containsGlyph((int) 'a'))
{
System.out.println("Font " + fontFile.getName() + " has the required glyph.");
}else
{
System.out.println("Font " + fontFile.getName() + " does NOT have the required glyph.");
}
}catch(Exception ex){}
}
这会打印出如下内容:
Font AGENCYB.TTF具有所需的标志符号。
Font AGENCYR.TTF具有所需的标志符号。
Font ALGER.TTF具有所需的标志符号。
字体ANTQUAB.TTF具有所需的标志符号。
当然
File windowsFontDir = new File("C:\\Windows\\Fonts");
for(File fontFile : windowsFontDir.listFiles()) {
try {
PdfFont font = PdfFontFactory.createFont(fontFile.getAbsolutePath());
if(font.containsGlyph((int) 'a'))
{
System.out.println("Font " + fontFile.getName() + " has the required glyph.");
}else
{
System.out.println("Font " + fontFile.getName() + " does NOT have the required glyph.");
}
}catch(Exception ex){}
}
这会打印出如下内容:
Font AGENCYB.TTF具有所需的标志符号。
Font AGENCYR.TTF具有所需的标志符号。
Font ALGER.TTF具有所需的标志符号。
字体ANTQUAB.TTF具有所需的标志符号。
@Joris建议的containsGlyph调用getGlyph并在返回Glyph实例时进行额外测试@Joris建议的containsGlyph调用getGlyph并在返回Glyph实例时进行额外测试非常感谢,Joris。这很有帮助。那么,这是公认的答案吗?提示…:谢谢你,乔里斯。这很有帮助。那么,这是公认的答案吗?提示…:D