PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Missing font styles.
https://forum.pdfsharp.net/viewtopic.php?f=2&t=274
Page 1 of 1

Author:  JM [ Wed Dec 12, 2007 10:13 am ]
Post subject:  Missing font styles.

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.

Author:  Thomas Hoevel [ Wed Dec 12, 2007 2:44 pm ]
Post subject: 

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).

Author:  JM [ Wed Dec 12, 2007 4:01 pm ]
Post subject: 

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

Author:  Thomas Hoevel [ Wed Dec 12, 2007 4:50 pm ]
Post subject: 

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).

Author:  JM [ Thu Dec 13, 2007 10:21 am ]
Post subject: 

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

Author:  Vyacheslav Popov [ Mon Dec 17, 2007 12:10 pm ]
Post subject: 

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
      }

Author:  Thomas Hoevel [ Mon Dec 17, 2007 12:21 pm ]
Post subject: 

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.

Author:  Vyacheslav Popov [ Mon Dec 17, 2007 12:44 pm ]
Post subject: 

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

Author:  Vyacheslav Popov [ Mon Dec 17, 2007 12:45 pm ]
Post subject: 

Sory, microsoft example here:

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

Author:  Vyacheslav Popov [ Mon Dec 17, 2007 6:07 pm ]
Post subject: 

Bug solved!!!

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/