On 05/02/11 11:47, Mark Storer wrote:
> This is what FontFactory.registerDirectories() is for.
> RegisterDirectories calls FontFactory.registerDirectory() on a wide
> variety of commonly used font paths:
>
> public int registerDirectories() {
> int count = 0;
> String windir = System.getenv("windir");
> String fileseparator = System.getProperty("file.separator");
> if (windir != null && fileseparator != null) {
> count += registerDirectory(windir + fileseparator +
> "fonts");
> }
> count += registerDirectory("/usr/share/X11/fonts", true);
> count += registerDirectory("/usr/X/lib/X11/fonts", true);
> count += registerDirectory("/usr/openwin/lib/X11/fonts", true);
> count += registerDirectory("/usr/share/fonts", true);
> count += registerDirectory("/usr/X11R6/lib/X11/fonts", true);
> count += registerDirectory("/Library/Fonts");
> count += registerDirectory("/System/Library/Fonts");
> return count;
> }
>
> The "true" param tells registerDirectory to scan all subdirectories, so
> it would find "/usr/share/fonts/truetype/msttcorefonts".
>
> The only problem with registerDirectories is that it takes time directly
> proportionate to the number and size of the fonts on your system to
> execute. If you're relaunching the app that uses iText on a regular
> basis rather than loading it once, registerDirectories can consume the
> majority of your execution time.
>
> YMMV.
>
> Looking at the above code, you could add a "windir" environment variable
> to just about any system with a "/fonts" folder and be Good To Go. We
> might want to consider a more general enviromental variable for this
> very occasion, or perhaps a specific list of fonts.
>
> --Mark Storer
> Senior Software Engineer
> Cardiff.com
Thanks Mark.
IIUC, then instead of the change I made, I could have make this change
(to book/src/part1/chapter02/DirectorPhrases2.java):
timesbd = FontFactory.getFont("timesbd");
times = FontFactory.getFont("times");
Is that right?
[snip]
>> -----Original Message-----
>> From: Larry Evans [mailto:[email protected]]
>> Sent: Monday, May 02, 2011 7:42 AM
>> To: [email protected]
>> Subject: [iText-questions] Portability of BaseFont.createFont
>> (was Re:Purpose of book/{build, examples}.xml?
[snip]
>> standard place to put things. Anyway, I found the fonts here:
>>
>> /usr/share/fonts/truetype/msttcorefonts
>>
>> I changed:
>>
>> book/src/part1/chapter02/DirectorPhrases2.java
>>
>> by substituting:
>>
>> /usr/share/fonts/truetype/msttcorefonts
>>
>> for:
>>
>> c:/windows/fonts/
>>
>> in the 2 statements:
>> timesbd = BaseFont.createFont(
>> "c:/windows/fonts/timesbd.ttf",
>> BaseFont.WINANSI, BaseFont.EMBEDDED);
>> times = BaseFont.createFont(
>> "c:/windows/fonts/times.ttf",
>> BaseFont.WINANSI, BaseFont.EMBEDDED);
>>
>> and that .java file now compiles without problem; however, I
>> will have to make similar changes to all files that have
>> similar errors.
[snip]
Now, the only reason I can think of why the path to the
font file was hardcoded instead of using FontFactory.getFont
is to save the time you mentioned here:
> The only problem with registerDirectories is that it takes time
> directly proportionate to the number and size of the fonts on
> your system to execute.
-regards,
Larry
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php