File: Ctrl_ColumnDef.java

package info (click to toggle)
h2orestart 0.7.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,168 kB
  • sloc: java: 21,845; makefile: 36; xml: 19
file content (259 lines) | stat: -rw-r--r-- 9,195 bytes parent folder | download
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* 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.paragraph;

import java.util.logging.Level;
import java.util.logging.Logger;

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

import HwpDoc.IContext;
import HwpDoc.Exception.NotImplementedException;
import HwpDoc.HwpElement.HwpRecordTypes.LineStyle2;

public class Ctrl_ColumnDef extends Ctrl {
	private static final Logger log = Logger.getLogger(Ctrl_ColumnDef.class.getName());

	private int size;
	
	public int    	    attr;
	public short        colCount;
	public boolean      sameSz;
	public short        sameGap;
	public short[]      colSzWidths;
	public short[]      colSzGaps;
	public LineStyle2   colLineStyle;
	public byte         colLineWidth;
	public int          colLineColor;

	public Ctrl_ColumnDef(String ctrlId) {
	    super(ctrlId);
	}
	
	public Ctrl_ColumnDef(String ctrlId, int size, byte[] buf, int off, int version) {
		super(ctrlId);
		
		int offset = off;
		// 속성의 bit 0-15(표 139참조)
		short attrLowBits	= (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
		offset += 2;
		// 단 사이 간격
		sameGap				= (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
		offset += 2;
		
		colCount          	= (short) (attrLowBits>>2 & 0xFF);
		sameSz              = (attrLowBits>>12 & 0x1) == 0x1; 
		// 단 너비가 동일하지 않으면, 단의 개수만큼 단의 폭
		if (!sameSz) {
		    colSzWidths = new short[colCount];
		    colSzGaps = new short[colCount-1];
			for(int i=0;i<colCount;i++) {
			    colSzWidths[i]		= (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
				offset += 2;
				if (i<colCount-1) {
				    colSzGaps[i]   = (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
	                offset += 2;
				}
			}
		}
		// 속성의 bit 16-32(표 139 참조)
		short attrHighBits	= (short) (buf[offset+1]<<8&0xFF00 | buf[offset]&0x00FF);
		offset += 2;
		// 단 구분선 종류(테두리/배경이 테두리 선 종류 참조)
		colLineStyle		= LineStyle2.from(buf[offset++]);
		// 단 구분선 굵기(테두리/배경이 테두리 선 굵기 참조)
		colLineWidth		= buf[offset++];
		// 단 구분선 굵기(테두리/배경이 테두리 선 굵기 참조)
        colLineColor        = buf[offset+3]<<24&0xFF000000 | buf[offset]<<16&0x00FF0000 | buf[offset+1]<<8&0x0000FF00 | buf[offset+2]&0x000000FF;
		offset += 4;
		attr 				= attrHighBits<<16 | attrLowBits;
		
		log.fine("                                                  " + toString());

		this.size = offset-off;
		this.fullfilled = true;
		
		log.finest(toString());
	}
	
	public Ctrl_ColumnDef(String ctrlId, Node node, int version, IContext context) throws NotImplementedException {
        super(ctrlId);
        
        // 초기값
        colLineStyle = LineStyle2.NONE;
        
        NamedNodeMap attributes = node.getAttributes();
        
        switch(attributes.getNamedItem("type").getNodeValue()) {
        case "NEWSPAPER":
        case "BALANCED_NEWSPAPER":
        case "PARALLEL":
            break;
        default:
        	if (log.isLoggable(Level.FINE)) {
        		throw new NotImplementedException("Ctrl_ColumnDef");
        	}
        }
        
        switch(attributes.getNamedItem("layout").getNodeValue()) {
        case "LEFT":
        case "RIGHT":
        case "MIRROR":
            break;
        default:
        	if (log.isLoggable(Level.FINE)) {
        		throw new NotImplementedException("Ctrl_ColumnDef");
        	}
        }

        String numStr = attributes.getNamedItem("colCount").getNodeValue();
        colCount = (short) Integer.parseInt(numStr);

        switch(attributes.getNamedItem("sameSz").getNodeValue()) {
        case "0":
            sameSz = false;    break;
        case "1":
            sameSz = true;     break;
        }

        // attributes.getNamedItem("sameGap").getNodeValue()
        if (!sameSz) {
            colSzWidths = new short[colCount];
            colSzGaps = new short[colCount];
        }
        
        int colSzIdx = 0;
        NodeList nodeList = node.getChildNodes();
        for (int i=0; i<nodeList.getLength(); i++) {
            Node child = nodeList.item(i);
            
            switch(child.getNodeName()) {
            case "hp:colLine":
                {
                    NamedNodeMap childAttrs = child.getAttributes();
                    colLineStyle = LineStyle2.valueOf(childAttrs.getNamedItem("type").getNodeValue());

                    switch(childAttrs.getNamedItem("width").getNodeValue()) {
                    case "0.1":
                    case "0.1 mm":
                        colLineWidth = 0; break;
                    case "0.12":
                    case "0.12 mm":
                        colLineWidth = 1; break;
                    case "0.15":
                    case "0.15 mm":
                        colLineWidth = 2; break;
                    case "0.2":
                    case "0.2 mm":
                        colLineWidth = 3; break;
                    case "0.25":
                    case "0.25 mm":
                        colLineWidth = 4; break;
                    case "0.3":
                    case "0.3 mm":
                        colLineWidth = 5; break;
                    case "0.4":
                    case "0.4 mm":
                        colLineWidth = 6; break;
                    case "0.5":
                    case "0.5 mm":
                        colLineWidth = 7; break;
                    case "0.6":
                    case "0.6 mm":
                        colLineWidth = 8; break;
                    case "0.7":
                    case "0.7 mm":
                        colLineWidth = 9; break;
                    case "1.0":
                    case "1.0 mm":
                        colLineWidth = 10; break;
                    case "1.5":
                    case "1.5 mm":
                        colLineWidth = 11; break;
                    case "2.0":
                    case "2.0 mm":
                        colLineWidth = 12; break;
                    case "3.0":
                    case "3.0 mm":
                        colLineWidth = 13; break;
                    case "4.0":
                    case "4.0 mm":
                        colLineWidth = 14; break;
                    case "5.0":
                    case "5.0 mm":
                        colLineWidth = 15; break;
                    }

                    colLineColor = 0x000000;
                    numStr = childAttrs.getNamedItem("color").getNodeValue();
                    if (!numStr.equals("NONE")) {
                        numStr = numStr.replaceAll("#",  "");
                        colLineColor = Integer.parseInt(numStr, 16);
                    }
                }
                break;
            case "hp:colSz":
                {
                    NamedNodeMap childAttrs = child.getAttributes();
                    
                    numStr = childAttrs.getNamedItem("width").getNodeValue();
                    colSzWidths[colSzIdx] = (short) Integer.parseInt(numStr);

                    numStr = childAttrs.getNamedItem("gap").getNodeValue();
                    colSzGaps[colSzIdx] = (short) Integer.parseInt(numStr);
                    
                    colSzIdx++;
                }
                break;
            default:
                log.fine(child.getNodeName() + "," + child.getNodeValue());
                if (log.isLoggable(Level.FINE)) {
                    throw new NotImplementedException("Ctrl_ColumnDef");
                }
                break;
            }
        }
        this.fullfilled = true;
    }

    public String toString() {
		StringBuffer strb = new StringBuffer();
		strb.append("CTRL("+ctrlId+")")
			.append("=속성:"+Integer.toBinaryString(attr))
			.append(",단개수:"+colCount)
			.append(",단간격:"+sameGap);
		if (colSzWidths!=null) {
			for(int i=0;i<colSzWidths.length;i++) {
				strb.append(",너비"+i+":"+colSzWidths[i]);
			}
		}
		strb.append(",구분선종류:"+colLineStyle)
			.append(",구분선굵기:"+colLineWidth)
			.append(",구분선색상:"+colLineColor);
		return strb.toString();
	}

	public int getSize() {
		return size;
	}
}