You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ac...@apache.org on 2008/07/29 18:00:23 UTC

svn commit: r680747 - in /xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop: fonts/ render/afp/ render/afp/fonts/

Author: acumiskey
Date: Tue Jul 29 09:00:14 2008
New Revision: 680747

URL: http://svn.apache.org/viewvc?rev=680747&view=rev
Log:
Added a base 12 (Helvetica, Times and Courier) fallback font collection for AFP environments.

Added:
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java   (with props)
Modified:
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java?rev=680747&r1=680746&r2=680747&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java Tue Jul 29 09:00:14 2008
@@ -110,6 +110,19 @@
     }
 
     /**
+     * Adds a series of new font triplets given an array of font family names.
+     * @param name internal key
+     * @param families an array of font family names
+     * @param style font style (normal, italic, oblique...)
+     * @param weight font weight
+     */
+    public void addFontProperties(String name, String[] families, String style, int weight) {
+        for (int i = 0; i < families.length; i++) {
+            addFontProperties(name, families[i], style, weight);
+        }
+    }
+
+    /**
      * Adds a new font triplet.
      * @param internalFontKey internal font key
      * @param triplet the font triplet to associate with the internal key
@@ -215,7 +228,7 @@
     }
 
     private FontTriplet fuzzyFontLookup(String family, String style,
-            int weight, FontTriplet startKey, boolean substFont) {
+            int weight, FontTriplet startKey, boolean substitutable) {
         FontTriplet key;
         String internalFontKey = null;
         if (!family.equals(startKey.getName())) {
@@ -232,7 +245,8 @@
             internalFontKey = getInternalFontKey(key);
         }
 
-        if (!substFont && internalFontKey == null) {
+        // return null if not found and not substitutable
+        if (!substitutable && internalFontKey == null) {
             return null;
         }
 
@@ -263,12 +277,12 @@
 
         // fallback 2: try the same font-family with default style and weight
         /* obsolete: replaced by the loop above
-        if (f == null) {
+        if (internalFontKey == null) {
             key = createFontKey(family, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            f = getInternalFontKey(key);
+            internalFontKey = getInternalFontKey(key);
         }*/
 
