package org.apache.fop.afp.fonts;
import org.apache.fop.afp.AFPEventProducer;
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;
public class AFPBase12FontCollection implements FontCollection {
private final AFPEventProducer eventProducer;
public AFPBase12FontCollection(AFPEventProducer eventProducer) {
this.eventProducer = eventProducer;
}
private static final int[] RASTER_SIZES = {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 30, 36};
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] * 1000;
FopCharacterSet characterSet = new FopCharacterSet(
CharacterSet.DEFAULT_CODEPAGE, CharacterSet.DEFAULT_ENCODING,
charsetName + CHARSET_REF[i], base14, eventProducer);
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;
}
public int setup(int start, FontInfo fontInfo) {
int num = start;
RasterFont font = null;
final String[] helveticaNames = {"Helvetica", "Arial", "sans-serif"};
font = createReferencedRasterFont("Helvetica");
addCharacterSet(font, "C0H200", new Helvetica());
num = addFontProperties(fontInfo, font, helveticaNames,
Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
font = createReferencedRasterFont("Helvetica Italic");
addCharacterSet(font, "C0H300", new HelveticaOblique());
num = addFontProperties(fontInfo, font, helveticaNames,
Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
font = createReferencedRasterFont("Helvetica (Semi) Bold");
addCharacterSet(font, "C0H400", new HelveticaBold());
num = addFontProperties(fontInfo, font, helveticaNames,
Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
font = createReferencedRasterFont("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", "any"};
font = createReferencedRasterFont("Times Roman");
addCharacterSet(font, "C0N200", new TimesRoman());
num = addFontProperties(fontInfo, font, timesNames,
Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
font = createReferencedRasterFont("Times Roman Italic");
addCharacterSet(font, "C0N300", new TimesItalic());
num = addFontProperties(fontInfo, font, timesNames,
Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
font = createReferencedRasterFont("Times Roman Bold");
addCharacterSet(font, "C0N400", new TimesBold());
num = addFontProperties(fontInfo, font, timesNames,
Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
font = createReferencedRasterFont("Times Roman Italic Bold");
addCharacterSet(font, "C0N500", new TimesBoldItalic());
num = addFontProperties(fontInfo, font, timesNames,
Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
final String[] courierNames = {"Courier", "monospace"};
font = createReferencedRasterFont("Courier");
addCharacterSet(font, "C04200", new Courier());
num = addFontProperties(fontInfo, font, courierNames,
Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
font = createReferencedRasterFont("Courier Italic");
addCharacterSet(font, "C04300", new CourierOblique());
num = addFontProperties(fontInfo, font, courierNames,
Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
font = createReferencedRasterFont("Courier Bold");
addCharacterSet(font, "C04400", new CourierBold());
num = addFontProperties(fontInfo, font, courierNames,
Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
font = createReferencedRasterFont("Courier Italic Bold");
addCharacterSet(font, "C04500", new CourierBoldOblique());
num = addFontProperties(fontInfo, font, courierNames,
Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
return num;
}
private RasterFont createReferencedRasterFont(String fontFamily) {
boolean embeddable = false;
return new RasterFont(fontFamily, embeddable);
}
}