Click here to Skip to main content
Click here to Skip to main content
Go to top

Silverlight XPS Viewer in SL4, Support viewbox and viewport property

, 4 May 2010
Rate this:
Please Sign up or sign in to vote.
Background...
Background
 
During my development last week I was working on a Silverlight based XPS viewer. During this viewer we came to a situation in which an XPS was made from power point slide. In that PPT two images were shown during rendering the images present in it.
 
The problem is that Silverlight doesn’t have any viewport or viewbox support. Along with these problems, the font files need to be downloaded externally so that we can render them in our XPS Viewer
 
Using the code
 
Now i have replace path into Image element, remove 1st image and change left and top to 2nd image plus increase hight.
 
 
// crate 2 rect, one of viewbox and 2nd is viewport
var viewbox = new Rect(Convert.ToDouble(tempviewbox[0]), Convert.ToDouble(tempviewbox[1]),
                                Convert.ToDouble(tempviewbox[2]), Convert.ToDouble(tempviewbox[3]));
 
var viewport = new Rect(Convert.ToDouble(tempviewPort[0]), Convert.ToDouble(tempviewPort[1]),
                                 Convert.ToDouble(tempviewPort[2]), Convert.ToDouble(tempviewPort[3]));
 
Image img = new Image(); 
img.Source = bitmapImage; 
img.Stretch = Stretch.Fill;
 
//Set Image Height (1st Image Height + 2nd Image Height) and Change Left and Top
img.Height = viewport.Height + Convert.ToDouble(vp[3]);  
img.SetValue(Canvas.LeftProperty, Convert.ToDouble(vp[0])); 
img.SetValue(Canvas.TopProperty, Convert.ToDouble(vp[1])); 
          
//Get Parent element of this image
var parent = path.Parent as Canvas;
//Get index of Image element
var index = parent.Children.IndexOf(path);
parent.Children.Insert(index, img);
 
//Microsoft has provided support in Silverlight 4, 
//Glyphs has a property of FontSource by which we can assign any font file stream to that. 
//By this provision I was able to provide font files to XPS Viewer, 
//this saved any extra DLL to be downloaded separately.
    
//Get Font file stream from xps
var stream = Application.GetResourceStream(_streamResourceInfo, ConvertPartName(glyphs.FontUri.ToString())).Stream;
glyphs.FontSource = new FontSource(stream); //assign stream 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

AzharTheGreat
Software Developer (Senior) Softech World Wide
Pakistan Pakistan
Rich Media Platform is a collection of technologies that combine to provide an end-to-end solution for interactive-media delivery over the Internet or the Enterprise Network. Each piece of the solution provides value within its own context and can be used de-coupled to do so in a different scenario. For example, Content Caching and Delivery can be used by itself to enhance an existing Video delivery network in an Enterprise, without needing other pieces of the Rich Media Platform.
 
The following illustration depicts the context for these technologies within a typical system context. Hover your mouse over the links to view brief descriptions.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 4 May 2010
Article Copyright 2010 by AzharTheGreat
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid