浏览代码

added support for background-color


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193248 13f79535-47bb-0310-9956-ffa450edef68
pull/42/head
jtauber 24 年前
父节点
当前提交
02d4084ce4

+ 2
- 1
STATUS 查看文件

@@ -12,7 +12,8 @@ Get images working
[DONE]Incorporate Eric Schaeffer's fix to tables in static-content
[DONE] Incorporate Kelly Campell's fixes to GifJpegImage
[PARTIAL] Incorporate Eric Schaeffer's further table fixes
Incorporate Eric Schaeffer's background colour implementation
[DONE] Incorporate Eric Schaeffer's background colour implementation
(actually used different approach with background colour as trait)

Other Bugs to fix:


+ 7
- 0
src/codegen/properties.xml 查看文件

@@ -323,5 +323,12 @@
</datatype>
<default>false</default>
</property>
<property>
<name>background-color</name>
<class-name>BackgroundColor</class-name>
<inherited>false</inherited>
<datatype>ColorType</datatype>
<default>transparent</default>
</property>
</property-list>


+ 13
- 1
src/org/apache/fop/datatypes/ColorType.java 查看文件

@@ -22,7 +22,7 @@
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Fop" and "Apache Software Foundation" must not be used to
4. The names "FOP" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
@@ -64,6 +64,9 @@ public class ColorType {
/** the blue component */
protected float blue;

/** the alpha component */
protected float alpha = 0;

/**
* set the colour given a particular String specifying either a
* colour name or #RGB or #RRGGBB
@@ -163,6 +166,11 @@ public class ColorType {
this.red = 0.7f;
this.green = 0.5f;
this.blue = 0;
} else if (value.toLowerCase().equals("transparent")) {
this.red = 0;
this.green = 0;
this.blue = 0;
this.alpha = 1;
} else {
this.red = 0;
this.green = 0;
@@ -183,4 +191,8 @@ public class ColorType {
public float red() {
return this.red;
}

public float alpha() {
return this.alpha;
}
}

+ 1
- 0
src/org/apache/fop/fo/PropertyListBuilder.java 查看文件

@@ -104,6 +104,7 @@ public class PropertyListBuilder {
propertyTable.put("href",HRef.maker());
propertyTable.put("column-width",ColumnWidth.maker());
propertyTable.put("keep-with-next",KeepWithNext.maker());
propertyTable.put("background-color",BackgroundColor.maker());

propertyTable.put("height",SVGLength.maker());
propertyTable.put("width",SVGLength.maker());

+ 7
- 2
src/org/apache/fop/fo/flow/Block.java 查看文件

@@ -55,6 +55,7 @@ package org.apache.fop.fo.flow;
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.*;
import org.apache.fop.datatypes.*;
import org.apache.fop.apps.FOPException;

public class Block extends FObjMixed {
@@ -82,6 +83,7 @@ public class Block extends FObjMixed {
int spaceAfter;
int textIndent;
int keepWithNext;
ColorType backgroundColor;

BlockArea blockArea;

@@ -133,6 +135,8 @@ public class Block extends FObjMixed {
this.properties.get("text-indent").getLength().mvalue();
this.keepWithNext =
this.properties.get("keep-with-next").getEnum();
this.backgroundColor =
this.properties.get("background-color").getColorType();

if (area instanceof BlockArea) {
area.end();
@@ -150,8 +154,8 @@ public class Block extends FObjMixed {

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

this.marker = 0;
@@ -182,6 +186,7 @@ public class Block extends FObjMixed {
area.spaceLeft(), startIndent, endIndent,
textIndent, align, alignLast, lineHeight);
blockArea.setPage(area.getPage());
blockArea.setBackgroundColor(backgroundColor);
blockArea.start();

int numChildren = this.children.size();

+ 2
- 2
src/org/apache/fop/fo/flow/DisplayGraphic.java 查看文件

@@ -144,8 +144,8 @@ public class DisplayGraphic extends FObj {

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

this.marker = 0;

+ 17
- 0
src/org/apache/fop/fo/flow/DisplayRule.java 查看文件

@@ -115,6 +115,23 @@ public class DisplayRule extends FObj {
area.addDisplaySpace(spaceBefore);
}

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;
}

RuleArea ruleArea = new RuleArea(fs,
area.getAllocationWidth(),
area.spaceLeft(),

+ 6
- 0
src/org/apache/fop/fo/flow/Table.java 查看文件

@@ -55,6 +55,7 @@ package org.apache.fop.fo.flow;
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.*;
import org.apache.fop.datatypes.*;
import org.apache.fop.apps.FOPException;

// Java
@@ -80,6 +81,7 @@ public class Table extends FObj {
int endIndent;
int spaceBefore;
int spaceAfter;
ColorType backgroundColor;

Vector columns = new Vector();
int currentColumnNumber = 0;
@@ -120,6 +122,9 @@ public class Table extends FObj {
this.properties.get("space-before.optimum").getLength().mvalue();
this.spaceAfter =
this.properties.get("space-after.optimum").getLength().mvalue();
this.backgroundColor =
this.properties.get("background-color").getColorType();

if (area instanceof BlockArea) {
area.end();
}
@@ -152,6 +157,7 @@ public class Table extends FObj {
area.spaceLeft(), startIndent, endIndent, 0,
0, 0, 0);
blockArea.setPage(area.getPage());
blockArea.setBackgroundColor(backgroundColor);
blockArea.start();

// added by Eric Schaeffer

+ 6
- 0
src/org/apache/fop/fo/flow/TableBody.java 查看文件

@@ -54,6 +54,7 @@ package org.apache.fop.fo.flow;
// FOP
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.datatypes.*;
import org.apache.fop.layout.*;
import org.apache.fop.apps.FOPException;

@@ -78,6 +79,7 @@ public class TableBody extends FObj {
int endIndent;
int spaceBefore;
int spaceAfter;
ColorType backgroundColor;

Vector columns;

@@ -117,6 +119,9 @@ public class TableBody extends FObj {
this.properties.get("space-before.optimum").getLength().mvalue();
this.spaceAfter =
this.properties.get("space-after.optimum").getLength().mvalue();
this.backgroundColor =
this.properties.get("background-color").getColorType();

if (area instanceof BlockArea) {
area.end();
}
@@ -138,6 +143,7 @@ public class TableBody extends FObj {
area.spaceLeft(), startIndent, endIndent, 0,
0, 0, 0);
blockArea.setPage(area.getPage());
blockArea.setBackgroundColor(backgroundColor);
blockArea.start();

int numChildren = this.children.size();

+ 6
- 0
src/org/apache/fop/fo/flow/TableCell.java 查看文件

@@ -55,6 +55,7 @@ import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.*;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.*;

public class TableCell extends FObj {

@@ -74,6 +75,7 @@ public class TableCell extends FObj {
int endIndent;
int spaceBefore;
int spaceAfter;
ColorType backgroundColor;

protected int startOffset;
protected int width;
@@ -119,6 +121,9 @@ public class TableCell extends FObj {
this.properties.get("space-before.optimum").getLength().mvalue();
this.spaceAfter =
this.properties.get("space-after.optimum").getLength().mvalue();
this.backgroundColor =
this.properties.get("background-color").getColorType();

if (area instanceof BlockArea) {
area.end();
}
@@ -140,6 +145,7 @@ public class TableCell extends FObj {
area.spaceLeft(), startIndent, endIndent, 0,
0, 0, 0);
blockArea.setPage(area.getPage());
blockArea.setBackgroundColor(backgroundColor);
blockArea.start();

// added by Eric Schaeffer

+ 6
- 0
src/org/apache/fop/fo/flow/TableRow.java 查看文件

@@ -54,6 +54,7 @@ package org.apache.fop.fo.flow;
// FOP
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.datatypes.*;
import org.apache.fop.layout.*;
import org.apache.fop.apps.FOPException;

@@ -78,6 +79,7 @@ public class TableRow extends FObj {
int endIndent;
int spaceBefore;
int spaceAfter;
ColorType backgroundColor;

int widthOfCellsSoFar = 0;
int largestCellHeight = 0;
@@ -120,6 +122,9 @@ public class TableRow extends FObj {
this.properties.get("space-before.optimum").getLength().mvalue();
this.spaceAfter =
this.properties.get("space-after.optimum").getLength().mvalue();
this.backgroundColor =
this.properties.get("background-color").getColorType();

if (area instanceof BlockArea) {
area.end();
}
@@ -141,6 +146,7 @@ public class TableRow extends FObj {
area.spaceLeft(), startIndent, endIndent, 0,
0, 0, 0);
blockArea.setPage(area.getPage());
blockArea.setBackgroundColor(backgroundColor);
blockArea.start();

int numChildren = this.children.size();

+ 13
- 0
src/org/apache/fop/layout/Area.java 查看文件

@@ -51,6 +51,9 @@

package org.apache.fop.layout;

// FOP
import org.apache.fop.datatypes.*;

// Java
import java.util.Vector;

@@ -77,6 +80,8 @@ abstract public class Area extends Box {
/* the page this area is on */
protected Page page;

protected ColorType backgroundColor;

public Area (FontState fontState) {
this.fontState = fontState;
}
@@ -137,6 +142,10 @@ abstract public class Area extends Box {
return this.page;
}

public ColorType getBackgroundColor() {
return this.backgroundColor;
}

public void increaseHeight(int amount) {
this.currentHeight += amount;
}
@@ -154,6 +163,10 @@ abstract public class Area extends Box {
this.page = page;
}

public void setBackgroundColor(ColorType bgColor) {
this.backgroundColor = bgColor;
}

public int spaceLeft() {
return maxHeight - currentHeight;
}

+ 11
- 2
src/org/apache/fop/render/pdf/PDFRenderer.java 查看文件

@@ -22,7 +22,7 @@
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Fop" and "Apache Software Foundation" must not be used to
4. The names "FOP" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
@@ -48,6 +48,7 @@
Software Foundation, please see <http://www.apache.org/>.
*/

package org.apache.fop.render.pdf;

// FOP
@@ -55,6 +56,7 @@ import org.apache.fop.render.Renderer;
import org.apache.fop.image.ImageArea;
import org.apache.fop.image.FopImage;
import org.apache.fop.layout.*;
import org.apache.fop.datatypes.*;
import org.apache.fop.svg.*;
import org.apache.fop.pdf.*;

@@ -123,7 +125,8 @@ public class PDFRenderer implements Renderer {
* @param areaTree the laid-out area tree
* @param writer the PrintWriter to write the PDF with
*/
public void render(AreaTree areaTree, PrintWriter writer) throws IOException {
public void render(AreaTree areaTree, PrintWriter writer)
throws IOException {
System.err.println("rendering areas to PDF");
this.pdfResources = this.pdfDoc.getResources();
Enumeration e = areaTree.getPages().elements();
@@ -233,6 +236,12 @@ public class PDFRenderer implements Renderer {
int ry = this.currentYPosition;
int w = area.getContentWidth();
int h = area.getHeight();
ColorType bg = area.getBackgroundColor();
if (bg.alpha() == 0) {
this.addRect(rx, ry, w, -h,
bg.red(), bg.green(), bg.blue(),
bg.red(), bg.green(), bg.blue());
}
Enumeration e = area.getChildren().elements();
while (e.hasMoreElements()) {
Box b = (Box) e.nextElement();

正在加载...
取消
保存