Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 /** Creates a new instance of DocumentFont */
 internal DocumentFont(PRIndirectReference refFont)
 {
     encoding = "";
     fontSpecific = false;
     this.refFont = refFont;
     fontType = FONT_TYPE_DOCUMENT;
     font = (PdfDictionary)PdfReader.GetPdfObject(refFont);
     fontName = PdfName.DecodeName(font.GetAsName(PdfName.BASEFONT).ToString());
     PdfName subType = font.GetAsName(PdfName.SUBTYPE);
     if (PdfName.TYPE1.Equals(subType) || PdfName.TRUETYPE.Equals(subType))
         DoType1TT();
     else {
         for (int k = 0; k < cjkNames.Length; ++k) {
             if (fontName.StartsWith(cjkNames[k])) {
                 fontName = cjkNames[k];
                 cjkMirror = BaseFont.CreateFont(fontName, cjkEncs[k], false);
                 return;
             }
         }
         String enc = PdfName.DecodeName(font.GetAsName(PdfName.ENCODING).ToString());
         for (int k = 0; k < cjkEncs2.Length; ++k) {
             if (enc.StartsWith(cjkEncs2[k])) {
                 if (k > 3)
                     k -= 4;
                 cjkMirror = BaseFont.CreateFont(cjkNames2[k], cjkEncs2[k], false);
                 return;
             }
         }
         if (PdfName.TYPE0.Equals(subType) && enc.Equals("Identity-H")) {
             ProcessType0(font);
             isType0 = true;
         }
     }
 }