Exemplo n.º 1
0
int
SFont_AlignedHeight (SFont_Font * Font, int w, int gap, char *text)
{
  char buf[512] = "";
  int width = 0;
  int ww = 0;
  int len = strlen (text);
  int i = 0;
  int y = 0;
  int nextWord = 0;

  if (text == NULL)
    return 0;

  for (i = 0; i < len; i++)
    {
      ww = wordWidth (Font, text, i, nextWord + 1);
      if ((width + ww) >= w)
	{
	  width = 0;
	  buf[0] = '\0';
	  y += Font->Surface->h + gap;
	}
      width += ww;
      copyWord (Font, text, buf, i, nextWord);
      i = nextWord;
      nextWord = findWord (Font, text, i + 1);
    }
  return y += Font->Surface->h;
}
Exemplo n.º 2
0
void
SFont_WriteAligned (SFont_Font * Font, int x, int y, int w,
		    int gap, int align, char *text)
{
  char buf[512] = "";
  int width = 0;
  int ww = 0;
  int len = strlen (text);
  int i = 0;
  int nextWord = 0;

  if (text == NULL)
    return;

  for (i = 0; i < len; i++)
    {
      ww = wordWidth (Font, text, i, nextWord + 1);
      if ((width + ww) >= w)
	{
	  switch (align)
	    {
	    case ALEFT:
	      SFont_Write (Font, x, y, buf);
	      break;
	    case ARIGHT:
	      SFont_Write (Font, x + w - width, y, buf);
	      break;
	    case ACENTER:
	      SFont_Write (Font, x + (w - width) / 2, y, buf);
	      break;
	    default:
	      break;
	    }
	  width = 0;
	  buf[0] = '\0';
	  y += Font->Surface->h + gap;
	}
      width += ww;
      copyWord (Font, text, buf, i, nextWord);
      i = nextWord;
      nextWord = findWord (Font, text, i + 1);
    }

  switch (align)
    {
    case ALEFT:
      SFont_Write (Font, x, y, buf);
      break;
    case ARIGHT:
      SFont_Write (Font, x + w - width, y, buf);
      break;
    case ACENTER:
      SFont_Write (Font, x + (w - width) / 2, y, buf);
      break;
    default:
      break;
    }
}
Exemplo n.º 3
0
/* Input:  character string c[].  It assumes that the string has
 *         words separated by spaces.  The words are numbered
 *         1, 2, ...   The input k denotes the kth word to search for. 
 * Output:  the kth word, which is stored in word[] */
void findWord(char word[], char c[], int k)
{
	int i;
	i = point2Word(c, k);
	if (i < 0) {
		word[0] = '\0';
		return;
	}
	copyWord(word, c, i);
}