Source for org.jfree.fonts.LEByteAccessUtilities

   1: /**
   2:  * ===========================================
   3:  * LibFonts : a free Java font reading library
   4:  * ===========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/libfonts/
   7:  *
   8:  * (C) Copyright 2006-2007, by Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  * ------------
  26:  * $Id: LEByteAccessUtilities.java 3523 2007-10-16 11:03:09Z tmorgner $
  27:  * ------------
  28:  * (C) Copyright 2006-2007, by Pentaho Corporation.
  29:  */
  30: 
  31: package org.jfree.fonts;
  32: 
  33: /**
  34:  * Reads byte-data using a Little-Endian access schema. Little-Endian is used for Type1 fonts.
  35:  *
  36:  * @author Thomas Morgner
  37:  */
  38: public class LEByteAccessUtilities
  39: {
  40:   private LEByteAccessUtilities()
  41:   {
  42:   }
  43: 
  44:   public static int readUShort (final byte[] data, final int pos)
  45:   {
  46:     return ((data[pos + 1] & 0xff) << 8) | (data[pos] & 0xff);
  47:   }
  48: 
  49:   public static long readULong (final byte[] data, final int pos)
  50:   {
  51:     final int c1 = (data[pos] & 0xff);
  52:     final int c2 = (data[pos + 1] & 0xff);
  53:     final int c3 = (data[pos + 2] & 0xff);
  54:     final int c4 = (data[pos + 3] & 0xff);
  55: 
  56:     long retval = ((long) c4 << 24);
  57:     retval |= (long)c3 << 16;
  58:     retval |= (long)c2 << 8;
  59:     retval |= (long)c1;
  60:     return retval;
  61:   }
  62: 
  63:   public static long readLongDateTime (final byte[] data, final int pos)
  64:   {
  65:     final int c1 = (data[pos] & 0xff);
  66:     final int c2 = (data[pos + 1] & 0xff);
  67:     final int c3 = (data[pos + 2] & 0xff);
  68:     final int c4 = (data[pos + 3] & 0xff);
  69:     final int c5 = (data[pos + 4] & 0xff);
  70:     final int c6 = (data[pos + 5] & 0xff);
  71:     final int c7 = (data[pos + 6] & 0xff);
  72:     final int c8 = (data[pos + 7] & 0xff);
  73: 
  74:     long retval = ((long) c8 << 56);
  75:     retval |= (long)c7 << 48;
  76:     retval |= (long)c6 << 40;
  77:     retval |= (long)c5 << 32;
  78:     retval |= (long)c4 << 24;
  79:     retval |= (long)c3 << 16;
  80:     retval |= (long)c2 << 8;
  81:     retval |= (long)c1;
  82:     return retval;
  83:   }
  84: 
  85:   public static short readShort (final byte[] data, final int pos)
  86:   {
  87:     return (short) ((data[pos + 1] & 0xff) << 8 | (data[pos] & 0xff));
  88:   }
  89: 
  90:   public static int readLong (final byte[] data, final int pos)
  91:   {
  92:     int retval = 0;
  93:     retval |= (long)(data[pos + 3] & 0xff) << 24;
  94:     retval |= (long)(data[pos + 2] & 0xff) << 16;
  95:     retval |= (long)(data[pos + 1] & 0xff) << 8;
  96:     retval |= (long)(data[pos ] & 0xff);
  97:     return retval;
  98:   }
  99: 
 100: }