You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Luca Furini <lf...@cs.unibo.it> on 2005/09/08 15:55:48 UTC

Re: svn commit: r279551 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java test/layoutengine/testcases/wrapper_text-transform_1.xml

Manuel Mall wrote:

> this is my code after integrating your patch to add the knuth elements 
> for line end / start border/padding for the common justify="start" or 
> "end" case. What I am getting now is a space at the beginning of each 
> line break!:
> 
> if (lineStartBAP != 0 || lineEndBAP != 0) {
>     sequence.add
>         (new KnuthGlue(lineEndBAP, 0, 0,
>                                 new LeafPosition(this, -1), true));
>     sequence.add
>         (new KnuthPenalty(0, 0, false,
>                                    new LeafPosition(this, -1), true));
>    sequence.add
>        (new KnuthGlue(wordSpaceIPD.opt - (lineStartBAP + lineEndBAP),
>                                wordSpaceIPD.max - wordSpaceIPD.opt,
>                                wordSpaceIPD.opt - wordSpaceIPD.min,
>         new LeafPosition(this, -1), true));
>     sequence.add
>         (new KnuthInlineBox(0, 0, 0, 0,
>                   notifyPos(new LeafPosition(this, -1)), true));
>     sequence.add
>         (new KnuthPenalty(0, KnuthElement.INFINITE, false,
>                                    new LeafPosition(this, -1), true));
>     sequence.add
>         (new KnuthGlue(lineStartBAP, 0, 0,
>                new LeafPosition(this, vecAreaInfo.size() - 1), false));
> } else {
> ...
> }

The LeafPosition(this, vecAreaInfo.size() - 1) (the Position containing 
the index of the AreaInfo objects storing information about the space) 
should be the one that is discared if a line break happens: i.e. the 
second one instead of the third.

With this change, this sequence should be correct for a space in justified 
text.

