Exemple #1
0
        private void Initialize()
        {
            if (_ClipPaths != null)
            {
                return;
            }

            _ClipPaths = new Collection <ClipPath>();
            _Values    = new Collection <EightBimValue>();

            int i = 0;

            while (i < Data.Length)
            {
                if (Data[i++] != '8')
                {
                    continue;
                }
                if (Data[i++] != 'B')
                {
                    continue;
                }
                if (Data[i++] != 'I')
                {
                    continue;
                }
                if (Data[i++] != 'M')
                {
                    continue;
                }

                if (i + 7 > Data.Length)
                {
                    return;
                }

                short id         = ByteConverter.ToShort(Data, ref i);
                bool  isClipPath = id > 1999 && id < 2998;

                string name   = null;
                int    length = Data[i++];
                if (length != 0)
                {
                    if (isClipPath && i + length < Data.Length)
                    {
                        name = Encoding.ASCII.GetString(Data, i, length);
                    }

                    i += length;
                }

                if ((length & 0x01) == 0)
                {
                    i++;
                }

                length = ByteConverter.ToUInt(Data, ref i);
                if (i + length > Data.Length)
                {
                    return;
                }

                if (length < 0)
                {
                    return;
                }

                if (length != 0)
                {
                    if (isClipPath)
                    {
                        ClipPath clipPath = CreateClipPath(name, i, length);
                        if (clipPath != null)
                        {
                            _ClipPaths.Add(clipPath);
                        }
                    }

                    byte[] data = new byte[length];
                    Array.Copy(Data, i, data, 0, length);
                    _Values.Add(new EightBimValue(id, data));
                }

                i += length;
            }
        }