void iupDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, unsigned char r, unsigned char g, unsigned char b, const char* font)
{
  int num_line;
  HFONT hOldFont, hFont = (HFONT)iupwinGetHFont(font);
  SetTextColor(dc->hBitmapDC, RGB(r, g, b));
  hOldFont = SelectObject(dc->hBitmapDC, hFont);

  num_line = iupStrLineCount(text);

  if (num_line == 1)
  {
    TCHAR* wtext = iupwinStrToSystemLen(text, &len);
    TextOut(dc->hBitmapDC, x, y, wtext, len);
  }
  else
  {
    int i, line_height, len;
    const char *p, *q;
    TCHAR* wtext;
    TEXTMETRIC tm;

    GetTextMetrics(dc->hBitmapDC, &tm);
    line_height = tm.tmHeight;

    p = text;
    for (i = 0; i < num_line; i++)
    {
      q = strchr(p, '\n');
      if (q) 
        len = (int)(q - p);  /* Cut the string to contain only one line */
      else 
        len = (int)strlen(p);  /* use the remaining characters */

      /* Draw the line */
      wtext = iupwinStrToSystemLen(p, &len);
      TextOut(dc->hBitmapDC, x, y, wtext, len);

      /* Advance the string */
      if (q) 
        p = q + 1;

      /* Advance a line */
      y += line_height;
    }
  }

  SelectObject(dc->hBitmapDC, hOldFont);
}
Beispiel #2
0
int iupdrvFontGetStringWidth(Ihandle* ih, const char* str)
{
  HDC hdc;
  HFONT oldhfont, hFont;
  SIZE size;
  int len;
  char* line_end;  
  TCHAR* wstr;
  if (!str || str[0]==0)
    return 0;

  hFont = (HFONT)iupwinGetHFontAttrib(ih);
  if (!hFont)
    return 0;

  hdc = winFontGetDC(ih);
  oldhfont = SelectObject(hdc, hFont);

  line_end = strchr(str, '\n');
  if (line_end)
    len = line_end-str;
  else
    len = strlen(str);

  wstr = iupwinStrToSystemLen(str, &len);
  GetTextExtentPoint32(hdc, wstr, len, &size);

  SelectObject(hdc, oldhfont);
  winFontReleaseDC(ih, hdc);

  return size.cx;
}