Author: jeremias
Date: Fri Aug 15 08:31:55 2008
New Revision: 686253
URL: http://svn.apache.org/viewvc?rev=686253&view=rev
Log:
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.
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFPainter.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java
Fri Aug 15 08:31:55 2008
@@ -44,6 +44,7 @@
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";
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java
Fri Aug 15 08:31:55 2008
@@ -31,6 +31,8 @@
*/
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 @@
this(new AffineTransform[] {transform});
}
+ public Group() {
+ this(EMPTY_TRANSFORM_ARRAY);
+ }
+
public AffineTransform[] getTransforms() {
return this.transforms;
}
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java
Fri Aug 15 08:31:55 2008
@@ -269,6 +269,14 @@
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
* @param fill the fill paint (may be null)
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
Fri Aug 15 08:31:55 2008
@@ -136,6 +136,7 @@
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 @@
}
+ 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
{
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java
Fri Aug 15 08:31:55 2008
@@ -584,12 +584,12 @@
/** [EMAIL PROTECTED] */
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 @@
saveGraphicsState();
//Viewport position
- concatenateTransformationMatrixMpt(positionTransform);
+ concatenateTransformationMatrixMpt(positionTransform, false);
//Background and borders
float bpwidth = (borderPaddingStart +
bv.getBorderAndPaddingWidthEnd());
@@ -670,7 +670,7 @@
//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 @@
/** [EMAIL PROTECTED] */
protected void clip() {
- // TODO Auto-generated method stub
- log.warn("clip() NYI");
+ throw new IllegalStateException("Not used");
}
/** [EMAIL PROTECTED] */
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);
+ }
}
/** [EMAIL PROTECTED] */
protected void closePath() {
- // TODO Auto-generated method stub
- log.warn("closePath() NYI");
+ throw new IllegalStateException("Not used");
}
/** [EMAIL PROTECTED] */
@@ -1056,14 +1058,12 @@
/** [EMAIL PROTECTED] */
protected void moveTo(float x, float y) {
- // TODO Auto-generated method stub
- log.warn("moveTo() NYI");
+ throw new IllegalStateException("Not used");
}
/** [EMAIL PROTECTED] */
protected void lineTo(float x, float y) {
- // TODO Auto-generated method stub
- log.warn("lineTo() NYI");
+ throw new IllegalStateException("Not used");
}
/** [EMAIL PROTECTED] */
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
Fri Aug 15 08:31:55 2008
@@ -350,6 +350,20 @@
}
/** [EMAIL PROTECTED] */
+ 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);
+ }
+ }
+
+ /** [EMAIL PROTECTED] */
public void drawRect(Rectangle rect, Paint fill, Color stroke) throws
IFException {
if (fill == null && stroke == null) {
return;
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFPainter.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFPainter.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFPainter.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFPainter.java
Fri Aug 15 08:31:55 2008
@@ -241,12 +241,7 @@
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);
}
}
@@ -330,6 +325,17 @@
}
/** [EMAIL PROTECTED] */
+ 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());
+ }
+
+ /** [EMAIL PROTECTED] */
public void drawRect(Rectangle rect, Paint fill, Color stroke) throws
IFException {
if (fill == null && stroke == null) {
return;
@@ -365,8 +371,10 @@
/** [EMAIL PROTECTED] */
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 @@
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 @@
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);
}
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java?rev=686253&r1=686252&r2=686253&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
Fri Aug 15 08:31:55 2008
@@ -279,6 +279,11 @@
}
/** [EMAIL PROTECTED] */
+ public void clipRect(Rectangle rect) throws IFException {
+ //TODO Implement me!!!
+ }
+
+ /** [EMAIL PROTECTED] */
public void drawRect(Rectangle rect, Paint fill, Color stroke) throws
IFException {
if (fill == null && stroke == null) {
return;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]