Carriage returns/line breaks in data [message #112018] |
Thu, 19 January 2006 23:42  |
Eclipse User |
|
|
|
I have long text data that has carriage returns and line breaks. It is not
putting the right spacing in PDF. Anyone have a work around? I have
tried putting HTML tags and \n \r escape characters in the data, doesn't
work.
Thanks...
|
|
|
|
|
Re: Carriage returns/line breaks in data [message #112198 is a reply to message #112120] |
Fri, 20 January 2006 08:34   |
Eclipse User |
|
|
|
On Fri, 20 Jan 2006 11:39:20 +0000 (UTC), mebo@gmx.at (Thomas A.
X-Berger) wrote:
>Hi,
>
>I have the same problem, but I haven't found a solution yet.
>But I've seen you visited the Bugzilla entries(123875,124589).
>So you already have a walkaround,don't you?
>
>MfU + best regards,
> Thomas.
I had the problem using long texts coming from a scripted datasource.
If the text contains a \n\r, birt doesn't automatically break the
lines, and a too long line flies out of the text block (which, I must
agree, isn't very readable...!)
I had to use a fixed-length font, and use scripting to parse the text
and insert line feeds in the 'too long' lines...
(code given as example)
var textToSplit= (row["dataLongText"] != null) ? row["dataLongText"] :
"";
res = "";
maxLen = 66;
// split the text in lines
var lines = textToSplit.split("\r\n");
for (i = 0; i < lines.length; i++) {
line = lines[i];
// if line is longer than maxLen, split it
if (line.length > maxLen) {
// split long line in words
var vecWords = line.split(" ");
j = 0;
lenLine = 0;
// for each word (but the last one)
for (j = 0; j < vecWords.length; j++) {
// check length
lenNextWord = vecWords[j].length + 1;
// if the line still is smaller than the max
length when we add the word and a space
if (lenLine + lenNextWord < maxLen+1) {
// add the word and a space
res = res + vecWords[j] + " ";
// increase the line length
lenLine += lenNextWord;
} // else (next word will make line too long)
else {
// we reached the max length for the
line; go to next line and insert word.
res = res + "\r\n" + vecWords[j] + "
";
// current line length = length of
(word + space)
lenLine = lenNextWord;
}
}
// remove last added space and insert line feed
res = res.substr(0, res.length - 1) + "\r\n";
} // else (only one word) add it to the result with a line
feed
else {
res = res + line + "\r\n";
}
// next line
}
// return result, but remove last CR LF
res.substr(0, res.length - 2);
|
|
|
|
Re: Carriage returns/line breaks in data: \n \r effects [message #112465 is a reply to message #112198] |
Fri, 20 January 2006 14:17   |
Eclipse User |
|
|
|
Looked over your code...the approach makes sense, though for my problem I
would look for the cr/lf in the data and add javascript escapes between
segments. Are you saying that you are not getting row["dataLongText"] to
wrap, when that is the sole entry in the data javascript? Any chance that
the Text Whitespace property is set to no wrap? I haven't had line
overflow problems-just can't get pretty spaces between paragraphs that are
in the original data. But when I split the data into paragraphs and enter
the escapes, I may have your problem, I guess.
I tested using escapes without using variables-and there is trick in RC2
that I had to do to get escapes to work. Basically, I need two line feeds
to get the line between paragraphs. If I put in \r \n \r \n (or \n \r \n
\r), in HTML I get the effect of :
Line one
Line two
In PDF, Line two disappears. However, if I just use \n \n, then you get
the same effect in HTML and PDF.
I'll have to see if I can test for the line feeds/carriage returns in the
original data and use your split technique. If it works, I'll post a
function in bug report 124589...unless they fix it before release
(unlikely, CVS is closed...)
Jett
|
|
|
|
|
|
Re: Carriage returns/line breaks in data: Function Posted [message #113837 is a reply to message #113135] |
Tue, 24 January 2006 02:52  |
Eclipse User |
|
|
|
Hi,
I've found out the reason why it didn't work on my machine, but I don't
understand it by now.
formattedText += " \n";
[/working code]
formattedText += "\n";
[/not working code]
It's the blank before the \n.
So if somebody else has problems with the line-break try to make some
spaces
before or after the line-break and hope for the best ;o)
MfU & best regards,
Thomas.
|
|
|
Powered by
FUDForum. Page generated in 0.05556 seconds