64 Scaler( wxDC * dc,
double xScale,
double yScale )
68 dc->SetLogicalScale( xScale, yScale );
93 dc->SetLogicalOrigin( xOrigin, yOrigin );
117 m_pen = dc->GetPen();
120 dc->SetBrush( brush );
142 TextObjectsChanger( wxDC *dc,
const wxFont &font,
const wxColour &textForeground,
const wxColour &textBackground )
148 dc->SetTextForeground( textForeground );
149 dc->SetTextBackground( textBackground );
189 std::fstream fin(
"/dev/random", std::ios::in );
200 unsigned int next =
m_seed;
205 result = (
unsigned int) ( next /
max ) % 2048;
210 result ^= (
unsigned int) ( next /
max ) % 1024;
215 result ^= (
unsigned int) ( next /
max ) % 1024;
221 static const unsigned int max = 65536;
233 : m_plplotEdgeLength(
PLFLT( SHRT_MAX ) )
243 strcpy(
m_mfo, mfo );
247 #ifdef WXPLVIEWER_DEBUG
248 strcpy(
m_mfo,
"plplotMemoryMap" );
250 strcpy(
m_mfo,
"plplotMemoryMap??????????" );
287 if ( !plsc->pageset )
292 if ( pls->
xdpi == 0.0 || pls->
ydpi == 0 )
294 if ( pls->
xdpi == 0.0 && pls->
ydpi == 0 )
315 pls->
dev = (
void *)
this;
363 for (
PLINT i = 1; i < npts; i++ )
380 x1 = x1 < 0 ? 0 : x1;
382 y1 = y1 < 0 ? 0 : y1;
387 PLINT width = abs( x1 - x2 );
388 PLINT height = abs( y1 - y2 );
390 if ( width > 0 && height > 0 )
395 wxColour bgColour( r, g, b, a * 255 );
397 m_dc->DrawRectangle( x, y, width, height );
418 wxPoint *points =
new wxPoint[pls->
dev_npts];
422 for (
int i = 0; i < pls->
dev_npts; i++ )
430 m_dc->DrawPolygon( pls->
dev_npts, points, xoffset, yoffset, wxODDEVEN_RULE );
434 m_dc->DrawPolygon( pls->
dev_npts, points, xoffset, yoffset, wxWINDING_RULE );
449 pls->
curcolor.
a * 255 ), width, wxSOLID );
462 pls->
curcolor.
a * 255 ), width, wxSOLID );
477 throw(
"wxPLDevice::SetDC The DC must be set before initialisation. The device is outputting to a separate viewer" );
483 #if wxVERSION_NUMBER >= 2902
496 gcdc =
dynamic_cast< wxGCDC*
>(
m_dc );
502 m_gc = gcdc->GetGraphicsContext();
517 if ( superscriptLevel == 0 )
521 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
522 if ( superscriptLevel > 0 )
523 return getTextOffset( superscriptLevel - 1, baseFontSize ) + baseFontSize * fontScale / 2.;
525 return getTextOffset( superscriptLevel + 1, baseFontSize ) - baseFontSize * fontScale * 0.8 / 2.;
557 while ( i < ucs4Len )
564 strncat( utf8_string, utf8,
565 sizeof ( utf8_string ) - strlen( utf8_string ) - 1 );
573 strncat( utf8_string, utf8,
574 sizeof ( utf8_string ) - strlen( utf8_string ) - 1 );
582 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
584 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, drawText );
587 fontScale = pow( 0.8, abs( superscriptLevel ) );
592 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
594 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, drawText );
597 fontScale = pow( 0.8, abs( superscriptLevel ) );
602 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
604 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, drawText );
618 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
620 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, drawText );
630 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
632 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, drawText );
650 wxString str = wxString::FromUTF8( utf8_string );
653 m_dc->GetTextExtent( str, &w, &h, &d, &l );
674 m_dc->DrawRotatedText( str,
685 if ( yOffset > 0.0001 )
688 double currentOffset = yOffset;
689 double currentHeight = h;
690 while ( currentOffset > 0.0001 )
692 currentOffset -=
m_yScale * scaledFontSize / 2.;
693 currentHeight *= 1.25;
701 : static_cast<int>( ( currentHeight + yOffset /
m_yScale ) );
703 else if ( yOffset < -0.0001 )
706 double currentOffset = yOffset;
707 double currentHeight = h;
708 double currentDepth = d;
709 while ( currentOffset < -0.0001 )
711 currentOffset +=
m_yScale * scaledFontSize * 1.25 / 2.;
712 currentHeight *= 1.25;
713 currentDepth *= 1.25;
739 unsigned char fontFamily, fontStyle, fontWeight;
746 return wxFont( (
int) ( scaledFontSize < 4 ? 4 : scaledFontSize ),
752 wxFONTENCODING_DEFAULT
781 printf(
"Non unicode string passed to the wxWidgets driver, ignoring\n" );
788 printf(
"Sorry, the wxWidgets drivers only handles strings of length < %d\n", 500 );
794 PLFLT baseFontSize = pls->
chrht * 72.0 / 25.4;
797 PLINT rcx[4], rcy[4];
801 for (
int i = 0; i < 4; i++ )
806 wxDCClipper clip( *
m_dc, wxRegion( 4, cpoints ) );
810 bool lineFeed =
false;
811 bool carriageReturn =
false;
812 wxCoord paraHeight = 0;
814 PLINT superscriptLevel = 0;
823 wxCoord paragraphWidth = 0;
828 && *( lineStart + lineLen ) != (
PLUNICODE)
'\n' )
835 lineFeed = carriageReturn;
837 && *( lineStart + lineLen ) == (
PLUNICODE) (
'\n' );
842 double lineStartSuperscriptLevel = superscriptLevel;
848 DrawTextLine( lineStart, lineLen, baseFontSize,
false, superscriptLevel );
857 superscriptLevel = lineStartSuperscriptLevel;
858 m_fci = lineStartFci;
859 m_dc->SetFont(
GetFont(
m_fci, pow( 0.8, abs( superscriptLevel ) ) * baseFontSize ) );
869 PLFLT cos_shear = cos( shear );
870 PLFLT sin_shear = sin( shear );
875 wxGraphicsMatrix originalMatrix =
m_gc->GetTransform();
878 wxGraphicsMatrix matrix =
m_gc->CreateMatrix(
879 cos_rot * stride, -sin_rot * stride,
880 cos_rot * sin_shear + sin_rot * cos_shear,
881 -sin_rot * sin_shear + cos_rot * cos_shear,
883 m_gc->ConcatTransform( matrix );
886 DrawTextLine( lineStart, lineLen, baseFontSize,
true, superscriptLevel );
887 m_gc->SetTransform( originalMatrix );
889 #if wxVERSION_NUMBER >= 2902
892 wxAffineMatrix2D originalMatrix =
m_dc->GetTransformMatrix();
894 wxAffineMatrix2D newMatrix = originalMatrix;
896 wxAffineMatrix2D textMatrix;
897 textMatrix.Set( wxMatrix2D( cos_rot * stride, -sin_rot * stride,
898 cos_rot * sin_shear + sin_rot * cos_shear,
899 -sin_rot * sin_shear + cos_rot * cos_shear ),
900 wxPoint2DDouble( 0.0, 0.0 ) );
901 newMatrix.Concat( textMatrix );
904 m_dc->SetTransformMatrix( newMatrix );
905 DrawTextLine( lineStart, lineLen, baseFontSize,
true, superscriptLevel );
906 m_dc->SetTransformMatrix( originalMatrix );
913 DrawTextLine( lineStart, lineLen, baseFontSize,
true, superscriptLevel );
917 lineStart += lineLen;
918 if ( carriageReturn )
975 plP_gphy( &xmin, &xmax, &ymin, &ymax );
1044 const size_t counterLimit = 10000;
1045 const size_t headerSize =
sizeof ( transmissionType ) +
sizeof (
size_t );
1046 bool completed =
false;
1047 while ( !completed && counter < counterLimit )
1057 size_t copyAmount = 0;
1058 size_t freeSpace = 0;
1076 if ( freeSpace <= headerSize )
1102 if ( amountToCopy == 0 )
1140 if ( freeSpace > headerSize )
1143 copyAmount =
MIN( amountToCopy, freeSpace - headerSize );
1146 if ( copyAmount != amountToCopy )
1153 (
char *) ( ©Amount ),
sizeof ( copyAmount ) );
1160 amountToCopy -= copyAmount;
1174 plwarn(
"Locking mutex failed when trying to communicate with wxPLViewer." );
1180 plwarn(
"Unknown error when trying to communicate with wxPLViewer." );
1184 if ( counter == counterLimit )
1186 plwarn(
"Communication timeout with wxPLViewer - disconnecting" );
1193 if ( strlen(
m_mfo ) > 0 )
1195 const size_t mapSize = 1024 * 1024;
1200 static Rand randomGenerator;
1201 while ( nTries < 10 )
1203 for (
int i = 0; i < strlen(
m_mfo ); ++i )
1205 if (
m_mfo[i] ==
'?' )
1206 mapName[i] =
'A' + (char) ( randomGenerator() % 26 );
1208 mapName[i] =
m_mfo[i];
1210 mapName[strlen(
m_mfo )] =
'\0';
1214 pldebug(
"wxPLDevice::SetupMemoryMap",
"nTries = %d, mapName = %s\n", nTries, mapName );
1215 strcpy( mutexName, mapName );
1216 strcat( mutexName,
"mut" );
1217 pldebug(
"wxPLDevice::SetupMemoryMap",
"nTries = %d, mutexName = %s\n", nTries, mutexName );
1231 plwarn(
"Error creating memory map for wxWidget instruction transmission. The plots will not be displayed" );
1245 wxString exeName = wxT(
"wxPLViewer" );
1249 wxArrayString files;
1250 wxDir::GetAllFiles( wxT(
BUILD_DIR ), &files, exeName, wxDIR_FILES | wxDIR_DIRS );
1251 if ( files.size() == 0 )
1252 wxDir::GetAllFiles( wxT(
BUILD_DIR ), &files, exeName + wxT(
".exe" ), wxDIR_FILES | wxDIR_DIRS );
1253 if ( files.size() > 0 )
1259 wxArrayString files;
1260 wxDir::GetAllFiles( wxT(
BIN_DIR ), &files, exeName, wxDIR_FILES | wxDIR_DIRS );
1261 if ( files.size() == 0 )
1262 wxDir::GetAllFiles( wxT(
BIN_DIR ), &files, exeName + wxT(
".exe" ), wxDIR_FILES | wxDIR_DIRS );
1263 if ( files.size() > 0 )
1268 command << wxT(
"\"" ) << exeName << wxT(
"\" " ) << wxString( mapName, wxConvUTF8 ) << wxT(
" " ) <<
1270 #ifndef WXPLVIEWER_DEBUG
1273 if ( wxExecute( command, wxEXEC_ASYNC ) == 0 )
1274 plwarn(
"Failed to run wxPLViewer - no plots will be shown" );
1277 command << wxT(
" &" );
1278 system( command.mb_str() );
1280 size_t maxTries = 1000;
1281 #else //WXPLVIEWER_DEBUG
1282 fprintf( stdout,
"Begin Running wxPLViewer in the debugger now to continue." );
1283 size_t maxTries = 100000;
1284 #endif //WXPLVIEWER_DEBUG
1288 while ( counter < maxTries && viewerSignal == 0 )
1292 if ( viewerSignal == 0 )
1293 plwarn(
"wxPLViewer failed to signal it has found the shared memory." );
1303 bool gotResponse =
false;
1304 while ( !gotResponse )
1306 wxMilliSleep( 100 );
1316 plwarn(
"plGetCursor cannot be used when the user supplies a wxDC or until wxPLViewer is initialised" );
1317 graphicsIn->
dX = -1;
1318 graphicsIn->
dY = -1;
1319 graphicsIn->
pX = -1;
1320 graphicsIn->
pY = -1;