Ejemplo n.º 1
0
        private void createDefaultAttributeObjects(ushort width, ushort height)
        {
            // Root Object
            BookAttrObject bookAttr = new BookAttrObject(GetNextObjId());

            bookAttr.createDefaultTags();
            m_Book.Objects.Add(bookAttr);
            m_Book.Header.dwRootObjectId = bookAttr.ID;

            // Create an empty table of contents.
            m_TocObject = new TocObject(GetNextObjId());
            m_Book.Objects.Add(m_TocObject);
            m_Book.Header.dwTocObjectId = m_TocObject.ID;

            m_MainBodyTextAttr = new TextAttrObject(GetNextObjId());
            m_MainBodyTextAttr.createDefaultTags(BlockAlignment.Left);
            m_Book.Objects.Add(m_MainBodyTextAttr);

            m_CenteredTextAttr = new TextAttrObject(GetNextObjId());
            m_CenteredTextAttr.createDefaultTags(BlockAlignment.Center);
            m_Book.Objects.Add(m_CenteredTextAttr);

            // Fill this one in later need id now for the BookAttrObject
            m_PageTree = new PageTreeObject(GetNextObjId());
            m_Book.Objects.Add(m_PageTree);
            bookAttr.Tags.Add(new UInt32Tag(TagId.ChildPageTree, m_PageTree.ID));

            m_PageAttr = new PageAttrObject(GetNextObjId());
            m_PageAttr.createDefaultTags();
            m_Book.Objects.Add(m_PageAttr);

            m_BlockAttr = new BlockAttrObject(GetNextObjId());
            m_BlockAttr.createDefaultTags(width, height);
            m_Book.Objects.Add(m_BlockAttr);
        }
Ejemplo n.º 2
0
        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);
            }
        }