/** * Get the <code>PdfAppearance</code> of a list field * @throws IOException on error * @throws DocumentException on error * @return A <code>PdfAppearance</code> */ internal PdfAppearance GetListAppearance() { PdfAppearance app = GetBorderAppearance(); app.BeginVariableText(); if (choices == null || choices.Length == 0) { app.EndVariableText(); return app; } int topChoice = choiceSelection; if (topChoice >= choices.Length) { topChoice = choices.Length - 1; } if (topChoice < 0) topChoice = 0; BaseFont ufont = RealFont; float usize = fontSize; if (usize == 0) usize = 12; bool borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET; float h = box.Height - borderWidth * 2; float offsetX = borderWidth; if (borderExtra) { h -= borderWidth * 2; offsetX *= 2; } float leading = ufont.GetFontDescriptor(BaseFont.BBOXURY, usize) - ufont.GetFontDescriptor(BaseFont.BBOXLLY, usize); int maxFit = (int)(h / leading) + 1; int first = 0; int last = 0; last = topChoice + maxFit / 2 + 1; first = last - maxFit; if (first < 0) { last += first; first = 0; } // first = topChoice; last = first + maxFit; if (last > choices.Length) last = choices.Length; topFirst = first; app.SaveState(); app.Rectangle(offsetX, offsetX, box.Width - 2 * offsetX, box.Height - 2 * offsetX); app.Clip(); app.NewPath(); Color fcolor = (textColor == null) ? GrayColor.GRAYBLACK : textColor; app.SetColorFill(new Color(10, 36, 106)); app.Rectangle(offsetX, offsetX + h - (topChoice - first + 1) * leading, box.Width - 2 * offsetX, leading); app.Fill(); float xp = offsetX * 2; float yp = offsetX + h - ufont.GetFontDescriptor(BaseFont.BBOXURY, usize); for (int idx = first; idx < last; ++idx, yp -= leading) { String ptext = choices[idx]; int rtl = CheckRTL(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI; ptext = RemoveCRLF(ptext); Phrase phrase = ComposePhrase(ptext, ufont, (idx == topChoice) ? GrayColor.GRAYWHITE : fcolor, usize); ColumnText.ShowTextAligned(app, Element.ALIGN_LEFT, phrase, xp, yp, 0, rtl, 0); } app.RestoreState(); app.EndVariableText(); return app; }
private float CalculateFontSize(float w, float h) { BaseFont ufont = RealFont; float fsize = fontSize; if (fsize == 0) { float bw = ufont.GetWidthPoint(text, 1); if (bw == 0) { fsize = 12; } else { fsize = w / bw; } float nfsize = h / (1 - ufont.GetFontDescriptor(BaseFont.DESCENT, 1)); fsize = Math.Min(fsize, nfsize); if (fsize < 4) { fsize = 4; } } return(fsize); }
/** Gets the font parameter identified by <CODE>key</CODE>. Valid values * for <CODE>key</CODE> are <CODE>ASCENT</CODE>, <CODE>CAPHEIGHT</CODE>, <CODE>DESCENT</CODE>, * <CODE>ITALICANGLE</CODE>, <CODE>BBOXLLX</CODE>, <CODE>BBOXLLY</CODE>, <CODE>BBOXURX</CODE> * and <CODE>BBOXURY</CODE>. * @param key the parameter to be extracted * @param fontSize the font size in points * @return the parameter in points * */ public override float GetFontDescriptor(int key, float fontSize) { if (cjkMirror != null) { return(cjkMirror.GetFontDescriptor(key, fontSize)); } switch (key) { case AWT_ASCENT: case ASCENT: return(Ascender * fontSize / 1000); case CAPHEIGHT: return(CapHeight * fontSize / 1000); case AWT_DESCENT: case DESCENT: return(Descender * fontSize / 1000); case ITALICANGLE: return(ItalicAngle); case BBOXLLX: return(llx * fontSize / 1000); case BBOXLLY: return(lly * fontSize / 1000); case BBOXURX: return(urx * fontSize / 1000); case BBOXURY: return(ury * fontSize / 1000); case AWT_LEADING: return(0); case AWT_MAXADVANCE: return((urx - llx) * fontSize / 1000); case FONT_WEIGHT: return(fontWeight * fontSize / 1000); } return(0); }
/** * Gets the button appearance. * @throws IOException on error * @throws DocumentException on error * @return the button appearance */ virtual public PdfAppearance GetAppearance() { PdfAppearance app = GetBorderAppearance(); Rectangle box = new Rectangle(app.BoundingBox); if ((text == null || text.Length == 0) && (layout == LAYOUT_LABEL_ONLY || (image == null && template == null && iconReference == null))) { return(app); } if (layout == LAYOUT_ICON_ONLY && image == null && template == null && iconReference == null) { return(app); } BaseFont ufont = RealFont; bool borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET; float h = box.Height - borderWidth * 2; float bw2 = borderWidth; if (borderExtra) { h -= borderWidth * 2; bw2 *= 2; } float offsetX = (borderExtra ? 2 * borderWidth : borderWidth); offsetX = Math.Max(offsetX, 1); float offX = Math.Min(bw2, offsetX); tp = null; float textX = float.NaN; float textY = 0; float fsize = fontSize; float wt = box.Width - 2 * offX - 2; float ht = box.Height - 2 * offX; float adj = (iconFitToBounds ? 0 : offX + 1); int nlayout = layout; if (image == null && template == null && iconReference == null) { nlayout = LAYOUT_LABEL_ONLY; } Rectangle iconBox = null; while (true) { switch (nlayout) { case LAYOUT_LABEL_ONLY: case LAYOUT_LABEL_OVER_ICON: if (text != null && text.Length > 0 && wt > 0 && ht > 0) { fsize = CalculateFontSize(wt, ht); textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2; textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2; } goto case LAYOUT_ICON_ONLY; case LAYOUT_ICON_ONLY: if (nlayout == LAYOUT_LABEL_OVER_ICON || nlayout == LAYOUT_ICON_ONLY) { iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, box.Right - adj, box.Top - adj); } break; case LAYOUT_ICON_TOP_LABEL_BOTTOM: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } float nht = box.Height * 0.35f - offX; if (nht > 0) { fsize = CalculateFontSize(wt, nht); } else { fsize = 4; } textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2; textY = offX - ufont.GetFontDescriptor(BaseFont.DESCENT, fsize); iconBox = new Rectangle(box.Left + adj, textY + fsize, box.Right - adj, box.Top - adj); break; case LAYOUT_LABEL_TOP_ICON_BOTTOM: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } nht = box.Height * 0.35f - offX; if (nht > 0) { fsize = CalculateFontSize(wt, nht); } else { fsize = 4; } textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2; textY = box.Height - offX - fsize; if (textY < offX) { textY = offX; } iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, box.Right - adj, textY + ufont.GetFontDescriptor(BaseFont.DESCENT, fsize)); break; case LAYOUT_LABEL_LEFT_ICON_RIGHT: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } float nw = box.Width * 0.35f - offX; if (nw > 0) { fsize = CalculateFontSize(wt, nw); } else { fsize = 4; } if (ufont.GetWidthPoint(text, fsize) >= wt) { nlayout = LAYOUT_LABEL_ONLY; fsize = fontSize; continue; } textX = offX + 1; textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2; iconBox = new Rectangle(textX + ufont.GetWidthPoint(text, fsize), box.Bottom + adj, box.Right - adj, box.Top - adj); break; case LAYOUT_ICON_LEFT_LABEL_RIGHT: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } nw = box.Width * 0.35f - offX; if (nw > 0) { fsize = CalculateFontSize(wt, nw); } else { fsize = 4; } if (ufont.GetWidthPoint(text, fsize) >= wt) { nlayout = LAYOUT_LABEL_ONLY; fsize = fontSize; continue; } textX = box.Width - ufont.GetWidthPoint(text, fsize) - offX - 1; textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2; iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, textX - 1, box.Top - adj); break; } break; } if (textY < box.Bottom + offX) { textY = box.Bottom + offX; } if (iconBox != null && (iconBox.Width <= 0 || iconBox.Height <= 0)) { iconBox = null; } bool haveIcon = false; float boundingBoxWidth = 0; float boundingBoxHeight = 0; PdfArray matrix = null; if (iconBox != null) { if (image != null) { tp = new PdfTemplate(writer); tp.BoundingBox = new Rectangle(image); writer.AddDirectTemplateSimple(tp, PdfName.FRM); tp.AddImage(image, image.Width, 0, 0, image.Height, 0, 0); haveIcon = true; boundingBoxWidth = tp.BoundingBox.Width; boundingBoxHeight = tp.BoundingBox.Height; } else if (template != null) { tp = new PdfTemplate(writer); tp.BoundingBox = new Rectangle(template.Width, template.Height); writer.AddDirectTemplateSimple(tp, PdfName.FRM); tp.AddTemplate(template, template.BoundingBox.Left, template.BoundingBox.Bottom); haveIcon = true; boundingBoxWidth = tp.BoundingBox.Width; boundingBoxHeight = tp.BoundingBox.Height; } else if (iconReference != null) { PdfDictionary dic = (PdfDictionary)PdfReader.GetPdfObject(iconReference); if (dic != null) { Rectangle r2 = PdfReader.GetNormalizedRectangle(dic.GetAsArray(PdfName.BBOX)); matrix = dic.GetAsArray(PdfName.MATRIX); haveIcon = true; boundingBoxWidth = r2.Width; boundingBoxHeight = r2.Height; } } } if (haveIcon) { float icx = iconBox.Width / boundingBoxWidth; float icy = iconBox.Height / boundingBoxHeight; if (proportionalIcon) { switch (scaleIcon) { case SCALE_ICON_IS_TOO_BIG: icx = Math.Min(icx, icy); icx = Math.Min(icx, 1); break; case SCALE_ICON_IS_TOO_SMALL: icx = Math.Min(icx, icy); icx = Math.Max(icx, 1); break; case SCALE_ICON_NEVER: icx = 1; break; default: icx = Math.Min(icx, icy); break; } icy = icx; } else { switch (scaleIcon) { case SCALE_ICON_IS_TOO_BIG: icx = Math.Min(icx, 1); icy = Math.Min(icy, 1); break; case SCALE_ICON_IS_TOO_SMALL: icx = Math.Max(icx, 1); icy = Math.Max(icy, 1); break; case SCALE_ICON_NEVER: icx = icy = 1; break; default: break; } } float xpos = iconBox.Left + (iconBox.Width - (boundingBoxWidth * icx)) * iconHorizontalAdjustment; float ypos = iconBox.Bottom + (iconBox.Height - (boundingBoxHeight * icy)) * iconVerticalAdjustment; app.SaveState(); app.Rectangle(iconBox.Left, iconBox.Bottom, iconBox.Width, iconBox.Height); app.Clip(); app.NewPath(); if (tp != null) { app.AddTemplate(tp, icx, 0, 0, icy, xpos, ypos); } else { float cox = 0; float coy = 0; if (matrix != null && matrix.Size == 6) { PdfNumber nm = matrix.GetAsNumber(4); if (nm != null) { cox = nm.FloatValue; } nm = matrix.GetAsNumber(5); if (nm != null) { coy = nm.FloatValue; } } app.AddTemplateReference(iconReference, PdfName.FRM, icx, 0, 0, icy, xpos - cox * icx, ypos - coy * icy); } app.RestoreState(); } if (!float.IsNaN(textX)) { app.SaveState(); app.Rectangle(offX, offX, box.Width - 2 * offX, box.Height - 2 * offX); app.Clip(); app.NewPath(); if (textColor == null) { app.ResetGrayFill(); } else { app.SetColorFill(textColor); } app.BeginText(); app.SetFontAndSize(ufont, fsize); app.SetTextMatrix(textX, textY); app.ShowText(text); app.EndText(); app.RestoreState(); } return(app); }
private void DoType1TT() { CMapToUnicode toUnicode = null; PdfObject enc = PdfReader.GetPdfObject(font.Get(PdfName.ENCODING)); if (enc == null) { PdfName baseFont = font.GetAsName(PdfName.BASEFONT); if (BuiltinFonts14.ContainsKey(fontName) && (PdfName.SYMBOL.Equals(baseFont) || PdfName.ZAPFDINGBATS.Equals(baseFont))) { FillEncoding(baseFont); } else { FillEncoding(null); } toUnicode = ProcessToUnicode(); if (toUnicode != null) { IDictionary <int, int> rm = toUnicode.CreateReverseMapping(); foreach (KeyValuePair <int, int> kv in rm) { uni2byte[kv.Key] = kv.Value; byte2uni[kv.Value] = kv.Key; } } } else { if (enc.IsName()) { FillEncoding((PdfName)enc); } else if (enc.IsDictionary()) { PdfDictionary encDic = (PdfDictionary)enc; enc = PdfReader.GetPdfObject(encDic.Get(PdfName.BASEENCODING)); if (enc == null) { FillEncoding(null); } else { FillEncoding((PdfName)enc); } PdfArray diffs = encDic.GetAsArray(PdfName.DIFFERENCES); if (diffs != null) { diffmap = new IntHashtable(); int currentNumber = 0; for (int k = 0; k < diffs.Size; ++k) { PdfObject obj = diffs[k]; if (obj.IsNumber()) { currentNumber = ((PdfNumber)obj).IntValue; } else { int[] c = GlyphList.NameToUnicode(PdfName.DecodeName(((PdfName)obj).ToString())); if (c != null && c.Length > 0) { uni2byte[c[0]] = currentNumber; byte2uni[currentNumber] = c[0]; diffmap[c[0]] = currentNumber; } else { if (toUnicode == null) { toUnicode = ProcessToUnicode(); if (toUnicode == null) { toUnicode = new CMapToUnicode(); } } string unicode = toUnicode.Lookup(new byte[] { (byte)currentNumber }, 0, 1); if ((unicode != null) && (unicode.Length == 1)) { this.uni2byte[unicode[0]] = currentNumber; this.byte2uni[currentNumber] = unicode[0]; this.diffmap[unicode[0]] = currentNumber; } } ++currentNumber; } } } } } PdfArray newWidths = font.GetAsArray(PdfName.WIDTHS); PdfNumber first = font.GetAsNumber(PdfName.FIRSTCHAR); PdfNumber last = font.GetAsNumber(PdfName.LASTCHAR); if (BuiltinFonts14.ContainsKey(fontName)) { BaseFont bf = BaseFont.CreateFont(fontName, WINANSI, false); int[] e = uni2byte.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = uni2byte[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } if (diffmap != null) //widths for differences must override existing ones { e = diffmap.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = diffmap[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } diffmap = null; } Ascender = bf.GetFontDescriptor(ASCENT, 1000); CapHeight = bf.GetFontDescriptor(CAPHEIGHT, 1000); Descender = bf.GetFontDescriptor(DESCENT, 1000); ItalicAngle = bf.GetFontDescriptor(ITALICANGLE, 1000); fontWeight = bf.GetFontDescriptor(FONT_WEIGHT, 1000); llx = bf.GetFontDescriptor(BBOXLLX, 1000); lly = bf.GetFontDescriptor(BBOXLLY, 1000); urx = bf.GetFontDescriptor(BBOXURX, 1000); ury = bf.GetFontDescriptor(BBOXURY, 1000); } if (first != null && last != null && newWidths != null) { int f = first.IntValue; int nSize = f + newWidths.Size; if (widths.Length < nSize) { int[] tmp = new int[nSize]; System.Array.Copy(widths, 0, tmp, 0, f); widths = tmp; } for (int k = 0; k < newWidths.Size; ++k) { widths[f + k] = newWidths.GetAsNumber(k).IntValue; } } FillFontDesc(font.GetAsDict(PdfName.FONTDESCRIPTOR)); }
/** * Get the <code>PdfAppearance</code> of a list field * @throws IOException on error * @throws DocumentException on error * @return A <code>PdfAppearance</code> */ internal PdfAppearance GetListAppearance() { PdfAppearance app = GetBorderAppearance(); if (choices == null || choices.Length == 0) { return(app); } app.BeginVariableText(); int topChoice = GetTopChoice(); BaseFont ufont = RealFont; float usize = fontSize; if (usize == 0) { usize = 12; } bool borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET; float h = box.Height - borderWidth * 2; float offsetX = borderWidth; if (borderExtra) { h -= borderWidth * 2; offsetX *= 2; } float leading = ufont.GetFontDescriptor(BaseFont.BBOXURY, usize) - ufont.GetFontDescriptor(BaseFont.BBOXLLY, usize); int maxFit = (int)(h / leading) + 1; int first = 0; int last = 0; first = topChoice; last = first + maxFit; if (last > choices.Length) { last = choices.Length; } topFirst = first; app.SaveState(); app.Rectangle(offsetX, offsetX, box.Width - 2 * offsetX, box.Height - 2 * offsetX); app.Clip(); app.NewPath(); BaseColor fcolor = (textColor == null) ? GrayColor.GRAYBLACK : textColor; // background boxes for selected value[s] app.SetColorFill(new BaseColor(10, 36, 106)); for (int curVal = 0; curVal < choiceSelections.Count; ++curVal) { int curChoice = choiceSelections[curVal]; // only draw selections within our display range... not strictly necessary with // that clipping rect from above, but it certainly doesn't hurt either if (curChoice >= first && curChoice <= last) { app.Rectangle(offsetX, offsetX + h - (curChoice - first + 1) * leading, box.Width - 2 * offsetX, leading); app.Fill(); } } float xp = offsetX * 2; float yp = offsetX + h - ufont.GetFontDescriptor(BaseFont.BBOXURY, usize); for (int idx = first; idx < last; ++idx, yp -= leading) { String ptext = choices[idx]; int rtl = CheckRTL(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI; ptext = RemoveCRLF(ptext); // highlight selected values against their (presumably) darker background BaseColor textCol = choiceSelections.Contains(idx) ? GrayColor.GRAYWHITE : fcolor; Phrase phrase = ComposePhrase(ptext, ufont, textCol, usize); ColumnText.ShowTextAligned(app, Element.ALIGN_LEFT, phrase, xp, yp, 0, rtl, 0); } app.RestoreState(); app.EndVariableText(); return(app); }
/** * Get the <code>PdfAppearance</code> of a text or combo field * @throws IOException on error * @throws DocumentException on error * @return A <code>PdfAppearance</code> */ public PdfAppearance GetAppearance() { PdfAppearance app = GetBorderAppearance(); app.BeginVariableText(); if (text == null || text.Length == 0) { app.EndVariableText(); return(app); } bool borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET; float h = box.Height - borderWidth * 2 - extraMarginTop; float bw2 = borderWidth; if (borderExtra) { h -= borderWidth * 2; bw2 *= 2; } float offsetX = Math.Max(bw2, 1); float offX = Math.Min(bw2, offsetX); app.SaveState(); app.Rectangle(offX, offX, box.Width - 2 * offX, box.Height - 2 * offX); app.Clip(); app.NewPath(); String ptext; if ((options & PASSWORD) != 0) { ptext = ObfuscatePassword(text); } else if ((options & MULTILINE) == 0) { ptext = RemoveCRLF(text); } else { ptext = text; //fixed by Kazuya Ujihara (ujihara.jp) } BaseFont ufont = RealFont; BaseColor fcolor = (textColor == null) ? GrayColor.GRAYBLACK : textColor; int rtl = CheckRTL(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI; float usize = fontSize; Phrase phrase = ComposePhrase(ptext, ufont, fcolor, usize); if ((options & MULTILINE) != 0) { float width = box.Width - 4 * offsetX - extraMarginLeft; float factor = ufont.GetFontDescriptor(BaseFont.BBOXURY, 1) - ufont.GetFontDescriptor(BaseFont.BBOXLLY, 1); ColumnText ct = new ColumnText(null); if (usize == 0) { usize = h / factor; if (usize > 4) { if (usize > 12) { usize = 12; } float step = Math.Max((usize - 4) / 10, 0.2f); ct.SetSimpleColumn(0, -h, width, 0); ct.Alignment = alignment; ct.RunDirection = rtl; for (; usize > 4; usize -= step) { ct.YLine = 0; ChangeFontSize(phrase, usize); ct.SetText(phrase); ct.Leading = factor * usize; int status = ct.Go(true); if ((status & ColumnText.NO_MORE_COLUMN) == 0) { break; } } } if (usize < 4) { usize = 4; } } ChangeFontSize(phrase, usize); ct.Canvas = app; float leading = usize * factor; float offsetY = offsetX + h - ufont.GetFontDescriptor(BaseFont.BBOXURY, usize); ct.SetSimpleColumn(extraMarginLeft + 2 * offsetX, -20000, box.Width - 2 * offsetX, offsetY + leading); ct.Leading = leading; ct.Alignment = alignment; ct.RunDirection = rtl; ct.SetText(phrase); ct.Go(); } else { if (usize == 0) { float maxCalculatedSize = h / (ufont.GetFontDescriptor(BaseFont.BBOXURX, 1) - ufont.GetFontDescriptor(BaseFont.BBOXLLY, 1)); ChangeFontSize(phrase, 1); float wd = ColumnText.GetWidth(phrase, rtl, 0); if (wd == 0) { usize = maxCalculatedSize; } else { usize = Math.Min(maxCalculatedSize, (box.Width - extraMarginLeft - 4 * offsetX) / wd); } if (usize < 4) { usize = 4; } } ChangeFontSize(phrase, usize); float offsetY = offX + ((box.Height - 2 * offX) - ufont.GetFontDescriptor(BaseFont.ASCENT, usize)) / 2; if (offsetY < offX) { offsetY = offX; } if (offsetY - offX < -ufont.GetFontDescriptor(BaseFont.DESCENT, usize)) { float ny = -ufont.GetFontDescriptor(BaseFont.DESCENT, usize) + offX; float dy = box.Height - offX - ufont.GetFontDescriptor(BaseFont.ASCENT, usize); offsetY = Math.Min(ny, Math.Max(offsetY, dy)); } if ((options & COMB) != 0 && maxCharacterLength > 0) { int textLen = Math.Min(maxCharacterLength, ptext.Length); int position = 0; if (alignment == Element.ALIGN_RIGHT) { position = maxCharacterLength - textLen; } else if (alignment == Element.ALIGN_CENTER) { position = (maxCharacterLength - textLen) / 2; } float step = (box.Width - extraMarginLeft) / maxCharacterLength; float start = step / 2 + position * step; if (textColor == null) { app.SetGrayFill(0); } else { app.SetColorFill(textColor); } app.BeginText(); foreach (Chunk ck in phrase) { BaseFont bf = ck.Font.BaseFont; app.SetFontAndSize(bf, usize); StringBuilder sb = ck.Append(""); for (int j = 0; j < sb.Length; ++j) { String c = sb.ToString(j, 1); float wd = bf.GetWidthPoint(c, usize); app.SetTextMatrix(extraMarginLeft + start - wd / 2, offsetY - extraMarginTop); app.ShowText(c); start += step; } } app.EndText(); } else { float x; switch (alignment) { case Element.ALIGN_RIGHT: x = extraMarginLeft + box.Width - (2 * offsetX); break; case Element.ALIGN_CENTER: x = extraMarginLeft + (box.Width / 2); break; default: x = extraMarginLeft + (2 * offsetX); break; } ColumnText.ShowTextAligned(app, alignment, phrase, x, offsetY - extraMarginTop, 0, rtl, 0); } } app.RestoreState(); app.EndVariableText(); return(app); }
private void DoType1TT() { CMapToUnicode toUnicode = null; PdfObject enc = PdfReader.GetPdfObject(font.Get(PdfName.ENCODING)); if (enc == null) { PdfName baseFont = font.GetAsName(PdfName.BASEFONT); if (BuiltinFonts14.ContainsKey(fontName) && (PdfName.SYMBOL.Equals(baseFont) || PdfName.ZAPFDINGBATS.Equals(baseFont))) { FillEncoding(baseFont); } else { FillEncoding(null); } toUnicode = ProcessToUnicode(); if (toUnicode != null) { IDictionary <int, int> rm = toUnicode.CreateReverseMapping(); foreach (KeyValuePair <int, int> kv in rm) { uni2byte[kv.Key] = kv.Value; byte2uni[kv.Value] = kv.Key; } } } else { if (enc.IsName()) { FillEncoding((PdfName)enc); } else if (enc.IsDictionary()) { PdfDictionary encDic = (PdfDictionary)enc; enc = PdfReader.GetPdfObject(encDic.Get(PdfName.BASEENCODING)); if (enc == null) { FillEncoding(null); } else { FillEncoding((PdfName)enc); } FillDiffMap(encDic, toUnicode); } } if (BuiltinFonts14.ContainsKey(fontName)) { BaseFont bf = BaseFont.CreateFont(fontName, WINANSI, false); int[] e = uni2byte.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = uni2byte[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } if (diffmap != null) { //widths for differences must override existing ones e = diffmap.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = diffmap[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } diffmap = null; } Ascender = bf.GetFontDescriptor(ASCENT, 1000); CapHeight = bf.GetFontDescriptor(CAPHEIGHT, 1000); Descender = bf.GetFontDescriptor(DESCENT, 1000); ItalicAngle = bf.GetFontDescriptor(ITALICANGLE, 1000); fontWeight = bf.GetFontDescriptor(FONT_WEIGHT, 1000); llx = bf.GetFontDescriptor(BBOXLLX, 1000); lly = bf.GetFontDescriptor(BBOXLLY, 1000); urx = bf.GetFontDescriptor(BBOXURX, 1000); ury = bf.GetFontDescriptor(BBOXURY, 1000); } FillWidths(); FillFontDesc(font.GetAsDict(PdfName.FONTDESCRIPTOR)); }
/** * Gets the field appearance. * @param isRadio <CODE>true</CODE> for a radio field and <CODE>false</CODE> * for a check field * @param on <CODE>true</CODE> for the checked state, <CODE>false</CODE> * otherwise * @throws IOException on error * @throws DocumentException on error * @return the appearance */ public PdfAppearance GetAppearance(bool isRadio, bool on) { if (isRadio && checkType == TYPE_CIRCLE) { return(GetAppearanceRadioCircle(on)); } PdfAppearance app = GetBorderAppearance(); if (!on) { return(app); } BaseFont ufont = RealFont; bool borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET; float h = box.Height - borderWidth * 2; float bw2 = borderWidth; if (borderExtra) { h -= borderWidth * 2; bw2 *= 2; } float offsetX = (borderExtra ? 2 * borderWidth : borderWidth); offsetX = Math.Max(offsetX, 1); float offX = Math.Min(bw2, offsetX); float wt = box.Width - 2 * offX; float ht = box.Height - 2 * offX; float fsize = fontSize; if (fsize == 0) { float bw = ufont.GetWidthPoint(text, 1); if (bw == 0) { fsize = 12; } else { fsize = wt / bw; } float nfsize = h / (ufont.GetFontDescriptor(BaseFont.ASCENT, 1)); fsize = Math.Min(fsize, nfsize); } app.SaveState(); app.Rectangle(offX, offX, wt, ht); app.Clip(); app.NewPath(); if (textColor == null) { app.ResetGrayFill(); } else { app.SetColorFill(textColor); } app.BeginText(); app.SetFontAndSize(ufont, fsize); app.SetTextMatrix((box.Width - ufont.GetWidthPoint(text, fsize)) / 2, (box.Height - ufont.GetAscentPoint(text, fsize)) / 2); app.ShowText(text); app.EndText(); app.RestoreState(); return(app); }