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); } }
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); } }
/// <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; }
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(); }
public DjvuImage(IDjvuPage page) { if (page == null) { throw new DjvuArgumentNullException(nameof(page)); } _Page = page; _Page.PropertyChanged += PagePropertyChanged; _Document = page.Document; }
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; }
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; } }
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); }
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 } }
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); }
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); }
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); }
/// <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); }
public DocumentNavigator(IDjvuDocument document) { BuildNavigation(document); }
public Bookmark(IDjvuReader reader, IDjvuDocument document, INavmChunk navm, Bookmark parent) { InitializeReferences(document, navm, parent); DecodeBookmarkData(reader); LoadReferencedPage(); }
public DjvuFormElement(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document, string chunkID = "", long length = 0) : base(reader, parent, document, chunkID, length) { InitializeInternal(); }
public AntaChunk(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document, string chunkID = "", long length = 0) : base(reader, parent, document, chunkID, length) { }
public UnknownChunk(IDjvuReader reader, IDjvuElement parent, IDjvuDocument document, string chunkID = "", long length = 0) : base(reader, parent, document, chunkID, length) { // Nothing }