the problem of "wxReportDocument" for print preview
Posted: 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?
Official forum for the wxWidgets Cross-Platform GUI Toolkit
https://forums.wxwidgets.org/
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);
}
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);
}
}
Do you mean change all references to wxXMLNode->AddProperty(... to wxXMLNode->AddAttribute(.... ?...and all references to wxXMLNode->GetProperty(... to wxXMLNode->GetAttribute(.... That will allow you to compile the code.
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.Once I made those changes, I was able to compile and run the example files and get the results shown in the documentation.
Code: Select all
wxImage::AddHandler( new wxPNGHandler );
wxImage::AddHandler( new wxJPEGHandler );