X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/793db75554d2d2bc5dc9b0fc42c0b7aa03a44183..c0b0635cf69537ca32377bad5650b39402cb21b6:/src/generic/dcpsg.cpp?ds=sidebyside diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index ed4bf8e189..2e423e5501 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -36,6 +36,7 @@ #include "wx/log.h" #include "wx/generic/dcpsg.h" #include "wx/prntbase.h" +#include "wx/generic/prntdlgg.h" #include "wx/paper.h" #include "wx/filefn.h" #if WXWIN_COMPATIBILITY_2_2 @@ -274,7 +275,7 @@ wxPostScriptDC::wxPostScriptDC () m_pageNumber = 0; - m_clipping = FALSE; + m_clipping = false; m_underlinePosition = 0.0; m_underlineThickness = 0.0; @@ -293,7 +294,7 @@ wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData) m_pageNumber = 0; - m_clipping = FALSE; + m_clipping = false; m_underlinePosition = 0.0; m_underlineThickness = 0.0; @@ -303,7 +304,7 @@ wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData) m_printData = printData; - m_ok = TRUE; + m_ok = true; } wxPostScriptDC::~wxPostScriptDC () @@ -326,16 +327,16 @@ bool wxPostScriptDC::Create( const wxString &output, bool interactive, wxWindow { wxPrintDialogData ddata( data ); wxPrintDialog dialog( parent, &data ); - dialog.GetPrintDialogData().SetSetupDialog(TRUE); + dialog.GetPrintDialogData().SetSetupDialog(true); if (dialog.ShowModal() != wxID_OK) { - m_ok = FALSE; - return FALSE; + m_ok = false; + return false; } data = dialog.GetPrintDialogData().GetPrintData(); } - return TRUE; + return true; } #endif @@ -353,7 +354,7 @@ void wxPostScriptDC::DoSetClippingRegion (wxCoord x, wxCoord y, wxCoord w, wxCoo wxDC::DoSetClippingRegion(x, y, w, h); - m_clipping = TRUE; + m_clipping = true; PsPrintf( wxT("gsave\n newpath\n") wxT("%d %d moveto\n") @@ -374,7 +375,7 @@ void wxPostScriptDC::DestroyClippingRegion() if (m_clipping) { - m_clipping = FALSE; + m_clipping = false; PsPrint( "grestore\n" ); } @@ -391,13 +392,13 @@ void wxPostScriptDC::Clear() bool wxPostScriptDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style)) { wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") ); - return FALSE; + return false; } bool wxPostScriptDC::DoGetPixel (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour * WXUNUSED(col)) const { wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") ); - return FALSE; + return false; } void wxPostScriptDC::DoCrossHair (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) @@ -699,14 +700,14 @@ void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], wxCoord xoffset, wxCo wxT("%d %d moveto\n"), LogicalToDeviceX(points[0].x+xoffset), LogicalToDeviceY(points[0].y+yoffset) ); - + for (i = 1; i < n; i++) { PsPrintf( wxT("%d %d lineto\n"), LogicalToDeviceX(points[i].x+xoffset), LogicalToDeviceY(points[i].y+yoffset) ); } - + PsPrint( "stroke\n" ); } @@ -863,7 +864,7 @@ void wxPostScriptDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord void wxPostScriptDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) { - DrawBitmap( icon, x, y, TRUE ); + DrawBitmap( icon, x, y, true ); } /* this has to be char, not wxChar */ @@ -1011,11 +1012,15 @@ void wxPostScriptDC::SetFont( const wxFont& font ) } } + // We may legitimately call SetFont before BeginDoc + if (!m_pstream) + return; + PsPrint( name ); PsPrint( " reencodeISO def\n" ); PsPrint( name ); PsPrint( " findfont\n" ); - + char buffer[100]; sprintf( buffer, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font.GetPointSize() * 1000) / 1000.0F); // this is a hack - we must scale font size (in pts) according to m_scaleY but @@ -1103,7 +1108,7 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) double redPS = (double)(red) / 255.0; double bluePS = (double)(blue) / 255.0; double greenPS = (double)(green) / 255.0; - + char buffer[100]; sprintf( buffer, "%.8f %.8f %.8f setrgbcolor\n", @@ -1112,7 +1117,7 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) if (buffer[i] == ',') buffer[i] = '.'; PsPrint( buffer ); - + m_currentRed = red; m_currentBlue = blue; m_currentGreen = green; @@ -1158,7 +1163,7 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) redPS, greenPS, bluePS ); for (int i = 0; i < 100; i++) if (buffer[i] == ',') buffer[i] = '.'; - + PsPrint( buffer ); m_currentRed = red; @@ -1178,6 +1183,9 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) #include "wx/x11/private.h" #endif +#include +#include FT_FREETYPE_H + #include "wx/fontutil.h" #include #include @@ -1278,6 +1286,25 @@ void draw_bezier_outline(wxPostScriptDC* caller, #endif + +#if wxUSE_PANGO +static void InitializePangoContext(PangoContext *context) +{ +#ifdef __WXGTK__ + pango_context_set_base_dir(context, + gtk_widget_get_default_direction() == GTK_TEXT_DIR_LTR ? + PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL); + pango_context_set_language(context, gtk_get_default_language()); +#else + // FIXME: assuming LTR is incorrect! + pango_context_set_base_dir(context, PANGO_DIRECTION_LTR); + wxString lang = wxGetLocale()->GetCanonicalName(); + pango_context_set_language(context, + pango_language_from_string(lang.ToAscii())); +#endif +} +#endif + void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) { wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); @@ -1326,13 +1353,12 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) int ps_dpi = 72; int pango_dpi = 600; PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi ); + + InitializePangoContext(context); double scale = (double)pango_dpi / (double)ps_dpi; scale /= m_userScaleY; - pango_context_set_language (context, pango_language_from_string ("en_US")); - pango_context_set_base_dir (context, PANGO_DIRECTION_LTR ); - pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description ); PangoLayout *layout = pango_layout_new (context); @@ -1416,7 +1442,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x), LogicalToDeviceY(by) ); PsPrint( "(" ); - + const wxWX2MBbuf textbuf = text.mb_str(); size_t len = strlen(textbuf); size_t i; @@ -1439,9 +1465,9 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) PsPrint(c); } } - + PsPrint( ") show\n" ); - + if (m_font.GetUnderlined()) { wxCoord uy = (wxCoord)(y + size - m_underlinePosition); @@ -1523,7 +1549,7 @@ void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x), LogicalToDeviceY(y)); - + char buffer[100]; sprintf(buffer, "%.8f rotate\n", angle); size_t i; @@ -1532,7 +1558,7 @@ void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord if (buffer[i] == ',') buffer[i] = '.'; } PsPrint( buffer); - + PsPrint( "(" ); const wxWX2MBbuf textbuf = text.mb_str(); size_t len = strlen(textbuf); @@ -1555,16 +1581,16 @@ void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord PsPrint(c); } } - + PsPrint( ") show\n" ); - + sprintf( buffer, "%.8f rotate\n", -angle ); for (i = 0; i < 100; i++) { if (buffer[i] == ',') buffer[i] = '.'; } PsPrint( buffer ); - + if (m_font.GetUnderlined()) { wxCoord uy = (wxCoord)(y + size - m_underlinePosition); @@ -1588,7 +1614,7 @@ void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord } PsPrint( buffer ); } - + CalcBoundingBox( x, y ); CalcBoundingBox( x + size * text.Length() * 2/3 , y ); } @@ -1773,11 +1799,11 @@ wxSize wxPostScriptDC::GetPPI(void) const bool wxPostScriptDC::StartDoc( const wxString& message ) { - wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") ); - - if ( m_printData.GetPrintMode() == wxPRINT_MODE_FILE ) + wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") ); + + if (m_printData.GetPrintMode() != wxPRINT_MODE_STREAM ) { - if (m_printData.GetFilename() == wxT("")) + if (m_printData.GetFilename() == wxEmptyString) { wxString filename = wxGetTempFileName( wxT("ps") ); m_printData.SetFilename(filename); @@ -1789,17 +1815,17 @@ bool wxPostScriptDC::StartDoc( const wxString& message ) if (!m_pstream) { wxLogError( _("Cannot open file for PostScript printing!")); - m_ok = FALSE; - return FALSE; + m_ok = false; + return false; } } - m_ok = TRUE; + m_ok = true; m_title = message; PsPrint( "%!PS-Adobe-2.0\n" ); PsPrintf( wxT("%%%%Title: %s\n"), m_title.c_str() ); - PsPrint( "%%Creator: wxWindows PostScript renderer\n" ); + PsPrint( "%%Creator: wxWidgets PostScript renderer\n" ); PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() ); if (m_printData.GetOrientation() == wxLANDSCAPE) PsPrint( "%%Orientation: Landscape\n" ); @@ -1854,7 +1880,7 @@ bool wxPostScriptDC::StartDoc( const wxString& message ) wxPageNumber = 1; m_pageNumber = 1; - return TRUE; + return true; } void wxPostScriptDC::EndDoc () @@ -1863,7 +1889,7 @@ void wxPostScriptDC::EndDoc () if (m_clipping) { - m_clipping = FALSE; + m_clipping = false; PsPrint( "grestore\n" ); } @@ -1938,17 +1964,20 @@ void wxPostScriptDC::EndDoc () PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury ); #endif -#if defined(__X__) || defined(__WXGTK__) +#ifndef __WXMSW__ + wxPostScriptPrintNativeData *data = + (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); + if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER)) { wxString command; - command += m_printData.GetPrinterCommand(); + command += data->GetPrinterCommand(); command += wxT(" "); - command += m_printData.GetPrinterOptions(); + command += data->GetPrinterOptions(); command += wxT(" "); command += m_printData.GetFilename(); - wxExecute( command, TRUE ); + wxExecute( command, true ); wxRemoveFile( m_printData.GetFilename() ); } #endif @@ -1973,11 +2002,14 @@ void wxPostScriptDC::StartPage() wxCoord translate_x, translate_y; double scale_x, scale_y; - translate_x = (wxCoord)m_printData.GetPrinterTranslateX(); - translate_y = (wxCoord)m_printData.GetPrinterTranslateY(); + wxPostScriptPrintNativeData *data = + (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); + + translate_x = (wxCoord)data->GetPrinterTranslateX(); + translate_y = (wxCoord)data->GetPrinterTranslateY(); - scale_x = m_printData.GetPrinterScaleX(); - scale_y = m_printData.GetPrinterScaleY(); + scale_x = data->GetPrinterScaleX(); + scale_y = data->GetPrinterScaleY(); if (m_printData.GetOrientation() == wxLANDSCAPE) { @@ -2012,9 +2044,9 @@ bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord xsrc, wxCoord ysrc, int rop, bool WXUNUSED(useMask), wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) ) { - wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") ); + wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") ); - wxCHECK_MSG( source, FALSE, wxT("invalid source dc") ); + wxCHECK_MSG( source, false, wxT("invalid source dc") ); /* blit into a bitmap */ wxBitmap bitmap( (int)fwidth, (int)fheight ); @@ -2026,7 +2058,7 @@ bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest, /* draw bitmap. scaling and positioning is done there */ DrawBitmap( bitmap, xdest, ydest ); - return TRUE; + return true; } wxCoord wxPostScriptDC::GetCharHeight() const @@ -2062,12 +2094,11 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, int pango_dpi = 600; PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi ); + InitializePangoContext(context); + double scale = pango_dpi / wx_dpi; scale /= m_userScaleY; - pango_context_set_language (context, pango_language_from_string ("en_US")); - pango_context_set_base_dir (context, PANGO_DIRECTION_LTR ); - PangoLayout *layout = pango_layout_new (context); PangoFontDescription *desc = fontToUse->GetNativeFontInfo()->description; @@ -2079,17 +2110,18 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); #endif pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); - PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; PangoRectangle rect; - pango_layout_line_get_extents(line, NULL, &rect); + pango_layout_get_extents(layout, NULL, &rect); - if (x) (*x) = (wxCoord) ( rect.width / PANGO_SCALE / scale ); - if (y) (*y) = (wxCoord) ( rect.height / PANGO_SCALE / scale ); + if (x) (*x) = (wxCoord) ( PANGO_PIXELS(rect.width) / scale ); + if (y) (*y) = (wxCoord) ( PANGO_PIXELS(rect.height) / scale ); if (descent) { - // Do something about metrics here - (*descent) = 0; + PangoLayoutIter *iter = pango_layout_get_iter(layout); + int baseline = pango_layout_iter_get_baseline(iter); + pango_layout_iter_free(iter); + *descent = wxCoord(*y - PANGO_PIXELS(baseline) / scale); } if (externalLeading) (*externalLeading) = 0; // ?? @@ -2139,7 +2171,7 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, / / example: / - / wxPostScriptDC dc(NULL, TRUE); + / wxPostScriptDC dc(NULL, true); / if (dc.Ok()){ / wxSetAFMPath("d:\\wxw161\\afm\\"); / dc.StartDoc("Test"); @@ -2220,11 +2252,14 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, FILE *afmFile = NULL; + wxPostScriptPrintNativeData *data = + (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); + // Get the directory of the AFM files wxString afmName; - if (!m_printData.GetFontMetricPath().IsEmpty()) + if (!data->GetFontMetricPath().IsEmpty()) { - afmName = m_printData.GetFontMetricPath(); + afmName = data->GetFontMetricPath(); afmName << wxFILE_SEP_PATH << name; afmFile = wxFopen(afmName,wxT("r")); } @@ -2440,13 +2475,16 @@ void wxPostScriptDC::PsPrintf( const wxChar* fmt, ... ) void wxPostScriptDC::PsPrint( const char* psdata ) { - switch( m_printData.GetPrintMode() ) + wxPostScriptPrintNativeData *data = + (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); + + switch (m_printData.GetPrintMode()) { #if wxUSE_STREAMS // append to output stream case wxPRINT_MODE_STREAM: { - wxOutputStream* outputstream = m_printData.GetOutputStream(); + wxOutputStream* outputstream = data->GetOutputStream(); wxCHECK_RET( outputstream, wxT("invalid outputstream") ); outputstream->Write( psdata, strlen( psdata ) ); } @@ -2462,13 +2500,16 @@ void wxPostScriptDC::PsPrint( const char* psdata ) void wxPostScriptDC::PsPrint( int ch ) { - switch( m_printData.GetPrintMode() ) + wxPostScriptPrintNativeData *data = + (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); + + switch (m_printData.GetPrintMode()) { #if wxUSE_STREAMS // append to output stream case wxPRINT_MODE_STREAM: { - wxOutputStream* outputstream = m_printData.GetOutputStream(); + wxOutputStream* outputstream = data->GetOutputStream(); wxCHECK_RET( outputstream, wxT("invalid outputstream") ); outputstream->PutC( ch ); } @@ -2518,12 +2559,12 @@ bool wxPostScriptModule::OnInit() { wxInitializePrintSetupData(); - return TRUE; + return true; } void wxPostScriptModule::OnExit() { - wxInitializePrintSetupData(FALSE); + wxInitializePrintSetupData(false); } #endif // WXWIN_COMPATIBILITY_2_2