前面的操作方法请参考此文:http://silverlight.cn/forums/thread/549.aspx

我使用的是方案二:

* 首先使用Word或者写字板应用程序,使用您中意的字体输入你的Silverlight中所需要的文字;
* 然后在Word或者写字板当中选择“打印”功能,打印机选择Microsoft XPS Document Writer(在您安装了.NET 3.0 Framework)后会自动增加;
* XPS Document Writer本身是一个打印到文件功能,在其文件选择框中选择文件路径,并且给出相应的文件名;
* 打印完成后,在文件浏览器中找到完成的XPS文件,并且将其后缀名由”.xps”修改为”.zip”;(其实微软的好多文件格式目前都使用了ZIP格式,比如Office 2007中的DOCX、PPTX、XLSX等等,都可以将名字改为ZIP后缀名,并且使用WinZip或者其它文件压缩程序打开)
* 直接找到这个压缩文件包中的“\documents\1\resources\fonts”中的文件,并且将其提取出来,这个文件名大部分为一个GUID加一个ODTTF后缀名;
* 将提取出来的ODTTF文件再次使用ZIP格式打包成myfonts.zip文件,并且放在您的Silverlight应用程序的根目录中;

我用的是C#来实现更改字体,写了个方法,代码如下:(TextBlock名字为testText,字体压缩包名字为fonts.zip)

void BeginLoadFonts()
{
Downloader down = new Downloader();
down.Completed += new EventHandler(down_Completed);
down.Open(“GET”, new Uri(“http://localhost/p/fonts.zip”));
down.Send();
}

void down_Completed(object sender, EventArgs e)
{
var down = sender as Downloader;
testText.SetFontSource(down);
testText.FontFamily = “SimSun”;
}

Page_Loaded事件中调用此方法就行了。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.