bool EditPrint::PrintScaling (wxDC *dc){ // check for dc, return if none if (!dc) return false; // get printer and screen sizing values wxSize ppiScr; GetPPIScreen (&ppiScr.x, &ppiScr.y); if (ppiScr.x == 0) { // most possible guess 96 dpi ppiScr.x = 96; ppiScr.y = 96; } wxSize ppiPrt; GetPPIPrinter (&ppiPrt.x, &ppiPrt.y); if (ppiPrt.x == 0) { // scaling factor to 1 ppiPrt.x = ppiScr.x; ppiPrt.y = ppiScr.y; } wxSize dcSize = dc->GetSize(); wxSize pageSize; GetPageSizePixels (&pageSize.x, &pageSize.y); // set user scale float scale_x = (float)(ppiPrt.x * dcSize.x) / (float)(ppiScr.x * pageSize.x); float scale_y = (float)(ppiPrt.y * dcSize.y) / (float)(ppiScr.y * pageSize.y); dc->SetUserScale (scale_x, scale_y); return true; }
void MunkHtmlPrintout::OnPreparePrinting() { int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h; float ppmm_h, ppmm_v; GetPageSizePixels(&pageWidth, &pageHeight); GetPageSizeMM(&mm_w, &mm_h); ppmm_h = (float)pageWidth / mm_w; ppmm_v = (float)pageHeight / mm_h; int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); int ppiScreenX, ppiScreenY; GetPPIScreen(&ppiScreenX, &ppiScreenY); wxDisplaySize(&scr_w, &scr_h); GetDC()->GetSize(&dc_w, &dc_h); GetDC()->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_h / (double)pageHeight); /* prepare headers/footers renderer: */ m_RendererHdr->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY); m_RendererHdr->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)), (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom))); if (m_Headers[0] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[0], 1)); m_HeaderHeight = m_RendererHdr->GetTotalHeight(); } else if (m_Headers[1] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[1], 1)); m_HeaderHeight = m_RendererHdr->GetTotalHeight(); } if (m_Footers[0] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[0], 1)); m_FooterHeight = m_RendererHdr->GetTotalHeight(); } else if (m_Footers[1] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[1], 1)); m_FooterHeight = m_RendererHdr->GetTotalHeight(); } /* prepare main renderer: */ m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY); m_Renderer->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)), (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom) - m_FooterHeight - m_HeaderHeight - ((m_HeaderHeight == 0) ? 0 : m_MarginSpace * ppmm_v) - ((m_FooterHeight == 0) ? 0 : m_MarginSpace * ppmm_v) )); m_Renderer->SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir); CountPages(); }
float wxTextPrintout::GetScale() { // First calculate scale int pw=0,ph=0,sw=0,sh=0; GetPPIPrinter(&pw,&ph); GetPPIScreen(&sw,&sh); if ((sw==0)||(sh==0)) { return float(1);} return (float(pw)/sw+float(ph)/sh)/2; }
void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) { // initialize values *minPage = 0; *maxPage = 0; *selPageFrom = 0; *selPageTo = 0; // scale DC if possible wxDC *dc = GetDC(); if (!dc) return; PrintScaling (dc); // get print page informations and convert to printer pixels wxSize ppiScr; GetPPIScreen (&ppiScr.x, &ppiScr.y); wxSize page = g_pageSetupData->GetPaperSize(); page.x = static_cast<int> (page.x * ppiScr.x / 25.4); page.y = static_cast<int> (page.y * ppiScr.y / 25.4); m_pageRect = wxRect (0, 0, page.x, page.y); // get margins informations and convert to printer pixels wxPoint pt = g_pageSetupData->GetMarginTopLeft(); int left = pt.x; int top = pt.y; pt = g_pageSetupData->GetMarginBottomRight(); int right = pt.x; int bottom = pt.y; top = static_cast<int> (top * ppiScr.y / 25.4); bottom = static_cast<int> (bottom * ppiScr.y / 25.4); left = static_cast<int> (left * ppiScr.x / 25.4); right = static_cast<int> (right * ppiScr.x / 25.4); m_printRect = wxRect (left, top, page.x - (left + right), page.y - (top + bottom)); // count pages while (HasPage (*maxPage)) { m_printed = m_edit->FormatRange (0, m_printed, m_edit->GetLength(), dc, dc, m_printRect, m_pageRect); *maxPage += 1; } if (*maxPage > 0) *minPage = 1; *selPageFrom = *minPage; *selPageTo = *maxPage; }
double MathPrintout::GetPPIScale() { int ppiScreenX, ppiScreenY; int ppiPrinterX, ppiPrinterY; GetPPIScreen(&ppiScreenX, &ppiScreenY); GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); #if defined __WXMAC__ return 0.6*((double)ppiPrinterY) / ((double)ppiScreenY); #else return ((double)ppiPrinterY) / ((double)ppiScreenY); #endif }
void wxHtmlPrintout::RenderPage(wxDC *dc, int page) { wxBusyCursor wait; int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h; float ppmm_h, ppmm_v; GetPageSizePixels(&pageWidth, &pageHeight); GetPageSizeMM(&mm_w, &mm_h); ppmm_h = (float)pageWidth / mm_w; ppmm_v = (float)pageHeight / mm_h; wxDisplaySize(&scr_w, &scr_h); dc->GetSize(&dc_w, &dc_h); int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); wxUnusedVar(ppiPrinterX); int ppiScreenX, ppiScreenY; GetPPIScreen(&ppiScreenX, &ppiScreenY); wxUnusedVar(ppiScreenX); dc->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_h / (double)pageHeight); m_Renderer->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY); dc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); m_Renderer->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), m_PageBreaks, m_PageBreaks[page-1], false, m_PageBreaks[page]-m_PageBreaks[page-1]); m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY); if (m_Headers[page % 2] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page)); m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop), m_PageBreaks); } if (m_Footers[page % 2] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page)); m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight), m_PageBreaks); } }
//------------------------------------------------------------------------------ // bool PrintScaling(wxDC *dc) //------------------------------------------------------------------------------ bool EditorPrintout::PrintScaling(wxDC *dc) { #ifdef DEBUG_PRINTOUT MessageInterface::ShowMessage("EditorPrintout::PrintScaling() entered\n"); #endif // check for dc, return if none if(!dc) return false; // get printer and screen sizing values wxSize ppiScr; GetPPIScreen(&ppiScr.x, &ppiScr.y); if(ppiScr.x == 0) { // most possible guess 96 dpi ppiScr.x = 96; ppiScr.y = 96; } wxSize ppiPrt; GetPPIPrinter(&ppiPrt.x, &ppiPrt.y); if(ppiPrt.x == 0) { // scaling factor to 1 ppiPrt.x = ppiScr.x; ppiPrt.y = ppiScr.y; } wxSize dcSize = dc->GetSize(); wxSize pageSize; GetPageSizePixels(&pageSize.x, &pageSize.y); // set user scale float scale_x =(float)(ppiPrt.x * dcSize.x) / (float)(ppiScr.x * pageSize.x); float scale_y =(float)(ppiPrt.y * dcSize.y) / (float)(ppiScr.y * pageSize.y); dc->SetUserScale(scale_x, scale_y); #ifdef DEBUG_PRINTOUT MessageInterface::ShowMessage ("EditorPrintout::PrintScaling() returning true\n"); #endif return true; }
bool TrussPrintout::OnPrintPage(int pageNum) { assert(HasPage(pageNum) && "this should only be called if HasPage returns true"); wxDC *dc = GetDC(); if (!dc || !dc->IsOk()) return false; int printer_x, printer_y, screen_x, screen_y; GetPPIPrinter(&printer_x, &printer_y); GetPPIScreen(&screen_x, &screen_y); float scale = printer_x / (float)screen_x; // wxFont is stupid apparently and uses "points" that don't actually match // up on the page. wxFont &f = *wxTheFontList->FindOrCreateFont(12 * scale, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); dc->SetFont(f); pages[pageNum-1].print(*dc); return true; }
void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) { // initialize values *minPage = 0; *maxPage = 0; *selPageFrom = 0; *selPageTo = 0; // scale DC if possible wxDC *dc = GetDC(); if (!dc) return; PrintScaling (dc); // get print page informations and convert to printer pixels wxSize ppiScr; GetPPIScreen (&ppiScr.x, &ppiScr.y); wxSize page = g_pageSetupData->GetPaperSize(); page.x = static_cast<int> (page.x * ppiScr.x / 25.4); page.y = static_cast<int> (page.y * ppiScr.y / 25.4); // In landscape mode we need to swap the width and height if ( g_pageSetupData->GetPrintData().GetOrientation() == wxLANDSCAPE ) { wxSwap(page.x, page.y); } m_pageRect = wxRect (0, 0, page.x, page.y); // get margins informations and convert to printer pixels wxPoint pt = g_pageSetupData->GetMarginTopLeft(); int left = pt.x; int top = pt.y; pt = g_pageSetupData->GetMarginBottomRight(); int right = pt.x; int bottom = pt.y; top = static_cast<int> (top * ppiScr.y / 25.4); bottom = static_cast<int> (bottom * ppiScr.y / 25.4); left = static_cast<int> (left * ppiScr.x / 25.4); right = static_cast<int> (right * ppiScr.x / 25.4); m_printRect = wxRect (left, top, page.x - (left + right), page.y - (top + bottom)); // count pages m_pageEnds.Clear(); int printed = 0; while ( printed < m_edit->GetLength() ) { printed = m_edit->FormatRange(false, printed, m_edit->GetLength(), dc, dc, m_printRect, m_pageRect); m_pageEnds.Add(printed); *maxPage += 1; } if (*maxPage > 0) *minPage = 1; *selPageFrom = *minPage; *selPageTo = *maxPage; }
/// Calculate scaling and rectangles, setting the device context scaling void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& headerRect, wxRect& footerRect) { // Get the logical pixels per inch of screen and printer int ppiScreenX, ppiScreenY; GetPPIScreen(&ppiScreenX, &ppiScreenY); int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); // This scales the DC so that the printout roughly represents the // the screen scaling. float scale = (float)((float)ppiPrinterX/(float)ppiScreenX); // Now we have to check in case our real page size is reduced // (e.g. because we're drawing to a print preview memory DC) int pageWidth, pageHeight; int w, h; dc->GetSize(&w, &h); GetPageSizePixels(&pageWidth, &pageHeight); // If printer pageWidth == current DC width, then this doesn't // change. But w might be the preview bitmap width, so scale down. float previewScale = (float)(w/(float)pageWidth); float overallScale = scale * previewScale; // The dimensions used for indentation etc. have to be unscaled // during printing to be correct when scaling is applied. if (!IsPreview()) m_richTextBuffer->SetScale(scale); // Calculate margins int marginLeft = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginLeft); int marginTop = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginTop); int marginRight = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginRight); int marginBottom = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginBottom); // Header and footer margins int headerMargin = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_headerFooterData.GetHeaderMargin()); int footerMargin = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_headerFooterData.GetFooterMargin()); dc->SetUserScale(overallScale, overallScale); wxRect rect((int) (marginLeft/scale), (int) (marginTop/scale), (int) ((pageWidth - marginLeft - marginRight)/scale), (int)((pageHeight - marginTop - marginBottom)/scale)); headerRect = wxRect(0, 0, 0, 0); if (!m_headerFooterData.GetHeaderText(wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT).IsEmpty() || !m_headerFooterData.GetHeaderText(wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_CENTRE).IsEmpty() || !m_headerFooterData.GetHeaderText(wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_RIGHT).IsEmpty() || !m_headerFooterData.GetHeaderText(wxRICHTEXT_PAGE_EVEN, wxRICHTEXT_PAGE_LEFT).IsEmpty() || !m_headerFooterData.GetHeaderText(wxRICHTEXT_PAGE_EVEN, wxRICHTEXT_PAGE_CENTRE).IsEmpty() || !m_headerFooterData.GetHeaderText(wxRICHTEXT_PAGE_EVEN, wxRICHTEXT_PAGE_RIGHT).IsEmpty()) { if (m_headerFooterData.GetFont().Ok()) dc->SetFont(m_headerFooterData.GetFont()); else dc->SetFont(*wxNORMAL_FONT); int charHeight = dc->GetCharHeight(); int headerHeight = (int) (charHeight + headerMargin/scale); headerRect = wxRect(rect.x, rect.y, rect.width, headerHeight); rect.y += headerHeight; rect.height -= headerHeight; } footerRect = wxRect(0, 0, 0, 0); if (!m_headerFooterData.GetFooterText(wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT).IsEmpty() || !m_headerFooterData.GetFooterText(wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_CENTRE).IsEmpty() || !m_headerFooterData.GetFooterText(wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_RIGHT).IsEmpty() || !m_headerFooterData.GetFooterText(wxRICHTEXT_PAGE_EVEN, wxRICHTEXT_PAGE_LEFT).IsEmpty() || !m_headerFooterData.GetFooterText(wxRICHTEXT_PAGE_EVEN, wxRICHTEXT_PAGE_CENTRE).IsEmpty() || !m_headerFooterData.GetFooterText(wxRICHTEXT_PAGE_EVEN, wxRICHTEXT_PAGE_RIGHT).IsEmpty()) { if (m_headerFooterData.GetFont().Ok()) dc->SetFont(m_headerFooterData.GetFont()); else dc->SetFont(*wxNORMAL_FONT); int charHeight = dc->GetCharHeight(); int footerHeight = (int) (charHeight + footerMargin/scale); footerRect = wxRect(rect.x, rect.y + rect.height, rect.width, footerHeight); rect.height -= footerHeight; } textRect = rect; }
void MyPrintout::DrawPageTwo() { // You might use THIS code to set the printer DC to ROUGHLY reflect // the screen text size. This page also draws lines of actual length // 5cm on the page. // Compare this to DrawPageOne(), which uses the really convenient routines // from wxPrintout to fit the screen image onto the printed page. This page // illustrates how to do all the scaling calculations yourself, if you're so // inclined. wxDC *dc = GetDC(); // Get the logical pixels per inch of screen and printer int ppiScreenX, ppiScreenY; GetPPIScreen(&ppiScreenX, &ppiScreenY); int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); // This scales the DC so that the printout roughly represents the screen // scaling. The text point size _should_ be the right size but in fact is // too small for some reason. This is a detail that will need to be // addressed at some point but can be fudged for the moment. float scale = (float)((float)ppiPrinterX/(float)ppiScreenX); // Now we have to check in case our real page size is reduced (e.g. because // we're drawing to a print preview memory DC) int pageWidth, pageHeight; int w, h; dc->GetSize(&w, &h); GetPageSizePixels(&pageWidth, &pageHeight); // If printer pageWidth == current DC width, then this doesn't change. But w // might be the preview bitmap width, so scale down. float overallScale = scale * (float)(w/(float)pageWidth); dc->SetUserScale(overallScale, overallScale); // Calculate conversion factor for converting millimetres into logical // units. There are approx. 25.4 mm to the inch. There are ppi device units // to the inch. Therefore 1 mm corresponds to ppi/25.4 device units. We also // divide by the screen-to-printer scaling factor, because we need to // unscale to pass logical units to DrawLine. // Draw 50 mm by 50 mm L shape float logUnitsFactor = (float)(ppiPrinterX/(scale*25.4)); float logUnits = (float)(50*logUnitsFactor); dc->SetPen(* wxBLACK_PEN); dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250); dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits)); dc->SetBackgroundMode(wxTRANSPARENT); dc->SetBrush(*wxTRANSPARENT_BRUSH); { // GetTextExtent demo: wxString words[7] = { wxT("This "), wxT("is "), wxT("GetTextExtent "), wxT("testing "), wxT("string. "), wxT("Enjoy "), wxT("it!") }; wxCoord w, h; long x = 200, y= 250; wxFont fnt(15, wxSWISS, wxNORMAL, wxNORMAL); dc->SetFont(fnt); for (int i = 0; i < 7; i++) { wxString word = words[i]; word.Remove( word.Len()-1, 1 ); dc->GetTextExtent(word, &w, &h); dc->DrawRectangle(x, y, w, h); dc->GetTextExtent(words[i], &w, &h); dc->DrawText(words[i], x, y); x += w; } } dc->SetFont(wxGetApp().GetTestFont()); dc->DrawText(wxT("Some test text"), 200, 300 ); // TESTING int leftMargin = 20; int rightMargin = 20; int topMargin = 20; int bottomMargin = 20; int pageWidthMM, pageHeightMM; GetPageSizeMM(&pageWidthMM, &pageHeightMM); float leftMarginLogical = (float)(logUnitsFactor*leftMargin); float topMarginLogical = (float)(logUnitsFactor*topMargin); float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin)); float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin)); dc->SetPen(* wxRED_PEN); dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical, (long)rightMarginLogical, (long)topMarginLogical); dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical, (long)rightMarginLogical, (long)bottomMarginLogical); WritePageHeader(this, dc, wxT("A header"), logUnitsFactor); }
void TrussPrintout::OnPreparePrinting() { int page_width, page_height; int current_page_y = 0; GetPageSizePixels(&page_width, &page_height); wxDC *dc = GetDC(); int printer_x, printer_y, screen_x, screen_y; GetPPIPrinter(&printer_x, &printer_y); GetPPIScreen(&screen_x, &screen_y); float scale = printer_x / (float)screen_x; // Use a 12pt font. For some reason wxFont doesn't use real points, so // we still have to scale it. wxFont &font = *wxTheFontList->FindOrCreateFont( 12 * scale, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ); dc->SetFont(font); // Margins: int ml, mt, mr, mb; int widthmm, heightmm; GetPageSizeMM(&widthmm, &heightmm); double one_mm_px = page_width / (double)widthmm; wxPoint margintl = page_setup_dialog_data->GetMarginTopLeft(); wxPoint marginbr = page_setup_dialog_data->GetMarginBottomRight(); ml = margintl.x * one_mm_px; mt = margintl.y * one_mm_px; mr = marginbr.x * one_mm_px; mb = marginbr.y * one_mm_px; page_height -= mt + mb; page_width -= ml + mr; for (int i = 0; i < printitems.size(); ++i) { if (printitems[i]->isbreak()) { PageBreak *pb = static_cast<PageBreak *>(printitems[i]); // Add room for the page header/title. current_page_y = get_text_height(*dc, pb->header); pages.push_back(Page(pb->header, ml, mt, mr, mb)); delete pb; } else { Truss *truss = static_cast<TrussContainer *>(printitems[i])->truss; int truss_height_px = truss->getHeight() * page_width / (60.0 * 12.0); int total_height = truss_height_px + get_text_height(*dc, truss->gettext()); if (!truss->getnotes().empty()) { total_height += get_text_height(*dc, truss->getnotes()); // Add the 1/2 line padding in between title and notes total_height += get_text_height(*dc, wxT("X")) / 2; } if (current_page_y + total_height > page_height) { current_page_y = get_text_height(*dc, "continuation..."); pages.push_back(Page("continuation...", ml, mt, mr, mb)); } pages.back().add(truss); current_page_y += total_height; // Add 3 blank lines of padding before the next truss. current_page_y += get_text_height(*dc, wxT("X")) * 3; delete static_cast<TrussContainer *>(printitems[i]); } } printitems.clear(); }
void wxHtmlPrintout::OnPreparePrinting() { int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h; float ppmm_h, ppmm_v; GetPageSizePixels(&pageWidth, &pageHeight); GetPageSizeMM(&mm_w, &mm_h); ppmm_h = (float)pageWidth / mm_w; ppmm_v = (float)pageHeight / mm_h; int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); wxUnusedVar(ppiPrinterX); int ppiScreenX, ppiScreenY; GetPPIScreen(&ppiScreenX, &ppiScreenY); wxUnusedVar(ppiScreenX); wxDisplaySize(&scr_w, &scr_h); GetDC()->GetSize(&dc_w, &dc_h); GetDC()->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_h / (double)pageHeight); /* prepare headers/footers renderer: */ m_RendererHdr->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY); m_RendererHdr->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)), (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom))); if (m_Headers[0] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[0], 1)); m_HeaderHeight = m_RendererHdr->GetTotalHeight(); } else if (m_Headers[1] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[1], 1)); m_HeaderHeight = m_RendererHdr->GetTotalHeight(); } if (m_Footers[0] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[0], 1)); m_FooterHeight = m_RendererHdr->GetTotalHeight(); } else if (m_Footers[1] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[1], 1)); m_FooterHeight = m_RendererHdr->GetTotalHeight(); } /* prepare main renderer: */ m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY); const int printAreaW = int(ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)); int printAreaH = int(ppmm_v * (mm_h - m_MarginTop - m_MarginBottom)); if ( m_HeaderHeight ) printAreaH -= int(m_HeaderHeight + m_MarginSpace * ppmm_v); if ( m_FooterHeight ) printAreaH -= int(m_FooterHeight + m_MarginSpace * ppmm_v); m_Renderer->SetSize(printAreaW, printAreaH); m_Renderer->SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir); if ( CheckFit(wxSize(printAreaW, printAreaH), wxSize(m_Renderer->GetTotalWidth(), m_Renderer->GetTotalHeight())) ) { // do paginate the document CountPages(); } //else: if we don't call CountPages() m_PageBreaks remains empty and our // GetPageInfo() will return 0 as max page and so nothing will be // printed }
void RawDataVisualizePrintout::DrawPageOne(wxDC *dc) { // You might use THIS code if you were scaling // graphics of known size to fit on the page. // We know the graphic is 200x200. If we didn't know this, // we'd need to calculate it. /* float maxX = 1200; float maxY = 915; // Let's have at least 50 device units margin float marginX = 50; float marginY = 50; // Add the margin to the graphic size maxX += (2*marginX); maxY += (2*marginY); // Get the size of the DC in pixels int w, h; dc->GetSize(&w, &h); // Calculate a suitable scaling factor float scaleX=(float)(w/maxX); float scaleY=(float)(h/maxY); // Use x or y scaling factor, whichever fits on the DC float actualScale = wxMin(scaleX,scaleY); // Calculate the position on the DC for centring the graphic float posX = (float)((w - (200*actualScale))/2.0); float posY = (float)((h - (200*actualScale))/2.0); // Set the scale and origin dc->SetUserScale(actualScale, actualScale); dc->SetDeviceOrigin( (long)posX, (long)posY ); */ // Get the logical pixels per inch of screen and printer int ppiScreenX, ppiScreenY; GetPPIScreen(&ppiScreenX, &ppiScreenY); int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); // This scales the DC so that the printout roughly represents the // the screen scaling. The text point size _should_ be the right size // but in fact is too small for some reason. This is a detail that will // need to be addressed at some point but can be fudged for the // moment. float scale = 1.0; //(float)((float)ppiPrinterX/(float)ppiScreenX); // Now we have to check in case our real page size is reduced // (e.g. because we're drawing to a print preview memory DC) int pageWidth, pageHeight; int w, h; dc->GetSize(&w, &h); GetPageSizePixels(&pageWidth, &pageHeight); // If printer pageWidth == current DC width, then this doesn't // change. But w might be the preview bitmap width, so scale down. float overallScale = scale * ((float)w/(float)pageWidth); dc->SetUserScale(overallScale, overallScale); wxPrintf(_T("%d %d\n"),w,h); wxPrintf(_T("%d %d\n"),pageWidth, pageHeight); wxPrintf(_T("%d %d\n"),ppiScreenX, ppiScreenY); wxPrintf(_T("%d %d\n"),ppiPrinterX, ppiPrinterY); if (frame->currentplot == 1) frame->DrawRawBoxplot(*dc); else if (frame->currentplot == 2) frame->DrawRawDensityPlot(*dc); }
//------------------------------------------------------------------------------ // void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) //------------------------------------------------------------------------------ void EditorPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) { #ifdef DEBUG_PRINTOUT MessageInterface::ShowMessage("EditorPrintout::GetPageInfo() entered\n"); #endif // initialize values *minPage = 0; *maxPage = 0; *selPageFrom = 0; *selPageTo = 0; // scale DC if possible wxDC *dc = GetDC(); if(!dc) return; PrintScaling(dc); // get print page informations and convert to printer pixels wxSize ppiScr; GetPPIScreen(&ppiScr.x, &ppiScr.y); wxSize page = globalPageSetupData->GetPaperSize(); page.x = static_cast<int>(page.x * ppiScr.x / 25.4); page.y = static_cast<int>(page.y * ppiScr.y / 25.4); mPageRect = wxRect(0, 0, page.x, page.y); // get margins informations and convert to printer pixels wxPoint pt = globalPageSetupData->GetMarginTopLeft(); int left = pt.x; int top = pt.y; pt = globalPageSetupData->GetMarginBottomRight(); int right = pt.x; int bottom = pt.y; top = static_cast<int>(top * ppiScr.y / 25.4); bottom = static_cast<int>(bottom * ppiScr.y / 25.4); left = static_cast<int>(left * ppiScr.x / 25.4); right = static_cast<int>(right * ppiScr.x / 25.4); mPrintRect = wxRect(left, top, page.x -(left + right), page.y -(top + bottom)); // count pages //while (HasPage(*maxPage)) <== causing infinite loop (loj) if (HasPage(*maxPage)) { mPagePrinted = mEditor->FormatRange(0, mPagePrinted, mEditor->GetLength(), dc, dc, mPrintRect, mPageRect); #ifdef DEBUG_PRINTOUT MessageInterface::ShowMessage(" mPagePrinted=%d\n", mPagePrinted); #endif *maxPage += 1; } if(*maxPage > 0) *minPage = 1; *selPageFrom = *minPage; *selPageTo = *maxPage; #ifdef DEBUG_PRINTOUT MessageInterface::ShowMessage("EditorPrintout::GetPageInfo() exiting\n"); #endif }