silverlight 1.0:Downloader对象

Using SetFontSource for Downloaded Fonts

The SetFontSource method can be used as a way of adding downloaded font content to the existing collection of type faces for a TextBlock object. The downloader parameter identifies the Downloader object representing the downloaded content. The downloaded content can either be an individual font file or packaged content, such as a Zip file, that contains one or more font files.

Note: Font files used with the SetFontSource method must be OpenType or TrueType® fonts, and have the file extension, "TTF".

The following JavaScript example shows how to use the Downloader object to download an individual font file.

JavaScript
// Event handler for initializing and executing a font file download request.
            function onMouseLeftButtonUp(sender, eventArgs)
            {
            // Retrieve a reference to the control.
            var control = sender.getHost();
            // Create a Downloader object.
            var downloader = control.createObject("downloader");
            // Add Completed event.
            downloader.addEventListener("Completed", "onCompleted");
            // Initialize the Downloader request.
            downloader.open("GET", "SHOWG.TTF", true);
            // Execute the Downloader request.
            downloader.send();
            }
            

When the font file has been downloaded, it needs to be added to the TextBlock's collection of type faces. Once it has been added to the collection, it can then be selected using the FontFamily property. The following JavaScript example shows how to use the SetFontSource method to add the the font file to the type face collection, and then set the FontFamily property to display the TextBlock with the downloaded font:

JavaScript
// Event handler for the Completed event.
            function onCompleted(sender, eventArgs)
            {
            // Retrieve the TextBlock object.
            var myTextBlock = sender.findName("myTextBlock");
            // Add the font files in the downloaded object to the TextBlock's type face collection.
            myTextBlock.setFontSource(sender);
            // Set the FontFamily property to the friendly name of the font.
            myTextBlock.fontFamily = "Showcard Gothic";
            myTextBlock.text = "Showcard Gothic";
            }
            

You can also download font files contained in a packaged format, such as a Zip file. The Zip file can contain other content files, such as image files.

其实我们知道silverlight不支持中文就是因为没有相应的字体文件,通过下载我们提供的字体文件,我们可以让silverlight显示中文。网上有很多介绍这个的实现方式。

1072617.html?type=1

shore 2008-02-18 18:24 发表评论

转载于:https://www.cnblogs.com/hotsoho.net/archive/2008/02/18/1206556.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值