Bug 49355 - Text renderer does not output correctly when margin is set
Summary: Text renderer does not output correctly when margin is set
Status: NEW
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: general (show other bugs)
Version: 0.95
Hardware: PC Windows XP
: P3 normal
Target Milestone: ---
Assignee: fop-dev
Depends on:
Reported: 2010-05-28 11:10 UTC by Vu
Modified: 2012-04-07 01:52 UTC (History)
0 users

This file contains sample .fo files for margin-top and margin-bottom settings (2.54 KB, application/zip)
2010-05-28 11:10 UTC, Vu

Note You need to log in before you can comment on or make changes to this bug.
Description Vu 2010-05-28 11:10:10 UTC
Created attachment 25493 [details]
This file contains sample .fo files for margin-top and margin-bottom settings

1. Configure FO to use text/plain as the output format

2. Generates an .fo file with margin-top sets (to create header)
3. If multiple page is generated, the margin-top value is compounded on the next pages and push the body text down until no more output for body text.

3. Generates an .fo file with margin-bottom sets (to create footer)
4. Body of text is not output

There are 2 attachments:
1) TextMarginTop.fo: This file contains 2 pages with header information set.
2) TextMarginBottom.fo: This file contains 2 pages with footer information set.
Comment 1 Vu 2010-05-28 11:24:00 UTC
Looking at the source file, I've noticed the following:

- The TXTRenderer uses TXTState as graphic state and TXTState implements as a stack (LinkedList)
- The CTM is pushed on to this graphic state in 2 cases:
   1) TXTRenderer.startVPArea()
   2) TXTRenderer.concatenateTransformationMatrix()

- But the CTM is popped out from this graphic state only when:
   1) TXTRenderer.endVPArea() is called

- There is no counterpart for TXTRenderer.concatenateTransformationMatrix() to popped the CTM out of the graphic state and that state accumulates all CTM and causes issue when rendering content.

My proposed approach is:
In TXTRenderer, create a new variable to keep a stack trace of when CTM is pushed, popped from the stack and whether it is pushed using the concatenateTransformationMatrix() method call.  When it is time for popping the CTM, check this new stack and pop the CTM out of the stack when the CTM is pushed on it using the concatenateTransformationMatrix() call.

-- Code example:

private LinkedList ctmTransformStack = new LinkedList();

protected void startVParea(CTM ctm, Rectangle2D clippingRect) {

protected void endVParea() {
    Boolean transformMatrix = (Boolean) ctmTransformStack.removeLast();
     * Perform compensation pop for concatenateTransformationMatrix()'s push
    while (transformMatrix.booleanValue()) {
      	transformMatrix = (Boolean) ctmTransformStack.removeLast();

protected void concatenateTransformationMatrix(AffineTransform at) {
   currentState.push(new CTM(ptToMpt(at)));
Comment 2 Glenn Adams 2012-04-07 01:37:15 UTC
resetting severity from major to normal pending further review
Comment 3 Glenn Adams 2012-04-07 01:43:26 UTC
resetting P2 open bugs to P3 pending further review