Re: TPaveText::AddText() behavior: Unix vs Win32

Valery Fine (fine@bnl.gov)
Sat, 6 Feb 1999 16:30:10 -0500


Hello Scott
On 5 Feb 99 at 23:13, you wrote:

> The following macro behaves differently under Win32 and Dec Unix
> (ROOT 2.21/03). Under Win98, the newlines generate empty boxes
> while in unix they properly generate new lines.
>
> Output to PostScript does not produce the newlines in either case.
> (However, if the same text is imported from a file using GetFile(),
> newlines are created as expected)
>
> Can anyone confirm this on other platforms?
>
> {
> TCanvas *c = new TCanvas("c","Test",1);
> TPaveText *pt = new TPaveText(0,0,1,1);
> pt->AddText("0\n1\n2\n3");
> pt->Draw();
> }
>
I've looked uo the source of that method.
It has comment:

/*-*-*-*-*Add a new Text line to this pavetext at given coordinates*-*-*-*-*

and the statement:

fLines->Add(newtext);

where "newtext' is a user's input parameter.

Both things together just prove this method is designed
to add one single line and what you found under UNIX is a king of "bug"(;-)
in UNIX implementation.
(see TText *TPaveText::GetLine(Int_t number))

This code doesn't expect one line o f text and calculates the tall of
the "visible" line taking in account only one row.
I suspect under Windows it draw all lines too but they are pro[erly clipped
out but the low level graphic layer.


What about
void TPaveText::ReadFile(const Text_t *filename, Option_t *option, Int_t nlines, Int_t fromline)
I suppose you meant very this method speaking

" . . . (However, if the same text is imported from a file using GetFile(),
newlines are created as expected)
. . . "

This method inside calls "AddText(s)" as many times as the number of the
lines your file does contain.

and its decription does say:

" Read from line number fromline a total of nlines"

This means you should split yourself your text by lines and then call "AddText".
for example instead of your

> TCanvas *c = new TCanvas("c","Test",1);
> TPaveText *pt = new TPaveText(0,0,1,1);
> pt->AddText("0\n1\n2\n3");
> pt->Draw();
===
apply something like:

TCanvas *c = new TCanvas("c","Test",1);
TPaveText *pt = new TPaveText(0,0,1,1);
//
char buffer[100];
char *p=strcpy(buffer,"0\n1\n2\n3");
char *lf = 0;
while(p && *p && lf=strchr(p,'\n')){
*lf = 0;
pt->AddText(p);
p = lf+1;
}
if (p) pt->AddText(p);
//
pt->Draw();
===

Hope this helps,
Valery
=================================================================
Dr. Valeri Faine (Fine)
------------------- Phone: +1 516 344 7806
Brookhaven National Laboratory FAX : +1 516 344 4206
Bldg. 510A /STAR mailto:fine@bnl.gov
Upton, New York, 11973-5000 http://nicewww.cern.ch/~fine
USA

Dr. Valery Fine Telex : 911621 dubna su
-----------
LCTA/Joint Inst.for Nuclear Res. Phone : +7 09621 6 40 80
141980 Dubna, Moscow region Fax : +7 09621 6 51 45
Russia mailto:fine@main1.jinr.dubna.su