View previous topic :: View next topic |
Author |
Message |
JM
Joined: 12 Dec 2007 Posts: 3 Location: London, UK
|
Posted: 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. |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: 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). _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
JM
Joined: 12 Dec 2007 Posts: 3 Location: London, UK
|
Posted: 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 |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: 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). _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
JM
Joined: 12 Dec 2007 Posts: 3 Location: London, UK
|
Posted: 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 |
|
Back to top |
|
|
Vyacheslav Popov
Joined: 23 Nov 2007 Posts: 18
|
Posted: 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
} |
|
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: 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. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
Vyacheslav Popov
Joined: 23 Nov 2007 Posts: 18
|
|
Back to top |
|
|
Vyacheslav Popov
Joined: 23 Nov 2007 Posts: 18
|
Posted: Mon Dec 17, 2007 12:45 pm Post subject: |
|
|
|
|
Back to top |
|
|
Vyacheslav Popov
Joined: 23 Nov 2007 Posts: 18
|
|
Back to top |
|
|
|