public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) {
String fullCode = code;
if (generateChecksum && checksumText)
fullCode = CalculateChecksum(code);
if (!startStopText)
fullCode = fullCode.Substring(1, fullCode.Length - 2);
float fontX = 0;
if (font != null) {
fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
}
byte[] bars = GetBarsCodabar(generateChecksum ? CalculateChecksum(code) : code);
int wide = 0;
for (int k = 0; k < bars.Length; ++k) {
wide += (int)bars[k];
}
int narrow = bars.Length - wide;
float fullWidth = x * (narrow + wide * n);
float barStartX = 0;
float textStartX = 0;
switch (textAlignment) {
case Element.ALIGN_LEFT:
break;
case Element.ALIGN_RIGHT:
if (fontX > fullWidth)
barStartX = fontX - fullWidth;
else
textStartX = fullWidth - fontX;
break;
default:
if (fontX > fullWidth)
barStartX = (fontX - fullWidth) / 2;
else
textStartX = (fullWidth - fontX) / 2;
break;
}
float barStartY = 0;
float textStartY = 0;
if (font != null) {
if (baseline <= 0)
textStartY = barHeight - baseline;
else {
textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
barStartY = textStartY + baseline;
}
}
bool print = true;
if (barColor != null)
cb.SetColorFill(barColor);
for (int k = 0; k < bars.Length; ++k) {
float w = (bars[k] == 0 ? x : x * n);
if (print)
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
print = !print;
barStartX += w;
}
cb.Fill();
if (font != null) {
if (textColor != null)
cb.SetColorFill(textColor);
cb.BeginText();
cb.SetFontAndSize(font, size);
cb.SetTextMatrix(textStartX, textStartY);
cb.ShowText(fullCode);
cb.EndText();
}
return BarcodeSize;
}