/// <exception cref="System.IO.IOException"/> public virtual RandomAccessFileOrArray GetMetricsFile() { isBuiltInFont = false; if (StandardFonts.IsStandardFont(afmPath)) { isBuiltInFont = true; byte[] buf = new byte[1024]; Stream resource = null; try { String resourcePath = FontResources.AFMS + afmPath + ".afm"; resource = ResourceUtil.GetResourceStream(resourcePath); if (resource == null) { throw new iText.IO.IOException("{0} was not found as resource.").SetMessageParams(resourcePath); } MemoryStream stream = new MemoryStream(); int read; while ((read = resource.Read(buf)) >= 0) { stream.Write(buf, 0, read); } buf = stream.ToArray(); } finally { if (resource != null) { try { resource.Dispose(); } catch (Exception) { } } } return(new RandomAccessFileOrArray(sourceFactory.CreateSource(buf))); } else { if (afmPath != null) { if (afmPath.ToLowerInvariant().EndsWith(".afm")) { return(new RandomAccessFileOrArray(sourceFactory.CreateBestSource(afmPath))); } else { if (afmPath.ToLowerInvariant().EndsWith(".pfm")) { MemoryStream ba = new MemoryStream(); RandomAccessFileOrArray rf = new RandomAccessFileOrArray(sourceFactory.CreateBestSource(afmPath)); Pfm2afm.Convert(rf, ba); rf.Close(); return(new RandomAccessFileOrArray(sourceFactory.CreateSource(ba.ToArray()))); } else { throw new iText.IO.IOException(iText.IO.IOException._1IsNotAnAfmOrPfmFontFile).SetMessageParams(afmPath); } } } else { if (afmData != null) { RandomAccessFileOrArray rf = new RandomAccessFileOrArray(sourceFactory.CreateSource(afmData)); if (IsAfmFile(rf)) { return(rf); } else { MemoryStream ba = new MemoryStream(); try { Pfm2afm.Convert(rf, ba); } catch (Exception) { throw new iText.IO.IOException("Invalid afm or pfm font file."); } finally { rf.Close(); } return(new RandomAccessFileOrArray(sourceFactory.CreateSource(ba.ToArray()))); } } else { throw new iText.IO.IOException("Invalid afm or pfm font file."); } } } }
/// <exception cref="System.IO.IOException"/> public virtual RandomAccessFileOrArray GetMetricsFile() { isBuiltInFont = false; if (FontConstants.BUILTIN_FONTS_14.Contains(afmPath)) { isBuiltInFont = true; byte[] buf = new byte[1024]; Stream resource = null; try { String resourcePath = FontConstants.AFM_RESOURCE_PATH + afmPath + ".afm"; resource = ResourceUtil.GetResourceStream(resourcePath); if (resource == null) { throw new iText.IO.IOException("1.not.found.as.resource").SetMessageParams(resourcePath); } MemoryStream stream = new MemoryStream(); int read; while ((read = resource.Read(buf)) >= 0) { stream.Write(buf, 0, read); } buf = stream.ToArray(); } finally { if (resource != null) { try { resource.Close(); } catch (Exception) { } } } return(new RandomAccessFileOrArray(sourceFactory.CreateSource(buf))); } else { if (afmPath != null) { if (afmPath.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".afm")) { return(new RandomAccessFileOrArray(sourceFactory.CreateBestSource(afmPath))); } else { if (afmPath.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".pfm")) { MemoryStream ba = new MemoryStream(); RandomAccessFileOrArray rf = new RandomAccessFileOrArray(sourceFactory.CreateBestSource(afmPath)); Pfm2afm.Convert(rf, ba); rf.Close(); return(new RandomAccessFileOrArray(sourceFactory.CreateSource(ba.ToArray()))); } else { throw new iText.IO.IOException(iText.IO.IOException._1IsNotAnAfmOrPfmFontFile).SetMessageParams(afmPath); } } } else { if (afmData != null) { RandomAccessFileOrArray rf = new RandomAccessFileOrArray(sourceFactory.CreateSource(afmData)); if (IsAfmFile(rf)) { return(rf); } else { MemoryStream ba = new MemoryStream(); try { Pfm2afm.Convert(rf, ba); } catch (Exception) { throw new iText.IO.IOException("invalid.afm.or.pfm.font.file"); } finally { rf.Close(); } return(new RandomAccessFileOrArray(sourceFactory.CreateSource(ba.ToArray()))); } } else { throw new iText.IO.IOException("invalid.afm.or.pfm.font.file"); } } } }