48 #include <wx/ustring.h>
64 typedef std::pair< PLUNICODE *, PLUNICODE *> uniIterPair;
67 std::vector< uniIterPair > lines( 1, uniIterPair( args->
unicode_array, textEnd ) );
72 lines.back().second = uni;
73 lines.push_back( uniIterPair( uni + 1, textEnd ) );
81 printf(
"Non unicode string passed to the wxWidgets driver, ignoring\n" );
88 printf(
"Sorry, the wxWidgets drivers only handles strings of length < %d\n", 500 );
97 PLINT currentSuperscriptLevel = 0;
98 PLFLT currentSuperscriptScale = 1.0;
99 PLFLT currentSuperscriptOffset = 0.0;
102 bool currentUnderlined =
false;
106 std::vector<wxCoord> lineWidths( lines.size() );
107 std::vector<wxCoord> lineHeights( lines.size() );
108 std::vector<wxCoord> lineDepths( lines.size() );
109 wxCoord paraWidth = 0;
110 wxCoord paraHeight = 0;
112 PLINT testSuperscriptLevel = currentSuperscriptLevel;
113 PLFLT testSuperscriptScale = currentSuperscriptScale;
114 PLFLT testSuperscriptOffset = currentSuperscriptOffset;
115 for (
size_t i = 0; i < lines.size(); ++i )
119 bool testUnderlined = currentUnderlined =
false;
120 PLFLT identityMatrix[6];
122 DrawTextLine( lines[i].first, lines[i].second - lines[i].first, 0, 0, 0, 0, identityMatrix, baseFontSize,
false,
123 testSuperscriptLevel, testSuperscriptScale, testSuperscriptOffset, testUnderlined, testFci,
124 0, 0, 0, 0.0, lineWidths[i], lineHeights[i], lineDepths[i] );
125 paraWidth =
MAX( paraWidth, lineWidths[i] );
126 paraHeight += lineHeights[i] + lineDepths[i];
133 wxCoord cumSumHeight = 0;
136 PLFLT textTransform[6];
138 textTransform[0] = args->
xform[0];
139 textTransform[2] = args->
xform[1];
140 textTransform[1] = args->
xform[2];
141 textTransform[3] = args->
xform[3];
142 textTransform[4] = 0.0;
143 textTransform[5] = 0.0;
144 PLFLT diorotTransform[6];
147 diorotTransform[0] = 1;
148 diorotTransform[1] = 0;
149 diorotTransform[2] = 0;
150 diorotTransform[3] = 1;
152 else if ( diorot == 1.0 )
154 diorotTransform[0] = 0;
155 diorotTransform[1] = -1;
156 diorotTransform[2] = 1;
157 diorotTransform[3] = 0;
159 else if ( diorot == 2.0 )
161 diorotTransform[0] = -1;
162 diorotTransform[1] = 0;
163 diorotTransform[2] = 0;
164 diorotTransform[3] = -1;
166 else if ( diorot == 3.0 )
168 diorotTransform[0] = 0;
169 diorotTransform[1] = 1;
170 diorotTransform[2] = -1;
171 diorotTransform[3] = 0;
176 PLFLT cosAngle = cos( angle );
177 PLFLT sinAngle = sin( angle );
178 diorotTransform[0] = cosAngle;
179 diorotTransform[1] = -sinAngle;
180 diorotTransform[2] = sinAngle;
181 diorotTransform[3] = cosAngle;
183 diorotTransform[4] = 0;
184 diorotTransform[5] = 0;
186 PLFLT finalTransform[6];
187 memcpy( finalTransform, textTransform,
sizeof (
PLFLT ) * 6 );
190 for (
size_t i = 0; i < lines.size(); ++i )
192 DrawTextLine( lines[i].first, lines[i].second - lines[i].first,
195 -lineWidths[i] * args->
just, lineHeights[i] * 0.5 - cumSumHeight,
196 finalTransform, baseFontSize,
true,
197 currentSuperscriptLevel, currentSuperscriptScale, currentSuperscriptOffset, currentUnderlined,
199 lineHeights[i], lineDepths[i] );
201 cumSumHeight += lineHeights[i] + lineDepths[i];
229 void PlDevice::DrawTextLine(
PLUNICODE* ucs4,
int ucs4Len, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y,
PLFLT *transform,
PLFLT baseFontSize,
bool drawText,
PLINT &superscriptLevel,
PLFLT &superscriptScale,
PLFLT &superscriptOffset,
bool &underlined,
PLUNICODE &fci,
unsigned char red,
unsigned char green,
unsigned char blue,
PLFLT alpha, wxCoord &textWidth, wxCoord &textHeight, wxCoord &textDepth )
246 PLFLT sectionTransform[6];
247 memcpy( sectionTransform, transform,
sizeof ( sectionTransform ) );
257 PLFLT actualSuperscriptOffset = 0.0;
260 while ( i < ucs4Len )
269 section += wxUString( (wxChar32) ucs4[i] );
274 wxCoord sectionWidth;
275 wxCoord sectionHeight;
276 wxCoord sectionDepth;
277 DrawTextSection( section, xOrigin, yOrigin, x + textWidth, y + actualSuperscriptOffset, transform,
278 baseFontSize * superscriptScale, drawText, underlined, fci, red, green, blue, alpha, sectionWidth, sectionHeight, sectionDepth );
279 textWidth += sectionWidth;
280 textHeight =
MAX( textHeight, sectionHeight );
281 textDepth =
MAX( textDepth, sectionDepth - superscriptOffset * baseFontSize );
282 section = wxEmptyString;
290 &oldOffset, &superscriptOffset );
291 actualSuperscriptOffset = superscriptOffset * baseFontSize * 0.75 * ( superscriptLevel > 0 ? 1.0 : -1.0 );
298 &oldOffset, &superscriptOffset );
299 actualSuperscriptOffset = superscriptOffset * baseFontSize * 0.75 * ( superscriptLevel > 0 ? 1.0 : -1.0 );
302 underlined = !underlined;
312 wxCoord sectionWidth;
313 wxCoord sectionHeight;
314 wxCoord sectionDepth;
315 DrawTextSection( section, xOrigin, yOrigin, x + textWidth, y + actualSuperscriptOffset, transform,
316 baseFontSize * superscriptScale, drawText, underlined, fci, red, green, blue, alpha, sectionWidth, sectionHeight, sectionDepth );
317 textWidth += sectionWidth;
318 textHeight =
MAX( textHeight, sectionHeight + superscriptOffset * baseFontSize );
319 textDepth =
MAX( textDepth, sectionDepth - superscriptOffset * baseFontSize );
320 section = wxEmptyString;
328 section += wxUString( (wxChar32) ucs4[i] );
336 wxCoord sectionWidth;
337 wxCoord sectionHeight;
338 wxCoord sectionDepth;
339 DrawTextSection( section, xOrigin, yOrigin, x + textWidth, y + actualSuperscriptOffset, transform,
340 baseFontSize * superscriptScale, drawText, underlined, fci, red, green, blue, alpha, sectionWidth, sectionHeight, sectionDepth );
341 textWidth += sectionWidth;
342 textHeight =
MAX( textHeight, sectionHeight + superscriptOffset * baseFontSize );
343 textDepth =
MAX( textDepth, sectionDepth - superscriptOffset * baseFontSize );
368 Scaler( wxDC * dc,
double xScale,
double yScale )
374 dc->SetUserScale( xScale, yScale );
405 dc->SetLogicalOrigin( xOrigin, yOrigin );
435 m_pen = dc->GetPen();
438 dc->SetBrush( brush );
503 TextObjectsChanger( wxDC *dc,
const wxFont &font,
const wxColour &textForeground,
const wxColour &textBackground )
508 dc->SetTextForeground( textForeground );
509 dc->SetTextBackground( textBackground );
525 dc->SetTextForeground( textForeground );
526 dc->SetTextBackground( textBackground );
558 wxRect newRect = rect;
562 dc->SetClippingRegion( wxRect( -1, -1, 1, 1 ) );
564 dc->SetClippingRegion( rect );
571 m_dc->DestroyClippingRegion();
572 m_dc->SetClippingRegion( wxRect( 0, 0, 0, 0 ) );
573 m_dc->DestroyClippingRegion();
606 std::fstream fin(
"/dev/urandom", std::ios::in );
612 fin.open(
"/dev/random", std::ios::in );
627 unsigned int next =
m_seed;
632 result = (
unsigned int) ( next /
max ) % 2048;
637 result ^= (
unsigned int) ( next /
max ) % 1024;
642 result ^= (
unsigned int) ( next /
max ) % 1024;
648 static const unsigned int max = 65536;
655 unsigned char plFontFamily, plFontStyle, plFontWeight;
664 pt =
ROUND( scaledFontSize );
670 m_size = std::numeric_limits<PLFLT>::quiet_NaN();
681 if ( createFontOnConstruction )
693 m_font = wxFont( pt, family, style, weight,
m_underlined, wxEmptyString, wxFONTENCODING_DEFAULT );
698 if ( pt == wxDEFAULT )
699 m_font.SetPointSize( pt );
734 Font newFont( fci, scaledFontSize, underlined );
753 : m_plplotEdgeLength(
PLFLT( SHRT_MAX ) ), m_interactiveTextImage( 1, 1 )
781 strcpy(
m_mfo, mfo );
785 #ifdef WXPLVIEWER_DEBUG
786 strcpy(
m_mfo,
"plplotMemoryMap" );
788 strcpy(
m_mfo,
"plplotMemoryMap??????????" );
826 if ( pls->
xdpi <= 0. || pls->
ydpi <= 0. )
854 pls->
dev = (
void *)
this;
916 for (
PLINT i = 1; i < npts; i++ )
933 x1 = x1 < 0 ? 0 : x1;
935 y1 = y1 < 0 ? 0 : y1;
940 PLINT width = abs( x1 - x2 );
941 PLINT height = abs( y1 - y2 );
943 if ( width > 0 && height > 0 )
948 wxColour bgColour( r, g, b, a * 255 );
950 m_dc->DrawRectangle( x, y, width, height );
971 wxPoint *points =
new wxPoint[pls->
dev_npts];
975 for (
int i = 0; i < pls->
dev_npts; i++ )
983 m_dc->DrawPolygon( pls->
dev_npts, points, xoffset, yoffset, wxODDEVEN_RULE );
987 m_dc->DrawPolygon( pls->
dev_npts, points, xoffset, yoffset, wxWINDING_RULE );
1002 pls->
curcolor.
a * 255 ), width, wxSOLID );
1015 pls->
curcolor.
a * 255 ), width, wxSOLID );
1030 throw(
"wxPLDevice::SetDC The DC must be set before initialisation. The device is outputting to a separate viewer" );
1036 #if wxVERSION_NUMBER >= 2902
1044 wxGCDC *gcdc = NULL;
1049 gcdc =
dynamic_cast< wxGCDC*
>(
m_dc );
1055 m_gc = gcdc->GetGraphicsContext();
1057 strcpy(
m_mfo,
"" );
1069 if ( superscriptLevel == 0 )
1073 PLFLT fontScale = pow( 0.8, abs( superscriptLevel ) );
1074 if ( superscriptLevel > 0 )
1075 return getTextOffset( superscriptLevel - 1, baseFontSize ) + baseFontSize * fontScale / 2.;
1077 return getTextOffset( superscriptLevel + 1, baseFontSize ) - baseFontSize * fontScale * 0.8 / 2.;
1103 void wxPLDevice::DrawTextSection( wxString section, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y,
PLFLT *transform,
PLFLT scaledFontSize,
bool drawText,
bool underlined,
PLUNICODE fci,
unsigned char red,
unsigned char green,
unsigned char blue,
PLFLT alpha, wxCoord §ionWidth, wxCoord §ionHeight, wxCoord §ionDepth )
1120 m_dc->GetTextExtent( section, §ionWidth, §ionHeight,
1121 §ionDepth, &leading, &theFont );
1122 sectionHeight -= sectionDepth + leading;
1123 sectionDepth += leading;
1132 §ionDepth, &leading, &theFont );
1133 sectionHeight -= sectionDepth + leading;
1134 sectionDepth += leading;
1141 if ( drawText &&
m_dc )
1144 m_dc->SetTextBackground( wxColour( red, green, blue, alpha * 255 ) );
1145 m_dc->SetTextForeground( wxColour( red, green, blue, alpha * 255 ) );
1148 PLINT rcx[4], rcy[4];
1151 for (
int i = 0; i < 4; i++ )
1156 Clipper clipper(
m_dc, wxRegion( 4, cpoints ).GetBox() );
1163 #if wxVERSION_NUMBER >= 2902
1164 wxAffineMatrix2D originalDcMatrix =
m_dc->GetTransformMatrix();
1166 wxAffineMatrix2D newMatrix = originalDcMatrix;
1168 wxAffineMatrix2D textMatrix;
1174 transform[0], transform[2],
1175 transform[1], transform[3] ),
1177 xTransform, yTransform ) );
1178 newMatrix.Concat( textMatrix );
1179 m_dc->SetTransformMatrix( newMatrix );
1183 m_dc->SetTransformMatrix( originalDcMatrix );
1188 wxGraphicsMatrix originalGcMatrix =
m_gc->GetTransform();
1220 wxGraphicsMatrix matrix =
m_gc->CreateMatrix(
1221 transform[0], -transform[1],
1222 -transform[2], transform[3],
1223 xTransform, -yTransform );
1224 wxGraphicsMatrix reflectMatrix =
m_gc->CreateMatrix();
1225 m_gc->ConcatTransform( matrix );
1227 m_gc->SetTransform( originalGcMatrix );
1239 PLFLT angle = atan2( transform[1], transform[0] ) * 180.0 /
M_PI;
1295 plP_gphy( &xmin, &xmax, &ymin, &ymax );
1370 const size_t counterLimit = 10000;
1371 const size_t headerSize =
sizeof ( transmissionType ) +
sizeof (
size_t );
1372 bool completed =
false;
1373 while ( !completed && counter < counterLimit )
1383 size_t copyAmount = 0;
1384 size_t freeSpace = 0;
1402 if ( freeSpace <= headerSize )
1415 plwarn(
"wxWidgets wrapping buffer" );
1429 if ( amountToCopy == 0 )
1438 && amountToCopy == 0 )
1441 (
void *) ( &transmissionType ),
sizeof ( transmissionType ) );
1477 (
void *) ( &transmissionType ),
sizeof ( transmissionType ) );
1491 if ( freeSpace > headerSize )
1494 copyAmount =
MIN( amountToCopy, freeSpace - headerSize );
1497 if ( copyAmount != amountToCopy )
1506 (
char *) ( ©Amount ),
sizeof ( copyAmount ) );
1513 amountToCopy -= copyAmount;
1529 plwarn(
"Locking mutex failed when trying to communicate with wxPLViewer." );
1535 plwarn(
"Unknown error when trying to communicate with wxPLViewer." );
1539 if ( counter == counterLimit )
1541 plwarn(
"Communication timeout with wxPLViewer - disconnecting" );
1549 if ( strlen(
m_mfo ) > 0 )
1551 const size_t mapSize = 1024 * 1024;
1556 static Rand randomGenerator;
1557 while ( nTries < 10 )
1560 for (
int i = 0; i < strlen(
m_mfo ); ++i )
1562 if (
m_mfo[i] ==
'?' )
1563 mapName[i] =
'A' + (char) ( randomGenerator() % 26 );
1565 mapName[i] =
m_mfo[i];
1568 mapName[strlen(
m_mfo )] =
'\0';
1572 pldebug(
"wxPLDevice::SetupMemoryMap",
"nTries = %d, mapName = %s\n", nTries, mapName );
1573 strcpy( mutexName, mapName );
1574 strcat( mutexName,
"mut" );
1575 pldebug(
"wxPLDevice::SetupMemoryMap",
"nTries = %d, mutexName = %s\n", nTries, mutexName );
1591 plwarn(
"Error creating memory map for wxWidget instruction transmission. The plots will not be displayed" );
1606 wxString exeName = wxT(
"wxPLViewer" );
1610 wxArrayString files;
1611 wxString utilsDir = wxString( wxT(
BUILD_DIR ) ) + wxString( wxT(
"/utils" ) );
1612 wxDir::GetAllFiles( utilsDir, &files, exeName, wxDIR_FILES | wxDIR_DIRS );
1613 if ( files.size() == 0 )
1614 wxDir::GetAllFiles( utilsDir, &files, exeName + wxT(
".exe" ), wxDIR_FILES | wxDIR_DIRS );
1615 if ( files.size() > 0 )
1621 wxArrayString files;
1622 wxDir::GetAllFiles( wxT(
BIN_DIR ), &files, exeName, wxDIR_FILES | wxDIR_DIRS );
1623 if ( files.size() == 0 )
1624 wxDir::GetAllFiles( wxT(
BIN_DIR ), &files, exeName + wxT(
".exe" ), wxDIR_FILES | wxDIR_DIRS );
1625 if ( files.size() > 0 )
1630 command << wxT(
"\"" ) << exeName << wxT(
"\" " ) << wxString( mapName, wxConvUTF8 ) << wxT(
" " ) <<
1632 #ifndef WXPLVIEWER_DEBUG
1635 if ( wxExecute( command, wxEXEC_ASYNC ) == 0 )
1636 plwarn(
"Failed to run wxPLViewer - no plots will be shown" );
1639 command << wxT(
" &" );
1640 system( command.mb_str() );
1642 size_t maxTries = 1000;
1643 #else //WXPLVIEWER_DEBUG
1644 wxString runMessage;
1645 runMessage <<
"Begin Running wxPLViewer in the debugger now to continue. Use the parameters: plplotMemoryMap " <<
1647 fprintf( stdout, runMessage );
1648 size_t maxTries = 100000;
1649 #endif //WXPLVIEWER_DEBUG
1653 while ( counter < maxTries && viewerSignal == 0 )
1658 if ( viewerSignal == 0 )
1659 plwarn(
"wxPLViewer failed to signal it has found the shared memory." );
1670 bool gotResponse =
false;
1671 while ( !gotResponse )
1673 wxMilliSleep( 100 );
1683 plwarn(
"plGetCursor cannot be used when the user supplies a wxDC or until wxPLViewer is initialised" );
1684 graphicsIn->
dX = -1;
1685 graphicsIn->
dY = -1;
1686 graphicsIn->
pX = -1;
1687 graphicsIn->
pY = -1;
1698 PLINT rcx[4], rcy[4];
1702 for (
int i = 0; i < 4; i++ )
1707 return wxRegion( 4, cpoints );
wxGCDC * m_interactiveTextGcdc
void plP_script_scale(PLBOOL ifupper, PLINT *level, PLFLT *old_scale, PLFLT *scale, PLFLT *old_offset, PLFLT *offset)
void SetColor(PLStream *pls)
void Flush(PLStream *pls)
TextObjectsChanger(wxDC *dc, const wxFont &font, const wxColour &textForeground, const wxColour &textBackground)
const PLFLT m_plplotEdgeLength
TextObjectsChanger & operator=(const TextObjectsChanger &)
wxImage m_interactiveTextImage
void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
void plP_fci2hex(PLUNICODE fci, unsigned char *phexdigit, unsigned char hexpower)
static const unsigned int max
wxColour m_textBackground
wxPLDevice(PLStream *pls, char *mfo, PLINT text, PLINT hrshsym)
void plP_affine_identity(PLFLT *affine_vector)
void SetWidth(PLStream *pls)
TextObjectsChanger(wxDC *dc, FontGrabber &fontGrabber, PLUNICODE fci, PLFLT size, bool underlined, const wxColour &textForeground, const wxColour &textBackground)
#define PLPLOT_MM_PER_INCH
virtual ~wxPLDevice(void)
wxChar m_prevSingleCharString
bool m_useDcTextTransform
void FillPolygon(PLStream *pls)
void DrawLine(short x1a, short y1a, short x2a, short y2a)
void ClearBackground(PLStream *pls, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)
TextObjectsChanger(wxDC *dc, const wxFont &font)
void DrawTextSection(wxString section, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord §ionWidth, wxCoord §ionHeight, wxCoord §ionDepth)
bool isEverythingClipped()
void DrawPolyline(short *xa, short *ya, PLINT npts)
void PreDestructorTidy(PLStream *pls)
OriginChanger & operator=(const OriginChanger &)
virtual void DrawTextSection(wxString section, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord §ionWidth, wxCoord §ionHeight, wxCoord §ionDepth)
PLINT m_prevSingleCharStringDepth
Scaler(wxDC *dc, double xScale, double yScale)
PLINT m_prevSingleCharStringHeight
DrawingObjectsChanger & operator=(const DrawingObjectsChanger &)
void create(const char *name, bool aquireOnCreate=false)
size_t m_localBufferPosition
Clipper & operator=(const Clipper &)
PLINT m_prevSingleCharStringWidth
TextObjectsSaver & operator=(const TextObjectsSaver &)
bool getUnderlined() const
Font GetFont(PLUNICODE fci, PLFLT scaledFontSize, bool underlined)
void drawText(PLStream *pls, EscText *args)
void difilt_clip(PLINT *x_coords, PLINT *y_coords)
#define PLPLOT_DEFAULT_WIDTH_PIXELS
#define PLPLOT_DEFAULT_PIXELS_PER_INCH
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
char m_mfo[PLPLOT_MAX_PATH]
void TransmitBuffer(PLStream *pls, unsigned char transmissionType)
void plP_affine_multiply(PLFLT *affine_vectorA, PLFLT_VECTOR affine_vectorB, PLFLT_VECTOR affine_vectorC)
static PLStream * pls[PL_NSTREAMS]
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
unsigned short unicode_array_len
DrawingObjectsChanger(wxDC *dc, const wxPen &pen, const wxBrush &brush)
#define PLPLOT_POINTS_PER_INCH
void FixAspectRatio(bool fix)
void EndPage(PLStream *pls)
unsigned int operator()()
static Tcl_DString command
TextObjectsSaver(wxDC *dc)
Clipper(wxDC *dc, const wxRect &rect)
wxColour m_textForeground
void create(const char *name, PLINT size, bool mustExist, bool mustNotExist)
PLINT m_prevSuperscriptLevel
void DrawTextLine(PLUNICODE *ucs4, int ucs4Len, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT baseFontSize, bool drawText, PLINT &superscriptLevel, PLFLT &superscriptScale, PLFLT &superscriptOffset, bool &underlined, PLUNICODE &fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &textWidth, wxCoord &textHeight, wxCoord &textDepth)
#define PLPLOT_wxLogDebug(string)
void plwarn(PLCHAR_VECTOR errormsg)
void SetSize(PLStream *pls, int width, int height)
void SetDC(PLStream *pls, wxDC *dc)
wxCoord m_prevSymbolHeight
void BeginPage(PLStream *pls)
PLMemoryMap m_outputMemoryMap
#define PLPLOT_DEFAULT_HEIGHT_PIXELS
void plP_gphy(PLINT *p_ixmin, PLINT *p_ixmax, PLINT *p_iymin, PLINT *p_iymax)
wxCoord m_prevSymbolWidth
PLUNICODE * unicode_array
OriginChanger(wxDC *dc, wxCoord xOrigin, wxCoord yOrigin)
Scaler & operator=(const Scaler &)
FontGrabber m_fontGrabber