/// <summary> /// Resolves the zone offsets for the location and text /// </summary> internal void ResolveOffsets(TextZone parent, TextZone sibling) { if (parent == null && sibling == null) { return; } if (sibling == null) { X += parent.Rectangle.Right; Y = parent.Rectangle.Top - (Y + Height); TextOffset += parent.TextOffset; } else { if (sibling.ZoneType == ZoneTypes.Page || sibling.ZoneType == ZoneTypes.Paragraph || sibling.ZoneType == ZoneTypes.Line) { X += sibling.Rectangle.Right; Y = sibling.Rectangle.Bottom - (Y + Height); } else if (sibling.ZoneType == ZoneTypes.Column || sibling.ZoneType == ZoneTypes.Word || sibling.ZoneType == ZoneTypes.Character) { X += sibling.Rectangle.Left; Y += sibling.Rectangle.Bottom; } TextOffset += sibling.TextOffset + sibling.TextLength; } }
public TextZone(IDjvuReader reader, TextZone parent, TextZone sibling, TextChunk chunkParent) { Parent = parent; ChunkParent = chunkParent; DecodeZoneData(reader, sibling, chunkParent); }
/// <summary> /// Decodes the data for the zone /// </summary> /// <param name="reader"></param> internal void DecodeZoneData(IDjvuReader reader, TextZone sibling, TextChunk chunkParent) { ZoneType = (ZoneTypes)reader.ReadByte(); X = reader.ReadUInt16BigEndian() - 0x8000; Y = reader.ReadUInt16BigEndian() - 0x8000; Width = reader.ReadUInt16BigEndian() - 0x8000; Height = reader.ReadUInt16BigEndian() - 0x8000; TextOffset = reader.ReadUInt16BigEndian() - 0x8000; TextLength = reader.ReadInt24BigEndian(); ResolveOffsets(Parent, sibling); Rectangle = new Rectangle(X, Y, Width, Height); int childrenZones = reader.ReadInt24BigEndian(); List <TextZone> children = new List <TextZone>(); TextZone childrenSibling = null; for (int x = 0; x < childrenZones; x++) { TextZone newZone = new TextZone(reader, this, childrenSibling, chunkParent); childrenSibling = newZone; children.Add(newZone); } Children = children.ToArray(); }
/// <summary> /// Reads the compressed text data /// </summary> internal void ReadCompressedTextData() { if (Length > 0) { using (IDjvuReader reader = GetTextDataReader(DataOffset)) { int length = (int)reader.ReadUInt24BigEndian(); byte[] textBytes = reader.ReadBytes(length); Text = Encoding.UTF8.GetString(textBytes); TextLength = _text.Length; Version = reader.ReadByte(); Zone = new TextZone(reader, null, null, this); } } _isDecoded = true; }