if (showBox) {
cb.setRGBColorFill(boxColor.getRed(), boxColor.getGreen(), boxColor.getBlue());
if (boxColor.getAlpha() < 255) {
cb.saveState();
float alpha = boxColor.getAlpha() / 255f;
PdfGState gState = new PdfGState();
gState.setFillOpacity(alpha);
cb.setGState(gState);
}
float textWidth = getTextWidth(bf, fontSize, label);
float textHeight = getTextHeight(bf, fontSize, label);
//A height of just textHeight seems to be half the text height sometimes
//BaseFont getAscentPoint and getDescentPoint may be not very precise
cb.rectangle(x - textWidth / 2f - outlineSize / 2f, -y - outlineSize / 2f - textHeight, textWidth + outlineSize, textHeight * 2f + outlineSize);
cb.fill();
if (boxColor.getAlpha() < 255) {
cb.restoreState();
}
}
cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
float textHeight = getTextHeight(bf, fontSize, label);
if (outlineSize > 0) {
cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
cb.setRGBColorStroke(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue());
cb.setLineWidth(outlineSize);
cb.setLineJoin(PdfContentByte.LINE_JOIN_ROUND);
cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
if (outlineColor.getAlpha() < 255) {
cb.saveState();
float alpha = outlineColor.getAlpha() / 255f;
PdfGState gState = new PdfGState();
gState.setStrokeOpacity(alpha);
cb.setGState(gState);
}
cb.beginText();
cb.setFontAndSize(bf, font.getSize());
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);