Skip to content

Commit d04ac0a

Browse files
committed
Code refactoring for renderers
Fix formatting issues, remove unused objects, rearrange imports
1 parent 8bbf49f commit d04ac0a

37 files changed

+577
-584
lines changed

forms/src/main/java/com/itextpdf/forms/form/renderer/AbstractFormFieldRenderer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ protected String getModelId() {
261261
/**
262262
* Checks if the renderer fits a certain width and height.
263263
*
264-
* @param availableWidth the available width
264+
* @param availableWidth the available width
265265
* @param availableHeight the available height
266266
*
267267
* @return true, if the renderer fits.
@@ -338,14 +338,14 @@ protected void writeAcroFormFieldLangAttribute(PdfDocument pdfDoc) {
338338

339339

340340
private void processLangAttribute() {
341-
IPropertyContainer propertyContainer = flatRenderer.getModelElement();
342-
String lang = getLang();
343-
if (propertyContainer instanceof IAccessibleElement && lang != null) {
344-
AccessibilityProperties properties = ((IAccessibleElement) propertyContainer)
345-
.getAccessibilityProperties();
346-
if (properties.getLanguage() == null) {
347-
properties.setLanguage(lang);
348-
}
349-
}
341+
IPropertyContainer propertyContainer = flatRenderer.getModelElement();
342+
String lang = getLang();
343+
if (propertyContainer instanceof IAccessibleElement && lang != null) {
344+
AccessibilityProperties properties = ((IAccessibleElement) propertyContainer)
345+
.getAccessibilityProperties();
346+
if (properties.getLanguage() == null) {
347+
properties.setLanguage(lang);
348+
}
349+
}
350350
}
351351
}

forms/src/main/java/com/itextpdf/forms/form/renderer/AbstractOneLineTextFieldRenderer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This file is part of the iText (R) project.
2424

2525
import com.itextpdf.forms.form.element.IFormField;
2626
import com.itextpdf.kernel.geom.Rectangle;
27-
import com.itextpdf.layout.renderer.BlockRenderer;
2827
import com.itextpdf.layout.renderer.IRenderer;
2928
import com.itextpdf.layout.renderer.LineRenderer;
3029

@@ -48,7 +47,7 @@ public abstract class AbstractOneLineTextFieldRenderer extends AbstractTextField
4847
* Crops the content lines.
4948
*
5049
* @param lines a list of lines
51-
* @param bBox the bounding box
50+
* @param bBox the bounding box
5251
*/
5352
void cropContentLines(List<LineRenderer> lines, Rectangle bBox) {
5453
adjustNumberOfContentLines(lines, bBox, 1);
@@ -75,8 +74,8 @@ private void updateParagraphHeight() {
7574
/**
7675
* Sets the content height.
7776
*
78-
* @param flatRenderer the flat renderer
79-
* @param height the height
77+
* @param flatRenderer the flat renderer
78+
* @param height the height
8079
*/
8180
void setContentHeight(IRenderer flatRenderer, float height) {
8281
Rectangle bBox = flatRenderer.getOccupiedArea().getBBox();

forms/src/main/java/com/itextpdf/forms/form/renderer/AbstractSelectFieldRenderer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ protected String getModelId() {
236236
* to the form field builder.
237237
*
238238
* @param builder {@link ChoiceFormFieldBuilder} to set options to
239-
* @param field {@link AbstractSelectField} to retrieve the options from
239+
* @param field {@link AbstractSelectField} to retrieve the options from
240240
*/
241241
protected void setupBuilderValues(ChoiceFormFieldBuilder builder, AbstractSelectField field) {
242242
List<SelectFieldItem> options = field.getOptions();
@@ -272,8 +272,9 @@ protected void setupBuilderValues(ChoiceFormFieldBuilder builder, AbstractSelect
272272
* Returns final height of the select field.
273273
*
274274
* @param availableHeight available height of the layout area
275-
* @param actualHeight actual occupied height of the select field
275+
* @param actualHeight actual occupied height of the select field
276276
* @param isClippedHeight indicates whether the layout area's height is clipped or not
277+
*
277278
* @return final height of the select field.
278279
*/
279280
protected float getFinalSelectFieldHeight(float availableHeight, float actualHeight, boolean isClippedHeight) {
@@ -291,6 +292,7 @@ protected float getFinalSelectFieldHeight(float availableHeight, float actualHei
291292
* Gets the conformance. If the conformance is not set, the conformance of the document is used.
292293
*
293294
* @param document the document
295+
*
294296
* @return the conformance or null if the conformance is not set.
295297
*/
296298
protected PdfConformance getConformance(PdfDocument document) {
@@ -308,6 +310,7 @@ protected PdfConformance getConformance(PdfDocument document) {
308310
* Gets options that are marked as selected from the select field options subtree.
309311
*
310312
* @param optionsSubTree options subtree to get selected options
313+
*
311314
* @return selected options list.
312315
*/
313316
protected List<IRenderer> getOptionsMarkedSelected(IRenderer optionsSubTree) {

forms/src/main/java/com/itextpdf/forms/form/renderer/AbstractTextFieldRenderer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public abstract class AbstractTextFieldRenderer extends AbstractFormFieldRendere
7171
* Creates a paragraph renderer.
7272
*
7373
* @param defaultValue the default value
74+
*
7475
* @return the renderer
7576
*/
7677
IRenderer createParagraphRenderer(String defaultValue) {
@@ -195,8 +196,8 @@ float updateHtmlColsSizeBasedWidth(float width) {
195196
* Adjust number of content lines.
196197
*
197198
* @param lines the lines that need to be rendered
198-
* @param bBox the bounding box
199-
* @param rows the desired number of lines
199+
* @param bBox the bounding box
200+
* @param rows the desired number of lines
200201
*/
201202
void adjustNumberOfContentLines(List<LineRenderer> lines, Rectangle bBox, int rows) {
202203
if (lines.size() != rows) {
@@ -208,8 +209,8 @@ void adjustNumberOfContentLines(List<LineRenderer> lines, Rectangle bBox, int ro
208209
/**
209210
* Adjust number of content lines.
210211
*
211-
* @param lines the lines that need to be rendered
212-
* @param bBox the bounding box
212+
* @param lines the lines that need to be rendered
213+
* @param bBox the bounding box
213214
* @param height the desired height of content
214215
*/
215216
void adjustNumberOfContentLines(List<LineRenderer> lines, Rectangle bBox, float height) {
@@ -238,7 +239,7 @@ float getLowestChildBottom(IRenderer renderer, float value) {
238239
}
239240

240241
private static void adjustNumberOfContentLines(List<LineRenderer> lines, Rectangle bBox,
241-
int linesNumber, float height) {
242+
int linesNumber, float height) {
242243
bBox.moveUp(bBox.getHeight() - height);
243244
bBox.setHeight(height);
244245
if (lines.size() > linesNumber) {

forms/src/main/java/com/itextpdf/forms/form/renderer/ButtonRenderer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ This file is part of the iText (R) project.
5454
import com.itextpdf.layout.renderer.IRenderer;
5555
import com.itextpdf.layout.renderer.LineRenderer;
5656
import com.itextpdf.layout.renderer.ParagraphRenderer;
57+
import org.slf4j.Logger;
58+
import org.slf4j.LoggerFactory;
5759

5860
import java.util.List;
5961
import java.util.Map;
6062

61-
import org.slf4j.Logger;
62-
import org.slf4j.LoggerFactory;
63-
6463
/**
6564
* The {@link AbstractTextFieldRenderer} implementation for buttons.
6665
*/
@@ -281,7 +280,7 @@ protected void applyAcroField(DrawContext drawContext) {
281280
button.setFontSize(fontSizeValue);
282281
button.getFirstFormAnnotation().setBackgroundColor(backgroundColor);
283282
applyDefaultFieldProperties(button);
284-
applyAccessibilityProperties(button,doc);
283+
applyAccessibilityProperties(button, doc);
285284
button.getFirstFormAnnotation().setFormFieldElement((Button) modelElement);
286285
button.enableFieldRegeneration();
287286
PdfAcroForm forms = PdfFormCreator.getAcroForm(doc, true);

forms/src/main/java/com/itextpdf/forms/form/renderer/CheckBoxRenderer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ protected void adjustFieldLayout(LayoutContext layoutContext) {
185185
* Checkboxes don't support setting of paddings as they are always centered.
186186
* So that this method returns the rectangle as is.
187187
*
188-
* @param rect a rectangle paddings will be applied on.
188+
* @param rect a rectangle paddings will be applied on.
189189
* @param paddings the paddings to be applied on the given rectangle
190-
* @param reverse indicates whether paddings will be applied
191-
* inside (in case of false) or outside (in case of true) the rectangle.
190+
* @param reverse indicates whether paddings will be applied
191+
* inside (in case of false) or outside (in case of true) the rectangle.
192192
*
193193
* @return The rectangle NOT modified by the paddings.
194194
*/
@@ -207,7 +207,7 @@ public IRenderer createFlatRenderer() {
207207
final UnitValue heightUV = getPropertyAsUnitValue(Property.HEIGHT);
208208
final UnitValue widthUV = getPropertyAsUnitValue(Property.WIDTH);
209209

210-
// if it is a percentage value, we need to calculate the actual value but we
210+
// if it is a percentage value, we need to calculate the actual value, but we
211211
// don't have the parent's width yet, so we will take the default value
212212
float height = DEFAULT_SIZE;
213213
if (heightUV != null && heightUV.isPointValue()) {

forms/src/main/java/com/itextpdf/forms/form/renderer/FormFieldValueNonTrimmingTextRenderer.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ This file is part of the iText (R) project.
3232
import com.itextpdf.layout.layout.TextLayoutResult;
3333
import com.itextpdf.layout.renderer.IRenderer;
3434
import com.itextpdf.layout.renderer.TextRenderer;
35-
3635
import org.slf4j.Logger;
3736
import org.slf4j.LoggerFactory;
3837

@@ -42,7 +41,7 @@ This file is part of the iText (R) project.
4241
*/
4342

4443
class FormFieldValueNonTrimmingTextRenderer extends TextRenderer {
45-
// Determines whether we want to trim leading space. In particular we don't want to trim
44+
// Determines whether we want to trim leading space. In particular, we don't want to trim
4645
// the very first leading spaces of the text value. When text overflows to the next lines,
4746
// whether we should trim the text depends on why the overflow happened
4847
private boolean callTrimFirst = false;
@@ -64,16 +63,16 @@ public LayoutResult layout(LayoutContext layoutContext) {
6463
!((TextLayoutResult) baseLayoutResult).isSplitForcedByNewline()) {
6564
// In case the overflow to the next line happened naturally (without a forced line break),
6665
// we don't want to preserve the extra spaces at the beginning of the next line
67-
((FormFieldValueNonTrimmingTextRenderer) baseLayoutResult.getOverflowRenderer()).setCallTrimFirst(true);
66+
((FormFieldValueNonTrimmingTextRenderer) baseLayoutResult.getOverflowRenderer()).setCallTrimFirst();
6867
}
6968
return baseLayoutResult;
7069
}
7170

7271
@Override
7372
public void trimFirst() {
74-
if (callTrimFirst) {
75-
super.trimFirst();
76-
}
73+
if (callTrimFirst) {
74+
super.trimFirst();
75+
}
7776
}
7877

7978
/**
@@ -85,12 +84,12 @@ protected TextRenderer createCopy(GlyphLine gl, PdfFont font) {
8584
Logger logger = LoggerFactory.getLogger(FormFieldValueNonTrimmingTextRenderer.class);
8685
logger.error(MessageFormatUtil.format(IoLogMessageConstant.CREATE_COPY_SHOULD_BE_OVERRIDDEN));
8786
}
88-
FormFieldValueNonTrimmingTextRenderer copy = new FormFieldValueNonTrimmingTextRenderer((Text)this.modelElement);
87+
FormFieldValueNonTrimmingTextRenderer copy = new FormFieldValueNonTrimmingTextRenderer((Text) this.modelElement);
8988
copy.setProcessedGlyphLineAndFont(gl, font);
9089
return copy;
9190
}
9291

93-
private void setCallTrimFirst(boolean callTrimFirst) {
94-
this.callTrimFirst = callTrimFirst;
92+
private void setCallTrimFirst() {
93+
this.callTrimFirst = true;
9594
}
9695
}

forms/src/main/java/com/itextpdf/forms/form/renderer/InputFieldRenderer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ This file is part of the iText (R) project.
5050
import com.itextpdf.layout.renderer.IRenderer;
5151
import com.itextpdf.layout.renderer.LineRenderer;
5252
import com.itextpdf.layout.renderer.ParagraphRenderer;
53-
54-
import java.util.List;
55-
import java.util.Map;
56-
5753
import com.itextpdf.layout.tagging.IAccessibleElement;
5854
import org.slf4j.Logger;
5955
import org.slf4j.LoggerFactory;
6056

57+
import java.util.List;
58+
import java.util.Map;
59+
6160
/**
6261
* The {@link AbstractOneLineTextFieldRenderer} implementation for input fields.
6362
*/
@@ -244,12 +243,12 @@ protected void applyAcroField(DrawContext drawContext) {
244243
inputField.setComb(true);
245244
inputField.setMaxLen(getMaxLen());
246245
}
247-
final int rotation = ((InputField)modelElement).getRotation();
246+
final int rotation = ((InputField) modelElement).getRotation();
248247
if (rotation != 0) {
249248
inputField.getFirstFormAnnotation().setRotation(rotation);
250249
}
251250
applyDefaultFieldProperties(inputField);
252-
applyAccessibilityProperties(inputField,doc);
251+
applyAccessibilityProperties(inputField, doc);
253252
inputField.getFirstFormAnnotation().setFormFieldElement((InputField) modelElement);
254253
inputField.enableFieldRegeneration();
255254
PdfFormCreator.getAcroForm(doc, true).addField(inputField, page);
@@ -292,7 +291,7 @@ protected boolean setMinMaxWidthBasedOnFixedWidth(MinMaxWidth minMaxWidth) {
292291
setProperty(Property.WIDTH, null);
293292
Float width = retrieveWidth(0);
294293
if (width != null) {
295-
// the field can be shrinked if necessary so only max width is set here
294+
// the field can be shrunk if necessary so only max width is set here
296295
minMaxWidth.setChildrenMaxWidth((float) width);
297296
result = true;
298297
}
@@ -341,6 +340,7 @@ private int getMaxLen() {
341340
* Obfuscates the content of a password input field.
342341
*
343342
* @param text the password
343+
*
344344
* @return a string consisting of '*' characters.
345345
*/
346346
private String obfuscatePassword(String text) {

forms/src/main/java/com/itextpdf/forms/form/renderer/RadioRenderer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public void drawBackground(DrawContext drawContext) {
114114
* @param rect {@inheritDoc}
115115
* @param borders {@inheritDoc}
116116
* @param reverse {@inheritDoc}
117+
*
117118
* @return {@inheritDoc}
118119
*/
119120
@Override
@@ -306,14 +307,14 @@ public void drawBorder(DrawContext drawContext) {
306307
final boolean isTaggingEnabled = drawContext.isTaggingEnabled();
307308
final PdfCanvas canvas = drawContext.getCanvas();
308309

309-
if (isTaggingEnabled){
310+
if (isTaggingEnabled) {
310311
canvas.openTag(new CanvasArtifact());
311312
}
312313
canvas.setStrokeColor(border.getColor())
313314
.setLineWidth(borderWidth)
314315
.circle(cx, cy, r)
315316
.stroke();
316-
if (isTaggingEnabled){
317+
if (isTaggingEnabled) {
317318
canvas.closeTag();
318319
}
319320
}
@@ -349,13 +350,13 @@ public void drawBackground(DrawContext drawContext) {
349350
final boolean isTaggingEnabled = drawContext.isTaggingEnabled();
350351
final PdfCanvas canvas = drawContext.getCanvas();
351352

352-
if (isTaggingEnabled){
353+
if (isTaggingEnabled) {
353354
canvas.openTag(new CanvasArtifact());
354355
}
355356
canvas.setFillColor(backgroundColor)
356357
.circle(cx, cy, r)
357358
.fill();
358-
if (isTaggingEnabled){
359+
if (isTaggingEnabled) {
359360
canvas.closeTag();
360361
}
361362
}

forms/src/main/java/com/itextpdf/forms/form/renderer/SelectFieldComboBoxRenderer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ This file is part of the iText (R) project.
5555
import com.itextpdf.layout.renderer.DrawContext;
5656
import com.itextpdf.layout.renderer.IRenderer;
5757
import com.itextpdf.layout.tagging.IAccessibleElement;
58+
import org.slf4j.Logger;
59+
import org.slf4j.LoggerFactory;
5860

5961
import java.util.ArrayList;
6062
import java.util.List;
6163
import java.util.Map;
62-
import org.slf4j.Logger;
63-
import org.slf4j.LoggerFactory;
6464

6565
/**
6666
* The {@link SelectFieldComboBoxRenderer} implementation for select field renderer.
@@ -121,7 +121,7 @@ protected void applyAcroField(DrawContext drawContext) {
121121
.setConformance(getConformance(doc));
122122

123123
applyMargins(area, false);
124-
final Map<Integer, Object> properties = FormFieldRendererUtil.removeProperties(this.modelElement);
124+
final Map<Integer, Object> properties = FormFieldRendererUtil.removeProperties(this.modelElement);
125125

126126
modelElement.setProperty(Property.FONT_PROVIDER, this.<FontProvider>getProperty(Property.FONT_PROVIDER));
127127
modelElement.setProperty(Property.RENDERING_MODE, this.<RenderingMode>getProperty(Property.RENDERING_MODE));

0 commit comments

Comments
 (0)