diff --git a/stb_easy_font.h b/stb_easy_font.h index 4dee383..2fad91f 100644 --- a/stb_easy_font.h +++ b/stb_easy_font.h @@ -1,4 +1,4 @@ -// stb_easy_font.h - v0.6 - bitmap font for 3D rendering - public domain +// stb_easy_font.h - v0.7 - bitmap font for 3D rendering - public domain // Sean Barrett, Feb 2015 // // Easy-to-deploy, @@ -16,8 +16,10 @@ // DOCUMENTATION: // // int stb_easy_font_width(char *text) +// int stb_easy_font_height(char *text) // -// Takes a string without newlines and returns the horizontal size. +// Takes a string and returns the horizontal size and the +// vertical size (which can vary if 'text' has newlines). // // int stb_easy_font_print(float x, float y, // char *text, unsigned char color[4], @@ -40,7 +42,7 @@ // // You can ignore z and color if you get them from elsewhere // This format was chosen in the hopes it would make it -// easier for you to reuse existing buffer-drawing code. +// easier for you to reuse existing vertex-buffer-drawing code. // // If you pass in NULL for color, it becomes 255,255,255,255. // @@ -63,11 +65,6 @@ // compact to me; -0.5 is a reasonable compromise as long as // you're scaling the font up. // -// SAMPLE CODE: -// -// Here's sample code for old OpenGL; it's a lot more complicated -// to make work on modern APIs, and that's your problem. -// // LICENSE // // This software is in the public domain. Where that dedication is not @@ -76,10 +73,16 @@ // // VERSION HISTORY // +// (2016-01-22) 0.7 width() supports multiline text; add height() // (2015-09-13) 0.6 #include ; updated license // (2015-02-01) 0.5 First release #if 0 +// SAMPLE CODE: +// +// Here's sample code for old OpenGL; it's a lot more complicated +// to make work on modern APIs, and that's your problem. +// void print_string(float x, float y, char *text, float r, float g, float b) { static char buffer[99999]; // ~500 chars @@ -222,11 +225,34 @@ static int stb_easy_font_print(float x, float y, char *text, unsigned char color static int stb_easy_font_width(char *text) { float len = 0; + float max_len = 0; while (*text) { - len += stb_easy_font_charinfo[*text-32].advance & 15; - len += stb_easy_font_spacing_val; + if (*text == '\n') { + if (len > max_len) max_len = len; + len = 0; + } else { + len += stb_easy_font_charinfo[*text-32].advance & 15; + len += stb_easy_font_spacing_val; + } ++text; } - return (int) ceil(len); + if (len > max_len) max_len = len; + return (int) ceil(max_len); +} + +static int stb_easy_font_height(char *text) +{ + float y = 0; + int nonempty_line=0; + while (*text) { + if (*text == '\n') { + y += 12; + nonempty_line = 0; + } else { + nonempty_line = 1; + } + ++text; + } + return (int) ceil(y + (nonempty_line ? 12 : 0)); } #endif diff --git a/stb_image.h b/stb_image.h index be25097..e06f7a1 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1,4 +1,4 @@ -/* stb_image - v2.09 - public domain image loader - http://nothings.org/stb_image.h +/* stb_image - v2.10 - public domain image loader - http://nothings.org/stb_image.h no warranty implied; use at your own risk Do this: @@ -146,6 +146,7 @@ Latest revision history: + 2.10 (2016-01-22) avoid warning introduced in 2.09 2.09 (2016-01-16) 16-bit TGA; comments in PNM files; STBI_REALLOC_SIZED 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA 2.07 (2015-09-13) partial animated GIF support @@ -3621,6 +3622,7 @@ static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room while (cur + n > limit) limit *= 2; q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); + STBI_NOTUSED(old_limit); if (q == NULL) return stbi__err("outofmem", "Out of memory"); z->zout_start = q; z->zout = q + cur; @@ -4410,6 +4412,7 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; while (ioff + c.length > idata_limit) idata_limit *= 2; + STBI_NOTUSED(idata_limit_old); p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); z->idata = p; } @@ -6456,6 +6459,7 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int /* revision history: + 2.10 (2016-01-22) avoid warning introduced in 2.09 by STBI_REALLOC_SIZED 2.09 (2016-01-16) allow comments in PNM files 16-bit-per-pixel TGA (not bit-per-component) info() for TGA could break due to .hdr handling