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();
}