1 /*
2  * JasperReports - Free Java Reporting Library.
3  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4  * http://www.jaspersoft.com
5  *
6  * Unless you have purchased a commercial license agreement from Jaspersoft,
7  * the following license terms apply:
8  *
9  * This program is part of JasperReports.
10  *
11  * JasperReports is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * JasperReports is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23  */

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 /**
40  * @author Teodor Danciu (teodord@users.sourceforge.net)
41  */

42 public class SimpleFontFamily implements FontFamily, JRCloneable {
43
44     /**
45      * 
46      */

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     /**
61      * @see #SimpleFontFamily(JasperReportsContext)
62      */

63     public SimpleFontFamily() {
64         this(DefaultJasperReportsContext.getInstance());
65     }
66
67     /**
68      * 
69      */

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     /**
102      * 
103      */

104     public void setName(String name) {
105         this.name = name;
106     }
107
108     /**
109      * @deprecated Replaced by {@link #setNormalFace(SimpleFontFace)}.
110      */

111     public void setNormal(String normal) {
112         if (normalFace == null) {
113             normalFace = new SimpleFontFace(jasperReportsContext);
114         }
115         normalFace.setTtf(normal);
116     }
117
118     /**
119      * @deprecated Replaced by {@link #setBoldFace(SimpleFontFace)}.
120      */

121     public void setBold(String bold) {
122         if (boldFace == null) {
123             boldFace = new SimpleFontFace(jasperReportsContext);
124         }
125         boldFace.setTtf(bold);
126     }
127
128     /**
129      * @deprecated Replaced by {@link #setItalicFace(SimpleFontFace)}.
130      */

131     public void setItalic(String italic) {
132         if (italicFace == null) {
133             italicFace = new SimpleFontFace(jasperReportsContext);
134         }
135         italicFace.setTtf(italic);
136     }
137
138     /**
139      * @deprecated Replaced by {@link #setBoldItalicFace(SimpleFontFace)}.
140      */

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     /**
154      * 
155      */

156     public void setNormalFace(SimpleFontFace normalFace) {
157         this.normalFace = normalFace;
158     }
159
160     @Override
161     public FontFace getBoldFace() {
162         return boldFace;
163     }
164
165     /**
166      * 
167      */

168     public void setBoldFace(SimpleFontFace boldFace) {
169         this.boldFace = boldFace;
170     }
171
172     @Override
173     public FontFace getItalicFace() {
174         return italicFace;
175     }
176
177     /**
178      * 
179      */

180     public void setItalicFace(SimpleFontFace italicFace) {
181         this.italicFace = italicFace;
182     }
183
184     @Override
185     public FontFace getBoldItalicFace() {
186         return boldItalicFace;
187     }
188
189     /**
190      * 
191      */

192     public void setBoldItalicFace(SimpleFontFace boldItalicFace) {
193         this.boldItalicFace = boldItalicFace;
194     }
195
196     /**
197      * @deprecated Replaced by {@link FontFace#getPdf()}.
198      */

199     @Override
200     public String getNormalPdfFont() {
201         return getNormalFace() == null ? null : getNormalFace().getPdf();
202     }
203
204     /**
205      * @deprecated Replaced by {@link SimpleFontFace#setPdf(String)}.
206      */

207     public void setNormalPdfFont(String normalPdfFont) {
208         if (normalFace == null) {
209             normalFace = new SimpleFontFace(jasperReportsContext);
210         }
211         normalFace.setPdf(normalPdfFont);
212     }
213
214     /**
215      * @deprecated Replaced by {@link FontFace#getPdf()}.
216      */

217     @Override
218     public String getBoldPdfFont() {
219         return getBoldFace() == null ? null : getBoldFace().getPdf();
220     }
221
222     /**
223      * @deprecated Replaced by {@link SimpleFontFace#setPdf(String)}.
224      */

225     public void setBoldPdfFont(String boldPdfFont) {
226         if (boldFace == null) {
227             boldFace = new SimpleFontFace(jasperReportsContext);
228         }
229         boldFace.setPdf(boldPdfFont);
230     }
231
232     /**
233      * @deprecated Replaced by {@link FontFace#getPdf()}.
234      */

235     @Override
236     public String getItalicPdfFont() {
237         return getItalicFace() == null ? null : getItalicFace().getPdf();
238     }
239
240     /**
241      * @deprecated Replaced by {@link SimpleFontFace#setPdf(String)}.
242      */

243     public void setItalicPdfFont(String italicPdfFont) {
244         if (italicFace == null) {
245             italicFace = new SimpleFontFace(jasperReportsContext);
246         }
247         italicFace.setPdf(italicPdfFont);
248     }
249
250     /**
251      * @deprecated Replaced by {@link FontFace#getPdf()}.
252      */

253     @Override
254     public String getBoldItalicPdfFont() {
255         return getBoldItalicFace() == null ? null : getBoldItalicFace().getPdf();
256     }
257
258     /**
259      * @deprecated Replaced by {@link SimpleFontFace#setPdf(String)}.
260      */

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     /**
274      * 
275      */

276     public void setPdfEncoding(String pdfEncoding) {
277         this.pdfEncoding = pdfEncoding;
278     }
279
280     @Override
281     public Boolean isPdfEmbedded() {
282         return isPdfEmbedded;
283     }
284
285     /**
286      * 
287      */

288     public void setPdfEmbedded(Boolean isPdfEmbedded) {
289         this.isPdfEmbedded = isPdfEmbedded;
290     }
291
292     /**
293      * 
294      */

295     public String getDefaultExportFont() {
296         return defaultExportFont;
297     }
298
299     /**
300      * 
301      */

302     public void setDefaultExportFont(String defaultExportFont) {
303         this.defaultExportFont = defaultExportFont;
304     }
305
306     /**
307      * 
308      */

309     public Map<String, String> getExportFonts() {
310         return exportFonts;
311     }
312
313     /**
314      * 
315      */

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     /**
327      * 
328      */

329     public Set<String> getLocales() {
330         return locales;
331     }
332
333     /**
334      * 
335      */

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     /**
351      * 
352      */

353     public void setVisible(boolean isVisible) {
354         this.isVisible = isVisible;
355     }
356
357 }
358