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 Simon Pepping <sp...@leverkruid.nl> on 2006/04/03 21:38:13 UTC
Generalized Knuth-Plass Linebreaking Algorithm
Hello,
Some time ago Manuel Mall pointed out a number of problems with
linebreaking in FOP. Specifically, there are some hard to solve
problems with suppression of whitespace before a linebreak.
I propose that the problems can be solved using a generalized set of
building blocks (a.k.a. Knuth elements):
1. Box, with elastic width. A box has two boolean properties:
1. suppress-at-linebreak, default value false. According to
the FO specification, in the default case in an FO text
it is true for the space character U+0020. The user may
deviate from the default and set it to false for the
space character, and to true for other characters.
2. is-BP, default value false. This property indicates
whether a box corresponds to a border and/or a padding
width. It is true for boxes which are generated by
padding widths and borders.
2. Penalty, with a penalty value and two elastic widths. When the
penalty element is the chosen linebreak, it contributes the
first elastic width before the linebreak and the second elastic
width after the linebreak.
Penalties are legal breakpoints. Boxes are not.
On my website I have published a detailed account of my proposal in
the essay 'Generalized Knuth-Plass Linebreaking Algorithm'. In order
to test my ideas in practice, I have written a simple implementation
in Java of this approach.
See http://www.leverkruid.nl/GKPLinebreaking/index.html.
Please, let me know what you think of it.
Regards, Simon
--
Simon Pepping
home page: http://www.leverkruid.nl
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Simon Pepping <sp...@leverkruid.nl>.
On Tue, Apr 04, 2006 at 10:15:26PM +0200, Jeremias Maerki wrote:
> I agree with Chris' comment about "isBP". BP could easily be
> misunderstood as "block progression", for example. Furthermore, you talk
I can do that.
> about border and padding, but as Manuel notes there's also space (the
> margin-kind, not whitespace). Note that spaces have stretch and shrink
> while border and padding do not. You don't have any reference to it in
I will add the margin. My boxes can have stretch and shrink, so that
is no problem
> your essay, but I assume that space resolution would still be possible
> with the current SpaceResolver. It would simply have to be adjusted to
> the new model, right? While I was digging into letter and word spaces I
Space resolution occurs before linebreaking. It is one of FOP's
components that building sequences of Knuth elements. It will have to
build a sequence of the new elements, which should not be a problem.
> realized that it will be worthwhile (even necessary) to look at the
> FO-specifics for these two properties if any bigger refactoring of the
> current inline progression handling is to be done. Both properties
> create (potentially conditional) spaces which would all need to be
> processed by the space resolver. So, I'm not sure, yet, if we already
> have the full picture here. I've got to find some quiet time to reflect
> on that some more.
As I said above, the two problems should be unrelated. Space
resolution has its own logic, but the outcome is an amount of space
that should be presented to the line breaker. The Knuth element system
provides the elements that can be used, and I expect that my modified
elements are sufficient for letter and word spacing. In fact it would
even be possible to have a single box for a word, its letter spacing
and its following word space (apart from hyphenation).
Simon
--
Simon Pepping
home page: http://www.leverkruid.nl
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Very interesting! I will probably need some more time to fully digest
everything, but so far it feels quite good and would certainly simplify
a few things. Thank you for this work. It will be very valuable.
I agree with Chris' comment about "isBP". BP could easily be
misunderstood as "block progression", for example. Furthermore, you talk
about border and padding, but as Manuel notes there's also space (the
margin-kind, not whitespace). Note that spaces have stretch and shrink
while border and padding do not. You don't have any reference to it in
your essay, but I assume that space resolution would still be possible
with the current SpaceResolver. It would simply have to be adjusted to
the new model, right? While I was digging into letter and word spaces I
realized that it will be worthwhile (even necessary) to look at the
FO-specifics for these two properties if any bigger refactoring of the
current inline progression handling is to be done. Both properties
create (potentially conditional) spaces which would all need to be
processed by the space resolver. So, I'm not sure, yet, if we already
have the full picture here. I've got to find some quiet time to reflect
on that some more.
On 03.04.2006 21:38:13 Simon Pepping wrote:
> Hello,
>
> Some time ago Manuel Mall pointed out a number of problems with
> linebreaking in FOP. Specifically, there are some hard to solve
> problems with suppression of whitespace before a linebreak.
>
> I propose that the problems can be solved using a generalized set of
> building blocks (a.k.a. Knuth elements):
>
> 1. Box, with elastic width. A box has two boolean properties:
>
> 1. suppress-at-linebreak, default value false. According to
> the FO specification, in the default case in an FO text
> it is true for the space character U+0020. The user may
> deviate from the default and set it to false for the
> space character, and to true for other characters.
>
> 2. is-BP, default value false. This property indicates
> whether a box corresponds to a border and/or a padding
> width. It is true for boxes which are generated by
> padding widths and borders.
>
> 2. Penalty, with a penalty value and two elastic widths. When the
> penalty element is the chosen linebreak, it contributes the
> first elastic width before the linebreak and the second elastic
> width after the linebreak.
>
> Penalties are legal breakpoints. Boxes are not.
>
> On my website I have published a detailed account of my proposal in
> the essay 'Generalized Knuth-Plass Linebreaking Algorithm'. In order
> to test my ideas in practice, I have written a simple implementation
> in Java of this approach.
>
> See http://www.leverkruid.nl/GKPLinebreaking/index.html.
>
> Please, let me know what you think of it.
>
> Regards, Simon
>
> --
> Simon Pepping
> home page: http://www.leverkruid.nl
Jeremias Maerki
Re: Knuth linebreaking elements for Formatting Objects
Posted by Simon Pepping <sp...@leverkruid.eu>.
On Mon, May 01, 2006 at 08:20:04PM +0200, Simon Pepping wrote:
> Hello,
>
> During the past weeks I added a test facility. This allows one to feed
> test texts in an XHTML-like document. It is now available on my web
> site, http://www.leverkruid.eu/GKPLinebreaking/index.html. Since
> publication, I discovered that there is a problem with the treatment
> of soft-hyphens. I am working on it.
The problem has been solved. In doing so I introduced a new element,
box-penalty. I also added a section to my essay about a derivation of
the elements. Finally I changed the title into something less
generalized.
> Note that I am changing web domain from nl to eu.
>
> On Mon, Apr 03, 2006 at 09:38:13PM +0200, Simon Pepping wrote:
> > Hello,
> >
> > Some time ago Manuel Mall pointed out a number of problems with
> > linebreaking in FOP. Specifically, there are some hard to solve
> > problems with suppression of whitespace before a linebreak.
> >
> > I propose that the problems can be solved using a generalized set of
> > building blocks (a.k.a. Knuth elements):
> >
> > 1. Box, with elastic width. A box has two boolean properties:
> >
> > 1. suppress-at-linebreak, default value false. According to
> > the FO specification, in the default case in an FO text
> > it is true for the space character U+0020. The user may
> > deviate from the default and set it to false for the
> > space character, and to true for other characters.
> >
> > 2. is-BP, default value false. This property indicates
> > whether a box corresponds to a border and/or a padding
> > width. It is true for boxes which are generated by
> > padding widths and borders.
> >
> > 2. Penalty, with a penalty value and two elastic widths. When the
> > penalty element is the chosen linebreak, it contributes the
> > first elastic width before the linebreak and the second elastic
> > width after the linebreak.
> >
> > Penalties are legal breakpoints. Boxes are not.
Regards, Simon
--
Simon Pepping
home page: http://www.leverkruid.eu
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Simon Pepping <sp...@leverkruid.eu>.
Hello,
During the past weeks I added a test facility. This allows one to feed
test texts in an XHTML-like document. It is now available on my web
site, http://www.leverkruid.eu/GKPLinebreaking/index.html. Since
publication, I discovered that there is a problem with the treatment
of soft-hyphens. I am working on it.
Note that I am changing web domain from nl to eu.
Regards, Simon
On Mon, Apr 03, 2006 at 09:38:13PM +0200, Simon Pepping wrote:
> Hello,
>
> Some time ago Manuel Mall pointed out a number of problems with
> linebreaking in FOP. Specifically, there are some hard to solve
> problems with suppression of whitespace before a linebreak.
>
> I propose that the problems can be solved using a generalized set of
> building blocks (a.k.a. Knuth elements):
>
> 1. Box, with elastic width. A box has two boolean properties:
>
> 1. suppress-at-linebreak, default value false. According to
> the FO specification, in the default case in an FO text
> it is true for the space character U+0020. The user may
> deviate from the default and set it to false for the
> space character, and to true for other characters.
>
> 2. is-BP, default value false. This property indicates
> whether a box corresponds to a border and/or a padding
> width. It is true for boxes which are generated by
> padding widths and borders.
>
> 2. Penalty, with a penalty value and two elastic widths. When the
> penalty element is the chosen linebreak, it contributes the
> first elastic width before the linebreak and the second elastic
> width after the linebreak.
>
> Penalties are legal breakpoints. Boxes are not.
>
> On my website I have published a detailed account of my proposal in
> the essay 'Generalized Knuth-Plass Linebreaking Algorithm'. In order
> to test my ideas in practice, I have written a simple implementation
> in Java of this approach.
>
> See http://www.leverkruid.nl/GKPLinebreaking/index.html.
>
> Please, let me know what you think of it.
>
> Regards, Simon
>
> --
> Simon Pepping
> home page: http://www.leverkruid.nl
>
--
Simon Pepping
home page: http://www.leverkruid.eu
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Chris Bowditch <bo...@hotmail.com>.
Simon Pepping wrote:
> Hello,
>
> Some time ago Manuel Mall pointed out a number of problems with
> linebreaking in FOP. Specifically, there are some hard to solve
> problems with suppression of whitespace before a linebreak.
This is excellent news Simon. I was a little concerned when Manuel
pointed out these problems and it became clear that the Knuth algorithm
could not solve them easily. I've only glanced at your proposal, so
can't comment on the details, but anything that gives us a way foward
with these whitespace handling problems has got to be good :)
>
> I propose that the problems can be solved using a generalized set of
> building blocks (a.k.a. Knuth elements):
>
> 1. Box, with elastic width. A box has two boolean properties:
>
> 1. suppress-at-linebreak, default value false. According to
> the FO specification, in the default case in an FO text
> it is true for the space character U+0020. The user may
> deviate from the default and set it to false for the
> space character, and to true for other characters.
>
> 2. is-BP, default value false. This property indicates
> whether a box corresponds to a border and/or a padding
> width. It is true for boxes which are generated by
> padding widths and borders.
One minor nit: could you rename is-BP to isBorderPadding? The
suppress-at-linebreak property is a long self explanatory name, whilst
isBP is somewhat cryptic. I initially thought it mean is Block
Progression....
>
> 2. Penalty, with a penalty value and two elastic widths. When the
> penalty element is the chosen linebreak, it contributes the
> first elastic width before the linebreak and the second elastic
> width after the linebreak.
>
> Penalties are legal breakpoints. Boxes are not.
>
> On my website I have published a detailed account of my proposal in
> the essay 'Generalized Knuth-Plass Linebreaking Algorithm'. In order
> to test my ideas in practice, I have written a simple implementation
> in Java of this approach.
>
> See http://www.leverkruid.nl/GKPLinebreaking/index.html.
>
> Please, let me know what you think of it.
Good work and thanks,
Chris
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Sounds good. I'm looking forward to seeing the new code in action when
it's ready. Keep in mind that you can place the code in a temporary
branch if you want.
On 28.05.2006 20:24:46 Simon Pepping wrote:
> I have published an update at
> http://www.leverkruid.eu/GKPLinebreaking/index.html. Bells and
> whistles have been implemented. Text alignment has been implemented. I
> am working on text-align-last.
>
> Regards, Simon
>
> On Mon, Apr 03, 2006 at 09:38:13PM +0200, Simon Pepping wrote:
> > Hello,
> >
> > Some time ago Manuel Mall pointed out a number of problems with
> > linebreaking in FOP. Specifically, there are some hard to solve
> > problems with suppression of whitespace before a linebreak.
> >
> > I propose that the problems can be solved using a generalized set of
> > building blocks (a.k.a. Knuth elements):
> >
> > 1. Box, with elastic width. A box has two boolean properties:
> >
> > 1. suppress-at-linebreak, default value false. According to
> > the FO specification, in the default case in an FO text
> > it is true for the space character U+0020. The user may
> > deviate from the default and set it to false for the
> > space character, and to true for other characters.
> >
> > 2. is-BP, default value false. This property indicates
> > whether a box corresponds to a border and/or a padding
> > width. It is true for boxes which are generated by
> > padding widths and borders.
> >
> > 2. Penalty, with a penalty value and two elastic widths. When the
> > penalty element is the chosen linebreak, it contributes the
> > first elastic width before the linebreak and the second elastic
> > width after the linebreak.
> >
> > Penalties are legal breakpoints. Boxes are not.
> >
> > On my website I have published a detailed account of my proposal in
> > the essay 'Generalized Knuth-Plass Linebreaking Algorithm'. In order
> > to test my ideas in practice, I have written a simple implementation
> > in Java of this approach.
> >
>
> --
> Simon Pepping
> home page: http://www.leverkruid.eu
Jeremias Maerki
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Simon Pepping <sp...@leverkruid.eu>.
I have published an update at
http://www.leverkruid.eu/GKPLinebreaking/index.html. Bells and
whistles have been implemented. Text alignment has been implemented. I
am working on text-align-last.
Regards, Simon
On Mon, Apr 03, 2006 at 09:38:13PM +0200, Simon Pepping wrote:
> Hello,
>
> Some time ago Manuel Mall pointed out a number of problems with
> linebreaking in FOP. Specifically, there are some hard to solve
> problems with suppression of whitespace before a linebreak.
>
> I propose that the problems can be solved using a generalized set of
> building blocks (a.k.a. Knuth elements):
>
> 1. Box, with elastic width. A box has two boolean properties:
>
> 1. suppress-at-linebreak, default value false. According to
> the FO specification, in the default case in an FO text
> it is true for the space character U+0020. The user may
> deviate from the default and set it to false for the
> space character, and to true for other characters.
>
> 2. is-BP, default value false. This property indicates
> whether a box corresponds to a border and/or a padding
> width. It is true for boxes which are generated by
> padding widths and borders.
>
> 2. Penalty, with a penalty value and two elastic widths. When the
> penalty element is the chosen linebreak, it contributes the
> first elastic width before the linebreak and the second elastic
> width after the linebreak.
>
> Penalties are legal breakpoints. Boxes are not.
>
> On my website I have published a detailed account of my proposal in
> the essay 'Generalized Knuth-Plass Linebreaking Algorithm'. In order
> to test my ideas in practice, I have written a simple implementation
> in Java of this approach.
>
--
Simon Pepping
home page: http://www.leverkruid.eu
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Simon Pepping <sp...@leverkruid.nl>.
On Tue, Apr 04, 2006 at 11:26:38PM +0800, Manuel Mall wrote:
> On Tuesday 04 April 2006 03:38, Simon Pepping wrote:
> > Hello,
> >
> <snip/>
>
> Simon,
>
> very interesting approach to the problem. You obviously gave this quite
> a significant amount of thought.
>
> While your approach may simplify many Knuth sequences for the less
> common (or more convoluted) cases you clearly state that the only case
> where the original Knuth algorithm has no solution is this "blasted"
> <space><border><space> case where the XSL-FO rules say we have to
> suppress the space before the border (assuming the usual property value
> settings).
>
> The solution in the context of the Knuth algorithm I had in mind is to
> do a simple re-ordering of the generated elements. Instead of
> generating the Knuth sequence for <space><border><space> we generate a
> sequence matching <border><space><space> which would suppress all
> spaces if a line break is created. However, if the spaces are not
> removed we render it as <space><border><space>. While I have not looked
> into the details of how this could be implemented in the current FOP
> code it didn't strike me as overly complicated.
>
> On the other hand your solution may well make such workaround
> unnecessary. IMO, your best bet to prove that it works is to branch the
> FOP code and plug your new model in. As you have outlined the mapping
> from old to new that shouldn't be too invasive.
I do not like workarounds very much. Often I prefer to reconsider the
basis. And it is a nice project to try to make a variant of Knuth's
method work.
I will first expand by implementation with a method to easily feed
test cases and with Knuth and Plass' bells and whistles. Then I may
try my hand at an implementation in a FOP branch. But that will take a
while because I have only a limited amount of time to spend on FOP.
Simon
--
Simon Pepping
home page: http://www.leverkruid.nl
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Manuel Mall <ma...@apache.org>.
On Tuesday 04 April 2006 03:38, Simon Pepping wrote:
> Hello,
>
<snip/>
Simon,
very interesting approach to the problem. You obviously gave this quite
a significant amount of thought.
While your approach may simplify many Knuth sequences for the less
common (or more convoluted) cases you clearly state that the only case
where the original Knuth algorithm has no solution is this "blasted"
<space><border><space> case where the XSL-FO rules say we have to
suppress the space before the border (assuming the usual property value
settings).
The solution in the context of the Knuth algorithm I had in mind is to
do a simple re-ordering of the generated elements. Instead of
generating the Knuth sequence for <space><border><space> we generate a
sequence matching <border><space><space> which would suppress all
spaces if a line break is created. However, if the spaces are not
removed we render it as <space><border><space>. While I have not looked
into the details of how this could be implemented in the current FOP
code it didn't strike me as overly complicated.
On the other hand your solution may well make such workaround
unnecessary. IMO, your best bet to prove that it works is to branch the
FOP code and plug your new model in. As you have outlined the mapping
from old to new that shouldn't be too invasive.
>
> Please, let me know what you think of it.
>
> Regards, Simon
Cheers
Manuel
Re: Generalized Knuth-Plass Linebreaking Algorithm
Posted by Simon Pepping <sp...@leverkruid.eu>.
Hello,
I have published another update at
http://www.leverkruid.eu/GKPLinebreaking/index.html. With this update
I consider my essay and test implementation complete.
Regards, Simon
On Mon, Apr 03, 2006 at 09:38:13PM +0200, Simon Pepping wrote:
> Hello,
>
> Some time ago Manuel Mall pointed out a number of problems with
> linebreaking in FOP. Specifically, there are some hard to solve
> problems with suppression of whitespace before a linebreak.
>
> I propose that the problems can be solved using a generalized set of
> building blocks (a.k.a. Knuth elements):
>
> 1. Box, with elastic width. A box has two boolean properties:
>
> 1. suppress-at-linebreak, default value false. According to
> the FO specification, in the default case in an FO text
> it is true for the space character U+0020. The user may
> deviate from the default and set it to false for the
> space character, and to true for other characters.
>
> 2. is-BP, default value false. This property indicates
> whether a box corresponds to a border and/or a padding
> width. It is true for boxes which are generated by
> padding widths and borders.
>
> 2. Penalty, with a penalty value and two elastic widths. When the
> penalty element is the chosen linebreak, it contributes the
> first elastic width before the linebreak and the second elastic
> width after the linebreak.
>
> Penalties are legal breakpoints. Boxes are not.
>
> On my website I have published a detailed account of my proposal in
> the essay 'Generalized Knuth-Plass Linebreaking Algorithm'. In order
> to test my ideas in practice, I have written a simple implementation
> in Java of this approach.
--
Simon Pepping
home page: http://www.leverkruid.eu