bool EditorPrintout::OnPrintPage(int pageNum) { wxASSERT(m_line && m_lineList); if (m_pages.empty()) return true; unsigned int page_ndx = pageNum-1; // page numbers start from one const unsigned int lastline = m_pages[page_ndx]; unsigned int line_id = page_ndx ? m_pages[page_ndx-1]+1 : 0; // Make page size scale with screen resolution MapScreenSizeToPage(); const wxRect rect = GetLogicalPageRect(); unsigned int ypos = rect.y; // We may have gotten a new dc, so we need a new line wxDC& dc = *GetDC(); const wxFont& font = m_theme.font; dc.SetFont(font); FixedLine line(dc, m_printDoc.GetDocument(), s_sel, s_brackets, s_lastpos, s_isShadow, m_theme); line.SetPrintMode(); line.Init(); line.SetWordWrap(cxWRAP_SMART); line.SetWidth(rect.width - m_gutter_width); // Draw gutter separator const unsigned int sep_xpos = m_gutter_width - 5; const unsigned int number_right = m_gutter_width - 8; dc.DrawLine(sep_xpos, rect.y, sep_xpos, rect.y + m_page_height); // Draw lines while (line_id <= lastline) { // Draw line number const wxString linenumber = wxString::Format(wxT("%u"), line_id+1); const wxSize ln_ext = dc.GetTextExtent(linenumber); dc.DrawText(linenumber, number_right - ln_ext.x, ypos); // Draw line line.SetLine(m_lineList->offset(line_id), m_lineList->end(line_id)); line.DrawLine(rect.x + m_gutter_width, ypos, rect, false); ypos += line.GetHeight(); ++line_id; } // Draw footer title ypos = rect.GetBottom() - m_line->GetCharHeight(); dc.DrawText(m_printDoc.GetName(), 0, ypos); // Draw footer pagenum const wxString pagefooter = wxString::Format(wxT("%d / %d"), pageNum, m_pages.size()); const wxSize extent = dc.GetTextExtent(pagefooter); dc.DrawText(pagefooter, rect.GetRight() - extent.x, ypos); return true; }
void EditorPrintout::OnPreparePrinting() { // Make page size scale with screen resolution MapScreenSizeToPage(); const wxRect size = GetLogicalPageRect(); // Set the current themes font const wxFont& font = m_theme.font; wxDC& dc = *GetDC(); dc.SetFont(font); // Initialize line info m_line = new FixedLine(dc, m_printDoc.GetDocument(), s_sel, s_brackets, s_lastpos, s_isShadow, m_theme); m_line->SetPrintMode(); m_line->Init(); m_line->SetWordWrap(cxWRAP_SMART); m_lineList = new LineListWrap(*m_line, m_printDoc.GetDocument()); m_lineList->SetOffsets(m_printDoc.GetOffsets()); // Calc gutter width const wxSize digit_ext = dc.GetTextExtent(wxT("0")); const unsigned int max_num_width = digits_in_number(m_lineList->size()); m_gutter_width = (max_num_width * digit_ext.x) + 8; m_line->SetWidth(size.width - m_gutter_width); m_lineList->invalidate(); m_lineList->prepare_all(); m_page_height = size.height - (m_line->GetCharHeight() * 2); // room for footer // Calculate page list if (m_lineList->size()) { unsigned int bottom_ypos = m_page_height; // Calc lines on pages while (bottom_ypos <= m_lineList->height()) { const unsigned int lastline = m_lineList->find_ypos(bottom_ypos)-1; m_pages.push_back(lastline); bottom_ypos = m_lineList->bottom(lastline) + m_page_height; } if (bottom_ypos > m_lineList->height()) m_pages.push_back(m_lineList->last()); } }
bool MyPrintout::OnPrintPage(int page) { wxDC *dc = GetDC(); if (dc) { if (page == 1) DrawPageOne(); else if (page == 2) DrawPageTwo(); // Draw page numbers at top left corner of printable area, sized so that // screen size of text matches paper size. MapScreenSizeToPage(); dc->DrawText(wxString::Format(wxT("PAGE %d"), page), 0, 0); return true; } else return false; }
bool wxSFPrintout::OnPrintPage(int page) { wxUnusedVar( page ); wxASSERT_MSG(m_pCanvas, wxT("Shape canvas must be set in the wxSFPrintout class instance.")); wxDC *dc = GetDC(); if (dc && m_pCanvas) { // get grawing size wxRect fitRect, totalBB = m_pCanvas->GetTotalBoundingBox(); wxCoord maxX = totalBB.GetRight(); wxCoord maxY = totalBB.GetBottom(); // set printing mode switch( m_pCanvas->GetPrintMode() ) { case wxSFShapeCanvas::prnFIT_TO_PAGE: FitThisSizeToPage(wxSize(maxX, maxY)); fitRect = GetLogicalPageRect(); break; case wxSFShapeCanvas::prnFIT_TO_PAPER: FitThisSizeToPaper(wxSize(maxX, maxY)); fitRect = GetLogicalPaperRect(); break; case wxSFShapeCanvas::prnFIT_TO_MARGINS: FitThisSizeToPageMargins(wxSize(maxX, maxY), *g_pageSetupData); fitRect = GetLogicalPageMarginsRect(*g_pageSetupData); break; case wxSFShapeCanvas::prnMAP_TO_PAGE: MapScreenSizeToPage(); fitRect = GetLogicalPageRect(); break; case wxSFShapeCanvas::prnMAP_TO_PAPER: MapScreenSizeToPaper(); fitRect = GetLogicalPaperRect(); break; case wxSFShapeCanvas::prnMAP_TO_MARGINS: MapScreenSizeToPage(); fitRect = GetLogicalPageMarginsRect(*g_pageSetupData); break; case wxSFShapeCanvas::prnMAP_TO_DEVICE: MapScreenSizeToDevice(); fitRect = GetLogicalPageRect(); break; } // This offsets the image so that it is centered within the reference // rectangle defined above. wxCoord xoff = ((fitRect.width - maxX - totalBB.GetLeft()) / 2) - fitRect.x; wxCoord yoff = ((fitRect.height - maxY - totalBB.GetTop()) / 2) - fitRect.y; switch( m_pCanvas->GetPrintHAlign() ) { case wxSFShapeCanvas::halignLEFT: xoff = 0; break; case wxSFShapeCanvas::halignRIGHT: xoff = fitRect.width - totalBB.GetWidth(); break; default: break; } switch( m_pCanvas->GetPrintVAlign() ) { case wxSFShapeCanvas::valignTOP: yoff = 0; break; case wxSFShapeCanvas::valignBOTTOM: yoff = fitRect.height - totalBB.GetHeight(); break; default: break; } OffsetLogicalOrigin(xoff, yoff); // store current canvas properties double prevScale = m_pCanvas->GetScale(); long prevStyle = m_pCanvas->GetStyle(); wxColour prevColour = m_pCanvas->GetCanvasColour(); // disable canvas background drawing if required if( !m_pCanvas->ContainsStyle( wxSFShapeCanvas::sfsPRINT_BACKGROUND ) ) { m_pCanvas->RemoveStyle( wxSFShapeCanvas::sfsGRADIENT_BACKGROUND ); m_pCanvas->RemoveStyle( wxSFShapeCanvas::sfsGRID_SHOW ); m_pCanvas->SetCanvasColour( *wxWHITE); } // draw the canvas content without any scale (dc is scaled by the printing framework) #if wxVERSION_NUMBER < 2900 double nScale = 1; if( wxSFShapeCanvas::IsGCEnabled() ) dc->GetUserScale( &nScale, &nScale ); m_pCanvas->SetScale(1); #ifdef __WXMSW__ wxSFScaledDC sdc( (wxWindowDC*)dc, nScale ); sdc.PrepareGC(); m_pCanvas->DrawContent(sdc, sfNOT_FROM_PAINT); #else m_pCanvas->DrawContent(*dc, sfNOT_FROM_PAINT); #endif m_pCanvas->SetScale(prevScale); #else m_pCanvas->SetScale(1); m_pCanvas->DrawContent(*dc, sfNOT_FROM_PAINT); m_pCanvas->SetScale(prevScale); #endif // restore previous canvas properties if needed if( !m_pCanvas->ContainsStyle( wxSFShapeCanvas::sfsPRINT_BACKGROUND ) ) { m_pCanvas->SetStyle( prevStyle ); m_pCanvas->SetCanvasColour( prevColour ); } return true; } else return false; }