You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ch...@apache.org on 2002/06/10 17:02:32 UTC

cvs commit: xml-fop/src/org/apache/fop/configuration FontInfo.java

chrisg      2002/06/10 08:02:32

  Modified:    src/org/apache/fop/configuration Tag: fop-0_20_2-maintain
                        FontInfo.java
  Log:
  BaseDir property is now used for loading custom fonts (Bug #7608)
  (thanks to Arnd Beissner and Brian O'Kelley)
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +62 -5     xml-fop/src/org/apache/fop/configuration/FontInfo.java
  
  Index: FontInfo.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/configuration/FontInfo.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- FontInfo.java	30 Jul 2001 20:29:19 -0000	1.2
  +++ FontInfo.java	10 Jun 2002 15:02:32 -0000	1.2.2.1
  @@ -1,5 +1,5 @@
   /*
  - * $Id: FontInfo.java,v 1.2 2001/07/30 20:29:19 tore Exp $
  + * $Id: FontInfo.java,v 1.2.2.1 2002/06/10 15:02:32 chrisg Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -8,16 +8,25 @@
   
   package org.apache.fop.configuration;
   
  +// Java
  +import java.io.File;
  +import java.net.URL;
  +import java.net.MalformedURLException;
   import java.util.Vector;
   
  +// Fop
  +import org.apache.fop.apps.FOPException;
  +
   /**
    * FontInfo contains meta information on fonts (where is the metrics file etc.)
    */
   
   public class FontInfo {
  +
       private String metricsFile, embedFile, name;
       private boolean kerning;
       private Vector fontTriplets;
  +    private String baseDir;
   
       public FontInfo(String name, String metricsFile, boolean kerning,
                       Vector fontTriplets, String embedFile) {
  @@ -28,12 +37,38 @@
           this.fontTriplets = fontTriplets;
       }
   
  -    public String getMetricsFile() {
  -        return metricsFile;
  +    /**
  +     * @return the (absolute) file name of the metrics file
  +     */
  +    public String getMetricsFile() throws FOPException {
  +        // check if it's a URL and convert it to a filename
  +        try {
  +            metricsFile = new URL(metricsFile).getFile();
  +        } catch (MalformedURLException mue) {}
  +
  +        // check if filename is absolute
  +        if ((new File(metricsFile).isAbsolute())) {
  +            return metricsFile;
  +        } else {
  +            return getBaseDir() + metricsFile;
  +        }
       }
   
  -    public String getEmbedFile() {
  -        return embedFile;
  +    /**
  +     * @return the (absolute) file name of the font
  +     */
  +    public String getEmbedFile() throws FOPException {
  +        // check if it's a URL and convert it to a filename
  +        try {
  +            embedFile = new URL(embedFile).getFile();
  +        } catch (MalformedURLException mue) {}
  +        
  +        // check if filename is absolute
  +        if ((new File(embedFile).isAbsolute())) {
  +            return embedFile;
  +        } else {
  +            return getBaseDir() + embedFile;
  +        }
       }
   
       public boolean getKerning() {
  @@ -43,6 +78,28 @@
       public Vector getFontTriplets() {
           return fontTriplets;
       }
  +
  +    /**
  +     * @return BaseDir (path)
  +     */
  +    private String getBaseDir() throws FOPException {
  +        baseDir = Configuration.getStringValue("baseDir");
  +        URL baseURL = null;
  +        try {
  +            baseURL = new URL(baseDir);
  +        } catch (MalformedURLException mue) {
  +            // if the href contains only a path then file is assumed
  +            try {
  +                baseURL = new URL("file:" + baseDir);
  +            } catch (MalformedURLException mue2) {
  +                throw new FOPException("Error with baseDir: "
  +                                             + mue2.getMessage());
  +            }
  +        }
  +        baseDir = baseURL.getFile();
  +        return baseDir;
  +    }
  +
   
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org