/// <summary> /// Converts a PFM file into an AFM file. /// @throws IOException on error /// </summary> /// <param name="inp">the PFM file</param> /// <param name="outp">the AFM file</param> public static void Convert(RandomAccessFileOrArray inp, Stream outp) { var p = new Pfm2Afm(inp, outp); p.openpfm(); p.putheader(); p.putchartab(); p.putkerntab(); p.puttrailer(); p._outp.Flush(); }
/// <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(); }