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.xml;
029:
030: import java.util.Map;
031:
032: import net.sf.jasperreports.engine.JRFont;
033: import net.sf.jasperreports.engine.JRReportFont;
034: import net.sf.jasperreports.engine.design.JRDesignFont;
035: import net.sf.jasperreports.engine.design.JRValidationException;
036: import net.sf.jasperreports.engine.design.JasperDesign;
037:
038: import org.xml.sax.Attributes;
039:
040: /**
041: * @author Teodor Danciu (teodord@users.sourceforge.net)
042: * @version $Id: JRFontFactory.java 1625 2007-03-09 17:21:31Z lucianc $
043: */
044: public abstract class JRFontFactory extends JRBaseFactory {
045:
046: /**
047: *
048: */
049: public abstract JRFont getFont();
050:
051: /**
052: *
053: */
054: public Object createObject(Attributes atts) {
055: JRFont font = getFont();
056: JRXmlLoader xmlLoader = (JRXmlLoader) digester.peek(digester
057: .getCount() - 1);
058: JasperDesign jasperDesign = (JasperDesign) digester
059: .peek(digester.getCount() - 2);
060:
061: if (atts.getValue(JRXmlConstants.ATTRIBUTE_reportFont) != null) {
062: Map fontsMap = jasperDesign.getFontsMap();
063:
064: if (!fontsMap.containsKey(atts
065: .getValue(JRXmlConstants.ATTRIBUTE_reportFont))) {
066: xmlLoader
067: .addError(new JRValidationException(
068: "Unknown report font : "
069: + atts
070: .getValue(JRXmlConstants.ATTRIBUTE_reportFont),
071: font));
072: }
073:
074: font.setReportFont((JRReportFont) fontsMap.get(atts
075: .getValue(JRXmlConstants.ATTRIBUTE_reportFont)));
076: }
077:
078: if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontName) != null)
079: font.setFontName(atts
080: .getValue(JRXmlConstants.ATTRIBUTE_fontName));
081:
082: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isBold) != null)
083: font.setBold(Boolean.valueOf(atts
084: .getValue(JRXmlConstants.ATTRIBUTE_isBold)));
085:
086: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic) != null)
087: font.setItalic(Boolean.valueOf(atts
088: .getValue(JRXmlConstants.ATTRIBUTE_isItalic)));
089:
090: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline) != null)
091: font.setUnderline(Boolean.valueOf(atts
092: .getValue(JRXmlConstants.ATTRIBUTE_isUnderline)));
093:
094: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough) != null)
095: font
096: .setStrikeThrough(Boolean
097: .valueOf(atts
098: .getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough)));
099:
100: if (atts.getValue(JRXmlConstants.ATTRIBUTE_size) != null)
101: font.setFontSize(Integer.parseInt(atts
102: .getValue(JRXmlConstants.ATTRIBUTE_size)));
103:
104: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName) != null)
105: font.setPdfFontName(atts
106: .getValue(JRXmlConstants.ATTRIBUTE_pdfFontName));
107:
108: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding) != null)
109: font.setPdfEncoding(atts
110: .getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding));
111:
112: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded) != null)
113: font.setPdfEmbedded(Boolean.valueOf(atts
114: .getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded)));
115:
116: return font;
117: }
118:
119: /**
120: *
121: */
122: public static class TextElementFontFactory extends JRFontFactory {
123: public JRFont getFont() {
124: return (JRFont) digester.peek();
125: }
126: }
127:
128: /**
129: *
130: */
131: public static class ChartFontFactory extends JRFontFactory {
132: public JRFont getFont() {
133: return new JRDesignFont();
134: }
135: }
136:
137: }
|