001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.gvt.font;
020:
021: import java.awt.Font;
022: import java.awt.font.TextAttribute;
023: import java.text.AttributedCharacterIterator;
024: import java.util.HashMap;
025: import java.util.Map;
026: import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
027:
028: /**
029: * A font family class for AWT fonts.
030: *
031: * @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
032: * @version $Id: AWTFontFamily.java 475477 2006-11-15 22:44:28Z cam $
033: */
034: public class AWTFontFamily implements GVTFontFamily {
035:
036: public static final AttributedCharacterIterator.Attribute TEXT_COMPOUND_DELIMITER = GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER;
037:
038: protected GVTFontFace fontFace;
039: protected Font font;
040:
041: /**
042: * Constructs an AWTFontFamily with the specified familyName.
043: *
044: * @param fontFace The name of the font family.
045: */
046: public AWTFontFamily(GVTFontFace fontFace) {
047: this .fontFace = fontFace;
048: }
049:
050: /**
051: * Constructs an AWTFontFamily with the specified familyName.
052: *
053: * @param familyName The name of the font family.
054: */
055: public AWTFontFamily(String familyName) {
056: this (new GVTFontFace(familyName));
057: }
058:
059: /**
060: * Constructs an AWTFontFamily with the specified familyName.
061: *
062: * @param fontFace The name of the font family.
063: */
064: public AWTFontFamily(GVTFontFace fontFace, Font font) {
065: this .fontFace = fontFace;
066: this .font = font;
067: }
068:
069: /**
070: * Returns the font family name.
071: *
072: * @return The family name.
073: */
074: public String getFamilyName() {
075: return fontFace.getFamilyName();
076: }
077:
078: /**
079: * Returns the font-face information for this font family.
080: */
081: public GVTFontFace getFontFace() {
082: return fontFace;
083: }
084:
085: /**
086: * Derives a GVTFont object of the correct size.
087: *
088: * @param size The required size of the derived font.
089: * @param aci The character iterator that will be rendered using
090: * the derived font.
091: */
092: public GVTFont deriveFont(float size,
093: AttributedCharacterIterator aci) {
094: if (font != null)
095: return new AWTGVTFont(font, size);
096:
097: return deriveFont(size, aci.getAttributes());
098: }
099:
100: /**
101: * Derives a GVTFont object of the correct size from an attribute Map.
102: * @param size The required size of the derived font.
103: * @param attrs The Attribute Map to get Values from.
104: */
105: public GVTFont deriveFont(float size, Map attrs) {
106: if (font != null)
107: return new AWTGVTFont(font, size);
108:
109: Map fontAttributes = new HashMap(attrs);
110: fontAttributes.put(TextAttribute.SIZE, new Float(size));
111: fontAttributes.put(TextAttribute.FAMILY, fontFace
112: .getFamilyName());
113: fontAttributes.remove(TEXT_COMPOUND_DELIMITER);
114: return new AWTGVTFont(fontAttributes);
115: }
116:
117: }
|