drawChar function

Image drawChar (
  1. Image image,
  2. BitmapFont font,
  3. int x,
  4. int y,
  5. String char,
  6. {int color}
)

Draw a single character from char horizontally into image at position x,y with the given color.

Implementation

Image drawChar(Image image, BitmapFont font, int x, int y, String char,
    {int color}) {
  var c = char.codeUnits[0];
  if (!font.characters.containsKey(c)) {
    return image;
  }

  var ch = font.characters[c];
  var x2 = x + ch.width;
  var y2 = y + ch.height;
  var pi = 0;
  for (var yi = y; yi < y2; ++yi) {
    for (var xi = x; xi < x2; ++xi) {
      if (color != null) {
        drawPixel(image, xi, yi, color);
      } else {
        drawPixel(image, xi, yi, ch.image[pi++]);
      }
    }
  }

  return image;
}