Silverlight 2 RTW读取XPS解决方案

本文介绍了一个使用Silverlight 2 RTW实现的XPS阅读器概念验证应用程序。虽然Silverlight 1.1 Alpha版本不包含显示XPS文档所需的类,但通过利用Downloader类支持的包功能,作者成功地创建了一个简单的XPS查看器。该应用能读取由XPS打印机驱动程序生成的文件,但可能无法解析其他类型的XPS文档。这是一个在Alpha平台上构建的概念验证应用,存在一些限制,如字体和图像处理问题,以及对TIFF格式的支持。尽管如此,它展示了Silverlight平台在支持XPS方面的潜力。
摘要由CSDN通过智能技术生成
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:

SimpleSilverlightXpsViewer Application

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

### 回答1: rtw.asap2setaddress是一个Matlab/Simulink中的命令,用于设置ASAP2文件的地址。 ASAP2(ASAM MCD-2MC)是一种用于描述汽车电子控制单元(ECU)的参数和测量数据的标准格式。这些数据包括特定ECU的内部参数、测量信号以及校准参数等。ASAP2文件通常由ECU供应商提供给汽车制造商,以便根据ECU的规格和要求进行校准和配置。 rtw.asap2setaddress命令的作用是为一个Simulink模型中的信号或参数设置ASAP2文件中的地址。在进行模型到ECU的代码生成过程中,该命令允许用户将模型中的信号映射到ASAP2文件中的相应位置。这样,代码生成工具就可以根据ASAP2文件的参数和地址信息,将模型中的信号正确地解析和输出到生成的代码中。 通过rtw.asap2setaddress命令,用户可以为每个需要映射的信号或参数指定ASAP2文件中的地址。这样做的好处是,ECU供应商可以使用相同的ASAP2文件来配置和校准不同的ECU,而无需修改源代码。同时,该命令还可以确保在ASAP2文件更新时,不会影响已经映射的信号和参数的地址。 总之,rtw.asap2setaddress是一个在Matlab/Simulink中用于设置ASAP2文件地址的命令。它为模型中的信号和参数提供了正确的映射关系,使得代码生成工具能够根据ASAP2文件生成符合ECU要求的代码。 ### 回答2: rtw.asap2setaddress 是一个 MATLAB 的函数,用于设置 ASAP2 协议文件(从 AUTOSAR 收集的数据)中的一个信号或参数的地址。ASAP2 是一种用于描述 ECU(电控单元)的软件特性的协议,主要用于汽车电子控制单元的开发过程中。 这个函数的功能是将 MATLAB 的信号或参数与 ASAP2 文件中的对应信号或参数关联起来。在使用此函数之前,我们需要加载 ASAP2 文件并初始化相关信息。 在调用 rtw.asap2setaddress 函数时,我们需要提供以下参数: 1. 数据类型(DataType):指定与 ASAP2 协议文件关联的 MATLAB 信号或参数的数据类型,如 int8、uint8、int16、uint16、int32、uint32、single 等。 2. 数据大小(DataSize):指定与 ASAP2 协议文件关联的 MATLAB 信号或参数的数据长度,如 scalar、vector、matrix 等。 3. 正式名称(FormalName):指定与 ASPA2 协议文件关联的 MATLAB 信号或参数的正式名称,与 ASAP2 文件中的名称一致。 4. 指定地址(Address):指定与 ASAP2 协议文件关联的 MATLAB 信号或参数在 ECU 内存中的地址。 通过调用 rtw.asap2setaddress 函数,我们可以将 ASAP2 文件中描述的信号或参数与 MATLAB 中定义的信号或参数关联起来,确保在生成的代码中,正确地将数据存储到对应的地址中。 总之,rtw.asap2setaddress 在 MATLAB 中的功能是用于与 ASAP2 协议文件中的信号或参数建立连接,从而在生成的代码中正确地设置对应的地址。 ### 回答3: rtw.asap2setaddress是一种MATLAB工具箱中的函数,用于设置AUTOSAR(Auto Adaptive Software Architecture)参数文件中的地址。AUTOSAR是一种用于开发汽车嵌入式软件的开放标准架构,用于提高汽车软件的可移植性和可重用性。 rtw.asap2setaddress函数的作用是为AUTOSAR参数文件中的信号和参数设置地址。通过设置地址,MATLAB可以将AUTOSAR参数文件中的数据和实际硬件的物理地址进行对应,从而在生成代码时确保正确地存储和访问这些数据。 使用rtw.asap2setaddress函数时,首先需要提供AUTOSAR参数文件的路径和文件名作为输入。接下来,需要指定具体的信号或参数名称以及相应的地址值。这里的地址可以是内存地址或寄存器地址,取决于硬件平台的要求。 设置地址后,MATLAB会自动在生成的代码中编写相应的地址映射信息。这样,当代码被转换为可执行文件并运行在实际硬件上时,软件与硬件之间的通信和数据交换将能够正确地进行。 总之,rtw.asap2setaddress函数是MATLAB工具箱提供的一个用于设置AUTOSAR参数文件中地址的实用工具。它可以帮助汽车嵌入式软件开发人员确保软件与硬件之间的数据存储和访问的正确性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值