With left- / right-aligned text the overall stretch and shrink of the sequence should not be changed, so the sequence should be:
       sequence.add
           (new KnuthGlue(lineEndBAP, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
                          new LeafPosition(this, -1), true));
       sequence.add
           (new KnuthPenalty(0, 0, false,
                             new LeafPosition(this, -1), true));
       sequence.add
          (new KnuthGlue(wordSpaceIPD.opt - (lineStartBAP + lineEndBAP),
                         - 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH,
                         0,
                         new LeafPosition(***, false));
       sequence.add
           (new KnuthInlineBox(0, 0, 0, 0,
                               new LeafPosition(this, -1), true));
       sequence.add
           (new KnuthPenalty(0, KnuthElement.INFINITE, false,
                             new LeafPosition(this, -1), true));
       sequence.add
           (new KnuthGlue(lineStartBAP, 0, 0,
                          new LeafPosition(this, -1), true));

With centered text the combined sequence should be:
       sequence.add
           (new KnuthGlue(lineEndBAP, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
                          new LeafPosition(this, -1), true));
       sequence.add
           (new KnuthPenalty(0, 0, false,
                             new LeafPosition(this, -1), true));
       sequence.add
          (new KnuthGlue(wordSpaceIPD.opt - (lineStartBAP + lineEndBAP),
                         - 6 * LineLayoutManager.DEFAULT_SPACE_WIDTH,
                         0,
                         new LeafPosition(***, false));
       sequence.add
           (new KnuthInlineBox(0, 0, 0, 0,
                               new LeafPosition(this, -1), true));
       sequence.add
           (new KnuthPenalty(0, KnuthElement.INFINITE, false,
                             new LeafPosition(this, -1), true));
       sequence.add
           (new KnuthGlue(lineStartBAP,
                          3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
                          new LeafPosition(this, -1), true));

The Position marked *** should be a LeafPosition(this, vecAreaInfo.size() 
- 1); as it is in the element more connected with the "real" space (if 
this element is ignored, the space is too) maybe it is this one that must 
be "notified".

[from your other message]
> I am also unsure what the correct knuth element sequences are in the 
> case of the forced line break and for hyphenation.

A forced line break should not be very different from the "real" end of 
the inline, so I think it should be enough to add a box/glue element 
(according to the conditionality [1]) whose width is lineEndBAP before the 
penalty. In this case, the next returned sequence should start with the 
elements for the initial border and padding.

As per the hyphenation, I think we could use the same sequence created for 
a space (according to the alignment), but with the first penalty (the 
second element) having the width of the "-".

While answering your message I noticed that there are some inconstitencies 
in the TextLM: for example, the LineLM.DEFAULT_SPACE_WIDTH is not used 
everywhere it should ... I'll try and find some time to fix them.

I hope I did not answer you too late, otherwise ... "tomorrow is another 
day" :-)
The time difference between Italy and Australia can hinder communication!

Regards
     Luca

[1] in effects, as a preserved line break forces the end of a line, if 
border and padding are conditional there is no need to add any element, as 
we are already sure it's the last inline area in the line!



Re: svn commit: r279551 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java test/layoutengine/testcases/wrapper_text-transform_1.xml

Posted by Manuel Mall <mm...@arcus.com.au>.
Luca,

I just noticed that the new Knuth sequences proposed below break the 
removal of spaces at the end of paragraphs as the assumptions made in 
the code about the sequence of Knuth elements signifying a space are 
not true any more. This can happen if we have a <fo:block> inside a 
<fo:inline> and the inline has border / padding with 
conditionality="retain". In this (convoluted) scenario we have a 
paragraph end in the middle of a fo:inline which has a right border.

Any ideas how to fix that apart from having complicated 'if' statements 
in the trailing spaces removal code?

Manuel

On Thu, 8 Sep 2005 09:55 pm, Luca Furini wrote:
> Manuel Mall wrote:
> > this is my code after integrating your patch to add the knuth
> > elements for line end / start border/padding for the common
> > justify="start" or "end" case. What I am getting now is a space at
> > the beginning of each line break!:
> >
> > if (lineStartBAP != 0 || lineEndBAP != 0) {
> >     sequence.add
> >         (new KnuthGlue(lineEndBAP, 0, 0,
> >                                 new LeafPosition(this, -1), true));
> >     sequence.add
> >         (new KnuthPenalty(0, 0, false,
> >                                    new LeafPosition(this, -1),
> > true)); sequence.add
> >        (new KnuthGlue(wordSpaceIPD.opt - (lineStartBAP +
> > lineEndBAP), wordSpaceIPD.max - wordSpaceIPD.opt, wordSpaceIPD.opt
> > - wordSpaceIPD.min, new LeafPosition(this, -1), true));
> >     sequence.add
> >         (new KnuthInlineBox(0, 0, 0, 0,
> >                   notifyPos(new LeafPosition(this, -1)), true));
> >     sequence.add
> >         (new KnuthPenalty(0, KnuthElement.INFINITE, false,
> >                                    new LeafPosition(this, -1),
> > true)); sequence.add
> >         (new KnuthGlue(lineStartBAP, 0, 0,
> >                new LeafPosition(this, vecAreaInfo.size() - 1),
> > false)); } else {
> > ...
> > }
>
> The LeafPosition(this, vecAreaInfo.size() - 1) (the Position
> containing the index of the AreaInfo objects storing information
> about the space) should be the one that is discared if a line break
> happens: i.e. the second one instead of the third.
>
> With this change, this sequence should be correct for a space in
> justified text.
>
> With left- / right-aligned text the overall stretch and shrink of the
> sequence should not be changed, so the sequence should be:
> sequence.add
>            (new KnuthGlue(lineEndBAP, 3 *
> LineLayoutManager.DEFAULT_SPACE_WIDTH, 0, new LeafPosition(this, -1),
> true)); sequence.add
>            (new KnuthPenalty(0, 0, false,
>                              new LeafPosition(this, -1), true));
>        sequence.add
>           (new KnuthGlue(wordSpaceIPD.opt - (lineStartBAP +
> lineEndBAP), - 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
>                          new LeafPosition(***, false));
>        sequence.add
>            (new KnuthInlineBox(0, 0, 0, 0,
>                                new LeafPosition(this, -1), true));
>        sequence.add
>            (new KnuthPenalty(0, KnuthElement.INFINITE, false,
>                              new LeafPosition(this, -1), true));
>        sequence.add
>            (new KnuthGlue(lineStartBAP, 0, 0,
>                           new LeafPosition(this, -1), true));
>
> With centered text the combined sequence should be:
>        sequence.add
>            (new KnuthGlue(lineEndBAP, 3 *
> LineLayoutManager.DEFAULT_SPACE_WIDTH, 0, new LeafPosition(this, -1),
> true)); sequence.add
>            (new KnuthPenalty(0, 0, false,
>                              new LeafPosition(this, -1), true));
>        sequence.add
>           (new KnuthGlue(wordSpaceIPD.opt - (lineStartBAP +
> lineEndBAP), - 6 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
>                          new LeafPosition(***, false));
>        sequence.add
>            (new KnuthInlineBox(0, 0, 0, 0,
>                                new LeafPosition(this, -1), true));
>        sequence.add
>            (new KnuthPenalty(0, KnuthElement.INFINITE, false,
>                              new LeafPosition(this, -1), true));
>        sequence.add
>            (new KnuthGlue(lineStartBAP,
>                           3 * LineLayoutManager.DEFAULT_SPACE_WIDTH,
> 0, new LeafPosition(this, -1), true));
>
> The Position marked *** should be a LeafPosition(this,
> vecAreaInfo.size() - 1); as it is in the element more connected with
> the "real" space (if this element is ignored, the space is too) maybe
> it is this one that must be "notified".
>
> [from your other message]
>
> > I am also unsure what the correct knuth element sequences are in
> > the case of the forced line break and for hyphenation.
>
> A forced line break should not be very different from the "real" end
> of the inline, so I think it should be enough to add a box/glue
> element (according to the conditionality [1]) whose width is
> lineEndBAP before the penalty. In this case, the next returned
> sequence should start with the elements for the initial border and
> padding.
>
> As per the hyphenation, I think we could use the same sequence
> created for a space (according to the alignment), but with the first
> penalty (the second element) having the width of the "-".
>
> While answering your message I noticed that there are some
> inconstitencies in the TextLM: for example, the
> LineLM.DEFAULT_SPACE_WIDTH is not used everywhere it should ... I'll
> try and find some time to fix them.
>
> I hope I did not answer you too late, otherwise ... "tomorrow is
> another day" :-)
> The time difference between Italy and Australia can hinder
> communication!
>
> Regards
>      Luca
>
> [1] in effects, as a preserved line break forces the end of a line,
> if border and padding are conditional there is no need to add any
> element, as we are already sure it's the last inline area in the
> line!

Re: svn commit: r279551 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java test/layoutengine/testcases/wrapper_text-transform_1.xml

Posted by Manuel Mall <mm...@arcus.com.au>.
On Thu, 8 Sep 2005 09:55 pm, Luca Furini wrote:
> Manuel Mall wrote:
<snip />
> I hope I did not answer you too late, otherwise ... "tomorrow is
> another day" :-)

Of course its not too late and yes "tomorrow is another day" :-). 

Your suggestions worked first time - great stuff.

Still need to look at the hyphenation stuff though.

> The time difference between Italy and Australia can hinder
> communication!
>

Look at it as an opportunity - you can think about any answers to my 
questions while I am sleeping => no pressure - no need to rush.

> Regards
>      Luca
>

Thanks

Manuel