001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.base;
029:
030: import java.awt.font.TextAttribute;
031: import java.io.Serializable;
032: import java.util.Map;
033:
034: import net.sf.jasperreports.engine.JRConstants;
035: import net.sf.jasperreports.engine.JRDefaultFontProvider;
036: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
037: import net.sf.jasperreports.engine.JRFont;
038: import net.sf.jasperreports.engine.JRReportFont;
039: import net.sf.jasperreports.engine.JRStyle;
040: import net.sf.jasperreports.engine.JRStyleContainer;
041: import net.sf.jasperreports.engine.util.JRStyleResolver;
042: import net.sf.jasperreports.engine.util.JRTextAttribute;
043:
044: /**
045: * @author Teodor Danciu (teodord@users.sourceforge.net)
046: * @version $Id: JRBaseFont.java 1759 2007-06-20 16:47:34Z lucianc $
047: */
048: public class JRBaseFont implements JRFont, Serializable {
049:
050: /**
051: *
052: */
053: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
054:
055: /**
056: *
057: */
058: protected JRDefaultFontProvider defaultFontProvider = null;
059:
060: /**
061: *
062: */
063: protected JRReportFont reportFont = null;
064:
065: /**
066: *
067: */
068: protected JRStyleContainer styleContainer = null;
069:
070: protected String fontName = null;
071: protected Boolean isBold = null;
072: protected Boolean isItalic = null;
073: protected Boolean isUnderline = null;
074: protected Boolean isStrikeThrough = null;
075: protected Integer fontSize = null;
076: protected String pdfFontName = null;
077: protected String pdfEncoding = null;
078: protected Boolean isPdfEmbedded = null;
079:
080: /**
081: *
082: */
083: public JRBaseFont() {
084: }
085:
086: /**
087: *
088: */
089: public JRBaseFont(Map attributes) {
090: String fontNameAttr = (String) attributes
091: .get(TextAttribute.FAMILY);
092: if (fontNameAttr != null) {
093: setFontName(fontNameAttr);
094: }
095:
096: Object bold = attributes.get(TextAttribute.WEIGHT);
097: if (bold != null) {
098: setBold(TextAttribute.WEIGHT_BOLD.equals(bold));
099: }
100:
101: Object italic = attributes.get(TextAttribute.POSTURE);
102: if (italic != null) {
103: setItalic(TextAttribute.POSTURE_OBLIQUE.equals(italic));
104: }
105:
106: Float sizeAttr = (Float) attributes.get(TextAttribute.SIZE);
107: if (sizeAttr != null) {
108: setFontSize(sizeAttr.intValue());
109: }
110:
111: Object underline = attributes.get(TextAttribute.UNDERLINE);
112: if (underline != null) {
113: setUnderline(TextAttribute.UNDERLINE_ON.equals(underline));
114: }
115:
116: Object strikeThrough = attributes
117: .get(TextAttribute.STRIKETHROUGH);
118: if (strikeThrough != null) {
119: setStrikeThrough(TextAttribute.STRIKETHROUGH_ON
120: .equals(strikeThrough));
121: }
122:
123: String pdfFontNameAttr = (String) attributes
124: .get(JRTextAttribute.PDF_FONT_NAME);
125: if (pdfFontNameAttr != null) {
126: setPdfFontName(pdfFontNameAttr);
127: }
128:
129: String pdfEncodingAttr = (String) attributes
130: .get(JRTextAttribute.PDF_ENCODING);
131: if (pdfEncodingAttr != null) {
132: setPdfEncoding(pdfEncodingAttr);
133: }
134:
135: Boolean isPdfEmbeddedAttr = (Boolean) attributes
136: .get(JRTextAttribute.IS_PDF_EMBEDDED);
137: if (isPdfEmbeddedAttr != null) {
138: setPdfEmbedded(isPdfEmbeddedAttr);
139: }
140: }
141:
142: /**
143: *
144: */
145: protected JRBaseFont(JRDefaultFontProvider defaultFontProvider) {
146: this .defaultFontProvider = defaultFontProvider;
147: }
148:
149: /**
150: *
151: */
152: public JRBaseFont(JRDefaultFontProvider defaultFontProvider,
153: JRReportFont reportFont, JRFont font) {
154: this (defaultFontProvider, reportFont, null, font);
155: }
156:
157: /**
158: *
159: */
160: public JRBaseFont(JRDefaultFontProvider defaultFontProvider,
161: JRReportFont reportFont, JRStyleContainer styleContainer,
162: JRFont font) {
163: this .defaultFontProvider = defaultFontProvider;
164:
165: this .reportFont = reportFont;
166:
167: this .styleContainer = styleContainer;
168:
169: if (font != null) {
170: fontName = font.getOwnFontName();
171: isBold = font.isOwnBold();
172: isItalic = font.isOwnItalic();
173: isUnderline = font.isOwnUnderline();
174: isStrikeThrough = font.isOwnStrikeThrough();
175: fontSize = font.getOwnFontSize();
176: pdfFontName = font.getOwnPdfFontName();
177: pdfEncoding = font.getOwnPdfEncoding();
178: isPdfEmbedded = font.isOwnPdfEmbedded();
179: }
180: }
181:
182: /**
183: *
184: */
185: public JRDefaultFontProvider getDefaultFontProvider() {
186: return defaultFontProvider;
187: }
188:
189: /**
190: *
191: */
192: public JRDefaultStyleProvider getDefaultStyleProvider() {
193: return styleContainer == null ? null : styleContainer
194: .getDefaultStyleProvider();
195: }
196:
197: /**
198: *
199: */
200: public JRStyle getStyle() {
201: return styleContainer == null ? null : styleContainer
202: .getStyle();
203: }
204:
205: /**
206: *
207: */
208: public JRReportFont getReportFont() {
209: return reportFont;
210: }
211:
212: /**
213: *
214: */
215: public void setReportFont(JRReportFont reportFont) {
216: this .reportFont = reportFont;
217: }
218:
219: /**
220: *
221: */
222: public String getFontName() {
223: return JRStyleResolver.getFontName(this );
224: }
225:
226: /**
227: *
228: */
229: public String getOwnFontName() {
230: return fontName;
231: }
232:
233: /**
234: *
235: */
236: public void setFontName(String fontName) {
237: this .fontName = fontName;
238: }
239:
240: /**
241: *
242: */
243: public boolean isBold() {
244: return JRStyleResolver.isBold(this );
245: }
246:
247: /**
248: *
249: */
250: public Boolean isOwnBold() {
251: return isBold;
252: }
253:
254: /**
255: *
256: */
257: public void setBold(boolean isBold) {
258: setBold(isBold ? Boolean.TRUE : Boolean.FALSE);
259: }
260:
261: /**
262: * Alternative setBold method which allows also to reset
263: * the "own" isBold property.
264: */
265: public void setBold(Boolean isBold) {
266: this .isBold = isBold;
267: }
268:
269: /**
270: *
271: */
272: public boolean isItalic() {
273: return JRStyleResolver.isItalic(this );
274: }
275:
276: /**
277: *
278: */
279: public Boolean isOwnItalic() {
280: return isItalic;
281: }
282:
283: /**
284: *
285: */
286: public void setItalic(boolean isItalic) {
287: setItalic(isItalic ? Boolean.TRUE : Boolean.FALSE);
288: }
289:
290: /**
291: * Alternative setItalic method which allows also to reset
292: * the "own" isItalic property.
293: */
294: public void setItalic(Boolean isItalic) {
295: this .isItalic = isItalic;
296: }
297:
298: /**
299: *
300: */
301: public boolean isUnderline() {
302: return JRStyleResolver.isUnderline(this );
303: }
304:
305: /**
306: *
307: */
308: public Boolean isOwnUnderline() {
309: return isUnderline;
310: }
311:
312: /**
313: *
314: */
315: public void setUnderline(boolean isUnderline) {
316: setUnderline(isUnderline ? Boolean.TRUE : Boolean.FALSE);
317: }
318:
319: /**
320: * Alternative setUnderline method which allows also to reset
321: * the "own" isUnderline property.
322: */
323: public void setUnderline(Boolean isUnderline) {
324: this .isUnderline = isUnderline;
325: }
326:
327: /**
328: *
329: */
330: public boolean isStrikeThrough() {
331: return JRStyleResolver.isStrikeThrough(this );
332: }
333:
334: /**
335: *
336: */
337: public Boolean isOwnStrikeThrough() {
338: return isStrikeThrough;
339: }
340:
341: /**
342: *
343: */
344: public void setStrikeThrough(boolean isStrikeThrough) {
345: setStrikeThrough(isStrikeThrough ? Boolean.TRUE : Boolean.FALSE);
346: }
347:
348: /**
349: * Alternative setStrikeThrough method which allows also to reset
350: * the "own" isStrikeThrough property.
351: */
352: public void setStrikeThrough(Boolean isStrikeThrough) {
353: this .isStrikeThrough = isStrikeThrough;
354: }
355:
356: /**
357: *
358: */
359: public int getFontSize() {
360: return JRStyleResolver.getFontSize(this );
361: }
362:
363: /**
364: *
365: */
366: public Integer getOwnFontSize() {
367: return fontSize;
368: }
369:
370: /**
371: *
372: */
373: public void setFontSize(int fontSize) {
374: setFontSize(new Integer(fontSize));
375: }
376:
377: /**
378: * Alternative setSize method which allows also to reset
379: * the "own" size property.
380: */
381: public void setFontSize(Integer fontSize) {
382: this .fontSize = fontSize;
383: }
384:
385: /**
386: * @deprecated Replaced by {@link #getFontSize()}.
387: */
388: public int getSize() {
389: return getFontSize();
390: }
391:
392: /**
393: * @deprecated Replaced by {@link #getOwnFontSize()}.
394: */
395: public Integer getOwnSize() {
396: return getOwnFontSize();
397: }
398:
399: /**
400: * @deprecated Replaced by {@link #setFontSize(int)}.
401: */
402: public void setSize(int size) {
403: setFontSize(size);
404: }
405:
406: /**
407: * @deprecated Replaced by {@link #setFontSize(Integer)}.
408: */
409: public void setSize(Integer size) {
410: setFontSize(size);
411: }
412:
413: /**
414: *
415: */
416: public String getPdfFontName() {
417: return JRStyleResolver.getPdfFontName(this );
418: }
419:
420: /**
421: *
422: */
423: public String getOwnPdfFontName() {
424: return pdfFontName;
425: }
426:
427: /**
428: *
429: */
430: public void setPdfFontName(String pdfFontName) {
431: this .pdfFontName = pdfFontName;
432: }
433:
434: /**
435: *
436: */
437: public String getPdfEncoding() {
438: return JRStyleResolver.getPdfEncoding(this );
439: }
440:
441: /**
442: *
443: */
444: public String getOwnPdfEncoding() {
445: return pdfEncoding;
446: }
447:
448: /**
449: *
450: */
451: public void setPdfEncoding(String pdfEncoding) {
452: this .pdfEncoding = pdfEncoding;
453: }
454:
455: /**
456: *
457: */
458: public boolean isPdfEmbedded() {
459: return JRStyleResolver.isPdfEmbedded(this );
460: }
461:
462: /**
463: *
464: */
465: public Boolean isOwnPdfEmbedded() {
466: return isPdfEmbedded;
467: }
468:
469: /**
470: *
471: */
472: public void setPdfEmbedded(boolean isPdfEmbedded) {
473: setPdfEmbedded(isPdfEmbedded ? Boolean.TRUE : Boolean.FALSE);
474: }
475:
476: /**
477: * Alternative setPdfEmbedded method which allows also to reset
478: * the "own" isPdfEmbedded property.
479: */
480: public void setPdfEmbedded(Boolean isPdfEmbedded) {
481: this .isPdfEmbedded = isPdfEmbedded;
482: }
483:
484: public String getStyleNameReference() {
485: return styleContainer == null ? null : styleContainer
486: .getStyleNameReference();
487: }
488:
489: }
|