public void VariableRectangle(Rectangle rect)
{
float t = rect.Top;
float b = rect.Bottom;
float r = rect.Right;
float l = rect.Left;
float wt = rect.BorderWidthTop;
float wb = rect.BorderWidthBottom;
float wr = rect.BorderWidthRight;
float wl = rect.BorderWidthLeft;
BaseColor ct = rect.BorderColorTop;
BaseColor cb = rect.BorderColorBottom;
BaseColor cr = rect.BorderColorRight;
BaseColor cl = rect.BorderColorLeft;
SaveState();
SetLineCap(PdfContentByte.LINE_CAP_BUTT);
SetLineJoin(PdfContentByte.LINE_JOIN_MITER);
float clw = 0;
bool cdef = false;
BaseColor ccol = null;
bool cdefi = false;
BaseColor cfil = null;
// draw top
if (wt > 0) {
SetLineWidth(clw = wt);
cdef = true;
if (ct == null)
ResetRGBColorStroke();
else
SetColorStroke(ct);
ccol = ct;
MoveTo(l, t - wt / 2f);
LineTo(r, t - wt / 2f);
Stroke();
}
// Draw bottom
if (wb > 0) {
if (wb != clw)
SetLineWidth(clw = wb);
if (!cdef || !CompareColors(ccol, cb)) {
cdef = true;
if (cb == null)
ResetRGBColorStroke();
else
SetColorStroke(cb);
ccol = cb;
}
MoveTo(r, b + wb / 2f);
LineTo(l, b + wb / 2f);
Stroke();
}
// Draw right
if (wr > 0) {
if (wr != clw)
SetLineWidth(clw = wr);
if (!cdef || !CompareColors(ccol, cr)) {
cdef = true;
if (cr == null)
ResetRGBColorStroke();
else
SetColorStroke(cr);
ccol = cr;
}
bool bt = CompareColors(ct, cr);
bool bb = CompareColors(cb, cr);
MoveTo(r - wr / 2f, bt ? t : t - wt);
LineTo(r - wr / 2f, bb ? b : b + wb);
Stroke();
if (!bt || !bb) {
cdefi = true;
if (cr == null)
ResetRGBColorFill();
else
SetColorFill(cr);
cfil = cr;
if (!bt) {
MoveTo(r, t);
LineTo(r, t - wt);
LineTo(r - wr, t - wt);
Fill();
}
if (!bb) {
MoveTo(r, b);
LineTo(r, b + wb);
LineTo(r - wr, b + wb);
Fill();
}
}
}
// Draw Left
if (wl > 0) {
if (wl != clw)
SetLineWidth(wl);
if (!cdef || !CompareColors(ccol, cl)) {
if (cl == null)
ResetRGBColorStroke();
else
SetColorStroke(cl);
}
bool bt = CompareColors(ct, cl);
bool bb = CompareColors(cb, cl);
MoveTo(l + wl / 2f, bt ? t : t - wt);
LineTo(l + wl / 2f, bb ? b : b + wb);
Stroke();
if (!bt || !bb) {
if (!cdefi || !CompareColors(cfil, cl)) {
if (cl == null)
ResetRGBColorFill();
else
SetColorFill(cl);
}
if (!bt) {
MoveTo(l, t);
LineTo(l, t - wt);
LineTo(l + wl, t - wt);
Fill();
}
if (!bb) {
MoveTo(l, b);
LineTo(l, b + wb);
LineTo(l + wl, b + wb);
Fill();
}
}
}
RestoreState();
}