internal PdfAppearance GetAppearance(PdfDictionary merged, String text, String fieldName) {
topFirst = 0;
TextField tx = null;
if (fieldCache == null || !fieldCache.ContainsKey(fieldName)) {
tx = new TextField(writer, null, null);
tx.SetExtraMargin(extraMarginLeft, extraMarginTop);
tx.BorderWidth = 0;
tx.SubstitutionFonts = substitutionFonts;
DecodeGenericDictionary(merged, tx);
//rect
PdfArray rect = merged.GetAsArray(PdfName.RECT);
Rectangle box = PdfReader.GetNormalizedRectangle(rect);
if (tx.Rotation == 90 || tx.Rotation == 270)
box = box.Rotate();
tx.Box = box;
if (fieldCache != null)
fieldCache[fieldName] = tx;
}
else {
tx = (TextField)fieldCache[fieldName];
tx.Writer = writer;
}
PdfName fieldType = merged.GetAsName(PdfName.FT);
if (PdfName.TX.Equals(fieldType)) {
tx.Text = text;
return tx.GetAppearance();
}
if (!PdfName.CH.Equals(fieldType))
throw new DocumentException("An appearance was requested without a variable text field.");
PdfArray opt = merged.GetAsArray(PdfName.OPT);
int flags = 0;
PdfNumber nfl = merged.GetAsNumber(PdfName.FF);
if (nfl != null)
flags = nfl.IntValue;
if ((flags & PdfFormField.FF_COMBO) != 0 && opt == null) {
tx.Text = text;
return tx.GetAppearance();
}
if (opt != null) {
String[] choices = new String[opt.Size];
String[] choicesExp = new String[opt.Size];
for (int k = 0; k < opt.Size; ++k) {
PdfObject obj = opt[k];
if (obj.IsString()) {
choices[k] = choicesExp[k] = ((PdfString)obj).ToUnicodeString();
}
else {
PdfArray a = (PdfArray) obj;
choicesExp[k] = a.GetAsString(0).ToUnicodeString();
choices[k] = a.GetAsString(1).ToUnicodeString();
}
}
if ((flags & PdfFormField.FF_COMBO) != 0) {
for (int k = 0; k < choices.Length; ++k) {
if (text.Equals(choicesExp[k])) {
text = choices[k];
break;
}
}
tx.Text = text;
return tx.GetAppearance();
}
int idx = 0;
for (int k = 0; k < choicesExp.Length; ++k) {
if (text.Equals(choicesExp[k])) {
idx = k;
break;
}
}
tx.Choices = choices;
tx.ChoiceExports = choicesExp;
tx.ChoiceSelection = idx;
}
PdfAppearance app = tx.GetListAppearance();
topFirst = tx.TopFirst;
return app;
}