Bug 31206 - [PATCH] Improvements over the new line breaking algorithm
Summary: [PATCH] Improvements over the new line breaking algorithm
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: page-master/layout (show other bugs)
Version: trunk
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-13 20:27 UTC by Luca Furini
Modified: 2012-04-01 06:50 UTC (History)
0 users



Attachments
patch file (38.50 KB, patch)
2004-09-13 20:28 UTC, Luca Furini
Details | Diff
Fo file: leaders with use-content and dots (3.45 KB, text/plain)
2004-09-13 20:29 UTC, Luca Furini
Details
Fo file: centered text with larger or smaller inlines (1.89 KB, text/plain)
2004-09-13 20:30 UTC, Luca Furini
Details
test fo that illustrates the text and line height issues (4.54 KB, text/xml)
2004-09-19 18:36 UTC, Simon Pepping
Details
revised patch (62.89 KB, patch)
2004-10-15 16:22 UTC, Luca Furini
Details | Diff
leaders with pattern = rule, dots and use-content with svg graphics (3.45 KB, text/plain)
2004-10-15 16:24 UTC, Luca Furini
Details
vertical alignment (top, bottom, middle, baseline) of inlines (4.43 KB, text/plain)
2004-10-15 16:24 UTC, Luca Furini
Details
vertical alignment of images (4.12 KB, text/plain)
2004-10-15 16:25 UTC, Luca Furini
Details
file 15px.gif used in the test fo file (851 bytes, image/gif)
2004-10-15 16:26 UTC, Luca Furini
Details
file 20px.gif used in the test fo file (862 bytes, image/gif)
2004-10-15 16:26 UTC, Luca Furini
Details
file 30px.gif used in the test fo file (883 bytes, image/gif)
2004-10-15 16:26 UTC, Luca Furini
Details
new interface InlineLevelLayoutManager.java (2.87 KB, text/plain)
2004-11-12 15:36 UTC, Luca Furini
Details
updated patch to existing files (85.40 KB, patch)
2004-11-12 15:37 UTC, Luca Furini
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Luca Furini 2004-09-13 20:27:14 UTC
Some improvements over the new line breaking algorithm (see also Simon's last 
comment to bug 29124):

- a new interface InlineLayoutManager, implemented by LeafNodeLM, 
InlineStackingLM and ContentLM

- leaders with pattern "use-content" and "dots" now works

- better handling of preserved linefeeds

I'm going to attach the proposed patch and a few test fo files.
Regards
    Luca
Comment 1 Luca Furini 2004-09-13 20:28:12 UTC
Created attachment 12716 [details]
patch file
Comment 2 Luca Furini 2004-09-13 20:29:28 UTC
Created attachment 12717 [details]
Fo file: leaders with use-content and dots
Comment 3 Luca Furini 2004-09-13 20:30:29 UTC
Created attachment 12718 [details]
Fo file: centered text with larger or smaller inlines
Comment 4 Luca Furini 2004-09-13 20:33:05 UTC
I forgot to say that I fix a bug in the TextLM: KnuthBoxes generated by the 
TLM had height = 0, so the line height was not always correct.
Comment 5 Simon Pepping 2004-09-19 18:34:15 UTC
Luca,

I have a few remarks:

1. InlineStackingLM implements InlineLM.  LineLM extends
InlineStackingLM and thus implements InlineLM. IMHO it should
not. Implementing InlineLM should be equivalent to
generatesInlineAreas returning true.

2. TextLM now extends LeafNodeLM instead of AbstractLM. What is the
gain?  I see no related changes in TextLM.

3. In LineLM:
    // this constant is used to create elements when text-align is center:
    // every TextLM descendant of LineLM must use the same value, 
    // otherwise the line breaking algorithm does not find the right
    // break point
    public static final int DEFAULT_SPACE_WIDTH = 3336;
    private static final int INFINITE_RATIO = 1000;

If these are static final, they might be better placed in
InlineLM. Alternatively, they might be attributes of the LineLM
object, which allows changing them per paragraph, e.g. depending on
the font. But then the problem arises how to propagate them to the
descendant LMs.

4. The textheight of the large font is rather large. The property
lineheight is not followed (reproduce existing behaviour).

5. LineLayoutManager:675: line is always 3, so that firstElementIndex
= 1 for the first line, and the first box is skipped in the line
height calculation.

I attach a test fo that illustrates the text and line height issues.

Regards, Simon
Comment 6 Simon Pepping 2004-09-19 18:36:17 UTC
Created attachment 12784 [details]
test fo that illustrates the text and line height issues
Comment 7 Luca Furini 2004-10-15 16:22:01 UTC
I'm going to attach a revised version of the improvement patch:

