private void ConnectPage(PageObject page, BBeB book) { Debug.WriteLineIf(s_bDebugMode, "Connecting page: " + page.ID); UInt32ArrayTag childIDs = (UInt32ArrayTag)page.FindFirstTag(TagId.PageObjectIds); if (childIDs != null) { foreach (uint id in childIDs.Value) { BBeBObject child = book.FindObject((ushort)id); if (child == null) { throw new InvalidBookException("Can't find object id " + id); } Debug.Assert(child.ID == id); Debug.WriteLineIf(s_bDebugMode, " Child: " + child.GetType().ToString() + " - id:" + child.ID); page.Children.Add(child); } } UInt32Tag objInfoTag = (UInt32Tag)page.FindFirstTag(TagId.ObjectInfoLink); if (objInfoTag != null) { page.InfoObj = book.FindObject((ushort)objInfoTag.Value); if (page.InfoObj == null) { throw new InvalidBookException("Can't find info object id " + objInfoTag.Value); } } StreamTagGroup stream = (StreamTagGroup)page.FindFirstTag(TagId.StreamGroup); if (stream != null) { BBeBObject tempObj = new BBeBObject(0x0); page.StreamTags = BBeBTagFactory.ParseAllTags(tempObj, stream.Data); } UInt32Tag linkTag = (UInt32Tag)page.FindFirstTag(TagId.Link); if (linkTag != null) { BBeBObject linkedObj = book.FindObject((ushort)linkTag.Value); if (linkedObj == null) { throw new InvalidBookException("Can't find object id " + linkTag.Value); } page.LinkObj = linkedObj; } }
private void write(ImageObject obj) { // Get image details UInt16ArrayTag rect = (UInt16ArrayTag)obj.FindFirstTag(TagId.ImageRect); UInt16ArrayTag size = (UInt16ArrayTag)obj.FindFirstTag(TagId.ImageSize); UInt32Tag streamId = (UInt32Tag)obj.FindFirstTag(TagId.ImageStream); int x = rect.Value[0]; int y = rect.Value[1]; int w = rect.Value[2]; int h = rect.Value[3]; ushort imageId = (ushort)streamId.Value; ImageStreamObject imageObj = (ImageStreamObject)book.FindObject(imageId); string type = ImageObject.getImageTypeAsString(imageObj.Contents); MemoryStream memStream = new MemoryStream(imageObj.Data); Bitmap image = new Bitmap(memStream); ImageInfo info = new ImageInfo(); info.image = image; info.position = new Rectangle(x, y, w, h); // @@IMAGENAME@@ will be replaced during save with the name of the file info.name = "@@IMAGENAME@@_" + (images.Count + 1); info.type = type; images.Add(info); handleImage(info); }
private void ConnectPageTree(BBeB book) { Debug.WriteLineIf(s_bDebugMode, "Connecting page tree"); PageTreeObject pageTree = (PageTreeObject)book.FindFirstObject(typeof(PageTreeObject)); if (pageTree == null) { throw new InvalidBookException("Couldn't find the required PageTree object"); } UInt32ArrayTag pageListTag = (UInt32ArrayTag)pageTree.FindFirstTag(TagId.PageList); if (pageListTag == null) { throw new InvalidBookException("Couldn't find the required PageList tag"); } foreach (uint id in pageListTag.Value) { PageObject page = (PageObject)book.FindObject((ushort)id); if (page == null) { throw new InvalidBookException("Can't find page id " + id); } pageTree.Pages.Add(page); } }
private void SerializeHeader(BBeB book, BBeBinaryWriter writer) { BBeBHeader header = book.Header; TocObject tocObject = (TocObject)book.FindObject((ushort)header.dwTocObjectId); if (tocObject == null) { throw new InvalidBookException("Can't find the TOC object"); } writer.Write(header.signature); writer.Write(header.wVersion); writer.Write(header.wPseudoEncByte); writer.Write(header.dwRootObjectId); writer.Write(header.NumberOfObjects); m_dwIndexOffsetVal = writer.Position; writer.Write(header.ObjectIndexOffset); writer.Write(header.dwUnknown1); writer.Write(header.byBindingDir); writer.Write(header.byPadding1); writer.Write(header.wDPI); writer.Write(header.wPadding2); writer.Write(header.wScreenWidth); writer.Write(header.wScreenHeight); writer.Write(header.byColorDepth); writer.Write(header.byPadding3); writer.Write(header.byUnkonwn2); writer.Write(header.dwTocObjectId); writer.WriteStreamOffsetReference(tocObject); // This may seem a little wasteful as we actually serialize the MetaData object twice // Once here and onces when we actualy write it to the stream, however we need to set // the compressed size in the header and we can only do it by compressing it first. // Really we should store the compressed byte stream and just save that out // but its not very big so the overhead is quite small { MemoryStream mem = new MemoryStream(); BinaryWriter sw = new BinaryWriter(mem); header.wDocInfoCompSize = (ushort)(SerializeMetaData(book.MetaData, sw) + 4); } writer.Write(header.wDocInfoCompSize); Debug.Assert(writer.Position == 0x4E); if (header.wVersion >= 800) { writer.Write(header.wThumbnailFlags); writer.Write(header.dwThumbSize); Debug.Assert(writer.Position == 0x54); } }
private void ConnectBlock(BlockObject block, BBeB book) { UInt32Tag linkTag = (UInt32Tag)block.FindFirstTag(TagId.Link); if (linkTag == null) { throw new InvalidBookException("Can't find link for block " + block.ID); } block.LinkObj = book.FindObject((ushort)linkTag.Value); if (block.LinkObj == null) { throw new InvalidBookException("Can't find object id " + linkTag.Value); } }
private void ConnectText(TextObject text, BBeB book) { UInt32Tag linkTag = (UInt32Tag)text.FindFirstTag(TagId.Link); if (linkTag == null) { throw new InvalidBookException("Can't find link for block " + text.ID); } BBeBObject LinkObj = book.FindObject((ushort)linkTag.Value); if (LinkObj == null) { throw new InvalidBookException("Can't find object id " + linkTag.Value); } }