
#include "libOLED/displayclass.H"

void
display_t::printString (font_t &font, char const *string, uint16_t length,
			colour_t colour)
{
  uint16_t const xSpacing = font.width () + 1;
  for (uint16_t yt = 0; yt < font.height (); yt++) // iterate down scan lines
    {
      uint16_t ys = m_cursor_y + yt;
      for (uint16_t xt = 0; xt < length; xt++)
	{
	  unsigned char c = string[xt];
	  uint16_t xs = xt * xSpacing + m_cursor_x;
	  for (uint16_t j = 0; j < font.spacing (); j++)
	    {
	      if (font.getPixel (c, j, yt) != 0)
		drawPixel (j + xs, ys, colour);
	    }
	}
    }
  // move the cursor.
  m_cursor_x += xSpacing * length;
}

// scale is multiplied by 256
void
display_t::printScaledString (font_t &font, char const *string,
				uint16_t length, uint16_t scale,
				colour_t colour)
{
  uint16_t xt, yt, jt, curr_x=0;
  uint16_t curr_y = m_cursor_y;
  if (scale < 1)
    return;
  for (yt = 0; yt < font.height () * 256; yt += scale) // iterate down scan lines
    {
      // iterate along the string
      // local x plotting coordinate
      curr_x = m_cursor_x;
      for (xt = 0; xt < length; xt++)
	{
	  for (jt = 0; jt < (font.spacing ()) * 256; jt += scale)
	    {
	      unsigned char c = (string[xt]);
	      if (font.getPixel (c, jt / 256, yt / 256))
		drawPixel (curr_x, curr_y, colour);
	      curr_x++;
	    }
	}
      curr_y++;
    }
  if (curr_x > width ())
    {
      curr_x = 0;
    }
  m_cursor_x = curr_x;
}

