@@ -45,11 +45,280 @@ This file is part of the iText (R) project.
45
45
package com .itextpdf .layout ;
46
46
47
47
import com .itextpdf .layout .element .AbstractElement ;
48
+ import com .itextpdf .layout .element .BlockElement ;
49
+ import com .itextpdf .layout .property .Property ;
50
+ import com .itextpdf .layout .property .VerticalAlignment ;
48
51
49
- /** Container object for style properties of an element. A style can be used as
52
+ /**
53
+ * Container object for style properties of an element. A style can be used as
50
54
* an effective way to define multiple equal properties to several elements.
51
55
* Used in {@link AbstractElement}
52
56
*/
53
57
public class Style extends ElementPropertyContainer <Style > {
54
58
59
+ /**
60
+ * Gets the current left margin width of the element.
61
+ * @return the left margin width, as a <code>float</code>
62
+ */
63
+ public Float getMarginLeft () {
64
+ return getProperty (Property .MARGIN_LEFT );
65
+ }
66
+
67
+ /**
68
+ * Sets the left margin width of the element.
69
+ * @param value the new left margin width
70
+ * @return this element
71
+ */
72
+ public Style setMarginLeft (float value ) {
73
+ setProperty (Property .MARGIN_LEFT , value );
74
+ return this ;
75
+ }
76
+
77
+ /**
78
+ * Gets the current right margin width of the element.
79
+ * @return the right margin width, as a <code>float</code>
80
+ */
81
+ public Float getMarginRight () {
82
+ return getProperty (Property .MARGIN_RIGHT );
83
+ }
84
+
85
+ /**
86
+ * Sets the right margin width of the element.
87
+ * @param value the new right margin width
88
+ * @return this element
89
+ */
90
+ public Style setMarginRight (float value ) {
91
+ setProperty (Property .MARGIN_RIGHT , value );
92
+ return this ;
93
+ }
94
+
95
+ /**
96
+ * Gets the current top margin width of the element.
97
+ * @return the top margin width, as a <code>float</code>
98
+ */
99
+ public Float getMarginTop () {
100
+ return getProperty (Property .MARGIN_TOP );
101
+ }
102
+
103
+ /**
104
+ * Sets the top margin width of the element.
105
+ * @param value the new top margin width
106
+ * @return this element
107
+ */
108
+ public Style setMarginTop (float value ) {
109
+ setProperty (Property .MARGIN_TOP , value );
110
+ return this ;
111
+ }
112
+
113
+ /**
114
+ * Gets the current bottom margin width of the element.
115
+ * @return the bottom margin width, as a <code>float</code>
116
+ */
117
+ public Float getMarginBottom () {
118
+ return getProperty (Property .MARGIN_BOTTOM );
119
+ }
120
+
121
+ /**
122
+ * Sets the bottom margin width of the element.
123
+ * @param value the new bottom margin width
124
+ * @return this element
125
+ */
126
+ public Style setMarginBottom (float value ) {
127
+ setProperty (Property .MARGIN_BOTTOM , value );
128
+ return this ;
129
+ }
130
+
131
+ /**
132
+ * Sets all margins around the element to the same width.
133
+ *
134
+ * @param commonMargin the new margin width
135
+ * @return this element
136
+ */
137
+ public Style setMargin (float commonMargin ) {
138
+ return setMargins (commonMargin , commonMargin , commonMargin , commonMargin );
139
+ }
140
+
141
+ /**
142
+ * Sets the margins around the element to a series of new widths.
143
+ *
144
+ * @param marginTop the new margin top width
145
+ * @param marginRight the new margin right width
146
+ * @param marginBottom the new margin bottom width
147
+ * @param marginLeft the new margin left width
148
+ * @return this element
149
+ */
150
+ public Style setMargins (float marginTop , float marginRight , float marginBottom , float marginLeft ) {
151
+ setMarginTop (marginTop );
152
+ setMarginRight (marginRight );
153
+ setMarginBottom (marginBottom );
154
+ setMarginLeft (marginLeft );
155
+ return this ;
156
+ }
157
+
158
+ /**
159
+ * Gets the current left padding width of the element.
160
+ * @return the left padding width, as a <code>float</code>
161
+ */
162
+ public Float getPaddingLeft () {
163
+ return getProperty (Property .PADDING_LEFT );
164
+ }
165
+
166
+ /**
167
+ * Sets the left padding width of the element.
168
+ * @param value the new left padding width
169
+ * @return this element
170
+ */
171
+ public Style setPaddingLeft (float value ) {
172
+ setProperty (Property .PADDING_LEFT , value );
173
+ return this ;
174
+ }
175
+
176
+ /**
177
+ * Gets the current right padding width of the element.
178
+ * @return the right padding width, as a <code>float</code>
179
+ */
180
+ public Float getPaddingRight () {
181
+ return getProperty (Property .PADDING_RIGHT );
182
+ }
183
+
184
+ /**
185
+ * Sets the right padding width of the element.
186
+ * @param value the new right padding width
187
+ * @return this element
188
+ */
189
+ public Style setPaddingRight (float value ) {
190
+ setProperty (Property .PADDING_RIGHT , value );
191
+ return this ;
192
+ }
193
+
194
+ /**
195
+ * Gets the current top padding width of the element.
196
+ * @return the top padding width, as a <code>float</code>
197
+ */
198
+ public Float getPaddingTop () {
199
+ return getProperty (Property .PADDING_TOP );
200
+ }
201
+
202
+ /**
203
+ * Sets the top padding width of the element.
204
+ * @param value the new top padding width
205
+ * @return this element
206
+ */
207
+ public Style setPaddingTop (float value ) {
208
+ setProperty (Property .PADDING_TOP , value );
209
+ return this ;
210
+ }
211
+
212
+ /**
213
+ * Gets the current bottom padding width of the element.
214
+ * @return the bottom padding width, as a <code>float</code>
215
+ */
216
+ public Float getPaddingBottom () {
217
+ return getProperty (Property .PADDING_BOTTOM );
218
+ }
219
+
220
+ /**
221
+ * Sets the bottom padding width of the element.
222
+ * @param value the new bottom padding width
223
+ * @return this element
224
+ */
225
+ public Style setPaddingBottom (float value ) {
226
+ setProperty (Property .PADDING_BOTTOM , value );
227
+ return this ;
228
+ }
229
+
230
+ /**
231
+ * Sets all paddings around the element to the same width.
232
+ *
233
+ * @param commonPadding the new padding width
234
+ * @return this element
235
+ */
236
+ public Style setPadding (float commonPadding ) {
237
+ return setPaddings (commonPadding , commonPadding , commonPadding , commonPadding );
238
+ }
239
+
240
+ /**
241
+ * Sets the paddings around the element to a series of new widths.
242
+ *
243
+ * @param paddingTop the new padding top width
244
+ * @param paddingRight the new padding right width
245
+ * @param paddingBottom the new padding bottom width
246
+ * @param paddingLeft the new padding left width
247
+ * @return this element
248
+ */
249
+ public Style setPaddings (float paddingTop , float paddingRight , float paddingBottom , float paddingLeft ) {
250
+ setPaddingTop (paddingTop );
251
+ setPaddingRight (paddingRight );
252
+ setPaddingBottom (paddingBottom );
253
+ setPaddingLeft (paddingLeft );
254
+ return this ;
255
+ }
256
+
257
+ /**
258
+ * Sets the vertical alignment of the element.
259
+ *
260
+ * @param verticalAlignment the vertical alignment setting
261
+ * @return this element
262
+ */
263
+ public Style setVerticalAlignment (VerticalAlignment verticalAlignment ) {
264
+ setProperty (Property .VERTICAL_ALIGNMENT , verticalAlignment );
265
+ return this ;
266
+ }
267
+
268
+ /**
269
+ * Sets a ratio which determines in which proportion will word spacing and character spacing
270
+ * be applied when horizontal alignment is justified.
271
+ * @param ratio the ratio coefficient. It must be between 0 and 1, inclusive.
272
+ * It means that <b>ratio</b> part of the free space will
273
+ * be compensated by word spacing, and <b>1-ratio</b> part of the free space will
274
+ * be compensated by character spacing.
275
+ * If <b>ratio</b> is 1, additional character spacing will not be applied.
276
+ * If <b>ratio</b> is 0, additional word spacing will not be applied.
277
+ */
278
+ public Style setSpacingRatio (float ratio ) {
279
+ setProperty (Property .SPACING_RATIO , ratio );
280
+ return this ;
281
+ }
282
+
283
+ /**
284
+ * Returns whether the {@link BlockElement} should be kept together as much
285
+ * as possible.
286
+ * @return the current value of the {@link Property#KEEP_TOGETHER} property
287
+ */
288
+ public Boolean isKeepTogether () {
289
+ return getProperty (Property .KEEP_TOGETHER );
290
+ }
291
+
292
+ /**
293
+ * Sets whether the {@link BlockElement} should be kept together as much
294
+ * as possible.
295
+ * @param keepTogether the new value of the {@link Property#KEEP_TOGETHER} property
296
+ * @return this element
297
+ */
298
+ public Style setKeepTogether (boolean keepTogether ) {
299
+ setProperty (Property .KEEP_TOGETHER , keepTogether );
300
+ return this ;
301
+ }
302
+
303
+ /**
304
+ * Sets the rotation radAngle.
305
+ *
306
+ * @param radAngle the new rotation radAngle, as a <code>float</code>
307
+ * @return this element
308
+ */
309
+ public Style setRotationAngle (float radAngle ) {
310
+ setProperty (Property .ROTATION_ANGLE , radAngle );
311
+ return this ;
312
+ }
313
+
314
+ /**
315
+ * Sets the rotation angle.
316
+ *
317
+ * @param angle the new rotation angle, as a <code>double</code>
318
+ * @return this element
319
+ */
320
+ public Style setRotationAngle (double angle ) {
321
+ setProperty (Property .ROTATION_ANGLE , (float ) angle );
322
+ return this ;
323
+ }
55
324
}
0 commit comments