Silverlight 2 RTW读取XPS解决方案

Silverlight 2 RTW读取XPS解决方案,第1张

概述Lighting up the XML Paper Specification [Proof-of-concept XPS reader for Silverlight!] Since getting involved with Silverlight and finding out the XPS document type WPF enables has XAML at its core, I lighting up the XML Paper Specification [Proof-of-concept XPS reader for Silverlight!]
Since getting involved with Silverlight and finding out the XPS document type WPF enables has XAML at its core,I've been wondering how Silverlight would do as a lightweight XPS vIEwer. First,a bit of background: WPF is the windows Presentation Foundation and represents a new approach to UI for windows. XPS refers to the XML Paper Specification,a device-independent file format for flexible document representation (think pdf) that's part of Office 2007 and .NET 3.0. WPF offers rich support for displaying XPS documents via its documentVIEwer and Xpsdocument classes (among others). Because the 1.1 Alpha release doesn't currently include the relevant classes,Silverlight wouldn't appear to be well suited for XPS document display at first glance... However,Silverlight does have the Downloader class which includes support for packages (for the purposes of this discussion,packages are basically just ZIP archives). Since an XPS document is really just a package,and the core document format XPS uses is XAML,and Silverlight speaks XAML (well,at least a subset of it!),maybe it's not such a stretch to do XPS with Silverlight after all. I thought it would be a neat exercise to try to write an XPS vIEwer with the publically available Silverlight 1.1 Alpha bits so I gave it a try and ended up with an application I call SimpleSilverlightXpsVIEwer:  

Go ahead and click here (or on the image above) to play around with the application in your browser. If you find yourself wondering how it works,just click here to download the complete source code/resources and play around with it yourself! (To build the SimpleSilverlightXpsVIEwer project,you'll want to use Orcas Beta 1 and the Silverlight Tools.) Of course,this is just a proof-of-concept application built on an Alpha platform,so there are some rough edges. :) Some notes are in order: I created my own XPS documents so I wouldn't have to worry about getting permission to use someone else's XPS documents. Office 2007 comes with a handy "Microsoft XPS document Writer" printer driver that lets you create an XPS document from any application simply by printing to the XPS "printer" (which then saves the resulting output to a file you specify). I created the three sample documents this way: the "Intro" document came from a simple Word document,the "Blog" document came from my blog via ie7,and the "Site" document came from the Silverlight Forums via ie7 with a landscape page layout.
Because the only kind of XPS document I've worked with is the kind the XPS printer driver outputs,there's a very good chance SimpleSilverlightXpsVIEwer won't understand the internal format of other valID XPS files. Remember,though,that I dIDn't set out to write an XPS file parser - I just set out to write a simple XPS vIEwer for Silverlight. :)
The translation of "XPS XAML" to "Silverlight XAML" is done by the XpsToSilverlightXamlReader class,a minimal derivation from XmlReader that performs on-the-fly modification of the "XPS XAML" to translate it into "Silverlight XAML". Specifically,some elements are renamed,some attribute values are tweaked,and some attributes are removed entirely. The tweaking is done to address the Glyphs.FontUri/ImageBrush.ImageSource issue mentioned next and re-points the relevant content to an external location.
XPS documents are entirely self-contained,with any necessary Fonts and images embedded in the file (package) itself. This is great for simplifying distribution and Silverlight's Downloader class makes it easy to get at indivIDual files in a package. However,SimpleSilverlightXpsVIEwer works best when the images and the Fonts are extracted from the XPS file:
Under the right conditions,embedded images can be fetched by Silverlight by using the ImageBrush.SetSource method. However,things tend to break if there are multiple references to the same image in a single page (an exception is thrown when the second call to SetSource is made),so SimpleSilverlightXpsVIEwer doesn't enable this by default. Interested partIEs can #define SETSOURCE (for both C# files) to experiment with this feature (things work fine for the first page of all of the sample documents,but break on the second pages of the Blog and Site documents).
The default behavior of Glyphs.FontUri does not seem to automatically pull the Font out of the package - at least not as it's used by SimpleSilverlightXpsVIEwer (possibly because Silverlight doesn't seem to like the leading '/' on package-relative paths). TextBlock has a SetFontSource method that seems interesting,but XPS XAML uses the Glyphs class which doesn't seem to support SetFontSource.
For some reason,the XPS documents generated by the XPS printer driver aren't directly open-able by Silverlight's Downloader (a COM exception is thrown). However,I've found that a quick un-ZIP/re-ZIP with either of my favorite ZIP tools yIElds XPS documents that open right up. I SUSPECT this is due to a simple issue with the Alpha Downloader implementation (endian-ness of the ZIP file,some special section embedded by the XPS printer driver,etc.) that Could be fixed by the Silverlight team without much difficulty.
Silverlight doesn't support the TIFF file format (which is not surprising because full support can be quite complex and TIFF images are hardly ever used on the web). As it happens,XPS printer driver output may contain TIFF images (it seems they're used as a mask of some kind behind another PNG or JPG image) - SimpleSilverlightXpsVIEwer simply ignores the TIFF images and neatly sIDe-steps the support issue. :)
While SimpleSilverlightXpsVIEwer is a cute proof-of-concept application I enjoyed writing,it is hardly the final word on Silverlight XPS support. (hey,I'm not even on the Silverlight team!) I don't kNow what the official plans are for more formal XPS support in the Silverlight platform,but my experIEnce with SimpleSilverlightXpsVIEwer suggests that most of the pIEces are already in place for a pretty reasonable XPS experIEnce with the Silverlight 1.1 Alpha. Throw in a couple of tweaks to Silverlight (and/or SimpleSilverlightXpsVIEwer!),and it should be possible to provIDe a pretty compelling XPS-like user experIEnce for Silverlight! REF:http://blogs.msdn.com/delay/archive/2007/05/22/lighting-up-the-xml-paper-specification-proof-of-concept-xps-reader-for-silverlight.aspx 总结

以上是内存溢出为你收集整理的Silverlight 2 RTW读取XPS解决方案全部内容,希望文章能够帮你解决Silverlight 2 RTW读取XPS解决方案所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1052380.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存