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.util;
029:
030: import java.awt.font.TextAttribute;
031: import java.util.HashMap;
032: import java.util.Map;
033:
034: import net.sf.jasperreports.engine.JRFont;
035:
036: /**
037: * @author Teodor Danciu (teodord@users.sourceforge.net)
038: * @version $Id: JRFontUtil.java 1498 2006-11-16 12:52:01Z teodord $
039: */
040: public class JRFontUtil {
041:
042: /**
043: *
044: */
045: public static Map getNonPdfAttributes(JRFont font) {
046: Map nonPdfAttributes = new HashMap();
047:
048: setNonPdfAttributes(nonPdfAttributes, font);
049:
050: return nonPdfAttributes;
051: }
052:
053: /**
054: *
055: */
056: public static Map getAttributes(JRFont font) {
057: Map attributes = new HashMap();
058:
059: setAttributes(attributes, font);
060:
061: return attributes;
062: }
063:
064: /**
065: *
066: */
067: private static Map setNonPdfAttributes(Map attributes, JRFont font) {
068: attributes.put(TextAttribute.FAMILY, font.getFontName());
069: attributes.put(TextAttribute.SIZE,
070: new Float(font.getFontSize()));
071:
072: if (font.isBold()) {
073: attributes.put(TextAttribute.WEIGHT,
074: TextAttribute.WEIGHT_BOLD);
075: }
076: if (font.isItalic()) {
077: attributes.put(TextAttribute.POSTURE,
078: TextAttribute.POSTURE_OBLIQUE);
079: }
080: if (font.isUnderline()) {
081: attributes.put(TextAttribute.UNDERLINE,
082: TextAttribute.UNDERLINE_ON);
083: }
084: if (font.isStrikeThrough()) {
085: attributes.put(TextAttribute.STRIKETHROUGH,
086: TextAttribute.STRIKETHROUGH_ON);
087: }
088:
089: return attributes;
090: }
091:
092: /**
093: *
094: */
095: public static Map setAttributes(Map attributes, JRFont font) {
096: attributes = JRFontUtil.setNonPdfAttributes(attributes, font);
097:
098: attributes.put(JRTextAttribute.PDF_FONT_NAME, font
099: .getPdfFontName());
100: attributes.put(JRTextAttribute.PDF_ENCODING, font
101: .getPdfEncoding());
102:
103: if (font.isPdfEmbedded()) {
104: attributes.put(JRTextAttribute.IS_PDF_EMBEDDED,
105: Boolean.TRUE);
106: }
107:
108: return attributes;
109: }
110:
111: }
|