Documentation
¶
Overview ¶
Package hwp5 provides a parser for HWP 5.x binary documents.
Package hwp5 provides a parser for HWP 5.x binary documents.
Index ¶
- Constants
- func DecodeUTF16LE(data []byte) string
- func DecompressStream(data []byte) ([]byte, error)
- func TagName(tagID uint16) string
- type BinDataInfo
- type CharShape
- type ControlInfo
- type DocInfo
- type DocumentProperties
- type FileHeader
- func (h *FileHeader) HasDRM() bool
- func (h *FileHeader) HasHistory() bool
- func (h *FileHeader) HasScript() bool
- func (h *FileHeader) HasSignature() bool
- func (h *FileHeader) HasXMLTemplate() bool
- func (h *FileHeader) IsCCL() bool
- func (h *FileHeader) IsCertEncrypted() bool
- func (h *FileHeader) IsCompressed() bool
- func (h *FileHeader) IsDistributable() bool
- func (h *FileHeader) IsEncrypted() bool
- func (h *FileHeader) IsMobileOptimized() bool
- type IDMappings
- type Image
- type ParaShape
- type Paragraph
- type Parser
- type Record
- type RecordHeader
- type RecordReader
- type Section
- type SectionParser
- type Style
- type Table
- type TableCell
- type TextExtractor
- type Version
Constants ¶
const ( // FileHeader 시그니처 Signature = "HWP Document File" // FileHeader 크기 (고정) FileHeaderSize = 256 // 속성 플래그 비트 FlagCompressed uint32 = 1 << 0 // 압축 여부 FlagEncrypted uint32 = 1 << 1 // 암호화 여부 FlagDistributable uint32 = 1 << 2 // 배포용 문서 FlagScript uint32 = 1 << 3 // 스크립트 저장 FlagDRM uint32 = 1 << 4 // DRM 보안 FlagXMLTemplate uint32 = 1 << 5 // XMLTemplate 저장 FlagHistory uint32 = 1 << 6 // 문서 이력 관리 FlagSignature uint32 = 1 << 7 // 전자 서명 FlagCertEncrypt uint32 = 1 << 8 // 공인 인증서 암호화 FlagSignatureReserv uint32 = 1 << 9 // 전자 서명 예비 FlagCertDRM uint32 = 1 << 10 // 공인 인증서 DRM FlagCCL uint32 = 1 << 11 // CCL 문서 FlagMobile uint32 = 1 << 12 // 모바일 최적화 )
const ( StreamFileHeader = "FileHeader" StreamDocInfo = "DocInfo" StreamBodyText = "BodyText" StreamViewText = "ViewText" StreamSummaryInfo = "\x05HwpSummaryInformation" StreamBinData = "BinData" StreamPrvText = "PrvText" StreamPrvImage = "PrvImage" StreamDocOptions = "DocOptions" StreamScripts = "Scripts" StreamXMLTemplate = "XMLTemplate" StreamDocHistory = "DocHistory" )
스트림 이름
const ( // DocInfo 레코드 태그 (0x0010 ~ 0x003F) TagDocumentProperties uint16 = 0x0010 // 문서 속성 TagIDMappings uint16 = 0x0011 // ID 매핑 테이블 크기 TagBinData uint16 = 0x0012 // 바이너리 데이터 TagFaceName uint16 = 0x0013 // 글꼴 TagBorderFill uint16 = 0x0014 // 테두리/배경 TagCharShape uint16 = 0x0015 // 글자 모양 TagTabDef uint16 = 0x0016 // 탭 정의 TagNumbering uint16 = 0x0017 // 문단 번호 TagBullet uint16 = 0x0018 // 글머리표 TagParaShape uint16 = 0x0019 // 문단 모양 TagStyle uint16 = 0x001A // 스타일 TagDocData uint16 = 0x001B // 문서 데이터 TagDistributeDocData uint16 = 0x001C // 배포용 문서 데이터 TagCompatibleDocument uint16 = 0x001E // 호환 문서 TagLayoutCompatible uint16 = 0x001F // 레이아웃 호환 TagTrackChange uint16 = 0x0020 // 변경 내역 추적 TagMemoShape uint16 = 0x0022 // 메모 모양 TagForbiddenChar uint16 = 0x0023 // 금칙 문자 TagTrackChange2 uint16 = 0x0024 // 변경 내역 2 TagTrackChangeAuthor uint16 = 0x0025 // 변경 내역 작성자 // Section/Body 레코드 태그 (0x0040 ~ 0x007F) TagParaHeader uint16 = 0x0042 // 문단 헤더 TagParaText uint16 = 0x0043 // 문단 텍스트 TagParaCharShape uint16 = 0x0044 // 문단 글자 모양 TagParaLineSeg uint16 = 0x0045 // 문단 레이아웃 TagParaRangeTag uint16 = 0x0046 // 문단 범위 태그 TagCtrlHeader uint16 = 0x0047 // 컨트롤 헤더 TagListHeader uint16 = 0x0048 // 리스트 헤더 TagPageDef uint16 = 0x0049 // 페이지 정의 TagFootnoteShape uint16 = 0x004A // 각주 모양 TagPageBorderFill uint16 = 0x004B // 페이지 테두리/배경 TagShapeComponent uint16 = 0x004C // 그리기 개체 TagTable uint16 = 0x004D // 표 TagShapeLine uint16 = 0x004E // 선 TagShapeRectangle uint16 = 0x004F // 사각형 TagShapeEllipse uint16 = 0x0050 // 타원 TagShapeArc uint16 = 0x0051 // 호 TagShapePolygon uint16 = 0x0052 // 다각형 TagShapeCurve uint16 = 0x0053 // 곡선 TagShapeOLE uint16 = 0x0054 // OLE TagShapePicture uint16 = 0x0055 // 그림 TagShapeContainer uint16 = 0x0056 // 컨테이너 TagCtrlData uint16 = 0x0057 // 컨트롤 데이터 TagEqEdit uint16 = 0x0058 // 수식 TagCtrlFormField uint16 = 0x005B // 양식 컨트롤 TagMemoList uint16 = 0x005C // 메모 리스트 TagCellListHeader uint16 = 0x005E // 셀 리스트 헤더 TagChartData uint16 = 0x0060 // 차트 데이터 TagVideoData uint16 = 0x0062 // 비디오 데이터 )
레코드 태그 ID (HWPTAG_*) 참조: HWP 5.0 명세서 4장 레코드 구조
const ( CtrlSection = "secd" // 구역 정의 CtrlColumn = "cold" // 단 정의 CtrlHeader = "head" // 머리말 CtrlFootnote = "fn " // 각주 CtrlEndnote = "en " // 미주 CtrlAutoNumber = "atno" // 자동 번호 CtrlNewNumber = "nwno" // 새 번호 CtrlPageHide = "pghd" // 페이지 숨김 CtrlPageOddEven = "pgct" // 홀/짝수 페이지 CtrlPageNumber = "pgno" // 페이지 번호 CtrlIndexMark = "idxm" // 찾아보기 표식 CtrlBookmark = "bokm" // 책갈피 CtrlOverlapping = "tcps" // 글자 겹침 CtrlHiddenComment = "tdut" // 숨은 설명 CtrlTable = "tbl " // 표 CtrlGSO = "gso " // 그리기 개체 CtrlEquation = "eqed" // 수식 CtrlFieldBegin = "%beg" // 필드 시작 CtrlFieldEnd = "%end" // 필드 끝 )
컨트롤 타입 ID (4바이트 문자열)
const ( CharLine = 0x0000 // 줄 나눔 CharPara = 0x000D // 문단 나눔 CharTab = 0x0009 // 탭 CharDrawingObj = 0x000B // 그리기 개체/표 CharInlineStart = 0x000C // 인라인 시작 CharFieldStart = 0x0003 // 필드 시작 CharFieldEnd = 0x0004 // 필드 끝 CharBookmark = 0x0005 // 책갈피 CharTitleMark = 0x0006 // 제목 표시 CharHyphen = 0x001E // 하이픈 CharNBSP = 0x001F // 줄바꿈 방지 공백 CharFixedWidthNBSP = 0x0018 // 고정폭 빈칸 CharExtChar = 0x0014 // 확장 문자 )
특수 문자 코드
Variables ¶
This section is empty.
Functions ¶
func DecodeUTF16LE ¶
DecodeUTF16LE decodes UTF-16LE bytes to string.
func DecompressStream ¶
DecompressStream decompresses zlib/deflate-compressed stream data. HWP 5.x uses raw deflate (no zlib header) for stream compression.
Types ¶
type BinDataInfo ¶
type BinDataInfo struct {
Type uint16 // 바이너리 데이터 타입
AbsPath string // 절대 경로
RelPath string // 상대 경로
BinDataID uint16 // BinData 스토리지 내 ID
Extension string // 확장자
}
BinDataInfo는 바이너리 데이터 정보 (HWPTAG_BIN_DATA)
func (*BinDataInfo) GetBinDataPath ¶
func (info *BinDataInfo) GetBinDataPath() string
GetBinDataPath returns the path to binary data in the BinData storage.
type CharShape ¶
type CharShape struct {
FaceID [7]uint16 // 언어별 글꼴 ID
Ratios [7]uint8 // 언어별 장평
Spacings [7]int8 // 언어별 자간
RelSizes [7]uint8 // 언어별 상대 크기
Offsets [7]int8 // 언어별 오프셋
Height int32 // 기준 크기 (100분의 1pt)
Attributes uint32 // 속성 플래그
ShadowGap1 int8 // 그림자 간격 1
ShadowGap2 int8 // 그림자 간격 2
TextColor uint32 // 글자 색
UnderColor uint32 // 밑줄 색
ShadeColor uint32 // 음영 색
ShadowColor uint32 // 그림자 색
BorderFillID uint16 // 테두리/배경 ID
StrikeColor uint32 // 취소선 색
}
CharShape는 글자 모양 (HWPTAG_CHAR_SHAPE)
func (*CharShape) GetFontSizePt ¶
GetFontSizePt returns the font size in points.
func (*CharShape) IsStrikeout ¶
IsStrikeout returns true if the character shape has strikeout.
func (*CharShape) IsUnderline ¶
IsUnderline returns true if the character shape has underline.
type ControlInfo ¶
ControlInfo represents information about an inline control character.
type DocInfo ¶
type DocInfo struct {
Properties *DocumentProperties
IDMappings *IDMappings
BinDataList []*BinDataInfo
FaceNames []string
CharShapes []*CharShape
ParaShapes []*ParaShape
Styles []*Style
}
DocInfo는 문서 정보 스트림에서 파싱된 데이터
func ParseDocInfo ¶
ParseDocInfo parses the DocInfo stream.
type DocumentProperties ¶
type DocumentProperties struct {
SectionCount uint16 // 구역 개수
PageStartNum uint16 // 시작 페이지 번호
FootnoteStart uint16 // 각주 시작 번호
EndnoteStart uint16 // 미주 시작 번호
PictureStart uint16 // 그림 시작 번호
TableStart uint16 // 표 시작 번호
EquationStart uint16 // 수식 시작 번호
ListIDCount uint32 // 리스트 ID 개수
ParaIDCount uint32 // 문단 ID 개수
CharUnitLoc uint32 // 글자 단위 위치
}
DocumentProperties는 문서 속성 (HWPTAG_DOCUMENT_PROPERTIES)
type FileHeader ¶
type FileHeader struct {
Signature [32]byte // 파일 시그니처 "HWP Document File"
Version Version // 파일 버전
Flags uint32 // 속성 플래그
LicenseInfo [216]byte // 예약 영역
}
FileHeader는 HWP 5.x 파일 헤더 구조체 참조: HWP 5.0 명세서 2.1 파일 인식 정보
func ParseFileHeader ¶
func ParseFileHeader(data []byte) (*FileHeader, error)
ParseFileHeader parses the FileHeader from raw bytes.
func (*FileHeader) HasDRM ¶
func (h *FileHeader) HasDRM() bool
HasDRM returns true if the document has DRM protection.
func (*FileHeader) HasHistory ¶
func (h *FileHeader) HasHistory() bool
HasHistory returns true if the document has revision history.
func (*FileHeader) HasScript ¶
func (h *FileHeader) HasScript() bool
HasScript returns true if the document contains scripts.
func (*FileHeader) HasSignature ¶
func (h *FileHeader) HasSignature() bool
HasSignature returns true if the document has a digital signature.
func (*FileHeader) HasXMLTemplate ¶
func (h *FileHeader) HasXMLTemplate() bool
HasXMLTemplate returns true if the document contains XML templates.
func (*FileHeader) IsCCL ¶
func (h *FileHeader) IsCCL() bool
IsCCL returns true if this is a CCL document.
func (*FileHeader) IsCertEncrypted ¶
func (h *FileHeader) IsCertEncrypted() bool
IsCertEncrypted returns true if encrypted with certificate.
func (*FileHeader) IsCompressed ¶
func (h *FileHeader) IsCompressed() bool
IsCompressed returns true if the document is compressed.
func (*FileHeader) IsDistributable ¶
func (h *FileHeader) IsDistributable() bool
IsDistributable returns true if this is a distribution document.
func (*FileHeader) IsEncrypted ¶
func (h *FileHeader) IsEncrypted() bool
IsEncrypted returns true if the document is encrypted.
func (*FileHeader) IsMobileOptimized ¶
func (h *FileHeader) IsMobileOptimized() bool
IsMobileOptimized returns true if optimized for mobile.
type IDMappings ¶
type IDMappings struct {
BinDataCount int32
FaceNameKorCount int32
FaceNameEngCount int32
FaceNameHanCount int32
FaceNameJpnCount int32
FaceNameOtherCount int32
FaceNameSymCount int32
FaceNameUserCount int32
BorderFillCount int32
CharShapeCount int32
TabDefCount int32
NumberingCount int32
BulletCount int32
ParaShapeCount int32
StyleCount int32
MemoShapeCount int32
TrackChangeCount int32
TrackChangeAuthorCount int32
}
IDMappings는 ID 매핑 테이블 크기 (HWPTAG_ID_MAPPINGS)
type Image ¶
type Image struct {
BinDataID uint16
BorderColor uint32
Width int32
Height int32
XOffset int32
YOffset int32
}
Image는 이미지 데이터
type ParaShape ¶
type ParaShape struct {
Attributes1 uint32 // 속성 1
LeftMargin int32 // 왼쪽 여백
RightMargin int32 // 오른쪽 여백
Indent int32 // 들여쓰기
ParaSpaceBefore int32 // 문단 위 간격
ParaSpaceAfter int32 // 문단 아래 간격
LineSpacing int32 // 줄 간격
TabDefID uint16 // 탭 정의 ID
NumberingID uint16 // 문단 번호 ID
BorderFillID uint16 // 테두리/배경 ID
BorderOffset1 int16 // 테두리 왼쪽 오프셋
BorderOffset2 int16 // 테두리 오른쪽 오프셋
BorderOffset3 int16 // 테두리 위 오프셋
BorderOffset4 int16 // 테두리 아래 오프셋
Attributes2 uint32 // 속성 2
Attributes3 uint32 // 속성 3
LineWrap uint32 // 줄 나눔 기준
AutoSpacing uint32 // 자동 줄 간격
}
ParaShape는 문단 모양 (HWPTAG_PARA_SHAPE)
type Paragraph ¶
type Paragraph struct {
Text string
Controls []ControlInfo
CharShapeID uint16
ParaShapeID uint16
StyleID uint16
DivisionType uint8
CharShapeCount uint16
RangeTagCount uint16
LineAlignCount uint16
InstanceID uint32
}
Paragraph는 문단 데이터
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses HWP 5.x binary documents.
func (*Parser) ExtractImages ¶
func (p *Parser) ExtractImages(dir string) ([]ir.ImageBlock, error)
ExtractImages extracts all images to the specified directory.
func (*Parser) GetDocInfo ¶
GetDocInfo returns the parsed document info.
func (*Parser) GetHeader ¶
func (p *Parser) GetHeader() *FileHeader
GetHeader returns the parsed file header.
func (*Parser) GetVersion ¶
GetVersion returns the HWP version string.
func (*Parser) IsCompressed ¶
IsCompressed returns true if the document is compressed.
type Record ¶
type Record struct {
TagID uint16 // 레코드 종류 (10비트)
Level uint16 // 논리적 계층 (10비트)
Size uint32 // 데이터 크기
Data []byte // 레코드 데이터
}
Record는 HWP 5.x 레코드 구조체 참조: HWP 5.0 명세서 2.3 레코드 구조
type RecordHeader ¶
type RecordHeader uint32
RecordHeader는 4바이트 레코드 헤더 구조: [TagID:10비트][Level:10비트][Size:12비트]
func ParseRecordHeader ¶
func ParseRecordHeader(data []byte) RecordHeader
ParseRecordHeader parses the 4-byte record header.
func (RecordHeader) Level ¶
func (h RecordHeader) Level() uint16
Level returns the nesting level (10 bits).
func (RecordHeader) Size ¶
func (h RecordHeader) Size() uint16
Size returns the data size (12 bits). If size is 0xFFF (4095), the actual size follows in the next 4 bytes.
func (RecordHeader) TagID ¶
func (h RecordHeader) TagID() uint16
TagID returns the tag ID (10 bits).
type RecordReader ¶
type RecordReader struct {
// contains filtered or unexported fields
}
RecordReader reads records from a stream.
func NewRecordReader ¶
func NewRecordReader(data []byte) *RecordReader
NewRecordReader creates a new record reader from raw stream data.
func (*RecordReader) Read ¶
func (r *RecordReader) Read() (*Record, error)
Read reads the next record.
func (*RecordReader) ReadAll ¶
func (r *RecordReader) ReadAll() ([]*Record, error)
ReadAll reads all records from the stream.
type SectionParser ¶
type SectionParser struct {
// contains filtered or unexported fields
}
SectionParser parses Section streams.
func NewSectionParser ¶
func NewSectionParser(docInfo *DocInfo) *SectionParser
NewSectionParser creates a new section parser.
type Style ¶
type Style struct {
Name string // 스타일 이름
EngName string // 영문 스타일 이름
Type uint8 // 스타일 타입
NextStyleID uint8 // 다음 스타일 ID
LangID int16 // 언어 ID
ParaShapeID uint16 // 문단 모양 ID
CharShapeID uint16 // 글자 모양 ID
LockForm bool // 잠금 여부
}
Style은 스타일 정의 (HWPTAG_STYLE)
type Table ¶
type Table struct {
Rows int
Cols int
Cells [][]*TableCell
BorderFill uint16
CellSpacing int16
LeftMargin int16
RightMargin int16
TopMargin int16
BottomMargin int16
}
Table은 표 데이터
type TableCell ¶
type TableCell struct {
Row int
Col int
RowSpan int
ColSpan int
Width int
Height int
Paragraphs []*Paragraph
}
TableCell은 표 셀 데이터
func (*TableCell) GetCellText ¶
GetCellText returns the text content of a cell.
type TextExtractor ¶
type TextExtractor struct {
// contains filtered or unexported fields
}
TextExtractor extracts text from ParaText records.
func NewTextExtractor ¶
func NewTextExtractor() *TextExtractor
NewTextExtractor creates a new text extractor.
func (*TextExtractor) ExtractText ¶
func (te *TextExtractor) ExtractText(data []byte) string
ExtractText extracts text from ParaText record data. ParaText는 UTF-16LE로 인코딩된 텍스트와 컨트롤 문자를 포함.
func (*TextExtractor) ExtractTextWithControls ¶
func (te *TextExtractor) ExtractTextWithControls(data []byte) (string, []ControlInfo)
ExtractTextWithControls extracts text and control information.