int y_min = Integer.MAX_VALUE;
int x_max = Integer.MIN_VALUE;
int y_max = Integer.MIN_VALUE;
for (int i = 0; i < charsCount; i++) {
BDFGlyph glyph = bdfFont.getGlyph(str.charAt(i));
if (glyph == null) {
continue;
}
glyph_box = glyph.getBbx(glyph_box);
final int fHeight = glyph_box.height;
final int[] fData = glyph.getData();
final int scan = fData.length / fHeight;
int fg_r = color.getRed();
int fg_g = color.getGreen();
int fg_b = color.getBlue();
//box location
final int bx = x + offset + glyph_box.x;
final int by = y - fHeight - glyph_box.y;
for (int k = 0; k < fHeight; k++) {
final int offsetLine = k * scan;
for (int j = 0; j < scan; j++) {
int fPixel = fData[offsetLine + j];
if (fPixel != 0) {
//pixel location
int px = bx + j;
int py = by + k;
if (tx != null) {
src.setLocation(px, py);
tx.transform(src, dst);
px = (int) dst.getX();
py = (int) dst.getY();
}
//clip
if (clip == null || clip.contains(px, py)) {
//compute color
int bg_color = surface.getRGBPixel(px, py);
int bg_r = (bg_color & 0x00FF0000) >> 16;
int bg_g = (bg_color & 0x0000FF00) >> 8;
int bg_b = (bg_color & 0x000000FF);
//todo improve this pixel composition
float alpha = fPixel / f_max;
int r = bg_r + ((int) ((fg_r - bg_r) * alpha)) & 0xFF;
int g = bg_g + ((int) ((fg_g - bg_g) * alpha)) & 0xFF;
int b = bg_b + ((int) ((fg_b - bg_b) * alpha)) & 0xFF;
fPixel = (((r << 16) + (g << 8) + b) | 0xFF000000);
surface.setRGBPixel(px, py, fPixel);
if (x_min > px) x_min = px;
if (y_min > py) y_min = py;
if (x_max < px) x_max = px;
if (y_max < py) y_max = py;
}
}
}
}
offset += glyph.getDWidth().width;
}
if (x_min < Integer.MAX_VALUE && y_min < Integer.MAX_VALUE &&
x_max > Integer.MIN_VALUE && y_max > Integer.MIN_VALUE)
surface.update(x_min, y_min, x_max - x_min + 1, y_max - y_min + 1);
}