Bug 41652 - linefeed-treatment="preserve" not honored
Summary: linefeed-treatment="preserve" not honored
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: fo tree (show other bugs)
Version: 0.93
Hardware: Other other
: P2 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-18 10:38 UTC by J
Modified: 2012-04-01 06:55 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description J 2007-02-18 10:38:01 UTC
In the actual peace of code


fo:block hyphenate="false" font-family="monospace" text-align="start"
wrap-option="no-wrap" font-size="8pt" id="d0e3596" white-space-collapse="false"
white-space-treatment="preserve" linefeed-treatment="preserve"
line-stacking-strategy="font-height">xxxxxxxxxxxxxxxxxxxxx

yyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzz</fo:block>

the second (empty) line is "swallowed"
Comment 1 Andreas L. Delmelle 2007-02-18 11:07:24 UTC
Confirmed with FOP Trunk.

Interestingly, if you insert a space between the two consecutive linefeeds, you do get an empty line... 
leading me to think that the linefeed is preserved, but one ends up with a zero-height line.

A way to fix this may exactly be to insert such a space-character in the code somewhere, whenever there 
are two consecutive linefeeds.
Comment 2 Andreas L. Delmelle 2007-02-18 13:18:59 UTC
Further investigation and debugging confirm my suspicion, I think:

In both cases, with or without the intermediate space, the list returned by the TextLM consists of 4 
InlineKnuthSequences. Without the intermediate space, the second sequence contains only a 
KnuthPenalty corresponding to the preserved linefeed.

My initial idea of Inserting a space character would lead to undesirable outcomes, in for instance the 
following case:

<fo:block linefeed-treatment="preserve">xxxx
<fo:inline background-color="blue">

yyyy</fo:inline>
zzzz</fo:block>

in case there is a space on the 'empty' line, one would expect the blue background to appear for the 
width of one space character. In case it's just two consecutive linefeeds, the line should be completely 
empty, so no background should be visible...

I see a possible fix in adding the following to fop.layoutmgr.InlineKnuthSequence.endSequence():

        if (!isClosed) {
            if (isEmpty()) {
                add(new KnuthGlue(1, 0, 0, null, true));
            }
       ...

Or in English: if endSequence() is called on an empty sequence, add a dummy glue element.
The glue will be suppressed because of the following infinite penalty, so will leave no trace behind 
when background colors are used, like in the above example, but it will trigger the generation of the 
expected empty line (in AreaTree terms: an empty linearea, or one containing only an empty 
inlineparent of zero ipd)

I'm going to leave it open FTM, to allow others to comment in on the proposed change.
Comment 3 Andreas L. Delmelle 2007-02-19 08:05:41 UTC
(In reply to comment #2)
> I see a possible fix in adding the following to fop.layoutmgr.InlineKnuthSequence.endSequence():
>

On second thought, maybe it's better to do something similar in 
LineLayoutManager.collectInlineKnuthElements().

At line 746, an attempt is made to deal with the situation of blank lines (~ InlineKnuthSequence 
containing nothing but a forced break), but the added KnuthInlineBox of w=0 still doesn't produce the 
expected result. It does work if you increase the width (to some value between 1 and iLineWidth). 

Still, using an auxiliary KnuthGlue instead of a box also works, and somehow seems more appropriate.

Opinions anyone?
Comment 4 Andreas L. Delmelle 2007-02-22 11:08:56 UTC
Decided on the proposed change in LineLayoutManager.

Bug fixed in FOP Trunk.
see:  http://svn.apache.org/viewvc?view=rev&rev=510626

Thanks for reporting the bug!
Comment 5 Glenn Adams 2012-04-01 06:55:47 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed