Welcome to MSDN Blogs Sign in | Join | Help

Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Since the public release of Microsoft Silverlight 2, I've gotten a few internal and external requests to migrate my SimpleSilverlightXpsViewer sample application to the final Silverlight bits. (Background reading: Introductory Post for the Alpha, Beta 1 Update, Beta 2 Update, Interesting Scenario.) Unfortunately, there is a pretty significant roadblock preventing this and I'm afraid I don't have a good solution. :(

Specifically, the "BreakingChangesBetweenBeta2andRelease" document contains the following item:

Font URI is Restricted to Assembly Resource

Who Is Affected:
Silverlight 2 Beta1 or Beta 2 applications (not Silverlight 1.0 applications) that reference fonts (or zip of fonts) via the URI syntax in the Control.FontFamily, TextBlock.FontFamily or Glyphs.FontUri attributes and where the fonts are not embedded within the assembly (dll) of the control or application.
Fix Required:
You can specify a font (or in some cases a zip of fonts) in URI format via the Control.FontFamily, TextBlock.FontFamily and the Glyphs.FontUri attributes. If you are, you will need to ensure your font is marked as a "resource" in the project system.

This is problematic for SimpleSilverlightXpsViewer because it uses Glyphs.FontUri to associate the font for the on-screen text with the corresponding ODTTF font file in the XPS document - and it's impossible for a general-purpose document viewer to have all the fonts in the world compiled into its own assembly. Making matters worse, fonts in an XPS document are identified by GUID, so it doesn't even seem possible to embed the N most common fonts and try to cover the 90% scenario by looking at font names and using the best available match. The seemingly obvious alternative is to use the FontSource property instead - but that's not exposed by the Glyphs class. The only workable option I see is to embed a single font in the viewer's resources and use that ONE font for ALL fonts in every XPS file. Obviously, this puts a pretty big damper on the idea of displaying an arbitrary XPS document how it was meant to be displayed because all the font fidelity of the original document is lost.

In controlled scenarios, it should still be possible to bundle an XPS document and its fonts in a compiled assembly and point some suitably modified version of SimpleSilverlightXpsViewer at that - but by then it's no longer as much of a client-side XPS viewer as it is a client+server document viewing solution (that could use straight XAML when you get down to it!). Unfortunately, my original vision of a Silverlight-based XPS viewer that lets users open any arbitrary XPS file on their computer or on the web is going to have to wait a little while longer to be realized. :(

In case folks are wondering, I did ask why this restriction is present. As I understand things (caveat: I am not a lawyer or a spokesperson for Microsoft), some fonts have copyrights and/or licensing restrictions placed on them by their creator and some of those fonts should not be made available via HTTP (where everybody can access them freely). I may not be happy about the consequences of this for SimpleSilverlightXpsViewer, but I understand why this restriction makes sense.

So to make a long story short: I have not yet come up with a good way to migrate SimpleSilverlightXpsViewer to Silverlight 2 and I apologize to all the folks who have expressed interest in this sample. For what it's worth, if I ever come up with a solution I like, I'll immediately update SimpleSilverlightXpsViewer and post the details! :)

Published Saturday, October 18, 2008 12:06 AM by Delay
Filed under:

Comments

# Silverlight Cream for October 18, 2008 -- #399

Monday, October 20, 2008 2:32 AM by Community Blogs

In this issue: Shawn Wildermuth, Laurence Moroney, Dave Relyea, Mike Taulty, Andy Beaulieu, Brad Abrams

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Thursday, October 30, 2008 7:12 PM by silverlightkb

Silverlight 2 can still load fonts from Isolated Storage, right? Can you expand the fonts in embeded XPS into the isolated storage before loading them?

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Thursday, October 30, 2008 7:38 PM by silverlightkb

Sorry, my comemnts was incorrect. I cannot load fonts from isolated storage with FontUri.

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Thursday, October 30, 2008 7:41 PM by Delay

silverlightkb,

I've not considered the IsolatedStorage angle, but I think may boil down to the same thing as the following exchange I had with someone else (paraphrased slightly):

Them: Note that you can download a font via WebClient or whatever and set it from code, it's just that it won't be downloaded automatically by the runtime.

Me: So how would that work? Are you suggesting the FontSource constructor that takes a Stream? I think I considered this briefly and then dismissed it when I saw that only TextBlock, TextBox, and PasswordBox use FontSource (per Reflector). The Glyphs class does not - and I think that still leaves me up a creek. Did you have something else in mind?

Them: Darn.

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Thursday, October 30, 2008 7:45 PM by Delay

silverlightkb,

It looks like our replies crossed paths. But it seems we came to the same conclusion. :(

Thank you very much for the idea - every bit helps!

# Fix for Simple XPS Silverlight Viewer for Silverlight 2

Monday, November 24, 2008 12:28 AM by Li Chen's Weblog

Fix for Simple XPS Silverlight Viewer for Silverlight 2

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Monday, November 24, 2008 12:46 AM by silverlightkb

Delay, I found a way to make it work (though not ideal). The fix is to package all the fonts in a separate XAP and load it dynamically. See my blog entry http://www.dotneteer.com/Weblog/post/2008/11/Fix-for-Simple-XPS-Silverlight-Viewer-for-Silverlight-2.aspx.

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Monday, November 24, 2008 2:12 AM by Delay

silverlightkb,

Congratulations on your creative solution! :) I think what you've done is a great approach for controlled scenarios because it's more flexible than alternative proposals that require fonts to be embedded directly in the viewer application itself. However, as I note above, I'm still hoping to be able to achieve the goal of a stand-alone viewer that works on unmodified XAP files (and avoids points 1 and 2 in your post) - but until then, yours is a very nice step in the right direction! Thanks!!

# Displaying XPS Documents in Silverlight

Monday, April 20, 2009 8:10 PM by simonguest.com

I’ve recently been involved on a project that has a requirement to create and view XPS documents in Silverlight. 

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Wednesday, August 05, 2009 4:29 PM by slyi

Could you use SL3 local font support to avoid the font packaging. http://cid-289eaf995528b9fd.skydrive.live.com/self.aspx/Public/localfont.zip

# re: Roadblock in the way of migrating the proof-of-concept Silverlight XPS reader [SimpleSilverlightXpsViewer sample does not work on Silverlight 2 RTW]

Wednesday, August 05, 2009 5:17 PM by Delay

slyi,

I'm not sure that you could. (FYI, I don't know what your attachment is and I didn't download it.) Specifically, an XPS file can contain ANY font in the world and you'd really like for that font to be used when rendering the relevant portions of the document. Because there's no guarantee that random font exists on the local machine, I'm not sure that local fonts solve the entire problem - though I agree they seem to improve the situation!

Anonymous comments are disabled
 
Page view tracker