Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j.
   * The package name has been changed; there may also be other changes.
   * 
   * This notice is included to meet the condition in clause 4(b) of the License. 
   */
  
   /*
   * 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: AFMFile.java 679326 2008-07-24 09:35:34Z vhennebert $ */
 
 package org.docx4j.fonts.fop.fonts.type1;
 
 import java.util.List;
 import java.util.Map;
 
Represents the contents of a Type 1 AFM font metrics file.
 
 public class AFMFile {
 
     private String fontName;
     private String fullName;
     private String familyName;
 
     private String weight;
     private RectangularShape fontBBox;
 
     private String encodingScheme;
     private String characterSet;
 
     private Number capHeight;
     private Number xHeight;
     private Number ascender;
     private Number descender;
     private Number stdHW;
     private Number stdVW;
 
         = new AFMWritingDirectionMetrics[3];
 
     private List charMetrics = new java.util.ArrayList();
     //List<AFMCharMetrics>
     private Map charNameToMetrics = new java.util.HashMap();
     //Map<String, AFMCharMetrics>
     private int firstChar = -1;
     private int lastChar = -1;
 
     private Map kerningMap;
     //Map<String, Map<String, Dimension2D>>
 
    
Default constructor.
 
     public AFMFile() {
         //nop
     }

    
Returns the FontName value.

Returns:
the font name
 
     public String getFontName() {
         return ;
     }

    
Sets the FontName value.

Parameters:
fontName the font name to set
 
     public void setFontName(String fontName) {
         this. = fontName;
     }

    
Returns the FullName value.

Returns:
the full name of the font
 
     public String getFullName() {
        return ;
    }

    
Sets the FullName value.

Parameters:
fullName the full name to set
    public void setFullName(String fullName) {
        this. = fullName;
    }

    
Returns the FamilyName value.

Returns:
the family name of the font
    public String getFamilyName() {
        return ;
    }

    
Sets the FamilyName value.

Parameters:
familyName the family name to set
    public void setFamilyName(String familyName) {
        this. = familyName;
    }

    
Returns the Weight value.

Returns:
the weight
    public String getWeight() {
        return ;
    }

    
Sets the Weight value.

Parameters:
weight the weight to set
    public void setWeight(String weight) {
        this. = weight;
    }

    
Returns the FontBBox value.

Returns:
the font's bounding box
    public RectangularShape getFontBBox() {
        return ;
    }

    
Returns the FontBBox value as integer array.

Returns:
the font's bounding box
    public int[] getFontBBoxAsIntArray() {
        RectangularShape rect = getFontBBox();
        return new int[] {
                (int)Math.floor(rect.getMinX()), (int)Math.floor(rect.getMinY()),
                (int)Math.ceil(rect.getMaxX()), (int)Math.ceil(rect.getMaxY())};
    }

    
Sets the FontBBox value.

Parameters:
fontBBox the fontBBox to set
    public void setFontBBox(RectangularShape fontBBox) {
        this. = fontBBox;
    }

    
Returns the EncodingScheme value.

Returns:
the encoding scheme
    public String getEncodingScheme() {
        return ;
    }

    
Sets the EncodingScheme value

Parameters:
encodingScheme the encodingScheme to set
    public void setEncodingScheme(String encodingScheme) {
        this. = encodingScheme;
    }

    
Returns the CharacterSet value.

Returns:
the characterSet
    public String getCharacterSet() {
        return ;
    }

    
Sets the CharacterSet value.

Parameters:
characterSet the characterSet to set
    public void setCharacterSet(String characterSet) {
        this. = characterSet;
    }

    
Returns the CapHeight value.

Returns:
the capHeight
    public Number getCapHeight() {
        return ;
    }

    
Sets the CapHeight value.

Parameters:
capHeight the capHeight to set
    public void setCapHeight(Number capHeight) {
        this. = capHeight;
    }

    
Returns the XHeight value.

Returns:
the xHeight
    public Number getXHeight() {
        return ;
    }

    
Sets the XHeight value.

Parameters:
height the xHeight to set
    public void setXHeight(Number height) {
         = height;
    }

    
Returns the Ascender value.

Returns:
the ascender
    public Number getAscender() {
        return ;
    }

    
Sets the Ascender value.

Parameters:
ascender the ascender to set
    public void setAscender(Number ascender) {
        this. = ascender;
    }

    
Returns the Descender value.

Returns:
the descender
    public Number getDescender() {
        return ;
    }

    
Sets the Descender value.

Parameters:
descender the descender to set
    public void setDescender(Number descender) {
        this. = descender;
    }

    
Returns the StdHW value.

Returns:
the descender
    public Number getStdHW() {
        return ;
    }

    
Sets the StdHW value.

Parameters:
stdHW the StdHW to set
    public void setStdHW(Number stdHW) {
        this. = stdHW;
    }

    
Returns the StdVW value.

Returns:
the descender
    public Number getStdVW() {
        return ;
    }

    
Sets the StdVW value.

Parameters:
stdVW the StdVW to set
    public void setStdVW(Number stdVW) {
        this. = stdVW;
    }

    
Gets writing direction metrics.

Parameters:
index the writing direction (0, 1 or 2)
Returns:
the writing direction metrics
        return this.[index];
    }

    
Sets writing direction metrics.

Parameters:
index the writing direction (0, 1 or 2)
metrics the writing direction metrics
    public void setWritingDirectionMetrics(int indexAFMWritingDirectionMetrics metrics) {
        this.[index] = metrics;
    }

    
Adds new character metrics.

Parameters:
metrics the character metrics
    public void addCharMetrics(AFMCharMetrics metrics) {
        String name = metrics.getCharName();
        if (metrics.getUnicodeSequence() == null) {
            //Ignore as no Unicode assignment is possible
            return;
        }
        this..add(metrics);
        if (name != null) {
            this..put(namemetrics);
        }
        int idx = metrics.getCharCode();
        if (idx >= 0) { //Only if the character is part of the encoding
            if ( < 0 || idx < ) {
                 = idx;
            }
            if ( < 0 || idx > ) {
                 = idx;
            }
        }
    }

    
Returns the number of character available for this font.

Returns:
the number of character
    public int getCharCount() {
        return this..size();
    }

    
Returns the first character index in the encoding that has a glyph.

Returns:
the first character index with a glyph
    public int getFirstChar() {
        return this.;
    }

    
Returns the last character index in the encoding that has a glyph.

Returns:
the last character index with a glyph
    public int getLastChar() {
        return this.;
    }

    
Returns the character metrics associated with the character name.

Parameters:
name the character name
Returns:
the character metrics or null if there's no such character
    public AFMCharMetrics getChar(String name) {
        return (AFMCharMetrics)this..get(name);
    }

    
Returns the list of AFMCharMetrics instances representing all the available characters.

Returns:
a List of AFMCharMetrics instances
    public List getCharMetrics() {
        return Collections.unmodifiableList(this.);
    }

    
Adds a X-kerning entry.

Parameters:
name1 the name of the first character
name2 the name of the second character
kx kerning value in x-direction
    public void addXKerning(String name1String name2double kx) {
        if (this. == null) {
            this. = new java.util.HashMap();
        }
        Map entries = (Map)this..get(name1);
        if (entries == null) {
            entries = new java.util.HashMap();
            this..put(name1entries);
        }
        entries.put(name2new Dimension2DDouble(kx, 0));
    }

    
Indicates whether the font has kerning information.

Returns:
true if there is kerning information
    public boolean hasKerning() {
        return this. != null;
    }

    
Creates and returns a kerning map for writing mode 0 (ltr) with character codes.

Returns:
the kerning map or null if there is no kerning information.
    public Map createXKerningMapEncoded() {
        if (!hasKerning()) {
            return null;
        }
        Map m = new java.util.HashMap();
        Iterator iterFrom = this..entrySet().iterator();
        while (iterFrom.hasNext()) {
            Map.Entry entryFrom = (Map.Entry)iterFrom.next();
            String name1 = (String)entryFrom.getKey();
            AFMCharMetrics chm1 = getChar(name1);
            if (chm1 == null || !chm1.hasCharCode()) {
                continue;
            }
            Map container = null;
            Map entriesTo = (Map)entryFrom.getValue();
            Iterator iterTo = entriesTo.entrySet().iterator();
            while (iterTo.hasNext()) {
                Map.Entry entryTo = (Map.Entry)iterTo.next();
                String name2 = (String)entryTo.getKey();
                AFMCharMetrics chm2 = getChar(name2);
                if (chm2 == null || !chm2.hasCharCode()) {
                    continue;
                }
                if (container == null) {
                    Integer k1 = new Integer(chm1.getCharCode());
                    container = (Map)m.get(k1);
                    if (container == null) {
                        container = new java.util.HashMap();
                        m.put(k1container);
                    }
                }
                Dimension2D dim = (Dimension2D)entryTo.getValue();
                container.put(new Integer(chm2.getCharCode()),
                        new Integer((int)Math.round(dim.getWidth())));
            }
        }
        return m;
    }

    
    public String toString() {
        return "AFM: " + getFullName();
    }
New to GrepCode? Check out our FAQ X