Get font name of odttf files generated by XPS document writer - silverlight

I have pdf file using only 2 type of fonts.
But when exporting the pdf to xps format, there are odttf files as many as glyphs elements in generated xps document.
Now I want every glyphs with the same font type to have the same FontUri value. But how to identify if 2 odttf files is the same font type?

Sometimes (but not always) it is possible to figure out the font name by looking at the final part of the odttf file. In fact, I am routinely extracting font names from odttf files (generated by the XPS Document Writer) with a python script by looking at what immediately precedes and follows the phrase "This is a unique ID" that can be found in the last 100 or so bytes of every odttf file that I have seen so far. Of course, this is a terrible hack - but it works (for me, at least).
Whether this really works seems to depend on what program generated the PDF file and/or what program is used to print the PDF file to the XPS Document Writer and/or what specific fonts the PDF document contains.
My experience is mostly limited to converting PDFs generated by pdflatex in this way: as an online math tutor I need to convert formulas, text and drawings from PDF to XAML in order to be able to paste them into a shared whiteboard that is based on WPF. So this hack might or might not work for you. (Also: this hack might stop working any time...)
Instead of trying to figure out the font name you could also convert your PDFs to XAML by eliminating the font references entirely: You can crop the PDF with pdfcrop (by Heiko Oberdiek) before sending it to the XPS Document Writer. In my experience this forces the combination of Adobe Reader and XPS Document Writer (for reasons unknown to me) to produce XAML code that does not contain any Glyphs, and thus no references to fonts (contained in obfuscated odttf files). But, unfortunately, you get much more XAML code, because all glyphs have to be represented by paths (which involves a great deal of repetition).
Regards,
Christian

Related

WPF style info from external text file

