Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        private void DoType1TT()
        {
            PdfObject enc = PdfReader.GetPdfObject(font.Get(PdfName.ENCODING));

            if (enc == null)
            {
                FillEncoding(null);
            }
            else
            {
                if (enc.IsName())
                {
                    FillEncoding((PdfName)enc);
                }
                else
                {
                    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;
                                }
                                ++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);
                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;
                for (int k = 0; k < newWidths.Size; ++k)
                {
                    widths[f + k] = newWidths.GetAsNumber(k).IntValue;
                }
            }
            FillFontDesc(font.GetAsDict(PdfName.FONTDESCRIPTOR));
        }
Ejemplo n.º 3
0
        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));
        }
        /// <summary>
        /// Creates a new Type1 font.
        /// @throws DocumentException the AFM file is invalid
        /// @throws IOException the AFM file could not be read
        /// </summary>
        /// <param name="ttfAfm">the AFM file if the input is made with a  byte  array</param>
        /// <param name="pfb">the PFB file if the input is made with a  byte  array</param>
        /// <param name="afmFile">the name of one of the 14 built-in fonts or the location of an AFM file. The file must end in '.afm'</param>
        /// <param name="enc">the encoding to be applied to this font</param>
        /// <param name="emb">true if the font is to be embedded in the PDF</param>
        /// <param name="forceRead"></param>
        internal Type1Font(string afmFile, string enc, bool emb, byte[] ttfAfm, byte[] pfb, bool forceRead)
        {
            if (emb && ttfAfm != null && pfb == null)
            {
                throw new DocumentException("Two byte arrays are needed if the Type1 font is embedded.");
            }

            if (emb && ttfAfm != null)
            {
                Pfb = pfb;
            }

            encoding  = enc;
            Embedded  = emb;
            _fileName = afmFile;
            FontType  = FONT_TYPE_T1;
            RandomAccessFileOrArray rf = null;
            Stream istr = null;

            if (BuiltinFonts14.ContainsKey(afmFile))
            {
                Embedded     = false;
                _builtinFont = true;
                var buf = new byte[1024];
                try
                {
                    istr = GetResourceStream(RESOURCE_PATH + afmFile + ".afm");
                    if (istr == null)
                    {
                        Console.Error.WriteLine(afmFile + " not found as resource.");
                        throw new DocumentException(afmFile + " not found as resource.");
                    }
                    var ostr = new MemoryStream();
                    while (true)
                    {
                        var size = istr.Read(buf, 0, buf.Length);
                        if (size == 0)
                        {
                            break;
                        }

                        ostr.Write(buf, 0, size);
                    }
                    buf = ostr.ToArray();
                }
                finally
                {
                    if (istr != null)
                    {
                        try
                        {
                            istr.Dispose();
                        }
                        catch
                        {
                            // empty on purpose
                        }
                    }
                }
                try
                {
                    rf = new RandomAccessFileOrArray(buf);
                    Process(rf);
                }
                finally
                {
                    if (rf != null)
                    {
                        try
                        {
                            rf.Close();
                        }
                        catch
                        {
                            // empty on purpose
                        }
                    }
                }
            }
            else if (afmFile.ToLowerInvariant().EndsWith(".afm"))
            {
                try
                {
                    if (ttfAfm == null)
                    {
                        rf = new RandomAccessFileOrArray(afmFile, forceRead);
                    }
                    else
                    {
                        rf = new RandomAccessFileOrArray(ttfAfm);
                    }

                    Process(rf);
                }
                finally
                {
                    if (rf != null)
                    {
                        try
                        {
                            rf.Close();
                        }
                        catch
                        {
                            // empty on purpose
                        }
                    }
                }
            }
            else if (afmFile.ToLowerInvariant().EndsWith(".pfm"))
            {
                try
                {
                    var ba = new MemoryStream();
                    if (ttfAfm == null)
                    {
                        rf = new RandomAccessFileOrArray(afmFile, forceRead);
                    }
                    else
                    {
                        rf = new RandomAccessFileOrArray(ttfAfm);
                    }

                    Pfm2Afm.Convert(rf, ba);
                    rf.Close();
                    rf = new RandomAccessFileOrArray(ba.ToArray());
                    Process(rf);
                }
                finally
                {
                    if (rf != null)
                    {
                        try
                        {
                            rf.Close();
                        }
                        catch
                        {
                            // empty on purpose
                        }
                    }
                }
            }
            else
            {
                throw new DocumentException(afmFile + " is not an AFM or PFM font file.");
            }

            _encodingScheme = _encodingScheme.Trim();
            if (_encodingScheme.Equals("AdobeStandardEncoding") || _encodingScheme.Equals("StandardEncoding"))
            {
                FontSpecific = false;
            }
            if (!encoding.StartsWith("#"))
            {
                PdfEncodings.ConvertToBytes(" ", enc); // check if the encoding exists
            }

            CreateEncoding();
        }
Ejemplo n.º 5
0
        /** Creates a new Type1 font.
         * @param ttfAfm the AFM file if the input is made with a <CODE>byte</CODE> array
         * @param pfb the PFB file if the input is made with a <CODE>byte</CODE> array
         * @param afmFile the name of one of the 14 built-in fonts or the location of an AFM file. The file must end in '.afm'
         * @param enc the encoding to be applied to this font
         * @param emb true if the font is to be embedded in the PDF
         * @throws DocumentException the AFM file is invalid
         * @throws IOException the AFM file could not be read
         */
        internal Type1Font(string afmFile, string enc, bool emb, byte[] ttfAfm, byte[] pfb, bool forceRead)
        {
            if (emb && ttfAfm != null && pfb == null)
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("two.byte.arrays.are.needed.if.the.type1.font.is.embedded"));
            }
            if (emb && ttfAfm != null)
            {
                this.pfb = pfb;
            }
            encoding = enc;
            embedded = emb;
            fileName = afmFile;
            FontType = FONT_TYPE_T1;
            RandomAccessFileOrArray rf = null;
            Stream istr = null;

            if (BuiltinFonts14.ContainsKey(afmFile))
            {
                embedded    = false;
                builtinFont = true;
                byte[] buf = new byte[1024];
                try {
                    istr = GetResourceStream(RESOURCE_PATH + afmFile + ".afm");
                    if (istr == null)
                    {
                        string msg = MessageLocalization.GetComposedMessage("1.not.found.as.resource", afmFile);
                        Console.Error.WriteLine(msg);
                        throw new DocumentException(msg);
                    }
                    MemoryStream ostr = new MemoryStream();
                    while (true)
                    {
                        int size = istr.Read(buf, 0, buf.Length);
                        if (size == 0)
                        {
                            break;
                        }
                        ostr.Write(buf, 0, size);
                    }
                    buf = ostr.ToArray();
                }
                finally {
                    if (istr != null)
                    {
                        try {
                            istr.Close();
                        }
                        catch {
                            // empty on purpose
                        }
                    }
                }
                try {
                    rf = new RandomAccessFileOrArray(buf);
                    Process(rf);
                }
                finally {
                    if (rf != null)
                    {
                        try {
                            rf.Close();
                        }
                        catch {
                            // empty on purpose
                        }
                    }
                }
            }
            else if (afmFile.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".afm"))
            {
                try {
                    if (ttfAfm == null)
                    {
                        rf = new RandomAccessFileOrArray(afmFile, forceRead);
                    }
                    else
                    {
                        rf = new RandomAccessFileOrArray(ttfAfm);
                    }
                    Process(rf);
                }
                finally {
                    if (rf != null)
                    {
                        try {
                            rf.Close();
                        }
                        catch {
                            // empty on purpose
                        }
                    }
                }
            }
            else if (afmFile.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".pfm"))
            {
                try {
                    MemoryStream ba = new MemoryStream();
                    if (ttfAfm == null)
                    {
                        rf = new RandomAccessFileOrArray(afmFile, forceRead);
                    }
                    else
                    {
                        rf = new RandomAccessFileOrArray(ttfAfm);
                    }
                    Pfm2afm.Convert(rf, ba);
                    rf.Close();
                    rf = new RandomAccessFileOrArray(ba.ToArray());
                    Process(rf);
                }
                finally {
                    if (rf != null)
                    {
                        try {
                            rf.Close();
                        }
                        catch  {
                            // empty on purpose
                        }
                    }
                }
            }
            else
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("1.is.not.an.afm.or.pfm.font.file", afmFile));
            }
            EncodingScheme = EncodingScheme.Trim();
            if (EncodingScheme.Equals("AdobeStandardEncoding") || EncodingScheme.Equals("StandardEncoding"))
            {
                fontSpecific = false;
            }
            if (!encoding.StartsWith("#"))
            {
                PdfEncodings.ConvertToBytes(" ", enc); // check if the encoding exists
            }
            CreateEncoding();
        }
        private void doType1Tt()
        {
            PdfObject enc = PdfReader.GetPdfObject(_font.Get(PdfName.Encoding));

            if (enc == null)
            {
                fillEncoding(null);
            }
            else
            {
                if (enc.IsName())
                {
                    fillEncoding((PdfName)enc);
                }
                else
                {
                    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;
                                }
                                ++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 = 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);
                _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;
                for (int k = 0; k < newWidths.Size; ++k)
                {
                    widths[f + k] = newWidths.GetAsNumber(k).IntValue;
                }
            }
            fillFontDesc(_font.GetAsDict(PdfName.Fontdescriptor));
        }