-        // fallback 3: try any family with orig style/weight
+        // fallback 3: try any family with original style/weight
         if (internalFontKey == null) {
             return fuzzyFontLookup("any", style, weight, startKey, false);
         }

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=680747&r1=680746&r2=680747&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java Tue Jul 29 09:00:14 2008
@@ -46,7 +46,7 @@
 
     /**
      * Default constructor
-     * 
+     *
      * @param userAgent user agent
      */
     public AFPRendererConfigurator(FOUserAgent userAgent) {
@@ -184,22 +184,24 @@
 
     /**
      * Builds a list of AFPFontInfo objects for use with the setup() method.
-     * 
+     *
      * @param cfg Configuration object
      * @return List the newly created list of fonts
      * @throws ConfigurationException if something's wrong with the config data
      */
-    private List buildFontListFromConfiguration(Configuration cfg)
+    private List/*<AFPFontInfo>*/ buildFontListFromConfiguration(Configuration cfg)
             throws ConfigurationException {
-        List fontList = new java.util.ArrayList();
+        List/*<AFPFontInfo>*/ fontList = new java.util.ArrayList();
         Configuration[] font = cfg.getChild("fonts").getChildren("font");
+        final String fontPath = null;
         for (int i = 0; i < font.length; i++) {
-            AFPFontInfo afi = buildFont(font[i], null);
+            AFPFontInfo afi = buildFont(font[i], fontPath);
             if (afi != null) {
                 if (log.isDebugEnabled()) {
                     log.debug("Adding font " + afi.getAFPFont().getFontName());
-                    for (int j = 0; j < afi.getFontTriplets().size(); ++j) {
-                        FontTriplet triplet = (FontTriplet) afi.getFontTriplets().get(j);
+                    List/*FontTriplet*/ fontTriplets = afi.getFontTriplets();
+                    for (int j = 0; j < fontTriplets.size(); ++j) {
+                        FontTriplet triplet = (FontTriplet) fontTriplets.get(j);
                         log.debug("  Font triplet "
                                   + triplet.getName() + ", "
                                   + triplet.getStyle() + ", "
@@ -214,7 +216,7 @@
 
     /**
      * Configure the AFP renderer.
-     * 
+     *
      * @param renderer AFP renderer
      * @throws FOPException fop exception
      * @see org.apache.fop.render.PrintRendererConfigurator#configure(Renderer)
@@ -224,13 +226,13 @@
         if (cfg != null) {
             AFPRenderer afpRenderer = (AFPRenderer)renderer;
             try {
-                List fontList = buildFontListFromConfiguration(cfg);
+                List/*<AFPFontInfo>*/ fontList = buildFontListFromConfiguration(cfg);
                 afpRenderer.setFontList(fontList);
             } catch (ConfigurationException e) {
                 LogUtil.handleException(log, e,
                         userAgent.getFactory().validateUserConfigStrictly());
             }
-                    
+
             // image information
             Configuration imagesCfg = cfg.getChild("images");
             if (!"color".equalsIgnoreCase(imagesCfg.getAttribute("mode", "b+w"))) {

Added: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java?rev=680747&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java Tue Jul 29 09:00:14 2008
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp.fonts;
+
+import org.apache.fop.fonts.Base14Font;
+import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.base14.Courier;
+import org.apache.fop.fonts.base14.CourierBold;
+import org.apache.fop.fonts.base14.CourierBoldOblique;
+import org.apache.fop.fonts.base14.CourierOblique;
+import org.apache.fop.fonts.base14.Helvetica;
+import org.apache.fop.fonts.base14.HelveticaBold;
+import org.apache.fop.fonts.base14.HelveticaOblique;
+import org.apache.fop.fonts.base14.TimesBold;
+import org.apache.fop.fonts.base14.TimesBoldItalic;
+import org.apache.fop.fonts.base14.TimesItalic;
+import org.apache.fop.fonts.base14.TimesRoman;
+
+/**
+ * Sets up a typical Base 12 font configuration for AFP
+ */
+public class AFPBase12FontCollection implements FontCollection {
+
+    /** standard raster font sizes */
+    private static final int[] RASTER_SIZES = {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 30, 36};
+
+    /** standard raster font charset references */
+    private static final String[] CHARSET_REF = {
+        "60", "70", "80", "90", "00", "A0", "B0", "D0", "F0", "H0", "J0", "N0", "T0", "Z0"};
+
+    private void addCharacterSet(RasterFont font, String charsetName, Base14Font base14) {
+        for (int i = 0; i < RASTER_SIZES.length; i++) {
+            int size = RASTER_SIZES[i];
+            FopCharacterSet characterSet = new FopCharacterSet(
+                    CharacterSet.DEFAULT_CODEPAGE, CharacterSet.DEFAULT_ENCODING,
+                    charsetName + CHARSET_REF[i], size, base14);
+            font.addCharacterSet(size, characterSet);
+        }
+    }
+
+    private int addFontProperties(FontInfo fontInfo, AFPFont font,
+            String[] names, String style, int weight, int num) {
+        String internalFontKey = "F" + num;
+        fontInfo.addMetrics(internalFontKey, font);
+        fontInfo.addFontProperties(internalFontKey, names, style, weight);
+        num++;
+        return num;
+    }
+
+    /** {@inheritDoc} */
+    public int setup(int start, FontInfo fontInfo) {
+
+        /**
+         * Add the base 12 fonts (Helvetica, Times and Courier)
+         *
+         * Note: this default font configuration may not be available
+         * on your AFP environment.
+         */
+        int num = start;
+        RasterFont font = null;
+
+        /** standard font family reference names for Helvetica font */
+        final String[] helveticaNamesPlusAny = {"Helvetica", "Arial", "sans-serif", "any"};
+        font = new RasterFont("Helvetica");
+        addCharacterSet(font, "C0H200", new Helvetica());
+        num = addFontProperties(fontInfo, font, helveticaNamesPlusAny,
+                Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
+
+        final String[] helveticaNames = {"Helvetica", "Arial", "sans-serif"};
+        font = new RasterFont("Helvetica Italic");
+        addCharacterSet(font, "C0H300", new HelveticaOblique());
+        num = addFontProperties(fontInfo, font, helveticaNames,
+                Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
+
+        font = new RasterFont("Helvetica (Semi) Bold");
+        addCharacterSet(font, "C0H400", new HelveticaBold());
+        num = addFontProperties(fontInfo, font, helveticaNames,
+                Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
+
+        font = new RasterFont("Helvetica Italic (Semi) Bold");
+        addCharacterSet(font, "C0H500", new HelveticaOblique());
+        num = addFontProperties(fontInfo, font, helveticaNames,
+                Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
+
+
+        final String[] timesNames = {"Times", "TimesRoman", "Times Roman", "Times-Roman",
+                "Times New Roman", "TimesNewRoman", "serif"};
+
+        font = new RasterFont("Times Roman");
+        addCharacterSet(font, "CON200", new TimesRoman());
+        num = addFontProperties(fontInfo, font, timesNames,
+                Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
+
+        font = new RasterFont("Times Roman Italic");
+        addCharacterSet(font, "CON300", new TimesItalic());
+        num = addFontProperties(fontInfo, font, timesNames,
+                Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
+
+        font = new RasterFont("Times Roman Bold");
+        addCharacterSet(font, "CON400", new TimesBold());
+        num = addFontProperties(fontInfo, font, timesNames,
+                Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
+
+        font = new RasterFont("Times Roman Italic Bold");
+        addCharacterSet(font, "CON500", new TimesBoldItalic());
+        num = addFontProperties(fontInfo, font, timesNames,
+                Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
+
+
+        /** standard font family reference names for Courier font */
+        final String[] courierNames = {"Courier", "monospace"};
+
+        font = new RasterFont("Courier");
+        addCharacterSet(font, "C04200", new Courier());
+        num = addFontProperties(fontInfo, font, courierNames,
+                Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
+
+        font = new RasterFont("Courier Italic");
+        addCharacterSet(font, "C04300", new CourierOblique());
+        num = addFontProperties(fontInfo, font, courierNames,
+                Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
+
+        font = new RasterFont("Courier Bold");
+        addCharacterSet(font, "C04400", new CourierBold());
+        num = addFontProperties(fontInfo, font, courierNames,
+                Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
+
+        font = new RasterFont("Courier Italic Bold");
+        addCharacterSet(font, "C04500", new CourierBoldOblique());
+        num = addFontProperties(fontInfo, font, courierNames,
+                Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
+
+        return num;
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java?rev=680747&r1=680746&r2=680747&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java Tue Jul 29 09:00:14 2008
@@ -23,13 +23,9 @@
 import java.util.List;
 
 import org.apache.fop.events.EventBroadcaster;
-import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontCollection;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
-import org.apache.fop.fonts.base14.Courier;
-import org.apache.fop.fonts.base14.Helvetica;
-import org.apache.fop.fonts.base14.TimesRoman;
 import org.apache.fop.render.afp.AFPEventProducer;
 
 /**
@@ -37,34 +33,29 @@
  */
 public class AFPFontCollection implements FontCollection {
 
-    private static final String DEFAULT_CODEPAGE = "T1V10500";
-    
-    private static final String DEFAULT_ENCODING = "Cp500";
-
-    
-    private EventBroadcaster eventBroadcaster;
-    
-    private List/*<EmbedFontInfo>*/ embedFontInfoList;
+    private final EventBroadcaster eventBroadcaster;
+
+    private final List/*<AFPFontInfo>*/ fontInfoList;
 
     /**
      * Main constructor
      *
      * @param eventBroadcaster the event broadcaster
-     * @param embedFontInfoList the embed font info list
+     * @param fontInfoList the font info list
      */
     public AFPFontCollection(EventBroadcaster eventBroadcaster,
-            List/*<EmbedFontInfo>*/ embedFontInfoList) {
+            List/*<AFPFontInfo>*/ fontInfoList) {
         this.eventBroadcaster = eventBroadcaster;
-        this.embedFontInfoList = embedFontInfoList;
+        this.fontInfoList = fontInfoList;
     }
-        
+
     /** {@inheritDoc} */
     public int setup(int start, FontInfo fontInfo) {
         int num = 1;
-        if (embedFontInfoList != null && embedFontInfoList.size() > 0) {
-            for (Iterator it = embedFontInfoList.iterator(); it.hasNext();) {
+        if (fontInfoList != null && fontInfoList.size() > 0) {
+            for (Iterator it = fontInfoList.iterator(); it.hasNext();) {
                 AFPFontInfo afpFontInfo = (AFPFontInfo)it.next();
-                AFPFont afpFont = (AFPFont)afpFontInfo.getAFPFont();
+                AFPFont afpFont = afpFontInfo.getAFPFont();
                 List/*<FontTriplet>*/ tripletList = afpFontInfo.getFontTriplets();
                 for (Iterator it2 = tripletList.iterator(); it2.hasNext();) {
                     FontTriplet triplet = (FontTriplet)it2.next();
@@ -77,41 +68,10 @@
         } else {
             AFPEventProducer eventProducer = AFPEventProducer.Provider.get(eventBroadcaster);
             eventProducer.warnDefaultFontSetup(this);
-        }
 
-        // note: these fonts may not exist on your AFP installation
-        if (fontInfo.fontLookup("sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
-            CharacterSet cs  = new FopCharacterSet(DEFAULT_CODEPAGE, DEFAULT_ENCODING, "CZH200",
-                    1, new Helvetica());
-            AFPFont bf = new OutlineFont("Helvetica", cs);
-            fontInfo.addFontProperties(
-                    "F" + num, "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            fontInfo.addMetrics("F" + num, bf);
-            num++;
-        }
-        if (fontInfo.fontLookup("serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
-            CharacterSet cs  = new FopCharacterSet(DEFAULT_CODEPAGE, DEFAULT_ENCODING, "CZN200",
-                    1, new TimesRoman());
-            AFPFont bf = new OutlineFont("Helvetica", cs);
-            fontInfo.addFontProperties("F" + num, "serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            fontInfo.addMetrics("F" + num, bf);
-            num++;
-        }
-        if (fontInfo.fontLookup("monospace", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
-            CharacterSet cs  = new FopCharacterSet(DEFAULT_CODEPAGE, DEFAULT_ENCODING, "CZ4200",
-                    1, new Courier());
-            AFPFont bf = new OutlineFont("Helvetica", cs);
-            fontInfo.addFontProperties(
-                    "F" + num, "monospace", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            fontInfo.addMetrics("F" + num, bf);
-            num++;
-        }
-        if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
-            FontTriplet ft = fontInfo.fontLookup(
-                    "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            fontInfo.addFontProperties(
-                    fontInfo.getInternalFontKey(ft), "any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            num++;
+            // Go with a default base 12 configuration for AFP environments
+            FontCollection base12FontCollection = new AFPBase12FontCollection();
+            num = base12FontCollection.setup(num, fontInfo);
         }
         return num;
     }

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java?rev=680747&r1=680746&r2=680747&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java Tue Jul 29 09:00:14 2008
@@ -49,8 +49,15 @@
     /** Static logging instance */
     protected static final Log log = LogFactory.getLog(CharacterSet.class.getName());
 
+    /** default codepage */
+    protected static final String DEFAULT_CODEPAGE = "T1V10500";
+
+    /** default encoding */
+    protected static final String DEFAULT_ENCODING = "Cp500";
+
     private static final int MAX_NAME_LEN = 8;
-    
+
+
     /** The code page to which the character set relates */
     protected String codePage;
 
@@ -67,7 +74,7 @@
     private boolean isMetricsLoaded = false;
 
     /** The current orientation (currently only 0 is supported by FOP) */
-    private String currentOrientation = "0";
+    private final String currentOrientation = "0";
 
     /** The collection of objects for each orientation */
     private Map characterSetOrientations = null;
@@ -195,7 +202,7 @@
 
     /**
      * XHeight refers to the height of the lower case letters above the baseline.
-     * 
+     *
      * @return the typical height of characters
      */
     public int getXHeight() {



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