wxPdfDocument page count alias not working on wxGTK 3.0 Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

wxPdfDocument page count alias not working on wxGTK 3.0

Post by iwbnwif »

Hello,

I wonder if anyone else is seeing this problem. I am using wxWidgets 3.0, wxGTK on Ubuntu 13.10.

I am trying to use the AliasNbPages() etc. to insert a total number of pages in each page's footer, however the text is not being converted from {nb}.

This has been working fine in wxMSW 2.9.5 but since I have moved to wxGTK and 3.0 it no longer works. I think that in wxWidgets 3.0 wxUSE_UNICODE is always defined.

The problem appears to be in pdfKernel.cpp helper function findString where the target string "{nb}" is never found.

This may be because in the function wxPDFDocument::ReplaceNbPagesAlias() the variable nbUni is not being loaded with the target string (it is an empty string), but nbAsc is being correctly set.

I have tried to debug this but haven't yet worked out what "makeFail" is supposed to do - should it set nbUni with the target string? Also I don't understand why the page buffer is searched for both the nbAsc and nbUni targets - surely it will either be Unicode or Ascii?

Many thanks for any help :D
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument page count alias not working on wxGTK 3.0

Post by utelle »

iwbnwif wrote:I wonder if anyone else is seeing this problem. I am using wxWidgets 3.0, wxGTK on Ubuntu 13.10.

I am trying to use the AliasNbPages() etc. to insert a total number of pages in each page's footer, however the text is not being converted from {nb}.

This has been working fine in wxMSW 2.9.5 but since I have moved to wxGTK and 3.0 it no longer works. I think that in wxWidgets 3.0 wxUSE_UNICODE is always defined.

The problem appears to be in pdfKernel.cpp helper function findString where the target string "{nb}" is never found.

This may be because in the function wxPDFDocument::ReplaceNbPagesAlias() the variable nbUni is not being loaded with the target string (it is an empty string), but nbAsc is being correctly set.

I have tried to debug this but haven't yet worked out what "makeFail" is supposed to do - should it set nbUni with the target string? Also I don't understand why the page buffer is searched for both the nbAsc and nbUni targets - surely it will either be Unicode or Ascii?
Most likely the problem is related to the font used for writing the text string containing the alias for the number of pages.

When I started to develop wxPdfDocument there was only support for the PDF core fonts and simple TrueType and Type1 fonts. For those fonts the characters of a text are written as is to the resulting PDF file. That is, either ASCII characters or Unicode characters. Therefore the page buffer is searched for the ASCII and Unicode representation of the alias.

For Unicode TrueType and OpenType fonts the story is different: for such fonts the characters of a text are "translated" to glyph numbers and only the glyph numbers are written to PDF.

The AliasNbPages feature rereads the created page contents, searches for the assigned string to be replaced (default {nb}) and replaces it by the final total number of pages.

The alias string is written out with the current font. Therefore it will be translated to glyph numbers for Unicode fonts. And that prevents the AliasNbPages feature from finding the alias, I'm sorry.

Unfortunately there is no easy solution. The only workaround is to use a core font or a simple TrueType or Type1 font to output the alias.

For a future version of wxPdfDocument I plan to replace the current AliasNbPages feature by a different method that will work with any font. Unfortunately there is no schedule yet, when this new method will be available.

Regards,

Ulrich
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxPdfDocument page count alias not working on wxGTK 3.0

Post by iwbnwif »

Ulrich

Thank you for the fast response!
Unfortunately there is no easy solution. The only workaround is to use a core font or a simple TrueType or Type1 font to output the alias.
This works perfectly :D

For reference to anyone who later finds this thread - the way in which I forced a simple TrueType font was to use:

Code: Select all

SetFont (wxFont (wxFontInfo(8).FaceName("Arial"));
Once again thanks for solving my problem.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Post Reply