File: HwpRecord_Style.java

package info (click to toggle)
h2orestart 0.7.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,168 kB
  • sloc: java: 21,845; makefile: 36; xml: 19
file content (129 lines) | stat: -rw-r--r-- 5,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright (C) 2023 ebandal
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 */
/* 본 제품은 한글과컴퓨터의 ᄒᆞᆫ글 문서 파일(.hwp) 공개 문서를 참고하여 개발하였습니다.
 * 개방형 워드프로세서 마크업 언어(OWPML) 문서 구조 KS X 6101:2018 문서를 참고하였습니다.
 * 작성자 : 반희수 ebandal@gmail.com  
 * 작성일 : 2022.10
 */
package HwpDoc.HwpElement;

import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import HwpDoc.HwpDocInfo;
import HwpDoc.Exception.HwpParseException;

public class HwpRecord_Style extends HwpRecord {
	private static final Logger log = Logger.getLogger(HwpRecord_Style.class.getName());
	private HwpDocInfo	parent;

	public String		name;				// 로컬 스타일 이름. 한글 윈도우에서는 한글 스타일 이름
	public String		engName;			// 영문 스타일 이름.
	public byte			type;				// 속성
	public byte			nextStyle;			// 다음 스타일 아이디 참조값
	public short		langId;				// 언어 아이디
	public int			paraShape;			// 문단 모양 아이디 참조값(문단 모양의 아이디 속성)
	public int			charShape;			// 글자 모양 아이디 참조값(글자 모양의 아이디 속성)
	public boolean		lockForm;			// 양식모드에서 style 보호하기
	
	HwpRecord_Style(int tagNum, int level, int size) {
		super(tagNum, level, size);
	}
	
	public HwpRecord_Style(HwpDocInfo docInfo, int tagNum, int level, int size, byte[] buf, int off, int version) throws HwpParseException {
		this(tagNum, level, size);
		this.parent = docInfo;

		int offset = off;
		int styleNameLen1 = (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF)*2;
		offset += 2;
		if (styleNameLen1 > 0) {
			name 		= new String(buf, offset, styleNameLen1, StandardCharsets.UTF_16LE);
			offset += styleNameLen1;
		}
		int styleNameLen2 = (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF)*2;
		offset += 2;
		if (styleNameLen2 > 0) {
			engName 	= new String(buf, offset, styleNameLen2, StandardCharsets.UTF_16LE);
			offset += styleNameLen2;
		}
		type 			= (byte) (buf[offset++]&0x00FF);
		nextStyle		= (byte) (buf[offset++]&0x00FF);
		
		langId 			= (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
		offset += 2;
		paraShape	 	= (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
		offset += 2;
		charShape	 	= (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
		offset += 2;
		
		log.fine("                                                  "
				+"ID="+(parent.styleList.size())
				+",스타일="+name
				+",스타일구분="+(type==0?"문단스타일":type==1?"글자스타일":"알수없음")
				+",문단모양ID="+paraShape
				+",글자모양ID="+charShape
				);
		
		if (offset-off-size!=0 && offset-off!=12+styleNameLen1+styleNameLen2) {
			log.fine("[TAG]=" + tag.toString() + ", size=" + size + ", but currentSize=" + (offset-off));
			dump(buf, off, size);
			throw new HwpParseException();
		}
	}

    public HwpRecord_Style(HwpDocInfo docInfo, Node node, int version) {
        super(HwpTag.HWPTAG_STYLE, 0, 0);
        this.parent = docInfo;

        NamedNodeMap attributes = node.getAttributes();
        
        // id값은 처리하지 않는다. List<HwpRecord_Style>에 순차적으로 추가한다.
        // String id = attributes.getNamedItem("id").getNodeValue();
        
        switch(attributes.getNamedItem("type").getNodeValue()) {
        case "PARA":
            type = 0;   break;
        case "CHAR":
            type = 1;   break;
        }

        name = attributes.getNamedItem("name").getNodeValue();
        engName = attributes.getNamedItem("engName").getNodeValue();
        
        String numStr = attributes.getNamedItem("paraPrIDRef").getNodeValue();
        paraShape = Integer.parseUnsignedInt(numStr);
        
        numStr = attributes.getNamedItem("charPrIDRef").getNodeValue();
        charShape = Integer.parseUnsignedInt(numStr);
        
        numStr = attributes.getNamedItem("nextStyleIDRef").getNodeValue();
        nextStyle = (byte) Integer.parseInt(numStr);
        
        numStr = attributes.getNamedItem("langID").getNodeValue();
        langId = (short) Integer.parseInt(numStr);
        
        switch(attributes.getNamedItem("lockForm").getNodeValue()) {
        case "0":
            lockForm = false;   break;
        case "1":
            lockForm = true;   break;
        }
    }
}