diff options
author | Adrian Cumiskey <acumiskey@apache.org> | 2008-07-17 17:44:08 +0000 |
---|---|---|
committer | Adrian Cumiskey <acumiskey@apache.org> | 2008-07-17 17:44:08 +0000 |
commit | fca2e35075123205aec111949b3f4017cab156f4 (patch) | |
tree | ea892e32648b03a85093750397652e6c7d789fbf /src/java/org/apache/fop/render | |
parent | d31eccba74b58470778230167deb633083694fbf (diff) | |
download | xmlgraphics-fop-fca2e35075123205aec111949b3f4017cab156f4.tar.gz xmlgraphics-fop-fca2e35075123205aec111949b3f4017cab156f4.zip |
Moved font setup stuff from setupFontInfo() in AFPRenderer and delegated this stuff to an AFPFontCollection class.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@677651 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r-- | src/java/org/apache/fop/render/afp/AFPRenderer.java | 57 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java | 110 |
2 files changed, 120 insertions, 47 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 5c8e80312..12c4a3f77 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -74,8 +74,12 @@ import org.apache.fop.datatypes.URISpecification; 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; @@ -85,6 +89,7 @@ import org.apache.fop.render.RendererContext; 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; @@ -279,53 +284,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { */ 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); } /** diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java b/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java new file mode 100644 index 000000000..55953daf0 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java @@ -0,0 +1,110 @@ +/* + * 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; + } + +} |