Skip to content

Commit 55ae03d

Browse files
committed
Fix backward compatibility issue in PdfFormField
Remove redundant comparing in setDefaultAppearance DEVSIX-1916
1 parent becad90 commit 55ae03d

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ This file is part of the iText (R) project.
101101
/**
102102
* This class represents a single field or field group in an {@link com.itextpdf.forms.PdfAcroForm
103103
* AcroForm}.
104-
* <p>
104+
*
105105
* <br><br>
106106
* To be able to be wrapped with this {@link PdfObjectWrapper} the {@link PdfObject}
107107
* must be indirect.
@@ -121,6 +121,7 @@ public class PdfFormField extends PdfObjectWrapper<PdfDictionary> {
121121

122122
/**
123123
* Size of text in form fields when font size is not explicitly set.
124+
*
124125
* @deprecated Will be made package-private in iText 7.2.
125126
*/
126127
@Deprecated
@@ -1658,22 +1659,16 @@ public PdfString getDefaultAppearance() {
16581659
* Sets default appearance string containing a sequence of valid page-content graphics or text state operators that
16591660
* define such properties as the field's text size and color.
16601661
*
1661-
* If form field has the same default appearance (incl. inherited) it won't be updated.
1662-
*
16631662
* @param defaultAppearance a valid sequence of PDF content stream syntax
16641663
* @return the edited field
16651664
*/
16661665
public PdfFormField setDefaultAppearance(String defaultAppearance) {
1667-
PdfString prev = getDefaultAppearance();
1668-
if (prev == null || !defaultAppearance.trim().equals(prev.getValue().trim()) || true) {
1669-
byte[] b = defaultAppearance.getBytes(StandardCharsets.UTF_8);
1670-
int len = b.length;
1671-
for (int k = 0; k < len; ++k) {
1672-
if (b[k] == '\n')
1673-
b[k] = 32;
1674-
}
1675-
getPdfObject().put(PdfName.DA, new PdfString(new String(b)));
1666+
byte[] b = defaultAppearance.getBytes(StandardCharsets.UTF_8);
1667+
for (int k = 0; k < b.length; ++k) {
1668+
if (b[k] == '\n')
1669+
b[k] = 32;
16761670
}
1671+
getPdfObject().put(PdfName.DA, new PdfString(new String(b)));
16771672
return this;
16781673
}
16791674

@@ -2633,7 +2628,7 @@ protected static PdfArray processOptions(String[] options) {
26332628
/**
26342629
* Generate default appearance, /DA key.
26352630
*
2636-
* @param font preferred font. If {@link #getFont()} is not null, it will be used instead.
2631+
* @param font preferred font. If {@link #getFont()} is not null, it will be used instead.
26372632
* @param fontSize preferred font size. If {@link PdfFormField#fontSize} is valid,
26382633
* it will be used instead.
26392634
* @return generated string
@@ -3077,9 +3072,9 @@ protected void drawRadioField(PdfCanvas canvas, float width, float height, boole
30773072
/**
30783073
* Draws the appearance of a checkbox with a specified state value.
30793074
*
3080-
* @param width the width of the checkbox to draw
3081-
* @param height the height of the checkbox to draw
3082-
* @param onStateName the state of the form field that will be drawn
3075+
* @param width the width of the checkbox to draw
3076+
* @param height the height of the checkbox to draw
3077+
* @param onStateName the state of the form field that will be drawn
30833078
*/
30843079
protected void drawCheckAppearance(float width, float height, String onStateName) {
30853080
PdfStream streamOn = (PdfStream) new PdfStream().makeIndirect(getDocument());
@@ -3179,6 +3174,26 @@ protected void drawPdfA2CheckAppearance(float width, float height, String value,
31793174
* @param font a {@link PdfFont}
31803175
* @param fontSize the size of the font
31813176
* @return a new {@link PdfFormXObject}
3177+
* @deprecated Will be removed in 7.2.
3178+
* @see #drawPushButtonAppearance(float, float, String, PdfFont, PdfName, float)
3179+
*/
3180+
@Deprecated
3181+
protected PdfFormXObject drawPushButtonAppearance(float width, float height, String text,
3182+
PdfFont font, float fontSize) {
3183+
return drawPushButtonAppearance(width, height, text, font, null, fontSize);
3184+
3185+
}
3186+
3187+
/**
3188+
* Draws the appearance for a push button.
3189+
*
3190+
* @param width the width of the pushbutton
3191+
* @param height the width of the pushbutton
3192+
* @param text the text to display on the button
3193+
* @param font a {@link PdfFont}
3194+
* @param fontName fontName in DR.
3195+
* @param fontSize the size of the font
3196+
* @return a new {@link PdfFormXObject}
31823197
*/
31833198
protected PdfFormXObject drawPushButtonAppearance(float width, float height, String text,
31843199
PdfFont font, PdfName fontName, float fontSize) {

0 commit comments

Comments
 (0)