- it fixes the line-height calculation errors
- better handling of preserved linefeed

I'm going to attach some test files too.

Regards
    Luca
Comment 8 Luca Furini 2004-10-15 16:22:55 UTC
Created attachment 13099 [details]
revised patch
Comment 9 Luca Furini 2004-10-15 16:24:10 UTC
Created attachment 13100 [details]
leaders with pattern = rule, dots and use-content with svg graphics
Comment 10 Luca Furini 2004-10-15 16:24:45 UTC
Created attachment 13101 [details]
vertical alignment (top, bottom, middle, baseline) of inlines
Comment 11 Luca Furini 2004-10-15 16:25:36 UTC
Created attachment 13102 [details]
vertical alignment of images
Comment 12 Luca Furini 2004-10-15 16:26:11 UTC
Created attachment 13103 [details]
file 15px.gif used in the test fo file
Comment 13 Luca Furini 2004-10-15 16:26:32 UTC
Created attachment 13104 [details]
file 20px.gif used in the test fo file
Comment 14 Luca Furini 2004-10-15 16:26:49 UTC
Created attachment 13105 [details]
file 30px.gif used in the test fo file
Comment 15 Simon Pepping 2004-11-06 14:24:42 UTC
Luca,

Leaders with content: in the test file leaders.fo I get PDF errors in
the SVG parts.

I have not checked the calculations of the vertical alignment. The
provided test fo files, and some test files I created myself, behave
well under the new code. I trust the code is OK.

As Finn pointed out, vertical-align is a shorthand property in
XSL. The values top, bottom, middle and baseline map to the values
before-edge, after-edge, middle and baseline of the property
alignment-baseline, with the properties alignment-adjust,
baseline-shift and dominant-baseline being at their default
values. Therefore I think if the current property vertical-align is
renamed to alignment-baseline, the code will keep working fine, and
the way is free to implement vertical-align as a shorthand property.

InlineLM is now a class (created by Finn on Oct. 19). The hierarchy
is:

InlineStackingLM
- InlineLM
- LineLM

The class InlineLM is at the position in the hierarchy where I think
InlineLM interface should be. Therefore I think InlineLM class can
well be merged with the proposed InlineLM interface.

I think the code in this patch is OK for committing to CVS. The items
noted above can be addressed over time.  However, the patch as it is
cannot be applied to the current version of CVS HEAD, due to the newly
created InlineLM class and extensive changes in property retrieval. If
you submit a patch of the same code against the current CVS HEAD, I
will commit it. Or you can keep it until you have write access to CVS
yourself.

Regards, Simon
Comment 16 Luca Furini 2004-11-12 15:35:26 UTC
I have created a new patch against HEAD.
I have tested it and it seems to work, but at the moment I'm not yet ready to 
commit it, sorry; maybe someone could do this in my place?

A few points which may need further work:

- I renamed the new interface from InlineLM to InlineLevelLM. Merging it with 
the new InlineLM class would involve having TextLM and LeafNodeLM extend 
InlineLM instead of AbstractLM, and this seems a bit strange to me

- the offset of the areas is set according to the value of the vertical-align 
property instead of alignment-baseline

- the offset of the viewport area generated by svg graphics is not set, 
because I couldn't find its height

- the offset of textAreas is set by the TextLM, which creates them; but 
vertical-align is a property of inline level formatting objects only, so the 
TextLM checks if the parent node is an Inline

- the main problem in applying the changes to the new code involved leaders 
with use-content; in the old code, the method LeaderLM.getLeaderInlineArea() 
created a ContentLM and an InlineStackingLM:
            LeaderLM
                |
                |
            ContentLM
                |
                |
         InlineStackingLM
            ____|____
            |   |   |
     (LMs handling the use-content)
but now InlineStackingLM does no more implement getNextKnuthElements(), and 
the InlineLM constructor requires an Inline node; I temporarily fixed this by 
adding a constructor for InlineLM with a Leader parameter, but I don't like 
this very much.

Regards,
    Luca
Comment 17 Luca Furini 2004-11-12 15:36:20 UTC
Created attachment 13414 [details]
new interface InlineLevelLayoutManager.java
Comment 18 Luca Furini 2004-11-12 15:37:04 UTC
Created attachment 13415 [details]
updated patch to existing files
Comment 19 Simon Pepping 2004-11-13 20:39:29 UTC
Applied. 

I made BasicLinkLM also extend InlineLM.

Thanks. Simon Pepping
Comment 20 Glenn Adams 2012-04-01 06:50:01 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed