Example #1
0
        /// <summary>
        /// Resolves the zone offsets for the location and text
        /// </summary>
        private void ResolveOffsets(TextZone parent, TextZone sibling)
        {
            if (parent == null && sibling == null)
            {
                return;
            }

            if (sibling == null)
            {
                _x          += parent.Rectangle.Right;
                _y           = parent.Rectangle.Top - (_y + Height);
                _textOffset += parent.TextOffset;
            }
            else
            {
                if (sibling.ZoneType == ZoneTypes.Page || sibling.ZoneType == ZoneTypes.Paragraph || sibling.ZoneType == ZoneTypes.Line)
                {
                    _x = _x + sibling.Rectangle.Right;
                    _y = sibling.Rectangle.Bottom - (_y + _height);
                }
                else if (sibling.ZoneType == ZoneTypes.Column || sibling.ZoneType == ZoneTypes.Word || sibling.ZoneType == ZoneTypes.Character)
                {
                    _x += sibling.Rectangle.Left;
                    _y += sibling.Rectangle.Bottom;
                }

                _textOffset += sibling.TextOffset + sibling.TextLength;
            }
        }
Example #2
0
        public TextZone(DjvuReader reader, TextZone parent, TextZone sibling, TextChunk chunkParent)
        {
            _parent      = parent;
            _chunkParent = chunkParent;

            DecodeZoneData(reader, sibling, chunkParent);
        }
Example #3
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.ReadUInt16BigEndian() - 0x8000;
            _y        = reader.ReadUInt16BigEndian() - 0x8000;
            _width    = reader.ReadUInt16BigEndian() - 0x8000;
            _height   = reader.ReadUInt16BigEndian() - 0x8000;

            _textOffset = reader.ReadUInt16BigEndian() - 0x8000;
            _textLength = reader.ReadInt24BigEndian();

            ResolveOffsets(_parent, sibling);

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

            int             childrenZones = reader.ReadInt24BigEndian();
            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();
        }
Example #4
0
        public TextZone(DjvuReader reader, TextZone parent, TextZone sibling, TextChunk chunkParent)
        {
            _parent = parent;
            _chunkParent = chunkParent;

            DecodeZoneData(reader, sibling, chunkParent);
        }
Example #5
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;
        }
Example #6
0
        /// <summary>
        /// Reads the compressed text data
        /// </summary>
        private void ReadCompressedTextData()
        {
            if (Length > 0)
            {
                using (DjvuReader reader = GetTextDataReader(_dataLocation))
                {
                    int    length    = (int)reader.ReadUInt24BigEndian();
                    byte[] textBytes = reader.ReadBytes(length);
                    TextBytes  = textBytes;
                    Text       = Encoding.UTF8.GetString(textBytes);
                    TextLength = _text.Length;
                    Version    = reader.ReadByte();

                    Zone = new TextZone(reader, null, null, this);
                }
            }
            _isDecoded = true;

            /* if (Length == 0) return;
             *
             * using (DjvuReader reader = GetTextDataReader(_dataLocation))
             * {
             *   _textLength = (int)reader.ReadUInt24BigEndian();
             *   byte[] textBytes = reader.ReadBytes(_textLength);
             *   _text = Encoding.UTF8.GetString(textBytes);
             *   if (_text.Contains("предварительной"))
             *   {
             *
             *   }
             *
             *
             *
             *   _version = reader.ReadByte();
             *   _textLength = _text.Length;
             *
             *   _zone = new TextZone(reader, null, null, this);
             * }
             *
             * _isDecoded = true;*/
        }
Example #7
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;
        }
Example #8
0
 public PageTextItem(DjvuPage page, PageTextSearch parent, TextZone zone)
     : base(page)
 {
     _zone = zone;
     _parent = parent;
 }
Example #9
0
 public PageTextSearch(DjvuPage page, TextZone[] items)
     : base(page)
 {
     _textItems = items.Select(x => new PageTextItem(page, this, x)).ToArray();
 }
Example #10
0
        /// <summary>
        /// Resolves the zone offsets for the location and text
        /// </summary>
        private void ResolveOffsets(TextZone parent, TextZone sibling)
        {
            if (parent == null && sibling == null) return;

            if (sibling == null)
            {
                _x += parent.Rectangle.Right;
                _y = parent.Rectangle.Top - (_y + Height);
                _textOffset += parent.TextOffset;
            }
            else
            {
                if (sibling.ZoneType == ZoneTypes.Page || sibling.ZoneType == ZoneTypes.Paragraph || sibling.ZoneType == ZoneTypes.Line)
                {
                    _x = _x + sibling.Rectangle.Right;
                    _y = sibling.Rectangle.Bottom - (_y + _height);
                }
                else if (sibling.ZoneType == ZoneTypes.Column || sibling.ZoneType == ZoneTypes.Word || sibling.ZoneType == ZoneTypes.Character)
                {
                    _x += sibling.Rectangle.Left;
                    _y += sibling.Rectangle.Bottom;
                }

                _textOffset += sibling.TextOffset + sibling.TextLength;
            }
        }
Example #11
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();
        }