wxPdfDocument with wxWidgets 3.0 font manager failing Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
praks411
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Mar 16, 2013 9:31 am

wxPdfDocument with wxWidgets 3.0 font manager failing

Post by praks411 »

Hi
I'm using wxPdfDoc-0.9.4 to generate certain pdf report, it was working perfectly with wxWidget-2.9 until recently we switched to
wxWidgets-3.0. I'm getting exception in wxpdfdoc.
During debugging I found that when I'm calling SetFont(wxT("Arial"), wxT("B"), 10) from my application code which finally goes to
wxPdfFont regFont = wxPdfFontManager::GetFontManager()->GetFont(font.GetFaceName(), styles) in pdfkernel.cpp, the wxPdfFontMager->GetFontManager() is returning NULL. I'm not sure why this is happening as wxPdfFontManager::ms_fontManager is getting initialize in wxPdfDocumentModule which should be call during initialization. I fear this is not happening.
I even tried replacing DECLARE_DYNAMIC_CLASS with wxDECLARE_DYNAMIC_CLASS and similar for IMPLEMENT_DYNAMIC_CLASS. However still it is not working.
Please someone suggest what could be going wrong and also what other changes do I need to take when migrating from wxWidgets-2.9 to 3.0 with respect to wxpdfdoc-0.9.4

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

Re: wxPdfDocument with wxWidgets 3.0 font manager failing

Post by utelle »

praks411 wrote:I'm using wxPdfDoc-0.9.4 to generate certain pdf report, it was working perfectly with wxWidget-2.9 until recently we switched to wxWidgets-3.0. I'm getting exception in wxpdfdoc.
I'm not aware of specific problems in using wxPdfDocument with wxWidgets 3.0. On which platform and with which compiler are you working? Which exact version of wxWidgets are you using? Version 3.0.0? Or version 3.0.1?
praks411 wrote:During debugging I found that when I'm calling SetFont(wxT("Arial"), wxT("B"), 10) from my application code which finally goes to wxPdfFont regFont = wxPdfFontManager::GetFontManager()->GetFont(font.GetFaceName(), styles) in pdfkernel.cpp,
This can't be the case. This call to the font manager is only reached if method SetFont was called with a wxFont argument.
praks411 wrote:the wxPdfFontMager->GetFontManager() is returning NULL. I'm not sure why this is happening as wxPdfFontManager::ms_fontManager is getting initialize in wxPdfDocumentModule which should be call during initialization. I fear this is not happening.
If method GetFontManager returns NULL, the global font manager instance wxPdfFontManager::ms_fontManager did not get initialized. However, I have no idea, why. It seems that the wxModule mechanism doesn't work for you. Please check whether method wxPdfDocumentModule::OnInit() gets called at all (set a break point in your debugger in this method). The next step depends on the result of this check. If the method OnInit doesn't get called the wxModule mechanism is broken. For example, if you are using wxWidgets through wxPython using dynamic loading of libraries it could be that the wxModule initialization doesn't get called. If the method OnInit gets called you have to find out when and where wxPdfFontManager::ms_fontManager gets reset to NULL.
praks411 wrote:I even tried replacing DECLARE_DYNAMIC_CLASS with wxDECLARE_DYNAMIC_CLASS and similar for IMPLEMENT_DYNAMIC_CLASS. However still it is not working.
Since the macros without the wx prefix just map to the new macros WITH wx prefix, it is clear that this modification can't solve the problem.
praks411 wrote:Please someone suggest what could be going wrong and also what other changes do I need to take when migrating from wxWidgets-2.9 to 3.0 with respect to wxpdfdoc-0.9.4
As said I'm not aware of specific changes to use wxPdfDocument with wxWidgets 3.0. Please answer the questions stated above and perform the checks mentioned above. With the answers we might be able to track down the problem.

Regards,

Ulrich
praks411
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Mar 16, 2013 9:31 am

Re: wxPdfDocument with wxWidgets 3.0 font manager failing

Post by praks411 »

Hi Ulrich,

Many thanks for the detailed explanation. Please find below some of the answers
1. Version of wxWidgets-3.0.0 with wxpdfdoc-0.9.4
2. Build using MS Visual Studio 2013 on Windows 7 64 bit machine, application mode 32bit debug build.
3. Regarding the function SetFont, i tried using both the call SetFont(wxT("Arial"), wxT("B"), 10) and SetFont(wxFont(wxFontInfo(8).FaceName("Arial"))) both of them ultimately call SelectFont which in turn call wxPdfFontManager::GetFontManager()->GetFont(font.GetFaceName(), styles). The main point is they uses GetFontManger() which is NULL.
4. You are correct I tried putting breakpoint in wxPdfDocumentModule in both OnInit() and OnExit() function but break point is not reached which means wxModule is not getting called so I think wxModule mechanism is broken.

Here is the snippet of my code, this was working perfectly with wxpdfdoc-0.9.4 and wxWidgets-2.9

Code: Select all

  wxPdfDocument m_pdfDoc(wxPORTRAIT, wxString("in"), wxPAPER_A4);
  wxPaperSize  m_selectPaperSize(wxPAPER_A4);
  wxPrintOrientation  m_selectedOrient(wxPORTRAIT);
  m_pdfDoc.SetFont(wxT("Arial"), wxT("B"), 10);
  //m_pdfDoc.SetFont(wxFont(wxFontInfo(8).FaceName("Arial")));
  m_pdfDoc.AddPage((int)m_selectedOrient, wxPaperSize(m_selectPaperSize));
