001 /**
002 * ===========================================
003 * LibFonts : a free Java font reading library
004 * ===========================================
005 *
006 * Project Info: http://reporting.pentaho.org/libfonts/
007 *
008 * (C) Copyright 2006-2007, by 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 * $Id: LEByteAccessUtilities.java 3523 2007-10-16 11:03:09Z tmorgner $
027 * ------------
028 * (C) Copyright 2006-2007, by Pentaho Corporation.
029 */
030
031 package org.jfree.fonts;
032
033 /**
034 * Reads byte-data using a Little-Endian access schema. Little-Endian is used for Type1 fonts.
035 *
036 * @author Thomas Morgner
037 */
038 public class LEByteAccessUtilities
039 {
040 private LEByteAccessUtilities()
041 {
042 }
043
044 public static int readUShort (final byte[] data, final int pos)
045 {
046 return ((data[pos + 1] & 0xff) << 8) | (data[pos] & 0xff);
047 }
048
049 public static long readULong (final byte[] data, final int pos)
050 {
051 final int c1 = (data[pos] & 0xff);
052 final int c2 = (data[pos + 1] & 0xff);
053 final int c3 = (data[pos + 2] & 0xff);
054 final int c4 = (data[pos + 3] & 0xff);
055
056 long retval = ((long) c4 << 24);
057 retval |= (long)c3 << 16;
058 retval |= (long)c2 << 8;
059 retval |= (long)c1;
060 return retval;
061 }
062
063 public static long readLongDateTime (final byte[] data, final int pos)
064 {
065 final int c1 = (data[pos] & 0xff);
066 final int c2 = (data[pos + 1] & 0xff);
067 final int c3 = (data[pos + 2] & 0xff);
068 final int c4 = (data[pos + 3] & 0xff);
069 final int c5 = (data[pos + 4] & 0xff);
070 final int c6 = (data[pos + 5] & 0xff);
071 final int c7 = (data[pos + 6] & 0xff);
072 final int c8 = (data[pos + 7] & 0xff);
073
074 long retval = ((long) c8 << 56);
075 retval |= (long)c7 << 48;
076 retval |= (long)c6 << 40;
077 retval |= (long)c5 << 32;
078 retval |= (long)c4 << 24;
079 retval |= (long)c3 << 16;
080 retval |= (long)c2 << 8;
081 retval |= (long)c1;
082 return retval;
083 }
084
085 public static short readShort (final byte[] data, final int pos)
086 {
087 return (short) ((data[pos + 1] & 0xff) << 8 | (data[pos] & 0xff));
088 }
089
090 public static int readLong (final byte[] data, final int pos)
091 {
092 int retval = 0;
093 retval |= (long)(data[pos + 3] & 0xff) << 24;
094 retval |= (long)(data[pos + 2] & 0xff) << 16;
095 retval |= (long)(data[pos + 1] & 0xff) << 8;
096 retval |= (long)(data[pos ] & 0xff);
097 return retval;
098 }
099
100 }