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 Eric SCHAEFFER <es...@posterconseil.com> on 1999/11/24 18:00:31 UTC

Bug in 'layout' when in table cell - Background color property

I found a bug in the layout function, 'endIndent' should be calculated like
this :

     if (this.isInTableCell) {
  startIndent += forcedStartOffset;
  endIndent += area.getAllocationWidth() - forcedWidth - forcedStartOffset;
     }

I've implemented the background-color property, but I had to introduce a
subclass of Box to do it. It saves the background color, startIndent,
endIndent, and the width and height of the area. When rendering, it draws a
filled rectangle before rendering the others area.
The problem is that, for tables (Table, TableBody, TableRow, TableCell), the
width or height of the area aren't always good and I had to calculate them
differently.
I don't know how to correct this. If someone has an idea...

My implementation works perfectly (I've made it for block, table,
table-body, table-row and table-cell). I've made others modifications (for
images), so the 'diff' is a bit polluated...

Added : BackgroundColorBox.java

package org.apache.fop.layout;

// FOP
import org.apache.fop.render.Renderer;
import org.apache.fop.datatypes.ColorType;

public class BackgroundColorBox extends Box {

    /* relative to area container */
    protected int startIndent;
    protected int endIndent;

  /* size of the box */
  protected int width;
  protected int height;

    /* bg color */
    protected ColorType bgColor;

    public BackgroundColorBox(
       int w, int h,
       int startIndent, int endIndent,
        ColorType bg_color) {

 this.width = w;
 this.height = h;
 this.startIndent = startIndent;
 this.endIndent = endIndent;

 this.bgColor = bg_color;
    }

    public void render(Renderer renderer) {
 renderer.renderBackgroundColorBox(this);
    }

    public int getWidth() {
 return width;
    }

    public void setWidth(int w) {
 width = w;
    }

    public int getHeight() {
 return height;
    }

    public void setHeight(int h) {
 height = h;
    }

    public int getEndIndent() {
 return endIndent;
    }

    public int getStartIndent() {
 return startIndent;
    }

    public ColorType getColor() {
 return this.bgColor;
    }
}


