Merge branch 'working'

pull/228/head
Sean Barrett 2016-01-22 05:17:46 -08:00
commit e0dafae042
2 changed files with 42 additions and 12 deletions

View File

@ -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 // Sean Barrett, Feb 2015
// //
// Easy-to-deploy, // Easy-to-deploy,
@ -16,8 +16,10 @@
// DOCUMENTATION: // DOCUMENTATION:
// //
// int stb_easy_font_width(char *text) // 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, // int stb_easy_font_print(float x, float y,
// char *text, unsigned char color[4], // char *text, unsigned char color[4],
@ -40,7 +42,7 @@
// //
// You can ignore z and color if you get them from elsewhere // You can ignore z and color if you get them from elsewhere
// This format was chosen in the hopes it would make it // 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. // 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 // compact to me; -0.5 is a reasonable compromise as long as
// you're scaling the font up. // 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 // LICENSE
// //
// This software is in the public domain. Where that dedication is not // This software is in the public domain. Where that dedication is not
@ -76,10 +73,16 @@
// //
// VERSION HISTORY // VERSION HISTORY
// //
// (2016-01-22) 0.7 width() supports multiline text; add height()
// (2015-09-13) 0.6 #include <math.h>; updated license // (2015-09-13) 0.6 #include <math.h>; updated license
// (2015-02-01) 0.5 First release // (2015-02-01) 0.5 First release
#if 0 #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) void print_string(float x, float y, char *text, float r, float g, float b)
{ {
static char buffer[99999]; // ~500 chars 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) static int stb_easy_font_width(char *text)
{ {
float len = 0; float len = 0;
float max_len = 0;
while (*text) { while (*text) {
len += stb_easy_font_charinfo[*text-32].advance & 15; if (*text == '\n') {
len += stb_easy_font_spacing_val; 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; ++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 #endif

View File

@ -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 no warranty implied; use at your own risk
Do this: Do this:
@ -146,6 +146,7 @@
Latest revision history: 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.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.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA
2.07 (2015-09-13) partial animated GIF support 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) while (cur + n > limit)
limit *= 2; limit *= 2;
q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); 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"); if (q == NULL) return stbi__err("outofmem", "Out of memory");
z->zout_start = q; z->zout_start = q;
z->zout = q + cur; 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; if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096;
while (ioff + c.length > idata_limit) while (ioff + c.length > idata_limit)
idata_limit *= 2; 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"); 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; z->idata = p;
} }
@ -6456,6 +6459,7 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int
/* /*
revision history: 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 2.09 (2016-01-16) allow comments in PNM files
16-bit-per-pixel TGA (not bit-per-component) 16-bit-per-pixel TGA (not bit-per-component)
info() for TGA could break due to .hdr handling info() for TGA could break due to .hdr handling