1 31 package org.pdfbox.pdmodel.interactive.form; 32 33 import org.pdfbox.cos.COSDictionary; 34 import org.pdfbox.cos.COSInteger; 35 import org.pdfbox.cos.COSName; 36 import org.pdfbox.cos.COSNumber; 37 import org.pdfbox.cos.COSString; 38 import org.pdfbox.util.BitFlagHelper; 39 40 import java.io.IOException ; 41 42 48 public abstract class PDVariableText extends PDField 49 { 50 53 public static final int FLAG_MULTILINE = 1 << 12; 54 57 public static final int FLAG_PASSWORD = 1 << 13; 58 61 public static final int FLAG_FILE_SELECT = 1 << 20; 62 65 public static final int FLAG_DO_NOT_SPELL_CHECK = 1 << 22; 66 69 public static final int FLAG_DO_NOT_SCROLL = 1 << 23; 70 73 public static final int FLAG_COMB = 1 << 24; 74 77 public static final int FLAG_RICH_TEXT = 1 << 25; 78 79 80 83 private COSString da; 84 85 private PDAppearance appearance; 86 87 88 91 public static final int QUADDING_LEFT = 0; 92 93 96 public static final int QUADDING_CENTERED = 1; 97 98 101 public static final int QUADDING_RIGHT = 2; 102 103 108 public PDVariableText( PDAcroForm theAcroForm ) 109 { 110 super( theAcroForm ); 111 } 112 113 119 public PDVariableText( PDAcroForm theAcroForm, COSDictionary field) 120 { 121 super( theAcroForm, field); 122 da = (COSString) field.getDictionaryObject(COSName.getPDFName("DA")); 123 } 124 125 132 public void setValue(String value) throws IOException 133 { 134 COSString fieldValue = new COSString(value); 135 getDictionary().setItem( COSName.getPDFName( "V" ), fieldValue ); 136 137 if(appearance == null) 142 { 143 this.appearance = new PDAppearance( getAcroForm(), this ); 144 } 145 appearance.setAppearanceValue(value); 146 } 147 148 155 public String getValue() throws IOException 156 { 157 return getDictionary().getString( "V" ); 158 } 159 160 163 public boolean isMultiline() 164 { 165 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_MULTILINE ); 166 } 167 168 173 public void setMultiline( boolean multiline ) 174 { 175 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_MULTILINE, multiline ); 176 } 177 178 181 public boolean isPassword() 182 { 183 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_PASSWORD ); 184 } 185 186 191 public void setPassword( boolean password ) 192 { 193 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_PASSWORD, password ); 194 } 195 196 199 public boolean isFileSelect() 200 { 201 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_FILE_SELECT ); 202 } 203 204 209 public void setFileSelect( boolean fileSelect ) 210 { 211 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_FILE_SELECT, fileSelect ); 212 } 213 214 217 public boolean doNotSpellCheck() 218 { 219 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_DO_NOT_SPELL_CHECK ); 220 } 221 222 227 public void setDoNotSpellCheck( boolean doNotSpellCheck ) 228 { 229 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_DO_NOT_SPELL_CHECK, doNotSpellCheck ); 230 } 231 232 235 public boolean doNotScroll() 236 { 237 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_DO_NOT_SCROLL ); 238 } 239 240 245 public void setDoNotScroll( boolean doNotScroll ) 246 { 247 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_DO_NOT_SCROLL, doNotScroll ); 248 } 249 250 253 public boolean shouldComb() 254 { 255 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_COMB ); 256 } 257 258 263 public void setComb( boolean comb ) 264 { 265 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_COMB, comb ); 266 } 267 268 271 public boolean isRichText() 272 { 273 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_RICH_TEXT ); 274 } 275 276 281 public void setRichText( boolean richText ) 282 { 283 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_RICH_TEXT, richText ); 284 } 285 286 289 protected COSString getDefaultAppearance() 290 { 291 return da; 292 } 293 294 303 public int getQ() 304 { 305 int retval = 0; 306 COSNumber number = (COSNumber)getDictionary().getDictionaryObject( COSName.getPDFName( "Q" ) ); 307 if( number != null ) 308 { 309 retval = number.intValue(); 310 } 311 return retval; 312 } 313 314 319 public void setQ( int q ) 320 { 321 getDictionary().setItem( COSName.getPDFName( "Q" ), new COSInteger( q ) ); 322 } 323 324 } | Popular Tags |