I tried building wxWidgets and wxpdfdoc again but it is not helping. I'm getting the same error.
Please suggest if I'm missing something.

Thanks and Regards,
Pradeep
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument with wxWidgets 3.0 font manager failing

Post by utelle »

Hi Pradeep,
praks411 wrote:Many thanks for the detailed explanation. Please find below some of the answers
1. Version of wxWidgets-3.0.0 with wxpdfdoc-0.9.4
2. Build using MS Visual Studio 2013 on Windows 7 64 bit machine, application mode 32bit debug build.
Up to now I used VC++ 2008 and VC++ 2010 for the development of wxPdfDocument, but I have VC++ 2013 installed in a virtual machine. I just made a quick test to compile wxPdfDocument using wxWidgets 3.0.1. The sample applications work as expected on my machine, that is, the wxModule OnInit method gets called and initializes the global wxPdfFontManager instance.
praks411 wrote:3. Regarding the function SetFont, i tried using both the call SetFont(wxT("Arial"), wxT("B"), 10) and SetFont(wxFont(wxFontInfo(8).FaceName("Arial"))) both of them ultimately call SelectFont which in turn call wxPdfFontManager::GetFontManager()->GetFont(font.GetFaceName(), styles).
Now, this sounds a bit strange. Yes, the font manager method GetFont is always called, but argument 1 is font.GetFaceName() only if SelecFont was called with a wxFont object.
praks411 wrote:The main point is they uses GetFontManger() which is NULL.

4. You are correct I tried putting breakpoint in wxPdfDocumentModule in both OnInit() and OnExit() function but break point is not reached which means wxModule is not getting called so I think wxModule mechanism is broken.
Unfortunately, I have no idea why the wxModule mechanism is not working for you. As stated above I just tested with VC++ 2013 and it worked for me, however, I used a wxWidgets DLL build. I will check static wxWidgets libraries later, too. ... The test with the static libraries also succeeded.
praks411 wrote:Here is the snippet of my code, this was working perfectly with wxpdfdoc-0.9.4 and wxWidgets-2.9

Code: Select all

  wxPdfDocument m_pdfDoc(wxPORTRAIT, wxString("in"), wxPAPER_A4);
  wxPaperSize  m_selectPaperSize(wxPAPER_A4);
  wxPrintOrientation  m_selectedOrient(wxPORTRAIT);
  m_pdfDoc.SetFont(wxT("Arial"), wxT("B"), 10);
  //m_pdfDoc.SetFont(wxFont(wxFontInfo(8).FaceName("Arial")));
  m_pdfDoc.AddPage((int)m_selectedOrient, wxPaperSize(m_selectPaperSize));
The code seems to be ok. However, you should keep in mind that method SetFont will only succeed if you are setting a PDF core font or if you have added the corresponding font to the wxPdfFontManager before calling SetFont.
praks411 wrote:I tried building wxWidgets and wxpdfdoc again but it is not helping. I'm getting the same error.
Please suggest if I'm missing something.
Well, I'm sorry, I'm a bit at a loss. My only guess is that your application doesn't initialize the wxWidgets library correctly. Do you try to build a GUI application or a console application? That is, are you using one of the wxWidgets macros IMPLEMENT_APP or IMPLEMENT_APP_CONSOLE? If nothing helps you could explicitly call wxInitialize to initialize the wxWidgets library (although this should happen automatically in a properly set up wxWidgets application).

Regards,
Ulrich
praks411
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Mar 16, 2013 9:31 am

Re: wxPdfDocument with wxWidgets 3.0 font manager failing

Post by praks411 »

Hi Utrich,

Thank you for your reply and suggestions. It is clear now there is some build issue at my side and wxModule mechanism is not working.
Can you please share what changes you have done when you compiled wxpdfdoc-0.9.4 with wxWidgets-3.0.0 with Visual Studio.
Currently I'm doing changes manually in wxpdfdoc, by changing reference of wxWidgets version from 2.9.5 to 3.0.0
I'm using Visual Studio 2013 on Windows 7 64 bit.

Best Regards,
Pradeep
praks411
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Mar 16, 2013 9:31 am

Re: wxPdfDocument with wxWidgets 3.0 font manager failing

Post by praks411 »

Hi Ulrich,

Thank you for your help and response. It is working now there was some problem in my Visual studio build.

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

Re: wxPdfDocument with wxWidgets 3.0 font manager failing

Post by utelle »

Hi Pradeep,
praks411 wrote:Thank you for your help and response. It is working now there was some problem in my Visual studio build.
Glad to hear that you solved the problems with your build.

Nevertheless, I just committed additional wxPdfDocument build files for wxWidgets 3.0.x to the wxCode SVN. You may find these new build files in subfolder build30 of the wxPdfDocument repository:

http://sourceforge.net/p/wxcode/code/HE ... c/build30/

Opening the VC9 solution with VC++ 2013 and letting VC++ 2013 convert the related project files worked for me. The environment variable WXWIN has to point to the root folder of your wxWidgets installation.

Best Regards,

Ulrich
Post Reply