Browse Source

Had to introduce "clip-rect" to handle clipping on background images, leader etc. A full viewport is probably too heavy-weight here. This is to be considered temporary pending verification with SVG and PCL implementations.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@686253 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_0
Jeremias Maerki 16 years ago
parent
commit
bacc153b5d

+ 1
- 0
src/java/org/apache/fop/render/intermediate/IFConstants.java View File

@@ -44,6 +44,7 @@ public interface IFConstants extends XMLConstants {
String EL_VIEWPORT = "viewport";
String EL_GROUP = "g";
String EL_IMAGE = "image";
String EL_CLIP_RECT = "clip-rect";
String EL_RECT = "rect";
String EL_BORDER_RECT = "border-rect";
String EL_FONT = "font";

+ 6
- 0
src/java/org/apache/fop/render/intermediate/IFGraphicContext.java View File

@@ -31,6 +31,8 @@ import org.apache.xmlgraphics.java2d.GraphicContext;
*/
public class IFGraphicContext extends GraphicContext {

private static final AffineTransform[] EMPTY_TRANSFORM_ARRAY = new AffineTransform[0];

private List groupList = new java.util.ArrayList();

/**
@@ -88,6 +90,10 @@ public class IFGraphicContext extends GraphicContext {
this(new AffineTransform[] {transform});
}

public Group() {
this(EMPTY_TRANSFORM_ARRAY);
}

public AffineTransform[] getTransforms() {
return this.transforms;
}

+ 8
- 0
src/java/org/apache/fop/render/intermediate/IFPainter.java View File

@@ -268,6 +268,14 @@ public interface IFPainter {
*/
void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException;

/**
* Restricts the current clipping region with the given rectangle.
* @param rect the rectangle's coordinates and extent
* @throws IFException if an error occurs while handling this event
*/
void clipRect(Rectangle rect) throws IFException;
//TODO clipRect() shall be considered temporary until verified with SVG and PCL

/**
* Draws a rectangle. Either fill or stroke has to be specified.
* @param rect the rectangle's coordinates and extent

+ 13
- 0
src/java/org/apache/fop/render/intermediate/IFParser.java View File

@@ -136,6 +136,7 @@ public class IFParser implements IFConstants {
elementHandlers.put(EL_GROUP, new GroupHandler());
elementHandlers.put(EL_FONT, new FontHandler());
elementHandlers.put(EL_TEXT, new TextHandler());
elementHandlers.put(EL_CLIP_RECT, new ClipRectHandler());
elementHandlers.put(EL_RECT, new RectHandler());
elementHandlers.put(EL_BORDER_RECT, new BorderRectHandler());
elementHandlers.put(EL_IMAGE, new ImageHandler());
@@ -441,6 +442,18 @@ public class IFParser implements IFConstants {

}

private class ClipRectHandler extends AbstractElementHandler {

public void startElement(Attributes attributes) throws IFException {
int x = Integer.parseInt(attributes.getValue("x"));
int y = Integer.parseInt(attributes.getValue("y"));
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
painter.clipRect(new Rectangle(x, y, width, height));
}

}

private class RectHandler extends AbstractElementHandler {

public void startElement(Attributes attributes) throws IFException {

+ 15
- 15
src/java/org/apache/fop/render/intermediate/IFRenderer.java View File

@@ -584,12 +584,12 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
protected void concatenateTransformationMatrix(AffineTransform at) {
if (!at.isIdentity()) {
concatenateTransformationMatrixMpt(ptToMpt(at));
concatenateTransformationMatrixMpt(ptToMpt(at), false);
}
}

private void concatenateTransformationMatrixMpt(AffineTransform at) {
if (!at.isIdentity()) {
private void concatenateTransformationMatrixMpt(AffineTransform at, boolean force) {
if (force || !at.isIdentity()) {
if (log.isTraceEnabled()) {
log.trace("-----concatenateTransformationMatrix: " + at);
}
@@ -659,7 +659,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {

saveGraphicsState();
//Viewport position
concatenateTransformationMatrixMpt(positionTransform);
concatenateTransformationMatrixMpt(positionTransform, false);

//Background and borders
float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd());
@@ -670,7 +670,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
//Shift to content rectangle after border painting
AffineTransform contentRectTransform = new AffineTransform();
contentRectTransform.translate(borderPaddingStart, borderPaddingBefore);
concatenateTransformationMatrixMpt(contentRectTransform);
concatenateTransformationMatrixMpt(contentRectTransform, false);

//Clipping
Rectangle clipRect = null;
@@ -994,20 +994,22 @@ public class IFRenderer extends AbstractPathOrientedRenderer {

/** {@inheritDoc} */
protected void clip() {
// TODO Auto-generated method stub
log.warn("clip() NYI");
throw new IllegalStateException("Not used");
}

/** {@inheritDoc} */
protected void clipRect(float x, float y, float width, float height) {
// TODO Auto-generated method stub
log.warn("clipRect() NYI");
pushGroup(new IFGraphicContext.Group());
try {
painter.clipRect(toMillipointRectangle(x, y, width, height));
} catch (IFException ife) {
handleIFException(ife);
}
}

/** {@inheritDoc} */
protected void closePath() {
// TODO Auto-generated method stub
log.warn("closePath() NYI");
throw new IllegalStateException("Not used");
}

/** {@inheritDoc} */
@@ -1056,14 +1058,12 @@ public class IFRenderer extends AbstractPathOrientedRenderer {

/** {@inheritDoc} */
protected void moveTo(float x, float y) {
// TODO Auto-generated method stub
log.warn("moveTo() NYI");
throw new IllegalStateException("Not used");
}

/** {@inheritDoc} */
protected void lineTo(float x, float y) {
// TODO Auto-generated method stub
log.warn("lineTo() NYI");
throw new IllegalStateException("Not used");
}

/** {@inheritDoc} */

+ 14
- 0
src/java/org/apache/fop/render/intermediate/IFSerializer.java View File

@@ -349,6 +349,20 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst
}
}

/** {@inheritDoc} */
public void clipRect(Rectangle rect) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
addAttribute(atts, "x", Integer.toString(rect.x));
addAttribute(atts, "y", Integer.toString(rect.y));
addAttribute(atts, "width", Integer.toString(rect.width));
addAttribute(atts, "height", Integer.toString(rect.height));
element(EL_CLIP_RECT, atts);
} catch (SAXException e) {
throw new IFException("SAX error in clipRect()", e);
}
}

