int xBaseLine = x;
int yBaseLine = y;
for (char element : chars) {
Glyph gl = font.getGlyph(element);
GlyphMetrics pointMetrics = gl.getGlyphPointMetrics();
if (gl.getWidth() == 0) {
xBaseLine += pointMetrics.getAdvanceX();
continue;
}
byte[] data = gl.getBitmap();
if (data == null) {
xBaseLine += pointMetrics.getAdvanceX();
} else {
xSrcSurf = 0;
ySrcSurf = 0;
xDstSurf = Math.round(xBaseLine + gl.getGlyphPointMetrics().getLSB());
yDstSurf = yBaseLine - gl.bmp_top;
int textWidth = gl.bmp_width;
int textHeight = gl.getPointHeight();
// if Regions don't intersect
if ((xDstSurf > cMaxX) || (yDstSurf > cMaxY) || (xDstSurf + textWidth < cMinX)
|| (yDstSurf + textHeight < cMinY)) {
// Nothing to do
} else {
if (xDstSurf >= cMinX) {
clWidth = Math.min(textWidth, cMaxX - xDstSurf);
} else {
xSrcSurf += cMinX - xDstSurf;
clWidth = Math.min(cMaxX - cMinX, textWidth - (cMinX - xDstSurf));
xDstSurf = cMinX;
}
if (yDstSurf >= cMinY) {
clHeight = Math.min(textHeight, cMaxY - yDstSurf);
} else {
ySrcSurf += cMinY - yDstSurf;
clHeight = Math.min(cMaxY - cMinY, textHeight - (cMinY - yDstSurf));
yDstSurf = cMinY;
}
// Drawing on the Raster
for (int h=0; h<clHeight; h++){
for (int w=0; w < clWidth ; w++) {
byte currByte = data[(ySrcSurf + h)*gl.bmp_pitch + (xSrcSurf+w)/8];
boolean emptyByte = ((currByte & (1 << (7 - ((xSrcSurf+w) % 8)))) != 0);
if (emptyByte) {
raster.setDataElements(xDstSurf+w, yDstSurf+h, color);
} else {
// Nothing to do
}
}
}
}
xBaseLine += pointMetrics.getAdvanceX();
}
}
}