Skip to content

Commit e306acb

Browse files
committed
增加Path对象的测试用例
增加了轴向渐变
1 parent bfd5a83 commit e306acb

File tree

11 files changed

+603
-8
lines changed

11 files changed

+603
-8
lines changed

ofdrw-core/src/main/java/org/ofdrw/core/OFDElement.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ public OFDElement setObjID(ST_ID objId) {
174174
return this;
175175
}
176176

177+
178+
/**
179+
* 移除元素中所有内容
180+
*
181+
* @return this
182+
*/
183+
public OFDElement removeAll() {
184+
this.elements().forEach(this::remove);
185+
return this;
186+
}
187+
177188
/**
178189
* 【可选】
179190
* <p>

ofdrw-core/src/main/java/org/ofdrw/core/basicStructure/pageObj/layer/PageBlockType.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.ofdrw.core.basicStructure.pageObj.layer;
22

33
import org.dom4j.Element;
4-
import org.ofdrw.core.basicStructure.pageObj.layer.block.CT_PageBlock;
4+
import org.ofdrw.core.basicStructure.pageObj.layer.block.*;
55

66
/**
77
* 用于表示页块类型的接口
@@ -22,19 +22,19 @@ public interface PageBlockType extends Element {
2222
*/
2323
static PageBlockType getInstance(Element element) {
2424
String qName = element.getQualifiedName();
25-
CT_PageBlock res = null;
25+
PageBlockType res = null;
2626
switch (qName) {
2727
case "ofd:TextObject":
28-
// TODO 2019-10-10 20:22:35 TextObject
28+
res = new TextObject(element);
2929
break;
3030
case "ofd:PathObject":
31-
// TODO 2019-10-10 20:26:36 PathObject
31+
res = new PathObject(element);
3232
break;
3333
case "ofd:ImageObject":
34-
// TODO 2019-10-10 20:26:51 ImageObject
34+
res = new ImageObject(element);
3535
break;
3636
case "ofd:CompositeObject":
37-
// TODO 2019-10-10 20:27:11 CompositeObject
37+
res = new CompositeObject(element);
3838
break;
3939
case "ofd:PageBlock":
4040
res = new CT_PageBlock(element);

ofdrw-core/src/main/java/org/ofdrw/core/basicType/ST_Pos.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public ST_Pos(double x, double y) {
2828
this.y = y;
2929
}
3030

31+
32+
public static ST_Pos getInstance(double x, double y) {
33+
return new ST_Pos(x,y);
34+
}
35+
3136
/**
3237
* 获取 ST_Pos 实例如果参数非法则返还null
3338
*

ofdrw-core/src/main/java/org/ofdrw/core/graph/pathObj/CT_Path.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public CT_Path setStrokeColor(CT_Color strokeColor) {
140140
if (!(strokeColor instanceof StrokeColor)) {
141141
strokeColor.setOFDName("StrokeColor");
142142
}
143+
this.removeOFDElemByNames("StrokeColor");
143144
this.add(strokeColor);
144145
return this;
145146
}
@@ -173,6 +174,7 @@ public CT_Path setFillColor(CT_Color fillColor) {
173174
if (!(fillColor instanceof FillColor)) {
174175
fillColor.setOFDName("FillColor");
175176
}
177+
this.removeOFDElemByNames("FillColor");
176178
this.add(fillColor);
177179
return this;
178180
}

ofdrw-core/src/main/java/org/ofdrw/core/pageDescription/color/color/CT_Color.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public CT_Color() {
3838
super("Color");
3939
}
4040

41+
/**
42+
* @param color 颜色族中的颜色
43+
*/
44+
public CT_Color(ColorClusterType color) {
45+
this();
46+
this.setColor(color);
47+
}
48+
49+
4150
protected CT_Color(String name) {
4251
super(name);
4352
}
@@ -56,8 +65,7 @@ protected CT_Color(String name) {
5665
*/
5766
public static CT_Color rgb(int r, int g, int b) {
5867
return new CT_Color()
59-
.setValue(new ST_Array(r, g, b))
60-
.setAlpha(255);
68+
.setValue(new ST_Array(r, g, b));
6169
}
6270

6371
/**
@@ -241,6 +249,9 @@ public Integer getAlpha() {
241249
* @return this
242250
*/
243251
public CT_Color setColor(ColorClusterType color) {
252+
if (color == null) {
253+
return this;
254+
}
244255
this.add(color);
245256
return this;
246257
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
package org.ofdrw.core.pageDescription.color.color.axialShd;
2+
3+
import org.dom4j.Element;
4+
import org.ofdrw.core.OFDElement;
5+
import org.ofdrw.core.basicType.ST_Pos;
6+
import org.ofdrw.core.pageDescription.color.color.ColorClusterType;
7+
8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
/**
13+
* 轴向渐变
14+
* <p>
15+
* 在轴向渐变中,颜色渐变沿着一条指定的轴线方向,轴线由起始点和结束点决定,
16+
* 与这条轴线垂直的直线上的点颜色相同。
17+
* <p>
18+
* 当轴向渐变某个方向设定为延伸时(Extend 不等于 0),渐变应沿轴在该方向的延长线
19+
* 延伸到超出裁剪区在该轴线的投影区域为止。当 MapType 为 Direct 时,延伸区域的
20+
* 渲染颜色使用该方向轴点所在的段的颜色;否则,按照在轴线区域内的渲染规则进行渲染。
21+
* <p>
22+
* 8.3.4.2 轴向渐变 图 29、30 表 29
23+
*
24+
* @author 权观宇
25+
* @since 2019-10-31 06:53:43
26+
*/
27+
public class CT_AxialShd extends OFDElement implements ColorClusterType {
28+
public CT_AxialShd(Element proxy) {
29+
super(proxy);
30+
}
31+
32+
public CT_AxialShd() {
33+
super("AxialShd");
34+
}
35+
36+
protected CT_AxialShd(String name) {
37+
super(name);
38+
}
39+
40+
/**
41+
* 【可选 属性】
42+
* 设置 渐变绘制的方式
43+
* <p>
44+
* 可选值参考{@link MapType}
45+
*
46+
* @param mapType 绘制方向
47+
* @return this
48+
*/
49+
public CT_AxialShd setMapType(MapType mapType) {
50+
if (mapType == null) {
51+
this.removeAttr("MapType");
52+
return this;
53+
}
54+
this.addAttribute("MapType", mapType.toString());
55+
return this;
56+
}
57+
58+
/**
59+
* 【可选 属性】
60+
* 获取 渐变绘制的方式
61+
* <p>
62+
* 可选值参考{@link MapType}
63+
*
64+
* @return 绘制方向
65+
*/
66+
public MapType getMapType() {
67+
return MapType.getInstance(this.attributeValue("MapType"));
68+
}
69+
70+
/**
71+
* 【可选 属性】
72+
* 设置 轴线一个渐变区间的长度
73+
* <p>
74+
* 当 MapType 的值不等于 Direct 时出现
75+
* <p>
76+
* 默认值为轴线长度
77+
*
78+
* @param mapUnit 轴线一个渐变区间的长度
79+
* @return this
80+
*/
81+
public CT_AxialShd setMapUnit(Double mapUnit) {
82+
if (mapUnit == null) {
83+
this.removeAttr("MapUnit");
84+
return this;
85+
}
86+
this.addAttribute("MapUnit", mapUnit.toString());
87+
return this;
88+
}
89+
90+
/**
91+
* 【可选 属性】
92+
* 获取 轴线一个渐变区间的长度
93+
* <p>
94+
* 当 MapType 的值不等于 Direct 时出现
95+
* <p>
96+
* 默认值为轴线长度
97+
*
98+
* @return 轴线一个渐变区间的长度
99+
*/
100+
public Double getMapUnit() {
101+
String str = this.attributeValue("MapUnit");
102+
if (str == null || str.trim().length() == 0) {
103+
return null;
104+
}
105+
return Double.parseDouble(str);
106+
}
107+
108+
/**
109+
* 【可选 属性】
110+
* 设置 轴线延长线方向是否继续绘制
111+
* <p>
112+
* 可选值参考{@link Extend}
113+
* <p>
114+
* 默认值为 {@link Extend#_0} 不向两侧继续绘制渐变
115+
*
116+
* @param extend 轴线延长线方向是否继续绘制
117+
* @return this
118+
*/
119+
public CT_AxialShd setExtend(Extend extend) {
120+
if (extend == null) {
121+
this.removeAttr("Extend");
122+
return this;
123+
}
124+
this.addAttribute("Extend", extend.toString());
125+
return this;
126+
}
127+
128+
/**
129+
* 【可选 属性】
130+
* 获取 轴线延长线方向是否继续绘制
131+
* <p>
132+
* 默认值为 {@link Extend#_0} 不向两侧继续绘制渐变
133+
*
134+
* @return 轴线延长线方向是否继续绘制,选值参考{@link Extend}
135+
*/
136+
public Extend getExtend() {
137+
return Extend.getInstance(this.attributeValue("Extend"));
138+
}
139+
140+
/**
141+
* 【必选 属性】
142+
* 设置 轴线起始点
143+
*
144+
* @param startPoint 轴线起始点
145+
* @return this
146+
*/
147+
public CT_AxialShd setStartPoint(ST_Pos startPoint) {
148+
if (startPoint == null) {
149+
throw new IllegalArgumentException("轴线起始点(StartPoint)不能为空");
150+
}
151+
this.addAttribute("StartPoint", startPoint.toString());
152+
return this;
153+
}
154+
155+
/**
156+
* 【必选 属性】
157+
* 获取 轴线起始点
158+
*
159+
* @return 轴线起始点
160+
*/
161+
public ST_Pos getStartPoint() {
162+
return ST_Pos.getInstance(this.attributeValue("StartPoint"));
163+
}
164+
165+
/**
166+
* 【必选 属性】
167+
* 设置 轴线结束点
168+
*
169+
* @param endPoint 轴线结束点
170+
* @return this
171+
*/
172+
public CT_AxialShd setEndPoint(ST_Pos endPoint) {
173+
if (endPoint == null) {
174+
throw new IllegalArgumentException("轴线结束点(StartPoint)不能为空");
175+
}
176+
this.addAttribute("EndPoint", endPoint.toString());
177+
return this;
178+
}
179+
180+
/**
181+
* 【必选 属性】
182+
* 设置 轴线结束点
183+
*
184+
* @return 轴线结束点
185+
*/
186+
public ST_Pos getEndPoint() {
187+
return ST_Pos.getInstance(this.attributeValue("EndPoint"));
188+
}
189+
190+
/**
191+
* 【必选】
192+
* 增加 段
193+
*
194+
* @param segment 段
195+
* @return this
196+
*/
197+
public CT_AxialShd addSegment(Segment segment) {
198+
if (segment == null) {
199+
throw new IllegalArgumentException("段(Segment)为空");
200+
}
201+
this.add(segment);
202+
return this;
203+
}
204+
205+
/**
206+
* 【必选】
207+
* 获取 段列表
208+
*
209+
* @return 段列表
210+
*/
211+
public List<Segment> getSegments() {
212+
List<Element> elements = this.getOFDElements("Segment");
213+
if (elements == null || elements.size() == 0) {
214+
return Collections.emptyList();
215+
}
216+
List<Segment> res = new ArrayList<>(elements.size());
217+
elements.forEach(item -> res.add(new Segment(item)));
218+
return res;
219+
}
220+
}

0 commit comments

Comments
 (0)