22
22
#include " graphicsdevice.hpp"
23
23
#include " gdlgstream.hpp"
24
24
#include " initsysvar.hpp"
25
+ #ifndef MAX
26
+ #define MAX (a,b ) ((a) < (b) ? (b) : (a))
27
+ #endif
25
28
26
29
using namespace std ;
27
30
@@ -380,8 +383,9 @@ void GDLGStream::SetCharSize(DLong ichx, DLong chy) {
380
383
gdlDefaultCharInitialized=1 ;
381
384
}
382
385
383
- void GDLGStream::NextPlot ( bool erase )
384
- {
386
+ void GDLGStream::NextPlot ( bool erase ) {
387
+ // restore charsize to default for newpage at beginning since adv() uses charsize to get box position.
388
+ if (!erase) sizeChar (1.0 );
385
389
DLongGDL* pMulti = SysVar::GetPMulti ();
386
390
387
391
DLong nx = (*pMulti)[ 1 ];
@@ -446,8 +450,7 @@ void GDLGStream::NextPlot( bool erase )
446
450
--(*pMulti)[0 ];
447
451
}
448
452
}
449
- // restore charsize to default for newpage
450
- sizeChar (1.0 );
453
+
451
454
}
452
455
453
456
void GDLGStream::NoSub ()
@@ -505,7 +508,7 @@ void GDLGStream::GetGeometry( long& xSize, long& ySize)
505
508
// - ... a look-up table instead of the long switch/case blocks ...
506
509
507
510
size_t len = strlen (in);
508
- if (stringLength) *stringLength=0 ;
511
+ if (stringLength!= NULL ) *stringLength=0 ;
509
512
// skip conversion if the string is empty
510
513
if (len == 0 ) return " " ;
511
514
@@ -694,12 +697,12 @@ void GDLGStream::GetGeometry( long& xSize, long& ySize)
694
697
}
695
698
else
696
699
{
697
- if (stringLength) *stringLength+=base*fact[curr_lev%7 ];
700
+ if (stringLength!= NULL ) *stringLength+=base*fact[curr_lev%7 ];
698
701
curr_pos++;
699
702
// handling IDL exclamation mark escape '!!'
700
703
if (in[i] == ' !' ) {
701
704
i++;
702
- if (stringLength) *stringLength+=base*fact[curr_lev%7 ];
705
+ if (stringLength!= NULL ) *stringLength+=base*fact[curr_lev%7 ];
703
706
}
704
707
// handling plplot number sign escape '##'
705
708
if
@@ -1029,12 +1032,12 @@ void GDLGStream::GetGeometry( long& xSize, long& ySize)
1029
1032
activeFontCodeNum = curr_fnt;
1030
1033
// if gdlGetStringLength function is available, use it to give back a better value ("X" and "I" do not have the same width in hershey format!)
1031
1034
#if PLPLOT_PRIVATE_NOT_HIDDEN
1032
- if (stringLength) *stringLength=gdlGetStringLength (out)/this ->mmCharLength ();
1035
+ if (stringLength!= NULL ) *stringLength=gdlGetStringLength (out)/this ->mmCharLength ();
1033
1036
#endif
1034
1037
return out;
1035
1038
retrn:
1036
1039
activeFontCodeNum = curr_fnt;
1037
- if (stringLength) *stringLength=0 ;
1040
+ if (stringLength!= NULL ) *stringLength=0 ;
1038
1041
cout << " ERROR: GDLGStream::TranslateFormatCodes(\" " << in << " \" ) = \" " << out << " \" " << endl;
1039
1042
return " " ;
1040
1043
}
@@ -1052,7 +1055,7 @@ void GDLGStream::setLineSpacing(PLFLT newSpacing)
1052
1055
}
1053
1056
PLFLT GDLGStream::getSymbolSize (){return theCurrentSymSize;}
1054
1057
void GDLGStream::mtex ( const char *side, PLFLT disp, PLFLT posit, PLFLT just,
1055
- const char *text)
1058
+ const char *text, double *stringCharLength, double *stringCharHeight )
1056
1059
{
1057
1060
// plot does not handle !C
1058
1061
size_t len = strlen (text);
@@ -1061,15 +1064,17 @@ void GDLGStream::mtex( const char *side, PLFLT disp, PLFLT posit, PLFLT just,
1061
1064
simple=false ;
1062
1065
}
1063
1066
if (simple) {
1064
- plstream::mtex (side,disp,posit,just,TranslateFormatCodes (text).c_str ());
1067
+ plstream::mtex (side,disp,posit,just,TranslateFormatCodes (text,stringCharLength).c_str ());
1068
+ if (stringCharHeight!=NULL ) *stringCharHeight = 1 ;
1065
1069
return ;
1066
1070
}
1067
1071
// complicated:
1072
+ if (stringCharHeight != NULL ) *stringCharHeight = 0 ;
1068
1073
double d=0 ;
1069
1074
std::string s (text);
1070
1075
std::string newline=" !C" ;
1071
- long pos = 0 , oldpos=0 ;
1072
- PLFLT ydisp=( 1.0 + nLineSpacing ()/nCharHeight () );
1076
+ size_t pos = 0 , oldpos=0 ;
1077
+ PLFLT yadd= nLineSpacing ()/nCharHeight ();
1073
1078
std::vector<long > positions;
1074
1079
while (pos != string::npos) {
1075
1080
pos = s.find (newline, oldpos);
@@ -1081,11 +1086,19 @@ void GDLGStream::mtex( const char *side, PLFLT disp, PLFLT posit, PLFLT just,
1081
1086
for (std::vector<long >::iterator it = positions.begin (); it != positions.end ();) {
1082
1087
oldpos=(*it++);
1083
1088
pos=(*(it++));
1084
- long l=pos-oldpos;
1089
+ size_t l=pos-oldpos;
1085
1090
if (l<0 ) l=string::npos;
1086
1091
// std::cerr<<pos<<":"<<l<<" "<<s.substr(oldpos,l)<<std::endl;
1087
- plstream::mtex (side,disp,posit,just,TranslateFormatCodes (s.substr (oldpos,l).c_str ()).c_str ());
1088
- disp+=ydisp;
1092
+ plstream::mtex (side,disp,posit,just,TranslateFormatCodes (s.substr (oldpos,l).c_str (),&d).c_str ());
1093
+ if (strstr (side," b" )!=NULL ) { // bottom increments 1 line
1094
+ disp += yadd;
1095
+ } else if (strstr (side," t" )!=NULL ) {// top decrements 1 line
1096
+ disp -= yadd;
1097
+ } else {// left decrements position in Y : change posit not disp unless parallel
1098
+ if (strstr (side," v" )!=NULL ) posit-=nLineSpacing ()/boxnYSize () ; else disp -= yadd;
1099
+ }
1100
+ if (stringCharLength!=NULL ) *stringCharLength = std::max<double >(*stringCharLength, d);
1101
+ if (stringCharHeight!=NULL ) *stringCharHeight += 1 ;
1089
1102
}
1090
1103
}
1091
1104
@@ -1106,8 +1119,8 @@ void GDLGStream::ptex( PLFLT x, PLFLT y, PLFLT dx, PLFLT dy, PLFLT just,
1106
1119
double d=0 ;
1107
1120
std::string s (text);
1108
1121
std::string newline=" !C" ;
1109
- long pos = 0 , oldpos=0 ;
1110
- PLFLT ydisp=(1.0 + nLineSpacing ()/nCharHeight ())*wCharHeight ();
1122
+ size_t pos = 0 , oldpos=0 ;
1123
+ PLFLT ydisp=(nLineSpacing ()/nCharHeight ())*wCharHeight ();
1111
1124
std::vector<long > positions;
1112
1125
while (pos != string::npos) {
1113
1126
pos = s.find (newline, oldpos);
@@ -1119,7 +1132,7 @@ void GDLGStream::ptex( PLFLT x, PLFLT y, PLFLT dx, PLFLT dy, PLFLT just,
1119
1132
for (std::vector<long >::iterator it = positions.begin (); it != positions.end ();) {
1120
1133
oldpos=(*it++);
1121
1134
pos=(*(it++));
1122
- long l=pos-oldpos;
1135
+ size_t l=pos-oldpos;
1123
1136
if (l<0 ) l=string::npos;
1124
1137
// std::cerr<<pos<<":"<<l<<" "<<s.substr(oldpos,l)<<std::endl;
1125
1138
plstream::ptex (x,y,dx,dy,just,TranslateFormatCodes (s.substr (oldpos,l).c_str (),&d).c_str ()) ;
@@ -1326,7 +1339,7 @@ void GDLGStream::adv(PLINT page)
1326
1339
if (thePage.curPage > thePage.nbPages ) thePage.curPage =1 ;
1327
1340
if (GDL_DEBUG_PLSTREAM) fprintf (stderr," adv() now at page %d\n " ,thePage.curPage );
1328
1341
PLFLT sxmin,symin,sxmax,symax,szmin,szmax;
1329
- getSubpageRegion (sxmin,symin,sxmax,symax,&szmin,&szmax);
1342
+ getSubpageRegion (& sxmin,& symin,& sxmax,& symax,&szmin,&szmax);
1330
1343
// SET ALL REGION TAGS
1331
1344
unsigned regionTag=SysVar::X ()->Desc ()->TagIndex (" REGION" );
1332
1345
(*static_cast <DFloatGDL*>(SysVar::X ()->GetTag (regionTag, 0 )))[0 ]=sxmin;
@@ -1339,19 +1352,47 @@ void GDLGStream::adv(PLINT page)
1339
1352
(*static_cast <DFloatGDL*>(SysVar::Z ()->GetTag (regionTag, 0 )))[1 ]=szmax;
1340
1353
}
1341
1354
1342
- void GDLGStream::getSubpageRegion (PLFLT &sxmin, PLFLT &symin, PLFLT &sxmax, PLFLT &symax, PLFLT *szmin, PLFLT *szmax){
1355
+ void GDLGStream::getSubpageRegion (PLFLT *sxmin, PLFLT *symin, PLFLT *sxmax, PLFLT *symax, PLFLT *szmin, PLFLT *szmax) {
1356
+ // here we must take into account the contents of ![X|Y|Z].OMARGIN
1357
+ unsigned int omarginTag = SysVar::X ()->Desc ()->TagIndex (" OMARGIN" );
1358
+ DFloat xstart = (*static_cast <DFloatGDL*> (SysVar::X ()->GetTag (omarginTag, 0 )))[0 ];
1359
+ xstart=MAX (xstart,0 );
1360
+ DFloat xend = (*static_cast <DFloatGDL*> (SysVar::X ()->GetTag (omarginTag, 0 )))[1 ];
1361
+ xend=MAX (xend,0 );
1362
+ omarginTag = SysVar::Y ()->Desc ()->TagIndex (" OMARGIN" );
1363
+ DFloat ystart = (*static_cast <DFloatGDL*> (SysVar::Y ()->GetTag (omarginTag, 0 )))[0 ];
1364
+ ystart=MAX (ystart,0 );
1365
+ DFloat yend = (*static_cast <DFloatGDL*> (SysVar::Y ()->GetTag (omarginTag, 0 )))[1 ];
1366
+ yend=MAX (yend,0 );
1367
+ // Z OMARGIN to BE CHECKED and code must be written.
1368
+ // omarginTag = SysVar::Z()->Desc()->TagIndex("OMARGIN");
1369
+ // DFloat zstart = (*static_cast<DFloatGDL*> (SysVar::Z()->GetTag(omarginTag, 0)))[0];
1370
+ // DFloat zend = (*static_cast<DFloatGDL*> (SysVar::Z()->GetTag(omarginTag, 0)))[1];
1371
+ DFloat xNormedPageSize=1 -(xend+xstart)*theCurrentChar.ndsx ;
1372
+ DFloat yNormedPageSize=1 -(yend+ystart)*theCurrentChar.nspacing ;
1373
+ if (xNormedPageSize < 0 || xNormedPageSize > 1 || yNormedPageSize < 0 || yNormedPageSize > 1 ) {
1374
+ Message (" Data coordinate system not established." );
1375
+ if (xNormedPageSize < 0 ) xNormedPageSize=0 ;
1376
+ if (yNormedPageSize < 0 ) yNormedPageSize=0 ;
1377
+ if (xNormedPageSize > 1 ) xNormedPageSize=1 ;
1378
+ if (yNormedPageSize > 1 ) yNormedPageSize=1 ;
1379
+ }
1380
+ DFloat zNormedPageSize=1 ; // zend-zstart??;
1381
+ DFloat xNormedOffset=xstart*theCurrentChar.ndsx ;
1382
+ DFloat yNormedOffset=yend*theCurrentChar.nspacing ;
1383
+ // check silly values: normed must be >0 and < 1
1343
1384
int p=thePage.curPage -1 ;
1344
- PLFLT width=1.0 /thePage.nx ;
1345
- PLFLT height=1.0 /thePage.ny ;
1346
- PLFLT profund=1.0 /thePage.nz ;
1385
+ PLFLT width=xNormedPageSize /thePage.nx ;
1386
+ PLFLT height=yNormedPageSize /thePage.ny ;
1387
+ PLFLT profund=zNormedPageSize /thePage.nz ;
1347
1388
int k= p / (thePage.nx *thePage.ny );
1348
1389
int l= p - k*(thePage.nx *thePage.ny );
1349
1390
int j= l /thePage.nx ;
1350
- int i= (l - j*thePage.nx );
1351
- sxmin=i*width;
1352
- sxmax=sxmin+width;
1353
- symax=1 -(j*height);
1354
- symin=symax-height;
1391
+ int i= (l - j*thePage.nx );
1392
+ * sxmin=i*width+xNormedOffset ;
1393
+ * sxmax=* sxmin+width;
1394
+ * symax=1 -(j*height+yNormedOffset );
1395
+ * symin=* symax-height;
1355
1396
if (szmin != NULL ) {
1356
1397
*szmin=k*profund;
1357
1398
*szmax=*szmin+profund;
0 commit comments