X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9357a69fb63604fa6db7232ba07f865227463bf1..3c86150dd768b4e490b603227de28aa57275ee4b:/src/generic/dcpsg.cpp diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index c8e91af7ac..b83d33c47e 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -274,7 +274,7 @@ wxPostScriptDC::wxPostScriptDC () m_pageNumber = 0; - m_clipping = FALSE; + m_clipping = false; m_underlinePosition = 0.0; m_underlineThickness = 0.0; @@ -293,7 +293,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 +303,7 @@ wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData) m_printData = printData; - m_ok = TRUE; + m_ok = true; } wxPostScriptDC::~wxPostScriptDC () @@ -326,16 +326,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 +353,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 +374,7 @@ void wxPostScriptDC::DestroyClippingRegion() if (m_clipping) { - m_clipping = FALSE; + m_clipping = false; PsPrint( "grestore\n" ); } @@ -391,13 +391,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 +699,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 +863,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 */ @@ -1014,12 +1014,12 @@ 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 @@ -1107,7 +1107,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", @@ -1116,7 +1116,7 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) if (buffer[i] == ',') buffer[i] = '.'; PsPrint( buffer ); - + m_currentRed = red; m_currentBlue = blue; m_currentGreen = green; @@ -1162,7 +1162,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; @@ -1285,6 +1285,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 = wxLocale::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") ); @@ -1333,13 +1352,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); @@ -1423,7 +1441,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; @@ -1446,9 +1464,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); @@ -1530,7 +1548,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; @@ -1539,7 +1557,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); @@ -1562,16 +1580,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); @@ -1595,7 +1613,7 @@ void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord } PsPrint( buffer ); } - + CalcBoundingBox( x, y ); CalcBoundingBox( x + size * text.Length() * 2/3 , y ); } @@ -1780,11 +1798,11 @@ wxSize wxPostScriptDC::GetPPI(void) const bool wxPostScriptDC::StartDoc( const wxString& message ) { - wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") ); + 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); @@ -1796,17 +1814,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" ); @@ -1861,7 +1879,7 @@ bool wxPostScriptDC::StartDoc( const wxString& message ) wxPageNumber = 1; m_pageNumber = 1; - return TRUE; + return true; } void wxPostScriptDC::EndDoc () @@ -1870,7 +1888,7 @@ void wxPostScriptDC::EndDoc () if (m_clipping) { - m_clipping = FALSE; + m_clipping = false; PsPrint( "grestore\n" ); } @@ -1955,7 +1973,7 @@ void wxPostScriptDC::EndDoc () command += wxT(" "); command += m_printData.GetFilename(); - wxExecute( command, TRUE ); + wxExecute( command, true ); wxRemoveFile( m_printData.GetFilename() ); } #endif @@ -2019,9 +2037,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 ); @@ -2033,7 +2051,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 @@ -2069,12 +2087,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; @@ -2086,17 +2103,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; // ?? @@ -2146,7 +2164,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"); @@ -2525,12 +2543,12 @@ bool wxPostScriptModule::OnInit() { wxInitializePrintSetupData(); - return TRUE; + return true; } void wxPostScriptModule::OnExit() { - wxInitializePrintSetupData(FALSE); + wxInitializePrintSetupData(false); } #endif // WXWIN_COMPATIBILITY_2_2