Index: test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
===================================================================
--- test/java/org/apache/fop/layoutengine/LayoutEngineTester.java	(révision 356368)
+++ test/java/org/apache/fop/layoutengine/LayoutEngineTester.java	(copie de travail)
@@ -125,6 +125,8 @@
             //Setup FOP for area tree rendering
             FOUserAgent ua = new FOUserAgent();
             ua.setBaseURL(testFile.getParentFile().toURL().toString());
+            File fontCfgFile = new File("conf/fonts.xconf");
+            ua.setFontCfgURL(fontCfgFile.toURL());
             XMLRenderer atrenderer = new XMLRenderer();
             atrenderer.setUserAgent(ua);
             atrenderer.setTransformerHandler(athandler);
Index: test/java/org/apache/fop/threading/FOProcessorImpl.java
===================================================================
--- test/java/org/apache/fop/threading/FOProcessorImpl.java	(révision 356368)
+++ test/java/org/apache/fop/threading/FOProcessorImpl.java	(copie de travail)
@@ -18,6 +18,7 @@
 
 package org.apache.fop.threading;
 
+import java.io.File;
 import java.io.InputStream;
 import java.io.OutputStream;
 
@@ -35,6 +36,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.MimeConstants;
@@ -84,7 +86,10 @@
 
     public void process(InputStream in, Templates templates, OutputStream out) 
                 throws org.apache.fop.apps.FOPException, java.io.IOException {
-        Fop fop = new Fop(MimeConstants.MIME_PDF);
+        FOUserAgent ua = new FOUserAgent();
+        File fontCfgFile = new File(baseDir, "conf/fonts.xconf");
+        ua.setFontCfgURL(fontCfgFile.toURL());
+        Fop fop = new Fop(MimeConstants.MIME_PDF, ua);
         fop.setOutputStream(out);
 
         try {
Index: test/java/org/apache/fop/BasicDriverTestCase.java
===================================================================
--- test/java/org/apache/fop/BasicDriverTestCase.java	(révision 356368)
+++ test/java/org/apache/fop/BasicDriverTestCase.java	(copie de travail)
@@ -28,6 +28,7 @@
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.cli.InputHandler;
@@ -52,7 +53,10 @@
     public void testFO2PDFWithJAXP() throws Exception {
         File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
-        Fop fop = new Fop(MimeConstants.MIME_PDF);
+        FOUserAgent ua = new FOUserAgent();
+        File fontCfgFile = new File(getBaseDir(), "conf/fonts.xconf");
+        ua.setFontCfgURL(fontCfgFile.toURL());
+        Fop fop = new Fop(MimeConstants.MIME_PDF, ua);
         fop.setOutputStream(baout);
         
         TransformerFactory factory = TransformerFactory.newInstance();
@@ -71,7 +75,10 @@
     public void testFO2PSWithJAXP() throws Exception {
         File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
-        Fop fop = new Fop(MimeConstants.MIME_POSTSCRIPT);
+        FOUserAgent ua = new FOUserAgent();
+        File fontCfgFile = new File(getBaseDir(), "conf/fonts.xconf");
+        ua.setFontCfgURL(fontCfgFile.toURL());
+        Fop fop = new Fop(MimeConstants.MIME_POSTSCRIPT, ua);
         fop.setOutputStream(baout);
         
         TransformerFactory factory = TransformerFactory.newInstance();
@@ -90,7 +97,10 @@
     public void testFO2RTFWithJAXP() throws Exception {
         File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
-        Fop fop = new Fop(MimeConstants.MIME_RTF);
+        FOUserAgent ua = new FOUserAgent();
+        File fontCfgFile = new File(getBaseDir(), "conf/fonts.xconf");
+        ua.setFontCfgURL(fontCfgFile.toURL());
+        Fop fop = new Fop(MimeConstants.MIME_RTF, ua);
         fop.setOutputStream(baout);
         
         TransformerFactory factory = TransformerFactory.newInstance();
@@ -110,7 +120,10 @@
         File xmlFile = new File(getBaseDir(), "test/xml/1.xml");
         File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
-        Fop fop = new Fop(MimeConstants.MIME_PDF);
+        FOUserAgent ua = new FOUserAgent();
+        File fontCfgFile = new File(getBaseDir(), "conf/fonts.xconf");
+        ua.setFontCfgURL(fontCfgFile.toURL());
+        Fop fop = new Fop(MimeConstants.MIME_PDF, ua);
         fop.setOutputStream(baout);
         
         InputHandler handler = new InputHandler(xmlFile, xsltFile, null);
Index: conf/fop.xconf
===================================================================
--- conf/fop.xconf	(révision 356368)
+++ conf/fop.xconf	(copie de travail)
@@ -16,6 +16,9 @@
 
   <!-- Base URL for resolving relative URLs -->
   <base>.</base>
+  <!-- URL for the font-configuration file. If relative, then it is set
+  relative to the base URL -->
+  <font-config-file>/path/to/Fop/conf/fonts.xconf</font-config-file>
   <!-- Internal resolution in dpi (dots/pixels per inch), default: 72dpi -->
   <resolution>72</resolution>
   <!-- Default page-height and page-width, in case
Index: src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
===================================================================
--- src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java	(copie de travail)
@@ -35,10 +35,11 @@
 import org.apache.fop.area.inline.Viewport;
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Typeface;
 import org.apache.fop.image.FopImage;
 import org.apache.fop.traits.BorderProps;
 
+import org.axsl.font.FontUse;
+
 /**
  * Abstract base class for renderers like PDF and PostScript where many painting operations
  * follow similar patterns which makes it possible to share some code.
@@ -593,21 +594,21 @@
     
     /**
      * Paints the text decoration marks.
-     * @param tf Current typeface
-     * @param fontsize Current font size
+     * @param fu current font use
+     * @param fontsize current font size
      * @param inline inline area to paint the marks for
      * @param baseline position of the baseline
      * @param startx start IPD
      */
-    protected void renderTextDecoration(Typeface tf, int fontsize, InlineArea inline, 
+    protected void renderTextDecoration(FontUse fu, int fontsize, InlineArea inline, 
                     int baseline, int startx) {
         boolean hasTextDeco = inline.hasUnderline() 
                 || inline.hasOverline() 
                 || inline.hasLineThrough();
         if (hasTextDeco) {
             endTextObject();
-            float descender = tf.getDescender(fontsize) / 1000f;
-            float capHeight = tf.getCapHeight(fontsize) / 1000f;
+            float descender = fu.getFont().getDescender(fontsize) / 1000f;
+            float capHeight = fu.getFont().getCapHeight(fontsize) / 1000f;
             float halfLineWidth = (descender / -8f) / 2f;
             float endx = (startx + inline.getIPD()) / 1000f;
             if (inline.hasUnderline()) {
Index: src/java/org/apache/fop/render/ps/PSSVGHandler.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSSVGHandler.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/PSSVGHandler.java	(copie de travail)
@@ -36,7 +36,6 @@
 import org.apache.batik.gvt.GraphicsNode;
 
 // FOP
-import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.XMLHandler;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.svg.SVGUserAgent;
@@ -44,6 +43,7 @@
 // Commons-Logging
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.axsl.font.FontConsumer;
 
 /**
  * PostScript XML handler for SVG. Uses Apache Batik for SVG processing.
@@ -69,7 +69,7 @@
     /**
      * The font information for the PostScript renderer.
      */
-    public static final String PS_FONT_INFO = "psFontInfo";
+    public static final String PS_FONT_CONSUMER = "psFontConsumer";
 
     /**
      * The width of the SVG graphic.
@@ -119,7 +119,7 @@
     public static PSInfo getPSInfo(RendererContext context) {
         PSInfo psi = new PSInfo();
         psi.psGenerator = (PSGenerator)context.getProperty(PS_GENERATOR);
-        psi.fontInfo = (org.apache.fop.fonts.FontInfo) context.getProperty(PS_FONT_INFO);
+        psi.fontConsumer = (FontConsumer) context.getProperty(PS_FONT_CONSUMER);
         psi.width = ((Integer)context.getProperty(PS_WIDTH)).intValue();
         psi.height = ((Integer)context.getProperty(PS_HEIGHT)).intValue();
         psi.currentXPosition = ((Integer)context.getProperty(PS_XPOS)).intValue();
@@ -134,8 +134,8 @@
 
         /** see PS_GENERATOR */
         private PSGenerator psGenerator;
-        /** see PS_FONT_INFO */
-        private org.apache.fop.fonts.FontInfo fontInfo;
+        /** see PS_FONT_CONSUMER */
+        private FontConsumer fontConsumer;
         /** see PS_PAGE_WIDTH */
         private int width;
         /** see PS_PAGE_HEIGHT */
@@ -161,19 +161,19 @@
         }
 
         /**
-         * Returns the fontInfo.
-         * @return FontInfo
+         * Returns the font consumer.
+         * @return the font consumer
          */
-        public FontInfo getFontInfo() {
-            return fontInfo;
+        public FontConsumer getFontConsumer() {
+            return fontConsumer;
         }
 
         /**
-         * Sets the fontInfo.
-         * @param fontInfo The fontInfo to set
+         * Sets the font consumer.
+         * @param fontConsumer The font consumer to set
          */
-        public void setFontInfo(FontInfo fontInfo) {
-            this.fontInfo = fontInfo;
+        public void setFontConsumer(FontConsumer fontConsumer) {
+            this.fontConsumer = fontConsumer;
         }
 
         /**
@@ -266,7 +266,7 @@
 
             GVTBuilder builder = new GVTBuilder();
             BridgeContext ctx = new BridgeContext(ua);
-            PSTextPainter textPainter = new PSTextPainter(psInfo.getFontInfo());
+            PSTextPainter textPainter = new PSTextPainter(psInfo.getFontConsumer());
             ctx.setTextPainter(textPainter);            
             PSTextElementBridge tBridge = new PSTextElementBridge(textPainter);
             ctx.putBridge(tBridge);
Index: src/java/org/apache/fop/render/ps/PSTranscoder.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSTranscoder.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/PSTranscoder.java	(copie de travail)
@@ -57,7 +57,7 @@
     }
 
     protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
-        return new PSDocumentGraphics2D(false);
+        return new PSDocumentGraphics2D(false, getFontMap());
     }
 
 }
Index: src/java/org/apache/fop/render/ps/PSRenderer.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSRenderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/PSRenderer.java	(copie de travail)
@@ -54,17 +54,18 @@
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.Typeface;
 import org.apache.fop.image.EPSImage;
 import org.apache.fop.image.FopImage;
 import org.apache.fop.image.ImageFactory;
 import org.apache.fop.image.XMLImage;
+import org.apache.fop.pdf.FontMap;
 import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.AbstractPathOrientedRenderer;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.ps.extensions.PSSetupCode;
 import org.apache.fop.util.CharUtilities;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
 
 import org.w3c.dom.Document;
 
@@ -104,6 +105,8 @@
 
     private boolean inTextMode = false;
     private boolean firstPageSequenceReceived = false;
+    
+    private FontMap fontMap;
 
     /** Used to temporarily store PSSetupCode instance until they can be written. */
     private List setupCodeList;
@@ -111,20 +114,19 @@
     /** This is a map of PSResource instances of all fonts defined (key: font key) */
     private Map fontResources;
     
+    /** Set up the font consumer.
+     * @param fontConsumer the font consumer.
+     */
+    public void setupFontConsumer(FontConsumer fontConsumer) {
+        super.setupFontConsumer(fontConsumer);
+        fontMap = new FontMap(fontConsumer, true);
+    }
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
      */
     public void configure(Configuration cfg) throws ConfigurationException {
         super.configure(cfg);
         this.autoRotateLandscape = cfg.getChild("auto-rotate-landscape").getValueAsBoolean(false);
-
-        //Font configuration
-        List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
-        if (this.fontList == null) {
-            this.fontList = cfgFonts;
-        } else {
-            this.fontList.addAll(cfgFonts);
-        }
     }
 
     /**
@@ -359,12 +361,12 @@
 
     /**
      * Changes the currently used font.
-     * @param name name of the font
+     * @param fontUse the new font use
      * @param size font size
      */
-    public void useFont(String name, int size) {
+    public void useFont(FontUse fontUse, int size) {
         try {
-            gen.useFont(name, size / 1000f);
+            gen.useFont(fontMap.getInternalName(fontUse), size / 1000f);
         } catch (IOException ioe) {
             handleIOTrouble(ioe);
         }
@@ -584,12 +586,10 @@
      */
     public void stopRenderer() throws IOException {
         //Notify resource usage for font which are not supplied
-        Map fonts = fontInfo.getUsedFonts();
-        Iterator e = fonts.keySet().iterator();
-        while (e.hasNext()) {
-            String key = (String)e.next();
-            //Typeface font = (Typeface)fonts.get(key);
-            PSResource res = (PSResource)this.fontResources.get(key);
+        FontUse[] fontUses = fontConsumer.getFontServer().getUsedFontUses(fontConsumer);
+        for (int i = 0; i < fontUses.length; i++) {
+            PSResource res = (PSResource)this.fontResources.get(
+                    fontMap.getInternalName(fontUses[i]));
             boolean supplied = gen.isResourceSupplied(res);
             if (!supplied) {
                 gen.notifyResourceUsage(res, true);
@@ -635,7 +635,7 @@
                 //Setup
                 gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
                 writeSetupCodeList(setupCodeList, "SetupCode");
-                this.fontResources = PSFontUtils.writeFontDict(gen, fontInfo);
+                this.fontResources = PSFontUtils.writeFontDict(gen, fontMap);
                 gen.writeln("FOPFonts begin");
                 gen.writeDSCComment(DSCConstants.END_SETUP);
             } catch (IOException ioe) {
@@ -810,17 +810,17 @@
     
     private void renderText(AbstractTextArea area, String text) {
         renderInlineAreaBackAndBorders(area);
-        String fontname = (String)area.getTrait(Trait.FONT_NAME);
+        FontUse fontUse = (FontUse)area.getTrait(Trait.FONT);
         int fontsize = area.getTraitAsInteger(Trait.FONT_SIZE);
 
         // This assumes that *all* CIDFonts use a /ToUnicode mapping
-        Typeface tf = (Typeface) fontInfo.getFonts().get(fontname);
+//        Typeface tf = (Typeface) fontInfo.getFonts().get(fontname);
 
         //Determine position
         int rx = currentIPPosition + area.getBorderAndPaddingWidthStart();
         int bl = currentBPPosition + area.getOffset() + area.getBaselineOffset();
 
-        useFont(fontname, fontsize);
+        useFont(fontUse, fontsize);
         ColorType ct = (ColorType)area.getTrait(Trait.COLOR);
         if (ct != null) {
             try {
@@ -831,13 +831,14 @@
         }
         
         boolean kerningAvailable = false;
-        Map kerning = tf.getKerningInfo();
-        if (kerning != null && !kerning.isEmpty()) {
-            //kerningAvailable = true;
-            //TODO Fix me when kerning is supported by the layout engine
-            log.warn("Kerning info is available, but kerning is not yet implemented for"
-                    + " the PS renderer and not currently supported by the layout engine.");
-        }
+        // TODO vh: kerning is available differently from FOrayFont
+//        Map kerning = tf.getKerningInfo();
+//        if (kerning != null && !kerning.isEmpty()) {
+//            //kerningAvailable = true;
+//            //TODO Fix me when kerning is supported by the layout engine
+//            log.warn("Kerning info is available, but kerning is not yet implemented for"
+//                    + " the PS renderer and not currently supported by the layout engine.");
+//        }
         
         beginTextObject();
         writeln("1 0 0 -1 " + gen.formatDouble(rx / 1000f) 
@@ -851,7 +852,7 @@
             sb.append("(");
             for (int i = 0; i < textLen; i++) {
                 final char c = text.charAt(i);
-                final char mapped = tf.mapChar(c);
+                final char mapped = fontUse.encodeCharacter(fontConsumer, c);
                 PSGenerator.escapeChar(mapped, sb);
             }
             sb.append(") t");
@@ -860,7 +861,7 @@
             int[] offsets = new int[textLen];
             for (int i = 0; i < textLen; i++) {
                 final char c = text.charAt(i);
-                final char mapped = tf.mapChar(c);
+                final char mapped = fontUse.encodeCharacter(fontConsumer, c);
                 int wordSpace;
                 //TODO Synchronize word space behaviour with TextLayoutManager
                 //Check the other renderers, too!
@@ -871,7 +872,7 @@
                 } else {
                     wordSpace = 0;
                 }
-                int cw = tf.getWidth(mapped, fontsize) / 1000;
+                int cw = fontUse.getFont().width(c, fontsize) / 1000;
                 offsets[i] = cw + area.getTextLetterSpaceAdjust() + wordSpace;
                 PSGenerator.escapeChar(mapped, sb);
             }
@@ -890,7 +891,7 @@
         }
         writeln(sb.toString());
 
-        renderTextDecoration(tf, fontsize, area, bl, rx);
+        renderTextDecoration(fontUse, fontsize, area, bl, rx);
     }
 
     /** @see org.apache.fop.render.AbstractPathOrientedRenderer#breakOutOfStateStack() */
@@ -1068,7 +1069,7 @@
         context.setUserAgent(userAgent);
 
         context.setProperty(PSSVGHandler.PS_GENERATOR, this.gen);
-        context.setProperty(PSSVGHandler.PS_FONT_INFO, fontInfo);
+        context.setProperty(PSSVGHandler.PS_FONT_CONSUMER, fontConsumer);
         context.setProperty(PSSVGHandler.PS_WIDTH,
                             new Integer((int) pos.getWidth()));
         context.setProperty(PSSVGHandler.PS_HEIGHT,
Index: src/java/org/apache/fop/render/ps/PSTextPainter.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSTextPainter.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/PSTextPainter.java	(copie de travail)
@@ -45,9 +45,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontUse;
 
 /**
  * Renders the attributed character iterator of a <tt>TextNode</tt>.
@@ -68,7 +69,7 @@
     /** the logger for this class */
     protected Log log = LogFactory.getLog(PSTextPainter.class);
     
-    private FontInfo fontInfo;
+    private FontConsumer fontConsumer;
 
     /**
      * Use the stroking text painter to get the bounds and shape.
@@ -79,10 +80,10 @@
 
     /**
      * Create a new PS text painter with the given font information.
-     * @param fontInfo the FontInfo object
+     * @param fontConsumer the font consumer
      */
-    public PSTextPainter(FontInfo fontInfo) {
-        this.fontInfo = fontInfo;
+    public PSTextPainter(FontConsumer fontConsumer) {
+        this.fontConsumer = fontConsumer;
     }
 
     /**
@@ -121,7 +122,8 @@
         boolean hasunsupported = false;
         
         String text = getText(aci);
-        Font font = makeFont(aci);
+        Float size = (Float)aci.getAttribute(TextAttribute.SIZE);
+        FontUse font = makeFont(aci, (size == null) ? 10000 : size.intValue() * 1000);
         if (hasUnsupportedGlyphs(text, font)) {
             log.trace("-> Unsupported glyphs found");
             hasunsupported = true;
@@ -272,10 +274,12 @@
         Paint strokePaint = tpi.strokePaint;
         Stroke stroke = tpi.strokeStroke;
 
-        Float fontSize = (Float)aci.getAttribute(TextAttribute.SIZE);
-        if (fontSize == null) {
+        Float size = (Float)aci.getAttribute(TextAttribute.SIZE);
+        if (size == null) {
             return loc;
         }
+        int fontSize = (size == null) ? 10000 : size.intValue() * 1000;
+        
         Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE);
         Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
 
@@ -286,13 +290,13 @@
         g2d.setPaint(foreground);
         g2d.setStroke(stroke);
 
-        Font font = makeFont(aci);
-        java.awt.Font awtFont = makeAWTFont(aci, font);
+        FontUse fontUse = makeFont(aci, fontSize);
+        java.awt.Font awtFont = makeAWTFont(aci, fontUse, fontSize / 1000);
 
         g2d.setFont(awtFont);
 
         String txt = getText(aci);
-        float advance = getStringWidth(txt, font);
+        float advance = fontUse.getFont().width(txt, fontSize, 0, 0) / 1000f;
         float tx = 0;
         if (anchor != null) {
             switch (anchor.getType()) {
@@ -308,13 +312,15 @@
         
         //Finally draw text
         if (g2d instanceof PSGraphics2D) {
-            ((PSGraphics2D) g2d).setOverrideFont(font);
+            ((PSGraphics2D) g2d).setOverrideFont(fontUse);
+            ((PSGraphics2D) g2d).setOverrideFontSize(fontSize);
         }
         try {
             g2d.drawString(txt, (float)(loc.getX() + tx), (float)(loc.getY()));
         } finally {
             if (g2d instanceof PSGraphics2D) {
                 ((PSGraphics2D) g2d).setOverrideFont(null);
+                ((PSGraphics2D) g2d).setOverrideFontSize(fontSize);
             }
         }
         loc.setLocation(loc.getX() + (double)advance, loc.getY());
@@ -347,34 +353,37 @@
         } 
     }
 
-    private String getStyle(AttributedCharacterIterator aci) {
+    private byte getStyle(AttributedCharacterIterator aci) {
         Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE);
         return ((posture != null) && (posture.floatValue() > 0.0))
-                       ? "italic" 
-                       : "normal";
+                       ? Font.FONT_STYLE_ITALIC 
+                       : Font.FONT_STYLE_NORMAL;
     }
 
-    private int getWeight(AttributedCharacterIterator aci) {
+    private short getWeight(AttributedCharacterIterator aci) {
         Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
         return ((taWeight != null) &&  (taWeight.floatValue() > 1.0)) 
-                       ? Font.BOLD
-                       : Font.NORMAL;
+                       ? Font.FONT_WEIGHT_BOLD
+                       : Font.FONT_WEIGHT_NORMAL;
     }
 
-    private Font makeFont(AttributedCharacterIterator aci) {
-        Float fontSize = (Float)aci.getAttribute(TextAttribute.SIZE);
-        if (fontSize == null) {
-            fontSize = new Float(10.0f);
-        }
-        String style = getStyle(aci);
-        int weight = getWeight(aci);
+    /**
+     * Make a font suitable for the given aci.
+     * @param aci 
+     * @param fontSize font size in millipoints.
+     * @return a suitable font use.
+     */
+    private FontUse makeFont(AttributedCharacterIterator aci, int fontSize) {
+        byte style = getStyle(aci);
+        short weight = getWeight(aci);
 
-        boolean found = false;
-        String fontFamily = null;
+        FontUse font = null;
         List gvtFonts = (List) aci.getAttribute(
                       GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
         if (gvtFonts != null) {
             Iterator i = gvtFonts.iterator();
+            String[] fontFamilies = new String[gvtFonts.size()];
+            int index = 0;
             while (i.hasNext()) {
                 GVTFontFamily fam = (GVTFontFamily) i.next();
                 /* (todo) Enable SVG Font painting
@@ -382,63 +391,77 @@
                     PROXY_PAINTER.paint(node, g2d);
                     return;
                 }*/
-                fontFamily = fam.getFamilyName();
-                if (fontInfo.hasFont(fontFamily, style, weight)) {
-                    String fname = fontInfo.fontLookup(
-                            fontFamily, style, weight);
-                    FontMetrics metrics = fontInfo.getMetricsFor(fname);
-                    int fsize = (int)(fontSize.floatValue() * 1000);
-                    return new Font(fname, metrics, fsize);
-                }
+                fontFamilies[index++] = fam.getFamilyName();
             }
+            int currentPos = aci.getIndex();
+            try {
+                font = fontConsumer.getFontServer().
+                        selectFontXSL(fontConsumer, fontFamilies, style, weight,
+                        Font.FONT_VARIANT_NORMAL, Font.FONT_STRETCH_NORMAL,
+                        fontSize, aci.first());
+            } catch (FontException f) {
+                try {
+                    font = fontConsumer.getFontServer().
+                            selectFontXSL(fontConsumer, new String[] {"any"}, style,
+                                    Font.FONT_WEIGHT_ANY,
+                                    Font.FONT_VARIANT_ANY,
+                                    Font.FONT_STRETCH_ANY,
+                                    fontSize, aci.first());
+                } catch (FontException e) { /* Should never happen */ }
+            }
+            aci.setIndex(currentPos);
         }
-        String fname = fontInfo.fontLookup(
-                "any", style, Font.NORMAL);
-        FontMetrics metrics = fontInfo.getMetricsFor(fname);
-        int fsize = (int)(fontSize.floatValue() * 1000);
-        return new Font(fname, metrics, fsize);
+        return font;
     }
 
-    private java.awt.Font makeAWTFont(AttributedCharacterIterator aci, Font font) {
-        final String style = getStyle(aci);
-        final int weight = getWeight(aci);
+    /**
+     * Make an AWT font corresponding to the given font use.
+     * @param aci
+     * @param fontUse the font use.
+     * @param fontSize the font size in points.
+     * @return the corresponding AWT font.
+     */
+    private java.awt.Font makeAWTFont(AttributedCharacterIterator aci,
+                                      FontUse fontUse,
+                                      int fontSize) {
+        final byte style = getStyle(aci);
+        final short weight = getWeight(aci);
         int fStyle = java.awt.Font.PLAIN;
-        if (weight == Font.BOLD) {
+        if (weight == Font.FONT_WEIGHT_BOLD) {
             fStyle |= java.awt.Font.BOLD;
         }
-        if ("italic".equals(style)) {
+        if (style == Font.FONT_STYLE_ITALIC) {
             fStyle |= java.awt.Font.ITALIC;
         }
-        return new java.awt.Font(font.getFontName(), fStyle,
-                             (int)(font.getFontSize() / 1000));
+        return new java.awt.Font(fontUse.postscriptName(), fStyle, fontSize);
     }
 
-    private float getStringWidth(String str, Font font) {
-        float wordWidth = 0;
-        float whitespaceWidth = font.getWidth(font.mapChar(' '));
+//    private float getStringWidth(String str, Font font) {
+//        float wordWidth = 0;
+//        float whitespaceWidth = font.getWidth(font.mapChar(' '));
+//
+//        for (int i = 0; i < str.length(); i++) {
+//            float charWidth;
+//            char c = str.charAt(i);
+//            if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
+//                charWidth = font.getWidth(font.mapChar(c));
+//                if (charWidth <= 0) {
+//                    charWidth = whitespaceWidth;
+//                }
+//            } else {
+//                charWidth = whitespaceWidth;
+//            }
+//            wordWidth += charWidth;
+//        }
+//        return wordWidth / 1000f;
+//    }
 
+    private boolean hasUnsupportedGlyphs(String str, FontUse font) {
         for (int i = 0; i < str.length(); i++) {
             float charWidth;
             char c = str.charAt(i);
             if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
-                charWidth = font.getWidth(font.mapChar(c));
-                if (charWidth <= 0) {
-                    charWidth = whitespaceWidth;
-                }
-            } else {
-                charWidth = whitespaceWidth;
-            }
-            wordWidth += charWidth;
-        }
-        return wordWidth / 1000f;
-    }
-
-    private boolean hasUnsupportedGlyphs(String str, Font font) {
-        for (int i = 0; i < str.length(); i++) {
-            float charWidth;
-            char c = str.charAt(i);
-            if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
-                if (!font.hasChar(c)) {
+                if (!font.glyphAvailable(c)) {
                     return true;
                 }
             }
Index: src/java/org/apache/fop/render/ps/EPSTranscoder.java
===================================================================
--- src/java/org/apache/fop/render/ps/EPSTranscoder.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/EPSTranscoder.java	(copie de travail)
@@ -56,7 +56,7 @@
     }
 
     protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
-        return new EPSDocumentGraphics2D(false);
+        return new EPSDocumentGraphics2D(false, getFontMap());
     }
 
 }
Index: src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java
===================================================================
--- src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java	(copie de travail)
@@ -25,9 +25,7 @@
 import java.io.OutputStream;
 import java.io.IOException;
 
-//FOP
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontSetup;
+import org.apache.fop.pdf.FontMap;
 
 /**
  * This class is a wrapper for the <tt>PSGraphics2D</tt> that
@@ -53,6 +51,9 @@
 
     protected Shape initialClip;
     protected AffineTransform initialTransform;
+    
+    /** The mappings of FontUses to their associated internal names. */
+    protected FontMap fontMap;
 
     
     /**
@@ -66,12 +67,11 @@
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
      */
-    AbstractPSDocumentGraphics2D(boolean textAsShapes) {
+    AbstractPSDocumentGraphics2D(boolean textAsShapes, FontMap fontMap) {
         super(textAsShapes);
 
         if (!textAsShapes) {
-            fontInfo = new FontInfo();
-            FontSetup.setup(fontInfo, null);
+            this.fontMap = fontMap;
         }
     }
 
@@ -105,15 +105,16 @@
      *
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
+     * @param fontMap the mappings of FontUses to their associated internal names
      * @param stream the stream that the final document should be written to.
      * @param width the width of the document
      * @param height the height of the document
      * @throws IOException an io exception if there is a problem
      *         writing to the output stream
      */
-    public AbstractPSDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
+    public AbstractPSDocumentGraphics2D(boolean textAsShapes, FontMap fontMap, OutputStream stream,
                                  int width, int height) throws IOException {
-        this(textAsShapes);
+        this(textAsShapes, fontMap);
         setupDocument(stream, width, height);
     }
 
@@ -219,7 +220,7 @@
         writePageHeader();
         if ((this.viewportWidth != this.width 
                 || this.viewportHeight != this.height)
-                && (this.viewportWidth > 0) && (this.viewportHeight > 0)){
+                && (this.viewportWidth > 0) && (this.viewportHeight > 0)) {
             gen.concatMatrix(this.width / this.viewportWidth, 0, 
                        0, -1 * (this.height / this.viewportHeight), 
                        0, this.height);
@@ -256,6 +257,7 @@
      */
     public AbstractPSDocumentGraphics2D(AbstractPSDocumentGraphics2D g) {
         super(g);
+        this.fontMap = g.fontMap;
     }
     
 
Index: src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java	(copie de travail)
@@ -25,8 +25,7 @@
 
 //FOP
 import org.apache.fop.Version;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontSetup;
+import org.apache.fop.pdf.FontMap;
 
 /**
  * This class is a wrapper for the <tt>PSGraphics2D</tt> that
@@ -51,13 +50,8 @@
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
      */
-    PSDocumentGraphics2D(boolean textAsShapes) {
-        super(textAsShapes);
-
-        if (!textAsShapes) {
-            fontInfo = new FontInfo();
-            FontSetup.setup(fontInfo, null);
-        }
+    PSDocumentGraphics2D(boolean textAsShapes, FontMap fontMap) {
+        super(textAsShapes, fontMap);
     }
 
     /**
@@ -68,15 +62,16 @@
      *
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
+     * @param fontMap map used to retrieve the internal keys for the fonts used in the document.
      * @param stream the stream that the final document should be written to.
      * @param width the width of the document
      * @param height the height of the document
      * @throws IOException an io exception if there is a problem
      *         writing to the output stream
      */
-    public PSDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
+    public PSDocumentGraphics2D(boolean textAsShapes, FontMap fontMap, OutputStream stream,
                                  int width, int height) throws IOException {
-        this(textAsShapes);
+        this(textAsShapes, fontMap);
         setupDocument(stream, width, height);
     }
 
@@ -112,8 +107,8 @@
         gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
         PSProcSets.writeFOPStdProcSet(gen);
         PSProcSets.writeFOPEPSProcSet(gen);
-        if (fontInfo != null) {
-            PSFontUtils.writeFontDict(gen, fontInfo);
+        if (fontConsumer != null) {
+            PSFontUtils.writeFontDict(gen, fontMap);
         }
         gen.writeDSCComment(DSCConstants.END_SETUP);
     }
@@ -129,7 +124,7 @@
         gen.writeln("/PageSize [" + width + " " + height + "]");
         gen.writeln("/ImagingBBox null");
         gen.writeln(">> setpagedevice");
-        if (fontInfo != null) {         
+        if (fontConsumer != null) {         
             gen.writeln("FOPFonts begin");
         }
     }
Index: src/java/org/apache/fop/render/ps/PSGraphics2D.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSGraphics2D.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/PSGraphics2D.java	(copie de travail)
@@ -60,10 +60,14 @@
 import org.apache.commons.logging.LogFactory;
 
 //FOP
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.image.FopImage;
 
+//aXSL
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontUse;
+
 /**
  * This concrete implementation of <tt>AbstractGraphics2D</tt> is a
  * simple help to programmers to get started with their own
@@ -88,12 +92,18 @@
 
     private boolean clippingDisabled = false;
 
-    /** Currently valid FontState */
-    protected Font font;
+    /** Currently valid FontUse */
+    protected FontUse fontUse;
+
+    /** Currently valid font size (in millipoints) */
+    protected int fontSize;
     
-    /** Overriding FontState */
-    protected Font overrideFont = null;
+    /** Overriding FontUse */
+    protected FontUse overrideFontUse = null;
     
+    /** Overriding font size (in millipoints) */
+    protected int overrideFontSize;
+    
     /** the current (internal) font name */
     protected String currentFontName;
 
@@ -106,7 +116,7 @@
     protected Color currentColour = new Color(0, 0, 0);
 
     /** FontInfo containing all available fonts */
-    protected FontInfo fontInfo;
+    protected FontConsumer fontConsumer;
 
     /**
      * Create a new Graphics2D that generates PostScript code.
@@ -137,12 +147,12 @@
 
         setPSGenerator(g.gen);
         this.clippingDisabled = g.clippingDisabled;
-        this.font             = g.font;
-        this.overrideFont     = g.overrideFont;
+        this.fontUse          = g.fontUse;
+        this.overrideFontUse  = g.overrideFontUse;
         this.currentFontName  = g.currentFontName;
         this.currentFontSize  = g.currentFontSize;
         this.currentColour    = g.currentColour;
-        this.fontInfo         = g.fontInfo;
+        this.fontConsumer     = g.fontConsumer;
     }
 
     /**
@@ -181,8 +191,8 @@
      * Return the font information associated with this object
      * @return the FontInfo object
      */
-    public FontInfo getFontInfo() {
-        return fontInfo;
+    public FontConsumer getFontConsumer() {
+        return fontConsumer;
     }
 
     /**
@@ -502,9 +512,9 @@
      */
     public void dispose() {
         this.gen = null;
-        this.font = null;
+        this.fontUse = null;
         this.currentColour = null;
-        this.fontInfo = null;
+        this.fontConsumer = null;
     }
 
     /**
@@ -860,12 +870,14 @@
         preparePainting();
         log.trace("drawString('" + s + "', " + x + ", " + y + ")");
         try {
-            if (this.overrideFont == null) {
+            if (this.overrideFontUse == null) {
                 java.awt.Font awtFont = getFont();
-                this.font = createFont(awtFont);
+                this.fontUse = createFont(awtFont, s);
+                this.fontSize = awtFont.getSize() * 1000;
             } else {
-                this.font = this.overrideFont;
-                this.overrideFont = null;
+                this.fontUse = this.overrideFontUse;
+                this.fontSize = this.overrideFontSize;
+                this.overrideFontUse = null;
             }
             
             //Color and Font state
@@ -901,33 +913,53 @@
         final int l = text.length();
         for (int i = 0; i < l; i++) {
             final char ch = text.charAt(i);
-            final char mch = this.font.mapChar(ch);
+            final char mch = this.fontUse.encodeCharacter(fontConsumer, ch);
             PSGenerator.escapeChar(mch, target);
         }
     }
 
-    private Font createFont(java.awt.Font f) {
+    /**
+     * Get a FontUse corresponding to the given AWT font.
+     * 
+     * @param f the AWT font.
+     * @param s text to be displayed. To help find a font capable of displaying the given text.
+     * @return a suitable FontUse.
+     */
+    private FontUse createFont(java.awt.Font f, String s) {
         String fontFamily = f.getFamily();
         if (fontFamily.equals("sanserif")) {
             fontFamily = "sans-serif";
         }
         int fontSize = 1000 * f.getSize();
-        String style = f.isItalic() ? "italic" : "normal";
-        int weight = f.isBold() ? Font.BOLD : Font.NORMAL;
-                
-        String fontKey = fontInfo.findAdjustWeight(fontFamily, style, weight);
-        if (fontKey == null) {
-            fontKey = fontInfo.findAdjustWeight("sans-serif", style, weight);
+        byte style = f.isItalic() ? Font.FONT_STYLE_ITALIC : Font.FONT_STYLE_NORMAL;
+        short weight = f.isBold() ? Font.FONT_WEIGHT_BOLD : Font.FONT_WEIGHT_NORMAL;
+        FontUse fontUse = null;
+        try {
+            fontUse = fontConsumer.getFontServer().selectFontXSL(fontConsumer,
+                    new String[] {fontFamily}, style, weight, Font.FONT_VARIANT_NORMAL,
+                    Font.FONT_STRETCH_NORMAL, fontSize, s.charAt(0));
+        } catch (FontException e) {
+            try {
+                fontUse = fontConsumer.getFontServer().selectFontXSL(fontConsumer,
+                        new String[] {"any"},
+                        Font.FONT_STYLE_ANY,
+                        Font.FONT_WEIGHT_ANY,
+                        Font.FONT_VARIANT_NORMAL,
+                        Font.FONT_STRETCH_NORMAL,
+                        fontSize, s.charAt(0));
+            } catch (FontException e1) { /* Should never happen */ }
         }
-        return new Font(fontKey, fontInfo.getMetricsFor(fontKey), fontSize);
+        
+        return fontUse;
     }
 
     private void establishCurrentFont() throws IOException {
-        if ((currentFontName != this.font.getFontName()) 
-                || (currentFontSize != this.font.getFontSize())) {
-            gen.writeln(this.font.getFontName() + " " + this.font.getFontSize() + " F");
-            currentFontName = this.font.getFontName();
-            currentFontSize = this.font.getFontSize();
+        String name = fontUse.postscriptName();
+        if ((currentFontName != name) 
+                || (currentFontSize != fontSize)) {
+            gen.writeln(name + " " + fontSize + " F");
+            currentFontName = name;
+            currentFontSize = fontSize;
         }
     }
 
@@ -1088,14 +1120,22 @@
     }
 
     /**
-     * Sets the overriding font.
-     * @param font Font to set
+     * Sets the overriding font use.
+     * @param ovFontUse Font use to set
      */
-    public void setOverrideFont(Font font) {
-        this.overrideFont = font;
+    public void setOverrideFont(FontUse ovFontUse) {
+        this.overrideFontUse = ovFontUse;
     }
     
     /**
+     * Sets the overriding font size.
+     * @param ovSize font size in millipoints
+     */
+    public void setOverrideFontSize(int ovSize) {
+        this.overrideFontSize = ovSize;
+    }
+    
+    /**
      * Gets the font metrics for the specified font.
      * @return    the font metrics for the specified font.
      * @param     f the specified font
Index: src/java/org/apache/fop/render/ps/PSFontUtils.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSFontUtils.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/PSFontUtils.java	(copie de travail)
@@ -18,28 +18,17 @@
 
 package org.apache.fop.render.ps;
 
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.util.Iterator;
 import java.util.Map;
 
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.commons.io.EndianUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.fop.fonts.CustomFont;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontType;
 import org.apache.fop.fonts.Glyphs;
-import org.apache.fop.fonts.LazyFont;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.util.ASCIIHexOutputStream;
-import org.apache.fop.util.SubInputStream;
+import org.apache.fop.pdf.FontMap;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontUse;
+import org.axsl.ps.Encoding;
+
 /**
  * Utility code for font handling in PostScript.
  */
@@ -48,172 +37,76 @@
     /**
      * Generates the PostScript code for the font dictionary.
      * @param gen PostScript generator to use for output
-     * @param fontInfo available fonts
+     * @param fontMap mappings of FontUses to their associated internal names
      * @return a Map of PSResource instances representing all defined fonts (key: font key)
      * @throws IOException in case of an I/O problem
      */
-    public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo) 
+    public static Map writeFontDict(PSGenerator gen, FontMap fontMap) 
                 throws IOException {
         gen.commentln("%FOPBeginFontDict");
         gen.writeln("/FOPFonts 100 dict dup begin");
 
         // write("/gfF1{/Helvetica findfont} bd");
         // write("/gfF3{/Helvetica-Bold findfont} bd");
-        Map fonts = fontInfo.getFonts();
         Map fontResources = new java.util.HashMap();
-        Iterator iter = fonts.keySet().iterator();
+        Iterator iter = fontMap.getMappings().iterator();
         while (iter.hasNext()) {
-            String key = (String)iter.next();
-            Typeface tf = (Typeface)fonts.get(key);
-            if (tf instanceof LazyFont) {
-                tf = ((LazyFont)tf).getRealFont();
-            }
-            PSResource fontRes = new PSResource("font", tf.getFontName());
-            fontResources.put(key, fontRes);
+            Map.Entry entry = (Map.Entry)iter.next();
+            String internalName = (String)entry.getValue();
+            FontUse fontUse = (FontUse)entry.getKey();
+            PSResource fontRes = new PSResource(PSResource.TYPE_FONT, internalName);
+            fontResources.put(internalName, fontRes);
             boolean embeddedFont = false;
-            if (FontType.TYPE1 == tf.getFontType()) {
-                if (tf instanceof CustomFont) {
-                    CustomFont cf = (CustomFont)tf;
-                    InputStream in = getInputStreamOnFont(gen, cf);
-                    if (in != null) {
-                        gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, 
-                                fontRes);
-                        embedType1Font(gen, in);
-                        gen.writeDSCComment(DSCConstants.END_RESOURCE);
-                        gen.notifyResourceUsage(fontRes, false);
-                        embeddedFont = true;
-                    }
-                }
+            Font font = fontUse.getFont();
+            if (font.getFontFormat() == Font.FORMAT_TYPE1
+                    && font.isEmbeddable()
+                    && !font.isPDFStandardFont()) {
+                gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, fontRes);
+                gen.writeByteArr(font.getContentsPostScriptHex(fontMap.getFontConsumer()));
+                gen.writeDSCComment(DSCConstants.END_RESOURCE);
+                gen.notifyResourceUsage(fontRes, false);
+                embeddedFont = true;
             }
             if (!embeddedFont) {
                 gen.writeDSCComment(DSCConstants.INCLUDE_RESOURCE, fontRes);
                 //Resource usage shall be handled by renderer
                 //gen.notifyResourceUsage(fontRes, true);
             }
-            gen.commentln("%FOPBeginFontKey: " + key);
-            gen.writeln("/" + key + " /" + tf.getFontName() + " def");
+            gen.commentln("%FOPBeginFontKey: " + internalName);
+            gen.writeln("/" + internalName + " /" + font.postscriptName() + " def");
             gen.commentln("%FOPEndFontKey");
         }
         gen.writeln("end def");
         gen.commentln("%FOPEndFontDict");
         gen.commentln("%FOPBeginFontReencode");
         defineWinAnsiEncoding(gen);
-        
+
         //Rewrite font encodings
-        iter = fonts.keySet().iterator();
+        iter = fontMap.getMappings().iterator();
         while (iter.hasNext()) {
-            String key = (String)iter.next();
-            Typeface fm = (Typeface)fonts.get(key);
-            if (null == fm.getEncoding()) {
+            FontUse fontUse = (FontUse)((Map.Entry)iter.next()).getKey();
+            Encoding encoding = fontUse.getEncoding();
+            if (encoding == null) {
                 //ignore (ZapfDingbats and Symbol run through here
                 //TODO: ZapfDingbats and Symbol should get getEncoding() fixed!
-            } else if ("WinAnsiEncoding".equals(fm.getEncoding())) {
-                gen.writeln("/" + fm.getFontName() + " findfont");
+            } else if (encoding.isPredefinedPS()) {
+                gen.writeln("/" + fontUse.postscriptName() + " findfont");
                 gen.writeln("dup length dict begin");
                 gen.writeln("  {1 index /FID ne {def} {pop pop} ifelse} forall");
-                gen.writeln("  /Encoding " + fm.getEncoding() + " def");
+                gen.writeln("  /Encoding " + encoding.getName() + " def");
                 gen.writeln("  currentdict");
                 gen.writeln("end");
-                gen.writeln("/" + fm.getFontName() + " exch definefont pop");
+                gen.writeln("/" + fontUse.postscriptName() + " exch definefont pop");
             } else {
                 gen.commentln("%WARNING: Only WinAnsiEncoding is supported. Font '" 
-                    + fm.getFontName() + "' asks for: " + fm.getEncoding());
+                    + fontUse.postscriptName() + "' asks for: " + encoding.getName());
             }
         }
         gen.commentln("%FOPEndFontReencode");
+        
         return fontResources;
     }
 
-    /**
-     * This method reads a Type 1 font from a stream and embeds it into a PostScript stream.
-     * Note: Only the IBM PC Format as described in section 3.3 of the Adobe Technical Note #5040
-     * is supported.
-     * @param gen The PostScript generator
-     * @param in the InputStream from which to read the Type 1 font
-     * @throws IOException in case an I/O problem occurs
-     */
-    private static void embedType1Font(PSGenerator gen, InputStream in) throws IOException {
-        boolean finished = false;
-        while (!finished) {
-            int segIndicator = in.read();
-            if (segIndicator < 0) {
-                throw new IOException("Unexpected end-of-file while reading segment indicator");
-            } else if (segIndicator != 128) {
-                throw new IOException("Expected ASCII 128, found: " + segIndicator);
-            }
-            int segType = in.read();
-            if (segType < 0) {
-                throw new IOException("Unexpected end-of-file while reading segment type");
-            }
-            int dataSegLen = 0;
-            switch (segType) {
-                case 1: //ASCII
-                    dataSegLen = EndianUtils.readSwappedInteger(in);
-
-                    BufferedReader reader = new BufferedReader(
-                            new java.io.InputStreamReader(
-                                    new SubInputStream(in, dataSegLen), "US-ASCII"));
-                    String line;
-                    while ((line = reader.readLine()) != null) {
-                        gen.writeln(line);
-                        }
-                    break;
-                case 2: //binary
-                    dataSegLen = EndianUtils.readSwappedInteger(in);
-
-                    SubInputStream sin = new SubInputStream(in, dataSegLen);
-                    ASCIIHexOutputStream hexOut = new ASCIIHexOutputStream(gen.getOutputStream());
-                    IOUtils.copy(sin, hexOut);
-                    gen.newLine();
-                    break;
-                case 3: //EOF
-                    finished = true;
-                    break;
-                default: throw new IOException("Unsupported segment type: " + segType);
-            }
-        }
-    }
-
-    private static InputStream getInputStreamOnFont(PSGenerator gen, CustomFont font) 
-                throws IOException {
-        if (font.isEmbeddable()) {
-            Source source = null;
-            if (font.getEmbedFileName() != null) {
-                source = gen.resolveURI(font.getEmbedFileName());
-            }
-            if (source == null && font.getEmbedResourceName() != null) {
-                source = new StreamSource(PSFontUtils.class
-                        .getResourceAsStream(font.getEmbedResourceName()));
-            }
-            if (source == null) {
-                return null;
-            }
-            InputStream in = null;
-            if (source instanceof StreamSource) {
-                in = ((StreamSource) source).getInputStream();
-            }
-            if (in == null && source.getSystemId() != null) {
-                try {
-                    in = new java.net.URL(source.getSystemId()).openStream();
-                } catch (MalformedURLException e) {
-                    new FileNotFoundException(
-                            "File not found. URL could not be resolved: "
-                                    + e.getMessage());
-                }
-            }
-            if (in == null) {
-                return null;
-            }
-            //Make sure the InputStream is decorated with a BufferedInputStream
-            if (!(in instanceof java.io.BufferedInputStream)) {
-                in = new java.io.BufferedInputStream(in);
-            }
-            return in;
-        } else {
-            return null;
-        }
-    }
-
     private static void defineWinAnsiEncoding(PSGenerator gen) throws IOException {
         gen.writeln("/WinAnsiEncoding [");
         for (int i = 0; i < Glyphs.WINANSI_ENCODING.length; i++) {
Index: src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java
===================================================================
--- src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java	(copie de travail)
@@ -74,7 +74,7 @@
      * Constructs a new <tt>AbstractPSTranscoder</tt>.
      */
     public AbstractPSTranscoder() {
-        super();
+        super(true);
     }
 
     protected abstract AbstractPSDocumentGraphics2D createDocumentGraphics2D();
@@ -146,7 +146,7 @@
         }*/
 
         BridgeContext ctx = new BridgeContext(userAgent);
-        PSTextPainter textPainter = new PSTextPainter(graphics.getFontInfo());
+        PSTextPainter textPainter = new PSTextPainter(graphics.getFontConsumer());
         ctx.setTextPainter(textPainter);
         ctx.putBridge(new PSTextElementBridge(textPainter));
 
Index: src/java/org/apache/fop/render/ps/EPSDocumentGraphics2D.java
===================================================================
--- src/java/org/apache/fop/render/ps/EPSDocumentGraphics2D.java	(révision 356368)
+++ src/java/org/apache/fop/render/ps/EPSDocumentGraphics2D.java	(copie de travail)
@@ -21,6 +21,7 @@
 import java.io.IOException;
 
 import org.apache.fop.Version;
+import org.apache.fop.pdf.FontMap;
 
 /**
  * This class is a wrapper for the <tt>AbstractPSDocumentGraphics2D</tt> that
@@ -42,9 +43,10 @@
      *
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
+     * @param fontMap map used to retrieve the internal names of the fonts used in the document
      */
-    public EPSDocumentGraphics2D(boolean textAsShapes) {
-        super(textAsShapes);
+    public EPSDocumentGraphics2D(boolean textAsShapes, FontMap fontMap) {
+        super(textAsShapes, fontMap);
     }
 
     protected void writeFileHeader() throws IOException {
@@ -68,8 +70,8 @@
         gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
         PSProcSets.writeFOPStdProcSet(gen);
         PSProcSets.writeFOPEPSProcSet(gen);
-        if (fontInfo != null) {
-            PSFontUtils.writeFontDict(gen, fontInfo);
+        if (fontConsumer != null) {
+            PSFontUtils.writeFontDict(gen, fontMap);
         }
         gen.writeDSCComment(DSCConstants.END_PROLOG);
     }
@@ -81,7 +83,7 @@
         gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[]
                 {ZERO, ZERO, new Integer(width), new Integer(height)});
         gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
-        if (fontInfo != null) {         
+        if (fontConsumer != null) {         
             gen.writeln("FOPFonts begin");
         }
     }
Index: src/java/org/apache/fop/render/Renderer.java
===================================================================
--- src/java/org/apache/fop/render/Renderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/Renderer.java	(copie de travail)
@@ -19,18 +19,19 @@
 package org.apache.fop.render;
 
 // Java
+import java.io.IOException;
 import java.io.OutputStream;
-import java.io.IOException;
 
 // FOP
 import org.apache.fop.apps.FOPException;
-import org.apache.fop.area.PageViewport;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.LineArea;
 import org.apache.fop.area.OffDocumentItem;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.area.PageViewport;
 
+import org.axsl.font.FontConsumer;
 
+
 /**
  * Interface implemented by all renderers. This interface is used to control
  * the rendering of pages and to let block and inline level areas call the
@@ -88,11 +89,11 @@
     void setUserAgent(FOUserAgent agent);
 
     /**
-     * Set up the given FontInfo.
+     * Set up the font consumer.
      *
-     * @param fontInfo  The font information
+     * @param fontConsumer The font consumer
      */
-    void setupFontInfo(FontInfo fontInfo);
+    void setupFontConsumer(FontConsumer fontConsumer);
 
     /**
      * Reports if out of order rendering is supported. <p>
Index: src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java
===================================================================
--- src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java	(révision 356368)
+++ src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java	(copie de travail)
@@ -109,4 +109,4 @@
     public boolean isEmpty() {
         return false;
     }
-}
\ No newline at end of file
+}
Index: src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java
===================================================================
--- src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java	(révision 356368)
+++ src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyle.java	(copie de travail)
@@ -68,4 +68,4 @@
     public void writeLevelGroup(RtfElement element)
     throws IOException {
     }
-}
\ No newline at end of file
+}
Index: src/java/org/apache/fop/render/rtf/RTFHandler.java
===================================================================
--- src/java/org/apache/fop/render/rtf/RTFHandler.java	(révision 356368)
+++ src/java/org/apache/fop/render/rtf/RTFHandler.java	(copie de travail)
@@ -85,7 +85,6 @@
 import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTableContainer;
 import org.apache.fop.render.rtf.rtflib.tools.BuilderContext;
 import org.apache.fop.render.rtf.rtflib.tools.TableContext;
-import org.apache.fop.fonts.FontSetup;
 import org.apache.fop.image.FopImage;
 import org.apache.fop.image.ImageFactory;
 import org.apache.fop.image.XMLImage;
@@ -129,8 +128,6 @@
         super(userAgent);
         this.os = os;
         bDefer = true;
-
-        FontSetup.setup(fontInfo, null);
     }
 
     /**
Index: src/java/org/apache/fop/render/xml/XMLRenderer.java
===================================================================
--- src/java/org/apache/fop/render/xml/XMLRenderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/xml/XMLRenderer.java	(copie de travail)
@@ -71,7 +71,7 @@
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.WordArea;
-import org.apache.fop.fonts.FontSetup;
+import org.axsl.font.FontUse;
 
 /**
  * Renderer that renders areas to XML for debugging purposes.
@@ -119,13 +119,6 @@
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
      */
     public void configure(Configuration cfg) throws ConfigurationException {
-        //Font configuration
-        List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
-        if (this.fontList == null) {
-            this.fontList = cfgFonts;
-        } else {
-            this.fontList.addAll(cfgFonts);
-        }
     }
 
     /**
@@ -283,9 +276,11 @@
                 String value = traitEntry.getValue().toString();
                 addAttribute(name, value);
                 if ("font-family".equals(name)) {
-                    addAttribute("font-name", fontInfo.getMetricsFor(value).getFontName());
-                    addAttribute("font-style", fontInfo.getFontStyleFor(value));
-                    addAttribute("font-weight", fontInfo.getFontWeightFor(value));
+                    FontUse fontUse = (FontUse) traitEntry.getValue();
+                    addAttribute("font-name", fontUse.postscriptName());
+                    // Style and weight should be present in the postscript name
+//                    addAttribute("font-style", fontInfo.getFontStyleFor(value));
+//                    addAttribute("font-weight", fontInfo.getFontWeightFor(value));
                 }
             }
         }
Index: src/java/org/apache/fop/render/PrintRenderer.java
===================================================================
--- src/java/org/apache/fop/render/PrintRenderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/PrintRenderer.java	(copie de travail)
@@ -18,31 +18,25 @@
 
 package org.apache.fop.render;
 
-// FOP
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontSetup;
-
 // Java
 import java.awt.Color;
-import java.util.List;
 
+// aXSL
+import org.axsl.font.FontConsumer;
+
 /** Abstract base class of "Print" type renderers.  */
 public abstract class PrintRenderer extends AbstractRenderer {
 
-    /** Font configuration */
-    protected FontInfo fontInfo;
+    /** Font consumer */
+    protected FontConsumer fontConsumer;
 
-    /** list of fonts */
-    protected List fontList = null;
-
     /**
-     * Set up the font info
+     * Set up the font consumer
      *
-     * @param inFontInfo  font info to set up
+     * @param inFontConsumer  font consumer to set up
      */
-    public void setupFontInfo(FontInfo inFontInfo) {
-        this.fontInfo = inFontInfo;
-        FontSetup.setup(fontInfo, fontList);
+    public void setupFontConsumer(FontConsumer inFontConsumer) {
+        this.fontConsumer = inFontConsumer;
     }
 
     /**
Index: src/java/org/apache/fop/render/java2d/RendererState.java
===================================================================
--- src/java/org/apache/fop/render/java2d/RendererState.java	(révision 356368)
+++ src/java/org/apache/fop/render/java2d/RendererState.java	(copie de travail)
@@ -58,15 +58,15 @@
     public abstract boolean updateColor(ColorType col, boolean fill, StringBuffer pdf);
 
     /**
-     * Set the current font name. Check if the font name will change and then
-     * set the new name.
+     * Set the current font. Check if the font will change and then set the new
+     * font.
      *
-     * @param name the new font name
-     * @param size
+     * @param fontUse the new font use
+     * @param size the new font size
      * @param pdf
      * @return true if the new Font changes the current Font
      */
-    public abstract boolean updateFont(String name, int size, StringBuffer pdf);
+    public abstract boolean updateFont(org.axsl.font.FontUse fontUse, int size, StringBuffer pdf);
 
     /**
      * Sets the current Stroke. The line width should be set with
Index: src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java
===================================================================
--- src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java	(révision 356368)
+++ src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java	(copie de travail)
@@ -30,8 +30,10 @@
 
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.FontInfo;
 
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * Keeps information about the current state of the Graphics2D currentGraphics.
  * It is also used as a stack to hold a graphics context.
@@ -51,8 +53,8 @@
 
     private List stateStack = new java.util.ArrayList();
 
-    /** Font configuration, passed from AWTRenderer */
-    private FontInfo fontInfo;
+    /** Font consumer, passed from AWTRenderer */
+    private FontConsumer fontConsumer;
 
     /** Initial AffinTransform passed by the renderer, includes scaling-info */
     private AffineTransform initialTransform;
@@ -60,12 +62,12 @@
     /**
      * State for storing graphics state.
      * @param graphics the graphics associated with the BufferedImage
-     * @param fontInfo the FontInfo from the renderer
+     * @param fontConsumer the FontConsumer from the renderer
      * @param at the initial AffineTransform containing the scale transformation
      */
-    public Java2DGraphicsState(Graphics2D graphics, FontInfo fontInfo,
+    public Java2DGraphicsState(Graphics2D graphics, FontConsumer fontConsumer,
             AffineTransform at) {
-        this.fontInfo = fontInfo;
+        this.fontConsumer = fontConsumer;
         this.currentGraphics = graphics;
         this.initialTransform = at;
         currentGraphics.setTransform(at);
@@ -172,21 +174,16 @@
     }
 
     /**
-     * @see org.apache.fop.render.java2d.RendererState#updateFont(java.lang.String,
+     * @see org.apache.fop.render.java2d.RendererState#updateFont(org.axsl.font.FontUse,
      * int, java.lang.StringBuffer)
      */
-    public boolean updateFont(String name, int size, StringBuffer pdf) {
+    public boolean updateFont(FontUse fontUse, int size, StringBuffer pdf) {
 
-        boolean updateName = (!name.equals(getGraph().getFont().getFontName()));
-        boolean updateSize = (size != (getGraph().getFont().getSize()));
 
-        if (updateName || updateSize) {
+        java.awt.Font awtFont = fontUse.getFont().getAWTFont(fontConsumer, size);
+        if (!getGraph().getFont().equals(awtFont)) {
             // the font name and/or the font size have changed
-            FontMetricsMapper mapper = (FontMetricsMapper) fontInfo
-                    .getMetricsFor(name);
-            java.awt.Font font = mapper.getFont(size);
-
-            currentGraphics.setFont(font);
+            currentGraphics.setFont(awtFont);
             return true;
         } else {
             return false;
Index: src/java/org/apache/fop/render/java2d/Java2DRenderer.java
===================================================================
--- src/java/org/apache/fop/render/java2d/Java2DRenderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/java2d/Java2DRenderer.java	(copie de travail)
@@ -61,9 +61,6 @@
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontMetrics;
 import org.apache.fop.image.FopImage;
 import org.apache.fop.image.ImageFactory;
 import org.apache.fop.image.XMLImage;
@@ -72,6 +69,11 @@
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.pdf.CTMHelper;
 import org.apache.fop.traits.BorderProps;
+
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 import org.w3c.dom.Document;
 
 /**
@@ -130,8 +132,8 @@
     /** a Line2D.Float used to draw text decorations and leaders */
     protected Line2D.Float line = new Line2D.Float();
 
-    /** Font configuration */
-    protected FontInfo fontInfo;
+    /** Font consumer */
+    protected FontConsumer fontConsumer;
 
     protected Map fontNames = new java.util.Hashtable();
 
@@ -160,14 +162,10 @@
     }
 
     /**
-     * @see org.apache.fop.render.Renderer#setupFontInfo(org.apache.fop.fonts.FontInfo)
+     * @see org.apache.fop.render.Renderer#setupFontConsumer(org.axsl.font.FontConsumer)
      */
-    public void setupFontInfo(FontInfo inFontInfo) {
-        // create a temp Image to test font metrics on
-        fontInfo = inFontInfo;
-        BufferedImage fontImage = new BufferedImage(100, 100,
-                BufferedImage.TYPE_INT_RGB);
-        FontSetup.setup(fontInfo, fontImage.createGraphics());
+    public void setupFontConsumer(FontConsumer fontConsumer) {
+        this.fontConsumer = fontConsumer;
     }
 
     /** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
@@ -308,7 +306,7 @@
         graphics.drawLine(0, pageHeight + 2, pageWidth + 2, pageHeight + 2);
         graphics.drawLine(1, pageHeight + 3, pageWidth + 3, pageHeight + 3);
 
-        state = new Java2DGraphicsState(graphics, this.fontInfo, at);
+        state = new Java2DGraphicsState(graphics, this.fontConsumer, at);
 
         // reset the current Positions
         currentBPPosition = 0;
@@ -731,9 +729,9 @@
         float x = currentIPPosition;
         float y = currentBPPosition + text.getOffset() + text.getBaselineOffset(); // baseline
 
-        String name = (String) text.getTrait(Trait.FONT_NAME);
+        FontUse fontUse = (FontUse) text.getTrait(Trait.FONT);
         int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
-        state.updateFont(name, size, null);
+        state.updateFont(fontUse, size, null);
 
         ColorType ct = (ColorType) text.getTrait(Trait.COLOR);
         state.updateColor(ct, false, null);
@@ -745,9 +743,7 @@
         // + x + ", y: " + y + state);
 
         // rendering text decorations
-        FontMetrics metrics = fontInfo.getMetricsFor(name);
-        Font fs = new Font(name, metrics, size);
-        renderTextDecoration(fs, text, y, x);
+        renderTextDecoration(fontUse.getFont(), size, text, y, x);
 
         super.renderText(text);
     }
@@ -760,9 +756,9 @@
         float x = currentIPPosition;
         float y = currentBPPosition + ch.getOffset() + ch.getBaselineOffset(); // baseline
 
-        String name = (String) ch.getTrait(Trait.FONT_NAME);
+        FontUse fontUse = (FontUse) ch.getTrait(Trait.FONT);
         int size = ((Integer) ch.getTrait(Trait.FONT_SIZE)).intValue();
-        state.updateFont(name, size, null);
+        state.updateFont(fontUse, size, null);
 
         ColorType ct = (ColorType) ch.getTrait(Trait.COLOR);
         state.updateColor(ct, false, null);
@@ -774,9 +770,7 @@
         // + x + ", y: " + y + state);
 
         // rendering text decorations
-        FontMetrics metrics = fontInfo.getMetricsFor(name);
-        Font fs = new Font(name, metrics, size);
-        renderTextDecoration(fs, ch, y, x);
+        renderTextDecoration(fontUse.getFont(), size, ch, y, x);
 
         super.renderCharacter(ch);
     }
@@ -785,25 +779,26 @@
      * Paints the text decoration marks.
      *
      * @param fs Current font
+     * @param fontSize font size
      * @param inline inline area to paint the marks for
      * @param baseline position of the baseline
      * @param startIPD start IPD
      */
-    protected void renderTextDecoration(Font fs, InlineArea inline,
+    protected void renderTextDecoration(Font fs, int fontSize, InlineArea inline,
             float baseline, float startIPD) {
 
         boolean hasTextDeco = inline.hasUnderline() || inline.hasOverline()
                 || inline.hasLineThrough();
 
         if (hasTextDeco) {
-            state.updateStroke((fs.getDescender() / (-8 * 1000f)),
+            state.updateStroke((fs.getDescender(fontSize) / (-8 * 1000f)),
                     Constants.EN_SOLID);
             float endIPD = startIPD + inline.getIPD();
             if (inline.hasUnderline()) {
                 ColorType ct = (ColorType) inline
                         .getTrait(Trait.UNDERLINE_COLOR);
                 state.updateColor(ct, false, null);
-                float y = baseline - fs.getDescender() / 2;
+                float y = baseline - fs.getDescender(fontSize) / 2;
                 line.setLine(startIPD / 1000f, y / 1000f, endIPD / 1000f,
                         y / 1000f);
                 state.getGraph().draw(line);
@@ -812,7 +807,7 @@
                 ColorType ct = (ColorType) inline
                         .getTrait(Trait.OVERLINE_COLOR);
                 state.updateColor(ct, false, null);
-                float y = (float) (baseline - (1.1 * fs.getCapHeight()));
+                float y = (float) (baseline - (1.1 * fs.getCapHeight(fontSize)));
                 line.setLine(startIPD / 1000f, y / 1000f, endIPD / 1000f,
                         y / 1000f);
                 state.getGraph().draw(line);
@@ -821,7 +816,7 @@
                 ColorType ct = (ColorType) inline
                         .getTrait(Trait.LINETHROUGH_COLOR);
                 state.updateColor(ct, false, null);
-                float y = (float) (baseline - (0.45 * fs.getCapHeight()));
+                float y = (float) (baseline - (0.45 * fs.getCapHeight(fontSize)));
                 line.setLine(startIPD / 1000f, y / 1000f, endIPD / 1000f,
                         y / 1000f);
                 state.getGraph().draw(line);
@@ -1075,7 +1070,7 @@
         try {
           PageViewport viewport = getPageViewport(pageIndex);
           AffineTransform at = graphics.getTransform();
-          state = new Java2DGraphicsState(graphics, this.fontInfo, at);
+          state = new Java2DGraphicsState(graphics, this.fontConsumer, at);
 
           // reset the current Positions
           currentBPPosition = 0;
Index: src/java/org/apache/fop/render/pdf/PDFRenderer.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFRenderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/pdf/PDFRenderer.java	(copie de travail)
@@ -56,13 +56,11 @@
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.datatypes.ColorType;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.FontMetrics;
+import org.apache.fop.fo.Constants;
 import org.apache.fop.image.FopImage;
 import org.apache.fop.image.ImageFactory;
 import org.apache.fop.image.XMLImage;
+import org.apache.fop.pdf.FontMap;
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.PDFColor;
 import org.apache.fop.pdf.PDFDocument;
@@ -81,8 +79,11 @@
 import org.apache.fop.render.AbstractPathOrientedRenderer;
 import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.RendererContext;
-import org.apache.fop.fo.Constants;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /*
 todo:
 
@@ -162,11 +163,16 @@
     /** drawing state */
     protected PDFState currentState = null;
 
-    /** Name of currently selected font */
-    protected String currentFontName = "";
-    /** Size of currently selected font */
+    /** Currently selected FontUse */
+    protected FontUse currentFontUse = null;
+    /** Size (in millipoints) of currently selected font */
     protected int currentFontSize = 0;
-    /** page height */
+    /**
+     * Font mappings of FontUse to internal name.
+     */
+    protected FontMap fontMap;
+    
+    /** page height */  
     protected int pageHeight;
 
     /** Registry of PDF filters */
@@ -209,6 +215,23 @@
      */
     public PDFRenderer() {
     }
+    
+    /**
+     * Setup the font consumer.
+     * @param fontConsumer the font consumer.
+     */
+    public void setupFontConsumer(FontConsumer fontConsumer) {
+        super.setupFontConsumer(fontConsumer);
+        fontMap = new FontMap(fontConsumer);
+    }
+    
+    /**
+     * Return the font map associated to this renderer.
+     * @return the mappings of FontUse to internal names
+     */
+    public FontMap getFontMap() {
+        return fontMap;
+    }
 
     /**
      * Configure the PDF renderer.
@@ -220,13 +243,6 @@
         //PDF filters
         this.filterMap = PDFFilterList.buildFilterMapFromConfiguration(cfg);
 
-        //Font configuration
-        List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
-        if (this.fontList == null) {
-            this.fontList = cfgFonts;
-        } else {
-            this.fontList.addAll(cfgFonts);
-        }
     }
 
     /**
@@ -234,7 +250,7 @@
      */
     public void setUserAgent(FOUserAgent agent) {
         super.setUserAgent(agent);
-        PDFSVGHandler xmlHandler = new PDFSVGHandler();
+        PDFSVGHandler xmlHandler = new PDFSVGHandler(fontMap);
         userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
     }
 
@@ -265,7 +281,7 @@
      * @see org.apache.fop.render.Renderer#stopRenderer()
      */
     public void stopRenderer() throws IOException {
-        pdfDoc.getResources().addFonts(pdfDoc, fontInfo);
+        pdfDoc.getResources().addFonts(pdfDoc, fontMap);
         pdfDoc.outputTrailer(ostream);
 
         this.pdfDoc = null;
@@ -280,7 +296,7 @@
         currentContext = null;
         currentPage = null;
         currentState = null;
-        currentFontName = "";
+        currentFontUse = null;
     }
 
     /**
@@ -468,7 +484,7 @@
         currentStream.add(CTMHelper.toPDFString(currentBasicTransform, false) + " cm\n");
         
         
-        currentFontName = "";
+        currentFontUse = null;
 
         Page p = page.getPage();
         renderPageAreas(p);
@@ -513,7 +529,7 @@
      * @param region the RegionViewport whose region is to be drawn
      */
     protected void handleRegionTraits(RegionViewport region) {
-        currentFontName = "";
+        currentFontUse = null;
         super.handleRegionTraits(region);
     }
 
@@ -1006,18 +1022,17 @@
         beginTextObject();
         StringBuffer pdf = new StringBuffer();
 
-        String name = (String) ch.getTrait(Trait.FONT_NAME);
+        FontUse font = (FontUse) ch.getTrait(Trait.FONT);
         int size = ((Integer) ch.getTrait(Trait.FONT_SIZE)).intValue();
 
         // This assumes that *all* CIDFonts use a /ToUnicode mapping
-        Typeface tf = (Typeface) fontInfo.getFonts().get(name);
-        boolean useMultiByte = tf.isMultiByte();
+        boolean useMultiByte = font.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
 
         // String startText = useMultiByte ? "<FEFF" : "(";
         String startText = useMultiByte ? "<" : "(";
         String endText = useMultiByte ? "> " : ") ";
 
-        updateFont(name, size, pdf);
+        updateFont(font, size, pdf);
         ColorType ct = (ColorType) ch.getTrait(Trait.COLOR);
         if (ct != null) {
             updateColor(ct, true, pdf);
@@ -1036,7 +1051,7 @@
             "; offset: " + ch.getOffset());
 */
         // Set letterSpacing
-        //float ls = fs.getLetterSpacing() / this.currentFontSize;
+        //float ls = font.getLetterSpacing() / this.currentFontSize;
         //pdf.append(ls).append(" Tc\n");
 
         if (!textOpen || bl != prevWordY) {
@@ -1061,14 +1076,12 @@
         String s = ch.getChar();
 
 
-        FontMetrics metrics = fontInfo.getMetricsFor(name);
-        Font fs = new Font(name, metrics, size);
-        escapeText(s, fs, useMultiByte, pdf);
+        escapeText(s, font, useMultiByte, pdf);
         pdf.append(endText);
 
         currentStream.add(pdf.toString());
 
-        renderTextDecoration(tf, size, ch, bl, rx);
+        renderTextDecoration(font, size, ch, bl, rx);
         
         super.renderCharacter(ch);
     }
@@ -1081,14 +1094,13 @@
         beginTextObject();
         StringBuffer pdf = new StringBuffer();
 
-        String name = (String) text.getTrait(Trait.FONT_NAME);
+        FontUse font = (FontUse) text.getTrait(Trait.FONT);
         int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
         
         // This assumes that *all* CIDFonts use a /ToUnicode mapping
-        Typeface tf = (Typeface) fontInfo.getFonts().get(name);
-        boolean useMultiByte = tf.isMultiByte();
-        
-        updateFont(name, size, pdf);
+        boolean useMultiByte = font.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
+
+        updateFont(font, size, pdf);
         ColorType ct = (ColorType) text.getTrait(Trait.COLOR);
         updateColor(ct, true, pdf);
 
@@ -1105,7 +1117,7 @@
             "; offset: " + text.getOffset());
 */
         // Set letterSpacing
-        //float ls = fs.getLetterSpacing() / this.currentFontSize;
+        //float ls = font.getLetterSpacing() / this.currentFontSize;
         //pdf.append(ls).append(" Tc\n");
 
         if (!textOpen || bl != prevWordY) {
@@ -1131,17 +1143,16 @@
 
         super.renderText(text);
 
-        renderTextDecoration(tf, size, text, bl, rx);
+        renderTextDecoration(font, size, text, bl, rx);
     }
     
     /**
      * @see org.apache.fop.render.AbstractRenderer#renderWord(WordArea)
      */
     public void renderWord(WordArea word) {
-        String name = (String) word.getParentArea().getTrait(Trait.FONT_NAME);
+        FontUse fontUse = (FontUse) word.getParentArea().getTrait(Trait.FONT);
         int size = ((Integer) word.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
-        Typeface tf = (Typeface) fontInfo.getFonts().get(name);
-        boolean useMultiByte = tf.isMultiByte();
+        boolean useMultiByte = fontUse.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
 
         String startText = useMultiByte ? "<" : "(";
         String endText = useMultiByte ? "> " : ") ";
@@ -1152,9 +1163,7 @@
 
         String s = word.getWord();
         
-        FontMetrics metrics = fontInfo.getMetricsFor(name);
-        Font fs = new Font(name, metrics, size);
-        escapeText(s, fs, useMultiByte, pdf);
+        escapeText(s, fontUse, useMultiByte, pdf);
         pdf.append(endText);
         
         currentStream.add(pdf.toString());
@@ -1166,10 +1175,9 @@
      * @see org.apache.fop.render.AbstractRenderer#renderSpace(SpaceArea)
      */
     public void renderSpace(SpaceArea space) {
-        String name = (String) space.getParentArea().getTrait(Trait.FONT_NAME);
+        FontUse fontUse = (FontUse) space.getParentArea().getTrait(Trait.FONT);
         int size = ((Integer) space.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
-        Typeface tf = (Typeface) fontInfo.getFonts().get(name);
-        boolean useMultiByte = tf.isMultiByte();
+        boolean useMultiByte = fontUse.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
 
         String startText = useMultiByte ? "<" : "(";
         String endText = useMultiByte ? "> " : ") ";
@@ -1180,9 +1188,7 @@
 
         String s = space.getSpace();
         
-        FontMetrics metrics = fontInfo.getMetricsFor(name);
-        Font fs = new Font(name, metrics, size);
-        escapeText(s, fs, useMultiByte, pdf);
+        escapeText(s, fontUse, useMultiByte, pdf);
         pdf.append(endText);
         
         if (useMultiByte) {
@@ -1197,27 +1203,28 @@
     /**
      * Escapes text according to PDF rules.
      * @param s Text to escape
-     * @param fs Font state
+     * @param fontUse Font use
      * @param useMultiByte Indicates the use of multi byte convention
      * @param pdf target buffer for the escaped text
      */
-    public void escapeText(String s, Font fs,
+    public void escapeText(String s, FontUse fontUse,
                            boolean useMultiByte, StringBuffer pdf) {
         String startText = useMultiByte ? "<" : "(";
         String endText = useMultiByte ? "> " : ") ";
 
         boolean kerningAvailable = false;
-        Map kerning = fs.getKerning();
-        if (kerning != null && !kerning.isEmpty()) {
-            //kerningAvailable = true;
-            //TODO Reenable me when the layout engine supports kerning, too
-            log.warn("Kerning support is disabled until it is supported by the layout engine!");
-        }
+// TODO vh: kerning is available differently from FOrayFont
+//        Map kerning = font.getKerning();
+//        if (kerning != null && !kerning.isEmpty()) {
+//            //kerningAvailable = true;
+//            //TODO Reenable me when the layout engine supports kerning, too
+//            log.warn("Kerning support is disabled until it is supported by the layout engine!");
+//        }
 
         int l = s.length();
 
         for (int i = 0; i < l; i++) {
-            char ch = fs.mapChar(s.charAt(i));
+            char ch = fontUse.encodeCharacter(fontConsumer, s.charAt(i));
 
             if (!useMultiByte) {
                 if (ch > 127) {
@@ -1237,10 +1244,11 @@
                 pdf.append(PDFText.toUnicodeHex(ch));
             }
 
+            // TODO vh
             if (kerningAvailable && (i + 1) < l) {
-                addKerning(pdf, (new Integer((int) ch)),
-                           (new Integer((int) fs.mapChar(s.charAt(i + 1)))
-                           ), kerning, startText, endText);
+//                addKerning(pdf, (new Integer((int) ch)),
+//                           (new Integer((int) fs.mapChar(s.charAt(i + 1)))
+//                           ), kerning, startText, endText);
             }
         }
     }
@@ -1268,7 +1276,7 @@
             textOpen = false;
             prevWordX = 0;
             prevWordY = 0;
-            currentFontName = "";
+            currentFontUse = null;
         }
     }
 
@@ -1321,14 +1329,15 @@
         updateColor(col, fill, null);
     }
     
-    private void updateFont(String name, int size, StringBuffer pdf) {
-        if ((!name.equals(this.currentFontName))
+    private void updateFont(FontUse fontUse, int size, StringBuffer pdf) {
+        if ((!fontUse.equals(this.currentFontUse))
                 || (size != this.currentFontSize)) {
             closeText();
 
-            this.currentFontName = name;
+            this.currentFontUse = fontUse;
             this.currentFontSize = size;
-            pdf = pdf.append("/" + name + " " + ((float) size / 1000f)
+            String internalName = (String) this.fontMap.getInternalName(fontUse);
+            pdf = pdf.append("/" + internalName + " " + ((float) size / 1000f)
                               + " Tf\n");
         }
     }
@@ -1475,8 +1484,8 @@
                             new Integer(currentIPPosition + (int) pos.getX()));
         context.setProperty(PDFSVGHandler.PDF_YPOS,
                             new Integer(currentBPPosition + (int) pos.getY()));
-        context.setProperty(PDFSVGHandler.PDF_FONT_INFO, fontInfo);
-        context.setProperty(PDFSVGHandler.PDF_FONT_NAME, currentFontName);
+        context.setProperty(PDFSVGHandler.PDF_FONT_CONSUMER, fontConsumer);
+        context.setProperty(PDFSVGHandler.PDF_FONT_USE, currentFontUse);
         context.setProperty(PDFSVGHandler.PDF_FONT_SIZE,
                             new Integer(currentFontSize));
         context.setProperty(PDFSVGHandler.PDF_WIDTH,
Index: src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java	(révision 356368)
+++ src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java	(copie de travail)
@@ -24,13 +24,10 @@
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 
-import org.apache.batik.bridge.ViewBox;
 import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.Graphics2DImagePainter;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.svg.PDFGraphics2D;
-import org.w3c.dom.svg.SVGDocument;
-import org.w3c.dom.svg.SVGSVGElement;
 
 /**
  * Graphics2DAdapter implementation for PDF.
@@ -82,9 +79,9 @@
 
         final boolean textAsShapes = false;
         PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes, 
-                pdfInfo.fi, pdfInfo.pdfDoc,
+                renderer.getFontMap(), pdfInfo.pdfDoc,
                 pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),
-                renderer.currentFontName,
+                renderer.currentFontUse,
                 renderer.currentFontSize);
         graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
         
Index: src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFSVGHandler.java	(révision 356368)
+++ src/java/org/apache/fop/render/pdf/PDFSVGHandler.java	(copie de travail)
@@ -20,19 +20,20 @@
 
 import org.apache.fop.render.XMLHandler;
 import org.apache.fop.render.RendererContext;
+import org.apache.fop.pdf.FontMap;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFNumber;
 import org.apache.fop.pdf.PDFPage;
+import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFState;
 import org.apache.fop.pdf.PDFStream;
-import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.svg.PDFBridgeContext;
-import org.apache.fop.svg.PDFTextElementBridge;
-import org.apache.fop.svg.PDFAElementBridge;
 import org.apache.fop.svg.PDFGraphics2D;
 import org.apache.fop.svg.SVGUserAgent;
-import org.apache.fop.fonts.FontInfo;
 
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 // Commons-Logging
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -43,14 +44,12 @@
 
 import java.io.OutputStream;
 
-import org.apache.batik.bridge.Bridge;
 import org.apache.batik.bridge.GVTBuilder;
 import org.apache.batik.bridge.BridgeContext;
 import org.apache.batik.bridge.ViewBox;
 import org.apache.batik.dom.svg.SVGDOMImplementation;
 
 import org.apache.batik.gvt.GraphicsNode;
-import org.apache.batik.util.SVGConstants;
 
 import org.w3c.dom.svg.SVGDocument;
 import org.w3c.dom.svg.SVGSVGElement;
@@ -114,15 +113,15 @@
     /**
      * The current font information for the pdf renderer.
      */
-    public static final String PDF_FONT_INFO = "fontInfo";
+    public static final String PDF_FONT_CONSUMER = "fontConsumer";
 
     /**
-     * The current pdf font name.
+     * The current pdf font use.
      */
-    public static final String PDF_FONT_NAME = "fontName";
+    public static final String PDF_FONT_USE = "fontUse";
 
     /**
-     * The current pdf font size.
+     * The current pdf font size (in millipoints).
      */
     public static final String PDF_FONT_SIZE = "fontSize";
 
@@ -135,11 +134,15 @@
      * The y position that this is being drawn at.
      */
     public static final String PDF_YPOS = "ypos";
+    
+    private FontMap fontMap;
 
     /**
      * Create a new PDF XML handler for use by the PDF renderer.
+     * @param fontMap a mapping of FontUses to their corresponding internal names
      */
-    public PDFSVGHandler() {
+    public PDFSVGHandler(FontMap fontMap) {
+        this.fontMap = fontMap;
     }
 
     /** @see org.apache.fop.render.XMLHandler */
@@ -170,8 +173,8 @@
         pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM);
         pdfi.width = ((Integer)context.getProperty(PDF_WIDTH)).intValue();
         pdfi.height = ((Integer)context.getProperty(PDF_HEIGHT)).intValue();
-        pdfi.fi = (FontInfo) context.getProperty(PDF_FONT_INFO);
-        pdfi.currentFontName = (String)context.getProperty(PDF_FONT_NAME);
+        pdfi.fc = (FontConsumer) context.getProperty(PDF_FONT_CONSUMER);
+        pdfi.currentFontUse = (FontUse)context.getProperty(PDF_FONT_USE);
         pdfi.currentFontSize = ((Integer)context.getProperty(PDF_FONT_SIZE)).intValue();
         pdfi.currentXPosition = ((Integer)context.getProperty(PDF_XPOS)).intValue();
         pdfi.currentYPosition = ((Integer)context.getProperty(PDF_YPOS)).intValue();
@@ -198,10 +201,10 @@
         public int width;
         /** see PDF_HEIGHT */
         public int height;
-        /** see PDF_FONT_INFO */
-        public FontInfo fi;
-        /** see PDF_FONT_NAME */
-        public String currentFontName;
+        /** see PDF_FONT_CONSUMER */
+        public FontConsumer fc;
+        /** see PDF_FONT_USE */
+        public FontUse currentFontUse;
         /** see PDF_FONT_SIZE */
         public int currentFontSize;
         /** see PDF_XPOS */
@@ -243,7 +246,7 @@
 
             final boolean strokeText = false;
             BridgeContext ctx = new PDFBridgeContext(ua, 
-                    (strokeText ? null : pdfInfo.fi),
+                    (strokeText ? null : pdfInfo.fc),
                     linkTransform);
             
             GraphicsNode root;
@@ -292,9 +295,9 @@
             if (pdfInfo.pdfContext == null) {
                 pdfInfo.pdfContext = pdfInfo.pdfPage;
             }
-            PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fi, pdfInfo.pdfDoc,
+            PDFGraphics2D graphics = new PDFGraphics2D(true, fontMap, pdfInfo.pdfDoc,
                                      pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),
-                                     pdfInfo.currentFontName,
+                                     pdfInfo.currentFontUse,
                                      pdfInfo.currentFontSize);
             graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
             pdfInfo.pdfState.push();
@@ -337,4 +340,4 @@
         return SVGDOMImplementation.SVG_NAMESPACE_URI;
     }
     
-}
\ No newline at end of file
+}
Index: src/java/org/apache/fop/render/AbstractRenderer.java
===================================================================
--- src/java/org/apache/fop/render/AbstractRenderer.java	(révision 356368)
+++ src/java/org/apache/fop/render/AbstractRenderer.java	(copie de travail)
@@ -22,8 +22,8 @@
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Iterator;
 import java.util.List;
-import java.util.Iterator;
 import java.util.Set;
 
 // XML
@@ -31,23 +31,25 @@
 
 // FOP
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.BeforeFloat;
 import org.apache.fop.area.Block;
 import org.apache.fop.area.BlockViewport;
 import org.apache.fop.area.BodyRegion;
 import org.apache.fop.area.CTM;
-import org.apache.fop.area.NormalFlow;
 import org.apache.fop.area.Footnote;
 import org.apache.fop.area.LineArea;
 import org.apache.fop.area.MainReference;
-import org.apache.fop.area.Span;
+import org.apache.fop.area.NormalFlow;
+import org.apache.fop.area.OffDocumentItem;
 import org.apache.fop.area.Page;
 import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.RegionReference;
 import org.apache.fop.area.RegionViewport;
-import org.apache.fop.area.RegionReference;
+import org.apache.fop.area.Span;
 import org.apache.fop.area.Trait;
-import org.apache.fop.area.OffDocumentItem;
+import org.apache.fop.area.inline.Character;
 import org.apache.fop.area.inline.Container;
 import org.apache.fop.area.inline.ForeignObject;
 import org.apache.fop.area.inline.Image;
@@ -56,14 +58,11 @@
 import org.apache.fop.area.inline.InlineParent;
 import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.Space;
+import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.Viewport;
-import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.Character;
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.area.inline.SpaceArea;
-import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -72,6 +71,8 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 
+import org.axsl.font.FontConsumer;
+
 /**
  * Abstract base class for all renderers. The Abstract renderer does all the
  * top level processing of the area tree and adds some abstract methods to
@@ -119,9 +120,9 @@
     }
 
     /**
-     *  @see org.apache.fop.render.Renderer#setupFontInfo(FontInfo)
+     *  @see org.apache.fop.render.Renderer#setupFontConsumer(Consumer)
      */
-    public abstract void setupFontInfo(FontInfo fontInfo);
+    public abstract void setupFontConsumer(FontConsumer fontConsumer);
 
     /**
      *  @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
Index: src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java	(copie de travail)
@@ -26,12 +26,14 @@
 import org.apache.fop.area.Block;
 import org.apache.fop.area.LineArea;
 import org.apache.fop.datatypes.Length;
-import org.apache.fop.fonts.Font;
 import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager;
 import org.apache.fop.layoutmgr.inline.LineLayoutManager;
 import org.apache.fop.traits.MinOptMax;
 import org.apache.fop.traits.SpaceVal;
 
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * LayoutManager for a block FO.
  */
@@ -69,12 +71,14 @@
 
     public void initialize() {
         super.initialize();
-        Font fs = getBlockFO().getCommonFont().getFontState(
-                  getBlockFO().getFOEventHandler().getFontInfo(), this);
+        FontConsumer fontConsumer = getBlockFO().getFOEventHandler(); 
+        FontUse fontUse = getBlockFO().getCommonFont().getFontState(
+                  fontConsumer, this);
+        int fontSize = getBlockFO().getCommonFont().getFontSize(this);
         
-        lead = fs.getAscender();
-        follow = -fs.getDescender();
-        middleShift = -fs.getXHeight() / 2;
+        lead = fontUse.getFont().getAscender(fontSize);
+        follow = -fontUse.getFont().getDescender(fontSize);
+        middleShift = -fontUse.getFont().getXHeight(fontSize) / 2;
         lineHeight = getBlockFO().getLineHeight().getOptimum(this).getLength();
         startIndent = getBlockFO().getCommonMarginBlock().startIndent.getValue(this);
         endIndent = getBlockFO().getCommonMarginBlock().endIndent.getValue(this); 
Index: src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java	(copie de travail)
@@ -33,7 +33,6 @@
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.properties.CommonMarginInline;
 import org.apache.fop.fo.properties.SpaceProperty;
-import org.apache.fop.fonts.Font;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthSequence;
@@ -45,10 +44,11 @@
 import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.Position;
 import org.apache.fop.layoutmgr.PositionIterator;
-import org.apache.fop.layoutmgr.inline.InlineStackingLayoutManager.StackingIter;
 import org.apache.fop.traits.MinOptMax;
 import org.apache.fop.traits.SpaceVal;
 
+import org.axsl.font.FontUse;
+
 /**
  * LayoutManager for objects which stack children in the inline direction,
  * such as Inline or Line
@@ -64,7 +64,8 @@
 
     private Position auxiliaryPosition;
 
-    private Font font;
+    private FontUse fontUse;
+    private int fontSize;
 
     /** The alignment adjust property */
     protected Length alignmentAdjust;
@@ -99,7 +100,9 @@
     /** @see LayoutManager#initialize */
     public void initialize() {
         int padding = 0;
-        font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+        fontUse = fobj.getCommonFont().getFontState(
+                fobj.getFOEventHandler().getFontConsumer(), this);
+        fontSize = fobj.getCommonFont().getFontSize(this);
         lineHeight = fobj.getLineHeight();
 
         if (fobj instanceof Inline) {
@@ -210,7 +213,8 @@
 
         SpaceSpecifier leadingSpace = context.getLeadingSpace();
         
-        alignmentContext = new AlignmentContext(font
+        alignmentContext = new AlignmentContext(fontUse.getFont()
+                                    , fontSize
                                     , lineHeight.getOptimum(this).getLength().getValue(this)
                                     , alignmentAdjust
                                     , alignmentBaseline
Index: src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java	(copie de travail)
@@ -18,7 +18,6 @@
 
 package org.apache.fop.layoutmgr.inline;
 
-import java.awt.geom.Rectangle2D;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.inline.Image;
 import org.apache.fop.fo.flow.ExternalGraphic;
Index: src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java	(copie de travail)
@@ -19,25 +19,30 @@
 package org.apache.fop.layoutmgr.inline;
 
 import org.apache.fop.fo.flow.PageNumberCitation;
+import org.apache.fop.fo.properties.CommonFont;
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.area.Resolvable;
 import org.apache.fop.area.Trait;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.UnresolvedPageNumber;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.fonts.Font;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.TraitSetter;
 
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * LayoutManager for the fo:page-number-citation formatting object
  */
 public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager {
 
     private PageNumberCitation fobj;
-    private Font font;
+    private FontConsumer fontConsumer;
+    private FontUse fontUse;
+    private int fontSize;
     
     // whether the page referred to by the citation has been resolved yet
     private boolean resolved = false;
@@ -55,7 +60,10 @@
     
     /** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
     public void initialize() {
-        font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+        fontConsumer = fobj.getFOEventHandler();
+        CommonFont commonFont = fobj.getCommonFont();
+        fontUse = commonFont.getFontState(fontConsumer, this);
+        fontSize = commonFont.getFontSize(this);
         setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
     }
 
@@ -64,7 +72,8 @@
      */
     protected AlignmentContext makeAlignmentContext(LayoutContext context) {
         return new AlignmentContext(
-                font
+                fontUse.getFont()
+                , fontSize
                 , fobj.getLineHeight().getOptimum(this).getLength().getValue(this)
                 , fobj.getAlignmentAdjust()
                 , fobj.getAlignmentBaseline()
@@ -110,17 +119,18 @@
             resolved = true;
         } else {
             resolved = false;
-            inline = new UnresolvedPageNumber(fobj.getRefId(), font);
+            inline = new UnresolvedPageNumber(fobj.getRefId(), fontConsumer, fontUse.getFont(), fontSize);
             String str = "MMM"; // reserve three spaces for page number
             int width = getStringWidth(str);
             inline.setIPD(width);
             
         }
         TraitSetter.setProducerID(inline, fobj.getId());
-        inline.setBPD(font.getAscender() - font.getDescender());
-        inline.setBaselineOffset(font.getAscender());
-        inline.addTrait(Trait.FONT_NAME, font.getFontName());
-        inline.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+        int ascender = fontUse.getFont().getAscender(fontSize);
+        inline.setBPD(ascender - fontUse.getFont().getDescender(fontSize));
+        inline.setBaselineOffset(ascender);
+        inline.addTrait(Trait.FONT, fontUse);
+        inline.addTrait(Trait.FONT_SIZE, new Integer(fontSize));
         inline.addTrait(Trait.COLOR, fobj.getColor());
         TraitSetter.addTextDecoration(inline, fobj.getTextDecoration());
         
@@ -132,9 +142,10 @@
      * @return width (in millipoints ??) of the string
      */
     private int getStringWidth(String str) {
+        fontUse.getFont().registerStringUsed(fontConsumer, str);
         int width = 0;
         for (int count = 0; count < str.length(); count++) {
-            width += font.getCharWidth(str.charAt(count));
+            width += fontUse.getFont().width(str.charAt(count), fontSize);
         }
         return width;
     }
Index: src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java	(copie de travail)
@@ -27,7 +27,7 @@
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.fo.FOText;
 import org.apache.fop.fo.flow.Inline;
-import org.apache.fop.fonts.Font;
+import org.apache.fop.fo.properties.CommonFont;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
@@ -42,6 +42,10 @@
 import org.apache.fop.traits.SpaceVal;
 import org.apache.fop.util.CharUtilities;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * LayoutManager for text (a sequence of characters) which generates one
  * or more inline areas.
@@ -112,7 +116,6 @@
     // byte order mark
     private static final char ZERO_WIDTH_NOBREAK_SPACE = '\uFEFF';
 
-    private Font font = null;
     /** Start index of first character in this parent Area */
     private short iAreaStart = 0;
     /** Start index of next TextArea */
@@ -132,6 +135,11 @@
     /** Number of space characters after previous possible break position. */
     private int iNbSpacesPending;
 
+    private FontUse fontUse;
+    private Font font;
+    private FontConsumer fontConsumer;
+    private int fontSize;
+
     private boolean bChanged = false;
     private int iReturnedIndex = 0;
     private short iThisStart = 0;
@@ -161,15 +169,24 @@
     
     /** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
     public void initialize() {
-        font = foText.getCommonFont().getFontState(foText.getFOEventHandler().getFontInfo(), this);
+        fontConsumer = foText.getFOEventHandler();
+        CommonFont commonFont = foText.getCommonFont();
+        fontUse = commonFont.getFontState(fontConsumer, this);
+        font = fontUse.getFont();
+        fontSize = commonFont.getFontSize(this);
+        // Register the characters of this text note for later font embedding
+        for (int i = 0; i < textArray.length; i++) {
+            font.registerCharUsed(fontConsumer, textArray[i]);
+        }
         
         // With CID fonts, space isn't neccesary currentFontState.width(32)
-        spaceCharIPD = font.getCharWidth(' ');
+        spaceCharIPD = font.width(' ', fontSize);
         // Use hyphenationChar property
-        hyphIPD = font.getCharWidth(foText.getCommonHyphenation().hyphenationCharacter);
+        hyphIPD = font.width(foText.getCommonHyphenation().hyphenationCharacter, fontSize);
         // Make half-space: <space> on either side of a word-space)
         SpaceVal ls = SpaceVal.makeLetterSpacing(foText.getLetterSpacing());
-        SpaceVal ws = SpaceVal.makeWordSpacing(foText.getWordSpacing(), ls, font);
+        SpaceVal ws = SpaceVal.makeWordSpacing(foText.getWordSpacing(), ls,
+                font, fontConsumer, fontSize);
         halfWS = new SpaceVal(MinOptMax.multiply(ws.getSpace(), 0.5),
                 ws.isConditional(), ws.isForcing(), ws.getPrecedence());
 
@@ -237,7 +254,7 @@
 
         for (; iNextStart < iStopIndex; iNextStart++) {
             char c = textArray[iNextStart];
-            hyphIPD.opt += font.getCharWidth(c);
+            hyphIPD.opt += font.width(c, fontSize);
             // letter-space?
         }
         // Need to include hyphen size too, but don't count it in the
@@ -295,6 +312,10 @@
 
         // add hyphenation character if the last word is hyphenated
         if (context.isLastArea() && ai.bHyphenated) {
+            // TODO vh: perhaps not the better place to register the hyphenation
+            // character for embedding
+            font.registerCharUsed(fontConsumer,
+                    foText.getCommonHyphenation().hyphenationCharacter);
             realWidth.add(new MinOptMax(hyphIPD));
         }
 
@@ -401,8 +422,8 @@
                                     adjust);
         }
         textArea.setIPD(width.opt + adjust);
-        textArea.setBPD(font.getAscender() - font.getDescender());
-        textArea.setBaselineOffset(font.getAscender());
+        textArea.setBPD(font.getAscender(fontSize) - font.getDescender(fontSize));
+        textArea.setBaselineOffset(font.getAscender(fontSize));
         if (textArea.getBPD() == alignmentContext.getHeight()) {
             textArea.setOffset(0);
         } else {
@@ -441,8 +462,8 @@
                 }
             }
         }
-        textArea.addTrait(Trait.FONT_NAME, font.getFontName());
-        textArea.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+        textArea.addTrait(Trait.FONT, fontUse);
+        textArea.addTrait(Trait.FONT_SIZE, new Integer(fontSize));
         textArea.addTrait(Trait.COLOR, foText.getColor());
         
         TraitSetter.addTextDecoration(textArea, foText.getTextDecoration());
@@ -505,7 +526,7 @@
                         && !(iTempStart > iNextStart
                              && BREAK_CHARS.indexOf(textArray[iTempStart - 1]) >= 0);
                         iTempStart++) {
-                    wordIPD.add(font.getCharWidth(textArray[iTempStart]));
+                    wordIPD.add(font.width(textArray[iTempStart], fontSize));
                 }
                 int iLetterSpaces = iTempStart - iThisStart - 1;
                 // if the last character is '-' or '/' and the next one
@@ -641,7 +662,7 @@
 
             for (int i = iStartIndex; i < iStopIndex; i++) {
                 char c = textArray[i];
-                newIPD.add(new MinOptMax(font.getCharWidth(c)));
+                newIPD.add(new MinOptMax(font.width(c, fontSize)));
             }
             // add letter spaces
             boolean bIsWordEnd
Index: src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java	(copie de travail)
@@ -19,22 +19,28 @@
 package org.apache.fop.layoutmgr.inline;
 
 import org.apache.fop.fo.flow.PageNumber;
+import org.apache.fop.fo.properties.CommonFont;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.Trait;
-import org.apache.fop.fonts.Font;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.TraitSetter;
 import org.apache.fop.traits.MinOptMax;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * LayoutManager for the fo:page-number formatting object
  */
 public class PageNumberLayoutManager extends LeafNodeLayoutManager {
     
     private PageNumber fobj;
-    private Font font;
-    
+    private FontConsumer fontConsumer;
+    private FontUse fontUse;
+    private int fontSize;
+        
     /**
      * Constructor
      *
@@ -48,7 +54,10 @@
     
     /** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#get(LayoutContext) */
     public void initialize() {
-        font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+        fontConsumer = fobj.getFOEventHandler();
+        CommonFont commonFont = fobj.getCommonFont();
+        fontUse = commonFont.getFontState(fontConsumer, this);
+        fontSize = commonFont.getFontSize(this);
         setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
     }
 
@@ -58,7 +67,8 @@
      */
     protected AlignmentContext makeAlignmentContext(LayoutContext context) {
         return new AlignmentContext(
-                font
+                fontUse.getFont()
+                , fontSize
                 , fobj.getLineHeight().getOptimum(this).getLength().getValue(this)
                 , fobj.getAlignmentAdjust()
                 , fobj.getAlignmentBaseline()
@@ -74,13 +84,15 @@
         TextArea text = new TextArea();
         String str = getCurrentPV().getPageNumberString();
         int width = getStringWidth(str);
+        Font f = fontUse.getFont();
+        f.registerStringUsed(fontConsumer, str);
         text.addWord(str, 0);
         text.setIPD(width);
-        text.setBPD(font.getAscender() - font.getDescender());
-        text.setBaselineOffset(font.getAscender());
-        text.addTrait(Trait.FONT_NAME, font.getFontName());
+        text.setBPD(f.getAscender(fontSize) - f.getDescender(fontSize));
+        text.setBaselineOffset(f.getAscender(fontSize));
+        text.addTrait(Trait.FONT, fontUse);
         text.addTrait(Trait.FONT_SIZE,
-                        new Integer(font.getFontSize()));
+                        new Integer(fontSize));
         text.addTrait(Trait.COLOR, fobj.getColor());        
 
         TraitSetter.addTextDecoration(text, fobj.getTextDecoration());
@@ -100,7 +112,7 @@
         ta.setBPD(baseArea.getBPD());
         ta.setOffset(baseArea.getOffset());
         ta.setBaselineOffset(baseArea.getBaselineOffset());
-        ta.addTrait(Trait.FONT_NAME, font.getFontName()); //only to initialize the trait map
+        ta.addTrait(Trait.FONT, fontUse); //only to initialize the trait map
         ta.getTraits().putAll(baseArea.getTraits());
         updateContent(ta);
         return ta;
@@ -122,8 +134,9 @@
      */
     private int getStringWidth(String str) {
         int width = 0;
+        Font f = fontUse.getFont();
         for (int count = 0; count < str.length(); count++) {
-            width += font.getCharWidth(str.charAt(count));
+            width += f.width(str.charAt(count), fontSize);
         }
         return width;
     }
Index: src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java	(copie de travail)
@@ -45,16 +45,16 @@
 import org.apache.fop.layoutmgr.SpaceSpecifier;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.LineArea;
+import org.apache.fop.area.Trait;
 import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.traits.MinOptMax;
 
 import java.util.ListIterator;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.LinkedList;
-import org.apache.fop.area.Trait;
-import org.apache.fop.fonts.Font;
 
-import org.apache.fop.traits.MinOptMax;
+import org.axsl.font.FontUse;
 
 /**
  * LayoutManager for lines. It builds one or more lines containing
@@ -607,8 +607,13 @@
 
     /** @see org.apache.fop.layoutmgr.LayoutManager */
     public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
-        Font fs = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
-        alignmentContext = new AlignmentContext(fs, lineHeight.getValue(this), context.getWritingMode());
+        FontUse fontUse = fobj.getCommonFont().getFontState(
+                fobj.getFOEventHandler().getFontConsumer(), this);
+        int fontSize = fobj.getCommonFont().getFontSize(this);
+        alignmentContext = new AlignmentContext(fontUse.getFont(),
+                                                fontSize,
+                                                lineHeight.getValue(this),
+                                                context.getWritingMode());
         context.setAlignmentContext(alignmentContext);
         // Get a break from currently active child LM
         // Set up constraints for inline level managers
Index: src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java	(copie de travail)
@@ -22,8 +22,9 @@
 import org.apache.fop.datatypes.LengthBase;
 import org.apache.fop.datatypes.SimplePercentBaseContext;
 import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Font;
 
+import org.axsl.font.Font;
+
 /**
  * The alignment context is carried within a LayoutContext and as
  * part of the Knuth Inline elements to facilitate proper line building.
@@ -109,6 +110,7 @@
     /**
      * Creates a new instance of AlignmentContext
      * @param font the font
+     * @param fontSize the font size in millipoints
      * @param lineHeight the computed value of the lineHeight property
      * @param alignmentAdjust the alignment-adjust property
      * @param alignmentBaseline the alignment-baseline property
@@ -117,17 +119,18 @@
      * @param parentAlignmentContext the parent alignment context
      */
     public AlignmentContext(Font font
+                            , int fontSize
                             , int lineHeight
                             , Length alignmentAdjust
                             , int alignmentBaseline
                             , Length baselineShift
                             , int dominantBaseline
                             , AlignmentContext parentAlignmentContext) {
-        this.areaHeight = font.getAscender() - font.getDescender();
+        this.areaHeight = font.getAscender(fontSize) - font.getDescender(fontSize);
         this.lineHeight = lineHeight;
         this.parentAlignmentContext = parentAlignmentContext;
         this.scaledBaselineTable = parentAlignmentContext.getScaledBaselineTable();
-        this.xHeight = font.getXHeight();
+        this.xHeight = font.getXHeight(fontSize);
         setAlignmentBaselineIdentifier(alignmentBaseline
                                        , parentAlignmentContext.getDominantBaselineIdentifier());
         setBaselineShift(baselineShift);
@@ -152,11 +155,13 @@
                 dominantBaselineIdentifier = dominantBaseline;
                 break;
         }
-        actualBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font, 
+        actualBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
+                                                            fontSize, 
                                                             dominantBaselineIdentifier, 
                                                             scaledBaselineTable.getWritingMode());
         if (newScaledBaselineTableRequired) {
-            scaledBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font, 
+            scaledBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
+                                    fontSize,
                                     dominantBaselineIdentifier, 
                                     scaledBaselineTable.getWritingMode());
         }
@@ -167,19 +172,20 @@
      * Creates a new instance of AlignmentContext based simply
      * on the font and the writing mode.
      * @param font the font
+     * @param fontSize the font size in millipoints
      * @param lineHeight the computed value of the lineHeight property
      * @param writingMode the current writing mode
      */
-    public AlignmentContext(Font font, int lineHeight, int writingMode) {
-        this.areaHeight = font.getAscender() - font.getDescender();
+    public AlignmentContext(Font font, int fontSize, int lineHeight, int writingMode) {
+        this.areaHeight = font.getAscender(fontSize) - font.getDescender(fontSize);
         this.lineHeight = lineHeight;
-        this.xHeight = font.getXHeight();
+        this.xHeight = font.getXHeight(fontSize);
         this.parentAlignmentContext = null;
-        this.scaledBaselineTable 
-                    = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font, writingMode);
+        this.scaledBaselineTable = ScaledBaselineTableFactory.
+                makeFontScaledBaselineTable(font, fontSize, writingMode);
         this.actualBaselineTable = scaledBaselineTable;
         this.alignmentBaselineIdentifier = getDominantBaselineIdentifier();
-        this.alignmentPoint = font.getAscender();
+        this.alignmentPoint = font.getAscender(fontSize);
         this.baselineShiftValue = 0;
     }
     
Index: src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java	(copie de travail)
@@ -24,7 +24,8 @@
 import org.apache.fop.area.inline.Space;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.fo.flow.Leader;
-import org.apache.fop.fonts.Font;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.properties.CommonFont;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
 import org.apache.fop.layoutmgr.KnuthPenalty;
@@ -39,15 +40,19 @@
 
 import java.util.List;
 import java.util.LinkedList;
-import org.apache.fop.fo.FObj;
 
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * LayoutManager for the fo:leader formatting object
  */
 public class LeaderLayoutManager extends LeafNodeLayoutManager {
     private Leader fobj;
-    private Font font = null;
-    
+    FontUse fontUse = null;
+    private int fontSize;
+    private FontConsumer fontConsumer;
+
     private LinkedList contentList = null;
     private ContentLayoutManager clm = null;
     
@@ -65,7 +70,10 @@
     
     /** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
     public void initialize() {
-        font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+        fontConsumer = fobj.getFOEventHandler();
+        CommonFont commonFont = fobj.getCommonFont();        
+        fontUse = commonFont.getFontState(fontConsumer, this);
+        fontSize = commonFont.getFontSize(this);
         // the property leader-alignment does not affect vertical positioning
         // (see section 7.21.1 in the XSL Recommendation)
         // setAlignment(node.getLeaderAlignment());
@@ -129,13 +137,14 @@
             TextArea t = new TextArea();
             char dot = '.'; // userAgent.getLeaderDotCharacter();
 
-            int width = font.getCharWidth(dot);
+            int width = fontUse.getFont().width(dot, fontSize);
+            fontUse.getFont().registerCharUsed(fontConsumer, dot);
             t.addWord("" + dot, 0);
             t.setIPD(width);
             t.setBPD(width);
             t.setBaselineOffset(width);
-            t.addTrait(Trait.FONT_NAME, font.getFontName());
-            t.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+            t.addTrait(Trait.FONT, fontUse);
+            t.addTrait(Trait.FONT_SIZE, new Integer(fontSize));
             t.addTrait(Trait.COLOR, fobj.getColor());
             Space spacer = null;
             if (fobj.getLeaderPatternWidth().getValue(this) > width) {
Index: src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java	(copie de travail)
@@ -19,7 +19,7 @@
 package org.apache.fop.layoutmgr.inline;
 
 import org.apache.fop.fo.flow.Character;
-import org.apache.fop.fonts.Font;
+import org.apache.fop.fo.properties.CommonFont;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
 import org.apache.fop.layoutmgr.KnuthPenalty;
@@ -36,8 +36,11 @@
 import java.util.LinkedList;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.layoutmgr.inline.AlignmentContext;
-import org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager.AreaInfo;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * LayoutManager for the fo:character formatting object
  */
@@ -45,7 +48,10 @@
     private Character fobj;
     private MinOptMax letterSpaceIPD;
     private int hyphIPD;
-    private Font font;
+    private FontUse fontUse;
+    private FontConsumer fontConsumer;
+    /** Font size in millipoints */
+    private int fontSize;
     private CommonBorderPaddingBackground borderProps = null;
 
     /**
@@ -61,14 +67,18 @@
     
     /** @see org.apache.fop.layoutmgr.LayoutManager#initialize */
     public void initialize() {
-        font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this);
+        fontConsumer = fobj.getFOEventHandler();
+        CommonFont commonFont = fobj.getCommonFont();
+        fontUse = commonFont.getFontState(fontConsumer, this);
+        fontSize = commonFont.getFontSize(this);
         SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing());
         letterSpaceIPD = ls.getSpace();
-        hyphIPD = font.getCharWidth(fobj.getCommonHyphenation().hyphenationCharacter);
+        hyphIPD = fontUse.getFont().width(fobj.getCommonHyphenation().hyphenationCharacter,
+                           fontSize);
         borderProps = fobj.getCommonBorderPaddingBackground();
         setCommonBorderPaddingBackground(borderProps);
         org.apache.fop.area.inline.Character chArea = getCharacterInlineArea(fobj);
-        chArea.setBaselineOffset(font.getAscender());
+        chArea.setBaselineOffset(fontUse.getFont().getAscender(fontSize));
         setCurrentArea(chArea);
     }
 
@@ -91,18 +101,22 @@
             return null;
         }
 
-        ipd = new MinOptMax(font.getCharWidth(fobj.getCharacter()));
+        Font font = fontUse.getFont();
+        char curChar = fobj.getCharacter();
+        ipd = new MinOptMax(font.width(curChar, fontSize));
+        font.registerCharUsed(fontConsumer, curChar);
 
         curArea.setIPD(ipd.opt);
-        curArea.setBPD(font.getAscender() - font.getDescender());
+        curArea.setBPD(font.getAscender(fontSize) - font.getDescender(fontSize));
 
-        curArea.addTrait(Trait.FONT_NAME, font.getFontName());
-        curArea.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+        curArea.addTrait(Trait.FONT, fontUse);
+        curArea.addTrait(Trait.FONT_SIZE, new Integer(fontSize));
         curArea.addTrait(Trait.COLOR, fobj.getColor());
 
         // TODO: may need some special handling for fo:character
         alignmentContext = new AlignmentContext(font
-                                    , font.getFontSize()
+                                    , fontSize
+                                    , fontSize
                                     , fobj.getAlignmentAdjust()
                                     , fobj.getAlignmentBaseline()
                                     , fobj.getBaselineShift()
Index: src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java	(révision 356368)
+++ src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java	(copie de travail)
@@ -19,9 +19,10 @@
 package org.apache.fop.layoutmgr.inline;
 
 import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Font;
 
+import org.axsl.font.Font;
 
+
 /**
  * A factory class for making alignment contexts.
  * Currently supports alignment contexts for basic fonts
@@ -33,26 +34,31 @@
      * Creates a new instance of BasicScaledBaselineTable for the given
      * font, baseline and writingmode.
      * @param font the font for which a baseline table is requested
+     * @param fontSize the font size
      * @param dominantBaselineIdentifier the dominant baseline given as an integer constant
      * @param writingMode the writing mode given as an integer constant
      * @return a scaled baseline table for the given font
      */
     public static ScaledBaselineTable makeFontScaledBaselineTable(Font font
+                                                                  , int fontSize
                                                                   , int dominantBaselineIdentifier
                                                                   , int writingMode) {
-        return new BasicScaledBaselineTable(font.getAscender(), font.getDescender()
-                                    , font.getXHeight(), dominantBaselineIdentifier, writingMode);
+        return new BasicScaledBaselineTable(font.getAscender(fontSize), font.getDescender(fontSize),
+                font.getXHeight(fontSize), dominantBaselineIdentifier, writingMode);
     }
     
     /**
      * Creates a new instance of BasicScaledBaselineTable for the given
      * font and writingmode. It assumes an alphabetic baseline.
      * @param font the font for which a baseline table is requested
+     * @param fontSize the font size
      * @param writingMode the writing mode given as an integer constant
      * @return a scaled baseline table for the given font
      */
-    public static ScaledBaselineTable makeFontScaledBaselineTable(Font font, int writingMode) {
-        return makeFontScaledBaselineTable(font, EN_ALPHABETIC, writingMode);
+    public static ScaledBaselineTable makeFontScaledBaselineTable(Font font
+                                                                  , int fontSize
+                                                                  , int writingMode) {
+        return makeFontScaledBaselineTable(font, fontSize, EN_ALPHABETIC, writingMode);
     }
     
     /**
Index: src/java/org/apache/fop/svg/PDFTextPainter.java
===================================================================
--- src/java/org/apache/fop/svg/PDFTextPainter.java	(révision 356368)
+++ src/java/org/apache/fop/svg/PDFTextPainter.java	(copie de travail)
@@ -22,7 +22,7 @@
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 /* java.awt.Font is not imported to avoid confusion with
-   org.apache.fop.fonts.Font */
+   org.axsl.font.Font */
 import java.text.AttributedCharacterIterator;
 import java.awt.font.TextAttribute;
 import java.awt.Shape;
@@ -41,9 +41,11 @@
 import org.apache.batik.bridge.SVGFontFamily;
 import org.apache.batik.gvt.renderer.StrokingTextPainter;
 
-import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontServer;
+import org.axsl.font.FontUse;
 
 /**
  * Renders the attributed character iterator of a <tt>TextNode</tt>.
@@ -60,7 +62,7 @@
  * @version $Id: PDFTextPainter.java,v 1.16 2003/03/07 09:51:25 jeremias Exp $
  */
 public class PDFTextPainter implements TextPainter {
-    private FontInfo fontInfo;
+    private FontConsumer fontConsumer;
 
     /**
      * Use the stroking text painter to get the bounds and shape.
@@ -73,8 +75,8 @@
      * Create a new PDF text painter with the given font information.
      * @param fi the fint info
      */
-    public PDFTextPainter(FontInfo fi) {
-        fontInfo = fi;
+    public PDFTextPainter(FontConsumer fc) {
+        fontConsumer = fc;
     }
 
     /**
@@ -114,10 +116,12 @@
         
         Paint forg = tpi.fillPaint;
         Paint strokePaint = tpi.strokePaint;
-        Float size = (Float) aci.getAttribute(TextAttribute.SIZE);
-        if (size == null) {
+        Float fsize = (Float) aci.getAttribute(TextAttribute.SIZE);
+        if (fsize == null) {
             return;
         }
+        int size = (int) (fsize.floatValue() * 1000f);
+        
         Stroke stroke = tpi.strokeStroke;
         /*
         Float xpos = (Float) aci.getAttribute(
@@ -156,75 +160,78 @@
             return;
         }
 
-        String style = ((posture != null) && (posture.floatValue() > 0.0))
-                       ? "italic" : "normal";
-        int weight = ((taWeight != null)
-                       &&  (taWeight.floatValue() > 1.0)) ? Font.BOLD
-                       : Font.NORMAL;
+        byte style = ((posture != null) && (posture.floatValue() > 0.0))
+                       ? Font.FONT_STYLE_ITALIC : Font.FONT_STYLE_NORMAL;
+        short weight = ((taWeight != null)
+                       &&  (taWeight.floatValue() > 1.0)) ? Font.FONT_WEIGHT_BOLD
+                       : Font.FONT_WEIGHT_NORMAL;
 
-        Font fontState = null;
-        FontInfo fi = fontInfo;
-        boolean found = false;
+        FontUse fontUse = null;
+        FontServer fs = fontConsumer.getFontServer();
+        boolean found = true;
         String fontFamily = null;
         if (gvtFonts != null) {
             Iterator i = gvtFonts.iterator();
+            String[] fontFamilies = new String[gvtFonts.size()];
+            int index = 0;
             while (i.hasNext()) {
                 GVTFontFamily fam = (GVTFontFamily) i.next();
                 if (fam instanceof SVGFontFamily) {
                     PROXY_PAINTER.paint(node, g2d);
                     return;
                 }
-                fontFamily = fam.getFamilyName();
-                if (fi.hasFont(fontFamily, style, weight)) {
-                    String fname = fontInfo.fontLookup(fontFamily, style,
-                                                       weight);
-                    FontMetrics metrics = fontInfo.getMetricsFor(fname);
-                    int fsize = (int)(size.floatValue() * 1000);
-                    fontState = new Font(fname, metrics, fsize);
-                    found = true;
-                    break;
-                }
+                fontFamilies[index++] = fam.getFamilyName();
             }
+            try {
+                fontUse = fs.selectFontXSL(fontConsumer, fontFamilies, style, weight,
+                        Font.FONT_VARIANT_NORMAL, Font.FONT_STRETCH_NORMAL, size, ch);
+                fontFamily = fontUse.postscriptName();
+            } catch (FontException f) {
+                found = false;
+            }
         }
         if (!found) {
-            String fname =
-              fontInfo.fontLookup("any", style, Font.NORMAL);
-            FontMetrics metrics = fontInfo.getMetricsFor(fname);
-            int fsize = (int)(size.floatValue() * 1000);
-            fontState = new Font(fname, metrics, fsize);
+            try {
+                fontUse = fs.selectFontXSL(fontConsumer, new String[] {"any"},
+                        Font.FONT_STYLE_ANY,
+                        Font.FONT_WEIGHT_ANY,
+                        Font.FONT_VARIANT_ANY,
+                        Font.FONT_STRETCH_ANY,
+                        size, ch);
+            } catch (FontException e) { /* Should never happen */ }
         } else {
             if (g2d instanceof PDFGraphics2D) {
-                ((PDFGraphics2D) g2d).setOverrideFontState(fontState);
+                ((PDFGraphics2D) g2d).setOverrideFontUse(fontUse);
+                ((PDFGraphics2D) g2d).setOverrideFontSize(size);
             }
         }
         int fStyle = java.awt.Font.PLAIN;
-        if (weight == Font.BOLD) {
-            if (style.equals("italic")) {
+        if (weight == Font.FONT_WEIGHT_BOLD) {
+            if (style == Font.FONT_STYLE_ITALIC) {
                 fStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
             } else {
                 fStyle = java.awt.Font.BOLD;
             }
         } else {
-            if (style.equals("italic")) {
+            if (style == Font.FONT_STYLE_ITALIC) {
                 fStyle = java.awt.Font.ITALIC;
             } else {
                 fStyle = java.awt.Font.PLAIN;
             }
         }
-        java.awt.Font font = new java.awt.Font(fontFamily, fStyle,
-                             (int)(fontState.getFontSize() / 1000));
+        java.awt.Font awtFont = new java.awt.Font(fontFamily, fStyle, size / 1000);
 
-        g2d.setFont(font);
+        g2d.setFont(awtFont);
 
-        float advance = getStringWidth(txt, fontState);
+        float advance = fontUse.getFont().width(txt, size, 0, 0) / 1000f;
         float tx = 0;
         if (anchor != null) {
             switch (anchor.getType()) {
                 case TextNode.Anchor.ANCHOR_MIDDLE:
-                    tx = -advance / 2;
+                    tx = -advance / 2000f; // convert back into points 
                     break;
                 case TextNode.Anchor.ANCHOR_END:
-                    tx = -advance;
+                    tx = -advance / 1000f;
             }
         }
         g2d.drawString(txt, (float)(loc.getX() + tx), (float)(loc.getY()));
@@ -261,26 +268,6 @@
         return hasunsupported;
     }
 
-    private float getStringWidth(String str, Font fontState) {
-        float wordWidth = 0;
-        float whitespaceWidth = fontState.getWidth(fontState.mapChar(' '));
-
-        for (int i = 0; i < str.length(); i++) {
-            float charWidth;
-            char c = str.charAt(i);
-            if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
-                charWidth = fontState.getWidth(fontState.mapChar(c));
-                if (charWidth <= 0) {
-                    charWidth = whitespaceWidth;
-                }
-            } else {
-                charWidth = whitespaceWidth;
-            }
-            wordWidth += charWidth;
-        }
-        return wordWidth / 1000f;
-    }
-
     /**
      * Get the outline shape of the text characters.
      * This uses the StrokingTextPainter to get the outline
@@ -397,4 +384,3 @@
     }
 
 }
-
Index: src/java/org/apache/fop/svg/PDFTextElementBridge.java
===================================================================
--- src/java/org/apache/fop/svg/PDFTextElementBridge.java	(révision 356368)
+++ src/java/org/apache/fop/svg/PDFTextElementBridge.java	(copie de travail)
@@ -24,7 +24,7 @@
 import org.apache.batik.bridge.TextUtilities;
 import org.apache.batik.gvt.GraphicsNode;
 
-import org.apache.fop.fonts.FontInfo;
+import org.axsl.font.FontConsumer;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -41,10 +41,10 @@
 
     /**
      * Constructs a new bridge for the &lt;text> element.
-     * @param fi the font infomration
+     * @param fc the font consumer
      */
-    public PDFTextElementBridge(FontInfo fi) {
-        pdfTextPainter = new PDFTextPainter(fi);
+    public PDFTextElementBridge(FontConsumer fc) {
+        pdfTextPainter = new PDFTextPainter(fc);
     }
 
     /**
Index: src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
===================================================================
--- src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java	(révision 356368)
+++ src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java	(copie de travail)
@@ -18,6 +18,7 @@
 
 package org.apache.fop.svg;
 
+import org.apache.fop.pdf.FontMap;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFFilterList;
 import org.apache.fop.pdf.PDFPage;
@@ -27,8 +28,6 @@
 import org.apache.fop.pdf.PDFResources;
 import org.apache.fop.pdf.PDFColor;
 import org.apache.fop.pdf.PDFAnnotList;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.avalon.framework.CascadingRuntimeException;
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.configuration.Configurable;
@@ -101,17 +100,12 @@
      *
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
+     * @param fontMap mappings of FontUses to their associated internal names.
      */
-    public PDFDocumentGraphics2D(boolean textAsShapes) {
-        super(textAsShapes);
+    public PDFDocumentGraphics2D(boolean textAsShapes, FontMap fontMap) {
+        super(textAsShapes, fontMap);
 
         this.pdfContext = new PDFContext();
-        if (!textAsShapes) {
-            fontInfo = new FontInfo();
-            FontSetup.setup(fontInfo, null);
-            //FontState fontState = new FontState("Helvetica", "normal",
-            //                          FontInfo.NORMAL, 12, 0);
-        }
         try {
             initialize();
         } catch (Exception e) {
@@ -128,15 +122,16 @@
      *
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
+     * @param fontMap mappings of FontUses to their associated internal names.
      * @param stream the stream that the final document should be written to.
      * @param width the width of the document
      * @param height the height of the document
      * @throws IOException an io exception if there is a problem
      *         writing to the output stream
      */
-    public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
+    public PDFDocumentGraphics2D(boolean textAsShapes, FontMap fontMap, OutputStream stream,
                                  int width, int height) throws IOException {
-        this(textAsShapes);
+        this(textAsShapes, fontMap);
         setupDocument(stream, width, height);
     }
 
@@ -147,9 +142,10 @@
      * for the bridge before the document size is known.
      * The resulting document is written to the stream after rendering.
      * This constructor is Avalon-style.
+     * @param fontMap mappings of FontUses to their associated internal names.
      */
-    public PDFDocumentGraphics2D() {
-        this(false);
+    public PDFDocumentGraphics2D(FontMap fontMap) {
+        this(false, fontMap);
     }
 
     /**
@@ -157,20 +153,12 @@
      */
     public void configure(Configuration cfg) throws ConfigurationException {
         this.cfg = cfg;
-        this.pdfContext.setFontList(FontSetup.buildFontListFromConfiguration(cfg));
     }
 
     /**
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        if (this.fontInfo == null) {
-            fontInfo = new FontInfo();
-            FontSetup.setup(fontInfo, this.pdfContext.getFontList());
-            //FontState fontState = new FontState("Helvetica", "normal",
-            //                          FontInfo.NORMAL, 12, 0);
-        }
-
         this.pdfDoc = new PDFDocument("Apache FOP: SVG to PDF Transcoder");
 
         if (this.cfg != null) {
@@ -212,14 +200,6 @@
     }
 
     /**
-     * Get the font info for this pdf document.
-     * @return the font information
-     */
-    public FontInfo getFontInfo() {
-        return fontInfo;
-    }
-
-    /**
      * Get the pdf document created by this class.
      * @return the pdf document
      */
@@ -321,7 +301,7 @@
             setClip(this.initialClip);
         }
 
-        currentFontName = "";
+        currentFontUse = null;
         currentFontSize = 0;
 
         if (currentStream == null) {
@@ -372,8 +352,8 @@
         // restorePDFState();
 
         closePage();
-        if (fontInfo != null) {
-            pdfDoc.getResources().addFonts(pdfDoc, fontInfo);
+        if (fontMap.getSize() != 0) {
+            pdfDoc.getResources().addFonts(pdfDoc, fontMap);
         }
         this.pdfDoc.output(outputStream);
         pdfDoc.outputTrailer(outputStream);
Index: src/java/org/apache/fop/svg/PDFGraphics2D.java
===================================================================
--- src/java/org/apache/fop/svg/PDFGraphics2D.java	(révision 356368)
+++ src/java/org/apache/fop/svg/PDFGraphics2D.java	(copie de travail)
@@ -18,6 +18,7 @@
 
 package org.apache.fop.svg;
 
+import org.apache.fop.pdf.FontMap;
 import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFResources;
 import org.apache.fop.pdf.PDFGState;
@@ -32,13 +33,7 @@
 import org.apache.fop.pdf.PDFLink;
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.BitmapImage;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontSetup;
-import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.LazyFont;
 import org.apache.fop.image.JpegImage;
-import org.apache.fop.fonts.CIDFont;
 import org.apache.fop.render.pdf.FopPDFImage;
 
 import org.apache.batik.ext.awt.g2d.AbstractGraphics2D;
@@ -50,6 +45,11 @@
 import org.apache.batik.gvt.PatternPaint;
 import org.apache.batik.gvt.GraphicsNode;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontUse;
+
 import java.text.AttributedCharacterIterator;
 import java.text.CharacterIterator;
 import java.awt.Graphics;
@@ -137,30 +137,36 @@
     protected int[] jpegCount = {0};
 
     /**
-     * The current font information.
+     * The font map.
      */
-    protected FontInfo fontInfo;
+    protected FontMap fontMap;
 
     /**
      * The override font state used when drawing text and the font cannot be
      * set using java fonts.
      */
-    protected Font ovFontState = null;
+    protected FontUse ovFontUse = null;
 
     /**
+     * The override font size (in millipoint) used when drawing text and the font cannot be
+     * set using java fonts.
+     */
+    protected int ovFontSize;
+
+    /**
      * the current stream to add PDF commands to
      */
     protected StringWriter currentStream = new StringWriter();
 
     /**
-     * the current (internal) font name
+     * the current font use
      */
-    protected String currentFontName;
+    protected FontUse currentFontUse;
 
     /**
      * the current font size in millipoints
      */
-    protected float currentFontSize;
+    protected int currentFontSize;
 
     /**
      * The output stream for the pdf document.
@@ -176,21 +182,20 @@
      * existing document.
      *
      * @param textAsShapes if true then draw text as shapes
-     * @param fi the current font information
+     * @param fontMap the font map
      * @param doc the pdf document for creating pdf objects
      * @param page the current resource context or page
      * @param pref the PDF reference of the current page
-     * @param font the current font name
-     * @param size the current font size
+     * @param fontUse the current font use
+     * @param size the current font size in millipoints
      */
-    public PDFGraphics2D(boolean textAsShapes, FontInfo fi, PDFDocument doc,
-                         PDFResourceContext page, String pref, String font, float size) {
-        this(textAsShapes);
+    public PDFGraphics2D(boolean textAsShapes, FontMap fontMap, PDFDocument doc,
+                         PDFResourceContext page, String pref, FontUse fontUse, int size) {
+        this(textAsShapes, fontMap);
         pdfDoc = doc;
         resourceContext = page;
-        currentFontName = font;
+        currentFontUse = fontUse;
         currentFontSize = size;
-        fontInfo = fi;
         pageRef = pref;
         graphicsState = new PDFState();
     }
@@ -199,9 +204,11 @@
      * Create a new PDFGraphics2D.
      *
      * @param textAsShapes true if drawing text as shapes
+     * @param fontMap the mappings of fonts to their corresponding internal names
      */
-    protected PDFGraphics2D(boolean textAsShapes) {
+    protected PDFGraphics2D(boolean textAsShapes, FontMap fontMap) {
         super(textAsShapes);
+        this.fontMap = fontMap;
     }
 
     /**
@@ -214,18 +221,27 @@
         super(g);
         this.pdfDoc = g.pdfDoc;
         this.resourceContext = g.resourceContext;
-        this.currentFontName = g.currentFontName;
+        this.currentFontUse = g.currentFontUse;
         this.currentFontSize = g.currentFontSize;
-        this.fontInfo = g.fontInfo;
+        this.fontMap = g.fontMap;
         this.pageRef = g.pageRef;
         this.graphicsState = g.graphicsState;
         this.currentStream = g.currentStream;
         this.jpegCount = g.jpegCount;
         this.outputStream = g.outputStream;
-        this.ovFontState = g.ovFontState;
+        this.ovFontUse = g.ovFontUse;
+        this.ovFontSize = g.ovFontSize;
     }
 
     /**
+     * Return the font consumer associated to this document.
+     * @return the font consumer.
+     */
+    public FontConsumer getFontConsumer() {
+        return fontMap.getFontConsumer();
+    }
+    
+    /**
      * Creates a new <code>Graphics</code> object that is
      * a copy of this <code>Graphics</code> object.
      * @return     a new graphics context that is a copy of
@@ -308,18 +324,30 @@
     }
     
     /**
-     * Set the override font state for drawing text.
+     * Set the override font use for drawing text.
      * This is used by the PDF text painter so that it can temporarily
      * set the font state when a java font cannot be used.
      * The next drawString will use this font state.
      *
-     * @param infont the font state to use
+     * @param infont the FontUse to use
      */
-    public void setOverrideFontState(Font infont) {
-        ovFontState = infont;
+    public void setOverrideFontUse(FontUse infont) {
+        ovFontUse = infont;
     }
 
     /**
+     * Set the override font size for drawing text.
+     * This is used by the PDF text painter so that it can temporarily
+     * set the font state when a java font cannot be used.
+     * The next drawString will use this font state.
+     *
+     * @param insize the font size to use
+     */
+    public void setOverrideFontSize(int insize) {
+        ovFontSize = insize;
+    }
+
+    /**
      * Restore the PDF graphics state to the starting state level.
      */
     /* seems not to be used
@@ -639,9 +667,9 @@
      */
     public void dispose() {
         pdfDoc = null;
-        fontInfo = null;
+        fontMap = null;
         currentStream = null;
-        currentFontName = null;
+        currentFontUse = null;
     }
 
     /**
@@ -1021,14 +1049,11 @@
     private boolean createPattern(PatternPaint pp, boolean fill) {
         preparePainting();
 
-        FontInfo fontInfo = new FontInfo();
-        FontSetup.setup(fontInfo, null);
-
         PDFResources res = pdfDoc.getFactory().makeResources();
         PDFResourceContext context = new PDFResourceContext(res);
-        PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo,
+        PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontMap,
                                         pdfDoc, context, pageRef,
-                                        "", 0);
+                                        null, 0);
         pattGraphic.setGraphicContext(new GraphicContext());
         pattGraphic.gc.validateTransformStack();
         pattGraphic.setRenderingHints(this.getRenderingHints());
@@ -1092,7 +1117,7 @@
         /** @todo see if pdfDoc and res can be linked here,
         (currently res <> PDFDocument's resources) so addFonts() 
         can be moved to PDFDocument class */
-        res.addFonts(pdfDoc, fontInfo);
+//        res.addFonts(pdfDoc, fontInfo);
 
         PDFPattern myPat = pdfDoc.getFactory().makePattern(
                                 resourceContext, 1, res, 1, 1, bbox,
@@ -1384,35 +1409,49 @@
     public void drawString(String s, float x, float y) {
         preparePainting();
 
-        Font fontState;
-        if (ovFontState == null) {
+        /*
+         * Explicitely set to null, otherwise the compiler complains that it may
+         * not have been initialized
+         */
+        FontUse fontUse = null;
+        int size;
+        if (ovFontUse == null) {
+            FontConsumer fontConsumer = fontMap.getFontConsumer();
             java.awt.Font gFont = getFont();
             String n = gFont.getFamily();
             if (n.equals("sanserif")) {
                 n = "sans-serif";
             }
-            int siz = gFont.getSize();
-            String style = gFont.isItalic() ? "italic" : "normal";
-            int weight = gFont.isBold() ? Font.BOLD : Font.NORMAL;
-            String fname = fontInfo.fontLookup(n, style, weight);
-            FontMetrics metrics = fontInfo.getMetricsFor(fname);
-            fontState = new Font(fname, metrics, siz * 1000);
+            size = gFont.getSize() * 1000;
+            byte style = gFont.isItalic() ? Font.FONT_STYLE_ITALIC : Font.FONT_STYLE_NORMAL;
+            short weight = gFont.isBold() ? Font.FONT_WEIGHT_BOLD : Font.FONT_WEIGHT_NORMAL;
+            try {
+                fontUse = fontConsumer.getFontServer().selectFontXSL(fontConsumer,
+                        new String[] {n}, style, weight, Font.FONT_VARIANT_NORMAL,
+                        Font.FONT_STRETCH_NORMAL, size, s.charAt(0));
+            } catch (FontException e) {
+                try {
+                    fontUse = fontConsumer.getFontServer().selectFontXSL(fontConsumer,
+                            new String[] {"any"},
+                            Font.FONT_STYLE_ANY,
+                            Font.FONT_WEIGHT_ANY,
+                            Font.FONT_VARIANT_ANY,
+                            Font.FONT_STRETCH_ANY,
+                            size, s.charAt(0));
+                } catch (FontException e1) { /* Should never happen */ }
+            }
         } else {
-            FontMetrics metrics = fontInfo.getMetricsFor(ovFontState.getFontName());
-            fontState = new Font(ovFontState.getFontName(),
-                                      metrics, ovFontState.getFontSize());
-            ovFontState = null;
+            fontUse = ovFontUse;
+            ovFontUse = null;
+            size = ovFontSize;
         }
-        String name;
-        float size;
-        name = fontState.getFontName();
-        size = (float)fontState.getFontSize() / 1000f;
-
-        if ((!name.equals(this.currentFontName))
+        
+        if ((!fontUse.equals(this.currentFontUse))
                 || (size != this.currentFontSize)) {
-            this.currentFontName = name;
+            this.currentFontUse = fontUse;
             this.currentFontSize = size;
-            currentStream.write("/" + name + " " + size + " Tf\n");
+            String name = fontMap.getInternalName(fontUse);
+            currentStream.write("/" + name + " " + ((float)size) / 1000f + " Tf\n");
 
         }
 
@@ -1435,22 +1474,15 @@
         Map kerning = null;
         boolean kerningAvailable = false;
 
+        /* TODO vh: kerning is yet unimplemented
         kerning = fontState.getKerning();
         if (kerning != null && !kerning.isEmpty()) {
             kerningAvailable = true;
         }
+        */
 
         // This assumes that *all* CIDFonts use a /ToUnicode mapping
-        boolean useMultiByte = false;
-        org.apache.fop.fonts.Typeface f =
-            (org.apache.fop.fonts.Typeface)fontInfo.getFonts().get(name);
-        if (f instanceof LazyFont) {
-            if (((LazyFont) f).getRealFont() instanceof CIDFont) {
-                useMultiByte = true;
-            }
-        } else if (f instanceof CIDFont) {
-            useMultiByte = true;
-        }
+        boolean useMultiByte = fontUse.getFont().getFontComplexity() == Font.FONT_COMPOSITE;
 
         // String startText = useMultiByte ? "<FEFF" : "(";
         String startText = useMultiByte ? "<" : "(";
@@ -1475,7 +1507,7 @@
         int l = s.length();
 
         for (int i = 0; i < l; i++) {
-            char ch = fontState.mapChar(s.charAt(i));
+            char ch = fontUse.encodeCharacter(getFontConsumer(), s.charAt(i));
 
             if (!useMultiByte) {
                 if (ch > 127) {
@@ -1496,9 +1528,9 @@
             }
 
             if (kerningAvailable && (i + 1) < l) {
-                addKerning(currentStream, (new Integer((int)ch)),
-                           (new Integer((int)fontState.mapChar(s.charAt(i + 1)))),
-                           kerning, startText, endText);
+//                addKerning(currentStream, (new Integer((int)ch)),
+//                           (new Integer((int)fontState.mapChar(s.charAt(i + 1)))),
+//                           kerning, startText, endText);
             }
 
         }
@@ -1593,17 +1625,18 @@
                 ch = iterator.next()) {
             //Map attr = iterator.getAttributes();
 
-            String name = fontState.getFontName();
-            int size = fontState.getFontSize();
-            if ((!name.equals(this.currentFontName))
-                    || (size != this.currentFontSize)) {
-                this.currentFontName = name;
-                this.currentFontSize = size;
-                currentStream.write("/" + name + " " + (size / 1000)
-                                    + " Tf\n");
+            // TODO vh: commented out because obsolete
+            // anyway it couldn't work (NPE because fontState == null)
+//            int size = fontState.getFontSize();
+//            if ((!fontUse.equals(this.currentFontUse))
+//                    || (size != this.currentFontSize)) {
+//                this.currentFontUse = fontUse;
+//                this.currentFontSize = size;
+//                currentStream.write("/" + name + " " + (size / 1000)
+//                                    + " Tf\n");
+//
+//            }
 
-            }
-
             currentStream.write(PDFNumber.doubleOut(vals[0], DEC) + " "
                                 + PDFNumber.doubleOut(vals[1], DEC) + " "
                                 + PDFNumber.doubleOut(vals[2], DEC) + " "
Index: src/java/org/apache/fop/svg/PDFBridgeContext.java
===================================================================
--- src/java/org/apache/fop/svg/PDFBridgeContext.java	(révision 356368)
+++ src/java/org/apache/fop/svg/PDFBridgeContext.java	(copie de travail)
@@ -23,15 +23,16 @@
 import org.apache.batik.bridge.BridgeContext;
 import org.apache.batik.bridge.DocumentLoader;
 import org.apache.batik.bridge.UserAgent;
-import org.apache.fop.fonts.FontInfo;
 
+import org.axsl.font.FontConsumer;
+
 /**
  * BridgeContext which registers the custom bridges for PDF output.
  */
 public class PDFBridgeContext extends BridgeContext {
     
-    /** The font list. */
-    private final FontInfo fontInfo;
+    /** The font consumer. */
+    private final FontConsumer fontConsumer;
 
     private AffineTransform linkTransform;
     
@@ -39,51 +40,51 @@
      * Constructs a new bridge context.
      * @param userAgent the user agent
      * @param loader the Document Loader to use for referenced documents.
-     * @param fontInfo the font list for the text painter, may be null
+     * @param fontConsumer the font consumer, may be null
      *                 in which case text is painted as shapes
      * @param linkTransform AffineTransform to properly place links,
      *                      may be null
      */
     public PDFBridgeContext(UserAgent userAgent,
                             DocumentLoader loader,
-                            FontInfo fontInfo,
+                            FontConsumer fontConsumer,
                             AffineTransform linkTransform) {
         super(userAgent, loader);
-        this.fontInfo = fontInfo;
+        this.fontConsumer = fontConsumer;
         this.linkTransform = linkTransform;
     }
 
     /**
      * Constructs a new bridge context.
      * @param userAgent the user agent
-     * @param fontInfo the font list for the text painter, may be null
+     * @param fontConsumer the font consumer, may be null
      *                 in which case text is painted as shapes
      * @param linkTransform AffineTransform to properly place links,
      *                      may be null
      */
-    public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo, 
+    public PDFBridgeContext(UserAgent userAgent, FontConsumer fontConsumer, 
                 AffineTransform linkTransform) {
         super(userAgent);
-        this.fontInfo = fontInfo;
+        this.fontConsumer = fontConsumer;
         this.linkTransform = linkTransform;
     }
 
     /**
      * Constructs a new bridge context.
      * @param userAgent the user agent
-     * @param fontInfo the font list for the text painter, may be null
+     * @param fontConsumer the font consumer, may be null
      *                 in which case text is painted as shapes
      */
-    public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo) {
-        this(userAgent, fontInfo, null);
+    public PDFBridgeContext(UserAgent userAgent, FontConsumer fontConsumer) {
+        this(userAgent, fontConsumer, null);
     }
 
     /** @see org.apache.batik.bridge.BridgeContext#registerSVGBridges() */
     public void registerSVGBridges() {
         super.registerSVGBridges();
 
-        if (fontInfo != null) {
-            putBridge(new PDFTextElementBridge(fontInfo));
+        if (fontConsumer != null) {
+            putBridge(new PDFTextElementBridge(fontConsumer));
         }
 
         PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
@@ -100,6 +101,6 @@
     // Make sure any 'sub bridge contexts' also have our bridges.
     public BridgeContext createBridgeContext() {
         return new PDFBridgeContext(getUserAgent(), getDocumentLoader(),
-                                    fontInfo, linkTransform);
+                                    fontConsumer, linkTransform);
     }
 }
Index: src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
===================================================================
--- src/java/org/apache/fop/svg/AbstractFOPTranscoder.java	(révision 356368)
+++ src/java/org/apache/fop/svg/AbstractFOPTranscoder.java	(copie de travail)
@@ -18,10 +18,14 @@
  
 package org.apache.fop.svg;
 
+import java.net.MalformedURLException;
+
 import org.xml.sax.EntityResolver;
 
 import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.commons.logging.Log;
+import org.apache.fop.pdf.FontMap;
+import org.apache.fop.tools.CommonsLogger;
 import org.apache.batik.bridge.UserAgent;
 import org.apache.batik.dom.svg.SVGDOMImplementation;
 import org.apache.batik.dom.util.DocumentFactory;
@@ -32,13 +36,17 @@
 import org.apache.batik.transcoder.image.ImageTranscoder;
 import org.apache.batik.transcoder.keys.BooleanKey;
 import org.apache.batik.util.SVGConstants;
+import org.axsl.common.PseudoLogger;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontServer;
+import org.foray.font.FOrayFontServer;
 import org.w3c.dom.DOMImplementation;
 
 /**
  * This is the common base class of all of FOP's transcoders.
  */
-public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder
-            {
+public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder implements FontConsumer {
 
     /**
      * The key to specify whether to stroke text instead of using text 
@@ -58,20 +66,88 @@
     protected UserAgent userAgent = createUserAgent();
 
     private Log logger;
+    /** PseudoLogger wrapper around logger. For adaptation to the aXSL interface. */
+    private PseudoLogger pseudoLogger;
     private EntityResolver resolver;
 
+    private FontMap fontMap;
+    
+    private FontServer fontServer;
+    
     /**
      * Constructs a new FOP-style transcoder.
+     * 
+     * @param registerAllFonts if <code>true</code>, all the fonts know by font
+     * server will be given an internal font name (this is useful for the PS
+     * transcoder). Otherwise internal names will be assigned only when needed.
      */
-    public AbstractFOPTranscoder() {
+    public AbstractFOPTranscoder(boolean registerAllFonts) {
         hints.put(KEY_DOCUMENT_ELEMENT_NAMESPACE_URI,
                   SVGConstants.SVG_NAMESPACE_URI);
         hints.put(KEY_DOCUMENT_ELEMENT, SVGConstants.SVG_SVG_TAG);
         hints.put(KEY_DOM_IMPLEMENTATION,
                   SVGDOMImplementation.getDOMImplementation());
+
+        try {
+            fontServer = new FOrayFontServer(getPseudoLogger());
+            /* TODO vh: plug font config file */
+            ((FOrayFontServer) fontServer).setBaseFontURL(new java.net.URL("file://"));
+            ((FOrayFontServer) fontServer).setup(
+                    new java.net.URL("file:///path/to/axsl-font-conf.xml"), null);
+        } catch (MalformedURLException e) {
+            // Should never happen
+        } catch (FontException e) {
+            // TODO vh
+            e.printStackTrace();
+        }
+        
+        fontMap = new FontMap(this, registerAllFonts);
     }
     
     /**
+     * @see org.axsl.font.FontConsumer#getFontServer()
+     */
+    public FontServer getFontServer() {
+        return fontServer;
+    }
+    
+    /**
+     * @see org.axsl.font.FontConsumer#getPseudoLogger()
+     */
+    public PseudoLogger getPseudoLogger() {
+        return pseudoLogger; 
+    }
+
+    /**
+     * @see org.axsl.font.FontConsumer#isUsingFreeStandingFonts()
+     */
+    public boolean isUsingFreeStandingFonts() {
+        return true;
+    }
+
+    /**
+     * @see org.axsl.font.FontConsumer#isUsingSystemFonts()
+     */
+    public boolean isUsingSystemFonts() {
+        return false;
+    }
+
+    /**
+     * @see org.axsl.font.FontConsumer#preferFreeStandingFonts()
+     */
+    public boolean preferFreeStandingFonts() {
+        return true;
+    }
+
+    /**
+     * Return the mappings of FontUses to their associated internal names.
+     * @return the font map associated to this transcoder.
+     */
+    protected FontMap getFontMap() {
+        return fontMap;
+    }
+
+    /**
      * Creates and returns the default user agent for this transcoder. Override
      * this method if you need non-default behaviour.
      * @return UserAgent the newly created user agent
@@ -82,6 +158,7 @@
     
     public void setLogger(Log logger) {
         this.logger = logger;
+        this.pseudoLogger = new CommonsLogger(logger);
     }
 
     /**
Index: src/java/org/apache/fop/svg/PDFTranscoder.java
===================================================================
--- src/java/org/apache/fop/svg/PDFTranscoder.java	(révision 356368)
+++ src/java/org/apache/fop/svg/PDFTranscoder.java	(copie de travail)
@@ -82,7 +82,7 @@
      * Constructs a new <tt>ImageTranscoder</tt>.
      */
     public PDFTranscoder() {
-        super();
+        super(false);
         this.handler = new FOPErrorHandler();
     }
 
@@ -118,7 +118,7 @@
                              TranscoderOutput output) 
         throws TranscoderException {
 
-        graphics = new PDFDocumentGraphics2D();
+        graphics = new PDFDocumentGraphics2D(getFontMap());
         
         try {
             if (this.cfg != null) {
@@ -179,7 +179,7 @@
 
     /** @see org.apache.batik.transcoder.SVGAbstractTranscoder#createBridgeContext() */
     protected BridgeContext createBridgeContext() {
-        BridgeContext ctx = new PDFBridgeContext(userAgent, graphics.getFontInfo());
+        BridgeContext ctx = new PDFBridgeContext(userAgent, graphics.getFontConsumer());
         return ctx;
     }
 
Index: src/java/org/apache/fop/apps/FOUserAgent.java
===================================================================
--- src/java/org/apache/fop/apps/FOUserAgent.java	(révision 356368)
+++ src/java/org/apache/fop/apps/FOUserAgent.java	(copie de travail)
@@ -87,6 +87,8 @@
     
     private String baseURL;
     
+    private URL fontCfgURL;
+    
     /** A user settable URI Resolver */
     private URIResolver uriResolver = null;
     /** Our default resolver if none is set */
@@ -411,6 +413,28 @@
             }
             log.info("Base URL set to: " + baseURL);
         }
+        if (userConfig.getChild("font-config-file", false) != null) {
+            try {
+                String fontCfgFile = userConfig.getChild("font-config-file").getValue(null);
+                if (fontCfgFile != null) {
+                    File file = new File(fontCfgFile);
+                    if (file.isAbsolute() || baseURL == null) {
+                        fontCfgFile = "file://" + file.getCanonicalPath(); 
+                        fontCfgFile = fontCfgFile.replace(
+                                System.getProperty("file.separator").charAt(0), '/');
+                    } else {
+                        fontCfgFile = baseURL + fontCfgFile.replace(
+                                System.getProperty("file.separator").charAt(0), '/');
+                    }
+                }
+                setFontCfgURL(new URL(fontCfgFile));
+            } catch (MalformedURLException mue) {
+                log.error("Font config URL in user config is malformed!");
+            } catch (IOException ioe) {
+                log.error("Error converting relative font config file to absolute URL.");
+            }
+            log.info("Font config URL set to: " + fontCfgURL);
+        }
         if (userConfig.getChild("pixelToMillimeter", false) != null) {
             this.resolution = 25.4f / userConfig.getChild("pixelToMillimeter")
                             .getAttributeAsFloat("value", DEFAULT_PX2MM);
@@ -480,6 +504,14 @@
     }
 
     /**
+     * Sets the font config URL.
+     * @param fontCfgURl font config URL
+     */
+    public void setFontCfgURL(URL fontCfgURL) {
+        this.fontCfgURL = fontCfgURL;
+    }
+
+    /**
      * Returns the base URL.
      * @return the base URL
      */
@@ -488,6 +520,14 @@
     }
 
     /**
+     * Returns the font config URL.
+     * @return the font config URL
+     */
+    public URL getFontCfgURL() {
+        return this.fontCfgURL;
+    }
+
+    /**
      * Sets the URI Resolver.
      * @param uriResolver the new URI resolver
      */
Index: src/java/org/apache/fop/fo/FOEventHandler.java
===================================================================
--- src/java/org/apache/fop/fo/FOEventHandler.java	(révision 356368)
+++ src/java/org/apache/fop/fo/FOEventHandler.java	(copie de travail)
@@ -19,12 +19,16 @@
 package org.apache.fop.fo;
 
 // Java
+import java.net.MalformedURLException;
 import java.util.HashSet;
 import java.util.Set;
 import org.xml.sax.SAXException;
 
 // Apache
+import org.apache.commons.logging.Log;
+
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.fo.flow.BasicLink;
 import org.apache.fop.fo.flow.Block;
 import org.apache.fop.fo.flow.BlockContainer;
@@ -45,9 +49,16 @@
 import org.apache.fop.fo.flow.TableRow;
 import org.apache.fop.fo.pagination.Flow;
 import org.apache.fop.fo.pagination.PageSequence;
-import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.tools.CommonsLogger;
 
+// FOrayFont
+import org.axsl.common.PseudoLogger;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontServer;
+import org.foray.font.FOrayFontServer;
 
+
 /**
  * Abstract class defining what should be done with SAX events that map to
  * XSL-FO input. The events are actually captured by fo/FOTreeBuilder, passed
@@ -59,18 +70,13 @@
  * handler that builds a structured (as opposed to formatted) document, such
  * as our MIF and RTF output targets.
  */
-public abstract class FOEventHandler {
+public abstract class FOEventHandler implements FontConsumer {
     
     /** 
      * The FOUserAgent for this process
      */
     protected FOUserAgent foUserAgent;
 
-    /** 
-     * The Font information relevant for this document
-     */
-    protected FontInfo fontInfo;
-
     /**
      * The current set of id's in the FO tree.
      * This is used so we know if the FO tree contains duplicates.
@@ -83,12 +89,93 @@
     protected PropertyListMaker propertyListMaker;
 
     /**
+     * Font server used to provide all needed font informations.
+     */
+    protected static FontServer fontServer;
+
+    private CommonsLogger pseudoLogger;
+    private boolean useFreeStandingFonts;
+    private boolean useSystemFonts;
+    private boolean preferFreeStandingFonts;
+
+    /**
+     * @inheritDoc
+     */
+    public FontServer getFontServer() {
+        return fontServer;
+    }
+    
+    /**
+     * @inheritDoc
+     */
+    public boolean preferFreeStandingFonts() {
+        return preferFreeStandingFonts;
+    }
+    
+    /**
+     * @inheritDoc
+     */
+    public PseudoLogger getPseudoLogger() {
+        return pseudoLogger;
+    }
+    
+    /**
+     * @inheritDoc
+     */
+    public boolean isUsingFreeStandingFonts() {
+        return useFreeStandingFonts;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean isUsingSystemFonts() {
+        return useSystemFonts;
+    }
+
+    /**
+     * Retrieve the font consumer for this document
+     * @return the FontConsumer instance for this document
+     */
+    public FontConsumer getFontConsumer() {
+        return this;
+    }
+
+
+    public FOEventHandler(FOUserAgent foUserAgent, String outputFormat, Log log) {
+        this(foUserAgent);
+        pseudoLogger = new CommonsLogger(log); 
+        if (outputFormat.equals(MimeConstants.MIME_PDF)
+                || outputFormat.equals(MimeConstants.MIME_POSTSCRIPT)) {
+            useFreeStandingFonts = true;
+            useSystemFonts = false;
+            preferFreeStandingFonts = true;
+        } else {
+            useFreeStandingFonts = false;
+            useSystemFonts = true;
+            preferFreeStandingFonts = false;            
+        }
+        if (fontServer == null) {
+            try {
+                fontServer = new FOrayFontServer(getPseudoLogger());
+                /* TODO vh: plug font config file */
+                ((FOrayFontServer) fontServer).setBaseFontURL(new java.net.URL("file://"));
+                ((FOrayFontServer) fontServer).setup(foUserAgent.getFontCfgURL(), null);
+            } catch (MalformedURLException e) { // Should not happen
+            } catch (FontException e) {
+                log.error("Unable to setup the font server");
+            }
+        }
+        /* TODO vh: will have to release */
+        fontServer.registerFontConsumer(this);
+    }
+
+    /**
      * Main constructor
      * @param foUserAgent the apps.FOUserAgent instance for this process
      */
     public FOEventHandler(FOUserAgent foUserAgent) {
         this.foUserAgent = foUserAgent;
-        this.fontInfo = new FontInfo();
     }
 
     /**
@@ -108,14 +195,6 @@
     }
 
     /**
-     * Retrieve the font information for this document
-     * @return the FontInfo instance for this document
-     */
-    public FontInfo getFontInfo() {
-        return this.fontInfo;
-    }
-
-    /**
      * Return the propertyListMaker.
     */
     public PropertyListMaker getPropertyListMaker() {
Index: src/java/org/apache/fop/fo/properties/CommonFont.java
===================================================================
--- src/java/org/apache/fop/fo/properties/CommonFont.java	(révision 356368)
+++ src/java/org/apache/fop/fo/properties/CommonFont.java	(copie de travail)
@@ -27,10 +27,13 @@
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.expr.PropertyException;
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontMetrics;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+import org.axsl.font.FontServer;
+import org.axsl.font.FontUse;
+
 /**
  * Collection of properties used in
  */
@@ -76,13 +79,17 @@
      */
     public int fontWeight;
 
-    private Font fontState;
+    private FontServer fontServer;
 
+    private FontUse fontUse;
+
     /**
      * Create a CommonFont object.
      * @param pList The PropertyList to get properties from.
+     * @param fontServer the server from which to get the font
      */
-    public CommonFont(PropertyList pList) throws PropertyException {
+    public CommonFont(PropertyList pList, FontServer fontServer)
+            throws PropertyException {
         List lst = pList.get(Constants.PR_FONT_FAMILY).getList();
         fontFamily = new String[lst.size()];
         for (int i = 0, c = lst.size(); i < c; i++) {
@@ -99,8 +106,17 @@
         fontStyle = pList.get(Constants.PR_FONT_STYLE).getEnum();
         fontVariant = pList.get(Constants.PR_FONT_VARIANT).getEnum();
         fontWeight = pList.get(Constants.PR_FONT_WEIGHT).getEnum();
+        this.fontServer = fontServer;
     }
-
+    
+    /**
+     * Return the font size based on the properties.
+     * @return the font size in millipoints.
+     */
+    public int getFontSize(PercentBaseContext context) {
+        return fontSize.getValue(context);
+    }
+     
     /** @return the first font-family name in the list */
     public String getFirstFontFamily() {
         return this.fontFamily[0];
@@ -119,57 +135,76 @@
         this.fontFamily = new String[] {value};
         
     }
-    
+
     /**
-     * Create and return a Font object based on the properties. 
+     * Return a font use based on the properties.
      * 
-     * @param fontInfo
-     * @return a Font object.
+     * @param fontConsumer font consumer to which the returned font use will be associated
+     * @return a FontUse instance corresponding to the properties
      */
-    public Font getFontState(FontInfo fontInfo, PercentBaseContext context) {
-        if (fontState == null) {
+    public FontUse getFontState(FontConsumer fontConsumer, PercentBaseContext context) {
+        if (fontUse == null) {
             /**@todo this is ugly. need to improve. */
 
-            int font_weight = 400;
+            short font_weight = Font.FONT_WEIGHT_ANY;
             if (fontWeight == Constants.EN_BOLDER) {
                 // +100 from inherited
             } else if (fontWeight == Constants.EN_LIGHTER) {
                 // -100 from inherited
             } else {
                 switch (fontWeight) {
-                case Constants.EN_100: font_weight = 100; break;
-                case Constants.EN_200: font_weight = 200; break;
-                case Constants.EN_300: font_weight = 300; break;
-                case Constants.EN_400: font_weight = 400; break;
-                case Constants.EN_500: font_weight = 500; break;
-                case Constants.EN_600: font_weight = 600; break;
-                case Constants.EN_700: font_weight = 700; break;
-                case Constants.EN_800: font_weight = 800; break;
-                case Constants.EN_900: font_weight = 900; break;
+                case Constants.EN_100: font_weight = Font.FONT_WEIGHT_100; break;
+                case Constants.EN_200: font_weight = Font.FONT_WEIGHT_200; break;
+                case Constants.EN_300: font_weight = Font.FONT_WEIGHT_300; break;
+                case Constants.EN_400: font_weight = Font.FONT_WEIGHT_400; break;
+                case Constants.EN_500: font_weight = Font.FONT_WEIGHT_500; break;
+                case Constants.EN_600: font_weight = Font.FONT_WEIGHT_600; break;
+                case Constants.EN_700: font_weight = Font.FONT_WEIGHT_700; break;
+                case Constants.EN_800: font_weight = Font.FONT_WEIGHT_800; break;
+                case Constants.EN_900: font_weight = Font.FONT_WEIGHT_900; break;
                 }
             }
 
-            String style = "normal";
+            byte style = Font.FONT_STYLE_NORMAL;
             switch (fontStyle) {
-            case Constants.EN_ITALIC: 
-                style = "italic";
-                break;
-            case Constants.EN_OBLIQUE: 
-                style = "oblique";
-                break;
-            case Constants.EN_BACKSLANT: 
-                style = "backslant";
-                break;
+            case Constants.EN_ITALIC: style = Font.FONT_STYLE_ITALIC; break;
+            case Constants.EN_OBLIQUE: style = Font.FONT_STYLE_OBLIQUE; break;
+            case Constants.EN_BACKSLANT: style = Font.FONT_STYLE_BACKSLANT; break;
             }
-            // NOTE: this is incomplete. font-size may be specified with
-            // various kinds of keywords too
-            //int fontVariant = propertyList.get("font-variant").getEnum();
-            String fname = fontInfo.fontLookup(getFontFamily(), style,
-                                               font_weight);
-            FontMetrics metrics = fontInfo.getMetricsFor(fname);
-            fontState = new Font(fname, metrics, fontSize.getValue(context));
+            byte variant = fontVariant == Constants.EN_SMALL_CAPS ? Font.FONT_VARIANT_SMALL_CAPS
+                    : Font.FONT_VARIANT_NORMAL;
+            byte stretch;
+            /* TODO vh: handle narrower and wider */
+            switch (fontStretch) {
+            case Constants.EN_NORMAL: stretch = Font.FONT_STRETCH_NORMAL; break;
+            case Constants.EN_ULTRA_CONDENSED: stretch = Font.FONT_STRETCH_ULTRA_CONDENSED; break;
+            case Constants.EN_EXTRA_CONDENSED: stretch = Font.FONT_STRETCH_EXTRA_CONDENSED; break;
+            case Constants.EN_CONDENSED: stretch = Font.FONT_STRETCH_CONDENSED; break;
+            case Constants.EN_SEMI_CONDENSED: stretch = Font.FONT_STRETCH_SEMI_CONDENSED; break;
+            case Constants.EN_SEMI_EXPANDED: stretch = Font.FONT_STRETCH_SEMI_EXPANDED; break;
+            case Constants.EN_EXPANDED: stretch = Font.FONT_STRETCH_EXPANDED; break;
+            case Constants.EN_EXTRA_EXPANDED: stretch = Font.FONT_STRETCH_EXTRA_EXPANDED; break;
+            case Constants.EN_ULTRA_EXPANDED: stretch = Font.FONT_STRETCH_ULTRA_EXPANDED; break;
+            default: stretch = Font.FONT_STRETCH_NORMAL;
+            }
+            try {
+                fontUse = fontServer.selectFontXSL(fontConsumer,
+                        getFontFamily(), style, font_weight, variant,
+                        stretch, fontSize.getValue(context), ' '/* TODO vh */);
+            } catch (FontException e) {
+                try {
+                    fontUse = fontServer.selectFontXSL(fontConsumer, new String[] {"any"},
+                            Font.FONT_STYLE_ANY,
+                            Font.FONT_WEIGHT_ANY,
+                            Font.FONT_VARIANT_ANY,
+                            Font.FONT_STRETCH_ANY,
+                            10000, ' ');
+                } catch (FontException e1) {
+                    // Should never happen (see area.RenderPagesModel)
+                }
+            }
         }
-        return fontState;
+        return fontUse;
     }
 
 }
Index: src/java/org/apache/fop/fo/PropertyList.java
===================================================================
--- src/java/org/apache/fop/fo/PropertyList.java	(révision 356368)
+++ src/java/org/apache/fop/fo/PropertyList.java	(copie de travail)
@@ -537,7 +537,7 @@
      * @throws PropertyException if there's a problem while processing the properties
      */
     public CommonFont getFontProps() throws PropertyException {
-        return new CommonFont(this);
+        return new CommonFont(this, this.fobj.getFOEventHandler().getFontServer());
     }
     
     /**
Index: src/java/org/apache/fop/traits/SpaceVal.java
===================================================================
--- src/java/org/apache/fop/traits/SpaceVal.java	(révision 356368)
+++ src/java/org/apache/fop/traits/SpaceVal.java	(copie de travail)
@@ -22,8 +22,10 @@
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.properties.Property;
 import org.apache.fop.fo.properties.SpaceProperty;
-import org.apache.fop.fonts.Font;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+
 /**
  * Store a single Space property value in simplified form, with all
  * Length values resolved. See section 4.3 in the specs.
@@ -71,13 +73,15 @@
         this.iPrecedence = iPrecedence;
     }
 
-    static public SpaceVal makeWordSpacing(Property wordSpacing, 
-                                           SpaceVal letterSpacing, 
-                                           Font fs) {
+    public static SpaceVal makeWordSpacing(Property wordSpacing,
+                                           SpaceVal letterSpacing,
+                                           Font fs,
+                                           FontConsumer fontConsumer,
+                                           int fontSize) {
         if (wordSpacing.getEnum() == Constants.EN_NORMAL) {
             // give word spaces the possibility to shrink by a third,
             // and stretch by a half;
-            int spaceCharIPD = fs.getCharWidth(' ');
+            int spaceCharIPD = fs.width(' ', fontSize);
             MinOptMax space = new MinOptMax(-spaceCharIPD / 3, 0, spaceCharIPD / 2);
             return new SpaceVal(
                     MinOptMax.add
@@ -88,7 +92,7 @@
         }        
     }
 
-    static public SpaceVal makeLetterSpacing(Property letterSpacing) {
+    public static SpaceVal makeLetterSpacing(Property letterSpacing) {
         if (letterSpacing.getEnum() == Constants.EN_NORMAL) {
             // letter spaces are set to zero (or use different values?)
             return new SpaceVal(new MinOptMax(0), true, true, 0);
Index: src/java/org/apache/fop/area/CachedRenderPagesModel.java
===================================================================
--- src/java/org/apache/fop/area/CachedRenderPagesModel.java	(révision 356368)
+++ src/java/org/apache/fop/area/CachedRenderPagesModel.java	(copie de travail)
@@ -20,7 +20,6 @@
 
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fonts.FontInfo;
 
 import java.util.Map;
 import java.util.HashMap;
@@ -35,6 +34,8 @@
 import java.io.BufferedOutputStream;
 import java.io.BufferedInputStream;
 
+import org.axsl.font.FontConsumer;
+
 /**
  * A simple cached render pages model.
  * If the page is prepared for later rendering then this saves
@@ -49,8 +50,8 @@
      * @see org.apache.fop.area.RenderPagesModel#RenderPagesModel(FOUserAgent, String, FontInfo, OutputStream)
      */
     public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat, 
-            FontInfo fontInfo, OutputStream stream) throws FOPException {
-        super(userAgent, outputFormat, fontInfo, stream);
+            FontConsumer fontConsumer, OutputStream stream) throws FOPException {
+        super(userAgent, outputFormat, fontConsumer, stream);
     }
 
     /**
Index: src/java/org/apache/fop/area/RenderPagesModel.java
===================================================================
--- src/java/org/apache/fop/area/RenderPagesModel.java	(révision 356368)
+++ src/java/org/apache/fop/area/RenderPagesModel.java	(copie de travail)
@@ -30,10 +30,12 @@
 // FOP
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.Renderer;
-import org.apache.fop.render.RendererFactory;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontException;
+
 /**
  * This uses the AreaTreeModel to store the pages
  * Each page is either rendered if ready or prepared
@@ -59,23 +61,29 @@
      * Create a new render pages model with the given renderer.
      * @param userAgent FOUserAgent object for process
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
-     * @param fontInfo FontInfo object
+     * @param fontConsumer FontConsumer object
      * @param stream OutputStream
      * @throws FOPException if the renderer cannot be properly initialized
      */
     public RenderPagesModel (FOUserAgent userAgent, String outputFormat, 
-        FontInfo fontInfo, OutputStream stream) throws FOPException {
+        FontConsumer fontConsumer, OutputStream stream) throws FOPException {
 
         super();
         renderer = userAgent.getRendererFactory().createRenderer(
                 userAgent, outputFormat);
 
         try {
-            renderer.setupFontInfo(fontInfo);
-            // check that the "any,normal,400" font exists
-            if (!fontInfo.isSetupValid()) {
-                throw new FOPException(
-                    "No default font defined by OutputConverter");
+            renderer.setupFontConsumer(fontConsumer);
+            // check that the default fallback font exists
+            try {
+                fontConsumer.getFontServer().selectFontXSL(fontConsumer, new String[] {"any"},
+                        Font.FONT_STYLE_ANY,
+                        Font.FONT_WEIGHT_ANY,
+                        Font.FONT_VARIANT_ANY,
+                        Font.FONT_STRETCH_ANY,
+                        10000, ' ');
+            } catch (FontException e) {
+                throw new FOPException("No default font defined by OutputConverter");
             }
             renderer.startRenderer(stream);
         } catch (IOException e) {
Index: src/java/org/apache/fop/area/Trait.java
===================================================================
--- src/java/org/apache/fop/area/Trait.java	(révision 356368)
+++ src/java/org/apache/fop/area/Trait.java	(copie de travail)
@@ -59,12 +59,12 @@
     public static final Integer EXTERNAL_LINK = new Integer(2);
 
     /**
-     * The font name from the font setup.
+     * The font use from the font setup.
      */
-    public static final Integer FONT_NAME = new Integer(3);
+    public static final Integer FONT = new Integer(3);
 
     /**
-     * Font size for the current font.
+     * Font size (in millipoints) for the current font.
      */
     public static final Integer FONT_SIZE = new Integer(4);
 
@@ -227,8 +227,8 @@
                           new TraitInfo("internal-link", String.class));
         TRAIT_INFO.put(EXTERNAL_LINK,
                           new TraitInfo("external-link", String.class));
-        TRAIT_INFO.put(FONT_NAME,
-                          new TraitInfo("font-family", String.class));
+        TRAIT_INFO.put(FONT,
+                          new TraitInfo("font-family", org.axsl.font.FontUse.class));
         TRAIT_INFO.put(FONT_SIZE,
                           new TraitInfo("font-size", Integer.class));
         TRAIT_INFO.put(COLOR, new TraitInfo("color", String.class));
Index: src/java/org/apache/fop/area/AreaTreeHandler.java
===================================================================
--- src/java/org/apache/fop/area/AreaTreeHandler.java	(révision 356368)
+++ src/java/org/apache/fop/area/AreaTreeHandler.java	(copie de travail)
@@ -46,6 +46,8 @@
 import org.apache.fop.layoutmgr.LayoutManagerMaker;
 import org.apache.fop.layoutmgr.LayoutManagerMapping;
 
+import org.axsl.font.FontConsumer;
+
 /**
  * Area tree handler for formatting objects.
  *
@@ -63,7 +65,7 @@
  * The area tree pages are organized in a model that depends on the
  * type of renderer.
  */
-public class AreaTreeHandler extends FOEventHandler {
+public class AreaTreeHandler extends FOEventHandler implements FontConsumer {
 
     // show statistics after document complete?
     private boolean outputStatistics;
@@ -109,9 +111,9 @@
      */
     public AreaTreeHandler (FOUserAgent userAgent, String outputFormat, 
                 OutputStream stream) throws FOPException {
-        super(userAgent);
+        super(userAgent, outputFormat, log);
 
-        model = new RenderPagesModel(userAgent, outputFormat, fontInfo,
+        model = new RenderPagesModel(userAgent, outputFormat, this,
             stream);
             
         lmMaker = userAgent.getLayoutManagerMakerOverride();
Index: src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
===================================================================
--- src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java	(révision 356368)
+++ src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java	(copie de travail)
@@ -20,8 +20,10 @@
 
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.area.Resolvable;
-import org.apache.fop.fonts.Font;
 
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+
 import java.util.List;
 
 /**
@@ -33,6 +35,8 @@
     private boolean resolved = false;
     private String pageIDRef;
     private Font font;
+    private FontConsumer fontConsumer;
+    private int fontSize;
     private String text;
 
     /**
@@ -41,10 +45,13 @@
      * @param id the id reference for resolving this
      * @param f  the font for formatting the page number
      */
-    public UnresolvedPageNumber(String id, Font f) {
+    public UnresolvedPageNumber(String id, FontConsumer fc, Font f, int fsize) {
         pageIDRef = id;
+        fontConsumer = fc;
         font = f;
+        fontSize = fsize;
         text = "?";
+        font.registerCharUsed(fontConsumer, '?');
     }
 
     /**
@@ -108,7 +115,9 @@
     private int getStringWidth(String str) {
         int width = 0;
         for (int count = 0; count < str.length(); count++) {
-            width += font.getCharWidth(str.charAt(count));
+            char c = str.charAt(count);
+            width += font.width(str.charAt(count), fontSize);
+            font.registerCharUsed(fontConsumer, c);
         }
         return width;
     }
Index: src/java/org/apache/fop/pdf/PDFFontType0.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFontType0.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFontType0.java	(copie de travail)
@@ -18,7 +18,6 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontType;
 
 /**
  * Class representing a Type0 font.
@@ -49,7 +48,7 @@
                         Object encoding) {
 
         /* generic creation of PDF object */
-        super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
+        super(fontname, PDFFont.TYPE0, basefont, encoding /* , mapping */);
 
         /* set fields using paramaters */
         this.descendantFonts = null;
@@ -70,7 +69,7 @@
                         PDFCIDFont descendantFonts) {
 
         /* generic creation of PDF object */
-        super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
+        super(fontname, PDFFont.TYPE0, basefont, encoding /* , mapping */);
 
         /* set fields using paramaters */
         this.descendantFonts = descendantFonts;
Index: src/java/org/apache/fop/pdf/PDFFontDescriptor.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFontDescriptor.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFontDescriptor.java	(copie de travail)
@@ -15,11 +15,9 @@
  */
 
 /* $Id$ */
- 
+
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontType;
-
 /**
  * Class representing a font descriptor (/FontDescriptor object).
  * <p>
@@ -46,7 +44,10 @@
     private AbstractPDFStream fontfile;
     // private String charSet = null;
 
-    private FontType subtype;
+    /**
+     * Font type. One of PDFFont.TYPE0, TYPE1, MMTYPE1, TRUETYPE
+     */
+    private byte subtype;
 
     /**
      * Create the /FontDescriptor object
@@ -109,7 +110,7 @@
      * @param subtype the font type defined in the font stream
      * @param fontfile the stream containing an embedded font
      */
-    public void setFontFile(FontType subtype, AbstractPDFStream fontfile) {
+    public void setFontFile(byte subtype, AbstractPDFStream fontfile) {
         this.subtype = subtype;
         this.fontfile = fontfile;
     }
@@ -165,7 +166,7 @@
             p.append(leading);
         }
         if (fontfile != null) {
-            if (subtype == FontType.TYPE1) {
+            if (subtype == PDFFont.TYPE1) {
                 p.append("\n/FontFile ");
             } else {
                 p.append("\n/FontFile2 ");
Index: src/java/org/apache/fop/pdf/PDFResources.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFResources.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFResources.java	(copie de travail)
@@ -18,17 +18,16 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.FontDescriptor;
-
-// Java
+//Java
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashMap;
-import java.util.HashSet;
 
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * class representing a /Resources object.
  *
@@ -86,20 +85,14 @@
      * Add the fonts in the font info to this PDF document's Font Resources.
      * 
      * @param doc PDF document to add fonts to
-     * @param fontInfo font info object to get font information from
+     * @param fontMap pairs of font names and their associated internal names
      */
-   public void addFonts(PDFDocument doc, FontInfo fontInfo) {
-        Map fonts = fontInfo.getUsedFonts();
-        Iterator e = fonts.keySet().iterator();
-        while (e.hasNext()) {
-            String f = (String)e.next();
-            Typeface font = (Typeface)fonts.get(f);
-            FontDescriptor desc = null;
-            if (font instanceof FontDescriptor) {
-                desc = (FontDescriptor)font;
-            }
-            addFont(doc.getFactory().makeFont(
-                f, font.getFontName(), font.getEncoding(), font, desc));
+    public void addFonts(PDFDocument doc, FontMap fontMap) {
+        FontConsumer fontConsumer = fontMap.getFontConsumer();
+        FontUse[] usedFontUses = fontConsumer.getFontServer().getUsedFontUses(fontConsumer);
+        for (int i = 0; i < usedFontUses.length; i++) {
+            String internalName = (String) fontMap.getInternalName(usedFontUses[i]);
+            addFont(doc.getFactory().makeFont(usedFontUses[i], internalName, fontConsumer));
         }
     }
 
Index: src/java/org/apache/fop/pdf/PDFFontType1.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFontType1.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFontType1.java	(copie de travail)
@@ -18,7 +18,6 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontType;
 
 /**
  * Class representing a Type1 or MMType1 font (not necessary for the base 14).
@@ -44,7 +43,7 @@
                         Object encoding) {
 
         /* generic creation of PDF object */
-        super(fontname, FontType.TYPE1, basefont, encoding);
+        super(fontname, PDFFont.TYPE1, basefont, encoding);
     }
 
 }
Index: src/java/org/apache/fop/pdf/PDFFontTrueType.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFontTrueType.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFontTrueType.java	(copie de travail)
@@ -18,7 +18,6 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontType;
 
 /**
  * Class representing a TrueType font.
@@ -40,7 +39,7 @@
                            Object encoding) {
 
         /* generic creation of PDF object */
-        super(fontname, FontType.TRUETYPE, basefont, encoding /* , mapping */);
+        super(fontname, PDFFont.TRUETYPE, basefont, encoding /* , mapping */);
     }
 
 }
Index: src/java/org/apache/fop/pdf/PDFDocument.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFDocument.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFDocument.java	(copie de travail)
@@ -24,9 +24,9 @@
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Iterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
Index: src/java/org/apache/fop/pdf/PDFFontNonBase14.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFontNonBase14.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFontNonBase14.java	(copie de travail)
@@ -18,7 +18,6 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontType;
 
 /**
  * A common ancestor for Type1, TrueType, MMType1 and Type3 fonts
@@ -50,11 +49,11 @@
      * Create the /Font object
      *
      * @param fontname the internal name for the font
-     * @param subtype the font's subtype
+     * @param subtype the font's subtype (one of PDFont.TYPE0, TYPE1, MMTYPE1, TRUETYPE)
      * @param basefont the base font name
      * @param encoding the character encoding schema used by the font
      */
-    public PDFFontNonBase14(String fontname, FontType subtype,
+    public PDFFontNonBase14(String fontname, byte subtype,
                             String basefont,
                             Object encoding) {
 
Index: src/java/org/apache/fop/pdf/PDFFont.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFont.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFont.java	(copie de travail)
@@ -18,8 +18,6 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontType;
-
 /**
  * Class representing a /Font object.
  * <p>
@@ -31,6 +29,31 @@
  */
 public class PDFFont extends PDFObject {
 
+    /* Copied from FOray PDFFont.java */
+    /** Font subtype indicating a composite font. */
+    public static final byte TYPE0 = 0;
+
+    /** Font subtype indicating a Type 1 simple font. */
+    public static final byte TYPE1 = 1;
+
+    /** Font subtype indicating a Multiple Master Type 1 simple font. */
+    public static final byte MMTYPE1 = 2;
+
+    /** Font subtype indicating a Type 3 simple font. */
+    public static final byte TYPE3 = 3;
+
+    /** Font subtype indicating a TrueType simple font. */
+    public static final byte TRUETYPE = 4;
+
+    /** Unknown font type. */
+    public static final byte OTHER = 5;
+
+    /** Font subtype names as output in the PDF. */
+    protected static final String[] TYPE_NAMES /* The order is important here. */
+            = {"Type0", "Type1", "MMType1", "Type3", "TrueType", "Other" };
+    /* End of copy from PDFFont.java */
+
+    
     /**
      * the internal name for the font (eg "F1")
      */
@@ -38,9 +61,9 @@
 
     /**
      * the font's subtype
-     * (as defined by the constants FontType: TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE)
+     * (as defined by the constants in PDFFont: TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE)
      */
-    protected FontType subtype;
+    protected byte subtype;
 
     /**
      * the base font name (eg "Helvetica")
@@ -69,7 +92,7 @@
      * @param basefont the base font name
      * @param encoding the character encoding schema used by the font
      */
-    public PDFFont(String fontname, FontType subtype,
+    public PDFFont(String fontname, byte subtype,
                    String basefont,
                    Object encoding /* , PDFToUnicode mapping */) {
 
@@ -88,29 +111,27 @@
      * factory method with the basic parameters
      *
      * @param fontname the internal name for the font
-     * @param subtype the font's subtype
+     * @param subtype the font's subtype (one of TYPE0, TYPE1, MMTYPE1, TYPE3 or TRUETYPE)
      * @param basefont the base font name
      * @param encoding the character encoding schema used by the font
      * @return the generated PDFFont object
      */
     public static PDFFont createFont(String fontname,
-                                     FontType subtype, String basefont,
+                                     byte subtype, String basefont,
                                      Object encoding) {
-        if (subtype == FontType.TYPE0) {
+        if (subtype == TYPE0) {
             return new PDFFontType0(fontname, basefont,
                                     encoding);
-        } else if ((subtype == FontType.TYPE1)
-                || (subtype == FontType.MMTYPE1)) {
-            return new PDFFontType1(fontname, basefont,
-                                    encoding);
-        } else if (subtype == FontType.TYPE3) {
-            //return new PDFFontType3(number, fontname, basefont, encoding);
+        } else if ((subtype == TYPE1)
+                || (subtype == MMTYPE1)) {
+            return new PDFFontType1(fontname, basefont, encoding);
+        } else if (subtype == TYPE3) {
+//            //return new PDFFontType3(number, fontname, basefont, encoding);
             return null; //NYI
-        } else if (subtype == FontType.TRUETYPE) {
-            return new PDFFontTrueType(fontname, basefont,
-                                       encoding);
+        } else if (subtype == TRUETYPE) {
+            return new PDFFontTrueType(fontname, basefont, encoding);
         } else {
-            return null;    // should not happend
+            return null;    // should not happen
         }
     }
 
@@ -119,7 +140,7 @@
      * for Type1, MMType1 and TrueType
      *
      * @param fontname the internal name for the font
-     * @param subtype the font's subtype
+     * @param subtype the font's subtype (one of TYPE0, TYPE1, MMTYPE1, TYPE3 or TRUETYPE)
      * @param basefont the base font name
      * @param encoding the character encoding schema used by the font
      * @param firstChar the first character code in the font
@@ -129,27 +150,27 @@
      * @return the generated PDFFont object
      */
     public static PDFFont createFont(String fontname,
-                                     FontType subtype, String basefont,
+                                     byte subtype, String basefont,
                                      Object encoding, int firstChar,
                                      int lastChar, PDFArray widths,
                                      PDFFontDescriptor descriptor) {
 
         PDFFontNonBase14 font;
-        if (subtype == FontType.TYPE0) {
+        if (subtype == TYPE0) {
             font = new PDFFontType0(fontname, basefont,
                                     encoding);
             font.setDescriptor(descriptor);
             return font;
-        } else if ((subtype == FontType.TYPE1) 
-                || (subtype == FontType.MMTYPE1)) {
+        } else if ((subtype == TYPE1) 
+                || (subtype == MMTYPE1)) {
             font = new PDFFontType1(fontname, basefont,
                                     encoding);
             font.setWidthMetrics(firstChar, lastChar, widths);
             font.setDescriptor(descriptor);
             return font;
-        } else if (subtype == FontType.TYPE3) {
+        } else if (subtype == TYPE3) {
             return null; //NYI, should not happend
-        } else if (subtype == FontType.TRUETYPE) {
+        } else if (subtype == TRUETYPE) {
             font = new PDFFontTrueType(fontname, basefont,
                                        encoding);
             font.setWidthMetrics(firstChar, lastChar, widths);
@@ -173,19 +194,15 @@
      * @param fontType font type
      * @return String corresponding PDF name
      */
-    protected String getPDFNameForFontType(FontType fontType) {
-        if (fontType == FontType.TYPE0) {
-            return fontType.getName();
-        } else if (fontType == FontType.TYPE1) {
-            return fontType.getName();
-        } else if (fontType == FontType.MMTYPE1) {
-            return fontType.getName();
-        } else if (fontType == FontType.TYPE3) {
-            return fontType.getName();
-        } else if (fontType == FontType.TRUETYPE) {
-            return fontType.getName();
-        } else {
-            throw new IllegalArgumentException("Unsupported font type: " + fontType.getName());
+    protected String getPDFNameForFontType(byte fontType) {
+        switch (fontType) {
+        case TYPE0:
+        case TYPE1:
+        case MMTYPE1:
+        case TYPE3:
+        case TRUETYPE: return TYPE_NAMES[fontType];
+        default:
+                throw new IllegalArgumentException("Unsupported font type");
         }
     }
 
Index: src/java/org/apache/fop/pdf/PDFFactory.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFactory.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFactory.java	(copie de travail)
@@ -20,30 +20,21 @@
 
 // Java
 import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.List;
 import java.util.Map;
 
 // Apache libs
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 // FOP
-import org.apache.fop.fonts.CIDFont;
-import org.apache.fop.fonts.CustomFont;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.FontDescriptor;
-import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.FontType;
-import org.apache.fop.fonts.LazyFont;
-import org.apache.fop.fonts.MultiByteFont;
-import org.apache.fop.fonts.truetype.FontFileReader;
-import org.apache.fop.fonts.truetype.TTFSubSetFile;
-import org.apache.fop.fonts.type1.PFBData;
-import org.apache.fop.fonts.type1.PFBParser;
+import org.apache.fop.fonts.CIDFontType;
 
+// FOray
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+
 /**
  * This class provides method to create and register PDF objects.
  */
@@ -949,145 +940,129 @@
     }
 
     /**
-     * make a Type1 /Font object
+     * make a Type1 /Font object.
      *
-     * @param fontname internal name to use for this font (eg "F1")
-     * @param basefont name of the base font (eg "Helvetica")
-     * @param encoding character encoding scheme used by the font
-     * @param metrics additional information about the font
-     * @param descriptor additional information about the font
+     * @param fontUse the font
+     * @param internalName internal name of the font
+     * @param fontConsumer associated font consumer
      * @return the created /Font object
      */
-    public PDFFont makeFont(String fontname, String basefont,
-                            String encoding, FontMetrics metrics,
-                            FontDescriptor descriptor) {
-        PDFFont preRegisteredfont = getDocument().findFont(fontname);
+    public PDFFont makeFont(FontUse fontUse, String internalName, FontConsumer fontConsumer) {
+        PDFFont preRegisteredfont = getDocument().findFont(internalName);
         if (preRegisteredfont != null) {
             return preRegisteredfont;
         }
 
-        if (descriptor == null) {
-            PDFFont font = new PDFFont(fontname, FontType.TYPE1, basefont, encoding);
-            getDocument().registerObject(font);
-            return font;
+        Font font = fontUse.getFont();
+        PDFFont pdfFont;
+        if (font.isPDFStandardFont()) {
+            pdfFont = new PDFFont(internalName, PDFFont.TYPE1,
+                    font.postscriptName(), fontUse.getEncoding().getName());
+            getDocument().registerObject(pdfFont);
         } else {
-            FontType fonttype = metrics.getFontType();
-
-            PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor);
-
-            PDFFontNonBase14 font = null;
-            if (fonttype == FontType.TYPE0) {
-                /*
-                 * Temporary commented out - customized CMaps
-                 * isn't needed until /ToUnicode support is added
-                 * PDFCMap cmap = new PDFCMap(++this.objectcount,
-                 * "fop-ucs-H",
-                 * new PDFCIDSystemInfo("Adobe",
-                 * "Identity",
-                 * 0));
-                 * cmap.addContents();
-                 * this.objects.add(cmap);
-                 */
-                font =
-                    (PDFFontNonBase14)PDFFont.createFont(fontname, fonttype,
-                                                         basefont,
-                                                         "Identity-H");
+            byte fontSubType;
+            if (font.getFontComplexity() == Font.FONT_COMPOSITE) {
+                fontSubType = PDFFont.TYPE0;
+            } else if (font.getFontFormat() == Font.FORMAT_TYPE1) {
+                    fontSubType = PDFFont.TYPE1;
+            } else if (font.getFontFormat() == Font.FORMAT_TRUETYPE) {
+                fontSubType = PDFFont.TRUETYPE;
             } else {
-
-                font =
-                    (PDFFontNonBase14)PDFFont.createFont(fontname, fonttype,
-                                                         basefont, encoding);
+                fontSubType = PDFFont.OTHER;
             }
-            getDocument().registerObject(font);
+            if (fontSubType == PDFFont.TYPE0) {
+                pdfFont = PDFFont.createFont(internalName, fontSubType,
+                        font.postscriptName(), "Identity-H");                
+            } else {
+                pdfFont = PDFFont.createFont(internalName, fontSubType,
+                        font.postscriptName(), fontUse.getEncoding().getName());
+            }
+            getDocument().registerObject(pdfFont);
+            
+            PDFFontDescriptor pdfdesc = makeFontDescriptor(fontUse, fontSubType, fontConsumer);
+            ((PDFFontNonBase14)pdfFont).setDescriptor(pdfdesc);
 
-            font.setDescriptor(pdfdesc);
-
-            if (fonttype == FontType.TYPE0) {
-                CIDFont cidMetrics;
-                if (metrics instanceof LazyFont) {
-                    cidMetrics = (CIDFont)((LazyFont) metrics).getRealFont();
-                } else {
-                    cidMetrics = (CIDFont)metrics;
-                }
-                PDFCIDSystemInfo sysInfo =
-                    new PDFCIDSystemInfo(cidMetrics.getRegistry(),
-                                         cidMetrics.getOrdering(),
-                                         cidMetrics.getSupplement());
-                PDFCIDFont cidFont =
-                    new PDFCIDFont(basefont,
-                                   cidMetrics.getCIDType(),
-                                   cidMetrics.getDefaultWidth(),
-                                   getSubsetWidths(cidMetrics), sysInfo,
-                                   (PDFCIDFontDescriptor)pdfdesc);
+            if (fontSubType == PDFFont.TYPE0) {
+                PDFCIDSystemInfo sysInfo = new PDFCIDSystemInfo("Adobe", "UCS", 0);
+                // TODO vh: does not work yet
+//                PDFCMap cmap = new PDFCMap("Identity-H", sysInfo);
+//                getDocument().registerObject(cmap);
+                PDFCIDFont cidFont = new PDFCIDFont(font.postscriptName(),
+                        CIDFontType.CIDTYPE2,
+                        font.getDefaultWidth(),
+                        getSubsetWidths(font, fontConsumer), sysInfo,
+                        (PDFCIDFontDescriptor) pdfdesc);
                 getDocument().registerObject(cidFont);
-
-                ((PDFFontType0)font).setDescendantFonts(cidFont);
+//                ((PDFFontType0) pdfFont).setCMAP(cmap);   
+                ((PDFFontType0) pdfFont).setDescendantFonts(cidFont);
             } else {
-                int firstChar = 0;
-                int lastChar = 255;
-                if (metrics instanceof CustomFont) {
-                    CustomFont cf = (CustomFont)metrics;
-                    firstChar = cf.getFirstChar();
-                    lastChar = cf.getLastChar();
-                }
-                font.setWidthMetrics(firstChar,
-                                     lastChar,
-                                     makeArray(metrics.getWidths()));
+                int firstChar = fontUse.getFirstChar();
+                int lastChar = fontUse.getLastChar();
+                int[] widths = shortArrayToIntArray(font.getWidths(fontConsumer));
+                ((PDFFontNonBase14)pdfFont).setWidthMetrics(firstChar, lastChar,
+                        makeArray(widths));
             }
-
-            return font;
         }
+        return pdfFont;
     }
 
-    public PDFWArray getSubsetWidths(CIDFont cidFont) {
+    public PDFWArray getSubsetWidths(Font cidFont, FontConsumer fontConsumer) {
         // Create widths for reencoded chars
+        // TODO vh: for now fonts aren't subsetted (I think)
         PDFWArray warray = new PDFWArray();
-        int[] tmpWidth = new int[cidFont.usedGlyphsCount];
-
-        for (int i = 0; i < cidFont.usedGlyphsCount; i++) {
-            Integer nw = (Integer)cidFont.usedGlyphsIndex.get(new Integer(i));
-            int nwx = (nw == null) ? 0 : nw.intValue();
-            tmpWidth[i] = cidFont.width[nwx];
-        }
-        warray.addEntry(0, tmpWidth);
+        warray.addEntry(0, shortArrayToIntArray(cidFont.getWidths(fontConsumer)));
         return warray;
+//        // Create widths for reencoded chars
+//        PDFWArray warray = new PDFWArray();
+//        int[] tmpWidth = new int[cidFont.usedGlyphsCount];
+//
+//        for (int i = 0; i < cidFont.usedGlyphsCount; i++) {
+//            Integer nw = (Integer)cidFont.usedGlyphsIndex.get(new Integer(i));
+//            int nwx = (nw == null) ? 0 : nw.intValue();
+//            tmpWidth[i] = cidFont.width[nwx];
+//        }
+//        warray.addEntry(0, tmpWidth);
+//        return warray;
     }
 
     /**
-     * make a /FontDescriptor object
+     * make a /FontDescriptor object.
      *
-     * @param desc the font descriptor
+     * @param fontUse the corresponding font use
+     * @param subType the font subtype; one of PDFFont.TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE
+     * @param fontConsumer the associated font consumer
      * @return the new PDF font descriptor
      */
-    public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc) {
-        PDFFontDescriptor descriptor = null;
-
-        if (desc.getFontType() == FontType.TYPE0) {
+    public PDFFontDescriptor makeFontDescriptor(FontUse fontUse, byte subType,
+            FontConsumer fontConsumer) {
+        PDFFontDescriptor descriptor;
+        Font font = fontUse.getFont();
+        if (subType == PDFFont.TYPE0) {
             // CID Font
-            descriptor = new PDFCIDFontDescriptor(desc.getFontName(),
-                                            desc.getFontBBox(),
-                                            desc.getCapHeight(),
-                                            desc.getFlags(),
-                                            desc.getItalicAngle(),
-                                            desc.getStemV(), null);
+            descriptor = new PDFCIDFontDescriptor(font.postscriptName(),
+                                            font.getFontBBox(),
+                                            font.getCapHeight(1000),
+                                            font.getFlags(),
+                                            font.getItalicAngle(),
+                                            font.getStemV(), null);
         } else {
             // Create normal FontDescriptor
-            descriptor = new PDFFontDescriptor(desc.getFontName(),
-                                         desc.getAscender(),
-                                         desc.getDescender(),
-                                         desc.getCapHeight(),
-                                         desc.getFlags(),
-                                         new PDFRectangle(desc.getFontBBox()),
-                                         desc.getStemV(),
-                                         desc.getItalicAngle());
+            descriptor = new PDFFontDescriptor(font.postscriptName(),
+                                         font.getAscender(1000),
+                                         font.getDescender(1000),
+                                         font.getCapHeight(1000),
+                                         font.getFlags(),
+                                         new PDFRectangle(font.getFontBBox()),
+                                         font.getStemV(),
+                                         font.getItalicAngle());
         }
         getDocument().registerObject(descriptor);
 
         // Check if the font is embeddable
-        if (desc.isEmbeddable()) {
-            AbstractPDFStream stream = makeFontFile(desc);
+        if (font.isEmbeddable()) {
+            AbstractPDFStream stream = makeFontFile(fontUse, fontConsumer);
             if (stream != null) {
-                descriptor.setFontFile(desc.getFontType(), stream);
+                descriptor.setFontFile(subType, stream);
                 getDocument().registerObject(stream);
             }
         }
@@ -1096,101 +1071,21 @@
 
     /**
      * Embeds a font.
-     * @param desc FontDescriptor of the font.
+     * @param fontUse the corresponding font use
+     * @param fontConsumer the associated font consumer
      * @return PDFStream The embedded font file
      */
-    public AbstractPDFStream makeFontFile(FontDescriptor desc) {
-        if (desc.getFontType() == FontType.OTHER) {
-            throw new IllegalArgumentException("Trying to embed unsupported font type: "
-                                                + desc.getFontType());
-        }
+    public AbstractPDFStream makeFontFile(FontUse fontUse, FontConsumer fontConsumer) {
+        
+        return new PDFFontFileStream(fontUse, fontConsumer);
 
-        Typeface tempFont;
-        if (desc instanceof LazyFont) {
-            tempFont = ((LazyFont)desc).getRealFont();
+        /*
+        embeddedFont.getFilterList().addFilter("flate");
+        if (getDocument().isEncryptionActive()) {
+            getDocument().applyEncryption(embeddedFont);
         } else {
-            tempFont = (Typeface)desc;
-        }
-        if (!(tempFont instanceof CustomFont)) {
-            throw new IllegalArgumentException(
-                      "FontDescriptor must be instance of CustomFont, but is a "
-                       + desc.getClass().getName());
-        }
-        CustomFont font = (CustomFont)tempFont;
-
-        InputStream in = null;
-        try {
-            // Get file first
-            if (font.getEmbedFileName() != null) {
-                try {
-                    in = getDocument().resolveURI(font.getEmbedFileName());
-                } catch (Exception e) {
-                    log.error("Failed to embed fontfile: "
-                                       + font.getEmbedFileName()
-                                       + "(" + e.getMessage() + ")");
-                }
-            }
-
-            // Get resource
-            if (in == null && font.getEmbedResourceName() != null) {
-                try {
-                    in = new java.io.BufferedInputStream(
-                            this.getClass().getResourceAsStream(
-                                font.getEmbedResourceName()));
-                } catch (Exception e) {
-                    log.error(
-                                         "Failed to embed fontresource: "
-                                       + font.getEmbedResourceName()
-                                       + "(" + e.getMessage() + ")");
-                }
-            }
-
-            if (in == null) {
-                return null;
-            } else {
-                try {
-                    AbstractPDFStream embeddedFont;
-                    if (desc.getFontType() == FontType.TYPE0) {
-                        MultiByteFont mbfont = (MultiByteFont)font;
-                        FontFileReader reader = new FontFileReader(in);
-
-                        TTFSubSetFile subset = new TTFSubSetFile();
-                        byte[] subsetFont = subset.readFont(reader,
-                                             mbfont.getTTCName(), mbfont.getUsedGlyphs());
-                        // Only TrueType CID fonts are supported now
-
-                        embeddedFont = new PDFTTFStream(subsetFont.length);
-                        ((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length);
-                    } else if (desc.getFontType() == FontType.TYPE1) {
-                        PFBParser parser = new PFBParser();
-                        PFBData pfb = parser.parsePFB(in);
-                        embeddedFont = new PDFT1Stream();
-                        ((PDFT1Stream)embeddedFont).setData(pfb);
-                    } else {
-                        byte[] file = IOUtils.toByteArray(in);
-                        embeddedFont = new PDFTTFStream(file.length);
-                        ((PDFTTFStream)embeddedFont).setData(file, file.length);
-                    }
-
-                    /*
-                    embeddedFont.getFilterList().addFilter("flate");
-                    if (getDocument().isEncryptionActive()) {
-                        getDocument().applyEncryption(embeddedFont);
-                    } else {
-                        embeddedFont.getFilterList().addFilter("ascii-85");
-                    }*/
-
-                    return embeddedFont;
-                } finally {
-                    in.close();
-                }
-            }
-        } catch (IOException ioe) {
-            log.error(
-                    "Failed to embed font [" + desc + "] "
-                    + desc.getFontName(), ioe);
-            return (PDFStream) null;
-        }
+            embeddedFont.getFilterList().addFilter("ascii-85");
+        }*/
     }
 
 
@@ -1241,6 +1136,21 @@
     /* ========================= misc. objects ============================= */
 
     /**
+     * Transform an array of short into an array of int. I wish there were a
+     * better mean to do that...
+     * 
+     * @param array of short
+     * @return array with the same values stored as integers
+     */
+    private static int[] shortArrayToIntArray(short[] shortArray) {
+        int[] intArray = new int[shortArray.length];
+        for (int i = 0; i < shortArray.length; i++) {
+            intArray[i] = shortArray[i];
+        }
+        return intArray;
+    }
+    
+    /**
      * make an Array object (ex. Widths array for a font)
      *
      * @param values the int array values
Index: src/java/org/apache/fop/pdf/PDFFontType3.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFontType3.java	(révision 356368)
+++ src/java/org/apache/fop/pdf/PDFFontType3.java	(copie de travail)
@@ -18,7 +18,6 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontType;
 
 /**
  * Class representing a Type3 font.
@@ -62,7 +61,7 @@
                         Object encoding) {
 
         /* generic creation of PDF object */
-        super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
+        super(fontname, PDFFont.TYPE3, basefont, encoding /* , mapping */);
 
         this.fontBBox = null;
         this.fontMatrix = null;
@@ -86,7 +85,7 @@
                         PDFCharProcs charProcs) {
 
         /* generic creation of PDF object */
-        super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
+        super(fontname, PDFFont.TYPE3, basefont, encoding /* , mapping */);
 
         this.fontBBox = fontBBox;
         this.fontMatrix = fontMatrix;
Index: build.xml
===================================================================
--- build.xml	(révision 356368)
+++ build.xml	(copie de travail)
@@ -168,7 +168,6 @@
   <property name="user.hyph.dir" value="${basedir}/hyph"/>
 
   <property name="build.dir" value="${basedir}/build"/>
-  <property name="build.gensrc.dir" value="${build.dir}/gensrc"/>
   <property name="build.classes.dir" value="${build.dir}/classes"/>
   <property name="build.sandbox-classes.dir" value="${build.dir}/sandbox-classes"/>
   <property name="build.javadocs.dir" value="${build.dir}/javadocs"/>
@@ -283,93 +282,24 @@
   </target>
 
   <!-- =================================================================== -->
-  <!-- Generate the source code                                            -->
-  <!-- =================================================================== -->
-  <target name="codegen" depends="init" description="Generates the java files from the xml resources">
-    <echo message="Generating the java files from xml resources"/>
-    <mkdir dir="${build.gensrc.dir}"/>
-    <mkdir dir="${build.gensrc.dir}/org/apache/fop/fonts/base14"/>
-
-    <style in="${src.codegen.dir}/encodings.xml"
-           style="${src.codegen.dir}/code-point-mapping.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/CodePointMapping.java"/>
-    <!-- Task unrolled because of a bug in Xalan included in some
-         JDK 1.4 releases
-    <style basedir="src/codegen" includes="Helvetica*.xml,Times*.xml,Courier*.xml"
-        style="${src.codegen.dir}/font-file.xsl"
-        destdir="${build.gensrc.dir}/org/apache/fop/fonts/base14" extension=".java">
-        <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    -->
-    <style in="${src.codegen.dir}/Courier.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/Courier.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/CourierOblique.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/CourierOblique.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/CourierBold.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/CourierBold.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/CourierBoldOblique.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/CourierBoldOblique.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/Helvetica.xml" style="${src.codegen.dir}/font-file.xsl"
-        destdir="${build.gensrc.dir}/org/apache/fop/fonts/base14"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/Helvetica.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/HelveticaBold.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/HelveticaBold.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/HelveticaOblique.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/HelveticaOblique.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/HelveticaBoldOblique.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/HelveticaBoldOblique.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/TimesRoman.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesRoman.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/TimesItalic.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesItalic.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/TimesBold.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesBold.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/TimesBoldItalic.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesBoldItalic.java">
-      <param name="encoding" expression="WinAnsiEncoding"/>
-    </style>
-    <style in="${src.codegen.dir}/Symbol.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/Symbol.java"/>
-    <style in="${src.codegen.dir}/ZapfDingbats.xml" style="${src.codegen.dir}/font-file.xsl"
-        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/ZapfDingbats.java"/>
-
-  </target>
-
-  <!-- =================================================================== -->
   <!-- Compiles the source directory                                       -->
   <!-- =================================================================== -->
-  <target name="compile-java" depends="init, codegen" description="Compiles the source code">
+  <target name="compile-java" depends="init" description="Compiles the source code">
     <!-- create directories -->
     <mkdir dir="${build.classes.dir}"/>
     <javac destdir="${build.classes.dir}" fork="javac.fork" debug="${javac.debug}"
            deprecation="${javac.deprecation}" optimize="${javac.optimize}"
            source="${javac.source}" target="${javac.target}">
-      <src path="${build.gensrc.dir}"/>
       <src path="${src.java.dir}"/>
       <src refid="graphics-configuration-adapter"/>
-      <patternset includes="**/*.java"/>
+      <patternset>
+        <include name="**/*.java"/>
+        <exclude name="org/apache/fop/fonts/**/*.java"/>
+        <exclude name="org/apache/fop/pdf/PDFT1Stream.java"/>
+        <exclude name="org/apache/fop/render/java2d/Font*.java"/>
+        <include name="org/apache/fop/fonts/Glyphs.java"/>
+        <include name="org/apache/fop/fonts/CIDFontType.java"/>
+      </patternset>
       <!--patternset includes="org/apache/fop/svg/GraphicsConfiguration.java"/-->
       <patternset refid="exclude-jce-dependencies"/>
       <patternset refid="exclude-jai"/>
@@ -385,6 +315,7 @@
       <fileset dir="${src.viewer.images.dir}"/>
     </copy>
 
+    <!--
     <mkdir dir="${build.sandbox-classes.dir}"/>
     <javac destdir="${build.sandbox-classes.dir}" fork="javac.fork" debug="${javac.debug}"
            deprecation="${javac.deprecation}" optimize="${javac.optimize}"
@@ -401,6 +332,7 @@
         <include name="META-INF/**"/>
       </fileset>
     </copy>
+    -->
   </target>
 
 
@@ -469,6 +401,7 @@
     </jar>
   </target>
 
+  <!--
   <target name="uptodate-jar-sandbox" depends="compile-java">
     <uptodate property="jar.sandbox.uptodate" targetfile="${build.dir}/fop-sandbox.jar">
       <srcfiles dir= "${build.sandbox-classes.dir}"/>
@@ -485,11 +418,12 @@
       </manifest>
     </jar>
   </target>
+  -->
 
   <!-- =================================================================== -->
   <!-- Creates the class package                                           -->
   <!-- =================================================================== -->
-  <target name="package" depends="jar-main,jar-hyphenation,jar-sandbox" description="Generates the jar files"/>
+  <target name="package" depends="jar-main,jar-hyphenation" description="Generates the jar files"/>
   
   <target name="servlet" depends="package" description="Generates the WAR with the sample FOP servlet">
     <echo message="Creating the WAR file"/>
@@ -820,7 +754,7 @@
   <!-- =================================================================== -->
   <!-- Creates the API documentation                                       -->
   <!-- =================================================================== -->
-  <target name="javadocs" depends="codegen" description="Generates javadocs">
+  <target name="javadocs" description="Generates javadocs">
     <!--condition property="javadoc.version.ok">
       <not>
         <or>
@@ -869,8 +803,6 @@
       </classpath>
       <sourcepath>
         <pathelement path="${src.java.dir}"/>
-        <pathelement path="${src.sandbox.dir}"/>
-        <pathelement path="${build.gensrc.dir}"/>
         <path refid="graphics-configuration-adapter"/>
       </sourcepath>
       <tag name="todo" scope="all" description="To do:"/>
@@ -1006,7 +938,7 @@
     <echo message="${checkstyle.noframes.xslt.message}"/>
   </target>
 
-  <target name="checkstyle-check" depends="checkstyle-avail, codegen" if="checkstyle.available">
+  <target name="checkstyle-check" depends="checkstyle-avail" if="checkstyle.available">
     
     <taskdef name="checkstyle" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" classpathref="checkstyle-runpath"/>
     <checkstyle config="${checkstyle.config}" failonviolation="false"
