Some more printing code to clear most of
the printing sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30241 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -212,11 +212,20 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
|
|||||||
wxGnomePrintNativeData *data =
|
wxGnomePrintNativeData *data =
|
||||||
(wxGnomePrintNativeData*) printdata.GetNativeData();
|
(wxGnomePrintNativeData*) printdata.GetNativeData();
|
||||||
|
|
||||||
|
// The GnomePrintJob is temporarily stored in the
|
||||||
|
// native print data as the native print setup dialog
|
||||||
|
// needs to access it.
|
||||||
GnomePrintJob *job = data->GetPrintJob();
|
GnomePrintJob *job = data->GetPrintJob();
|
||||||
m_gpc = gnome_print_job_get_context (job);
|
m_gpc = gnome_print_job_get_context (job);
|
||||||
|
|
||||||
|
printout->SetIsPreview(false);
|
||||||
|
|
||||||
|
if (m_printDialogData.GetMinPage() < 1)
|
||||||
|
m_printDialogData.SetMinPage(1);
|
||||||
|
if (m_printDialogData.GetMaxPage() < 1)
|
||||||
|
m_printDialogData.SetMaxPage(9999);
|
||||||
|
|
||||||
wxDC *dc;
|
wxDC *dc;
|
||||||
|
|
||||||
if (prompt)
|
if (prompt)
|
||||||
dc = PrintDialog( parent );
|
dc = PrintDialog( parent );
|
||||||
else
|
else
|
||||||
@@ -225,11 +234,26 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
|
|||||||
if (!dc)
|
if (!dc)
|
||||||
{
|
{
|
||||||
gnome_print_job_close( job );
|
gnome_print_job_close( job );
|
||||||
|
sm_lastError = wxPRINTER_ERROR;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxSize ScreenPixels = wxGetDisplaySize();
|
||||||
|
wxSize ScreenMM = wxGetDisplaySizeMM();
|
||||||
|
|
||||||
|
printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
|
||||||
|
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
|
||||||
|
printout->SetPPIPrinter( wxPostScriptDC::GetResolution(),
|
||||||
|
wxPostScriptDC::GetResolution() );
|
||||||
|
|
||||||
printout->SetDC(dc);
|
printout->SetDC(dc);
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
dc->GetSize(&w, &h);
|
||||||
|
printout->SetPageSizePixels((int)w, (int)h);
|
||||||
|
dc->GetSizeMM(&w, &h);
|
||||||
|
printout->SetPageSizeMM((int)w, (int)h);
|
||||||
|
|
||||||
printout->OnPreparePrinting();
|
printout->OnPreparePrinting();
|
||||||
printout->OnBeginPrinting();
|
printout->OnBeginPrinting();
|
||||||
|
|
||||||
@@ -447,8 +471,6 @@ void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
|
|||||||
x = XLOG2DEV(x);
|
x = XLOG2DEV(x);
|
||||||
y = YLOG2DEV(y);
|
y = YLOG2DEV(y);
|
||||||
|
|
||||||
wxPrintf( wxT("x,y: %d,%d\n"), x, y );
|
|
||||||
|
|
||||||
bool underlined = m_font.Ok() && m_font.GetUnderlined();
|
bool underlined = m_font.Ok() && m_font.GetUnderlined();
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
@@ -589,11 +611,71 @@ wxCoord wxGnomePrintDC::GetCharWidth() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
|
void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
|
||||||
wxCoord *descent,
|
wxCoord *descent,
|
||||||
wxCoord *externalLeading,
|
wxCoord *externalLeading,
|
||||||
wxFont *theFont ) const
|
wxFont *theFont ) const
|
||||||
{
|
{
|
||||||
|
if ( width )
|
||||||
|
*width = 0;
|
||||||
|
if ( height )
|
||||||
|
*height = 0;
|
||||||
|
if ( descent )
|
||||||
|
*descent = 0;
|
||||||
|
if ( externalLeading )
|
||||||
|
*externalLeading = 0;
|
||||||
|
|
||||||
|
if (string.IsEmpty())
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
if (height)
|
||||||
|
*height = (wxCoord) h;
|
||||||
|
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
|
void wxGnomePrintDC::DoGetSize(int* width, int* height) const
|
||||||
@@ -615,8 +697,6 @@ void wxGnomePrintDC::DoGetSize(int* width, int* height) const
|
|||||||
*width = (int) w;
|
*width = (int) w;
|
||||||
if (height)
|
if (height)
|
||||||
*height = (int) h;
|
*height = (int) h;
|
||||||
|
|
||||||
wxPrintf( wxT("size %d,%d\n"), *width, *height );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const
|
void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const
|
||||||
|
@@ -212,11 +212,20 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
|
|||||||
wxGnomePrintNativeData *data =
|
wxGnomePrintNativeData *data =
|
||||||
(wxGnomePrintNativeData*) printdata.GetNativeData();
|
(wxGnomePrintNativeData*) printdata.GetNativeData();
|
||||||
|
|
||||||
|
// The GnomePrintJob is temporarily stored in the
|
||||||
|
// native print data as the native print setup dialog
|
||||||
|
// needs to access it.
|
||||||
GnomePrintJob *job = data->GetPrintJob();
|
GnomePrintJob *job = data->GetPrintJob();
|
||||||
m_gpc = gnome_print_job_get_context (job);
|
m_gpc = gnome_print_job_get_context (job);
|
||||||
|
|
||||||
|
printout->SetIsPreview(false);
|
||||||
|
|
||||||
|
if (m_printDialogData.GetMinPage() < 1)
|
||||||
|
m_printDialogData.SetMinPage(1);
|
||||||
|
if (m_printDialogData.GetMaxPage() < 1)
|
||||||
|
m_printDialogData.SetMaxPage(9999);
|
||||||
|
|
||||||
wxDC *dc;
|
wxDC *dc;
|
||||||
|
|
||||||
if (prompt)
|
if (prompt)
|
||||||
dc = PrintDialog( parent );
|
dc = PrintDialog( parent );
|
||||||
else
|
else
|
||||||
@@ -225,11 +234,26 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
|
|||||||
if (!dc)
|
if (!dc)
|
||||||
{
|
{
|
||||||
gnome_print_job_close( job );
|
gnome_print_job_close( job );
|
||||||
|
sm_lastError = wxPRINTER_ERROR;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxSize ScreenPixels = wxGetDisplaySize();
|
||||||
|
wxSize ScreenMM = wxGetDisplaySizeMM();
|
||||||
|
|
||||||
|
printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
|
||||||
|
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
|
||||||
|
printout->SetPPIPrinter( wxPostScriptDC::GetResolution(),
|
||||||
|
wxPostScriptDC::GetResolution() );
|
||||||
|
|
||||||
printout->SetDC(dc);
|
printout->SetDC(dc);
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
dc->GetSize(&w, &h);
|
||||||
|
printout->SetPageSizePixels((int)w, (int)h);
|
||||||
|
dc->GetSizeMM(&w, &h);
|
||||||
|
printout->SetPageSizeMM((int)w, (int)h);
|
||||||
|
|
||||||
printout->OnPreparePrinting();
|
printout->OnPreparePrinting();
|
||||||
printout->OnBeginPrinting();
|
printout->OnBeginPrinting();
|
||||||
|
|
||||||
@@ -447,8 +471,6 @@ void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
|
|||||||
x = XLOG2DEV(x);
|
x = XLOG2DEV(x);
|
||||||
y = YLOG2DEV(y);
|
y = YLOG2DEV(y);
|
||||||
|
|
||||||
wxPrintf( wxT("x,y: %d,%d\n"), x, y );
|
|
||||||
|
|
||||||
bool underlined = m_font.Ok() && m_font.GetUnderlined();
|
bool underlined = m_font.Ok() && m_font.GetUnderlined();
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
@@ -589,11 +611,71 @@ wxCoord wxGnomePrintDC::GetCharWidth() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
|
void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
|
||||||
wxCoord *descent,
|
wxCoord *descent,
|
||||||
wxCoord *externalLeading,
|
wxCoord *externalLeading,
|
||||||
wxFont *theFont ) const
|
wxFont *theFont ) const
|
||||||
{
|
{
|
||||||
|
if ( width )
|
||||||
|
*width = 0;
|
||||||
|
if ( height )
|
||||||
|
*height = 0;
|
||||||
|
if ( descent )
|
||||||
|
*descent = 0;
|
||||||
|
if ( externalLeading )
|
||||||
|
*externalLeading = 0;
|
||||||
|
|
||||||
|
if (string.IsEmpty())
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
if (height)
|
||||||
|
*height = (wxCoord) h;
|
||||||
|
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
|
void wxGnomePrintDC::DoGetSize(int* width, int* height) const
|
||||||
@@ -615,8 +697,6 @@ void wxGnomePrintDC::DoGetSize(int* width, int* height) const
|
|||||||
*width = (int) w;
|
*width = (int) w;
|
||||||
if (height)
|
if (height)
|
||||||
*height = (int) h;
|
*height = (int) h;
|
||||||
|
|
||||||
wxPrintf( wxT("size %d,%d\n"), *width, *height );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const
|
void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const
|
||||||
|
Reference in New Issue
Block a user