public static HwpV3DocumentInformation Create(BinaryReader reader) { HwpV3DocumentInformation result = new HwpV3DocumentInformation(); // 커서 줄 result.CursorLine = reader.ReadWord(); // 커서 칸 result.CursorColumn = reader.ReadWord(); // 용지 종류 result.PaperSize = reader.ReadByte(); // 용지 방향 result.PaperOrientation = reader.ReadByte(); // 용지 길이 result.PaperHeight = reader.ReadHUnit(); // 용지 너비 result.PaperWidth = reader.ReadHUnit(); // 위쪽 여백 result.TopMargin = reader.ReadHUnit(); // 아래쪽 여백 result.BottomMargin = reader.ReadHUnit(); // 왼쪽 여백 result.LeftMargin = reader.ReadHUnit(); // 오른쪽 여백 result.RightMargin = reader.ReadHUnit(); // 머리말 길이 result.HeaderHeight = reader.ReadHUnit(); // 꼬리말 길이 result.FooterHeight = reader.ReadHUnit(); // 제본 여백 result.BindingMargin = reader.ReadHUnit(); // 문서 보호 result.Protection = reader.ReadDWord(); // 예약 result.Reserved = reader.ReadWord(); // 쪽 번호 연결 result.ContinuousPageNo = reader.ReadByte(); // 각주 번호 연결 result.ContinuousFootnoteNo = reader.ReadByte(); // 연결 인쇄 파일 result.LinkedPrintingFile = reader.ReadKCharString(40); // 덧붙이는 말 result.Comments = reader.ReadKCharString(24); // 암호 여부 result.PasswordProtected = reader.ReadWord(); // 시작 페이지 번호 result.StartPageNo = reader.ReadWord(); // 각주 시작 번호 result.StartFootnoteNo = reader.ReadWord(); // 각주 개수 result.FootnoteCount = reader.ReadWord(); // 각주 분리선과 본문 사이의 간격 result.FootnoteDividerTopMargin = reader.ReadHUnit(); // 각주와 본문 사이의 간격 result.FootnoteTopMargin = reader.ReadHUnit(); // 각주와 각주 사이의 간격 result.FootnoteSpacing = reader.ReadHUnit(); // 각주 번호에 괄호 붙임 result.FootnoteNumberDecoration = reader.ReadEChar(); // 각주 분리선 너비 result.FootnoteDividerWidth = reader.ReadByte(); // 테두리 간격 result.BorderSpacing = reader.ReadHUnitArray(4); // 테두리 종류 result.BorderType = reader.ReadWord(); // 빈 줄 감춤 result.HideEmptyLine = reader.ReadByte(); // 틀 옮김 result.ShapeMoving = reader.ReadByte(); // 압축 result.Compressed = reader.ReadByte(); // Sub Revision result.SubRevision = reader.ReadByte(); // 정보 블록 길이 result.InformationBlockLength = reader.ReadWord(); return(result); }
public static HwpV3DocumentInformationBlockCollection Create(BinaryReader reader, HwpV3DocumentInformation docinfo) { HwpV3DocumentInformationBlockCollection results = new HwpV3DocumentInformationBlockCollection(); results.Length = docinfo.InformationBlockLength; using (MemoryStream memStream = new MemoryStream(reader.ReadBytes((int)results.Length))) using (BinaryReader subReader = new BinaryReader(memStream)) { while (memStream.Position < memStream.Length) { results.Add(HwpV3DocumentInformationBlock.Create(subReader)); } } return(results); }
public static HwpV3Document Load(string filePath) { HwpV3Document doc = new HwpV3Document(); using (Stream file = File.OpenRead(filePath)) using (BinaryReader reader = new BinaryReader(file)) { doc.Signature = HwpV3DocumentSignature.Create(reader); doc.Information = HwpV3DocumentInformation.Create(reader); doc.Summary = HwpV3DocumentSummary.Create(reader); doc.InformationBlocks = HwpV3DocumentInformationBlockCollection.Create(reader, doc.Information); bool requireDecompress = ((int)doc.Information.Compressed != 0); MemoryStream extractedFile = new MemoryStream(); byte[] buffer = new byte[64000]; int read = 0; if (requireDecompress) { using (DeflateStream deflateStream = new DeflateStream(file, CompressionMode.Decompress, true)) { while ((read = deflateStream.Read(buffer, 0, buffer.Length)) > 0) { extractedFile.Write(buffer, 0, read); } } } else { while ((read = file.Read(buffer, 0, buffer.Length)) > 0) { extractedFile.Write(buffer, 0, read); } } extractedFile.Seek(0L, SeekOrigin.Begin); using (extractedFile) using (BinaryReader subReader = new BinaryReader(extractedFile)) { doc.FontNames = HwpV3FontNames.Create(subReader); doc.Styles = HwpV3DocumentStyleCollection.Create(subReader); doc.Paragraph = HwpV3Paragraph.Create(subReader); doc.AdditionalBlock1 = HwpV3AdditionalBlock.Create(subReader); uint additionalBlock2Size = 0u; bool hasAdditionalBlock2 = false; BinaryReader target = (requireDecompress ? reader : subReader); target.BaseStream.Seek(-8, SeekOrigin.End); uint id = target.ReadDWord(); if (id == 0u) { additionalBlock2Size = target.ReadDWord(); if (additionalBlock2Size != 0u) { hasAdditionalBlock2 = true; } } if (hasAdditionalBlock2) { target.BaseStream.Position = target.BaseStream.Length - additionalBlock2Size; doc.AdditionalBlock2 = HwpV3AdditionalBlock.Create(reader); } } return(doc); } }