30 #include <wx/wfstream.h>
31 #include <wx/except.h>
45 #ifdef PL_HAVE_FREETYPE
46 static void plD_pixel_wxwidgets(
PLStream *pls,
short x,
short y );
47 static PLINT plD_read_pixel_wxwidgets(
PLStream *pls,
short x,
short y );
48 static void plD_set_pixel_wxwidgets(
PLStream *pls,
short x,
short y,
PLINT colour );
49 static void init_freetype_lv1(
PLStream *pls );
50 static void init_freetype_lv2(
PLStream *pls );
60 #include <Carbon/Carbon.h>
61 extern "C" {
void CPSEnableForegroundOperation( ProcessSerialNumber* psn ); }
75 va_start( args, fmt );
76 fprintf( stderr,
"Verbose: " );
77 vfprintf( stderr, fmt, args );
78 fprintf( stderr,
"\n" );
96 va_start( args, fmt );
97 fprintf( stderr,
"Debug: " );
98 vfprintf( stderr, fmt, args );
99 fprintf( stderr,
"\n" );
120 "wxwidgets:wxWidgets Driver:1:wxwidgets:51:wxwidgets\n"
123 "wxpng:wxWidgets PNG Driver:0:wxwidgets:52:wxpng\n"
174 devName = (
const char **) malloc(
NDEV *
sizeof (
char** ) );
176 devDesc = (
const char **) malloc(
NDEV *
sizeof (
char** ) );
245 while ( i < ucs4Len )
252 strncat( utf8_string, utf8,
253 sizeof ( utf8_string ) - strlen( utf8_string ) - 1 );
261 strncat( utf8_string, utf8,
262 sizeof ( utf8_string ) - strlen( utf8_string ) - 1 );
334 PLFLT downscale, downscale2;
337 static PLINT freetype = -1;
338 static PLINT smooth_text = 1;
346 #if wxUSE_GRAPHICS_CONTEXT
355 #ifdef PL_HAVE_FREETYPE
356 {
"freetype",
DRV_INT, &freetype,
"Use FreeType library" },
357 {
"smooth",
DRV_INT, &smooth_text,
"Turn text smoothing on (1) or off (0)" },
359 {
"hrshsym",
DRV_INT, &
hrshsym,
"Use Hershey symbol set (hrshsym=0|1)" },
360 {
"backend",
DRV_INT, &backend,
"Choose backend: (0) standard, (1) using AGG library, (2) using wxGraphicsContext" },
361 {
"text",
DRV_INT, &
text,
"Use own text routines (text=0|1)" },
374 #if wxUSE_GRAPHICS_CONTEXT
386 dev =
new wxPLDevAGG;
389 if ( freetype == -1 )
403 if ( freetype == -1 )
409 plexit(
"Insufficient memory" );
411 pls->
dev = (
void *) dev;
434 #ifdef PL_HAVE_FREETYPE
450 init_freetype_lv1( pls );
451 FT_Data* FT = (FT_Data *) pls->
FT;
452 FT->want_smooth_text = smooth_text;
486 if ( downscale < downscale2 )
487 downscale = downscale2;
501 #ifdef PL_HAVE_FREETYPE
503 init_freetype_lv2( pls );
522 #ifndef ENABLE_DYNDRIVERS
558 #endif // PLD_wxwidgets
570 #ifndef ENABLE_DYNDRIVERS
629 if ( !( dev->
ready ) )
632 dev->
DrawLine( x1a, y1a, x2a, y2a );
659 if ( !( dev->
ready ) )
694 memDC.SelectObject( bitmap );
697 wxImage
buffer = bitmap.ConvertToImage();
698 wxFFileOutputStream fstream( pls->
OutFile );
699 if ( !( buffer.SaveFile( fstream, dev->
bitmapType ) ) )
700 puts(
"Troubles saving file!" );
701 memDC.SelectObject( wxNullBitmap );
787 FT_Data *FT = (FT_Data *) pls->
FT;
789 plD_FreeType_Destroy( pls );
795 wxPLGetApp().RemoveFrame( dev->
m_frame );
796 if ( !wxPLGetApp().FrameCount() )
841 if ( !( dev->
ready ) )
884 if ( !( dev->
ready ) )
889 #ifdef PL_HAVE_FREETYPE
890 plD_render_freetype_text( pls, (
EscText *) ptr );
899 wxSize* size = (wxSize *) ptr;
900 wx_set_size( pls, size->GetWidth(), size->GetHeight() );
905 if ( !( dev->
ready ) )
932 *( (
int *) ptr ) = dev->
backend;
952 if ( !( dev->
ready ) )
1004 #ifdef PL_HAVE_FREETYPE
1007 FT_Data *FT = (FT_Data *) pls->
FT;
1008 FT->scalex = dev->
scalex;
1009 FT->scaley = dev->
scaley;
1024 if ( errormessage[0] )
1026 wxMessageDialog dialog( 0, wxString( errormessage, *wxConvCurrent ), wxString(
"wxWidgets PLplot App error", *wxConvCurrent ), wxOK | wxICON_ERROR );
1042 if ( errormessage[0] )
1044 wxMessageDialog dialog( 0, ( wxString( errormessage, *wxConvCurrent ) + wxString(
" aborting operation...", *wxConvCurrent ) ), wxString(
"wxWidgets PLplot App abort", *wxConvCurrent ), wxOK | wxICON_ERROR );
1052 #ifdef PL_HAVE_FREETYPE
1060 static void plD_pixel_wxwidgets(
PLStream *pls,
short x,
short y )
1066 if ( !( dev->
ready ) )
1069 dev->PutPixel( x, y );
1089 static void plD_set_pixel_wxwidgets(
PLStream *pls,
short x,
short y,
PLINT colour )
1095 if ( !( dev->
ready ) )
1098 dev->PutPixel( x, y, colour );
1118 static PLINT plD_read_pixel_wxwidgets(
PLStream *pls,
short x,
short y )
1124 if ( !( dev->
ready ) )
1127 return dev->GetPixel( x, y );
1139 static void init_freetype_lv1(
PLStream *pls )
1143 plD_FreeType_init( pls );
1145 FT_Data *FT = (FT_Data *) pls->
FT;
1146 FT->pixel = (plD_pixel_fp) plD_pixel_wxwidgets;
1154 FT->BLENDED_ANTIALIASING = 1;
1155 FT->read_pixel = (plD_read_pixel_fp) plD_read_pixel_wxwidgets;
1156 FT->set_pixel = (plD_set_pixel_fp) plD_set_pixel_wxwidgets;
1185 static void init_freetype_lv2(
PLStream *pls )
1190 FT_Data *FT = (FT_Data *) pls->
FT;
1192 FT->scalex = dev->
scalex;
1193 FT->scaley = dev->
scaley;
1196 FT->smooth_text = 0;
1198 if ( ( FT->want_smooth_text == 1 ) && ( FT->BLENDED_ANTIALIASING == 0 ) )
1200 FT->ncol0_org = pls->
ncol0;
1201 FT->ncol0_xtra = 16777216 - ( pls->
ncol1 + pls->
ncol0 );
1202 FT->ncol0_width = FT->ncol0_xtra / ( pls->
ncol0 - 1 );
1203 if ( FT->ncol0_width > 4 )
1215 level_save = pls->
level;
1217 pl_set_extended_cmap0( pls, FT->ncol0_width, FT->ncol0_org );
1218 pls->
level = level_save;
1220 FT->smooth_text = 1;
1223 plwarn(
"Insufficient colour slots available in CMAP0 to do text smoothing." );
1225 else if ( ( FT->want_smooth_text == 1 ) && ( FT->BLENDED_ANTIALIASING == 1 ) )
1227 FT->smooth_text = 1;
1283 static bool initApp =
false;
1290 ProcessSerialNumber psn;
1292 GetCurrentProcess( &psn );
1293 CPSEnableForegroundOperation( &psn );
1294 SetFrontProcess( &psn );
1299 wxLog::GetActiveTarget();
1301 wxPLGetApp().CallOnInit();
1303 wxCATCH_ALL( wxPLGetApp().OnUnhandledException();
plexit(
"Can't init wxWidgets!" ); )
1308 wxString title( pls->
plwindow, *wxConvCurrent );
1312 title += wxT(
" - wxWidgets (basic)" );
1315 title += wxT(
" - wxWidgets (wxGC)" );
1318 title += wxT(
" - wxWidgets (AGG)" );
1324 wxPLGetApp().AddFrame( dev->
m_frame );
1328 if ( dev->
xpos != 0 || dev->
ypos != 0 )
1330 wxDefaultCoord, wxDefaultCoord,
1331 wxSIZE_USE_EXISTING );
1376 ~CallOnExit() {
if ( exit ) wxPLGetApp().OnExit();}
1380 callOnExit.exit =
true;
1381 wxPLGetApp().SetAdvanceFlag( runonce );
1382 wxPLGetApp().SetRefreshFlag();
1387 wxPLGetApp().AddPendingEvent( event );
1388 wxPLGetApp().OnRun();
1389 callOnExit.exit =
false;
1391 wxCATCH_ALL( wxPLGetApp().OnUnhandledException();
plexit(
"Problem running wxWidgets!" ); )
1395 wxPLGetApp().OnExit();