Exemplo n.º 1
0
int textStringGeometrics(TEXT_FONT *font, const char *string, int linelen, int *w_set) {
	int j,  w, w_max, t, b;

	if (!font)
		return 0;
	w_max = 0;
	w = *w_set;
	for (j = 0; *string; j++, w = 0) {
		for (; *string != 0 && *string != '\n';) {
			t = textStringWordLength(font, string, &b);
			if (t + w >= linelen) {
				if (w > 0)
					break;
				else 
					b = textStringBytesOnLine(font, string, linelen, &t);
			}

			string += b;
			w += t;

			if (*string == ' ') {
				if (textGetGlyphWidth(font, ' ') + w >= linelen) {
					string++;
					break;
				}

				w += textGetGlyphWidth(font, ' ');
				string++;
			}
		}
		if (w == 0 && *string != '\n') {	// We can't fit a single glyph. Meh. //
			*w_set = 0;
			return 0;
		}
			
		if (w > w_max)
			w_max = w;
		if (*string == '\n')
			string++;
	}

	if (w_set)
		*w_set = w_max;
	return j * textFontGetHS(font);
}
Exemplo n.º 2
0
int textStringBytesOnLine(TEXT_FONT *font, const char *string, int linelen, int *w_m) {
	int i, w;
	unsigned int glyph;

	if (!font)
		return 0;
	
	for (i = w = 0; string[i] != 0;) {
		glyph = utf8GetChar(&string[i]);
		if (textGetGlyphWidth(font, glyph) + w > linelen) {
			*w_m = w;
			return i;
		}
		w += textGetGlyphWidth(font, glyph);
		i += utf8GetValidatedCharLength(&string[i]);
	}

	*w_m = w;
	return i;
}
Exemplo n.º 3
0
int textGetStringWidth(TEXT_FONT *font, const char *string) {
	int i, w;
	unsigned int glyph;

	for (i = w = 0; string[i] != 0; ) {
		glyph = utf8GetChar(&string[i]);
		i += utf8GetValidatedCharLength(&string[i]);
		w += textGetGlyphWidth(font, glyph);
	}

	return w;
}
Exemplo n.º 4
0
int textStringWordLength(TEXT_FONT *font, const char *string, int *bytes) {
	int i, w;
	unsigned int glyph;
	
	if (bytes)
		*bytes = 0;
	if (!font)
		return 0;

	for (i = w = 0; string[i] != 0 && string[i] != ' ' && string[i] != '\n';) {
		glyph = utf8GetChar(&string[i]);
		i += utf8GetValidatedCharLength(&string[i]);
		w += textGetGlyphWidth(font, glyph);
	}
	
	if (bytes)
		*bytes = i;
	return w;
}
Exemplo n.º 5
0
unsigned int EXPORT_THIS d_font_glyph_w(void *font, const char *s) {
	unsigned int c;
	
	c = utf8GetChar(s);
	return textGetGlyphWidth(font, c);
}