1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
* 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 static final String DEFAULT_CODEPAGE = "T1V10500";
private static final String DEFAULT_ENCODING = "Cp500";
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 afpFontInfo = (AFPFontInfo)it.next();
AFPFont afpFont = (AFPFont)afpFontInfo.getAFPFont();
List/*<FontTriplet>*/ tripletList = afpFontInfo.getFontTriplets();
for (Iterator it2 = tripletList.iterator(); it2.hasNext();) {
FontTriplet triplet = (FontTriplet)it2.next();
fontInfo.addFontProperties("F" + num,
triplet.getName(), triplet.getStyle(), triplet.getWeight());
fontInfo.addMetrics("F" + num, afpFont);
num++;
}
}
} else {
AFPEventProducer eventProducer = AFPEventProducer.Provider.get(eventBroadcaster);
eventProducer.warnDefaultFontSetup(this);
}
// note: these fonts may not exist on your AFP installation
if (fontInfo.fontLookup("sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
CharacterSet cs = new FopCharacterSet(DEFAULT_CODEPAGE, DEFAULT_ENCODING, "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(DEFAULT_CODEPAGE, DEFAULT_ENCODING, "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(DEFAULT_CODEPAGE, DEFAULT_ENCODING, "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;
}
}
|