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 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 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); } }
/// <summary> /// Write the tag serialized data using the supplied writer. /// </summary> /// <remarks> /// This is a really KLUDGY routine. Even though it deals with primitive /// types it has knowledge of what those types mean. For example the UInt16ArrayTag /// doesn't have a length value written, but the UInt32ArrayTag does. This is /// a very brittle solution to this problem and needs to be fixed. The solution is /// to have a serialize method for each tag type (uggh) - so you see why I took /// this shortcut. /// </remarks> /// <param name="tag"></param> /// <param name="writer"></param> private static void SerializeTag(BBeBTag tag, BBeBinaryWriter writer) { ushort id = (ushort)(0xf500 + tag.Id); if (tag.GetType() == typeof(ByteTag)) { ByteTag t = (ByteTag)tag; writer.Write(id); writer.Write(t.Value); } else if (tag.GetType() == typeof(StreamTagGroup)) { StreamTagSerializer.Serialize(writer, (StreamTagGroup)tag); } else if (tag.GetType() == typeof(ByteArrayTag)) { ByteArrayTag t = (ByteArrayTag)tag; if (t.Id == TagId.StreamStart) { byte[] data = t.Value; writer.Write(BBeBLib.TagId.StreamSize); writer.Write((uint)data.Length); writer.Write(id); writer.Write(data); writer.Write(BBeBLib.TagId.StreamEnd); } else { writer.Write(id); writer.Write(t.Value); } } else if (tag.GetType() == typeof(UInt16Tag)) { UInt16Tag t = (UInt16Tag)tag; writer.Write(id); writer.Write(t.Value); } else if (tag.GetType() == typeof(UInt16ArrayTag)) { UInt16ArrayTag t = (UInt16ArrayTag)tag; writer.Write(id); foreach (ushort val in t.Value) { writer.Write(val); } } else if (tag.GetType() == typeof(UInt32Tag)) { UInt32Tag t = (UInt32Tag)tag; // StreamSize is written out by the StreamStart tag as the data may be compressed if (t.Id != TagId.StreamSize) { writer.Write(id); // Zero byte tags (but have hardcoded data associated with them if (t.Id != TagId.BaseButtonStart && t.Id != TagId.FocusinButtonStart && t.Id != TagId.PushButtonStart && t.Id != TagId.UpButtonStart) { writer.Write(t.Value); } } } else if (tag.GetType() == typeof(UInt32ArrayTag)) { UInt32ArrayTag t = (UInt32ArrayTag)tag; writer.Write(id); // JumpTo doesn't have a length set and is hardcoded to 2! if (t.Id != TagId.JumpTo) { writer.Write((ushort)t.Value.Length); } foreach (uint val in t.Value) { writer.Write(val); } } else if (tag.GetType() == typeof(StringTag)) { StringTag t = (StringTag)tag; writer.Write(id); writer.Write(t.Value); } else if (tag.GetType() == typeof(MessageTag)) { MessageTag t = (MessageTag)tag; writer.Write(id); writer.Write((ushort)t.parameters); byte[] data = System.Text.Encoding.Unicode.GetBytes(t.param1); writer.Write((ushort)data.Length); writer.Write(data); data = System.Text.Encoding.Unicode.GetBytes(t.param2); writer.Write((ushort)data.Length); writer.Write(data); } else if (tag.GetType() == typeof(EmpDotsCodeTag)) { EmpDotsCodeTag t = (EmpDotsCodeTag)tag; writer.Write(id); writer.Write((uint)t.Value); SerializeTag(t.FontFace, writer); writer.Write(t.DotsCode); } else if (tag.GetType() == typeof(IDOnlyTag)) { IDOnlyTag t = (IDOnlyTag)tag; if (t.Id != TagId.StreamEnd) { writer.Write(id); } } else if (tag.GetType() == typeof(BBeBTag)) { BBeBTag t = (BBeBTag)tag; if (t.Id != TagId.StreamEnd) { writer.Write(id); } } else { Debug.Assert(false, "Unknown tag type: " + tag.GetType().ToString()); } }