9
9
import com .openhtmltopdf .css .style .CssContext ;
10
10
import com .openhtmltopdf .newtable .CollapsedBorderValue ;
11
11
12
- /**
13
- * Created by IntelliJ IDEA.
14
- * User: patrick
15
- * Date: Oct 21, 2005
16
- * Time: 3:24:04 PM
17
- * To change this template use File | Settings | File Templates.
18
- */
19
12
public class BorderPropertySet extends RectPropertySet {
20
- public static final BorderPropertySet EMPTY_BORDER = new BorderPropertySet (0.0f , 0.0f , 0.0f , 0.0f );
21
-
13
+ public static final BorderPropertySet EMPTY_BORDER = new BorderPropertySet (true , 0.0f , 0.0f , 0.0f , 0.0f );
14
+
15
+ private boolean _allowBevel ;
16
+
22
17
private IdentValue _topStyle ;
23
18
private IdentValue _rightStyle ;
24
19
private IdentValue _bottomStyle ;
@@ -34,8 +29,9 @@ public class BorderPropertySet extends RectPropertySet {
34
29
private BorderRadiusCorner _bottomRight ;
35
30
private BorderRadiusCorner _bottomLeft ;
36
31
37
- public BorderPropertySet (BorderPropertySet border ) {
38
- this (border .top (), border .right (), border .bottom (), border .left ());
32
+ private BorderPropertySet (BorderPropertySet border ) {
33
+ this (border .isBevelAllowed (), border .top (), border .right (), border .bottom (), border .left ());
34
+
39
35
this ._topStyle = border .topStyle ();
40
36
this ._rightStyle = border .rightStyle ();
41
37
this ._bottomStyle = border .bottomStyle ();
@@ -45,13 +41,15 @@ public BorderPropertySet(BorderPropertySet border) {
45
41
this ._rightColor = border .rightColor ();
46
42
this ._bottomColor = border .bottomColor ();
47
43
this ._leftColor = border .leftColor ();
48
-
44
+
49
45
this ._topLeft = border ._topLeft ;
50
46
this ._topRight = border ._topRight ;
51
47
this ._bottomLeft = border ._bottomLeft ;
52
48
this ._bottomRight = border ._bottomRight ;
53
49
}
54
- public BorderPropertySet (
50
+
51
+ private BorderPropertySet (
52
+ boolean allowBevel ,
55
53
float top ,
56
54
float right ,
57
55
float bottom ,
@@ -61,45 +59,52 @@ public BorderPropertySet(
61
59
BorderRadiusCorner bottomRightCorner ,
62
60
BorderRadiusCorner bottomLeftCorner
63
61
) {
62
+ this ._allowBevel = allowBevel ;
63
+
64
64
this ._top = top ;
65
65
this ._right = right ;
66
66
this ._bottom = bottom ;
67
67
this ._left = left ;
68
-
68
+
69
69
this ._topLeft = topLeftCorner ;
70
70
this ._topRight = topRightCorner ;
71
71
this ._bottomLeft = bottomLeftCorner ;
72
72
this ._bottomRight = bottomRightCorner ;
73
73
}
74
74
75
75
public BorderPropertySet (
76
+ boolean allowBevel ,
76
77
float top ,
77
78
float right ,
78
79
float bottom ,
79
80
float left
80
81
) {
82
+ this ._allowBevel = allowBevel ;
83
+
81
84
this ._top = top ;
82
85
this ._right = right ;
83
86
this ._bottom = bottom ;
84
87
this ._left = left ;
85
-
88
+
86
89
this ._topLeft = new BorderRadiusCorner ();
87
90
this ._topRight = new BorderRadiusCorner ();
88
91
this ._bottomLeft = new BorderRadiusCorner ();
89
92
this ._bottomRight = new BorderRadiusCorner ();
90
93
}
91
-
94
+
92
95
public BorderPropertySet (
96
+ boolean allowBevel ,
93
97
CollapsedBorderValue top ,
94
98
CollapsedBorderValue right ,
95
99
CollapsedBorderValue bottom ,
96
100
CollapsedBorderValue left
97
101
) {
98
- this ( top .width (),
102
+ this (allowBevel ,
103
+ top .width (),
99
104
right .width (),
100
105
bottom .width (),
101
106
left .width ());
102
-
107
+
103
108
this ._topStyle = top .style ();
104
109
this ._rightStyle = right .style ();
105
110
this ._bottomStyle = bottom .style ();
@@ -108,8 +113,8 @@ public BorderPropertySet(
108
113
this ._topColor = top .color ();
109
114
this ._rightColor = right .color ();
110
115
this ._bottomColor = bottom .color ();
111
- this ._leftColor = left .color ();
112
-
116
+ this ._leftColor = left .color ();
117
+
113
118
this ._topLeft = new BorderRadiusCorner ();
114
119
this ._topRight = new BorderRadiusCorner ();
115
120
this ._bottomLeft = new BorderRadiusCorner ();
@@ -120,6 +125,8 @@ private BorderPropertySet(
120
125
CalculatedStyle style ,
121
126
CssContext ctx
122
127
) {
128
+ _allowBevel = style .isIdent (CSSName .FS_BORDER_RENDERING , IdentValue .AUTO );
129
+
123
130
_top = ( style .isIdent (CSSName .BORDER_TOP_STYLE , IdentValue .NONE ) ||
124
131
style .isIdent (CSSName .BORDER_TOP_STYLE , IdentValue .HIDDEN )
125
132
?
@@ -136,7 +143,7 @@ private BorderPropertySet(
136
143
style .isIdent (CSSName .BORDER_LEFT_STYLE , IdentValue .HIDDEN )
137
144
?
138
145
0 : style .getFloatPropertyProportionalHeight (CSSName .BORDER_LEFT_WIDTH , 0 , ctx ));
139
-
146
+
140
147
_topColor = style .asColor (CSSName .BORDER_TOP_COLOR );
141
148
_rightColor = style .asColor (CSSName .BORDER_RIGHT_COLOR );
142
149
_bottomColor = style .asColor (CSSName .BORDER_BOTTOM_COLOR );
@@ -146,12 +153,7 @@ private BorderPropertySet(
146
153
_rightStyle = style .getIdent (CSSName .BORDER_RIGHT_STYLE );
147
154
_bottomStyle = style .getIdent (CSSName .BORDER_BOTTOM_STYLE );
148
155
_leftStyle = style .getIdent (CSSName .BORDER_LEFT_STYLE );
149
- /*
150
- _topLeft = new BorderRadiusCorner(style.valueByName(CSSName.BORDER_TOP_LEFT_RADIUS), ctx);
151
- _topRight = new BorderRadiusCorner(style.valueByName(CSSName.BORDER_TOP_RIGHT_RADIUS), ctx);
152
- _bottomLeft = new BorderRadiusCorner(style.valueByName(CSSName.BORDER_BOTTOM_LEFT_RADIUS), ctx);
153
- _bottomRight = new BorderRadiusCorner(style.valueByName(CSSName.BORDER_BOTTOM_RIGHT_RADIUS), ctx);
154
- */
156
+
155
157
_topLeft = new BorderRadiusCorner (CSSName .BORDER_TOP_LEFT_RADIUS , style , ctx );
156
158
_topRight = new BorderRadiusCorner (CSSName .BORDER_TOP_RIGHT_RADIUS , style , ctx );
157
159
_bottomLeft = new BorderRadiusCorner (CSSName .BORDER_BOTTOM_LEFT_RADIUS , style , ctx );
@@ -200,6 +202,13 @@ public String toString() {
200
202
return "BorderPropertySet[top=" + _top + ",right=" + _right + ",bottom=" + _bottom + ",left=" + _left + "]" ;
201
203
}
202
204
205
+ /**
206
+ * See {@link CSSName#FS_BORDER_RENDERING}
207
+ */
208
+ public boolean isBevelAllowed () {
209
+ return this ._allowBevel ;
210
+ }
211
+
203
212
public boolean noTop () {
204
213
return this ._topStyle == IdentValue .NONE || (int ) _top == 0 ;
205
214
}
@@ -247,16 +256,16 @@ public FSColor bottomColor() {
247
256
public FSColor leftColor () {
248
257
return _leftColor ;
249
258
}
250
-
259
+
251
260
public boolean hasHidden () {
252
261
return _topStyle == IdentValue .HIDDEN || _rightStyle == IdentValue .HIDDEN ||
253
262
_bottomStyle == IdentValue .HIDDEN || _leftStyle == IdentValue .HIDDEN ;
254
- }
255
-
263
+ }
264
+
256
265
public boolean hasBorderRadius () {
257
266
return getTopLeft ().hasRadius () || getTopRight ().hasRadius () || getBottomLeft ().hasRadius () || getBottomRight ().hasRadius ();
258
267
}
259
-
268
+
260
269
public BorderRadiusCorner getBottomRight () {
261
270
return _bottomRight ;
262
271
}
@@ -288,10 +297,10 @@ public BorderRadiusCorner getTopLeft() {
288
297
public void setTopLeft (BorderRadiusCorner topLeft ) {
289
298
this ._topLeft = topLeft ;
290
299
}
291
-
300
+
292
301
public BorderPropertySet normalizedInstance (Rectangle bounds ) {
293
302
float factor = 1 ;
294
-
303
+
295
304
// top
296
305
factor = Math .min (factor , bounds .width / getSideWidth (_topLeft , _topRight , bounds .width ));
297
306
// bottom
@@ -300,36 +309,32 @@ public BorderPropertySet normalizedInstance(Rectangle bounds) {
300
309
factor = Math .min (factor , bounds .height / getSideWidth (_topRight , _bottomRight , bounds .height ));
301
310
// left
302
311
factor = Math .min (factor , bounds .height / getSideWidth (_bottomLeft , _bottomRight , bounds .height ));
303
-
304
- BorderPropertySet newPropSet = new BorderPropertySet (_top , _right , _bottom , _left ,
312
+
313
+ BorderPropertySet newPropSet = new BorderPropertySet (true , _top , _right , _bottom , _left ,
305
314
new BorderRadiusCorner (factor *_topLeft .getMaxLeft (bounds .height ), factor *_topLeft .getMaxRight (bounds .width )),
306
315
new BorderRadiusCorner (factor *_topRight .getMaxLeft (bounds .width ), factor *_topRight .getMaxRight (bounds .height )),
307
316
new BorderRadiusCorner (factor *_bottomRight .getMaxLeft (bounds .height ), factor *_bottomRight .getMaxRight (bounds .width )),
308
317
new BorderRadiusCorner (factor *_bottomLeft .getMaxLeft (bounds .width ), factor *_bottomLeft .getMaxRight (bounds .height )));
309
-
318
+
310
319
newPropSet ._topColor = _topColor ;
311
320
newPropSet ._rightColor = _rightColor ;
312
321
newPropSet ._bottomColor = _bottomColor ;
313
322
newPropSet ._leftColor = _leftColor ;
314
-
323
+
315
324
newPropSet ._topStyle = _topStyle ;
316
325
newPropSet ._rightStyle = _rightStyle ;
317
326
newPropSet ._bottomStyle = _bottomStyle ;
318
327
newPropSet ._leftStyle = _leftStyle ;
319
-
328
+
320
329
return newPropSet ;
321
330
}
322
331
323
332
/**
324
- * helper function for normalizeBorderRadius. Gets the max side width for each of the corners or the side width whichever is larger
325
- * @param left
326
- * @param right
327
- * @param sideWidth
328
- * @return
333
+ * Helper function for normalizeBorderRadius. Gets the max side width for each
334
+ * of the corners or the side width whichever is larger.
329
335
*/
330
336
private float getSideWidth (BorderRadiusCorner left , BorderRadiusCorner right , float sideWidth ) {
331
337
return Math .max (sideWidth , left .getMaxRight (sideWidth ) + right .getMaxLeft (sideWidth ));
332
338
}
333
339
334
340
}
335
-
0 commit comments