git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_RoundedCorners@1396073 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
<Bug pattern="SF_SWITCH_FALLTHROUGH"/> | <Bug pattern="SF_SWITCH_FALLTHROUGH"/> | ||||
</Match> | </Match> | ||||
<Match> | <Match> | ||||
<Class name="org.apache.fop.render.java2d.Java2DBorderPainter"/> | |||||
<Class name="org.apache.fop.render.java2d.Java2DGraphicsPainter"/> | |||||
<Method name="drawLine"/> | <Method name="drawLine"/> | ||||
<Bug pattern="SF_SWITCH_FALLTHROUGH"/> | <Bug pattern="SF_SWITCH_FALLTHROUGH"/> | ||||
</Match> | </Match> |
private void includeObject(AbstractNamedAFPObject namedObj, AFPDataObjectInfo dataObjectInfo) { | private void includeObject(AbstractNamedAFPObject namedObj, AFPDataObjectInfo dataObjectInfo) { | ||||
// create the include object | // create the include object | ||||
AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); | |||||
String objectName = namedObj.getName(); | String objectName = namedObj.getName(); | ||||
AbstractCachedObject cachedObject; | AbstractCachedObject cachedObject; |
* numbers. | * numbers. | ||||
*/ | */ | ||||
int PR_X_NUMBER_CONVERSION_FEATURES = 285; | int PR_X_NUMBER_CONVERSION_FEATURES = 285; | ||||
/** Scope for table header */ | /** Scope for table header */ | ||||
int PR_X_HEADER_COLUMN = 286; | int PR_X_HEADER_COLUMN = 286; | ||||
import org.apache.fop.fo.FObj; | import org.apache.fop.fo.FObj; | ||||
import org.apache.fop.fo.PropertyList; | import org.apache.fop.fo.PropertyList; | ||||
import org.apache.fop.fo.expr.PropertyException; | import org.apache.fop.fo.expr.PropertyException; | ||||
import org.apache.fop.util.CompareUtil; | |||||
/** | /** | ||||
* Stores all common border and padding properties. | * Stores all common border and padding properties. |
* @param bpsStart the border traits associated with start edge | * @param bpsStart the border traits associated with start edge | ||||
* @param bpsEnd the border traits associated with end edge | * @param bpsEnd the border traits associated with end edge | ||||
* @param level of bidirectional embedding | * @param level of bidirectional embedding | ||||
* @param innerBackgroundColor the background color of the block | |||||
* @param innerBackgroundColor the background color of the block | |||||
*/ | */ | ||||
protected void drawBorders( // CSOK: ParameterNumber | protected void drawBorders( // CSOK: ParameterNumber | ||||
float startx, float starty, float width, float height, | float startx, float starty, float width, float height, |
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Locale; | |||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.fop.afp.AFPDitheredRectanglePainter; | import org.apache.fop.afp.AFPDitheredRectanglePainter; | ||||
private int roundedCornerCount = 0; | private int roundedCornerCount = 0; | ||||
/** Medium Map referenced on previous page **/ | |||||
private String lastMediumMap; | |||||
private static enum Location { | private static enum Location { | ||||
ELSEWHERE, IN_DOCUMENT_HEADER, FOLLOWING_PAGE_SEQUENCE, IN_PAGE_HEADER | ELSEWHERE, IN_DOCUMENT_HEADER, FOLLOWING_PAGE_SEQUENCE, IN_PAGE_HEADER | ||||
} | } | ||||
// Make a unique id | // Make a unique id | ||||
StringBuffer idBuilder = new StringBuffer("RC"); | StringBuffer idBuilder = new StringBuffer("RC"); | ||||
String tmp = Integer.toHexString(roundedCornerCount).toUpperCase(); | |||||
String tmp = Integer.toHexString(roundedCornerCount).toUpperCase(Locale.ENGLISH); | |||||
if (tmp.length() > 6) { | if (tmp.length() > 6) { | ||||
//Will never happen | //Will never happen | ||||
//log.error("Rounded corners cache capacity exceeded"); | //log.error("Rounded corners cache capacity exceeded"); |
GeneralPath cut = new GeneralPath(); | GeneralPath cut = new GeneralPath(); | ||||
cut.moveTo(0, 0); | cut.moveTo(0, 0); | ||||
float borderWidthRatio = ((float) beforeWidth) / startWidth; | |||||
if (beforeWidth * startRadius > startWidth * beforeRadius) { | |||||
cut.lineTo(startRadius, borderWidthRatio * startRadius); | |||||
cut.lineTo(startRadius, 0); | |||||
} else { | |||||
cut.lineTo(startRadius, borderWidthRatio * startRadius); | |||||
cut.lineTo(startRadius, 0); | |||||
} | |||||
cut.lineTo(startRadius, ((float) startRadius * beforeWidth) / startWidth); | |||||
cut.lineTo(startRadius, 0); | |||||
clip.intersect(new Area(cut)); | clip.intersect(new Area(cut)); | ||||
clip.transform(transform); | clip.transform(transform); | ||||
return clip; | return clip; | ||||
GeneralPath cut = new GeneralPath(); | GeneralPath cut = new GeneralPath(); | ||||
cut.moveTo(0, 0); | cut.moveTo(0, 0); | ||||
float borderWidthRatio = ((float) beforeWidth) / startWidth; | |||||
if (beforeWidth * startRadius > startWidth * beforeRadius) { | |||||
cut.lineTo(startRadius, borderWidthRatio * startRadius); | |||||
cut.lineTo(startRadius, 0); | |||||
} else { | |||||
cut.lineTo(startRadius, borderWidthRatio * startRadius); | |||||
cut.lineTo(startRadius, 0); | |||||
} | |||||
cut.lineTo(startRadius, ((float) startRadius * beforeWidth) / startWidth); | |||||
cut.lineTo(startRadius, 0); | |||||
clip.subtract(new Area(cut)); | clip.subtract(new Area(cut)); | ||||
clip.transform(transform); | clip.transform(transform); | ||||
return clip; | return clip; | ||||
hints.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); | hints.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); | ||||
hints.put("TARGET_RESOLUTION", | hints.put("TARGET_RESOLUTION", | ||||
new Integer(context.getPaintingState().getResolution())); | |||||
Integer.valueOf(context.getPaintingState().getResolution())); | |||||
try { | try { |
* @throws IOException if an I/O error occurs | * @throws IOException if an I/O error occurs | ||||
*/ | */ | ||||
void cubicBezierTo(int p1x, int p1y, int p2x, int p2y, int p3x, int p3y) throws IOException; | void cubicBezierTo(int p1x, int p1y, int p2x, int p2y, int p3x, int p3y) throws IOException; | ||||
} | |||||
} |
/** TODO remove before integration*/ | /** TODO remove before integration*/ | ||||
public static final String ROUNDED_CORNERS = "fop.round-corners"; | public static final String ROUNDED_CORNERS = "fop.round-corners"; | ||||
/** TODO Use a class to model border instead of an array | |||||
* convention index of top, bottom, right and left borders */ | |||||
protected static final int TOP = 0, RIGHT = 1, BOTTOM = 2, LEFT = 3; | |||||
/** TODO Use a class to model border corners instead of an array | |||||
convention index of top-left, top-right, bottom-right and bottom-left border corners*/ | |||||
protected static final int TOP_LEFT = 0, TOP_RIGHT = 1, BOTTOM_RIGHT = 2, BOTTOM_LEFT = 3; | |||||
// TODO Use a class to model border instead of an array | |||||
/** Convention index of before top */ | |||||
protected static final int TOP = 0; | |||||
/** Convention index of right border */ | |||||
protected static final int RIGHT = 1; | |||||
/** Convention index of bottom border */ | |||||
protected static final int BOTTOM = 2; | |||||
/** Convention index of left border */ | |||||
protected static final int LEFT = 3; | |||||
// TODO Use a class to model border corners instead of an array | |||||
/** Convention index of top-left border corners */ | |||||
protected static final int TOP_LEFT = 0; | |||||
/** Convention index of top-right-end border corners */ | |||||
protected static final int TOP_RIGHT = 1; | |||||
/** Convention index of bottom-right border corners */ | |||||
protected static final int BOTTOM_RIGHT = 2; | |||||
/** Convention index of bottom-left border corners */ | |||||
protected static final int BOTTOM_LEFT = 3; | |||||
private final GraphicsPainter graphicsPainter; | private final GraphicsPainter graphicsPainter; | ||||
int outerx = startx - clipw[LEFT]; | int outerx = startx - clipw[LEFT]; | ||||
int clipx = outerx + clipw[LEFT]; | int clipx = outerx + clipw[LEFT]; | ||||
int innerx = outerx + bw[LEFT]; | int innerx = outerx + bw[LEFT]; | ||||
saveGraphicsState(); | saveGraphicsState(); | ||||
moveTo(clipx, ey1); | moveTo(clipx, ey1); | ||||
final int width = borderRect.width - start.getClippedWidth() - end.getClippedWidth(); | final int width = borderRect.width - start.getClippedWidth() - end.getClippedWidth(); | ||||
final int height = borderRect.height - before.getClippedWidth() - after.getClippedWidth(); | final int height = borderRect.height - before.getClippedWidth() - after.getClippedWidth(); | ||||
//Determine scale factor if any adjacent elliptic corners overlap | //Determine scale factor if any adjacent elliptic corners overlap | ||||
double cornerCorrectionFactor = calculateCornerScaleCorrection(width, height, before, after, start, end); | |||||
double cornerCorrectionFactor = calculateCornerScaleCorrection(width, height, before, after, start, | |||||
end); | |||||
drawBorderSegment(start, before, end, 0, width, startx, starty, cornerCorrectionFactor); | drawBorderSegment(start, before, end, 0, width, startx, starty, cornerCorrectionFactor); | ||||
drawBorderSegment(before, end, after, 1, height, startx + width, starty, cornerCorrectionFactor); | drawBorderSegment(before, end, after, 1, height, startx + width, starty, cornerCorrectionFactor); | ||||
drawBorderSegment(end, after, start, 2, width, startx + width, starty + height, cornerCorrectionFactor); | |||||
drawBorderSegment(end, after, start, 2, width, startx + width, starty + height, | |||||
cornerCorrectionFactor); | |||||
drawBorderSegment(after, start, before, 3, height, startx, starty + height, cornerCorrectionFactor); | drawBorderSegment(after, start, before, 3, height, startx, starty + height, cornerCorrectionFactor); | ||||
} | } | ||||
private static final Corner SQUARE = new Corner(0, 0, null, 0, 0, 0, 0); | private static final Corner SQUARE = new Corner(0, 0, null, 0, 0, 0, 0); | ||||
/** The radius of the elliptic corner in the x direction */ | /** The radius of the elliptic corner in the x direction */ | ||||
protected final int radiusX; | |||||
private final int radiusX; | |||||
/** The radius of the elliptic corner in the y direction */ | /** The radius of the elliptic corner in the y direction */ | ||||
protected final int radiusY; | |||||
private final int radiusY; | |||||
/** The start and end angles of the corner ellipse */ | /** The start and end angles of the corner ellipse */ | ||||
private final CornerAngles angles; | private final CornerAngles angles; |
import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
import org.xml.sax.SAXException; | import org.xml.sax.SAXException; | ||||
import org.apache.batik.parser.AWTTransformProducer; | |||||
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.batik.parser.AWTTransformProducer; | |||||
import org.apache.xmlgraphics.xmp.Metadata; | import org.apache.xmlgraphics.xmp.Metadata; | ||||
import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter; | import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter; | ||||
import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema; | import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema; |
this.painter.restoreGraphicsState(); | this.painter.restoreGraphicsState(); | ||||
this.currentPath = null; | this.currentPath = null; | ||||
} | } | ||||
} | |||||
} |
boolean startOrBefore, int style, Color col) { | boolean startOrBefore, int style, Color col) { | ||||
float w = x2 - x1; | float w = x2 - x1; | ||||
float h = y2 - y1; | float h = y2 - y1; | ||||
float colFactor; | |||||
switch (style) { | switch (style) { | ||||
case Constants.EN_DASHED: | case Constants.EN_DASHED: | ||||
generator.setColor(col); | generator.setColor(col); | ||||
break; | break; | ||||
case Constants.EN_GROOVE: | case Constants.EN_GROOVE: | ||||
case Constants.EN_RIDGE: | case Constants.EN_RIDGE: | ||||
{ | |||||
float colFactor = (style == Constants.EN_GROOVE ? 0.4f : -0.4f); | |||||
colFactor = (style == Constants.EN_GROOVE ? 0.4f : -0.4f); | |||||
generator.setSolidLine(); | generator.setSolidLine(); | ||||
if (horz) { | if (horz) { | ||||
Color uppercol = ColorUtil.lightenColor(col, -colFactor); | Color uppercol = ColorUtil.lightenColor(col, -colFactor); | ||||
.strokeLine(xm1 + w3 + w3, y1, xm1 + w3 + w3, y2); | .strokeLine(xm1 + w3 + w3, y1, xm1 + w3 + w3, y2); | ||||
} | } | ||||
break; | break; | ||||
} | |||||
case Constants.EN_INSET: | case Constants.EN_INSET: | ||||
case Constants.EN_OUTSET: | case Constants.EN_OUTSET: | ||||
{ | |||||
float colFactor = (style == Constants.EN_OUTSET ? 0.4f : -0.4f); | |||||
colFactor = (style == Constants.EN_OUTSET ? 0.4f : -0.4f); | |||||
generator.setSolidLine(); | generator.setSolidLine(); | ||||
Color c = col; | Color c = col; | ||||
if (horz) { | if (horz) { | ||||
.strokeLine(xm1, y1, xm1, y2); | .strokeLine(xm1, y1, xm1, y2); | ||||
} | } | ||||
break; | break; | ||||
} | |||||
case Constants.EN_HIDDEN: | case Constants.EN_HIDDEN: | ||||
break; | break; | ||||
default: | default: | ||||
String xS = format(xStart); | String xS = format(xStart); | ||||
String xE = format(xEnd); | String xE = format(xEnd); | ||||
String yS = format(yStart); | String yS = format(yStart); | ||||
String yE = format(yEnd); | |||||
if (style == RuleStyle.GROOVE) { | if (style == RuleStyle.GROOVE) { | ||||
addLine("m", xS, yS) | addLine("m", xS, yS) | ||||
.addLine("l", xE, yS) | .addLine("l", xE, yS) |
import org.apache.fop.fo.Constants; | import org.apache.fop.fo.Constants; | ||||
import org.apache.fop.render.intermediate.ArcToBezierCurveTransformer; | import org.apache.fop.render.intermediate.ArcToBezierCurveTransformer; | ||||
import org.apache.fop.render.intermediate.BezierCurvePainter; | import org.apache.fop.render.intermediate.BezierCurvePainter; | ||||
import org.apache.fop.render.intermediate.BorderPainter; | |||||
import org.apache.fop.render.intermediate.GraphicsPainter; | import org.apache.fop.render.intermediate.GraphicsPainter; | ||||
import org.apache.fop.traits.RuleStyle; | import org.apache.fop.traits.RuleStyle; | ||||
import org.apache.fop.util.ColorUtil; | import org.apache.fop.util.ColorUtil; | ||||
gen.useColor(col); | gen.useColor(col); | ||||
if (horz) { | if (horz) { | ||||
float unit = Math.abs(2 * h); | float unit = Math.abs(2 * h); | ||||
int rep = (int)(w / unit); | |||||
int rep = (int) (w / unit); | |||||
if (rep % 2 == 0) { | if (rep % 2 == 0) { | ||||
rep++; | rep++; | ||||
} | } | ||||
drawLine(gen, x1, ym, x2, ym); | drawLine(gen, x1, ym, x2, ym); | ||||
} else { | } else { | ||||
float unit = Math.abs(2 * w); | float unit = Math.abs(2 * w); | ||||
int rep = (int)(h / unit); | |||||
int rep = (int) (h / unit); | |||||
if (rep % 2 == 0) { | if (rep % 2 == 0) { | ||||
rep++; | rep++; | ||||
} | } | ||||
gen.useLineCap(1); //Rounded! | gen.useLineCap(1); //Rounded! | ||||
if (horz) { | if (horz) { | ||||
float unit = Math.abs(2 * h); | float unit = Math.abs(2 * h); | ||||
int rep = (int)(w / unit); | |||||
int rep = (int) (w / unit); | |||||
if (rep % 2 == 0) { | if (rep % 2 == 0) { | ||||
rep++; | rep++; | ||||
} | } | ||||
drawLine(gen, x1, ym, x2, ym); | drawLine(gen, x1, ym, x2, ym); | ||||
} else { | } else { | ||||
float unit = Math.abs(2 * w); | float unit = Math.abs(2 * w); | ||||
int rep = (int)(h / unit); | |||||
int rep = (int) (h / unit); | |||||
if (rep % 2 == 0) { | if (rep % 2 == 0) { | ||||
rep++; | rep++; | ||||
} | } |
*/ | */ | ||||
public class BorderProps implements Serializable { | public class BorderProps implements Serializable { | ||||
private static final long serialVersionUID = 7053576586478548795L; | |||||
private static final long serialVersionUID = 8022237892391068187L; | |||||
public enum Mode { | public enum Mode { | ||||
SEPARATE("separate") { | SEPARATE("separate") { | ||||
return true; | return true; | ||||
} else { | } else { | ||||
if (obj instanceof BorderProps) { | if (obj instanceof BorderProps) { | ||||
BorderProps other = (BorderProps)obj; | |||||
BorderProps other = (BorderProps) obj; | |||||
return (style == other.style) | return (style == other.style) | ||||
&& org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor( | && org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor( | ||||
color, other.color) | color, other.color) | ||||
return sbuf.toString(); | return sbuf.toString(); | ||||
} | } | ||||
private static class BorderPropsDeserializer { | |||||
private static final class BorderPropsDeserializer { | |||||
private static final BorderPropsDeserializer INSTANCE = new BorderPropsDeserializer(); | private static final BorderPropsDeserializer INSTANCE = new BorderPropsDeserializer(); | ||||
m.find(); | m.find(); | ||||
int width = Integer.parseInt(m.group()); | int width = Integer.parseInt(m.group()); | ||||
Mode mode = Mode.SEPARATE; | Mode mode = Mode.SEPARATE; | ||||
if ( m.find()) { | |||||
if (m.find()) { | |||||
String ms = m.group(); | String ms = m.group(); | ||||
if (Mode.COLLAPSE_INNER.value.equalsIgnoreCase(ms)) { | if (Mode.COLLAPSE_INNER.value.equalsIgnoreCase(ms)) { | ||||
mode = Mode.COLLAPSE_INNER; | mode = Mode.COLLAPSE_INNER; |