internal override float GetCharWidth(char c, float fontSize) { PDFArray widths = GetDictionary()["Widths"] as PDFArray; if (widths != null) { PDFNumber fc = GetDictionary()["FirstChar"] as PDFNumber; int firstChar = 0; if (fc != null) { firstChar = (int)fc.GetValue(); } int glyf = getGlyf(c); PDFNumber w = widths[glyf - firstChar] as PDFNumber; if (w != null) { return((float)(w.GetValue() * fontSize / 1000.0f)); } } else { StandardFonts font; if (isStandardFont(out font)) { IGlyfMetrics metrics = getStandardFontMetrics(font); return(metrics.GetCharWidth(c) * fontSize / 1000.0f); } } return(0); }
internal override float GetTextWidth(PDFString str, float fontSize) { PDFArray widths = GetDictionary()["Widths"] as PDFArray; byte[] data = str.GetBytes(); float result = 0; if (widths != null) { PDFNumber fc = GetDictionary()["FirstChar"] as PDFNumber; int firstChar = 0; if (fc != null) { firstChar = (int)fc.GetValue(); } for (int i = 0; i < data.Length; ++i) { PDFNumber w = widths[data[i] - firstChar] as PDFNumber; if (w != null) { result += (float)w.GetValue(); } } return(result * fontSize / 1000.0f); } StandardFonts font; if (isStandardFont(out font)) { IGlyfMetrics metrics = getStandardFontMetrics(font); string tmp = ConvertFromFontEncoding(str); for (int i = 0; i < tmp.Length; ++i) { result += metrics.GetCharWidth(tmp[i]); } } return(result * fontSize / 1000.0f); }