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 org.apache.batik.util.SVGConstants;
022:
023: /**
024: * One line Class Desc
025: *
026: * Complete Class Desc
027: *
028: * @author <a href="mailto:deweese@apache.org">l449433</a>
029: * @version $Id: GVTFontFace.java 475477 2006-11-15 22:44:28Z cam $
030: */
031: public class GVTFontFace implements SVGConstants {
032: protected String familyName;
033: protected float unitsPerEm;
034: protected String fontWeight;
035: protected String fontStyle;
036: protected String fontVariant;
037: protected String fontStretch;
038: protected float slope;
039: protected String panose1;
040: protected float ascent;
041: protected float descent;
042: protected float strikethroughPosition;
043: protected float strikethroughThickness;
044: protected float underlinePosition;
045: protected float underlineThickness;
046: protected float overlinePosition;
047: protected float overlineThickness;
048:
049: /**
050: * Constructes an GVTFontFace with the specfied font-face attributes.
051: */
052: public GVTFontFace(String familyName, float unitsPerEm,
053: String fontWeight, String fontStyle, String fontVariant,
054: String fontStretch, float slope, String panose1,
055: float ascent, float descent, float strikethroughPosition,
056: float strikethroughThickness, float underlinePosition,
057: float underlineThickness, float overlinePosition,
058: float overlineThickness) {
059: this .familyName = familyName;
060: this .unitsPerEm = unitsPerEm;
061: this .fontWeight = fontWeight;
062: this .fontStyle = fontStyle;
063: this .fontVariant = fontVariant;
064: this .fontStretch = fontStretch;
065: this .slope = slope;
066: this .panose1 = panose1;
067: this .ascent = ascent;
068: this .descent = descent;
069: this .strikethroughPosition = strikethroughPosition;
070: this .strikethroughThickness = strikethroughThickness;
071: this .underlinePosition = underlinePosition;
072: this .underlineThickness = underlineThickness;
073: this .overlinePosition = overlinePosition;
074: this .overlineThickness = overlineThickness;
075: }
076:
077: /**
078: * Constructs an SVGFontFace with default values for all the
079: * font-face attributes other than familyName
080: */
081: public GVTFontFace(String familyName) {
082: this (familyName, 1000, SVG_FONT_FACE_FONT_WEIGHT_DEFAULT_VALUE,
083: SVG_FONT_FACE_FONT_STYLE_DEFAULT_VALUE,
084: SVG_FONT_FACE_FONT_VARIANT_DEFAULT_VALUE,
085: SVG_FONT_FACE_FONT_STRETCH_DEFAULT_VALUE, 0,
086: SVG_FONT_FACE_PANOSE_1_DEFAULT_VALUE, 800, 200, 300,
087: 50, -75, 50, 800, 50);
088: }
089:
090: /**
091: * Returns the family name of this font, it may contain more than one.
092: */
093: public String getFamilyName() {
094: return familyName;
095: }
096:
097: public boolean hasFamilyName(String family) {
098: String ffname = familyName;
099: if (ffname.length() < family.length()) {
100: return false;
101: }
102:
103: ffname = ffname.toLowerCase();
104:
105: int idx = ffname.indexOf(family.toLowerCase());
106:
107: if (idx == -1) {
108: return false;
109: }
110:
111: // see if the family name is not the part of a bigger family name.
112: if (ffname.length() > family.length()) {
113: boolean quote = false;
114: if (idx > 0) {
115: char c = ffname.charAt(idx - 1);
116: switch (c) {
117: default:
118: return false;
119: case ' ':
120: loop: for (int i = idx - 2; i >= 0; --i) {
121: switch (ffname.charAt(i)) {
122: default:
123: return false;
124: case ' ':
125: continue;
126: case '"':
127: case '\'':
128: quote = true;
129: break loop;
130: }
131: }
132: break;
133: case '"':
134: case '\'':
135: quote = true;
136: case ',':
137: }
138: }
139: if (idx + family.length() < ffname.length()) {
140: char c = ffname.charAt(idx + family.length());
141: switch (c) {
142: default:
143: return false;
144: case ' ':
145: loop: for (int i = idx + family.length() + 1; i < ffname
146: .length(); i++) {
147: switch (ffname.charAt(i)) {
148: default:
149: return false;
150: case ' ':
151: continue;
152: case '"':
153: case '\'':
154: if (!quote) {
155: return false;
156: }
157: break loop;
158: }
159: }
160: break;
161: case '"':
162: case '\'':
163: if (!quote) {
164: return false;
165: }
166: case ',':
167: }
168: }
169: }
170: return true;
171: }
172:
173: /**
174: * Returns the font-weight.
175: */
176: public String getFontWeight() {
177: return fontWeight;
178: }
179:
180: /**
181: * Returns the font-style.
182: */
183: public String getFontStyle() {
184: return fontStyle;
185: }
186:
187: /**
188: * The number of coordinate units on the em square for this font.
189: */
190: public float getUnitsPerEm() {
191: return unitsPerEm;
192: }
193:
194: /**
195: * Returns the maximum unaccented height of the font within the font
196: * coordinate system.
197: */
198: public float getAscent() {
199: return ascent;
200: }
201:
202: /**
203: * Returns the maximum unaccented depth of the font within the font
204: * coordinate system.
205: */
206: public float getDescent() {
207: return descent;
208: }
209:
210: /**
211: * Returns the position of the strikethrough decoration.
212: */
213: public float getStrikethroughPosition() {
214: return strikethroughPosition;
215: }
216:
217: /**
218: * Returns the stroke thickness to use when drawing a strikethrough.
219: */
220: public float getStrikethroughThickness() {
221: return strikethroughThickness;
222: }
223:
224: /**
225: * Returns the position of the underline decoration.
226: */
227: public float getUnderlinePosition() {
228: return underlinePosition;
229: }
230:
231: /**
232: * Returns the stroke thickness to use when drawing a underline.
233: */
234: public float getUnderlineThickness() {
235: return underlineThickness;
236: }
237:
238: /**
239: * Returns the position of the overline decoration.
240: */
241: public float getOverlinePosition() {
242: return overlinePosition;
243: }
244:
245: /**
246: * Returns the stroke thickness to use when drawing a overline.
247: */
248: public float getOverlineThickness() {
249: return overlineThickness;
250: }
251: }
|