/** * Converts a PFM file into an AFM file. * @param inp the PFM file * @param outp the AFM file * @throws IOException on error */ public static void Convert(RandomAccessFileOrArray inp, Stream outp) { Pfm2afm p = new Pfm2afm(inp, outp); p.Openpfm(); p.Putheader(); p.Putchartab(); p.Putkerntab(); p.Puttrailer(); p.outp.Flush(); }
/** 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("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) { 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 { // 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(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(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(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(); }