the problem of "wxReportDocument" for print preview

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
dqf88
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Aug 10, 2012 9:59 am

the problem of "wxReportDocument" for print preview

Postby dqf88 » Fri Aug 21, 2015 1:06 pm

When using "wxReportDocument" for print preview, the page can not show all the contents, how to solve this problem, please?
Image 3.png
Image 3.png (49.97 KiB) Viewed 1003 times

beMax56
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Aug 24, 2016 6:54 pm

Re: the problem of "wxReportDocument" for print preview

Postby beMax56 » Wed Aug 24, 2016 7:10 pm

There are several issues with wxReportDocument as it exists on the wxCode server (v1.2.2). What I have found:
1) To compile against wxWidgets 3.1.0, you need to change all references to wxXMLNode->GetProperties() to wxXMLNode->GetAttributes() and all references to wxXMLNode->GetProperty(... to wxXMLNode->GetAttribute(... Making those changes and linking in all of the wxWidget dlls will allow you to build the library and the samples.

2) The printout.cpp module has a bug in how it calculates the overallScale value. It takes the ratio of PPIprinter/PPIScreen and multiplies that by the Printerwidth/screenwidth. I think this was done because of a bug in wxWidgets 2.8 but in 3.1.0 it cause a large scaling error. To fix this, I did not multiply by the ratio of PPIPrinter/PPIscreen. This fixes the size of the items on the print preview and printout but the text scaling is all wrong. All of the text is too small.

I haven't found a way to correct the text scaling but if I do, I will post back.

I hope this helps other users. If someone has fixed these issues, please let me know.

Thanks,

Brian

beMax56
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Aug 24, 2016 6:54 pm

Re: the problem of "wxReportDocument" for print preview

Postby beMax56 » Sat Aug 27, 2016 1:43 am

I have figured out how to fix the wxReportDocument library so that it works correctly with wxWidgets 3.1.0 using the TDM-GCC 5-1 compiler on a WIndows 10 64bit system.

As I mentioned above, changes to the wxXMLNode class require you to replace all references to wxXMLNode->GetProperties() to wxXMLNode->GetAttributes() and all references to wxXMLNode->GetProperty(... to wxXMLNode->GetAttribute(.... That will allow you to compile the code.

The scaling issues were a little harder to figure out. Apparently, there were some bugs in the wxDC classes in ver 2.8 and maybe 2.9 that were fixed in v 3.1.0.

First of all: The changes I mentioned earlier about changes to the printout.cpp routines were not needed after all. I changed them back to the original code.

The only changes needed are in the Pageitems files (both header and cpp file). In the pageitems.h file, a small change is needed to the MM2PX inline functon. I had to comment out the conditional call to dc->GetUserScale and just call that routine. The corrected code looks like this:

Code: Select all

inline int MM2PX(double mm, wxDC *dc, bool toScreen)
{
   double sx = 1.0, sy = 1.0;
//   if( !toScreen ) dc->GetUserScale(&sx, &sy);

    dc->GetUserScale(&sx, &sy);
   return wxRound((((double)(dc->GetPPI().x) / 25.4) * mm) / sx);
}


In the pageitems.cpp file, In the wxReportImageItem::DrawToDC function, I had to comment out the conditional starting with 'if (toScreen)'.
That line was making graphics many times too large. I suspect that was to correct for an earlier bug. In any case, the correct code should be:

Code: Select all

void wxReportImageItem::DrawToDC(wxDC* dc, bool toScreen, const wxReportPageStyle& pageStyle)
{
   wxImage image;
   if(image.LoadFile(this->m_sValue))
   {
      double scale = dc->GetPPI().x / (double)this->m_iPPI; //(25.4 * dc->GetSize().x) / (this->m_iPPI * dc->GetSizeMM().x); // calculate scale factor
      double updscale = scale;
      double prevScaleX = 1, prevScaleY = 1;
      dc->GetUserScale(&prevScaleX, &prevScaleY);
//      if(toScreen) updscale *= prevScaleX;   // <---- this is the commented out code.  Not needed with wxWidgets 3.1.0

       dc->SetUserScale(updscale, updscale);

      int x = (double)(MM2PX(this->m_position.x + pageStyle.GetLeftMargin(), dc, true)) / scale;// / (scale*prevScaleX);
      int y = (double)(MM2PX(this->m_position.y + pageStyle.GetTopMargin(), dc, true)) / scale;// / (scale*prevScaleX);

      dc->DrawBitmap(wxBitmap(image), x, y);

      if(this->m_style.GetBorder() > 0)
      {
         int borderWidth = (double)(MM2PX(this->m_style.GetBorderThickness(), dc, true)) / scale;
         /*int bx = x - borderWidth;
         int by = y - borderWidth;
         int bw = this->m_iWidth + 2*borderWidth;
         int bh = this->m_iHeight + 2*borderWidth;*/
         dc->SetPen(wxPen(this->m_style.GetBorderColor(), borderWidth));
         /*dc->DrawRectangle(bx, by, bw, bh);*/
         dc->DrawRectangle(x, y, this->m_iWidth, this->m_iHeight);
      }

      dc->SetUserScale(prevScaleX, prevScaleY);
   }
}


Once I made those changes, I was able to compile and run the example files and get the results shown in the documentation. This is a really great library for creating database reports. I hope others will find this information helpful. Many thanks to the original authors.

Good luck,

Brian

iwbnwif
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Tue Mar 19, 2013 8:52 pm

Re: the problem of "wxReportDocument" for print preview

Postby iwbnwif » Sun Aug 28, 2016 4:34 pm

Thank you for looking into this and posting the results of your work here, it is certainly useful.

...and all references to wxXMLNode->GetProperty(... to wxXMLNode->GetAttribute(.... That will allow you to compile the code.


Do you mean change all references to wxXMLNode->AddProperty(... to wxXMLNode->AddAttribute(.... ?

Once I made those changes, I was able to compile and run the example files and get the results shown in the documentation.


Are you able to make the TemplateViewer sample work properly? I tried to save the 3 examples created by LayoutGeneratorGUI as XML files and then load them into the TemplateViewer, but the text positioning seems to be wrong compared to the print preview.

Also the TemplateViewer does not setup the PNG image handler, to do so add the following to the start of MainApp::OnInit():

Code: Select all

   
    wxImage::AddHandler( new wxPNGHandler );
    wxImage::AddHandler( new wxJPEGHandler );
wxWidgets 3.10, MinGW 4.7.3, g++ 4.8.2, Ubuntu 14.04LTS, 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.

beMax56
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Aug 24, 2016 6:54 pm

Re: the problem of "wxReportDocument" for print preview

Postby beMax56 » Sun Sep 04, 2016 1:28 am

Hi iwbnwif,

Sorry to take so long to reply. I have not been able to get back to this until this evening.

With respect to getting the library to compile, I was using TDM GCC 5-1 with wxWidgets 3.1.0 under Codeblocks 16.01.

I can't remember the specifics now, sorry. The compiler complained about any calls to AddProperty or GetProperty or AddProperties or GetProperties calls associated with the wxXMLNode class. From looking online, I found that the wxXMLNode class had replaced all references to Add/Get/Property/Properties with Add/Get/Attribute/Attributes so I made changes to any of the instances where the compiler complained. I did not have to make any change other than change Property to Attribute and Properties to Attributes. I hope that is clear.

With respect to the Template Viewer,

I haven't played with that at all. I will try to get a chance to work with that this week. Once I got the Layout Generator and Table demo workiing, I started developing my app It would be nice to be able to store templates and call them up. I'll look into it. Chances are that it is still a little buggy. There were significant changes to wxWidgets between 2.8 when this library was written and 3.1.

I'll post back if I figure anything out. This is just a hobby for me so I can't spend too much time on it.

Brian

iwbnwif
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Tue Mar 19, 2013 8:52 pm

Re: the problem of "wxReportDocument" for print preview

Postby iwbnwif » Sun Sep 04, 2016 8:33 am

Hello,

No problem, this is a sort of sideline for me too!

Although wxReportDocument has a lot of promise, in the end I found LimeReport and wrote some wxWidgets bindings for it.

Of course it would be nice to have a native wxWidgets reporting framework, but this is a good solution for me at the moment.
wxWidgets 3.10, MinGW 4.7.3, g++ 4.8.2, Ubuntu 14.04LTS, 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.


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 1 guest