void Initialize()
{
bool embeddingRestricted = this.fontData.os2.fsType == 0x0002;
//this.fontName = image.n
this.italicAngle = this.fontData.post.italicAngle;
this.xMin = this.fontData.head.xMin;
this.yMin = this.fontData.head.yMin;
this.xMax = this.fontData.head.xMax;
this.yMax = this.fontData.head.yMax;
this.underlinePosition = this.fontData.post.underlinePosition;
this.underlineThickness = this.fontData.post.underlineThickness;
this.strikeoutPosition = this.fontData.os2.yStrikeoutPosition;
this.strikeoutSize = this.fontData.os2.yStrikeoutSize;
// No documetation found how to get the set vertical stems width from the
// TrueType tables.
// The following formula comes from PDFlib Lite source code. Acrobat 5.0 sets
// /StemV to 0 always. I think the value doesn't matter.
//float weight = (float)(this.image.os2.usWeightClass / 65.0f);
//this.stemV = (int)(50 + weight * weight); // MAGIC
this.stemV = 0;
// PDFlib states that some Apple fonts miss the OS/2 table.
Debug.Assert(fontData.os2 != null, "TrueType font has no OS/2 table.");
this.unitsPerEm = fontData.head.unitsPerEm;
// PDFlib takes sTypoAscender and sTypoDescender from OS/2 tabel, but GDI+ uses usWinAscent and usWinDescent
if (fontData.os2.sTypoAscender != 0)
this.ascender = fontData.os2.usWinAscent;
else
this.ascender = fontData.hhea.ascender;
Debug.Assert(this.ascender > 0, "PDFsharp internal: Ascender should be greater than 0.");
if (fontData.os2.sTypoDescender != 0)
{
this.descender = fontData.os2.usWinDescent;
Debug.Assert(this.descender > 0, "PDFsharp internal: Font with non positive ascender value found.");
#if true_
Debug.WriteLine(String.Format(CultureInfo.InvariantCulture,
"os2.usWinDescent={0}, hhea.descender={1}, os2.sTypoDescender={2}", fontData.os2.usWinDescent, fontData.hhea.descender, fontData.os2.sTypoDescender));
#endif
// Force sign from hhea.descender
// TODO:
this.descender = Math.Abs(this.descender) * Math.Sign(fontData.hhea.descender);
}
else
this.descender = fontData.hhea.descender;
Debug.Assert(this.descender < 0, "PDFsharp internal: Ascender should be less than 0.");
this.leading = fontData.hhea.lineGap;
// sCapHeight and sxHeight are only valid if version >= 2
if (fontData.os2.version >= 2 && fontData.os2.sCapHeight != 0)
this.capHeight = fontData.os2.sCapHeight;
else
this.capHeight = fontData.hhea.ascender;
if (fontData.os2.version >= 2 && fontData.os2.sxHeight != 0)
this.xHeight = fontData.os2.sxHeight;
else
this.xHeight = (int)(0.66f * this.ascender);
//this.flags = this.image.
Encoding ansi = PdfEncoders.WinAnsiEncoding; // System.Text.Encoding.Default;
Encoding unicode = System.Text.Encoding.Unicode;
byte[] bytes = new byte[256];
bool symbol = this.fontData.cmap.symbol;
this.widths = new int[256];
for (int idx = 0; idx < 256; idx++)
{
bytes[idx] = (byte)idx;
// PDFlib handles some font flaws here...
// We wait for bug reports.
char ch = (char)idx;
string s = ansi.GetString(bytes, idx, 1);
if (s.Length != 0)
{
if (s[0] != ch)
ch = s[0];
}
#if DEBUG
if (idx == (int)'S')
GetType();
#endif
int glyphIndex;
if (symbol)
{
glyphIndex = idx + (this.fontData.os2.usFirstCharIndex & 0xFF00);
glyphIndex = CharCodeToGlyphIndex((char)glyphIndex);
}
else
{
//Debug.Assert(idx + (this.fontData.os2.usFirstCharIndex & 0xFF00) == idx);
//glyphIndex = CharCodeToGlyphIndex((char)idx);
glyphIndex = CharCodeToGlyphIndex(ch);
}
this.widths[idx] = GlyphIndexToPdfWidth(glyphIndex);
}
}
public int[] widths;