Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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: AFMParser.java 1761019 2016-09-16 10:43:45Z ssteiner $ */
package org.apache.fop.fonts.type1;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.fonts.NamedCharacter;
/**
* Parses the contents of a Type 1 AFM font metrics file into an object structure ({@link AFMFile}).
*/
public class AFMParser {
private static Log log = LogFactory.getLog(AFMParser.class);
private static final String START_FONT_METRICS = "StartFontMetrics";
//private static final String END_FONT_METRICS = "EndFontMetrics";
private static final String FONT_NAME = "FontName";
private static final String FULL_NAME = "FullName";
private static final String FAMILY_NAME = "FamilyName";
private static final String WEIGHT = "Weight";
private static final String FONT_BBOX = "FontBBox";
private static final String ENCODING_SCHEME = "EncodingScheme";
private static final String CHARACTER_SET = "CharacterSet";
private static final String IS_BASE_FONT = "IsBaseFont";
private static final String IS_CID_FONT = "IsCIDFont";
private static final String CAP_HEIGHT = "CapHeight";
private static final String X_HEIGHT = "XHeight";
private static final String ASCENDER = "Ascender";
private static final String DESCENDER = "Descender";
private static final String STDHW = "StdHW";
private static final String STDVW = "StdVW";
private static final String UNDERLINE_POSITION = "UnderlinePosition";
private static final String UNDERLINE_THICKNESS = "UnderlineThickness";
private static final String ITALIC_ANGLE = "ItalicAngle";
private static final String IS_FIXED_PITCH = "IsFixedPitch";
private static final String START_DIRECTION = "StartDirection";
private static final String END_DIRECTION = "EndDirection";
private static final String START_CHAR_METRICS = "StartCharMetrics";
private static final String END_CHAR_METRICS = "EndCharMetrics";
private static final String C = "C";
private static final String CH = "CH";
private static final String WX = "WX";
private static final String W0X = "W0X";
private static final String W1X = "W1X";
private static final String WY = "WY";
private static final String W0Y = "W0Y";
private static final String W1Y = "W1Y";
private static final String W = "W";
private static final String W0 = "W0";
private static final String W1 = "W1";
private static final String N = "N";
private static final String B = "B";
private static final String START_TRACK_KERN = "StartTrackKern";
private static final String END_TRACK_KERN = "EndTrackKern";
//private static final String START_KERN_PAIRS = "StartKernPairs";
//private static final String START_KERN_PAIRS0 = "StartKernPairs0";
private static final String START_KERN_PAIRS1 = "StartKernPairs1";
//private static final String END_KERN_PAIRS = "EndKernPairs";
private static final String START_COMPOSITES = "StartComposites";
private static final String START_COMP_FONT_METRICS = "StartCompFontMetrics";
private static final String KP = "KP";
private static final String KPH = "KPH";
private static final String KPX = "KPX";
private static final String KPY = "KPY";
private static final int PARSE_NORMAL = 0;
private static final int PARSE_CHAR_METRICS = 1;
private static final Map VALUE_PARSERS;
private static final Map PARSE_MODE_CHANGES;
static {
VALUE_PARSERS = new HashMap();
VALUE_PARSERS.put(START_FONT_METRICS, new StartFontMetrics());
VALUE_PARSERS.put(FONT_NAME, new StringSetter(FONT_NAME));
VALUE_PARSERS.put(FULL_NAME, new StringSetter(FULL_NAME));
VALUE_PARSERS.put(FAMILY_NAME, new StringSetter(FAMILY_NAME));
VALUE_PARSERS.put(WEIGHT, new StringSetter(WEIGHT));
VALUE_PARSERS.put(ENCODING_SCHEME, new StringSetter(ENCODING_SCHEME));
VALUE_PARSERS.put(FONT_BBOX, new FontBBox());
VALUE_PARSERS.put(CHARACTER_SET, new StringSetter(CHARACTER_SET));
VALUE_PARSERS.put(IS_BASE_FONT, new IsBaseFont());
VALUE_PARSERS.put(IS_CID_FONT, new IsCIDFont());
VALUE_PARSERS.put(CAP_HEIGHT, new NumberSetter(CAP_HEIGHT));
VALUE_PARSERS.put(X_HEIGHT, new NumberSetter(X_HEIGHT));
VALUE_PARSERS.put(ASCENDER, new NumberSetter(ASCENDER));
VALUE_PARSERS.put(DESCENDER, new NumberSetter(DESCENDER));
VALUE_PARSERS.put(STDHW, new NumberSetter(STDHW));
VALUE_PARSERS.put(STDVW, new NumberSetter(STDVW));
VALUE_PARSERS.put(START_DIRECTION, new StartDirection());
VALUE_PARSERS.put(END_DIRECTION, new EndDirection());
VALUE_PARSERS.put(UNDERLINE_POSITION, new WritingDirNumberSetter(UNDERLINE_POSITION));
VALUE_PARSERS.put(UNDERLINE_THICKNESS, new WritingDirNumberSetter(UNDERLINE_THICKNESS));
VALUE_PARSERS.put(ITALIC_ANGLE, new WritingDirDoubleSetter(ITALIC_ANGLE));
VALUE_PARSERS.put(IS_FIXED_PITCH, new WritingDirBooleanSetter(IS_FIXED_PITCH));
VALUE_PARSERS.put(C, new IntegerSetter("CharCode"));
VALUE_PARSERS.put(CH, new NotImplementedYet(CH));
VALUE_PARSERS.put(WX, new DoubleSetter("WidthX"));
VALUE_PARSERS.put(W0X, new DoubleSetter("WidthX"));
VALUE_PARSERS.put(W1X, new NotImplementedYet(W1X));
VALUE_PARSERS.put(WY, new DoubleSetter("WidthY"));
VALUE_PARSERS.put(W0Y, new DoubleSetter("WidthY"));
VALUE_PARSERS.put(W1Y, new NotImplementedYet(W1Y));
VALUE_PARSERS.put(W, new NotImplementedYet(W));
VALUE_PARSERS.put(W0, new NotImplementedYet(W0));
VALUE_PARSERS.put(W1, new NotImplementedYet(W1));
VALUE_PARSERS.put(N, new NamedCharacterSetter("Character"));
VALUE_PARSERS.put(B, new CharBBox());
VALUE_PARSERS.put(START_TRACK_KERN, new NotImplementedYet(START_TRACK_KERN));
VALUE_PARSERS.put(START_KERN_PAIRS1, new NotImplementedYet(START_KERN_PAIRS1));
VALUE_PARSERS.put(START_COMPOSITES, new NotImplementedYet(START_COMPOSITES));
VALUE_PARSERS.put(START_COMP_FONT_METRICS, new NotImplementedYet(START_COMP_FONT_METRICS));
VALUE_PARSERS.put(KP, new NotImplementedYet(KP));
VALUE_PARSERS.put(KPH, new NotImplementedYet(KPH));
VALUE_PARSERS.put(KPX, new KPXHandler());
VALUE_PARSERS.put(KPY, new NotImplementedYet(KPY));
PARSE_MODE_CHANGES = new HashMap();
PARSE_MODE_CHANGES.put(START_CHAR_METRICS, PARSE_CHAR_METRICS);
PARSE_MODE_CHANGES.put(END_CHAR_METRICS, PARSE_NORMAL);
}
/**
* Main constructor.
*/
public AFMParser() {
}
/**
* Parses an AFM file from a stream.
* @param in the stream to read from
* @param afmFileName the name of the AFM file
* @return the parsed AFM file
* @throws IOException if an I/O error occurs
*/
public AFMFile parse(InputStream in, String afmFileName) throws IOException {
Reader reader = new java.io.InputStreamReader(in, "US-ASCII");
try {
return parse(new BufferedReader(reader), afmFileName);
} finally {
IOUtils.closeQuietly(reader);
}
}
/**
* Parses an AFM file from a BufferedReader.
* @param reader the BufferedReader instance to read from
* @param afmFileName the name of the AFM file
* @return the parsed AFM file
* @throws IOException if an I/O error occurs
*/
public AFMFile parse(BufferedReader reader, String afmFileName) throws IOException {
Stack