wxPdfDocument accentuated chars and ArialNarrow

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
pderep
In need of some credit
In need of some credit
Posts: 2
Joined: Sat Dec 07, 2013 4:40 pm

wxPdfDocument accentuated chars and ArialNarrow

Post by pderep »

Hi guys, long time no talk! ;-)

Using wxPdfDocument (Win32 static Unicode build), i'm trying to output some french accentuated text using the font Arial Narrow (an MS font installed with Office), only to see funny garbage in lieu of the text I'm expecting.

For example, if I do:

wxString text ( wxT("Bureau du président; Bureaux; Réunion du conseil d’administration") );
pdf.SetFont(wxT("ArialNarrow"),wxT(""), 7);
pdf.MultiCell ( 70, 2, text, 0, wxPDF_ALIGN_LEFT );

The program outputs some strange random characters (a mixture of «, ', " and squares).

This thread (http://forums.wxwidgets.org/viewtopic.p ... tf#p149552) seems promising, but everything I tried from it led to nowhere.

In a word, help! :-)

Thanks,

Paul de Repentigny
pderep
In need of some credit
In need of some credit
Posts: 2
Joined: Sat Dec 07, 2013 4:40 pm

Re: wxPdfDocument accentuated chars and ArialNarrow

Post by pderep »

OK, I found that the application I was working on was loading and external font file from a local folder, and that font definition file did not support more than the standard ASCII set.

Which brings me to another question I'll post as a new thread (finding installed fonts).

Anyway, thanks!

PdR
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument accentuated chars and ArialNarrow

Post by utelle »

pderep wrote:Using wxPdfDocument (Win32 static Unicode build), i'm trying to output some french accentuated text using the font Arial Narrow (an MS font installed with Office), only to see funny garbage in lieu of the text I'm expecting.

For example, if I do:

wxString text ( wxT("Bureau du président; Bureaux; Réunion du conseil d’administration") );
pdf.SetFont(wxT("ArialNarrow"),wxT(""), 7);
pdf.MultiCell ( 70, 2, text, 0, wxPDF_ALIGN_LEFT );

The program outputs some strange random characters (a mixture of «, ', " and squares).
As you mentioned in your second post it is of course important that the used font really contains the glyphs for all characters you want to write to the resulting PDF file. However, it is also important to take the encoding of the source code files into account, if you specify strings with non-ASCII characters within the source code. Quite often source code is encoded in Windows codepage cp1252. That is, you have to convert the string accordingly before using it within your application for writing it to PDF. Even if you use an editor for your source code which encodes your files in UTF-8, you need to convert the string before using it. The wxString class of wxWidgets offers a method FromUTF8 to do this. For other encodings you need to use a wxString constructor with conversion by passing an appropirate wxMBConv instance.

Regards,

Ulrich
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument accentuated chars and ArialNarrow

Post by utelle »

pderep wrote:OK, I found that the application I was working on was loading and external font file from a local folder, and that font definition file did not support more than the standard ASCII set.

Which brings me to another question I'll post as a new thread (finding installed fonts).
Just for this purpose the class wxPdfFontManager offers the method RegisterSystemFonts. This method registers all installed fonts. Be aware that registering all installed fonts may take a while if there are many installed fonts. However, at startup of an application it's usually acceptable to let the user wait for a short period of time while the application is initialized.

Regards,

Ulrich
Post Reply