示例#1
0
 /// <summary>
 /// Decodes the available IFF chunks
 /// </summary>
 /// <param name="reader"></param>
 internal void DecodeRootForm(DjvuReader reader)
 {
     RootForm = DjvuParser.GetRootForm(reader, null, this);
     RootForm.Initialize(reader);
     foreach (IDjvuNode chunk in RootForm.Children)
     {
         chunk.Initialize(reader);
     }
 }
示例#2
0
        public List <T> GetRootFormChildren <T>() where T : DjvuNode
        {
            if (RootForm.ChunkType == ChunkType.Djvu)
            {
                return(new List <T>(new T[] { RootForm as T }));
            }

            string    id        = typeof(T).Name.Replace("Chunk", null);
            ChunkType chunkType = DjvuParser.GetChunkType(id);

            return(RootForm.Children.Where <IDjvuNode>(x => x.ChunkType == chunkType)
                   .ToList <IDjvuNode>().ConvertAll <T>(x => (T)x));
        }
示例#3
0
        public void ToStringTest()
        {
            IDjvuReader        reader     = null;
            Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>();

            readerMock.Setup <long>(x => x.Position).Returns(1024);
            reader = readerMock.Object;

            IDjvuElement element = (IDjvuElement)DjvuParser.CreateDecodedDjvuNode(reader, null, null, ChunkType.Djvi, "DJVI", 127);
            string       result  = element.ToString();

            Assert.False(String.IsNullOrWhiteSpace(result));
            Assert.Contains("ID: DJVI", result);
            Assert.Contains("Name: Djvi", result);
            Assert.Contains("Length: 127", result);
            Assert.Contains("Offset: 1024", result);
            Assert.Contains("Children: 0", result);
        }
示例#4
0
        public void IsRootFormChildTest()
        {
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.Dirm));
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.Djvi));
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.Djvu));
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.Navm));
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.Thum));
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.Form));
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.PM44, ChunkType.PM44Form));
            Assert.True(DjvuParser.IsRootFormChild(ChunkType.BM44, ChunkType.BM44Form));

            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Djvm));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Anta));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Antz));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.BG44));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.BM44));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.BM44Form));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.PM44));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.PM44Form));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.BGjp));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Cida));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Djbz));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.FG44));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.FGbz));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.FGjp));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Incl));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Info));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Sjbz));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Smmr));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Text));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.TH44));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Txta));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Txtz));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Unknown));
            Assert.False(DjvuParser.IsRootFormChild(ChunkType.Wmrm));
        }
示例#5
0
        public void CreateDecodedDjvuNode_Theory(IDjvuReader reader, IDjvuDocument rootDocument,
                                                 IDjvuElement parent, ChunkType chunkType,
                                                 string chunkID = "", long length = 0)
        {
            if (reader == null)
            {
                Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>();
                readerMock.Setup <long>(x => x.Position).Returns(1024);
                reader = readerMock.Object;
            }

            if (ChunkType.Info == chunkType)
            {
                length = 10;
            }

            IDjvuNode node = DjvuParser.CreateDecodedDjvuNode(reader, rootDocument, parent, chunkType, chunkID, length);

            Assert.NotNull(node);
            Assert.Equal <ChunkType>(chunkType, node.ChunkType);
            Assert.Equal(chunkID, node.ChunkID);
            Assert.Equal <long>(length, node.Length);
            Assert.Equal <long>(reader.Position, node.DataOffset);
        }
示例#6
0
        /// <summary>
        /// Decodes the children of this chunk
        /// </summary>
        /// <param name="reader"></param>
        public virtual void ReadChildren(IDjvuReader reader)
        {
            _TempChildren = new List <IDjvuNode>();

            long maxPosition = this.Length + DataOffset;

            // Jump to next FORM data "space" - it is skipped for root FORM
            if (this != Document.RootForm)
            {
                reader.Position = DataOffset;
                if (DjvuParser.IsFormChunk(ChunkType))
                {
                    maxPosition -= 4;
                }
            }

            // Read in all the chunks
            while (true)
            {
                if (reader.Position % 2 == 1)
                {
                    reader.Position++;
                }

                if (reader.Position >= maxPosition)
                {
                    break;
                }

                // Read the chunk ID
                string    id     = reader.ReadUTF8String(4);
                ChunkType type   = DjvuParser.GetChunkType(id);
                long      length = reader.ReadUInt32BigEndian();

                bool isFormChunk = DjvuParser.IsFormChunk(type);

                if (isFormChunk)
                {
                    id   = reader.ReadUTF8String(4);
                    type = DjvuParser.GetChunkType(id);
                }

                // Reset the stream position
                // reader.Position -= 4;

                var chunk = DjvuParser.CreateDecodedDjvuNode(reader, Document, this, type, id, length);

                if (chunk != null)
                {
                    if (!DjvuParser.IsRootFormChild(type))
                    {
                        _TempChildren.Add(chunk);
                        _TempChildren[_TempChildren.Count - 1].Initialize(reader);
                        reader.Position = chunk.Length + chunk.DataOffset;
                    }
                    else
                    {
                        Document.RootForm._TempChildren.Add(chunk);
                        reader.Position = chunk.Length + chunk.DataOffset;
                        if (isFormChunk)
                        {
                            reader.Position -= 4;
                        }
                    }
                }
            }

            Children      = _TempChildren;
            _TempChildren = null;
        }