示例#1
0
        public void InclChunk_Theory(string file, DjvuJsonDocument doc)
        {
            byte[] buffer = null;
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                buffer = new byte[fs.Length];
                int result = fs.Read(buffer, 0, buffer.Length);
                Assert.Equal <long>(fs.Length, result);
            }
            Mock <IDjvuDocument> docMock    = new Mock <IDjvuDocument>();
            Mock <IDjvuElement>  parentMock = new Mock <IDjvuElement>();
            IDjvuElement         parent     = parentMock.Object;
            IDjvuDocument        document   = docMock.Object;

            using (MemoryStream ms = new MemoryStream(buffer, false))
                using (IDjvuReader reader = new DjvuReader(ms))
                {
                    InclChunk chunk = new InclChunk(reader, parent, document, "INCL", buffer.Length);
                    Assert.False(chunk.IsInitialized);
                    // Support multiple INCL chunks in single DjvuChunk
                    var testChunk = doc.Data.Pages[0].Children
                                    .Where(x => x.ID == "INCL" && x.Name == chunk.IncludeID)
                                    .FirstOrDefault <DjvuJsonDocument.Chunk>();
                    Assert.NotNull(testChunk);
                    Assert.Equal(testChunk.Name, chunk.IncludeID);
                }
        }
示例#2
0
        public void Palette_Theory(string file, DjvuJsonDocument doc)
        {
            byte[] buffer = null;
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                buffer = new byte[fs.Length];
                int result = fs.Read(buffer, 0, buffer.Length);
                Assert.Equal <long>(fs.Length, result);
            }
            Mock <IDjvuDocument> docMock    = new Mock <IDjvuDocument>();
            Mock <IDjvuElement>  parentMock = new Mock <IDjvuElement>();
            IDjvuElement         parent     = parentMock.Object;
            IDjvuDocument        document   = docMock.Object;

            using (MemoryStream ms = new MemoryStream(buffer, false))
                using (IDjvuReader reader = new DjvuReader(ms))
                {
                    FGbzChunk chunk = new FGbzChunk(reader, parent, document, "FGBZ", buffer.Length);
                    Assert.False(chunk.IsInitialized);
                    var testChunk = doc.Data.Pages[0].Children
                                    .Where(x => x.ID == "FGbz")
                                    .FirstOrDefault <DjvuJsonDocument.Chunk>();
                    Assert.Equal <int>((int)testChunk?.Version.Value, chunk.Version);
                    Assert.Equal <int>((int)testChunk.Colors.Value, (int)chunk.Palette?.PaletteColors?.Length);
                }
        }
示例#3
0
 /// <summary>
 /// IFFChunk constructor
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="parent"></param>
 /// <param name="document"></param>
 /// <param name="chunkID"></param>
 /// <param name="length"></param>
 public DjvuNode(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document,
                 string chunkID = "", long length = 0)
 {
     Reader     = reader;
     Parent     = parent;
     Document   = document;
     Length     = length;
     ChunkID    = chunkID;
     DataOffset = reader.Position;
 }
示例#4
0
        public Bookmark(IDjvuDocument document, INavmChunk navm, Bookmark parent, string name, string url, Bookmark[] children)
        {
            InitializeReferences(document, navm, parent);

            Name     = name;
            Url      = url;
            Children = children;

            LoadReferencedPage();
        }
示例#5
0
        public DjvuImage(IDjvuPage page)
        {
            if (page == null)
            {
                throw new DjvuArgumentNullException(nameof(page));
            }

            _Page = page;
            _Page.PropertyChanged += PagePropertyChanged;
            _Document              = page.Document;
        }
示例#6
0
        internal void BuildNavigation(IDjvuDocument document)
        {
            List <Bookmark> bookmarks = new List <Bookmark>();

            for (int x = 0; x < document.Pages.Count; x++)
            {
                IDjvuPage page    = document.Pages[x];
                int       pageNum = x + 1;
                bookmarks.Add(new Bookmark(document, null, null,
                                           string.Format("Page {0}", pageNum), string.Format("#{0}", pageNum), new Bookmark[0]));
            }

            Bookmarks = bookmarks;
        }
示例#7
0
        internal void InitializeReferences(IDjvuDocument document, INavmChunk navm, Bookmark parent)
        {
            Document = document;
            Parent   = parent;

            if (navm != null)
            {
                NavmNode = navm;
            }
            else if (parent != null)
            {
                NavmNode = parent.NavmNode;
            }
            else if (document != null)
            {
                NavmNode = document.RootForm.Children
                           .Where(x => x.ChunkType == ChunkType.Navm)
                           .FirstOrDefault() as INavmChunk;
            }
        }
