63 Scaler( wxDC * dc,
double xScale,
double yScale )
69 dc->SetLogicalScale( xScale, yScale );
98 dc->SetLogicalOrigin( xOrigin, yOrigin );
126 m_pen = dc->GetPen();
129 dc->SetBrush( brush );
155 TextObjectsChanger( wxDC *dc,
const wxFont &font,
const wxColour &textForeground,
const wxColour &textBackground )
163 dc->SetTextForeground( textForeground );
164 dc->SetTextBackground( textBackground );
217 wxRect newRect = rect;
221 dc->SetClippingRegion( wxRect( -1, -1, 1, 1 ) );
223 dc->SetClippingRegion( rect );
230 m_dc->DestroyClippingRegion();
231 m_dc->SetClippingRegion( wxRect( 0, 0, 0, 0 ) );
232 m_dc->DestroyClippingRegion();
263 std::fstream fin(
"/dev/random", std::ios::in );
274 unsigned int next =
m_seed;
279 result = (
unsigned int) ( next /
max ) % 2048;
284 result ^= (
unsigned int) ( next /
max ) % 1024;
289 result ^= (
unsigned int) ( next /
max ) % 1024;
295 static const unsigned int max = 65536;
302 unsigned char plFontFamily, plFontStyle, plFontWeight;
311 pt =
ROUND( scaledFontSize );
354 return m_prevFont = wxFont( pt, family, style, weight, underlined, wxEmptyString, wxFONTENCODING_DEFAULT );
364 : m_plplotEdgeLength(
PLFLT( SHRT_MAX ) )
377 strcpy(
m_mfo, mfo );
381 #ifdef WXPLVIEWER_DEBUG
382 strcpy(
m_mfo,
"plplotMemoryMap" );
384 strcpy(
m_mfo,
"plplotMemoryMap??????????" );
421 if ( !plsc->pageset )
426 if ( pls->
xdpi == 0.0 || pls->
ydpi == 0 )
428 if ( pls->
xdpi == 0.0 && pls->
ydpi == 0 )
449 pls->
dev = (
void *)
this;
509 for (
PLINT i = 1; i < npts; i++ )
526 x1 = x1 < 0 ? 0 : x1;
528 y1 = y1 < 0 ? 0 : y1;
533 PLINT width = abs( x1 - x2 );
534 PLINT height = abs( y1 - y2 );
536 if ( width > 0 && height > 0 )
541 wxColour bgColour( r, g, b, a * 255 );
543 m_dc->DrawRectangle( x, y, width, height );
564 wxPoint *points =
new wxPoint[pls->
dev_npts];
568 for (
int i = 0; i < pls->
dev_npts; i++ )
576 m_dc->DrawPolygon( pls->
dev_npts, points, xoffset, yoffset, wxODDEVEN_RULE );
580 m_dc->DrawPolygon( pls->
dev_npts, points, xoffset, yoffset, wxWINDING_RULE );
595 pls->
curcolor.
a * 255 ), width, wxSOLID );
608 pls->
curcolor.
a * 255 ), width, wxSOLID );
623 throw(
"wxPLDevice::SetDC The DC must be set before initialisation. The device is outputting to a separate viewer" );
629 #if wxVERSION_NUMBER >= 2902
642 gcdc =
dynamic_cast< wxGCDC*
>(
m_dc );
648 m_gc = gcdc->GetGraphicsContext();
663 if ( superscriptLevel == 0 )
667 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
668 if ( superscriptLevel > 0 )
669 return getTextOffset( superscriptLevel - 1, baseFontSize ) + baseFontSize * fontScale / 2.;
671 return getTextOffset( superscriptLevel + 1, baseFontSize ) - baseFontSize * fontScale * 0.8 / 2.;
685 if ( !
m_dc && drawText )
703 while ( i < ucs4Len )
710 strncat( utf8_string, utf8,
711 sizeof ( utf8_string ) - strlen( utf8_string ) - 1 );
719 strncat( utf8_string, utf8,
720 sizeof ( utf8_string ) - strlen( utf8_string ) - 1 );
728 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
730 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, underlined, drawText );
733 fontScale = pow( 0.8, abs( superscriptLevel ) );
739 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
741 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, underlined, drawText );
744 fontScale = pow( 0.8, abs( superscriptLevel ) );
750 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
752 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, underlined, drawText );
754 underlined = !underlined;
767 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
769 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, underlined, drawText );
780 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
782 DrawTextSection( utf8_string, baseFontSize * fontScale, yOffset, underlined, drawText );
795 if ( !
m_dc && drawText )
800 wxString str = wxString::FromUTF8( utf8_string );
804 m_dc->GetTextExtent( str, &w, &h, &d, &l );
813 bool gotResponse =
false;
816 while ( !gotResponse && counter < 1000 )
822 if ( counter == 1000 )
823 plwarn(
"Failed to get text size from wxPLViewer - timeout" );
848 m_dc->DrawRotatedText( str,
859 if ( yOffset > 0.0001 )
862 double currentOffset = yOffset;
863 double currentHeight = h;
864 while ( currentOffset > 0.0001 )
866 currentOffset -=
m_yScale * scaledFontSize / 2.;
867 currentHeight *= 1.25;
875 : static_cast<int>( ( currentHeight + yOffset /
m_yScale ) );
877 else if ( yOffset < -0.0001 )
880 double currentOffset = yOffset;
881 double currentHeight = h;
882 double currentDepth = d;
883 while ( currentOffset < -0.0001 )
885 currentOffset +=
m_yScale * scaledFontSize * 1.25 / 2.;
886 currentHeight *= 1.25;
887 currentDepth *= 1.25;
935 printf(
"Non unicode string passed to the wxWidgets driver, ignoring\n" );
942 printf(
"Sorry, the wxWidgets drivers only handles strings of length < %d\n", 500 );
948 PLFLT baseFontSize = pls->
chrht * 72.0 / 25.4;
951 PLINT rcx[4], rcy[4];
955 for (
int i = 0; i < 4; i++ )
961 Clipper clipper(
m_dc, wxRegion( 4, cpoints ).GetBox() );
965 bool lineFeed =
false;
966 bool carriageReturn =
false;
967 wxCoord paraHeight = 0;
969 PLINT superscriptLevel = 0;
980 wxCoord paragraphWidth = 0;
984 double lineStartSuperscriptLevel = superscriptLevel;
986 bool lineStartUnderlined = underlined;
990 && *( lineStart + lineLen ) != (
PLUNICODE)
'\n' )
997 lineFeed = carriageReturn;
999 && *( lineStart + lineLen ) == (
PLUNICODE) (
'\n' );
1010 && lastFontWasCached )
1017 DrawTextLine( lineStart, lineLen, baseFontSize,
false, superscriptLevel, underlined );
1027 superscriptLevel = lineStartSuperscriptLevel;
1028 m_fci = lineStartFci;
1029 underlined = lineStartUnderlined;
1040 PLFLT cos_shear = cos( shear );
1041 PLFLT sin_shear = sin( shear );
1046 wxGraphicsMatrix originalMatrix =
m_gc->GetTransform();
1049 wxGraphicsMatrix matrix =
m_gc->CreateMatrix(
1050 cos_rot * stride, -sin_rot * stride,
1051 cos_rot * sin_shear + sin_rot * cos_shear,
1052 -sin_rot * sin_shear + cos_rot * cos_shear,
1054 m_gc->ConcatTransform( matrix );
1057 DrawTextLine( lineStart, lineLen, baseFontSize,
true, superscriptLevel, underlined );
1058 m_gc->SetTransform( originalMatrix );
1060 #if wxVERSION_NUMBER >= 2902
1063 wxAffineMatrix2D originalMatrix =
m_dc->GetTransformMatrix();
1065 wxAffineMatrix2D newMatrix = originalMatrix;
1067 wxAffineMatrix2D textMatrix;
1068 textMatrix.Set( wxMatrix2D( cos_rot * stride, -sin_rot * stride,
1069 cos_rot * sin_shear + sin_rot * cos_shear,
1070 -sin_rot * sin_shear + cos_rot * cos_shear ),
1071 wxPoint2DDouble( 0.0, 0.0 ) );
1072 newMatrix.Concat( textMatrix );
1075 m_dc->SetTransformMatrix( newMatrix );
1076 DrawTextLine( lineStart, lineLen, baseFontSize,
true, superscriptLevel, underlined );
1077 m_dc->SetTransformMatrix( originalMatrix );
1084 DrawTextLine( lineStart, lineLen, baseFontSize,
true, superscriptLevel, underlined );
1088 lineStart += lineLen;
1089 if ( carriageReturn )
1157 plP_gphy( &xmin, &xmax, &ymin, &ymax );
1226 const size_t counterLimit = 10000;
1227 const size_t headerSize =
sizeof ( transmissionType ) +
sizeof (
size_t );
1228 bool completed =
false;
1229 while ( !completed && counter < counterLimit )
1239 size_t copyAmount = 0;
1240 size_t freeSpace = 0;
1258 if ( freeSpace <= headerSize )
1271 plwarn(
"wxWidgets wrapping buffer" );
1285 if ( amountToCopy == 0 )
1294 && amountToCopy == 0 )
1297 (
void *) ( &transmissionType ),
sizeof ( transmissionType ) );
1333 (
void *) ( &transmissionType ),
sizeof ( transmissionType ) );
1347 if ( freeSpace > headerSize )
1350 copyAmount =
MIN( amountToCopy, freeSpace - headerSize );
1353 if ( copyAmount != amountToCopy )
1362 (
char *) ( ©Amount ),
sizeof ( copyAmount ) );
1369 amountToCopy -= copyAmount;
1385 plwarn(
"Locking mutex failed when trying to communicate with wxPLViewer." );
1391 plwarn(
"Unknown error when trying to communicate with wxPLViewer." );
1395 if ( counter == counterLimit )
1397 plwarn(
"Communication timeout with wxPLViewer - disconnecting" );
1404 if ( strlen(
m_mfo ) > 0 )
1406 const size_t mapSize = 1024 * 1024;
1411 static Rand randomGenerator;
1412 while ( nTries < 10 )
1414 for (
int i = 0; i < strlen(
m_mfo ); ++i )
1416 if (
m_mfo[i] ==
'?' )
1417 mapName[i] =
'A' + (char) ( randomGenerator() % 26 );
1419 mapName[i] =
m_mfo[i];
1421 mapName[strlen(
m_mfo )] =
'\0';
1425 pldebug(
"wxPLDevice::SetupMemoryMap",
"nTries = %d, mapName = %s\n", nTries, mapName );
1426 strcpy( mutexName, mapName );
1427 strcat( mutexName,
"mut" );
1428 pldebug(
"wxPLDevice::SetupMemoryMap",
"nTries = %d, mutexName = %s\n", nTries, mutexName );
1442 plwarn(
"Error creating memory map for wxWidget instruction transmission. The plots will not be displayed" );
1457 wxString exeName = wxT(
"wxPLViewer" );
1461 wxArrayString files;
1462 wxString utilsDir = wxString( wxT(
BUILD_DIR ) ) + wxString( wxT(
"/utils" ) );
1463 wxDir::GetAllFiles( utilsDir, &files, exeName, wxDIR_FILES | wxDIR_DIRS );
1464 if ( files.size() == 0 )
1465 wxDir::GetAllFiles( utilsDir, &files, exeName + wxT(
".exe" ), wxDIR_FILES | wxDIR_DIRS );
1466 if ( files.size() > 0 )
1472 wxArrayString files;
1473 wxDir::GetAllFiles( wxT(
BIN_DIR ), &files, exeName, wxDIR_FILES | wxDIR_DIRS );
1474 if ( files.size() == 0 )
1475 wxDir::GetAllFiles( wxT(
BIN_DIR ), &files, exeName + wxT(
".exe" ), wxDIR_FILES | wxDIR_DIRS );
1476 if ( files.size() > 0 )
1481 command << wxT(
"\"" ) << exeName << wxT(
"\" " ) << wxString( mapName, wxConvUTF8 ) << wxT(
" " ) <<
1483 #ifndef WXPLVIEWER_DEBUG
1486 if ( wxExecute( command, wxEXEC_ASYNC ) == 0 )
1487 plwarn(
"Failed to run wxPLViewer - no plots will be shown" );
1490 command << wxT(
" &" );
1491 system( command.mb_str() );
1493 size_t maxTries = 1000;
1494 #else //WXPLVIEWER_DEBUG
1495 wxString runMessage;
1496 runMessage <<
"Begin Running wxPLViewer in the debugger now to continue. Use the parameters: plplotMemoryMap " <<
1498 fprintf( stdout, runMessage );
1499 size_t maxTries = 100000;
1500 #endif //WXPLVIEWER_DEBUG
1504 while ( counter < maxTries && viewerSignal == 0 )
1509 if ( viewerSignal == 0 )
1510 plwarn(
"wxPLViewer failed to signal it has found the shared memory." );
1520 bool gotResponse =
false;
1521 while ( !gotResponse )
1523 wxMilliSleep( 100 );
1533 plwarn(
"plGetCursor cannot be used when the user supplies a wxDC or until wxPLViewer is initialised" );
1534 graphicsIn->
dX = -1;
1535 graphicsIn->
dY = -1;
1536 graphicsIn->
pX = -1;
1537 graphicsIn->
pY = -1;
1548 PLINT rcx[4], rcy[4];
1552 for (
int i = 0; i < 4; i++ )
1557 return wxRegion( 4, cpoints );