in fop-core/src/main/java/org/apache/fop/render/intermediate/BorderPainter.java [104:276]
protected void drawRectangularBorders(Rectangle borderRect,
BorderProps bpsTop, BorderProps bpsBottom,
BorderProps bpsLeft, BorderProps bpsRight) throws IOException {
bpsTop = sanitizeBorderProps(bpsTop);
bpsBottom = sanitizeBorderProps(bpsBottom);
bpsLeft = sanitizeBorderProps(bpsLeft);
bpsRight = sanitizeBorderProps(bpsRight);
int startx = borderRect.x;
int starty = borderRect.y;
int width = borderRect.width;
int height = borderRect.height;
boolean[] b = new boolean[] {
(bpsTop != null), (bpsRight != null),
(bpsBottom != null), (bpsLeft != null)};
if (!b[TOP] && !b[RIGHT] && !b[BOTTOM] && !b[LEFT]) {
return;
}
int[] bw = new int[] {
(b[TOP] ? bpsTop.width : 0),
(b[RIGHT] ? bpsRight.width : 0),
(b[BOTTOM] ? bpsBottom.width : 0),
(b[LEFT] ? bpsLeft.width : 0)};
int[] clipw = new int[] {
BorderProps.getClippedWidth(bpsTop),
BorderProps.getClippedWidth(bpsRight),
BorderProps.getClippedWidth(bpsBottom),
BorderProps.getClippedWidth(bpsLeft)};
starty += clipw[TOP];
height -= clipw[TOP];
height -= clipw[BOTTOM];
startx += clipw[LEFT];
width -= clipw[LEFT];
width -= clipw[RIGHT];
boolean[] slant = new boolean[] {
(b[LEFT] && b[TOP]),
(b[TOP] && b[RIGHT]),
(b[RIGHT] && b[BOTTOM]),
(b[BOTTOM] && b[LEFT])};
if (bpsTop != null) {
int sx1 = startx;
int sx2 = (slant[TOP_LEFT] ? sx1 + bw[LEFT] - clipw[LEFT] : sx1);
int ex1 = startx + width;
int ex2 = (slant[TOP_RIGHT] ? ex1 - bw[RIGHT] + clipw[RIGHT] : ex1);
int outery = starty - clipw[TOP];
int clipy = outery + clipw[TOP];
int innery = outery + bw[TOP];
saveGraphicsState();
moveTo(sx1, clipy);
int sx1a = sx1;
int ex1a = ex1;
if (isCollapseOuter(bpsTop)) {
if (isCollapseOuter(bpsLeft)) {
sx1a -= clipw[LEFT];
}
if (isCollapseOuter(bpsRight)) {
ex1a += clipw[RIGHT];
}
lineTo(sx1a, outery);
lineTo(ex1a, outery);
}
lineTo(ex1, clipy);
lineTo(ex2, innery);
lineTo(sx2, innery);
closePath();
clip();
drawBorderLine(sx1a, outery, ex1a, innery, true, true,
bpsTop.style, bpsTop.color);
restoreGraphicsState();
}
if (bpsRight != null) {
int sy1 = starty;
int sy2 = (slant[TOP_RIGHT] ? sy1 + bw[TOP] - clipw[TOP] : sy1);
int ey1 = starty + height;
int ey2 = (slant[BOTTOM_RIGHT] ? ey1 - bw[BOTTOM] + clipw[BOTTOM] : ey1);
int outerx = startx + width + clipw[RIGHT];
int clipx = outerx - clipw[RIGHT];
int innerx = outerx - bw[RIGHT];
saveGraphicsState();
moveTo(clipx, sy1);
int sy1a = sy1;
int ey1a = ey1;
if (isCollapseOuter(bpsRight)) {
if (isCollapseOuter(bpsTop)) {
sy1a -= clipw[TOP];
}
if (isCollapseOuter(bpsBottom)) {
ey1a += clipw[BOTTOM];
}
lineTo(outerx, sy1a);
lineTo(outerx, ey1a);
}
lineTo(clipx, ey1);
lineTo(innerx, ey2);
lineTo(innerx, sy2);
closePath();
clip();
drawBorderLine(innerx, sy1a, outerx, ey1a, false, false,
bpsRight.style, bpsRight.color);
restoreGraphicsState();
}
if (bpsBottom != null) {
int sx1 = startx;
int sx2 = (slant[BOTTOM_LEFT] ? sx1 + bw[LEFT] - clipw[LEFT] : sx1);
int ex1 = startx + width;
int ex2 = (slant[BOTTOM_RIGHT] ? ex1 - bw[RIGHT] + clipw[RIGHT] : ex1);
int outery = starty + height + clipw[BOTTOM];
int clipy = outery - clipw[BOTTOM];
int innery = outery - bw[BOTTOM];
saveGraphicsState();
moveTo(ex1, clipy);
int sx1a = sx1;
int ex1a = ex1;
if (isCollapseOuter(bpsBottom)) {
if (isCollapseOuter(bpsLeft)) {
sx1a -= clipw[LEFT];
}
if (isCollapseOuter(bpsRight)) {
ex1a += clipw[RIGHT];
}
lineTo(ex1a, outery);
lineTo(sx1a, outery);
}
lineTo(sx1, clipy);
lineTo(sx2, innery);
lineTo(ex2, innery);
closePath();
clip();
drawBorderLine(sx1a, innery, ex1a, outery, true, false,
bpsBottom.style, bpsBottom.color);
restoreGraphicsState();
}
if (bpsLeft != null) {
int sy1 = starty;
int sy2 = (slant[TOP_LEFT] ? sy1 + bw[TOP] - clipw[TOP] : sy1);
int ey1 = sy1 + height;
int ey2 = (slant[BOTTOM_LEFT] ? ey1 - bw[BOTTOM] + clipw[BOTTOM] : ey1);
int outerx = startx - clipw[LEFT];
int clipx = outerx + clipw[LEFT];
int innerx = outerx + bw[LEFT];
saveGraphicsState();
moveTo(clipx, ey1);
int sy1a = sy1;
int ey1a = ey1;
if (isCollapseOuter(bpsLeft)) {
if (isCollapseOuter(bpsTop)) {
sy1a -= clipw[TOP];
}
if (isCollapseOuter(bpsBottom)) {
ey1a += clipw[BOTTOM];
}
lineTo(outerx, ey1a);
lineTo(outerx, sy1a);
}
lineTo(clipx, sy1);
lineTo(innerx, sy2);
lineTo(innerx, ey2);
closePath();
clip();
drawBorderLine(outerx, sy1a, innerx, ey1a, false, true, bpsLeft.style, bpsLeft.color);
restoreGraphicsState();
}
}