Exemplo n.º 1
0
        // Based on section 6.1.1 of MicroType Express draft spec
        public static int Read255UShort(Buffer buf)
        {
            int  kWordCode         = 253;
            int  kOneMoreByteCode2 = 254;
            int  kOneMoreByteCode1 = 255;
            int  kLowestUCode      = 253;
            byte code = 0;

            code = buf.ReadByte();
            if (JavaUnsignedUtil.AsU8(code) == kWordCode)
            {
                short result = buf.ReadShort();
                return(JavaUnsignedUtil.AsU16(result));
            }
            else
            {
                if (JavaUnsignedUtil.AsU8(code) == kOneMoreByteCode1)
                {
                    byte result = buf.ReadByte();
                    return(JavaUnsignedUtil.AsU8(result) + kLowestUCode);
                }
                else
                {
                    if (JavaUnsignedUtil.AsU8(code) == kOneMoreByteCode2)
                    {
                        byte result = buf.ReadByte();
                        return(JavaUnsignedUtil.AsU8(result) + kLowestUCode * 2);
                    }
                    else
                    {
                        return(JavaUnsignedUtil.AsU8(code));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static int ReadBase128(Buffer buf)
        {
            int result = 0;

            for (int i = 0; i < 5; ++i)
            {
                byte code = 0;
                code = buf.ReadByte();
                // Leading zeros are invalid.
                if (i == 0 && JavaUnsignedUtil.AsU8(code) == 0x80)
                {
                    throw new FontCompressionException(FontCompressionException.READ_BASE_128_FAILED);
                }
                // If any of the top seven bits are set then we're about to overflow.
                if ((result & unchecked ((int)(0xfe000000))) != 0)
                {
                    throw new FontCompressionException(FontCompressionException.READ_BASE_128_FAILED);
                }
                result = (result << 7) | (code & 0x7f);
                if ((code & 0x80) == 0)
                {
                    return(result);
                }
            }
            // Make sure not to exceed the size bound
            throw new FontCompressionException(FontCompressionException.READ_BASE_128_FAILED);
        }
Exemplo n.º 3
0
 // Helper functions for storing integer values into byte streams.
 // No bounds checking is performed, that is the responsibility of the caller.
 public static int StoreU32(byte[] dst, int offset, int x)
 {
     dst[offset]     = JavaUnsignedUtil.ToU8(x >> 24);
     dst[offset + 1] = JavaUnsignedUtil.ToU8(x >> 16);
     dst[offset + 2] = JavaUnsignedUtil.ToU8(x >> 8);
     dst[offset + 3] = JavaUnsignedUtil.ToU8(x);
     return(offset + 4);
 }
Exemplo n.º 4
0
        private int ReadAsNumber(int n_bytes)
        {
            byte[] buffer = new byte[n_bytes];
            Read(buffer, 0, n_bytes);
            int result = 0;

            for (int i = 0; i < n_bytes; ++i)
            {
                result = (result << 8) | JavaUnsignedUtil.AsU8(buffer[i]);
            }
            return(result);
        }
Exemplo n.º 5
0
 public static int StoreU16(byte[] dst, int offset, int x)
 {
     dst[offset]     = JavaUnsignedUtil.ToU8(x >> 8);
     dst[offset + 1] = JavaUnsignedUtil.ToU8(x);
     return(offset + 2);
 }
Exemplo n.º 6
0
 public virtual byte ReadByte()
 {
     return(JavaUnsignedUtil.ToU8(ReadAsNumber(1)));
 }
Exemplo n.º 7
0
 public virtual short ReadShort()
 {
     return(JavaUnsignedUtil.ToU16(ReadAsNumber(2)));
 }