File: Ctrl_ShapeConnectLine.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 (175 lines) | stat: -rw-r--r-- 6,832 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
/* 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.ArrayList;
import java.util.List;
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;

public class Ctrl_ShapeConnectLine extends Ctrl_GeneralShape {
    private static final Logger log = Logger.getLogger(Ctrl_ShapeConnectLine.class.getName());
    private int size;

    public ConnectLineType type;       // 연결선 형식
    public ConnectPoint    startPt;    // 연결선 시작점 정보
    public ConnectPoint    endPt;      // 연결선 끝점 정보
    public List<Point>	controlPoints;

    public Ctrl_ShapeConnectLine(String ctrlId, int size, byte[] buf, int off, int version) {
        super(ctrlId, size, buf, off, version);
        this.size = offset-off;

        log.fine("                                                  " + toString());
    }

    public Ctrl_ShapeConnectLine(Ctrl_GeneralShape shape) {
        super(shape);

        this.size = shape.getSize();
    }

    public Ctrl_ShapeConnectLine(String ctrlId, Node node, int version, IContext context) throws NotImplementedException {
        super(ctrlId, node, version, context);

        NamedNodeMap attributes = node.getAttributes();
        if (attributes.getNamedItem("type")!=null) {
            type = ConnectLineType.valueOf(attributes.getNamedItem("type").getNodeValue());
        }
        
        String numStr;
        
        NodeList nodeList = node.getChildNodes();
        for (int i=nodeList.getLength()-1; i>=0; i--) {
            Node child = nodeList.item(i);
            switch(child.getNodeName()) {
            case "hp:startPt":    // 시작점
                {
                    NamedNodeMap childAttrs = child.getAttributes();
                    if (startPt==null) {
                    	startPt = new ConnectPoint();
                    }
                    numStr = childAttrs.getNamedItem("x").getNodeValue();
                    startPt.x = Integer.parseInt(numStr);
                    numStr = childAttrs.getNamedItem("y").getNodeValue();
                    startPt.y = Integer.parseInt(numStr);
                    numStr = childAttrs.getNamedItem("subjectIDRef").getNodeValue();
                    startPt.subjectIDRef = (short) Integer.parseInt(numStr);
                    numStr = childAttrs.getNamedItem("subjectIdx").getNodeValue();
                    startPt.subjectIdx = (short) Integer.parseInt(numStr);
                }
                node.removeChild(child);
                break;
            case "hp:endPt":      // 끝점
                {
                    NamedNodeMap childAttrs = child.getAttributes();
                    if (endPt==null) {
                    	endPt = new ConnectPoint();
                    }
                    numStr = childAttrs.getNamedItem("x").getNodeValue();
                    endPt.x = Integer.parseInt(numStr);
                    numStr = childAttrs.getNamedItem("y").getNodeValue();
                    endPt.y = Integer.parseInt(numStr);
                    numStr = childAttrs.getNamedItem("subjectIDRef").getNodeValue();
                    endPt.subjectIDRef = (short) Integer.parseInt(numStr);
                    numStr = childAttrs.getNamedItem("subjectIdx").getNodeValue();
                    endPt.subjectIdx = (short) Integer.parseInt(numStr);
                }
                node.removeChild(child);
                break;
            case "hp:controlPoints":
                {
                    if (controlPoints == null) {
                        controlPoints = new ArrayList<Point>();
                    }
                    NodeList grandChildList = child.getChildNodes();
                    for (int j=0; j<grandChildList.getLength(); j++) {
                        Point p = new Point();
                        Node grandChild = grandChildList.item(j);
                        switch(grandChild.getNodeName()) {
                        case "hp:point":
                            NamedNodeMap grandChildAttrs = grandChild.getAttributes();
                            numStr = grandChildAttrs.getNamedItem("x").getNodeValue();
                            p.x = Integer.parseInt(numStr);
                            numStr = grandChildAttrs.getNamedItem("y").getNodeValue();
                            p.y = Integer.parseInt(numStr);
                            break;
                        }
                        controlPoints.add(p);
                    }
                }
                node.removeChild(child);
                break;
            default:
            	break;
            }
        }
    }

    public String toString() {
        StringBuffer strb = new StringBuffer();
        strb.append("CTRL("+ctrlId+")")
            .append("=공통속성:"+super.toString());
        return strb.toString();
    }

    @Override
    public int getSize() {
        return size;
    }
	
    public static class ConnectPoint extends Point {
        public short subjectIDRef;
        public short subjectIdx;
    }
	
    public static enum ConnectLineType {
        STRAIGHT_NOARROW   (0x0),
        STRAIGHT_ONEWAY    (0x1),
        STRAIGHT_BOTH      (0x2),
        STROKE_NOARROW     (0x3),
        STROKE_ONEWAY      (0x4),
        STROKE_BOTH        (0x5),
        ARC_NOARROW        (0x6),
        ARC_ONEWAY         (0x7),
        ARC_BOTH           (0x8);
        
        private int num;
        
        private ConnectLineType(int num) { 
            this.num = num;
        }

        public static ConnectLineType from(int num) {
            for (ConnectLineType type: values()) {
                if (type.num == num)
                    return type;
            }
            return null;
        }
    }
}