Your suggestion was applied.
Paulo
----- Original Message -----
From: Hans Oesterholt-Dijkema
To: [email protected]
Sent: Sunday, August 29, 2010 8:54 AM
Subject: [iText-questions] FontMapper enhancement
L.S.,
The default font mapper of iText is not very efficient. It scans whole
directories for fonts, opens every font file for font parameters and fills the
names and aliases hashmaps.
I think it could be implemented more efficient if it allows for persisting
the font parameters associated with a path. However, one also wants to track
changes in the font directories. So I would propose the following change to the
DefaultFontMapper code:
*******************************************************************************
public void insertFile(File file) {
String name = file.getPath().toLowerCase();
try {
if (name.endsWith(".ttf") || name.endsWith(".otf") ||
name.endsWith(".afm")) {
Object allNames[] =
BaseFont.getAllFontNames(file.getPath(), BaseFont.CP1252, null);
insertNames(allNames, file.getPath());
++count;
}
else if (name.endsWith(".ttc")) {
String ttcs[] =
BaseFont.enumerateTTCNames(file.getPath());
for (int j = 0; j < ttcs.length; ++j) {
String nt = file.getPath() + "," + j;
Object allNames[] = BaseFont.getAllFontNames(nt,
BaseFont.CP1252, null);
insertNames(allNames, nt);
}
++count;
}
}
catch (Exception e) {
}
}
/** Inserts all the fonts recognized by iText in the
* <CODE>directory</CODE> into the map. The encoding
* will be <CODE>BaseFont.CP1252</CODE> but can be
* changed later.
* @param dir the directory to scan
* @return the number of files processed
*/
public int insertDirectory(String dir) {
File file = new File(dir);
if (!file.exists() || !file.isDirectory())
return 0;
File files[] = file.listFiles();
if (files == null)
return 0;
int count = 0;
for (int k = 0; k < files.length; ++k) {
insertFile(files[k]);
}
return count;
}
*******************************************************************************
This allows programmers to override 'insertNames()' and 'insertFile()' to
build
up a persistent fontmapper cache, while still be able to track changes in the
font directories.
Best regards,
Hans Oesterholt.
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/