@@ -31,9 +31,11 @@ This file is part of the iText (R) project.
31
31
*/
32
32
class GridCell {
33
33
private final IRenderer value ;
34
- private final IntRectangle gridArea ;
35
- private Rectangle layoutArea = new Rectangle (0.0f , 0.0f , 0.0f ,0.0f );
36
- private boolean isValueFitOnCellArea = true ;
34
+ private int gridX ;
35
+ private int gridY ;
36
+ private final int spanColumn ;
37
+ private final int spanRow ;
38
+ private final Rectangle layoutArea = new Rectangle (0.0f , 0.0f , 0.0f ,0.0f );
37
39
38
40
/**
39
41
* Create a grid cell and init value renderer position on a grid based on its properties.
@@ -42,30 +44,31 @@ class GridCell {
42
44
*/
43
45
GridCell (IRenderer value ) {
44
46
this .value = value ;
45
- final int [] rowValues = initRowColumnsValues (value .<Integer >getProperty (Property .GRID_ROW_START ),
46
- value .<Integer >getProperty (Property .GRID_ROW_END ));
47
- int height = rowValues [0 ] == 0 ? 1 : rowValues [1 ] - rowValues [0 ];
48
-
49
- final int [] columnValues = initRowColumnsValues (value .<Integer >getProperty (Property .GRID_COLUMN_START ),
50
- value .<Integer >getProperty (Property .GRID_COLUMN_END ));
51
- int width = columnValues [0 ] == 0 ? 1 : columnValues [1 ] - columnValues [0 ];
52
- gridArea = new IntRectangle (columnValues [0 ] - 1 , rowValues [0 ] - 1 , width , height );
47
+ final int [] rowPlacement = initAxisPlacement (value .<Integer >getProperty (Property .GRID_ROW_START ),
48
+ value .<Integer >getProperty (Property .GRID_ROW_END ), value .<Integer >getProperty (Property .GRID_ROW_SPAN ));
49
+ gridY = rowPlacement [0 ];
50
+ spanRow = rowPlacement [1 ];
51
+
52
+ final int [] columnPlacement = initAxisPlacement (value .<Integer >getProperty (Property .GRID_COLUMN_START ),
53
+ value .<Integer >getProperty (Property .GRID_COLUMN_END ), value .<Integer >getProperty (Property .GRID_COLUMN_SPAN ));
54
+ gridX = columnPlacement [0 ];
55
+ spanColumn = columnPlacement [1 ];
53
56
}
54
57
55
58
int getColumnStart () {
56
- return gridArea . getLeft () ;
59
+ return gridX ;
57
60
}
58
61
59
62
int getColumnEnd () {
60
- return gridArea . getRight () ;
63
+ return gridX + spanColumn ;
61
64
}
62
65
63
66
int getRowStart () {
64
- return gridArea . getBottom () ;
67
+ return gridY ;
65
68
}
66
69
67
70
int getRowEnd () {
68
- return gridArea . getTop () ;
71
+ return gridY + spanRow ;
69
72
}
70
73
71
74
int getStart (GridOrder order ) {
@@ -85,11 +88,11 @@ int getEnd(GridOrder order) {
85
88
}
86
89
87
90
int getGridHeight () {
88
- return gridArea . getHeight () ;
91
+ return spanRow ;
89
92
}
90
93
91
94
int getGridWidth () {
92
- return gridArea . getWidth () ;
95
+ return spanColumn ;
93
96
}
94
97
95
98
int getGridSpan (GridOrder order ) {
@@ -104,119 +107,56 @@ IRenderer getValue() {
104
107
return value ;
105
108
}
106
109
107
- boolean isValueFitOnCellArea () {
108
- return isValueFitOnCellArea ;
109
- }
110
-
111
110
Rectangle getLayoutArea () {
112
111
return layoutArea ;
113
112
}
114
113
115
- IntRectangle getGridArea () {
116
- return gridArea ;
117
- }
118
-
119
- void setLayoutArea (Rectangle layoutArea ) {
120
- this .layoutArea = layoutArea ;
121
- }
122
-
123
- void setValueFitOnCellArea (boolean valueFitOnCellArea ) {
124
- isValueFitOnCellArea = valueFitOnCellArea ;
125
- }
126
-
127
114
void setPos (int y , int x ) {
128
- this .gridArea . setY ( y ) ;
129
- this .gridArea . setX ( x ) ;
115
+ this .gridY = y ;
116
+ this .gridX = x ;
130
117
}
131
118
132
119
/**
133
- * init row/column start/end value
120
+ * Init axis placement values
134
121
* if start > end values are swapped
135
- * if only start or end are specified - other value is initialized so cell would have height/width = 1
136
122
*
137
123
* @param start x/y pos of cell on a grid
138
124
* @param end x/y + width/height pos of cell on a grid
139
- * @return row/column start/end values as a pair, where first value is start, second is end
125
+ * @param span vertical or horizontal span of the cell on a grid
126
+ * @return row/column start + vertical/horizontal span values as a pair, where first value is start, second is span
140
127
*/
141
- private int [] initRowColumnsValues (Integer start , Integer end ) {
142
- int [] result = new int [] {0 , 0 };
128
+ private int [] initAxisPlacement (Integer start , Integer end , Integer span ) {
129
+ int [] result = new int [] {0 , 1 };
143
130
if (start != null && end != null ) {
144
- result [0 ] = (int )start ;
145
- result [1 ] = (int )end ;
146
- if (start > end ) {
147
- result [0 ] = (int )end ;
148
- result [1 ] = (int )start ;
131
+ int intStart = (int ) start ;
132
+ int intEnd = (int ) end ;
133
+ if (intStart < intEnd ) {
134
+ result [0 ] = intStart ;
135
+ result [1 ] = intEnd - intStart ;
136
+ } else {
137
+ result [0 ] = intEnd ;
138
+ result [1 ] = intStart - intEnd ;
149
139
}
150
140
} else if (start != null ) {
151
- result [0 ] = (int )start ;
152
- result [1 ] = (int )start + 1 ;
141
+ result [0 ] = (int ) start ;
142
+ if (span != null ) {
143
+ result [1 ] = (int ) span ;
144
+ }
145
+ // span default value 1 was set up on the result array initialization
153
146
} else if (end != null ) {
154
- result [0 ] = end <= 1 ? 1 : ((int )end ) - 1 ;
155
- result [1 ] = end <= 1 ? 2 : (int )end ;
147
+ int intEnd = (int ) end ;
148
+ if (span == null ) {
149
+ result [0 ] = end <= 1 ? 1 : ((int ) end ) - 1 ;
150
+ // span default value 1 was set up on the result array initialization
151
+ } else {
152
+ int intSpan = (int ) span ;
153
+ result [1 ] = intSpan ;
154
+ result [0 ] = Math .max (intEnd - intSpan , 1 );
155
+ }
156
+ } else if (span != null ) {
157
+ result [1 ] = (int ) span ;
156
158
}
159
+ result [0 ] -= 1 ;
157
160
return result ;
158
161
}
159
-
160
- /**
161
- * This class represents an integer rectangle.
162
- * x,y - represents a bottom left corner of this rectangle.
163
- */
164
- static class IntRectangle {
165
- private int x ;
166
- private int y ;
167
- private int width ;
168
- private int height ;
169
-
170
- public IntRectangle (int x , int y , int width , int height ) {
171
- this .x = x ;
172
- this .y = y ;
173
- this .width = width ;
174
- this .height = height ;
175
- }
176
-
177
- public int getLeft () {
178
- return x ;
179
- }
180
-
181
- public int getRight () {
182
- return x + width ;
183
- }
184
-
185
- public int getTop () {
186
- return y + height ;
187
- }
188
-
189
- public int getBottom () {
190
- return y ;
191
- }
192
-
193
- public int getWidth () {
194
- return width ;
195
- }
196
-
197
- public int getHeight () {
198
- return height ;
199
- }
200
-
201
- public void setX (int x ) {
202
- this .x = x ;
203
- }
204
-
205
- public void setY (int y ) {
206
- this .y = y ;
207
- }
208
-
209
- public void setWidth (int width ) {
210
- this .width = width ;
211
- }
212
-
213
- public void setHeight (int height ) {
214
- this .height = height ;
215
- }
216
-
217
- @ Override
218
- public String toString () {
219
- return "Rectangle: start(" + x + ',' + y + ") ," + width + 'x' + height ;
220
- }
221
- }
222
162
}
0 commit comments