diff options
author | Diego Borghetti <bdiego@gmail.com> | 2009-02-11 00:41:14 +0300 |
---|---|---|
committer | Diego Borghetti <bdiego@gmail.com> | 2009-02-11 00:41:14 +0300 |
commit | 2c82163d5b20333ff13aea6b626b4cad803b7bd5 (patch) | |
tree | a5cdad92dfe8f24fd57a36cdba6270a6cf22f6c8 /source/blender | |
parent | e4ce4a00a08e3922529a550bdab7e01175d8dc94 (diff) |
commit to continue in my home.
Also I remove some of the #if 0.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenfont/intern/blf_dir.c | 4 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 1 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 47 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal.h | 6 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal_types.h | 4 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_util.c | 131 |
6 files changed, 168 insertions, 25 deletions
diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index 2472d36a1d8..dea422a1765 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -25,8 +25,6 @@ * ***** END GPL LICENSE BLOCK ***** */ -#if 0 - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -167,5 +165,3 @@ int blf_dir_split(const char *str, char *file, int *size) } return(0); } - -#endif /* zero!! */ diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 8c7ec7a480f..42043a58781 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -48,6 +48,7 @@ #include "BLI_string.h" #include "blf_internal_types.h" +#include "blf_internal.h" /* freetype2 handle. */ diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index bea49ccb387..ca8751a8746 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -48,22 +48,9 @@ #include "BLI_string.h" #include "blf_internal_types.h" +#include "blf_internal.h" -unsigned int blf_glyph_hash(unsigned int val) -{ - unsigned int key; - - key= val; - key += ~(key << 16); - key ^= (key >> 5); - key += (key << 3); - key ^= (key >> 13); - key += ~(key << 9); - key ^= (key >> 17); - return(key % 257); -} - GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi) { GlyphCacheBLF *p; @@ -169,7 +156,7 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, FT_UInt idx) GlyphBLF *p; unsigned int key; - key= blf_glyph_hash(idx); + key= blf_hash(idx); p= gc->bucket[key].first; while (p) { if (p->index == idx) @@ -260,9 +247,37 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) g->uv[1][0]= ((float)(g->xoff + g->width)) / ((float)g->p2_width); g->uv[1][1]= ((float)(g->yoff + g->height)) / ((float)g->p2_height); - key= blf_glyph_hash(g->index); + /* update the x offset for the next glyph. */ + gc->x_offs += (int)(g->box.xmax - g->box.xmin + gc->pad); + + key= blf_hash(g->index); BLI_addhead(&gc->bucket[key], g); return(g); } +void blf_glyph_render(GlyphBLF *g, float x, float y) +{ + GLint cur_tex; + float dx; + + glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex); + if (cur_tex != g->tex) + glBindTexture(GL_TEXTURE_2D, &g->tex); + + dx= floor(x + g->pos_x); + glBegin(GL_QUADS); + glTexCoord2f(g->uv[0][0], g->uv[0][1]); + glVertex2f(dx, y + g->pos_y); + + glTexCoord2f(g->uv[0][0], g->uv[1][1]); + glVertex2f(dx, y + g->pos_y - g->height); + + glTexCoord2f(g->uv[1][0], g->uv[1][1]); + glVertex2f(dx + g->width, y + g->pos_y - g->height); + + glTexCoord2f(g->uv[1][0], g->uv[0][1]); + glVertex2f(dx + g->width, y + g->pos_y); + glEnd(); +} + #endif /* zero!! */ diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index b88c83e4b13..8af94a8fb99 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -28,11 +28,11 @@ #ifndef BLF_INTERNAL_H #define BLF_INTERNAL_H -#if 0 +unsigned int blf_next_p2(unsigned int x); +unsigned int blf_hash(unsigned int val); +int blf_utf8_next(unsigned char *buf, int *iindex); char *blf_dir_search(const char *file); int blf_dir_split(const char *str, char *file, int *size); -#endif /* zero! */ - #endif /* BLF_INTERNAL_H */ diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index b9ae9dfdac7..396230410b2 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -28,8 +28,6 @@ #ifndef BLF_INTERNAL_TYPES_H #define BLF_INTERNAL_TYPES_H -#if 0 - typedef struct DirBLF { struct DirBLF *next; struct DirBLF *prev; @@ -38,6 +36,8 @@ typedef struct DirBLF { char *path; } DirBLF; +#if 0 + typedef struct _GlyphCacheBLF { struct _GlyphCacheBLF *next; struct _GlyphCacheBLF *prev; diff --git a/source/blender/blenfont/intern/blf_util.c b/source/blender/blenfont/intern/blf_util.c new file mode 100644 index 00000000000..a4ccbedc38b --- /dev/null +++ b/source/blender/blenfont/intern/blf_util.c @@ -0,0 +1,131 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +unsigned int blf_next_p2(unsigned int x) +{ + x -= 1; + x |= (x >> 16); + x |= (x >> 8); + x |= (x >> 4); + x |= (x >> 2); + x |= (x >> 1); + x += 1; + return(x); +} + +unsigned int blf_hash(unsigned int val) +{ + unsigned int key; + + key= val; + key += ~(key << 16); + key ^= (key >> 5); + key += (key << 3); + key ^= (key >> 13); + key += ~(key << 9); + key ^= (key >> 17); + return(key % 257); +} + +/* + * This function is from Imlib2 library (font_main.c), a + * library that does image file loading and saving as well + * as rendering, manipulation, arbitrary polygon support, etc. + * + * Copyright (C) 2000 Carsten Haitzler and various contributors + * The original name: imlib_font_utf8_get_next + * more info here: http://docs.enlightenment.org/api/imlib2/html/ + */ +int blf_utf8_next(unsigned char *buf, int *iindex) +{ + /* Reads UTF8 bytes from 'buf', starting at 'index' and + * returns the code point of the next valid code point. + * 'index' is updated ready for the next call. + * + * Returns 0 to indicate an error (e.g. invalid UTF8) + */ + int index= *iindex, r; + unsigned char d= buf[index++], d2, d3, d4; + + if (!d) + return(0); + + if (d < 0x80) { + *iindex= index; + return(d); + } + + if ((d & 0xe0) == 0xc0) { + /* 2 byte */ + d2= buf[index++]; + if ((d2 & 0xc0) != 0x80) + return(0); + r= d & 0x1f; /* copy lower 5 */ + r <<= 6; + r |= (d2 & 0x3f); /* copy lower 6 */ + } + else if ((d & 0xf0) == 0xe0) { + /* 3 byte */ + d2= buf[index++]; + d3= buf[index++]; + + if ((d2 & 0xc0) != 0x80 || (d3 & 0xc0) != 0x80) + return(0); + + r= d & 0x0f; /* copy lower 4 */ + r <<= 6; + r |= (d2 & 0x3f); + r <<= 6; + r |= (d3 & 0x3f); + } + else { + /* 4 byte */ + d2= buf[index++]; + d3= buf[index++]; + d4= buf[index++]; + + if ((d2 & 0xc0) != 0x80 || (d3 & 0xc0) != 0x80 || + (d4 & 0xc0) != 0x80) + return(0); + + r= d & 0x0f; /* copy lower 4 */ + r <<= 6; + r |= (d2 & 0x3f); + r <<= 6; + r |= (d3 & 0x3f); + r <<= 6; + r |= (d4 & 0x3f); + } + *iindex= index; + return(r); +} |