📄 gprint.cpp
字号:
return;
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
#endif
size_t datalen = strlen((const char*)data);
pango_layout_set_text( m_layout, (const char*) data, datalen);
if (underlined)
{
PangoAttrList *attrs = pango_attr_list_new();
PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
a->start_index = 0;
a->end_index = datalen;
pango_attr_list_insert(attrs, a);
pango_layout_set_attributes(m_layout, attrs);
pango_attr_list_unref(attrs);
}
if (m_textForegroundColour.Ok())
{
unsigned char red = m_textForegroundColour.Red();
unsigned char blue = m_textForegroundColour.Blue();
unsigned char green = m_textForegroundColour.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;
}
}
int w,h;
if (fabs(m_scaleY - 1.0) > 0.00001)
{
// If there is a user or actually any scale applied to
// the device context, scale the font.
// scale font description
gint oldSize = pango_font_description_get_size( m_fontdesc );
double size = oldSize;
size = size * m_scaleY;
pango_font_description_set_size( m_fontdesc, (gint)size );
// actually apply scaled font
pango_layout_set_font_description( m_layout, m_fontdesc );
pango_layout_get_pixel_size( m_layout, &w, &h );
#if 0
if ( m_backgroundMode == wxSOLID )
{
gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
}
#endif
// Draw layout.
gs_lgp->gnome_print_moveto (m_gpc, x, y);
if (fabs(angle) > 0.00001)
{
gs_lgp->gnome_print_gsave( m_gpc );
gs_lgp->gnome_print_rotate( m_gpc, angle );
gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
gs_lgp->gnome_print_grestore( m_gpc );
}
else
{
gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
}
// reset unscaled size
pango_font_description_set_size( m_fontdesc, oldSize );
// actually apply unscaled font
pango_layout_set_font_description( m_layout, m_fontdesc );
}
else
{
pango_layout_get_pixel_size( m_layout, &w, &h );
#if 0
if ( m_backgroundMode == wxSOLID )
{
gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
}
#endif
// Draw layout.
gs_lgp->gnome_print_moveto (m_gpc, x, y);
if (fabs(angle) > 0.00001)
{
gs_lgp->gnome_print_gsave( m_gpc );
gs_lgp->gnome_print_rotate( m_gpc, angle );
gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
gs_lgp->gnome_print_grestore( m_gpc );
}
else
{
gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );
}
}
if (underlined)
{
// undo underline attributes setting:
pango_layout_set_attributes(m_layout, NULL);
}
CalcBoundingBox (x + w, y + h);
}
void wxGnomePrintDC::Clear()
{
}
void wxGnomePrintDC::SetFont( const wxFont& font )
{
m_font = font;
if (m_font.Ok())
{
if (m_fontdesc)
pango_font_description_free( m_fontdesc );
m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
pango_layout_set_font_description( m_layout, m_fontdesc );
}
}
void wxGnomePrintDC::SetPen( const wxPen& pen )
{
if (!pen.Ok()) return;
m_pen = pen;
gs_lgp->gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f );
static const double dotted[] = {2.0, 5.0};
static const double short_dashed[] = {4.0, 4.0};
static const double wxCoord_dashed[] = {4.0, 8.0};
static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0};
switch (m_pen.GetStyle())
{
case wxDOT: gs_lgp->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break;
case wxSHORT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break;
case wxLONG_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break;
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)
{
SetDeviceOrigin( 0,0 );
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
// right now, although it shouldn't
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::SetDeviceOrigin( wxCoord x, wxCoord y )
{
int h = 0;
int w = 0;
GetSize( &w, &h );
wxDC::SetDeviceOrigin( x, h-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)
#endif
// wxUSE_LIBGNOMEPRINT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -