📄 gprint.cpp
字号:
case wxDOT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; case wxUSER_DASH: { // It may be noted that libgnomeprint between at least // versions 2.8.0 and 2.12.1 makes a copy of the dashes // and then leak the memory since it doesn't set the // internal flag "privatedash" to 0. wxDash *wx_dashes; int num = m_pen.GetDashes (&wx_dashes); gdouble *g_dashes = g_new( gdouble, num ); int i; for (i = 0; i < num; ++i) g_dashes[i] = (gdouble) wx_dashes[i]; gs_lgp -> gnome_print_setdash( m_gpc, num, g_dashes, 0); g_free( g_dashes ); } break; case wxSOLID: case wxTRANSPARENT: default: gs_lgp->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; } unsigned char red = m_pen.GetColour().Red(); unsigned char blue = m_pen.GetColour().Blue(); unsigned char green = m_pen.GetColour().Green(); if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) { double redPS = (double)(red) / 255.0; double bluePS = (double)(blue) / 255.0; double greenPS = (double)(green) / 255.0; gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); m_currentRed = red; m_currentBlue = blue; m_currentGreen = green; }}void wxGnomePrintDC::SetBrush( const wxBrush& brush ){ if (!brush.Ok()) return; m_brush = brush; // Brush colour unsigned char red = m_brush.GetColour().Red(); unsigned char blue = m_brush.GetColour().Blue(); unsigned char green = m_brush.GetColour().Green(); if (!m_colour) { // Anything not white is black if (! (red == (unsigned char) 255 && blue == (unsigned char) 255 && green == (unsigned char) 255) ) { red = (unsigned char) 0; green = (unsigned char) 0; blue = (unsigned char) 0; } // setgray here ? } if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) { double redPS = (double)(red) / 255.0; double bluePS = (double)(blue) / 255.0; double greenPS = (double)(green) / 255.0; gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); m_currentRed = red; m_currentBlue = blue; m_currentGreen = green; }}void wxGnomePrintDC::SetLogicalFunction( int function ){}void wxGnomePrintDC::SetBackground( const wxBrush& brush ){}void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height){}void wxGnomePrintDC::DestroyClippingRegion(){}bool wxGnomePrintDC::StartDoc(const wxString& message){ return true;}void wxGnomePrintDC::EndDoc(){ gs_lgp->gnome_print_end_doc( m_gpc );}void wxGnomePrintDC::StartPage(){ gs_lgp->gnome_print_beginpage( m_gpc, (const guchar*) "page" );}void wxGnomePrintDC::EndPage(){ gs_lgp->gnome_print_showpage( m_gpc );}wxCoord wxGnomePrintDC::GetCharHeight() const{ pango_layout_set_text( m_layout, "H", 1 ); int w,h; pango_layout_get_pixel_size( m_layout, &w, &h ); return h;}wxCoord wxGnomePrintDC::GetCharWidth() const{ pango_layout_set_text( m_layout, "H", 1 ); int w,h; pango_layout_get_pixel_size( m_layout, &w, &h ); return w;}void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, wxCoord *descent, wxCoord *externalLeading, wxFont *theFont ) const{ if ( width ) *width = 0; if ( height ) *height = 0; if ( descent ) *descent = 0; if ( externalLeading ) *externalLeading = 0; if (string.empty()) { return; } // Set new font description if (theFont) pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description ); // Set layout's text#if wxUSE_UNICODE const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); const char *dataUTF8 = (const char *)data;#else const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); if ( !wdata ) { if (width) (*width) = 0; if (height) (*height) = 0; return; } const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); const char *dataUTF8 = (const char *)data;#endif if ( !dataUTF8 ) { // hardly ideal, but what else can we do if conversion failed? return; } pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); int w,h; pango_layout_get_pixel_size( m_layout, &w, &h ); if (width) *width = (wxCoord)(w / m_scaleX); if (height) *height = (wxCoord)(h / m_scaleY); if (descent) { PangoLayoutIter *iter = pango_layout_get_iter(m_layout); int baseline = pango_layout_iter_get_baseline(iter); pango_layout_iter_free(iter); *descent = h - PANGO_PIXELS(baseline); } // Reset old font description if (theFont) pango_layout_set_font_description( m_layout, m_fontdesc );}void wxGnomePrintDC::DoGetSize(int* width, int* height) const{ wxGnomePrintNativeData *native = (wxGnomePrintNativeData*) m_printData.GetNativeData(); // Query page size. This seems to omit the margins double pw,ph; gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); if (width) *width = (int) (pw + 0.5); if (height) *height = (int) (ph + 0.5);}void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const{ wxGnomePrintNativeData *native = (wxGnomePrintNativeData*) m_printData.GetNativeData(); // This code assumes values in Pts. double pw,ph; gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); // Convert to mm. const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); if (width) *width = (int) (pw + 0.5); if (height) *height = (int) (ph + 0.5);}wxSize wxGnomePrintDC::GetPPI() const{ return wxSize(72,72);}void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ){ m_signX = (xLeftRight ? 1 : -1); m_signY = (yBottomUp ? 1 : -1); ComputeScaleAndOrigin();}void wxGnomePrintDC::SetLogicalOrigin( wxCoord x, wxCoord y ){ wxDC::SetLogicalOrigin( x, y );}void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y ){ wxDC::SetDeviceOrigin( x, y );}void wxGnomePrintDC::SetResolution(int ppi){}int wxGnomePrintDC::GetResolution(){ return 72;}class wxGnomePrintModule: public wxModule{public: wxGnomePrintModule() {} bool OnInit(); void OnExit();private: DECLARE_DYNAMIC_CLASS(wxGnomePrintModule)};bool wxGnomePrintModule::OnInit(){ gs_lgp = new wxGnomePrintLibrary; if (gs_lgp->IsOk()) wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); return true;}void wxGnomePrintModule::OnExit(){ delete gs_lgp;}IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule)// ----------------------------------------------------------------------------// Print preview// ----------------------------------------------------------------------------IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase)void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout), wxPrintout * WXUNUSED(printoutForPrinting)){ DetermineScaling();}wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintDialogData *data) : wxPrintPreviewBase(printout, printoutForPrinting, data){ Init(printout, printoutForPrinting);}wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data) : wxPrintPreviewBase(printout, printoutForPrinting, data){ Init(printout, printoutForPrinting);}wxGnomePrintPreview::~wxGnomePrintPreview(){}bool wxGnomePrintPreview::Print(bool interactive){ if (!m_printPrintout) return false; wxPrinter printer(& m_printDialogData); return printer.Print(m_previewFrame, m_printPrintout, interactive);}void wxGnomePrintPreview::DetermineScaling(){ wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); if (paperType == wxPAPER_NONE) paperType = wxPAPER_NONE; wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); if (paper) { wxSize ScreenPixels = wxGetDisplaySize(); wxSize ScreenMM = wxGetDisplaySizeMM(); m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); m_previewPrintout->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution()); wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); // TODO: get better resolution information from wxGnomePrintDC, if possible. sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrintDC::GetResolution() / 72.0); sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrintDC::GetResolution() / 72.0); wxSize sizeTenthsMM(paper->GetSize()); wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); // If in landscape mode, we need to swap the width and height. if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) { m_pageWidth = sizeDevUnits.y; m_pageHeight = sizeDevUnits.x; m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); } else { m_pageWidth = sizeDevUnits.x; m_pageHeight = sizeDevUnits.y; m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); } m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); // At 100%, the page should look about page-size on the screen. m_previewScaleX = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution(); m_previewScaleY = m_previewScaleX; }}#endif // wxUSE_LIBGNOMEPRINT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -