iTextSharp.text.pdf.DocumentFont.DoType1TT C# (CSharp) Метод

DoType1TT() приватный Метод

private DoType1TT ( ) : void
Результат void
        private void DoType1TT()
        {
            CMapToUnicode toUnicode = null;
            PdfObject enc = PdfReader.GetPdfObject(font.Get(PdfName.ENCODING));
            if (enc == null) {
                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;
                    }
                }
            }
            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;
                                    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.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;
                    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));
        }