Exemplo n.º 1
0
        public void SearchForTextStringTest()
        {
            string file = Path.Combine(Util.ArtifactsDataPath, "test077C_P01.txtz");

            using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TxtzChunk unk  = new TxtzChunk(reader, null, null, null, stream.Length);
                    string    test = "landscapes";

                    Assert.True(unk.TextLength > 0);
                    Assert.NotNull(unk.Text);
                    Assert.Equal(unk.TextLength, unk.Text.Length);
                    Assert.Equal(1, unk.Version);
                    Assert.True(unk.Text.Contains(test), "Text not found on page");

                    int contains     = 0;
                    int preContains  = 0;
                    int postContains = 0;

                    VerifyZoneContainsText(unk.Zone, test, ref contains, ref preContains, ref postContains);

                    Assert.True(contains > 0, "Text not found in zones");
                    //Assert.True(postContains > 0, "Text not found in PostText");
                    //Assert.True(preContains > 0, "Text not found in PreText");
                }
        }
Exemplo n.º 2
0
        public void TxtzChunkTest001()
        {
            Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>();

            readerMock.Setup(x => x.Position).Returns(1024);

            TxtzChunk unk = new TxtzChunk(readerMock.Object, null, null, null, 0);

            Assert.Equal <ChunkType>(ChunkType.Txtz, unk.ChunkType);
            Assert.Equal(ChunkType.Txtz.ToString(), unk.Name);
            Assert.Equal <long>(1024, unk.DataOffset);
        }
Exemplo n.º 3
0
        public void TxtzChunk_Theory(string file)
        {
            using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TxtzChunk unk = new TxtzChunk(reader, null, null, null, stream.Length);

                    Assert.Equal <ChunkType>(ChunkType.Txtz, unk.ChunkType);
                    Assert.Equal(ChunkType.Txtz.ToString(), unk.Name);
                    Assert.Equal <long>(0, unk.DataOffset);
                    Assert.True(unk.TextLength > 0);
                    Assert.NotNull(unk.Text);
                    Assert.Equal(unk.TextLength, unk.Text.Length);
                    Assert.Equal(1, unk.Version);
                }
        }
Exemplo n.º 4
0
        public void TextZoneTest001()
        {
            string file = Path.Combine(Util.ArtifactsDataPath, "test077C_P01.txtz");

            using (FileStream stream = new FileStream(file, FileMode.Open))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TxtzChunk unk = new TxtzChunk(reader, null, null, null, stream.Length);

                    Assert.True(unk.TextLength > 0);
                    Assert.NotNull(unk.Text);
                    Assert.Equal(unk.TextLength, unk.Text.Length);
                    Assert.Equal(1, unk.Version);

                    VisitTextZones(unk.Zone);
                }
        }
Exemplo n.º 5
0
        public void TxtzChunkTest002()
        {
            string file = Path.Combine(Util.ArtifactsDataPath, "test077C_P01.txtz");

            using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TxtzChunk unk = new TxtzChunk(reader, null, null, null, stream.Length);

                    Assert.Equal <ChunkType>(ChunkType.Txtz, unk.ChunkType);
                    Assert.Equal(ChunkType.Txtz.ToString(), unk.Name);
                    Assert.Equal <long>(0, unk.DataOffset);
                    Assert.True(unk.TextLength > 0);
                    Assert.NotNull(unk.Text);
                    Assert.Equal(unk.TextLength, unk.Text.Length);
                    Assert.Equal(1, unk.Version);
                }
        }
Exemplo n.º 6
0
        public void SearchForTextRectangleTest()
        {
            string file = Path.Combine(Util.ArtifactsDataPath, "test077C_P01.txtz");

            using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TxtzChunk unk = new TxtzChunk(reader, null, null, null, stream.Length);

                    Assert.True(unk.TextLength > 0);
                    Assert.NotNull(unk.Text);
                    Assert.Equal(unk.TextLength, unk.Text.Length);
                    Assert.Equal(1, unk.Version);

                    var result = unk.Zone.SearchForText(new System.Drawing.Rectangle(0, 0, 10000, 10000));
                    Assert.NotNull(result);
                    Assert.True(result.Length > 0);
                }
        }
Exemplo n.º 7
0
        public void TextZone_Theory(string file)
        {
            using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TxtzChunk unk = new TxtzChunk(reader, null, null, null, stream.Length);

                    Assert.True(unk.TextLength > 0);
                    Assert.NotNull(unk.Text);
                    Assert.Equal(unk.TextLength, unk.Text.Length);
                    Assert.Equal(1, unk.Version);

                    TextZone zone     = unk.Zone;
                    var      preText  = zone.GetPreTextData();
                    var      postText = zone.GetPostTextData();
                    var      text     = zone.GetTextData();

                    Assert.NotNull(text);
                }
        }
