1
24 package net.sf.jasperreports.engine.fonts;
25
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.Locale;
29 import java.util.Map;
30 import java.util.Set;
31
32 import net.sf.jasperreports.engine.DefaultJasperReportsContext;
33 import net.sf.jasperreports.engine.JRCloneable;
34 import net.sf.jasperreports.engine.JRRuntimeException;
35 import net.sf.jasperreports.engine.JasperReportsContext;
36 import net.sf.jasperreports.engine.util.JRDataUtils;
37
38
39
42 public class SimpleFontFamily implements FontFamily, JRCloneable {
43
44
47 private JasperReportsContext jasperReportsContext;
48 private String name;
49 private SimpleFontFace normalFace;
50 private SimpleFontFace boldFace;
51 private SimpleFontFace italicFace;
52 private SimpleFontFace boldItalicFace;
53 private String pdfEncoding;
54 private Boolean isPdfEmbedded;
55 private String defaultExportFont;
56 private Map<String, String> exportFonts;
57 private Set<String> locales;
58 private boolean isVisible = true;
59
60
63 public SimpleFontFamily() {
64 this(DefaultJasperReportsContext.getInstance());
65 }
66
67
70 public SimpleFontFamily(JasperReportsContext jasperReportsContext) {
71 this.jasperReportsContext = jasperReportsContext;
72 }
73
74 @Override
75 public Object clone() {
76 try {
77 SimpleFontFamily clone = (SimpleFontFamily) super.clone();
78 if (normalFace != null)
79 clone.setNormalFace((SimpleFontFace) normalFace.clone());
80 if (boldFace != null)
81 clone.setBoldFace((SimpleFontFace) boldFace.clone());
82 if (italicFace != null)
83 clone.setItalicFace((SimpleFontFace) italicFace.clone());
84 if (boldItalicFace != null)
85 clone.setBoldItalicFace((SimpleFontFace) boldItalicFace.clone());
86 if (locales != null)
87 clone.setLocales(new HashSet<String>(locales));
88 if (exportFonts != null)
89 clone.setExportFonts(new HashMap<String, String>(exportFonts));
90 return clone;
91 } catch (CloneNotSupportedException e) {
92 throw new JRRuntimeException(e);
93 }
94 }
95
96 @Override
97 public String getName() {
98 return name;
99 }
100
101
104 public void setName(String name) {
105 this.name = name;
106 }
107
108
111 public void setNormal(String normal) {
112 if (normalFace == null) {
113 normalFace = new SimpleFontFace(jasperReportsContext);
114 }
115 normalFace.setTtf(normal);
116 }
117
118
121 public void setBold(String bold) {
122 if (boldFace == null) {
123 boldFace = new SimpleFontFace(jasperReportsContext);
124 }
125 boldFace.setTtf(bold);
126 }
127
128
131 public void setItalic(String italic) {
132 if (italicFace == null) {
133 italicFace = new SimpleFontFace(jasperReportsContext);
134 }
135 italicFace.setTtf(italic);
136 }
137
138
141 public void setBoldItalic(String boldItalic) {
142 if (boldItalicFace == null) {
143 boldItalicFace = new SimpleFontFace(jasperReportsContext);
144 }
145 boldItalicFace.setTtf(boldItalic);
146 }
147
148 @Override
149 public FontFace getNormalFace() {
150 return normalFace;
151 }
152
153
156 public void setNormalFace(SimpleFontFace normalFace) {
157 this.normalFace = normalFace;
158 }
159
160 @Override
161 public FontFace getBoldFace() {
162 return boldFace;
163 }
164
165
168 public void setBoldFace(SimpleFontFace boldFace) {
169 this.boldFace = boldFace;
170 }
171
172 @Override
173 public FontFace getItalicFace() {
174 return italicFace;
175 }
176
177
180 public void setItalicFace(SimpleFontFace italicFace) {
181 this.italicFace = italicFace;
182 }
183
184 @Override
185 public FontFace getBoldItalicFace() {
186 return boldItalicFace;
187 }
188
189
192 public void setBoldItalicFace(SimpleFontFace boldItalicFace) {
193 this.boldItalicFace = boldItalicFace;
194 }
195
196
199 @Override
200 public String getNormalPdfFont() {
201 return getNormalFace() == null ? null : getNormalFace().getPdf();
202 }
203
204
207 public void setNormalPdfFont(String normalPdfFont) {
208 if (normalFace == null) {
209 normalFace = new SimpleFontFace(jasperReportsContext);
210 }
211 normalFace.setPdf(normalPdfFont);
212 }
213
214
217 @Override
218 public String getBoldPdfFont() {
219 return getBoldFace() == null ? null : getBoldFace().getPdf();
220 }
221
222
225 public void setBoldPdfFont(String boldPdfFont) {
226 if (boldFace == null) {
227 boldFace = new SimpleFontFace(jasperReportsContext);
228 }
229 boldFace.setPdf(boldPdfFont);
230 }
231
232
235 @Override
236 public String getItalicPdfFont() {
237 return getItalicFace() == null ? null : getItalicFace().getPdf();
238 }
239
240
243 public void setItalicPdfFont(String italicPdfFont) {
244 if (italicFace == null) {
245 italicFace = new SimpleFontFace(jasperReportsContext);
246 }
247 italicFace.setPdf(italicPdfFont);
248 }
249
250
253 @Override
254 public String getBoldItalicPdfFont() {
255 return getBoldItalicFace() == null ? null : getBoldItalicFace().getPdf();
256 }
257
258
261 public void setBoldItalicPdfFont(String boldItalicPdfFont) {
262 if (boldItalicFace == null) {
263 boldItalicFace = new SimpleFontFace(jasperReportsContext);
264 }
265 boldItalicFace.setPdf(boldItalicPdfFont);
266 }
267
268 @Override
269 public String getPdfEncoding() {
270 return pdfEncoding;
271 }
272
273
276 public void setPdfEncoding(String pdfEncoding) {
277 this.pdfEncoding = pdfEncoding;
278 }
279
280 @Override
281 public Boolean isPdfEmbedded() {
282 return isPdfEmbedded;
283 }
284
285
288 public void setPdfEmbedded(Boolean isPdfEmbedded) {
289 this.isPdfEmbedded = isPdfEmbedded;
290 }
291
292
295 public String getDefaultExportFont() {
296 return defaultExportFont;
297 }
298
299
302 public void setDefaultExportFont(String defaultExportFont) {
303 this.defaultExportFont = defaultExportFont;
304 }
305
306
309 public Map<String, String> getExportFonts() {
310 return exportFonts;
311 }
312
313
316 public void setExportFonts(Map<String, String> exportFonts) {
317 this.exportFonts = exportFonts;
318 }
319
320 @Override
321 public String getExportFont(String key) {
322 String exportFont = exportFonts == null ? null : (String) exportFonts.get(key);
323 return exportFont == null ? defaultExportFont : exportFont;
324 }
325
326
329 public Set<String> getLocales() {
330 return locales;
331 }
332
333
336 public void setLocales(Set<String> locales) {
337 this.locales = locales;
338 }
339
340 @Override
341 public boolean supportsLocale(Locale locale) {
342 return locales == null || locales.isEmpty() || locales.contains(JRDataUtils.getLocaleCode(locale));
343 }
344
345 @Override
346 public boolean isVisible() {
347 return isVisible;
348 }
349
350
353 public void setVisible(boolean isVisible) {
354 this.isVisible = isVisible;
355 }
356
357 }
358