001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source 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, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.quercus.lib.pdf;
031:
032: /**
033: * font
034: */
035: public class Font {
036: private String _fontName;
037: private String _weight;
038:
039: private double _llxBBox;
040: private double _llyBBox;
041: private double _urxBBox;
042: private double _uryBBox;
043:
044: private double _capHeight;
045: private double _xHeight;
046: private double _ascender;
047: private double _descender;
048:
049: private double _underlinePosition;
050: private double _underlineThickness;
051: private double _italicAngle;
052:
053: private FontChar[] _chars = new FontChar[256];
054:
055: public String getFontName() {
056: return _fontName;
057: }
058:
059: void setFontName(String name) {
060: _fontName = name;
061: }
062:
063: public String getWeight() {
064: return _weight;
065: }
066:
067: void setWeight(String weight) {
068: _weight = weight;
069: }
070:
071: void setBBox(double llx, double lly, double urx, double ury) {
072: _llxBBox = llx;
073: _llyBBox = lly;
074: _urxBBox = urx;
075: _uryBBox = ury;
076: }
077:
078: public double getCapHeight() {
079: return _capHeight;
080: }
081:
082: void setCapHeight(double height) {
083: _capHeight = height;
084: }
085:
086: public double getXHeight() {
087: return _xHeight;
088: }
089:
090: void setXHeight(double height) {
091: _xHeight = height;
092: }
093:
094: public double getAscender() {
095: return _ascender;
096: }
097:
098: void setAscender(double ascender) {
099: _ascender = ascender;
100: }
101:
102: public double getDescender() {
103: return _descender;
104: }
105:
106: void setDescender(double descender) {
107: _descender = descender;
108: }
109:
110: public double getUnderlinePosition() {
111: return _underlinePosition;
112: }
113:
114: void setUnderlinePosition(double underlinePosition) {
115: _underlinePosition = underlinePosition;
116: }
117:
118: public double getUnderlineThickness() {
119: return _underlineThickness;
120: }
121:
122: void setUnderlineThickness(double underlineThickness) {
123: _underlineThickness = underlineThickness;
124: }
125:
126: public double getItalicAngle() {
127: return _italicAngle;
128: }
129:
130: void setItalicAngle(double italicAngle) {
131: _italicAngle = italicAngle;
132: }
133:
134: void addChar(FontChar fontChar) {
135: int code = fontChar.getCode();
136:
137: if (code >= 0 && code < _chars.length)
138: _chars[code] = fontChar;
139: }
140:
141: public double stringWidth(String text) {
142: double width = 0;
143:
144: int len = text.length();
145: char prevChar = 0;
146:
147: for (int i = 0; i < len; i++) {
148: char ch = text.charAt(i);
149:
150: if (ch >= 256)
151: continue;
152:
153: FontChar fontChar = _chars[ch];
154:
155: if (fontChar == null)
156: continue;
157:
158: width += fontChar.getWidth();
159:
160: // XXX: kerning
161:
162: prevChar = ch;
163: }
164:
165: return width;
166: }
167: }
|