/** {@inheritDoc} */
public void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException {
if (fill == null && stroke == null) {

+ 18
- 9
src/java/org/apache/fop/render/pdf/PDFPainter.java View File

@@ -241,12 +241,7 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
generator.saveGraphicsState();
generator.concatenate(generator.toPoints(transform));
if (clipRect != null) {
StringBuffer sb = new StringBuffer();
sb.append(format(clipRect.x)).append(' ');
sb.append(format(clipRect.y)).append(' ');
sb.append(format(clipRect.width)).append(' ');
sb.append(format(clipRect.height)).append(" re W n\n");
generator.add(sb.toString());
clipRect(clipRect);
}
}

@@ -329,6 +324,17 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
return PDFNumber.doubleOut(value / 1000f);
}

/** {@inheritDoc} */
public void clipRect(Rectangle rect) throws IFException {
generator.endTextObject();
StringBuffer sb = new StringBuffer();
sb.append(format(rect.x)).append(' ');
sb.append(format(rect.y)).append(' ');
sb.append(format(rect.width)).append(' ');
sb.append(format(rect.height)).append(" re W n\n");
generator.add(sb.toString());
}

/** {@inheritDoc} */
public void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException {
if (fill == null && stroke == null) {
@@ -365,8 +371,10 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
/** {@inheritDoc} */
public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
BorderProps start, BorderProps end) throws IFException {
generator.endTextObject();
this.borderPainter.drawBorders(rect, before, after, start, end);
if (before != null || after != null || start != null || end != null) {
generator.endTextObject();
this.borderPainter.drawBorders(rect, before, after, start, end);
}
}

private Typeface getTypeface(String fontName) {
@@ -387,6 +395,7 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
FontTriplet triplet = new FontTriplet(
state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
//TODO Ignored: state.getFontVariant()
//TODO Opportunity for font caching if font state is more heavily used
String fontKey = fontInfo.getInternalFontKey(triplet);
int sizeMillipoints = state.getFontSize();
float fontSize = sizeMillipoints / 1000f;
@@ -431,7 +440,7 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
if (CharUtilities.isFixedWidthSpace(orgChar)) {
//Fixed width space are rendered as spaces so copy/paste works in a reader
ch = font.mapChar(CharUtilities.SPACE);
glyphAdjust = font.getCharWidth(ch) - font.getCharWidth(orgChar);
glyphAdjust = -(font.getCharWidth(ch) - font.getCharWidth(orgChar));
} else {
ch = font.mapChar(orgChar);
}

+ 5
- 0
src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java View File

@@ -278,6 +278,11 @@ public abstract class AbstractSVGPainter extends AbstractXMLWritingIFPainter
}
}

/** {@inheritDoc} */
public void clipRect(Rectangle rect) throws IFException {
//TODO Implement me!!!
}

/** {@inheritDoc} */
public void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException {
if (fill == null && stroke == null) {

Loading…
Cancel
Save