Ejemplo n.º 7
0
        /** Creates a new Type1 font.
         * @param ttfAfm the AFM file if the input is made with a <CODE>byte</CODE> array
         * @param pfb the PFB file if the input is made with a <CODE>byte</CODE> array
         * @param afmFile the name of one of the 14 built-in fonts or the location of an AFM file. The file must end in '.afm'
         * @param enc the encoding to be applied to this font
         * @param emb true if the font is to be embedded in the PDF
         * @throws DocumentException the AFM file is invalid
         * @throws IOException the AFM file could not be read
         */
        internal Type1Font(string afmFile, string enc, bool emb, byte[] ttfAfm, byte[] pfb)
        {
            if (emb && ttfAfm != null && pfb == null)
            {
                throw new DocumentException("Two byte arrays are needed if the Type1 font is embedded.");
            }
            if (emb && ttfAfm != null)
            {
                this.pfb = pfb;
            }
            encoding = enc;
            embedded = emb;
            fileName = afmFile;
            FontType = FONT_TYPE_T1;
            RandomAccessFileOrArray rf = null;
            Stream istr = null;

            if (BuiltinFonts14.ContainsKey(afmFile))
            {
                embedded    = false;
                builtinFont = true;
                byte[] buf = new byte[1024];
                try {
                    istr = getResourceStream(afmFile + ".afm");
                    if (istr == null)
                    {
                        Console.Error.WriteLine(afmFile + " not found as resource.");
                        throw new DocumentException(afmFile + " not found as resource.");
                    }
                    MemoryStream ostr = new MemoryStream();
                    while (true)
                    {
                        int size = istr.Read(buf, 0, buf.Length);
                        if (size == 0)
                        {
                            break;
                        }
                        ostr.Write(buf, 0, size);
                    }
                    buf = ostr.ToArray();
                }
                finally {
                    if (istr != null)
                    {
                        try {
                            istr.Close();
                        }
                        catch (Exception e) {
                            e.GetType();
                            // empty on purpose
                        }
                    }
                }
                try {
                    rf = new RandomAccessFileOrArray(buf);
                    process(rf);
                }
                finally {
                    if (rf != null)
                    {
                        try {
                            rf.close();
                        }
                        catch (Exception e) {
                            e.GetType();
                            // empty on purpose
                        }
                    }
                }
            }
            else if (afmFile.ToLower().EndsWith(".afm"))
            {
                try {
                    if (ttfAfm == null)
                    {
                        rf = new RandomAccessFileOrArray(afmFile);
                    }
                    else
                    {
                        rf = new RandomAccessFileOrArray(ttfAfm);
                    }
                    process(rf);
                }
                finally {
                    if (rf != null)
                    {
                        try {
                            rf.close();
                        }
                        catch (Exception e) {
                            e.GetType();
                            // empty on purpose
                        }
                    }
                }
            }
            else
            {
                throw new DocumentException(afmFile + " is not an AFM font file.");
            }
            try {
                EncodingScheme = EncodingScheme.Trim();
                if (EncodingScheme.Equals("AdobeStandardEncoding") || EncodingScheme.Equals("StandardEncoding"))
                {
                    fontSpecific = false;
                }
                System.Text.Encoding.GetEncoding(enc).GetBytes(" ");
                createEncoding();
            }
            catch (Exception e) {
                throw new DocumentException(e.Message);
            }
        }