Not sure if this is possible, but I have a WPF application that now has a requirement to be skinnable.
Basically, this equates to several key colours and a couple of logos.
Is there any way of grabbing the hex values for the colours in defined styles from an external (ie comes with the application but isn't compiled) text/xml file?
I want to be able to select the colours, create the file and then deploy to the user with the application so that I don't have to maintain multiple versions.
I'm not even sure that this is the best way to achieve what i'm after.
Has anyone done anything akin to this?
I would be extremely grateful if someone could point me in the right direction.
Thanks
just hold the color values in a config file simple text file will suffice.
though you can use VisualStudio Resource file..
file will contain lines in each:
item_enum_name item_type item_value
for example:
main_screen_bg_color Color Black
company_logo URI \logos\logo1.jpg
and so on..
just load the file parse it and use bind to the values...

How should I use .ico files in a Winforms Application?

I'm developing a WinForms c# 3.0 application. Our designer created quite a lot of .ico files containing all the needed art. The choice of .ico was made because quite often, the same image is needed in several places in different dimensions.
Now, it seems .ico files are really annoying to use in visual studio. The only way to use those images seems to be through images list (which aren't supported by all controls).
Compared to other resources, you can't write this :
foo.Image = global::RFQHUB.RFQHUBClient.Properties.Resources.foo; // Cannot implicitly convert type 'System.Drawing.Icon' to 'System.Drawing.Image'
Here are the options I'm considering :
create ImageLists of all possible sizes referencing all my icons in my main window. Link these ImageLists from other windows and find a way to export Image objects from the ImageList when I can't use it directly ; since ImageList contains a Draw() method, this should probably be possible.
convert all the x.ico I've got in several x16.gif ...x48.gif, and use those through resources.
I'd be interested to know if some people have been successfully using .ico resources in a Winform application. In so, how did you set up things ?
ICO isn't quite an obsolete format, but it's close. It's still useful for your application icon, but for almost everything else, it's better to use an ImageList for each size that you need. And it's much faster to populate an ImageList from a bitmap that contains multiple images layed out in a grid.
You also want to use an Alpha channel transparency in your bitmaps to get the best result, so storing them as .PNG files in your resources is the best way to go, since PNG supports an alpha channel. ICO and GIF files support only single bit for transparency - every pixel is either fully opaque or fully transparent. An 8 bit alpha channel for transparency looks much nicer.
If you can send your artist back to the drawing board then you should do so, and have him/her do full anti-aliased images with alpha. If you can't, then I suggest that you write a small program to convert all of your icon files into bitmaps suitable for loading into ImageLists.
Convert the images into PNG. Point. Whoever decided to use .ico files to start with should get talked to in private - the argument holds no ground.

What's the point of XPS?

When I read books about WPF, I saw the authors mention XPS like it was something important. Windows also includes its XPS viewer, and I've seen that listed as a "feature" of Windows.
But why? What's the point? Who the heck uses it? It's my understanding that XPS is, basically, like PDF, xhtml, or ePub (which is just xhtml)...or even Word's docx format. Many of the features are the same among those formats.
It doesn't seem to have any major benefits compared to any of those other formats. It seems to me that xhtml would be so much more useful than XPS as a way to save and load FlowDocuments from the RichTextBox. I've looked at multiple blogs about converting between the two. Most or all of the rich text on the internet is (x)html. Beyond that, I don't think anyone uses it just to publish their docs; PDF is preferred. It seems like XPS is just some random format that MS made and decided to push. I generally love MS, but they do have a habit of that kind of thing. Couldn't MS have made an api using xhtml instead? That would have been more useful in a lot of situations, I'd think.
So, is there a point to using XPS, particularly in comparison to one of the other formats I mentioned (or any I haven't)? Have you ever used XPS in your programs or otherwise?
As U62 already stated, WPF comes with a DocumentViewer control which enables you to view XPS documents. The DocumentViewer also has some useful fonctions like Print, Zoom, FitToPage etc... So you don't need to implement that or use a third party tool.
What I just finished an hour ago using XPS and the DocumentViewer was some kind of "Adress label print preview". Allow the user to select some contacts from a list of contacts, click "Print Preview". This opens a new XAML Window which contains a DocumentViewer control and a ListBox with the choice of different Labels (e.g. 1 sheet with 12 labels [2 columns, 6 rows], 1 sheet with a single label whose width and height can be user defined).
Based on the users selection, I generate an XPS Document in the layout the user selected with the adresses of the selected contacts. If e.g. the user selected 4 contacts and wishes to print them on "SingleLabelSheet"'s, I generate 1 XPS document with 4 pages, each page containing 1 Adress. Then I display the XPS in the DocumentViewer and the user can print the labels on our Label Printer.
Once I understood how the XPS API worked (at least the Basics), it was a matter of 2 hours to get this up and running.
So, basically, I see XPS as an easy to use API to display FixedDocuments which are to be generated on the fly. But I wouldn't personnally go about saving them to my HDD or somehow modify them or whatever you generally do with documents.
The only actual advantage I can think of is that you have a control for viewing XPS documents in WPF applications. The other formats you mention mean you would have to bring in a 3rd party renderer (or write one yourself if you have a year to spare).
btw. I don't know much about ePub, but XPS isn't directly comparable with XHTML, it's more like PDF in that it's designed to have a fixed layout.
XPS to WPF is like WMF to Win32/WinForms, it's a persistent format that let you store and print native WPF graphics.
XPS is used to print from WPF (even when you print directly from the application without saving, the internal printing system is built on XPS) so what should MS do:
Create a new file format that exactly fit with what they are trying to do
Build a 100% perfect translator from WPF to a format they don't control like PDF (and hope Adobe doesn't break all WPF applications out there with the next release of Acrobat Reader).
What would you do?
Saving XPS files is just a nice bonus.
Look, I may be a pessimist on XPS as a report generation solution, but I gave it a go and found the initial documentation to be hard to understand, with less real world samples out there than what I would have liked. When I put it into a real world business application I found it to be frustrating, particularly in LOB apps that require tables that span over multiple pages.
Things may have changed since then but as soon as I started looking at tables that spanned over several pages and I wanted column headers to go to the top, etc. I found that the API required me to do what I would call excessive workarounds with unnecessary complexity.
So, things may have changed since then (about 8 months ago), but I went from XPS to using ITextSharp and that has been a lot less painful.
So the only advantage I would say, like everyone else, is the built in viewer in WPF - but other than that I feel the API may need to "mature" a bit more before I will attempt something again in it.
Actually I found a really nice reason to use XPS. I wanted to print from multiple sources, merge documents and specify duplex and stapled. Finally it should be printed as one document with duplex and stapled. I was having a difficult time doing so but found that by printing to XPS (saved to disc) I could accomplish my goal with minimum fuss. I haven't found any other method that is so easy and straightforward.
Dim PrintServer As New SysPrint.PrintServer("\\" & My.Computer.Name)
Dim PrintQ As New SysPrint.PrintQueue(PrintServer, "Ricoh Main")
Dim Jobs As SysPrint.PrintJobInfoCollection = PrintQ.GetPrintJobInfoCollection
Dim able As SysPrint.PrintCapabilities = PrintQ.GetPrintCapabilities()
Dim CurrentTicket As SysPrint.PrintTicket = PrintQ.CurrentJobSettings.CurrentPrintTicket
If able.StaplingCapability IsNot Nothing AndAlso able.StaplingCapability.Count > 0 Then
If able.StaplingCapability.Contains(Printing.Stapling.StapleTopLeft) Then
CurrentTicket.Stapling = Printing.Stapling.StapleTopLeft
End If
Else
Debug.Print("no stapling capability")
End If
CurrentTicket.Duplexing = Printing.Duplexing.TwoSidedLongEdge
Dim fiName As String = "S:\Temp\PS\XPS\Test.xps"
Dim TestJob As SysPrint.PrintSystemJobInfo _
= PrintQ.AddJob("Test job", fiName, False)
XPS (code named "metro") was clearly designed as the Microsoft alternative to PDF and PostScript in Windows Vista. See this old article here: Microsoft Readies New Document Printing Specification
There are different approches when inventing document formats:
Some are made for quick view on screen (say low def) like HTML, doc.
Some other are (or can be) very respectuous of printing contrains (say quality based) like PDF, XPS.
So XPS whiches to be as good as PDF, plus it is formated in XML, so "maybe" it is more standard than the stream approch in PDF.
The black spot of XPS is maybe the management of special colors (Pantone, paper effects).

How to embed a png in an Adobe Illustrator or Expression Design file to create XAML

I have an AI file. I paste it into Expression Blend and then export the XAML for use in my WPF project. Works for most of my files, but some export the XAML plus a seperate png file. What can I do so that the png is embedded into the paths of my image and not a seperate image? Can it be done?
Checkout this page that describes converting raster graphics to vector and then XAML -
http://weblogs.asp.net/rrobbins/archive/2007/11/11/how-to-convert-raster-graphics-to-xaml.aspx
Another route that you could try is to use Expression Design to convert the .ai file.
(Please note that once you have Expression Design open, you need to create a new document before the File->Import menu item is even enabled.)
However, once you convert the .ai file with Expression Design, you will likely still have the problem of having some raster information in the .ai ... which as Terrapin already mentions is hard to convert to vector (and usually brings a high memory footprint to get even close to the quality of the raster image).
But to help you out there, Expression Design also comes with some ability to convert raster information into vector. If you select the image that you want to convert, just go to Object->Image->Auto Trace Image in order to convert it.
See this StackOverflow question for more info, but basically Microsoft allows you to download a trial that you can use for 90 days.
Hope that helps.
It sounds like the PNG that is generated is probably the raster part of your AI file, and it can't be converted to vector graphics. Are you importing PNGs, or JPGs, or another raster graphic into your AI file?
To convert raster images to vectorial images, I found Inkscape (free) to do an excellent job (comparable to VectorMagic, which is not free anymore by the way).
In Inkscape, import your image and use the Path/Trace Bitmap function. It has a lot of control.
Once you converted to a vectorial image, save it as a SVG. Then, using ViewerSvg, you can convert to XAML vector data. (Path & Canvas)

How do I convert an Illustrator file to a path for WPF

Our graphics person uses Adobe Illustrator and we'd like to use her images inside our WPF application as paths. Is there a way to do this?
You can go from AI to SVG to XAML.
From Adobe Illustrator: File -> Save As -> *.SVG.
SVG "Profile 1.1" seems to be sufficient.
Note that to preserve path/group names in XAML you should enable "Preserve Illustrator Editing Capabilities" (or at least as it's called in CS4).
SharpVectors can convert SVG data to XAML data. This will produce a fragment of XAML with root <DrawingGroup>.
Do what you need to do to copy-paste and otherwise use the XAML, such as placing it into an Image like below. Named objects or groups in the AI file should still have their names in the XAML i.e. via x:Name="...".
<Image>
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup ... the output from step #2 ...>...</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
Coordinate systems can be a pain if you want to be animating things. There are some other posts such as this which may have insights.
Get her to export the illustrations as some other format (recent versions of Illustrator support SVG) that you can use or convert to something that will work.
The detour suggested by #ConcernedOfTunbridgeWells is starting to make sense now. Other solutions are not being maintained and do not work anymore.
Hence, you can use this option as workaround:
Save files as svg.
Convert them to XAML using Inkscape.
This solution even has the advantage of text will stay text and is not converted to a path.
How to convert many files?
Inkscape also supports a batch mode to convert many files at once. I took a great script (by Johannes Deml) for batch conversions on Windows that takes vectors files and converts them to various other formats using Inkscapes batch mode. I adapted it to convert to XAML, too.
You can find the script that includes XAML on Github. Some instructions on how to use the script are provided by the original author.

Resources