vmote       2003/08/30 11:52:35

  Modified:    src/java/org/apache/fop/fonts CIDFont.java
                        MultiByteFont.java
               src/java/org/apache/fop/pdf PDFFactory.java
  Log:
  1. move some data structures related to used glyphs from fonts/MultiByteFont to 
superclass fonts/CIDFont
  2. move getSubsetWidths() from fonts/CIDFont (and subclass) to pdf/PDFFactory
  
  Revision  Changes    Path
  1.5       +16 -8     xml-fop/src/java/org/apache/fop/fonts/CIDFont.java
  
  Index: CIDFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/CIDFont.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CIDFont.java      23 Aug 2003 17:38:12 -0000      1.4
  +++ CIDFont.java      30 Aug 2003 18:52:35 -0000      1.5
  @@ -50,13 +50,28 @@
    */
   package org.apache.fop.fonts;
   
  -import org.apache.fop.pdf.PDFWArray;
  +//Java
  +import java.util.Map;
   
   /**
    * Abstract base class for CID fonts.
    */
   public abstract class CIDFont extends CustomFont {
   
  +    /**
  +     * usedGlyphs contains orginal, new glyph index
  +     */
  +    public Map usedGlyphs = new java.util.HashMap();
  +
  +    /**
  +     * usedGlyphsIndex contains new glyph, original index
  +     */
  +    public Map usedGlyphsIndex = new java.util.HashMap();
  +    public int usedGlyphsCount = 0;
  +
  +    //private PDFWArray warray = new PDFWArray();
  +    public int width[] = null;
  +
       // ---- Required ----
       /**
        * Returns the name of the base font.
  @@ -106,12 +121,5 @@
       public boolean isMultiByte() {
           return true;
       }
  -
  -    /**
  -     * Returns a PDFWArray containing all the widths of the subset to be used.
  -     * @return the character widths
  -     * (todo) Try to avoid dependency on PDF library
  -     */
  -    public abstract PDFWArray getSubsetWidths();
   
   }
  
  
  
  1.4       +0 -34     xml-fop/src/java/org/apache/fop/fonts/MultiByteFont.java
  
  Index: MultiByteFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/MultiByteFont.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultiByteFont.java        23 Aug 2003 17:38:12 -0000      1.3
  +++ MultiByteFont.java        30 Aug 2003 18:52:35 -0000      1.4
  @@ -53,9 +53,6 @@
   //Java
   import java.util.Map;
   
  -//FOP
  -import org.apache.fop.pdf.PDFWArray;
  -
   /**
    * Generic MultiByte (CID) font
    */
  @@ -73,24 +70,10 @@
       private CIDFontType cidType = CIDFontType.CIDTYPE2;
   
       private String namePrefix = null;    // Quasi unique prefix
  -    //private PDFWArray warray = new PDFWArray();
  -    private int width[] = null;
   
       private BFEntry[] bfentries = null;
   
       /**
  -     * usedGlyphs contains orginal, new glyph index
  -     */
  -    private Map usedGlyphs = new java.util.HashMap();
  -
  -    /**
  -     * usedGlyphsIndex contains new glyph, original index
  -     */
  -    private Map usedGlyphsIndex = new java.util.HashMap();
  -    private int usedGlyphsCount = 0;
  -
  -
  -    /**
        * Default constructor
        */
       public MultiByteFont() {
  @@ -223,23 +206,6 @@
               arr[i] *= size;
           */
           return arr;
  -    }
  -
  -    /**
  -     * @see org.apache.fop.fonts.CIDFont#getSubsetWidths()
  -     */
  -    public PDFWArray getSubsetWidths() {
  -        // Create widths for reencoded chars
  -        PDFWArray warray = new PDFWArray();
  -        int[] tmpWidth = new int[usedGlyphsCount];
  -
  -        for (int i = 0; i < usedGlyphsCount; i++) {
  -            Integer nw = (Integer)usedGlyphsIndex.get(new Integer(i));
  -            int nwx = (nw == null) ? 0 : nw.intValue();
  -            tmpWidth[i] = width[nwx];
  -        }
  -        warray.addEntry(0, tmpWidth);
  -        return warray;
       }
   
       /**
  
  
  
  1.6       +54 -41    xml-fop/src/java/org/apache/fop/pdf/PDFFactory.java
  
  Index: PDFFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PDFFactory.java   14 Aug 2003 14:59:56 -0000      1.5
  +++ PDFFactory.java   30 Aug 2003 18:52:35 -0000      1.6
  @@ -3,34 +3,34 @@
    * ============================================================================
    *                    The Apache Software License, Version 1.1
    * ============================================================================
  - * 
  + *
    * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  - * 
  + *
    * Redistribution and use in source and binary forms, with or without modifica-
    * tion, are permitted provided that the following conditions are met:
  - * 
  + *
    * 1. Redistributions of source code must retain the above copyright notice,
    *    this list of conditions and the following disclaimer.
  - * 
  + *
    * 2. Redistributions in binary form must reproduce the above copyright notice,
    *    this list of conditions and the following disclaimer in the documentation
    *    and/or other materials provided with the distribution.
  - * 
  + *
    * 3. The end-user documentation included with the redistribution, if any, must
    *    include the following acknowledgment: "This product includes software
    *    developed by the Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself, if
    *    and wherever such third-party acknowledgments normally appear.
  - * 
  + *
    * 4. The names "FOP" and "Apache Software Foundation" must not be used to
    *    endorse or promote products derived from this software without prior
    *    written permission. For written permission, please contact
    *    [EMAIL PROTECTED]
  - * 
  + *
    * 5. Products derived from this software may not be called "Apache", nor may
    *    "Apache" appear in their name, without prior written permission of the
    *    Apache Software Foundation.
  - * 
  + *
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  @@ -42,12 +42,12 @@
    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    * ============================================================================
  - * 
  + *
    * This software consists of voluntary contributions made by many individuals
    * on behalf of the Apache Software Foundation and was originally created by
    * James Tauber <[EMAIL PROTECTED]>. For more information on the Apache
    * Software Foundation, please see <http://www.apache.org/>.
  - */ 
  + */
   package org.apache.fop.pdf;
   
   // Java
  @@ -81,7 +81,7 @@
   public class PDFFactory {
   
       private PDFDocument document;
  -    
  +
       /**
        * Creates a new PDFFactory.
        * @param document the parent PDFDocument needed to register the generated
  @@ -100,7 +100,7 @@
       }
   
       /* ========================= structure objects ========================= */
  -    
  +
       /**
        * Make a /Catalog (Root) object. This object is written in
        * the trailer.
  @@ -158,7 +158,7 @@
   
       /**
        * Make a /Page object. The page is assigned an object number immediately
  -     * so references can already be made. The page must be added to the 
  +     * so references can already be made. The page must be added to the
        * PDFDocument later using addObject().
        *
        * @param resources resources object to use
  @@ -183,7 +183,7 @@
       }
   
       /* ========================= functions ================================= */
  -    
  +
       /**
        * Make a Type 0 sampled function
        *
  @@ -661,7 +661,7 @@
        * @param theXUID optional:the extended unique Identifier if used.
        * @param theExtGState optional: the extended graphics state, if used.
        * @param theMatrix Optional:List of Doubles that specify the matrix.
  -     * @return the PDF pattern that was created       
  +     * @return the PDF pattern that was created
        */
       public PDFPattern makePattern(PDFResourceContext res,
                                     int thePatternType, PDFShading theShading,
  @@ -688,7 +688,7 @@
   
       /**
        * Make a gradient
  -     *  
  +     *
        * @param res the PDF resource context to add the shading, may be null
        * @param radial if true a radial gradient will be created
        * @param theColorspace the colorspace of the gradient
  @@ -732,7 +732,7 @@
                       getDocument().getColorSpace());
               }
   
  -            if (getDocument().getColorSpace() 
  +            if (getDocument().getColorSpace()
                       != nextColor.getColorSpace()) {
                   nextColor.setColorSpace(
                       getDocument().getColorSpace());
  @@ -753,7 +753,7 @@
   
           if (radial) {
               if (theCoords.size() == 6) {
  -                myShad = makeShading(res, 3, getDocument().getPDFColorSpace(), 
  +                myShad = makeShading(res, 3, getDocument().getPDFColorSpace(),
                                        null, null,
                                        false, theCoords, null, myfunky,
                                        null);
  @@ -768,16 +768,16 @@
                   newCoords.add(theCoords.get(1));
                   newCoords.add(new Double(0.0));
   
  -                myShad = makeShading(res, 3, getDocument().getPDFColorSpace(), 
  +                myShad = makeShading(res, 3, getDocument().getPDFColorSpace(),
                                        null, null,
                                        false, newCoords, null, myfunky,
                                        null);
   
               }
           } else {
  -            myShad = makeShading(res, 2, getDocument().getPDFColorSpace(), 
  -                                 null, null, 
  -                                 false, theCoords, null, myfunky, 
  +            myShad = makeShading(res, 2, getDocument().getPDFColorSpace(),
  +                                 null, null,
  +                                 false, theCoords, null, myfunky,
                                    null);
   
           }
  @@ -881,7 +881,7 @@
           goToReference = gt.referencePDF();
           return goToReference;
       }
  -    
  +
       /**
        * Create and return a goto pdf document action.
        * This creates a pdf files spec and pdf goto remote action.
  @@ -941,7 +941,7 @@
           return obj;
       }
   
  -    
  +
   
       /* ========================= fonts ===================================== */
   
  @@ -953,7 +953,7 @@
        */
       public PDFEncoding makeEncoding(String encodingName) {
           PDFEncoding encoding = new PDFEncoding(encodingName);
  -        
  +
           getDocument().registerObject(encoding);
           return encoding;
       }
  @@ -1027,7 +1027,7 @@
                       new PDFCIDFont(basefont,
                                      cidMetrics.getCIDType(),
                                      cidMetrics.getDefaultWidth(),
  -                                   cidMetrics.getSubsetWidths(), sysInfo,
  +                                   getSubsetWidths(cidMetrics), sysInfo,
                                      (PDFCIDFontDescriptor)pdfdesc);
                   getDocument().registerObject(cidFont);
   
  @@ -1049,6 +1049,19 @@
           }
       }
   
  +    public PDFWArray getSubsetWidths(CIDFont cidFont) {
  +        // 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
  @@ -1100,8 +1113,8 @@
           if (desc.getFontType() == FontType.OTHER) {
               throw new IllegalArgumentException("Trying to embed unsupported font 
type: "
                                                   + desc.getFontType());
  -        } 
  -        
  +        }
  +
           Typeface tempFont;
           if (desc instanceof LazyFont) {
               tempFont = ((LazyFont)desc).getRealFont();
  @@ -1114,7 +1127,7 @@
                          + desc.getClass().getName());
           }
           CustomFont font = (CustomFont)tempFont;
  -        
  +
           InputStream in = null;
           try {
               // Get file first
  @@ -1123,11 +1136,11 @@
                       in = getDocument().resolveURI(font.getEmbedFileName());
                   } catch (Exception e) {
                       getDocument().getLogger().error("Failed to embed fontfile: "
  -                                       + font.getEmbedFileName() 
  +                                       + font.getEmbedFileName()
                                          + "(" + e.getMessage() + ")");
                   }
               }
  -    
  +
               // Get resource
               if (in == null && font.getEmbedResourceName() != null) {
                   try {
  @@ -1141,7 +1154,7 @@
                                          + "(" + e.getMessage() + ")");
                   }
               }
  -    
  +
               if (in == null) {
                   return null;
               } else {
  @@ -1154,7 +1167,7 @@
                           TTFSubSetFile subset = new TTFSubSetFile();
                           ContainerUtil.enableLogging(subset,
                               getDocument().getLogger().getChildLogger("fonts"));
  -        
  +
                           byte[] subsetFont = subset.readFont(reader,
                                                mbfont.getTTCName(), 
mbfont.getUsedGlyphs());
                           // Only TrueType CID fonts are supported now
  @@ -1171,7 +1184,7 @@
                           embeddedFont = new PDFTTFStream(file.length);
                           ((PDFTTFStream)embeddedFont).setData(file, file.length);
                       }
  -                    
  +
                       /*
                       embeddedFont.getFilterList().addFilter("flate");
                       if (getDocument().isEncryptionActive()) {
  @@ -1179,7 +1192,7 @@
                       } else {
                           embeddedFont.getFilterList().addFilter("ascii-85");
                       }*/
  -                    
  +
                       return embeddedFont;
                   } finally {
                       in.close();
  @@ -1205,12 +1218,12 @@
        */
       public PDFStream makeStream(String type, boolean add) {
   
  -        // create a PDFStream with the next object number 
  +        // create a PDFStream with the next object number
           // and add it to the list of objects
           PDFStream obj = new PDFStream();
           obj.setDocument(getDocument());
           obj.getFilterList().addDefaultFilters(
  -                getDocument().getFilterMap(), 
  +                getDocument().getFilterMap(),
                   type);
   
           if (add) {
  @@ -1230,9 +1243,9 @@
       public PDFICCStream makePDFICCStream() {
           PDFICCStream iccStream = new PDFICCStream();
           iccStream.getFilterList().addDefaultFilters(
  -                getDocument().getFilterMap(), 
  +                getDocument().getFilterMap(),
                   PDFFilterList.CONTENT_FILTER);
  -        
  +
           getDocument().registerObject(iccStream);
           //getDocument().applyEncryption(iccStream);
           return iccStream;
  @@ -1248,7 +1261,7 @@
        */
       public PDFArray makeArray(int[] values) {
           PDFArray array = new PDFArray(values);
  -        
  +
           getDocument().registerObject(array);
           return array;
       }
  @@ -1273,7 +1286,7 @@
           wanted.addValues(PDFGState.DEFAULT);
           wanted.addValues(settings);
   
  -    
  +
           PDFGState existing = getDocument().findGState(wanted, current);
           if (existing != null) {
               return existing;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to