Пример #1
0
        /// <summary>
        /// Decodes the data for the zone
        /// </summary>
        /// <param name="reader"></param>
        private void DecodeZoneData(DjvuReader reader, TextZone sibling, TextChunk chunkParent)
        {
            _zoneType = (ZoneTypes)reader.ReadByte();
            _x        = reader.ReadUInt16MSB() - 0x8000;
            _y        = reader.ReadUInt16MSB() - 0x8000;
            _width    = reader.ReadUInt16MSB() - 0x8000;
            _height   = reader.ReadUInt16MSB() - 0x8000;

            _textOffset = reader.ReadUInt16MSB() - 0x8000;
            _textLength = reader.ReadInt24MSB();

            ResolveOffsets(_parent, sibling);

            _rectangle = new Rectangle(_x, _y, _width, _height);

            int             childrenZones = reader.ReadInt24MSB();
            List <TextZone> children      = new List <TextZone>();

            TextZone childrenSibling = null;

            for (int x = 0; x < childrenZones; x++)
            {
                TextZone newZone = new TextZone(reader, this, childrenSibling, chunkParent);
                childrenSibling = newZone;

                children.Add(newZone);
            }

            _children = children.ToArray();
        }
Пример #2
0
        /// <summary>
        /// Reads the compressed data from the djvu file
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="count"></param>
        /// <param name="compressedSectionLength"></param>
        private void ReadCompressedData(DjvuReader reader, int count, int compressedSectionLength)
        {
            DjvuReader decompressor = reader.GetBZZEncodedReader(compressedSectionLength);

            // Read the component sizes
            for (int x = 0; x < count; x++)
            {
                _components[x].Size = decompressor.ReadInt24MSB();
            }

            // Read the component flag information
            for (int x = 0; x < count; x++)
            {
                _components[x].DecodeFlags(decompressor.ReadSByte());
            }

            // Read the component strings
            for (int x = 0; x < count; x++)
            {
                _components[x].ID = decompressor.ReadNullTerminatedString();
                if (_components[x].HasName == true)
                {
                    _components[x].Name = decompressor.ReadNullTerminatedString();
                }
                if (_components[x].HasTitle == true)
                {
                    _components[x].Title = decompressor.ReadNullTerminatedString();
                }
            }

            _isInitialized = true;
        }
Пример #3
0
        /// <summary>
        /// Loads the bookmark data
        /// </summary>
        /// <param name="reader"></param>
        private void DecodeBookmarkData(DjvuReader reader)
        {
            int childrenCount = reader.ReadByte();

            int textSize = reader.ReadInt24MSB();

            Name = reader.ReadUTF8String(textSize);

            int urlSize = reader.ReadInt24MSB();

            URL = reader.ReadUTF8String(urlSize);

            // Read in all the children bookmarks
            List <Bookmark> children = new List <Bookmark>();

            for (int x = 0; x < childrenCount; x++)
            {
                children.Add(new Bookmark(reader, Document, this));
            }
            _children = children.ToArray();
        }
Пример #4
0
        /// <summary>
        /// Reads the compressed text data
        /// </summary>
        private void ReadCompressedTextData()
        {
            if (Length == 0)
            {
                return;
            }

            using (DjvuReader reader = GetTextDataReader(_dataLocation))
            {
                _textLength = reader.ReadInt24MSB();
                byte[] textBytes = reader.ReadBytes(_textLength);
                _text    = Encoding.UTF7.GetString(textBytes);
                _version = reader.ReadSByte();

                _zone = new TextZone(reader, null, null, this);
            }

            _isDecoded = true;
        }