Exemplo n.º 8
0
        public static IDjvuNode CreateEncodedDjvuNode(IDjvuWriter writer, IDjvuElement parent, ChunkType chunkType, long length)
        {
            IDjvuNode result = null;

            switch (chunkType)
            {
            case ChunkType.Djvm:
                result = new DjvmChunk(writer, parent, length);
                break;

            case ChunkType.Djvu:
                result = new DjvuChunk(writer, parent, length);
                break;

            case ChunkType.Djvi:
                result = new DjviChunk(writer, parent, length);
                break;

            case ChunkType.Thum:
                result = new ThumChunk(writer, parent, length);
                break;

            case ChunkType.Dirm:
                result = new DirmChunk(writer, parent, length);
                break;

            case ChunkType.Navm:
                result = new NavmChunk(writer, parent, length);
                break;

            case ChunkType.Anta:
                result = new AntaChunk(writer, parent, length);
                break;

            case ChunkType.Antz:
                result = new AntzChunk(writer, parent, length);
                break;

            case ChunkType.Txta:
                result = new TxtaChunk(writer, parent, length);
                break;

            case ChunkType.Txtz:
                result = new TxtzChunk(writer, parent, length);
                break;

            case ChunkType.Djbz:
                result = new DjbzChunk(writer, parent, length);
                break;

            case ChunkType.Sjbz:
                result = new SjbzChunk(writer, parent, length);
                break;

            case ChunkType.FG44:
                result = new FG44Chunk(writer, parent, length);
                break;

            case ChunkType.BG44:
                result = new BG44Chunk(writer, parent, length);
                break;

            case ChunkType.TH44:
                result = new TH44Chunk(writer, parent, length);
                break;

            case ChunkType.BM44:
                result = new BM44Chunk(writer, parent, length);
                break;

            case ChunkType.BM44Form:
                result = new BM44Form(writer, parent, length);
                break;

            case ChunkType.PM44:
                result = new PM44Chunk(writer, parent, length);
                break;

            case ChunkType.PM44Form:
                result = new PM44Form(writer, parent, length);
                break;

            case ChunkType.Wmrm:
                result = new WmrmChunk(writer, parent, length);
                break;

            case ChunkType.FGbz:
                result = new FGbzChunk(writer, parent, length);
                break;

            case ChunkType.Info:
                result = new InfoChunk(writer, parent, length);
                break;

            case ChunkType.Incl:
                result = new InclChunk(writer, parent, length);
                break;

            case ChunkType.BGjp:
                result = new BGjpChunk(writer, parent, length);
                break;

            case ChunkType.FGjp:
                result = new FGjpChunk(writer, parent, length);
                break;

            case ChunkType.Smmr:
                result = new SmmrChunk(writer, parent, length);
                break;

            default:
                throw new DjvuInvalidOperationException($"Chunk type is not supported in encoding. ChunkType: {chunkType}");
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Builds the appropriate chunk for the ID
        /// </summary>
        /// <returns></returns>
        public static IDjvuNode CreateDecodedDjvuNode(IDjvuReader reader, IDjvuDocument rootDocument,
                                                      IDjvuElement parent, ChunkType chunkType,
                                                      string chunkID = "", long length = 0)
        {
            IDjvuNode result = null;

            switch (chunkType)
            {
            case ChunkType.Djvm:
                result = new DjvmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Djvu:
                result = new DjvuChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Djvi:
                result = new DjviChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Thum:
                result = new ThumChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Dirm:
                result = new DirmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Navm:
                result = new NavmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Anta:
                result = new AntaChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Antz:
                result = new AntzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Txta:
                result = new TxtaChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Txtz:
                result = new TxtzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Djbz:
                result = new DjbzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Sjbz:
                result = new SjbzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.FG44:
                result = new FG44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BG44:
                result = new BG44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.TH44:
                result = new TH44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BM44:
                result = new BM44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BM44Form:
                result = new BM44Form(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.PM44:
                result = new PM44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.PM44Form:
                result = new PM44Form(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Wmrm:
                result = new WmrmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.FGbz:
                result = new FGbzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Info:
                result = new InfoChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Incl:
                result = new InclChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BGjp:
                result = new BGjpChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.FGjp:
                result = new FGjpChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Smmr:
                result = new SmmrChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Cida:
                result = new CidaChunk(reader, parent, rootDocument, chunkID, length);
                break;

            default:
                result = new UnknownChunk(reader, parent, rootDocument, chunkID, length);
                break;
            }

            return(result);
        }