示例#8
0
        public void ImageTest()
        {
            Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>();

            readerMock.SetupAllProperties();
            readerMock.Object.Position = 1024;

            Mock <IDjvuDocument> docMock    = new Mock <IDjvuDocument>();
            Mock <IDjvuElement>  parentMock = new Mock <IDjvuElement>();

            IDjvuReader   reader   = readerMock.Object;
            IDjvuElement  parent   = parentMock.Object;
            IDjvuDocument document = docMock.Object;

            SjbzChunk chunk = new SjbzChunk(reader, parent, document, "SJBZ", 2048);

            Assert.False(chunk.IsInitialized);

            chunk.ReadData(reader);
            Assert.Equal <long>(reader.Position, chunk.DataOffset + chunk.Length);
        }
示例#9
0
        public DjvuPage(int pageNumber, IDjvuDocument document, DirmComponent header,
            ITH44Chunk thumbnail, IReadOnlyList<IDjviChunk> includedItems, DjvuFormElement form)
        {
            PageNumber = pageNumber;
            Document = document;
            Header = header;
            Thumbnail = thumbnail;
            IncludeFiles = includedItems;
            PageForm = form;
            _DjvuImage = new DjvuImage(this);
            PropertyChanged += DjvuPage_PropertyChanged;

            if (form.ChunkType != ChunkType.BM44Form && form.ChunkType != ChunkType.PM44Form && Info == null)
            {
                throw new DjvuFormatException(
                    $"Page {PageNumber} does not have associated Info chunk." +
                    "Page is invalid and can not be displayed");
            }
            else if (form.ChunkType == ChunkType.BM44Form || form.ChunkType == ChunkType.PM44Form)
            {
                // TODO: Debug log or assert
            }
        }
示例#10
0
        public void FGbzChunkTest001()
        {
            Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>();

            readerMock.Setup <long>(x => x.Position).Returns(1024);
            // readerMock.SetupAllProperties();

            Mock <IDjvuDocument> docMock    = new Mock <IDjvuDocument>();
            Mock <IDjvuElement>  parentMock = new Mock <IDjvuElement>();

            IDjvuReader   reader   = readerMock.Object;
            IDjvuElement  parent   = parentMock.Object;
            IDjvuDocument document = docMock.Object;

            FGbzChunk chunk = new FGbzChunk(reader, parent, document, "FGBZ", 2048);

            Assert.False(chunk.IsInitialized);
            Assert.Equal <long>(1024, chunk.DataOffset);
            Assert.Equal <long>(2048, chunk.Length);
            Assert.Same(reader, chunk.Reader);
            Assert.Same(parent, chunk.Parent);
            Assert.Same(document, chunk.Document);
        }
示例#11
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);
        }
示例#12
0
        public static DjvuFormElement GetRootForm(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document)
        {
            string formStr = reader.ReadUTF8String(4);
            // use of uint in Djvu Format limits file read size to 4 GB - should be long (int64)
            int    length   = (int)reader.ReadUInt32BigEndian();
            string formType = reader.ReadUTF8String(4);

            reader.Position -= 4;

            ChunkType type = DjvuParser.GetFormType(formType);

            DjvuFormElement formObj = (DjvuFormElement)DjvuParser.CreateDecodedDjvuNode(reader, document, parent, type, formType, length);

            return(formObj);
        }
示例#13
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);
        }
示例#14
0
 public DocumentNavigator(IDjvuDocument document)
 {
     BuildNavigation(document);
 }
示例#15
0
 public Bookmark(IDjvuReader reader, IDjvuDocument document, INavmChunk navm, Bookmark parent)
 {
     InitializeReferences(document, navm, parent);
     DecodeBookmarkData(reader);
     LoadReferencedPage();
 }
示例#16
0
 public DjvuFormElement(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document,
                        string chunkID = "", long length = 0)
     : base(reader, parent, document, chunkID, length)
 {
     InitializeInternal();
 }
示例#17
0
 public AntaChunk(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document,
                  string chunkID = "", long length = 0)
     : base(reader, parent, document, chunkID, length)
 {
 }
示例#18
0
 public UnknownChunk(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document,
                     string chunkID = "", long length = 0)
     : base(reader, parent, document, chunkID, length)
 {
     // Nothing
 }