Пример #5
0
        /// <summary>
        /// Decodes the palette data
        /// </summary>
        /// <param name="reader"></param>
        private void ReadPaletteData(DjvuReader reader)
        {
            sbyte header       = reader.ReadSByte();
            bool  isShapeTable = (header >> 7) == 1;

            _version = header & 127;

            int paletteSize = reader.ReadInt16MSB();

            // Read in the palette colors
            List <Pixel> paletteColors = new List <Pixel>();

            for (int x = 0; x < paletteSize; x++)
            {
                sbyte b = reader.ReadSByte();
                sbyte g = reader.ReadSByte();
                sbyte r = reader.ReadSByte();

                paletteColors.Add(new Pixel(b, g, r));
            }
            _paletteColors = paletteColors.ToArray();

            if (isShapeTable == true)
            {
                int totalBlits = reader.ReadInt24MSB();

                DjvuReader compressed = reader.GetBZZEncodedReader();

                // Read in the blit colors
                List <int> blitColors = new List <int>();
                for (int x = 0; x < totalBlits; x++)
                {
                    int index = compressed.ReadInt16MSB();
                    blitColors.Add(index);
                }
                _blitColors = blitColors.ToArray();
            }
        }
Пример #6
0
        /// <summary>
        /// Decodes the palette data
        /// </summary>
        /// <param name="reader"></param>
        private void ReadPaletteData(DjvuReader reader)
        {
            sbyte header = reader.ReadSByte();
            bool isShapeTable = (header >> 7) == 1;
            _version = header & 127;

            int paletteSize = reader.ReadInt16MSB();

            // Read in the palette colors
            List<Pixel> paletteColors = new List<Pixel>();
            for (int x = 0; x < paletteSize; x++)
            {
                sbyte b = reader.ReadSByte();
                sbyte g = reader.ReadSByte();
                sbyte r = reader.ReadSByte();

                paletteColors.Add(new Pixel(b, g, r));
            }
            _paletteColors = paletteColors.ToArray();

            if (isShapeTable == true)
            {
                int totalBlits = reader.ReadInt24MSB();

                DjvuReader compressed = reader.GetBZZEncodedReader();

                // Read in the blit colors
                List<int> blitColors = new List<int>();
                for (int x = 0; x < totalBlits; x++)
                {
                    int index = compressed.ReadInt16MSB();
                    blitColors.Add(index);
                }
                _blitColors = blitColors.ToArray();
            }
        }
Пример #7
0
        /// <summary>
        /// Decodes the data for the zone
        /// </summary>
        /// <param name="reader"></param>
        private void DecodeZoneData(DjvuReader reader, TextZone sibling, TextChunk chunkParent)
        {
            _zoneType = (ZoneTypes)reader.ReadByte();
            _x = reader.ReadUInt16MSB() - 0x8000;
            _y = reader.ReadUInt16MSB() - 0x8000;
            _width = reader.ReadUInt16MSB() - 0x8000;
            _height = reader.ReadUInt16MSB() - 0x8000;

            _textOffset = reader.ReadUInt16MSB() - 0x8000;
            _textLength = reader.ReadInt24MSB();

            ResolveOffsets(_parent, sibling);

            _rectangle = new Rectangle(_x, _y, _width, _height);

            int childrenZones = reader.ReadInt24MSB();
            List<TextZone> children = new List<TextZone>();

            TextZone childrenSibling = null;

            for (int x = 0; x < childrenZones; x++)
            {
                TextZone newZone = new TextZone(reader, this, childrenSibling, chunkParent);
                childrenSibling = newZone;

                children.Add(newZone);
            }

            _children = children.ToArray();
        }
Пример #8
0
        /// <summary>
        /// Loads the bookmark data
        /// </summary>
        /// <param name="reader"></param>
        private void DecodeBookmarkData(DjvuReader reader)
        {
            int childrenCount = reader.ReadByte();

            int textSize = reader.ReadInt24MSB();
            Name = reader.ReadUTF8String(textSize);

            int urlSize = reader.ReadInt24MSB();
            URL = reader.ReadUTF8String(urlSize);

            // Read in all the children bookmarks
            List<Bookmark> children = new List<Bookmark>();
            for (int x = 0; x < childrenCount; x++)
            {
                children.Add(new Bookmark(reader, Document, this));
            }
            _children = children.ToArray();
        }