import org.apache.fop.events.ResourceEventProducer;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.extensions.ExtensionAttachment;
+import org.apache.fop.fonts.CustomFontCollection;
+import org.apache.fop.fonts.FontCollection;
import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontManager;
import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.fonts.base14.Base14FontCollection;
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.extensions.AFPElementMapping;
import org.apache.fop.render.afp.extensions.AFPPageSetup;
import org.apache.fop.render.afp.fonts.AFPFont;
+import org.apache.fop.render.afp.fonts.AFPFontCollection;
import org.apache.fop.render.afp.fonts.AFPFontInfo;
import org.apache.fop.render.afp.fonts.CharacterSet;
import org.apache.fop.render.afp.fonts.FopCharacterSet;
*/
public void setupFontInfo(FontInfo inFontInfo) {
this.fontInfo = inFontInfo;
- int num = 1;
- if (super.embedFontInfoList != null && super.embedFontInfoList.size() > 0) {
- for (Iterator it = super.embedFontInfoList.iterator(); it.hasNext();) {
- AFPFontInfo afi = (AFPFontInfo)it.next();
- AFPFont bf = (AFPFont)afi.getAFPFont();
- for (Iterator it2 = afi.getFontTriplets().iterator(); it2.hasNext();) {
- FontTriplet ft = (FontTriplet)it2.next();
- this.fontInfo.addFontProperties("F" + num, ft.getName()
- , ft.getStyle(), ft.getWeight());
- this.fontInfo.addMetrics("F" + num, bf);
- num++;
- }
- }
- } else {
- AFPEventProducer eventProducer = AFPEventProducer.Provider.get(
- getUserAgent().getEventBroadcaster());
- eventProducer.warnDefaultFontSetup(this);
- }
- if (this.fontInfo.fontLookup("sans-serif", "normal", 400) == null) {
- CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZH200 ",
- 1, new Helvetica());
- AFPFont bf = new OutlineFont("Helvetica", cs);
- this.fontInfo.addFontProperties("F" + num, "sans-serif", "normal", 400);
- this.fontInfo.addMetrics("F" + num, bf);
- num++;
- }
- if (this.fontInfo.fontLookup("serif", "normal", 400) == null) {
- CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZN200 ",
- 1, new TimesRoman());
- AFPFont bf = new OutlineFont("Helvetica", cs);
- this.fontInfo.addFontProperties("F" + num, "serif", "normal", 400);
- this.fontInfo.addMetrics("F" + num, bf);
- num++;
- }
- if (this.fontInfo.fontLookup("monospace", "normal", 400) == null) {
- CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZ4200 ",
- 1, new Courier());
- AFPFont bf = new OutlineFont("Helvetica", cs);
- this.fontInfo.addFontProperties("F" + num, "monospace", "normal", 400);
- this.fontInfo.addMetrics("F" + num, bf);
- num++;
- }
- if (this.fontInfo.fontLookup("any", "normal", 400) == null) {
- FontTriplet ft = this.fontInfo.fontLookup("sans-serif", "normal", 400);
- this.fontInfo.addFontProperties(
- this.fontInfo.getInternalFontKey(ft), "any", "normal", 400);
- }
+ FontManager fontManager = userAgent.getFactory().getFontManager();
+ FontCollection[] fontCollections = new FontCollection[] {
+ new AFPFontCollection(userAgent.getEventBroadcaster(), getFontList())
+ };
+ fontManager.setup(getFontInfo(), fontCollections);
}
/**
--- /dev/null
+/*
+ * 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 java.util.Iterator;
+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;
+
+/**
+ * A base collection of AFP fonts
+ */
+public class AFPFontCollection implements FontCollection {
+
+ private EventBroadcaster eventBroadcaster;
+ private List/*<EmbedFontInfo>*/ embedFontInfoList;
+
+ /**
+ * Main constructor
+ *
+ * @param eventBroadcaster the event broadcaster
+ * @param embedFontInfoList the embed font info list
+ */
+ public AFPFontCollection(EventBroadcaster eventBroadcaster,
+ List/*<EmbedFontInfo>*/ embedFontInfoList) {
+ this.eventBroadcaster = eventBroadcaster;
+ this.embedFontInfoList = embedFontInfoList;
+ }
+
+ /** {@inheritDoc} */
+ public int setup(int start, FontInfo fontInfo) {
+ int num = 1;
+ if (embedFontInfoList != null && embedFontInfoList.size() > 0) {
+ for (Iterator it = embedFontInfoList.iterator(); it.hasNext();) {
+ AFPFontInfo afi = (AFPFontInfo)it.next();
+ AFPFont bf = (AFPFont)afi.getAFPFont();
+ for (Iterator it2 = afi.getFontTriplets().iterator(); it2.hasNext();) {
+ FontTriplet ft = (FontTriplet)it2.next();
+ fontInfo.addFontProperties("F" + num, ft.getName()
+ , ft.getStyle(), ft.getWeight());
+ fontInfo.addMetrics("F" + num, bf);
+ num++;
+ }
+ }
+ } else {
+ AFPEventProducer eventProducer = AFPEventProducer.Provider.get(eventBroadcaster);
+ eventProducer.warnDefaultFontSetup(this);
+ }
+ if (fontInfo.fontLookup("sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
+ CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "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("T1V10500", "Cp500", "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("T1V10500", "Cp500", "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++;
+ }
+ return num;
+ }
+
+}