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
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
 
 

> -----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?
> 
> On 05/02/11 01:15, 1T3XT BVBA wrote:
> > Op 1/05/2011 19:28, Larry Evans schreef:
> >> Did an `svn update` then `ant execute` which got much 
> fewer errors, 
> >> but still got some suggesting a windows path expression (using c:) 
> >> instaad of something more generic was used:
> > That's documented on p374.
> > 
> > The rationale is that we make it easy for Windows users to run the 
> > code, whereas Linux users are smart enough to fix this problem.
> > 
> > Using the c:/windows/fonts/ path is the "simple" solution.
> > The generic solution is explained from section 11.4.1 on (p374).
> > 
> Thanks for the reference.  However, the suggestion on that 
> page to look at:
> 
>   /usr/share/X11/fonts/
> 
> doesn't work for ubuntu, which I gather is typical for linux 
> distributions which sometimes (maybe often) don't have a 
> 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.  Wouldn't providing a constant string, 
> somewhere, for the directory where the fonts are located make 
> the code more portable?  I mean something like the:
> 
>    public static final String RESULT =
> "results/part1/chapter02/director_phrases_2.pdf";
> 
> only it would be:
> 
>   public static final String FONTSDIR
>     = "c:/windows/fonts/";
> 
> for windows, and:
> 
>   public static final String FONTSDIR
>     = "/usr/share/fonts/truetype/msttcorefonts/";
> 
> for ubuntu, and, as suggested on p. 374:
> 
>   public static final String FONTSDIR
>     = "/Library/fonts/";
> 
> for Mac.  Also, this os specific code could be documented in 
> maybe a README.protability.txt file or something like that.  
> It would be nice if the `mv clean install` command could make 
> this change automagically.  Software oackages made with make 
> usually have a configure script which is initially run before 
> make to handle this sort of os specific problems.
> Is it possible for mvn to do something similar?
> 
> -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
> 
> 

------------------------------------------------------------------------------
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

Reply via email to