001: /*
002: * $Id: HheaTable.java,v 1.3 2007/12/20 18:33:30 rbair Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020: */
021:
022: package com.sun.pdfview.font.ttf;
023:
024: import java.nio.ByteBuffer;
025:
026: /**
027: *
028: * @author jkaplan
029: */
030: public class HheaTable extends TrueTypeTable {
031:
032: /** Holds value of property version. */
033: private int version;
034:
035: /** Holds value of property ascent. */
036: private short ascent;
037:
038: /** Holds value of property descent. */
039: private short descent;
040:
041: /** Holds value of property lineGap. */
042: private short lineGap;
043:
044: /** Holds value of property advanceWidthMax. */
045: private short advanceWidthMax;
046:
047: /** Holds value of property minLeftSideBearing. */
048: private short minLeftSideBearing;
049:
050: /** Holds value of property minRightSideBearing. */
051: private short minRightSideBearing;
052:
053: /** Holds value of property xMaxExtent. */
054: private short xMaxExtent;
055:
056: /** Holds value of property caretSlopeRise. */
057: private short caretSlopeRise;
058:
059: /** Holds value of property caretSlopeRun. */
060: private short caretSlopeRun;
061:
062: /** Holds value of property caretOffset. */
063: private short caretOffset;
064:
065: /** Holds value of property metricDataFormat. */
066: private short metricDataFormat;
067:
068: /** Holds value of property numOfLongHorMetrics. */
069: private short numOfLongHorMetrics;
070:
071: /** Creates a new instance of HeadTable
072: * Makes up reasonable(?) defaults for all values
073: */
074: protected HheaTable() {
075: super (TrueTypeTable.HEAD_TABLE);
076:
077: setVersion(0x10000);
078: }
079:
080: /**
081: * Parse the data before it is set
082: */
083: public void setData(ByteBuffer data) {
084: if (data.remaining() != 36) {
085: throw new IllegalArgumentException("Bad Head table size");
086: }
087: setVersion(data.getInt());
088: setAscent(data.getShort());
089: setDescent(data.getShort());
090: setLineGap(data.getShort());
091: setAdvanceWidthMax(data.getShort());
092: setMinLeftSideBearing(data.getShort());
093: setMinRightSideBearing(data.getShort());
094: setXMaxExtent(data.getShort());
095: setCaretSlopeRise(data.getShort());
096: setCaretSlopeRun(data.getShort());
097: setCaretOffset(data.getShort());
098:
099: // padding
100: data.getShort();
101: data.getShort();
102: data.getShort();
103: data.getShort();
104:
105: setMetricDataFormat(data.getShort());
106: setNumOfLongHorMetrics(data.getShort());
107: }
108:
109: /**
110: * Get the data we have stored
111: */
112: public ByteBuffer getData() {
113: ByteBuffer buf = ByteBuffer.allocate(getLength());
114:
115: buf.putInt(getVersion());
116: buf.putShort(getAscent());
117: buf.putShort(getDescent());
118: buf.putShort(getLineGap());
119: buf.putShort(getAdvanceWidthMax());
120: buf.putShort(getMinLeftSideBearing());
121: buf.putShort(getMinRightSideBearing());
122: buf.putShort(getXMaxExtent());
123: buf.putShort(getCaretSlopeRise());
124: buf.putShort(getCaretSlopeRun());
125: buf.putShort(getCaretOffset());
126:
127: // padding
128: buf.putShort((short) 0);
129: buf.putShort((short) 0);
130: buf.putShort((short) 0);
131: buf.putShort((short) 0);
132:
133: buf.putShort(getMetricDataFormat());
134: buf.putShort(getNumOfLongHorMetrics());
135:
136: // reset the position to the start of the buffer
137: buf.flip();
138:
139: return buf;
140: }
141:
142: /**
143: * Get the length of this table
144: */
145: public int getLength() {
146: return 36;
147: }
148:
149: /** Getter for property version.
150: * @return Value of property version.
151: *
152: */
153: public int getVersion() {
154: return version;
155: }
156:
157: /** Setter for property version.
158: * @param version New value of property version.
159: *
160: */
161: public void setVersion(int version) {
162: this .version = version;
163: }
164:
165: /**
166: * Create a pretty string
167: */
168: public String toString() {
169: StringBuffer buf = new StringBuffer();
170: String indent = " ";
171:
172: buf.append(indent + "Version : "
173: + Integer.toHexString(getVersion()) + "\n");
174: buf.append(indent + "Ascent : " + getAscent()
175: + "\n");
176: buf.append(indent + "Descent : " + getDescent()
177: + "\n");
178: buf.append(indent + "LineGap : " + getLineGap()
179: + "\n");
180: buf.append(indent + "AdvanceWidthMax : "
181: + getAdvanceWidthMax() + "\n");
182: buf.append(indent + "MinLSB : "
183: + getMinLeftSideBearing() + "\n");
184: buf.append(indent + "MinRSB : "
185: + getMinRightSideBearing() + "\n");
186: buf.append(indent + "MaxExtent : " + getXMaxExtent()
187: + "\n");
188: buf.append(indent + "CaretSlopeRise : "
189: + getCaretSlopeRise() + "\n");
190: buf.append(indent + "CaretSlopeRun : "
191: + getCaretSlopeRun() + "\n");
192: buf.append(indent + "CaretOffset : " + getCaretOffset()
193: + "\n");
194: buf.append(indent + "MetricDataFormat : "
195: + getMetricDataFormat() + "\n");
196: buf.append(indent + "NumOfLongHorMetrics : "
197: + getNumOfLongHorMetrics() + "\n");
198: return buf.toString();
199: }
200:
201: /** Getter for property ascent.
202: * @return Value of property ascent.
203: *
204: */
205: public short getAscent() {
206: return this .ascent;
207: }
208:
209: /** Setter for property ascent.
210: * @param ascent New value of property ascent.
211: *
212: */
213: public void setAscent(short ascent) {
214: this .ascent = ascent;
215: }
216:
217: /** Getter for property descent.
218: * @return Value of property descent.
219: *
220: */
221: public short getDescent() {
222: return this .descent;
223: }
224:
225: /** Setter for property descent.
226: * @param descent New value of property descent.
227: *
228: */
229: public void setDescent(short descent) {
230: this .descent = descent;
231: }
232:
233: /** Getter for property lineGap.
234: * @return Value of property lineGap.
235: *
236: */
237: public short getLineGap() {
238: return this .lineGap;
239: }
240:
241: /** Setter for property lineGap.
242: * @param lineGap New value of property lineGap.
243: *
244: */
245: public void setLineGap(short lineGap) {
246: this .lineGap = lineGap;
247: }
248:
249: /** Getter for property advanceWidthMax.
250: * @return Value of property advanceWidthMax.
251: *
252: */
253: public short getAdvanceWidthMax() {
254: return this .advanceWidthMax;
255: }
256:
257: /** Setter for property advanceWidthMax.
258: * @param advanceWidthMax New value of property advanceWidthMax.
259: *
260: */
261: public void setAdvanceWidthMax(short advanceWidthMax) {
262: this .advanceWidthMax = advanceWidthMax;
263: }
264:
265: /** Getter for property minLeftSideBearing.
266: * @return Value of property minLeftSideBearing.
267: *
268: */
269: public short getMinLeftSideBearing() {
270: return this .minLeftSideBearing;
271: }
272:
273: /** Setter for property minLeftSideBearing.
274: * @param minLeftSideBearing New value of property minLeftSideBearing.
275: *
276: */
277: public void setMinLeftSideBearing(short minLeftSideBearing) {
278: this .minLeftSideBearing = minLeftSideBearing;
279: }
280:
281: /** Getter for property minRIghtSideBearing.
282: * @return Value of property minRIghtSideBearing.
283: *
284: */
285: public short getMinRightSideBearing() {
286: return this .minRightSideBearing;
287: }
288:
289: /** Setter for property minRIghtSideBearing.
290: * @param minRightSideBearing New value of property minRIghtSideBearing.
291: *
292: */
293: public void setMinRightSideBearing(short minRightSideBearing) {
294: this .minRightSideBearing = minRightSideBearing;
295: }
296:
297: /** Getter for property xMaxExtent.
298: * @return Value of property xMaxExtent.
299: *
300: */
301: public short getXMaxExtent() {
302: return this .xMaxExtent;
303: }
304:
305: /** Setter for property xMaxExtent.
306: * @param xMaxExtent New value of property xMaxExtent.
307: *
308: */
309: public void setXMaxExtent(short xMaxExtent) {
310: this .xMaxExtent = xMaxExtent;
311: }
312:
313: /** Getter for property caretSlopeRise.
314: * @return Value of property caretSlopeRise.
315: *
316: */
317: public short getCaretSlopeRise() {
318: return this .caretSlopeRise;
319: }
320:
321: /** Setter for property caretSlopeRise.
322: * @param caretSlopeRise New value of property caretSlopeRise.
323: *
324: */
325: public void setCaretSlopeRise(short caretSlopeRise) {
326: this .caretSlopeRise = caretSlopeRise;
327: }
328:
329: /** Getter for property caretSlopeRun.
330: * @return Value of property caretSlopeRun.
331: *
332: */
333: public short getCaretSlopeRun() {
334: return this .caretSlopeRun;
335: }
336:
337: /** Setter for property caretSlopeRun.
338: * @param caretSlopeRun New value of property caretSlopeRun.
339: *
340: */
341: public void setCaretSlopeRun(short caretSlopeRun) {
342: this .caretSlopeRun = caretSlopeRun;
343: }
344:
345: /** Getter for property caretOffset.
346: * @return Value of property caretOffset.
347: *
348: */
349: public short getCaretOffset() {
350: return this .caretOffset;
351: }
352:
353: /** Setter for property caretOffset.
354: * @param caretOffset New value of property caretOffset.
355: *
356: */
357: public void setCaretOffset(short caretOffset) {
358: this .caretOffset = caretOffset;
359: }
360:
361: /** Getter for property metricDataFormat.
362: * @return Value of property metricDataFormat.
363: *
364: */
365: public short getMetricDataFormat() {
366: return this .metricDataFormat;
367: }
368:
369: /** Setter for property metricDataFormat.
370: * @param metricDataFormat New value of property metricDataFormat.
371: *
372: */
373: public void setMetricDataFormat(short metricDataFormat) {
374: this .metricDataFormat = metricDataFormat;
375: }
376:
377: /** Getter for property numOfLongHorMetrics.
378: * @return Value of property numOfLongHorMetrics.
379: *
380: */
381: public short getNumOfLongHorMetrics() {
382: return this .numOfLongHorMetrics;
383: }
384:
385: /** Setter for property numOfLongHorMetrics.
386: * @param numOfLongHorMetrics New value of property numOfLongHorMetrics.
387: *
388: */
389: public void setNumOfLongHorMetrics(short numOfLongHorMetrics) {
390: this.numOfLongHorMetrics = numOfLongHorMetrics;
391: }
392:
393: }
|