📄 type1fontdata.cs
字号:
case "FontName": { sFontName = asToken[1]; break; }
case "FullName": { sFullName = asToken[1]; break; }
case "FamilyName": { sFamilyName = asToken[1]; break; }
case "Weight": { sWeight = asToken[1]; break; }
case "FontBBox": {
fFontBBox_llx = Single.Parse(asToken[1]);
fFontBBox_lly = Single.Parse(asToken[2]);
fFontBBox_urx = Single.Parse(asToken[3]);
fFontBBox_ury = Single.Parse(asToken[4]);
break;
}
case "Version": { sVersion = asToken[1]; break; }
case "Notice": { sNotice = sLine.Substring(7); break; }
case "EncodingScheme": { sEncodingScheme = asToken[1]; break; }
case "CharacterSet": { sCharacterSet = asToken[1]; break; }
case "IsBaseFont": { bIsBaseFont = Boolean.Parse(asToken[1]); break; }
case "CapHeight": { fCapHeight = Single.Parse(asToken[1]); break; }
case "XHeight": { fXHeight = Single.Parse(asToken[1]); break; }
case "Ascender": { fAscender = Single.Parse(asToken[1]); break; }
case "Descender": { fDescender = Single.Parse(asToken[1]); break; }
case "StdHW": { fStdHW = Single.Parse(asToken[1]); break; }
case "StdVW": { fStdVW = Single.Parse(asToken[1]); break; }
case "UnderlinePosition": { fUnderlinePosition = Single.Parse(asToken[1]); break; }
case "UnderlineThickness": { fUnderlineThickness = Single.Parse(asToken[1]); break; }
case "ItalicAngle": { fItalicAngle = Single.Parse(asToken[1]); break; }
case "IsFixedPitch": { bIsFixedPitch = Boolean.Parse(asToken[1]); break; }
case "StartCharMetrics": { iCharMetricsCount = Int32.Parse(asToken[1]); goto EndGeneralInfo; }
default: {
Debug.Fail("Unknown token [" + asToken[0] + "] in AFM file: " + sFontName);
break;
}
}
NextLine:
sLine = streamReader.ReadLine();
} while (sLine != null);
EndGeneralInfo:
// check for required fields
Debug.Assert(sFontMetricsVersion != null);
Debug.Assert(iMetricsSets == 0);
if (sFontName == null) {
throw new ReportException("FontName is required in AFM file: " + sFontName);
}
if (Single.IsNaN(fFontBBox_llx) || Single.IsNaN(fFontBBox_lly) || Single.IsNaN(fFontBBox_urx) || Single.IsNaN(fFontBBox_ury)) {
throw new ReportException("FontBBox is required in AFM file: " + sFamilyName);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -x
// character metrics
if (iCharMetricsCount <= 0) {
throw new ReportException("Character metrics expected in AFM file: " + sFontName);
}
aCharMetrics = new CharMetrics[AdobeFromUnicode.aiAdobeFromUnicode.Length]; // !!!
for (Int32 iLine = 0; iLine < iCharMetricsCount; iLine++) {
sLine = streamReader.ReadLine();
if (sLine == null) {
throw new ReportException("More character metrics definitions expected in AFM file: " + sFontName);
}
new CharMetrics(sLine, this);
}
sLine = streamReader.ReadLine();
if (!sLine.StartsWith("EndCharMetrics")) {
throw new ReportException("Token [EndCharMetrics] expected in AFM file: " + sFontName);
}
aCharMetrics[173] = aCharMetrics[45]; // same character definition
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -x
// kerning data
sLine = streamReader.ReadLine();
//if (!sLine.StartsWith("StartKernData")) {
// throw new ReportException("Token [StartKernData] expected in AFM file: " + sFontName);
//}
}
finally {
streamReader.Close();
}
}
//----------------------------------------------------------------------------------------------------x
// <summary></summary>
// <returns></returns>
//private Boolean bIsBuiltinFont14() {
// return "Courier,Helvetica,Symbol,Times-Roman,ZapfDingbats".IndexOf(sName) >= 0;
//}
//====================================================================================================x
/// <summary>AFM Character Metrics</summary>
/// <example><code>C 102 ; WX 333 ; N f ; B 20 0 383 683 ; L i fi ; L l fl ;</code></example>
public class CharMetrics {
/// <summary>Character code</summary>
internal Int32 iCharacterCode = -1;
/// <summary>Horizontal character width for writing direction 0</summary>
internal Single fWidthX = 250;
/// <summary>Character name</summary>
internal String sName;
/// <summary>Font box</summary>
internal Single fBBox_llx;
internal Single fBBox_lly;
internal Single fBBox_urx;
internal Single fBBox_ury;
/// <summary>Ligature sequence</summary>
internal ArrayList al_Ligature;
//----------------------------------------------------------------------------------------------------x
/// <summary></summary>
/// <param name="sLine"></param>
/// <param name="type1FontData"></param>
internal CharMetrics(String sLine, Type1FontData type1FontData) {
String[] asLineToken = sLine.Split(Type1FontData.acDelimiterSemicolon, 10);
if (asLineToken.Length <= 2) {
throw new ReportException("Invalid character metrics definition in AFM file: " + type1FontData.sFontName);
}
for (Int32 iExpr = 0; iExpr < asLineToken.Length; iExpr++) {
if (asLineToken[iExpr].Length == 0) {
continue;
}
String[] asToken = asLineToken[iExpr].Trim().Split(acDelimiterToken, 5);
switch (asToken[0]) {
case "C": { iCharacterCode = Int32.Parse(asToken[1], CultureInfo.InvariantCulture); break; }
case "CH": { iCharacterCode = Int32.Parse(asToken[1], System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture); break; }
case "WX": case "W0X": { fWidthX = Single.Parse(asToken[1], CultureInfo.InvariantCulture); break; }
case "N": { sName = asToken[1]; break; }
case "B": {
fBBox_llx = Single.Parse(asToken[1]);
fBBox_lly = Single.Parse(asToken[2]);
fBBox_urx = Single.Parse(asToken[3]);
fBBox_ury = Single.Parse(asToken[4]);
break;
}
case "L": {
if (al_Ligature == null) {
al_Ligature = new ArrayList(10);
}
al_Ligature.Add(new Ligature(asToken[1], asToken[2]));
break;
}
default: {
Debug.Fail("Unknown token [" + asToken[0] + "] in AFM file: " + type1FontData.sFontName);
break;
}
}
}
// find index
Int32 iIndex = iCharacterCode;
if (type1FontData.sFontName != "Symbol" && type1FontData.sFontName != "ZapfDingbats") {
switch (iIndex) {
case 39: iIndex = 0; break; // quoteright
case 96: iIndex = 0; break; // quoteleft
case 127: iIndex = -1; break; // does not exist!
case 128: iIndex = -1; break; // does not exist!
case 129: iIndex = -1; break; // does not exist!
case 130: iIndex = -1; break; // does not exist!
case 131: iIndex = -1; break; // does not exist!
case 132: iIndex = -1; break; // does not exist!
case 133: iIndex = -1; break; // does not exist!
case 134: iIndex = -1; break; // does not exist!
case 135: iIndex = -1; break; // does not exist!
case 136: iIndex = -1; break; // does not exist!
case 137: iIndex = -1; break; // does not exist!
case 138: iIndex = -1; break; // does not exist!
case 139: iIndex = -1; break; // does not exist!
case 140: iIndex = -1; break; // does not exist!
case 141: iIndex = -1; break; // does not exist!
case 142: iIndex = -1; break; // does not exist!
case 143: iIndex = -1; break; // does not exist!
case 144: iIndex = -1; break; // does not exist!
case 145: iIndex = -1; break; // does not exist!
case 146: iIndex = -1; break; // does not exist!
case 147: iIndex = -1; break; // does not exist!
case 148: iIndex = -1; break; // does not exist!
case 149: iIndex = -1; break; // does not exist!
case 150: iIndex = -1; break; // does not exist!
case 151: iIndex = -1; break; // does not exist!
case 152: iIndex = -1; break; // does not exist!
case 153: iIndex = -1; break; // does not exist!
case 154: iIndex = -1; break; // does not exist!
case 155: iIndex = -1; break; // does not exist!
case 156: iIndex = -1; break; // does not exist!
case 157: iIndex = -1; break; // does not exist!
case 158: iIndex = -1; break; // does not exist!
case 159: iIndex = -1; break; // does not exist!
case 160: iIndex = -1; break; // does not exist!
case 164: iIndex = 0; break; // fraction "/"
case 166: iIndex = 0; break; // florin
case 168: iIndex = 164; break; // currency "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -