Rasterizing WinRT

4/25/2012 By Sergey 0 comments

Earlier we posted that creating WinRT editions should be painless.

Well, today we rewrite that “should”. Our earlier blog mostly talked about deployment, assuming that the WinRT graphical API would basically be similar to the non-Metro API. This assumption turned out to be incorrect. WinRT does not offer GDI+ (System.Drawing), nor does it offer WPF (Windows Presentation Foundation) in all its glory. It does appear to be remarkably similar to the SilverLight API, but there are some serious differences.

1. Clipping: similar to Silverlight, all graphical elements have a Clip property. In WinRT however this is no longer has the general Geometry type, but it has been restricted to a RectangleGeometry. There is also no OpacityMask in WinRT. At this point it is not clear to us how we can achieve any form of non-rectangular clipping (which is ubiquitous in PDF documents).

2. Images: similar to Silverlight, it is possible to use a WritableBitmap to fill images with binary pixel data. In Silverlight, one can use SetSource() to specify a stream of ARGB values (bytes). In WinRT however, one needs to assign an instance of IRandomAccessStream. It is not clear to us yet how we can create such an instance for (for example) a stream of data. There appears to be no standard solution for using a MemoryStream as an IRandomAccessStream, which looks like a serious omission to us. We tried to create our own simple implementation based on a MemoryStream, but alas, so far this just started throwing unclear exceptions (to be continued some other time…)

3. Radial Shadings: WinRT has no Radial shadings

To illustrate this: we have been able to arrive at a first internal version of PDFRasterizer.NET for metro, using some stubs for various parts. We obtained the following result:


While Adobe Reader shows this file as:


We expect that we will be able to solve (or work around) the image loading problems if we look into this a bit further. And for now we assume that radial shading is just something that just did not make it into the preview release. The Metro Clipping issue is quite serious however, if it is not an accidental restriction. The same applies to the omission of the OpacityMask.

I should also mention that the depicted rendering differences are not all related to the issues mentioned above. We simply did not have the time yet to implement some of the more complex shadings. This mostly applies to the bottom part of the page. This also means however, that it is not yet entirely certain that we will not encounter additional issues there.

Interestingly, Windows 8 comes with a metro-style PDF viewer. This shows this document as follows:


This shows the following:

  • The radial shading at the bottom left is also missing in the built-in viewer. This seems to support our assumption that radial shading is just something that just did not make it into the preview release.
  • This viewer does not suffer from the clipping restriction. This seems to suggest that it either uses some internal features that we do not have access to, or it uses an different platform altogether, possibly C++ and DirectX. The problem with DirectX however is that there is no C# binding for DirectX and even if there were it cannot be mixed with XAML for as far as we know. So at present this is no option for us.

At this point, we feel that the preview release of WinRT is still a bit too limited to actually implement a full-blown viewer for it. We are driving the metro but some of the stations are missing.