public void RealizeFont(Glyphs glyphs)
{
var absURI = glyphs.FontUri;
if (!glyphs.FontUri.IsAbsoluteUri)
{
var uriCtx = glyphs as System.Windows.Markup.IUriContext;
var host = uriCtx.BaseUri.Host;
absURI = new Uri("pack://" + host + glyphs.FontUri.OriginalString, UriKind.Absolute);
}
var nameInPdf = "";
KeyValuePair <string, PdfFont> exist;
if (_fonts.TryGetValue(absURI.OriginalString, out exist))
{
this.realizedFont = exist.Value;
nameInPdf = exist.Key;
}
else
{
GlyphTypeface typeFace =
new GlyphTypeface(absURI);
string name = String.Format("XPS-Font-{0:00}", ++fontCount);
name = PdfFont.CreateEmbeddedFontSubsetName(name);
var fontStream = typeFace.GetFontStream();
var memStream = new System.IO.MemoryStream();
var buff = new byte[512];
int len = 0;
while ((len = fontStream.Read(buff, 0, buff.Length)) > 0)
{
memStream.Write(buff, 0, len);
}
var fontData = memStream.ToArray();
Font font = new Font(name, fontData);
nameInPdf = writer.GetFontName(font);
_fonts.Add(absURI.OriginalString, new KeyValuePair <string, PdfFont>(
nameInPdf, font.PdfFont));
this.realizedFont = font.PdfFont;
}
//if (fontName != this.realizedFontName || this.realizedFontSize != font.Size)
{
//this.writer.WriteLiteral("{0} {1:0.###} Tf\n", fontName, -glyphs.FontRenderingEmSize);
this.writer.WriteLiteral("{0} {1:0.###} Tf\n", nameInPdf, -glyphs.FontRenderingEmSize);
//this.realizedFontName = fontName;
//this.realizedFontSize = font.Size;
}
}