PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 19, 2024 8:37 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Missing font styles.
PostPosted: Wed Dec 12, 2007 10:13 am 
Offline

Joined: Wed Dec 12, 2007 9:55 am
Posts: 3
Location: London, UK
Hi,
I am looking to use PDFSharp to produce PDF's from XPS documents, I can extract the text, fonts and font styles from an XPS document but when I try and write that information to the PDF I find that the styles are not being applied in some cases, in particular bold and italic. I notice in part of the PDFSharp code that there are some TODO's to implement bold and italic.
The general form of my code is :-
If lFontFamily.IsStyleAvailable(FontStyle.Italic) Then
pdffont = New Font(lFontFamily, dblFontSizeTemp, FontStyle.Italic, GraphicsUnit.World)
End if
Dim XPdfFont As XFont
XPdfFont = CType(pdffont, XFont)
gfx.DrawString(strCapturedString, XPdfFont, PDFBrush, obj.OriginX / (96.0 / 72.0), obj.OriginY / (96.0 / 72.0))

Am I missing something here in terms of applying styles and if not are there plans to implement the other font styles in the future.

Many thanks
JM.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 12, 2007 2:44 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Most fonts include 4 files: Regular, Bold, Italic, BoldItalic.
With these fonts you can use all styles.

Some fonts only have 1 through 3 files - with these fonts you cannot use all styles with PDFsharp - at least not with version 1.00 and probably not with version 1.10 (currently under construction).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 12, 2007 4:01 pm 
Offline

Joined: Wed Dec 12, 2007 9:55 am
Posts: 3
Location: London, UK
I am testing using the following code :-

Code:
lFont = New System.Drawing.Font("Verdana", 20, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.World)
Font = CType(lFont, XFont)
gfx.DrawString("Hello World", Font, XBrushes.Black, X, Y)


Although I have 4 seperate Verdana fonts for each style on my pc this piece of code does not work, i.e it does not draw in italics.
I also have 4 seperate fonts for Times New Roman on my PC and the code works in that case.
I have looped through all of the fonts installed on my PC and sent the ouput to a PDF via PDFSharp and only Arial, Courier New and Times New Roman produce all four styles despite many of the others have all four styles.
Am I doing something wrong here?

confused
JM


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 12, 2007 4:50 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Without lFont and CType it'll work.
Please try:
Code:
font = new XFont(...
instead.

At first glance I'd say this is a bug in PDFsharp ...
... but one with a simple work-around (or rather work-straight).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 13, 2007 10:21 am 
Offline

Joined: Wed Dec 12, 2007 9:55 am
Posts: 3
Location: London, UK
Thanks for your response.

I've tried what you suggested as follows:-

Code:
If font_family.IsStyleAvailable(System.Drawing.FontStyle.Italic) Then
Font = New XFont(font_family.Name, 20, System.Drawing.FontStyle.Italic)
gfx.DrawString("Hello, World!", Font, XBrushes.Black, X, Y)
End If


This still does not work for me the output is produced but not in italics, it still only works for three fonts on my PC. In fact I've tried all available overloads to create the XFont and get the same result each time.
Any suggestions?

JM


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 17, 2007 12:10 pm 
Offline

Joined: Fri Nov 23, 2007 12:10 pm
Posts: 18
This is pending work. See:

PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer in line 520 and 525

Code:
      if (bold && !descriptor.IsBoldFace)
      {
        // TODO: emulate bold by thicker outline
      }

      if (italic && !descriptor.IsBoldFace)
      {
        // TODO: emulate italic by shearing transformation
      }


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 17, 2007 12:21 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Vyacheslav Popov wrote:
This is pending work.

This does not apply to the majority of fonts like Arial, Verdana, Tahoma, Segoe UI, ...
... because these fonts include files for regular, bold, italic, and bolditalic styles that can be used by PDFsharp.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 17, 2007 12:44 pm 
Offline

Joined: Fri Nov 23, 2007 12:10 pm
Posts: 18
Yes, but you see my solution:
http://forum.pdfsharp.net/viewtopic.php?p=597&mforum=pdfsharp#597
and microsoft example
http://forum.pdfsharp.net/viewtopic.php?p=597&mforum=pdfsharp#597


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 17, 2007 12:45 pm 
Offline

Joined: Fri Nov 23, 2007 12:10 pm
Posts: 18
Sory, microsoft example here:

http://msdn2.microsoft.com/en-us/library/y505zzfw(VS.80).aspx


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 17, 2007 6:07 pm 
Offline

Joined: Fri Nov 23, 2007 12:10 pm
Posts: 18
Bug solved!!!

http://forum.pdfsharp.net/viewtopic.php?p=602&mforum=pdfsharp#602


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 296 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group