001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either 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, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * TextUtility.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout.text;
030:
031: import org.jfree.fonts.registry.BaselineInfo;
032: import org.jfree.fonts.registry.FontMetrics;
033:
034: /**
035: * Creation-Date: 04.04.2007, 14:46:14
036: *
037: * @author Thomas Morgner
038: */
039: public class TextUtility {
040: private TextUtility() {
041: }
042:
043: private static int translateBaselines(final int baseline) {
044: switch (baseline) {
045: case BaselineInfo.HANGING:
046: return ExtendedBaselineInfo.HANGING;
047: case BaselineInfo.ALPHABETIC:
048: return ExtendedBaselineInfo.ALPHABETHIC;
049: case BaselineInfo.CENTRAL:
050: return ExtendedBaselineInfo.CENTRAL;
051: case BaselineInfo.IDEOGRAPHIC:
052: return ExtendedBaselineInfo.IDEOGRAPHIC;
053: case BaselineInfo.MATHEMATICAL:
054: return ExtendedBaselineInfo.MATHEMATICAL;
055: case BaselineInfo.MIDDLE:
056: return ExtendedBaselineInfo.MIDDLE;
057: default:
058: throw new IllegalArgumentException("Invalid baseline");
059: }
060: }
061:
062: public static ExtendedBaselineInfo createBaselineInfo(
063: final int codepoint, final FontMetrics fontMetrics,
064: final BaselineInfo reusableBaselineInfo) {
065: if (fontMetrics == null) {
066: throw new NullPointerException("FontMetrics cannot be null");
067: }
068:
069: final BaselineInfo baselineInfo = fontMetrics.getBaselines(
070: codepoint, reusableBaselineInfo);
071: final int dominantBaseline = TextUtility
072: .translateBaselines(baselineInfo.getDominantBaseline());
073:
074: final long[] baselines = new long[ExtendedBaselineInfo.BASELINE_COUNT];
075: baselines[ExtendedBaselineInfo.ALPHABETHIC] = baselineInfo
076: .getBaseline(BaselineInfo.ALPHABETIC);
077: baselines[ExtendedBaselineInfo.CENTRAL] = baselineInfo
078: .getBaseline(BaselineInfo.CENTRAL);
079: baselines[ExtendedBaselineInfo.HANGING] = baselineInfo
080: .getBaseline(BaselineInfo.HANGING);
081: baselines[ExtendedBaselineInfo.IDEOGRAPHIC] = baselineInfo
082: .getBaseline(BaselineInfo.IDEOGRAPHIC);
083: baselines[ExtendedBaselineInfo.MATHEMATICAL] = baselineInfo
084: .getBaseline(BaselineInfo.MATHEMATICAL);
085: baselines[ExtendedBaselineInfo.MIDDLE] = baselineInfo
086: .getBaseline(BaselineInfo.MIDDLE);
087: baselines[ExtendedBaselineInfo.BEFORE_EDGE] = 0;
088: baselines[ExtendedBaselineInfo.TEXT_BEFORE_EDGE] = 0;
089: baselines[ExtendedBaselineInfo.TEXT_AFTER_EDGE] = fontMetrics
090: .getMaxHeight();
091: baselines[ExtendedBaselineInfo.AFTER_EDGE] = baselines[ExtendedBaselineInfo.TEXT_AFTER_EDGE];
092:
093: final long underlinePosition = fontMetrics
094: .getUnderlinePosition();
095: final long strikeThroughPosition = fontMetrics
096: .getStrikeThroughPosition();
097: return new DefaultExtendedBaselineInfo(dominantBaseline,
098: baselines, underlinePosition, strikeThroughPosition);
099: }
100:
101: }
|