Index: ./src/org/apache/fop/fo/flow/TableCell.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableCell.java,v
retrieving revision 1.6
diff -r1.6 TableCell.java
57a58
> import org.apache.fop.datatypes.ColorType;
76a78
>     ColorType bgColor;
124a127,128
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
137c141
<
---
>
163,164c167
<      height += blockArea.getHeight();
<
---
> //     height += blockArea.getHeight();
166a170,180
> //// TEST ////
>    height = blockArea.getHeight();
> //// TEST ////
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            width, blockArea.getHeight(),
>            startIndent + startOffset, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
Index: ./src/org/apache/fop/fo/flow/Block.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Block.java,v
retrieving revision 1.5
diff -r1.5 Block.java
57a58
> import org.apache.fop.datatypes.ColorType;
82a84
>     ColorType bgColor;
132a135,137
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
>
149,150c154
<   endIndent = area.getAllocationWidth() - startIndent -
<       forcedWidth;
---
>   endIndent += area.getAllocationWidth() - forcedWidth -
forcedStartOffset;
175c179
<
---
>
197a202,209
>   if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>    BackgroundColorBox bg =
>        new BackgroundColorBox(
>             blockArea.getContentWidth(), blockArea.getHeight(),
>             startIndent, endIndent,
>          this.bgColor);
>    area.addChild(bg);
>   }
206a219,226
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), blockArea.getHeight(),
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
Index: ./src/org/apache/fop/fo/flow/DisplayGraphic.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/DisplayGraphic.java,v
retrieving revision 1.5
diff -r1.5 DisplayGraphic.java
146,147c146
<   endIndent = area.getAllocationWidth() - startIndent -
<       forcedWidth;
---
>   endIndent += area.getAllocationWidth() - forcedWidth -
forcedStartOffset;
156c155
<
---
>
158c157,202
<
---
>
>  if ( img != null ) {
>   double ratio = ((double) img.getpixelwidth()) / ((double)
img.getpixelheight());
>
>   width = img.getWidth();
>   height = img.getHeight();
>
>   // FIXE-ME : not the good way...
> /*  int page_width =
this.properties.get("page-width").getLength().mvalue() -
>     this.properties.get("margin-right").getLength().mvalue() -
>     this.properties.get("margin-left").getLength().mvalue();
>   int page_height =
this.properties.get("page-height").getLength().mvalue() -
>     this.properties.get("margin-top").getLength().mvalue() -
>     this.properties.get("margin-bottom").getLength().mvalue();
>   while ( ( width > page_width ) || ( height > page_height ) ) {
>    if ( width > page_width ) {
>     width = page_width;
>     height = (int) (width / ratio);
>    }
>    if ( height > page_height ) {
>     height = page_height;
>     width = (int) (ratio * height);
>    }
>   }
> */  int area_max_width = area.getAllocationWidth();
>   int page_height =
this.properties.get("page-height").getLength().mvalue() -
>     this.properties.get("margin-top").getLength().mvalue() -
>     this.properties.get("margin-bottom").getLength().mvalue();
>   while ( ( width > area_max_width ) || ( height > page_height ) ) {
>    if ( width > area_max_width ) {
>     width = area_max_width;
>     height = (int) (((double) width) / ratio);
>    }
>    if ( height > page_height ) {
>     height = page_height;
>     width = (int) (ratio * ((double) height));
>    }
>   }
>
>   img.setDimensions(width, height);
>   // Test if enougth space
>   if ( height > area.spaceLeft() ) {
>    return AREA_FULL_NONE;
>   }
>  }
>
Index: ./src/org/apache/fop/fo/flow/DisplayRule.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/DisplayRule.java,v
retrieving revision 1.5
diff -r1.5 DisplayRule.java
117a118,133
>     if (this.isInLabel) {
>  startIndent += bodyIndent;
>  endIndent += (area.getAllocationWidth()
>         - distanceBetweenStarts - startIndent)
>      + labelSeparation;
>     }
>
>     if (this.isInListBody) {
>  startIndent += bodyIndent + distanceBetweenStarts;
>     }
>
>     if (this.isInTableCell) {
>  startIndent += forcedStartOffset;
>  endIndent += area.getAllocationWidth() - forcedWidth - forcedStartOffset;
>    }
>
Index: ./src/org/apache/fop/fo/flow/Table.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Table.java,v
retrieving revision 1.6
diff -r1.6 Table.java
57a58
> import org.apache.fop.datatypes.ColorType;
81a83
>     ColorType bgColor;
121a124,127
>
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
>
148c154
<
---
>
193a200,207
>    if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>     BackgroundColorBox bg =
>         new BackgroundColorBox(
>              blockArea.getContentWidth(), blockArea.getHeight(),
>              startIndent, endIndent,
>           this.bgColor);
>     area.addChild(bg);
>    }
201a216,223
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), blockArea.getHeight(),
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
Index: ./src/org/apache/fop/fo/flow/TableBody.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableBody.java,v
retrieving revision 1.5
diff -r1.5 TableBody.java
57a58
> import org.apache.fop.datatypes.ColorType;
79a81
>     ColorType bgColor;
121a124,125
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
160a165,172
>   if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>    BackgroundColorBox bg =
>        new BackgroundColorBox(
>             blockArea.getContentWidth(), blockArea.getHeight(),
>             startIndent, endIndent,
>          this.bgColor);
>    area.addChild(bg);
>   }
167a180,187
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), blockArea.getHeight(),
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
Index: ./src/org/apache/fop/fo/flow/TableRow.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableRow.java,v
retrieving revision 1.6
diff -r1.6 TableRow.java
57a58
> import org.apache.fop.datatypes.ColorType;
79a81
>     ColorType bgColor;
124a127,128
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
176a181,188
>   if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>    BackgroundColorBox bg =
>        new BackgroundColorBox(
>             blockArea.getContentWidth(), largestCellHeight,
>             startIndent, endIndent,
>          this.bgColor);
>    area.addChild(bg);
>   }
189a202,210
>  Vector blockAreaChildren = blockArea.getChildren();
>  int blockAreaNumChildren = blockAreaChildren.size();
>  for (int i = 0; i < blockAreaNumChildren; i++) {
>      Box box = (Box) blockAreaChildren.elementAt(i);
>      if ( box instanceof BackgroundColorBox ) {
>       ((BackgroundColorBox) box).setHeight(largestCellHeight);
>      }
>  }
>
190a212,219
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), largestCellHeight,
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
193c222
<  area.increaseHeight(largestCellHeight);
---
> // area.increaseHeight(largestCellHeight);
Index: ./src/org/apache/fop/fo/PropertyListBuilder.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/PropertyListBuilder.java,v
retrieving revision 1.5
diff -r1.5 PropertyListBuilder.java
111a112
>     propertyTable.put("background-color",BackgroundColor.maker());
122c123
<       file://System.err.println("WARNING: property " + propertyName + "
ignored");
---
>       System.err.println("WARNING: property " + propertyName + "
ignored");
Index: ./src/org/apache/fop/layout/BlockArea.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/layout/BlockArea.java,v
retrieving revision 1.5
diff -r1.5 BlockArea.java
54a55
> import org.apache.fop.datatypes.ColorType;
83c84
<
---
>
Index: ./src/org/apache/fop/layout/Makefile
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/layout/Makefile,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 Makefile
11a12
>  BackgroundColorBox.java \
Index: ./src/org/apache/fop/render/Renderer.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/render/Renderer.java,v
retrieving revision 1.5
diff -r1.5 Renderer.java
87a88,90
>     /** render the background color box */
>     public void renderBackgroundColorBox(BackgroundColorBox box);
>
Index: ./src/org/apache/fop/render/pdf/PDFRenderer.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
retrieving revision 1.5
diff -r1.5 PDFRenderer.java
59a60
> import org.apache.fop.datatypes.ColorType;
235a237
>
253a256,276
>      * render background color to PDF
>      *
>      * @param area the BackgroundColorArea to render
>      */
>     public void renderBackgroundColorBox(BackgroundColorBox box) {
>  ColorType bgColor = box.getColor();
>  int rx = this.currentAreaContainerXPosition
>      + box.getStartIndent();
>  int ry = this.currentYPosition;
>  int w = box.getWidth();
>  int h = box.getHeight();
>
>  // if not transparent
>  if ( ( bgColor.red() >= 0 ) && ( bgColor.green() >= 0 ) &&
 bgColor.blue() >= 0 ) ) {
>   addRect( rx, ry - h, w, h,
>      bgColor.red(), bgColor.green(), bgColor.blue(),
>      bgColor.red(), bgColor.green(), bgColor.blue());
>  }
>     }
>
>     /**
266c289,290
<  this.currentYPosition -= h*1000;
---
> // this.currentYPosition -= h*1000;
>  this.currentYPosition -= h;
269a294,310
>  int pw = img.getpixelwidth();
>  int ph = img.getpixelheight();
>  int[] pixels = img.getimagemap();
>
>  float rx = (x + img.getX())/1000f;
>  float ry = (y + img.getY())/1000f;
>  float rh = img.getHeight()/1000f;
>  float rw = img.getWidth()/1000f;
>
>  currentStream.add("ET\nq\n" + rw + " 0 0 " + rh + " " + rx + " " +
(ry-rh)
>      + " cm\nBI\n/W " + pw + "\n/H " + ph +
>      "\n/BPC 8\n/CS /RGB\n/F [/ASCIIHexDecode]\nID\n");
>  currentStream.addImageArray(pixels, pw, ph);
>  currentStream.add("EI\nQ\nBT\n");
>
> //// TEST ////
> /*
270a312,317
>
>  currentStream.add("ET\nq\n" + rw + " 0 0 " + rh + " " + rx + " " + (ry -
h)
>     + " cm\n/Im" + xObjectNum + " Do\nQ\nBT\n");
> */
> //// TEST ////
> /* int xObjectNum = this.pdfDoc.addImage(img);
277c324
<     }
---
> */    }
Index: ./src/codegen/properties.xml
===================================================================
RCS file: /home/cvspublic/xml-fop/src/codegen/properties.xml,v
retrieving revision 1.2
diff -r1.2 properties.xml
313a314,320
>   <property>
>     <name>background-color</name>
>     <class-name>BackgroundColor</class-name>
>     <inherited>false</inherited>
>     <datatype>ColorType</datatype>
>     <default>transparent</default>
>   </property>
Index: ./src/org/apache/fop/datatypes/ColorType.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/datatypes/ColorType.java,v
retrieving revision 1.5
diff -r1.5 ColorType.java
71a72,75
>      float transparent_red = -1;
>      float transparent_green = -1;
>      float transparent_blue = -1;
>
165a170,173
>      } else if (value.toLowerCase().equals("transparent")) {
>   this.red = transparent_red;
>   this.green = transparent_green;
>   this.blue = transparent_blue;
Index: ./src/org/apache/fop/render/xml/XMLRenderer.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/render/xml/XMLRenderer.java,v
retrieving revision 1.6
diff -r1.6 XMLRenderer.java
217a218,226
>      * render background color to XML
>      *
>      * @param area the BackgroundColorArea to render
>      */
>     public void renderBackgroundColorBox(BackgroundColorBox box) {
>      // Not yet implemented
>     }
>
>     /**

The command completed successfully.

_______________________________________

Eric SCHAEFFER
eschaeffer@posterconseil.com

POSTER CONSEIL
118 rue de Tocqueville
75017 PARIS
FRANCE
Tel. : 33-140541058
Fax : 33-140541059
_______________________________________



Re: Bug in 'layout' when in table cell - Background color property

Posted by James Tauber <jt...@jtauber.com>.
> As we are speaking of the XSL spec, I wanted to center my tables on the
page
> and I didn't find the property for doing this. I've made modifications to
do
> it with the 'text-align' property, but ....

I seem to recall this will be addressed in the next XSL spec, but I am not
sure.

James


Re: Bug in 'layout' when in table cell - Background color property

Posted by Eric SCHAEFFER <es...@posterconseil.com>.
As we are speaking of the XSL spec, I wanted to center my tables on the page
and I didn't find the property for doing this. I've made modifications to do
it with the 'text-align' property, but ....

Eric.

_______________________________________

Eric SCHAEFFER
eschaeffer@posterconseil.com

POSTER CONSEIL
118 rue de Tocqueville
75017 PARIS
FRANCE
Tel. : 33-140541058
Fax : 33-140541059
_______________________________________

----- Original Message -----
From: James Tauber <jt...@jtauber.com>
To: <fo...@xml.apache.org>
Sent: Friday, November 26, 1999 10:33 AM
Subject: Re: Bug in 'layout' when in table cell - Background color property


> > > > I've implemented the background-color property, but I had to
introduce
> a
> > > > subclass of Box to do it. It saves the background color,
startIndent,
> > > > endIndent, and the width and height of the area.
> > >
> > > I think this should be incorporated into Area rather that Box as only
> > Areas
> > > have backgrounds, not spaces (Box is the super of Area and Space).
> > >
> >
> > Ok
>
> Actually, now that I look more closely at your code I see that a
> BackgroundColorBox is in *addition* to the actual Area containing the
text.
>
> I always thought background colour should be a trait on an Area (I think
> that is more the way the XSL spec treats it).
>
> James
>
>
>
>


Re: Bug in 'layout' when in table cell - Background color property

Posted by James Tauber <jt...@jtauber.com>.
> > > I've implemented the background-color property, but I had to introduce
a
> > > subclass of Box to do it. It saves the background color, startIndent,
> > > endIndent, and the width and height of the area.
> >
> > I think this should be incorporated into Area rather that Box as only
> Areas
> > have backgrounds, not spaces (Box is the super of Area and Space).
> >
>
> Ok

Actually, now that I look more closely at your code I see that a
BackgroundColorBox is in *addition* to the actual Area containing the text.

I always thought background colour should be a trait on an Area (I think
that is more the way the XSL spec treats it).

James





Re: Bug in 'layout' when in table cell - Background color property

Posted by Eric SCHAEFFER <es...@posterconseil.com>.
Hum, difficult problem. I thought about creating the length property with a
'base' unit (as the font size, for example, for 'em' unit). Like this, we
can compute correctly the length value ('em', '%', 'auto', ...). But it's
just changing the problem : how to know the good 'base' unit to use when
creating the property...

Eric.

_______________________________________

Eric SCHAEFFER
eschaeffer@posterconseil.com

POSTER CONSEIL
118 rue de Tocqueville
75017 PARIS
FRANCE
Tel. : 33-140541058
Fax : 33-140541059
_______________________________________

----- Original Message -----
From: James Tauber <jt...@jtauber.com>
To: <fo...@xml.apache.org>
Sent: Tuesday, November 30, 1999 12:49 PM
Subject: Re: Bug in 'layout' when in table cell - Background color property


> > Yes, but if I want to have a table with two columns, each one with a
> column
> > width of 50%, and a table width of 90%, how do I calculate the computed
> > length ? Percentages are relative to the container width (area or area
> > container), and not a XSL property. I need to have access to the width
of
> > the parent area.
> >
> > Am I wrong ?
>
> No, you are correct. I thought you were talking about percentages of XSL
> properties.
>
> Percentages of area traits is more tricky. We need some way of making a
> Length express not just an absolute length but a percentage. One problem
is
> that sometimes a percentage in a length *does* mean relative to an XSL
> property (not a trait). For example, a line-height of 120% means 120% of
the
> font-size property. So it is something that is dependent on the property.
We
> need to be able to say "when column-width is a percentage, create a Length
> that isn't really a length but is a percentage that will be used to
> calculate the real value once the containing area's width is known".
>
> One possible solution, but it seems to be a hack, would be for Length to
> have a method isPercentage() that returns a boolean and a pvalue() method
> that returns the percentage. Then a special contructor is used to create a
> "percentage Length". When TableCell is laying out its child Blocks it
could
> call isPercentage() on the column-width property and if it returns true,
> pvalue() is called and multiplied by the containing area's width rather
than
> just using the mvalue().
>
> I am just thinking out loud here. I don't know if this is the best
approach.
>
> James
>


Re: Bug in 'layout' when in table cell - Background color property

Posted by Arved Sandstrom <Ar...@chebucto.ns.ca>.
On Tue, 30 Nov 1999, James Tauber wrote:

> Percentages of area traits is more tricky. We need some way of making a
> Length express not just an absolute length but a percentage. One problem is
> that sometimes a percentage in a length *does* mean relative to an XSL
> property (not a trait). For example, a line-height of 120% means 120% of the
> font-size property. So it is something that is dependent on the property. We
> need to be able to say "when column-width is a percentage, create a Length
> that isn't really a length but is a percentage that will be used to
> calculate the real value once the containing area's width is known".
> 
> One possible solution, but it seems to be a hack, would be for Length to
> have a method isPercentage() that returns a boolean and a pvalue() method
> that returns the percentage. Then a special contructor is used to create a
> "percentage Length". When TableCell is laying out its child Blocks it could
> call isPercentage() on the column-width property and if it returns true,
> pvalue() is called and multiplied by the containing area's width rather than
> just using the mvalue().
> 
> I am just thinking out loud here. I don't know if this is the best approach.
> 
Another possibility (and this is also just musing) is to realize that all
uses of lengths are to increment/decrement by them, or to scale by them,
or to get/set their value.

Percentages and absolutes behave differently when used to add/subtract or
scale, obviously.

So why not have an abstract Length, which is concretely subclassed by
AbsoluteLength and RelativeLength? Class Length has abstract methods for
scale() and incrementBy(), for example.

Then if we had two lengths, R being a percentage, and A being an absolute,
we'd be able to handle the various situations

A + B, A - B, A * B, A / B, cA, cB, c + A, c + B, etc etc

properly with the logic hidden.

Just some thoughts right off the top of my pointy head - barely thought
about the implementation. :-)

Arved



Re: Bug in 'layout' when in table cell - Background color property

Posted by James Tauber <jt...@jtauber.com>.
> Yes, but if I want to have a table with two columns, each one with a
column
> width of 50%, and a table width of 90%, how do I calculate the computed
> length ? Percentages are relative to the container width (area or area
> container), and not a XSL property. I need to have access to the width of
> the parent area.
>
> Am I wrong ?

No, you are correct. I thought you were talking about percentages of XSL
properties.

Percentages of area traits is more tricky. We need some way of making a
Length express not just an absolute length but a percentage. One problem is
that sometimes a percentage in a length *does* mean relative to an XSL
property (not a trait). For example, a line-height of 120% means 120% of the
font-size property. So it is something that is dependent on the property. We
need to be able to say "when column-width is a percentage, create a Length
that isn't really a length but is a percentage that will be used to
calculate the real value once the containing area's width is known".

One possible solution, but it seems to be a hack, would be for Length to
have a method isPercentage() that returns a boolean and a pvalue() method
that returns the percentage. Then a special contructor is used to create a
"percentage Length". When TableCell is laying out its child Blocks it could
call isPercentage() on the column-width property and if it returns true,
pvalue() is called and multiplied by the containing area's width rather than
just using the mvalue().

I am just thinking out loud here. I don't know if this is the best approach.

James


Re: Bug in 'layout' when in table cell - Background color property

Posted by Eric SCHAEFFER <es...@posterconseil.com>.
----- Original Message -----
From: James Tauber <jt...@jtauber.com>
To: <fo...@xml.apache.org>
Sent: Saturday, November 27, 1999 9:51 AM
Subject: Re: Bug in 'layout' when in table cell - Background color property


> > - the property modele should be updated. The spec introduces the notion
of
> > specified value, computed value and actual value (only the computed
value
> is
> > inherited). The problem is that we can't compute secified values when
they
> > are relative to the parent fo properties (like percent for example)
> because
> > the property doesn't have access to the fo it belongs.
>
> It should have access to what it needs. A property has access to all other
> properties on that FO as well as all the properties of the parent. That is
> enough, right?
>
> Look at text-align-last and line-height, both of which are, in certains
> cases, derived from another property.
>
> James
>
>

Yes, but if I want to have a table with two columns, each one with a column
width of 50%, and a table width of 90%, how do I calculate the computed
length ? Percentages are relative to the container width (area or area
container), and not a XSL property. I need to have access to the width of
the parent area.

Am I wrong ?

Eric.

_______________________________________

Eric SCHAEFFER
eschaeffer@posterconseil.com

POSTER CONSEIL
118 rue de Tocqueville
75017 PARIS
FRANCE
Tel. : 33-140541058
Fax : 33-140541059
_______________________________________



Re: Bug in 'layout' when in table cell - Background color property

Posted by James Tauber <jt...@jtauber.com>.
> - the property modele should be updated. The spec introduces the notion of
> specified value, computed value and actual value (only the computed value
is
> inherited). The problem is that we can't compute secified values when they
> are relative to the parent fo properties (like percent for example)
because
> the property doesn't have access to the fo it belongs.

It should have access to what it needs. A property has access to all other
properties on that FO as well as all the properties of the parent. That is
enough, right?

Look at text-align-last and line-height, both of which are, in certains
cases, derived from another property.

James



Re: Bug in 'layout' when in table cell - Background color property

Posted by Eric SCHAEFFER <es...@posterconseil.com>.
----- Original Message -----
From: James Tauber <jt...@jtauber.com>
To: <fo...@xml.apache.org>
Sent: Friday, November 26, 1999 9:18 AM
Subject: Re: Bug in 'layout' when in table cell - Background color property


> > I've implemented the background-color property, but I had to introduce a
> > subclass of Box to do it. It saves the background color, startIndent,
> > endIndent, and the width and height of the area.
>
> I think this should be incorporated into Area rather that Box as only
Areas
> have backgrounds, not spaces (Box is the super of Area and Space).
>

Ok

> > When rendering, it draws a
> > filled rectangle before rendering the others area.
> > The problem is that, for tables (Table, TableBody, TableRow, TableCell),
> the
> > width or height of the area aren't always good and I had to calculate
them
> > differently.
> > I don't know how to correct this. If someone has an idea...
>
> Tables were very much a hack when I did them. They need cleaning up.
>
> We can discuss this more.
>
> In particular, I'd like to remove references to lists and tables in Area
and
> instead introduce general notions of modifications to indent.
>
> James
>

Yep, I think it will be good too. I've read again the XSL spec, and thought
about two things :

- the property modele should be updated. The spec introduces the notion of
specified value, computed value and actual value (only the computed value is
inherited). The problem is that we can't compute secified values when they
are relative to the parent fo properties (like percent for example) because
the property doesn't have access to the fo it belongs.

- The other problem (I think, but I'm not sure) is that the area's size
properties aren't always set (area container for example :
contentRectangleWidth ?) and it can raise problems when comupting children
areas' size or xOffset.

The way startIndent and endIndent is used cause me problems too (pb with
inheritence, specified values, tables or lists). I wonder if it's the good
way, but I don't understand the XSL spec enougth to tell you what to do ...
(I'm a bit lost, specially with block areas -> line areas -> text, and have
to make things work before y2k).

Eric.

_______________________________________

Eric SCHAEFFER
eschaeffer@posterconseil.com

POSTER CONSEIL
118 rue de Tocqueville
75017 PARIS
FRANCE
Tel. : 33-140541058
Fax : 33-140541059
_______________________________________



Re: Bug in 'layout' when in table cell - Background color property

Posted by James Tauber <jt...@jtauber.com>.
> I've implemented the background-color property, but I had to introduce a
> subclass of Box to do it. It saves the background color, startIndent,
> endIndent, and the width and height of the area.

I think this should be incorporated into Area rather that Box as only Areas
have backgrounds, not spaces (Box is the super of Area and Space).

> When rendering, it draws a
> filled rectangle before rendering the others area.
> The problem is that, for tables (Table, TableBody, TableRow, TableCell),
the
> width or height of the area aren't always good and I had to calculate them
> differently.
> I don't know how to correct this. If someone has an idea...

Tables were very much a hack when I did them. They need cleaning up.

We can discuss this more.

In particular, I'd like to remove references to lists and tables in Area and
instead introduce general notions of modifications to indent.

James


Re: Bug in 'layout' when in table cell - Background color property

Posted by Eric SCHAEFFER <es...@posterconseil.com>.
Youps. I've made this change everywhere but didn't select the files when
generating the diff....

(there's also other modifications...)

Index: ./src/org/apache/fop/fo/flow/Block.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Block.java,v
retrieving revision 1.5
diff -r1.5 Block.java
57a58
> import org.apache.fop.datatypes.ColorType;
82a84
>     ColorType bgColor;
132a135,137
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
>
149,150c154
<   endIndent = area.getAllocationWidth() - startIndent -
<       forcedWidth;
---
>   endIndent += area.getAllocationWidth() - forcedWidth -
forcedStartOffset;
175c179
<
---
>
197a202,209
>   if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>    BackgroundColorBox bg =
>        new BackgroundColorBox(
>             blockArea.getContentWidth(), blockArea.getHeight(),
>             startIndent, endIndent,
>          this.bgColor);
>    area.addChild(bg);
>   }
206a219,226
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), blockArea.getHeight(),
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
Index: ./src/org/apache/fop/fo/flow/DisplayGraphic.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/DisplayGraphic.java,v
retrieving revision 1.5
diff -r1.5 DisplayGraphic.java
146,147c146
<   endIndent = area.getAllocationWidth() - startIndent -
<       forcedWidth;
---
>   endIndent += area.getAllocationWidth() - forcedWidth -
forcedStartOffset;
156c155
<
---
>
158c157,202
<
---
>
>  if ( img != null ) {
>   double ratio = ((double) img.getpixelwidth()) / ((double)
img.getpixelheight());
>
>   width = img.getWidth();
>   height = img.getHeight();
>
>   // FIXE-ME : not the good way...
> /*  int page_width =
this.properties.get("page-width").getLength().mvalue() -
>     this.properties.get("margin-right").getLength().mvalue() -
>     this.properties.get("margin-left").getLength().mvalue();
>   int page_height =
this.properties.get("page-height").getLength().mvalue() -
>     this.properties.get("margin-top").getLength().mvalue() -
>     this.properties.get("margin-bottom").getLength().mvalue();
>   while ( ( width > page_width ) || ( height > page_height ) ) {
>    if ( width > page_width ) {
>     width = page_width;
>     height = (int) (width / ratio);
>    }
>    if ( height > page_height ) {
>     height = page_height;
>     width = (int) (ratio * height);
>    }
>   }
> */  int area_max_width = area.getAllocationWidth();
>   int page_height =
this.properties.get("page-height").getLength().mvalue() -
>     this.properties.get("margin-top").getLength().mvalue() -
>     this.properties.get("margin-bottom").getLength().mvalue();
>   while ( ( width > area_max_width ) || ( height > page_height ) ) {
>    if ( width > area_max_width ) {
>     width = area_max_width;
>     height = (int) (((double) width) / ratio);
>    }
>    if ( height > page_height ) {
>     height = page_height;
>     width = (int) (ratio * ((double) height));
>    }
>   }
>
>   img.setDimensions(width, height);
>   // Test if enougth space
>   if ( height > area.spaceLeft() ) {
>    return AREA_FULL_NONE;
>   }
>  }
>
Index: ./src/org/apache/fop/fo/flow/DisplayRule.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/DisplayRule.java,v
retrieving revision 1.5
diff -r1.5 DisplayRule.java
117a118,133
>     if (this.isInLabel) {
>  startIndent += bodyIndent;
>  endIndent += (area.getAllocationWidth()
>         - distanceBetweenStarts - startIndent)
>      + labelSeparation;
>     }
>
>     if (this.isInListBody) {
>  startIndent += bodyIndent + distanceBetweenStarts;
>     }
>
>     if (this.isInTableCell) {
>  startIndent += forcedStartOffset;
>  endIndent += area.getAllocationWidth() - forcedWidth - forcedStartOffset;
>    }
>
Index: ./src/org/apache/fop/fo/flow/Makefile
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Makefile,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 Makefile
15a16
>  ListItem.java \
Index: ./src/org/apache/fop/fo/flow/Table.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Table.java,v
retrieving revision 1.6
diff -r1.6 Table.java
57a58
> import org.apache.fop.datatypes.ColorType;
81a83,84
>     ColorType bgColor;
>     int align;
121a125,130
>
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
>    this.align =
>   this.properties.get("text-align").getEnum();
>
147a157,184
>
>  // added by Eric Shaeffer
>  currentColumnNumber = 0;
>
>  int numChildren = this.children.size();
>  int totalWidth = 0;
>
>  for (int i = this.marker; i < numChildren; i++) {
>   FONode fo = (FONode) children.elementAt(i);
>   if (fo instanceof TableColumn) {
>    TableColumn c = (TableColumn) fo;
>    int num = c.getColumnNumber();
>    if (num == 0) {
>     num = currentColumnNumber + 1;
>    }
>    currentColumnNumber = num;
>    if (num > columns.size()) {
>     columns.setSize(num);
>    }
>    columns.setElementAt(c, num-1);
>    totalWidth += c.getColumnWidth();
>   } else if (fo instanceof TableBody) {
>    if (columns.size() == 0) {
>     System.err.println("WARNING: current implementation of tables requires
a table-column for each column, indicating column-width");
>     return OK;
>    }
>   }
>  }
148a186,212
> // FIXE ME : pb allocationWidth, contentRectangleWidth, startIndent,
endIndent
>  int padding = 0;
>  int initialStartOffset = 0;
>  switch (this.align) {
>   case TextAlign.START: // left
>    padding = area.getContentWidth() - totalWidth;
>    initialStartOffset = 0;
>    endIndent += padding;
>    break;
>   case TextAlign.END: // right
>    padding = area.getContentWidth() - totalWidth;
>    initialStartOffset = padding;
>    startIndent += padding;
>    break;
>   case TextAlign.CENTERED: // center
>    padding = (int)( ( (double) (area.getContentWidth() - totalWidth) ) /
2.0 );
>    initialStartOffset = padding;
>    startIndent += padding;
>    endIndent += padding;
>    break;
>   case TextAlign.JUSTIFIED: // justify
>    padding = area.getContentWidth() - totalWidth;
>    initialStartOffset = 0;
>    endIndent += padding;
>    break;
>  }
>
156,159d219
<  // added by Eric Shaeffer
<  currentColumnNumber = 0;
<
<  int numChildren = this.children.size();
162c222
<      if (fo instanceof TableColumn) {
---
> /*     if (fo instanceof TableColumn) {
178c238
<
---
> */
184a245
>      if (fo instanceof TableBody) {
186a248,249
>   ((TableBody) fo).setInitialStartOffset(initialStartOffset);
>
193a257,264
>    if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>     BackgroundColorBox bg =
>         new BackgroundColorBox(
>              blockArea.getContentWidth(), blockArea.getHeight(),
>              startIndent, endIndent,
>           this.bgColor);
>     area.addChild(bg);
>    }
201a273,280
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), blockArea.getHeight(),
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
Index: ./src/org/apache/fop/fo/flow/TableBody.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableBody.java,v
retrieving revision 1.5
diff -r1.5 TableBody.java
57a58
> import org.apache.fop.datatypes.ColorType;
79a81,82
>     ColorType bgColor;
>     int initialStartOffset = 0;
121a125,126
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
152a158
>      row.setInitialStartOffset(this.initialStartOffset);
160a167,174
>   if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>    BackgroundColorBox bg =
>        new BackgroundColorBox(
>             blockArea.getContentWidth(), blockArea.getHeight(),
>             startIndent, endIndent,
>          this.bgColor);
>    area.addChild(bg);
>   }
167a182,189
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), blockArea.getHeight(),
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
185a208,211
>     }
>
>     public void setInitialStartOffset(int offset) {
>  this.initialStartOffset = offset;
Index: ./src/org/apache/fop/fo/flow/TableCell.java
===================================================================
RCS file:
/home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableCell.java,v
retrieving revision 1.6
diff -r1.6 TableCell.java
57a58
> import org.apache.fop.datatypes.ColorType;
76a78
>     ColorType bgColor;
124a127,128
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
137c141
<
---
>
163,164c167
<      height += blockArea.getHeight();
<
---
> //     height += blockArea.getHeight();
166a170,180
> //// TEST ////
>    height = blockArea.getHeight();
> //// TEST ////
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            width, blockArea.getHeight(),
>            startIndent + startOffset, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
Index: ./src/org/apache/fop/fo/flow/TableRow.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableRow.java,v
retrieving revision 1.6
diff -r1.6 TableRow.java
57a58
> import org.apache.fop.datatypes.ColorType;
79a81
>     ColorType bgColor;
80a83
>     int initialStartOffset = 0;
124a128,129
>      this.bgColor =
>   this.properties.get("background-color").getColorType();
140,141c145,147
<      area.spaceLeft(), startIndent, endIndent, 0,
<      0, 0, 0);
---
>      area.spaceLeft(), startIndent, endIndent,
>      0, 0, 0,
>      0);
152c158
<  widthOfCellsSoFar = 0;
---
>  widthOfCellsSoFar = initialStartOffset;
176a183,190
>   if ( ( status != AREA_FULL_NONE ) && ( this.bgColor.red() >= 0 ) &&
 this.bgColor.green() >= 0 ) && ( this.bgColor.blue() >= 0 ) ) {
>    BackgroundColorBox bg =
>        new BackgroundColorBox(
>             blockArea.getContentWidth(), largestCellHeight,
>             startIndent, endIndent,
>          this.bgColor);
>    area.addChild(bg);
>   }
189a204,212
>  Vector blockAreaChildren = blockArea.getChildren();
>  int blockAreaNumChildren = blockAreaChildren.size();
>  for (int i = 0; i < blockAreaNumChildren; i++) {
>      Box box = (Box) blockAreaChildren.elementAt(i);
>      if ( box instanceof BackgroundColorBox ) {
>       ((BackgroundColorBox) box).setHeight(largestCellHeight);
>      }
>  }
>
190a214,221
>  if ( ( this.bgColor.red() >= 0 ) && ( this.bgColor.green() >= 0 ) &&
 this.bgColor.blue() >= 0 ) ) {
>   BackgroundColorBox bg =
>       new BackgroundColorBox(
>            blockArea.getContentWidth(), largestCellHeight,
>            startIndent, endIndent,
>         this.bgColor);
>   area.addChild(bg);
>  }
193c224
<  area.increaseHeight(largestCellHeight);
---
> // area.increaseHeight(largestCellHeight);
207a239,242
>     }
>
>     public void setInitialStartOffset(int offset) {
>  this.initialStartOffset = offset;

The command completed successfully.



_______________________________________

Eric SCHAEFFER
eschaeffer@posterconseil.com

POSTER CONSEIL
118 rue de Tocqueville
75017 PARIS
FRANCE
Tel. : 33-140541058
Fax : 33-140541059
_______________________________________

----- Original Message -----
From: James Tauber <jt...@jtauber.com>
To: <fo...@xml.apache.org>
Sent: Friday, November 26, 1999 9:56 AM
Subject: Re: Bug in 'layout' when in table cell - Background color property


> > I found a bug in the layout function, 'endIndent' should be calculated
> like
> > this :
> >
> >      if (this.isInTableCell) {
> >   startIndent += forcedStartOffset;
> >   endIndent += area.getAllocationWidth() - forcedWidth -
> forcedStartOffset;
> >      }
>
> In the diffs you sent (which I am working through now) this change is only
> made in DisplayRule.java. Does it need to be made anywhere else?
>
> James
>


Re: Bug in 'layout' when in table cell - Background color property

Posted by James Tauber <jt...@jtauber.com>.
> I found a bug in the layout function, 'endIndent' should be calculated
like
> this :
>
>      if (this.isInTableCell) {
>   startIndent += forcedStartOffset;
>   endIndent += area.getAllocationWidth() - forcedWidth -
forcedStartOffset;
>      }

In the diffs you sent (which I am working through now) this change is only
made in DisplayRule.java. Does it need to be made anywhere else?

James