Add blender internal font.
authorDiego Borghetti <bdiego@gmail.com>
Mon, 30 Mar 2009 05:32:46 +0000 (05:32 +0000)
committerDiego Borghetti <bdiego@gmail.com>
Mon, 30 Mar 2009 05:32:46 +0000 (05:32 +0000)
This is the old bmfont library but using textures.

I made small test in the space Info and work fine,
commit now to finish tomorrow from work.

source/blender/blenfont/BLF_api.h
source/blender/blenfont/intern/blf.c
source/blender/blenfont/intern/blf_font.c
source/blender/blenfont/intern/blf_font_helv10.h [new file with mode: 0644]
source/blender/blenfont/intern/blf_internal.c [new file with mode: 0644]
source/blender/blenfont/intern/blf_internal.h
source/blender/blenfont/intern/blf_internal_types.h

index 0e96bf8ceb135c6db6e62e33d48e98a6dd0a8b6b..71554df57abc6688b6e396e0862619b582c95292 100644 (file)
@@ -52,6 +52,9 @@ void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
 void BLF_enable(int option);
 void BLF_disable(int option);
 
+/* return the id of the current font. */
+int BLF_get(void);
+
 /* Read the .Blanguages file, return 1 on success or 0 if fails. */
 int BLF_lang_init(void);
 
index 43c85b78977094bf678a27a094880b3b02abd048..8e3b27bb42586a6d1b259cfdf7f1e8f41f9a167d 100644 (file)
@@ -165,7 +165,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
        FontBLF *font;
        int i;
 
-       if (!name || !mem || !mem_size)
+       if (!name)
                return(-1);
 
        i= blf_search(name);
@@ -181,19 +181,27 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
                return(-1);
        }
 
-#ifdef WITH_FREETYPE2
-       font= blf_font_new_from_mem(name, mem, mem_size);
+       font= blf_internal_new(name);
        if (!font) {
-               printf("Can't load font, %s from memory!!\n", name);
-               return(-1);
+#ifdef WITH_FREETYPE2
+               if (!mem || !mem_size) {
+                       printf("Can't load font, %s from memory!!\n", name);
+                       return(-1);
+               }
+
+               font= blf_font_new_from_mem(name, mem, mem_size);
+#endif /* WITH_FREETYPE2 */
+
+               if (!font) {
+                       printf("Can't load font, %s from memory!!\n", name);
+                       return(-1);
+               }
        }
 
        global_font[global_font_num]= font;
        i= global_font_num;
        global_font_num++;
        return(i);
-#endif /* WITH_FREETYPE2 */
-       return(-1);
 }
 
 void BLF_set(int fontid)
@@ -202,6 +210,11 @@ void BLF_set(int fontid)
                global_font_cur= fontid;
 }
 
+int BLF_get(void)
+{
+       return(global_font_cur);
+}
+
 void BLF_enable(int option)
 {
        FontBLF *font;
@@ -272,7 +285,7 @@ void BLF_draw(char *str)
        FontBLF *font;
 
        font= global_font[global_font_cur];
-       if (font && font->draw && font->glyph_cache) {
+       if (font && font->draw) {
                glEnable(GL_BLEND);
                glEnable(GL_TEXTURE_2D);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -297,7 +310,7 @@ void BLF_boundbox(char *str, rctf *box)
        FontBLF *font;
 
        font= global_font[global_font_cur];
-       if (font && font->boundbox_get && font->glyph_cache)
+       if (font && font->boundbox_get)
                (*font->boundbox_get)(font, str, box);
 }
 
@@ -306,7 +319,7 @@ float BLF_width(char *str)
        FontBLF *font;
 
        font= global_font[global_font_cur];
-       if (font && font->width_get && font->glyph_cache)
+       if (font && font->width_get)
                return((*font->width_get)(font, str));
        return(0.0f);
 }
@@ -316,7 +329,7 @@ float BLF_height(char *str)
        FontBLF *font;
 
        font= global_font[global_font_cur];
-       if (font && font->height_get && font->glyph_cache)
+       if (font && font->height_get)
                return((*font->height_get)(font, str));
        return(0.0f);
 }
index a80e97327f3d6cdb20a99f4e8fb359353db419f4..d5c6ae5b359325d05a25fd529a011e52d8691bc0 100644 (file)
@@ -110,6 +110,9 @@ void blf_font_draw(FontBLF *font, char *str)
        int pen_x, pen_y;
        int i, has_kerning;
 
+       if (!font->glyph_cache)
+               return;
+
        face= (FT_Face)font->engine;
        i= 0;
        pen_x= 0;
@@ -161,6 +164,9 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
        int pen_x, pen_y;
        int i, has_kerning;
 
+       if (!font->glyph_cache)
+               return;
+
        face= (FT_Face)font->engine;
        box->xmin= 32000.0f;
        box->xmax= -32000.0f;
@@ -228,6 +234,9 @@ float blf_font_width(FontBLF *font, char *str)
 {
        rctf box;
 
+       if (!font->glyph_cache)
+               return(0.0f);
+
        blf_font_boundbox(font, str, &box);
        return((box.xmax - box.xmin) * font->aspect);
 }
@@ -236,6 +245,9 @@ float blf_font_height(FontBLF *font, char *str)
 {
        rctf box;
 
+       if (!font->glyph_cache)
+               return(0.0f);
+
        blf_font_boundbox(font, str, &box);
        return((box.ymax - box.ymin) * font->aspect);
 }
diff --git a/source/blender/blenfont/intern/blf_font_helv10.h b/source/blender/blenfont/intern/blf_font_helv10.h
new file mode 100644 (file)
index 0000000..7a0a48d
--- /dev/null
@@ -0,0 +1,487 @@
+/**
+ * $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 *****
+ */
+
+#ifndef BLF_FONT_HELV10_H
+#define BLF_FONT_HELV10_H
+
+static unsigned char helv10_bitmap_data[]= {
+       0x80,0x00,0x80,0x80,0x80,0x80,0x80,0x80,
+       0xa0,0xa0,0x50,0x50,0xf8,0x28,0x7c,0x28,
+       0x28,0x20,0x70,0xa8,0x28,0x70,0xa0,0xa8,
+       0x70,0x20,0x26,0x29,0x16,0x10,0x08,0x68,
+       0x94,0x64,0x64,0x98,0x98,0xa4,0x60,0x50,
+       0x50,0x20,0x80,0x40,0x40,0x20,0x40,0x40,
+       0x80,0x80,0x80,0x80,0x40,0x40,0x20,0x80,
+       0x40,0x40,0x20,0x20,0x20,0x20,0x40,0x40,
+       0x80,0xa0,0x40,0xa0,0x20,0x20,0xf8,0x20,
+       0x20,0x80,0x40,0x40,0xf8,0x80,0x80,0x80,
+       0x40,0x40,0x40,0x40,0x20,0x20,0x70,0x88,
+       0x88,0x88,0x88,0x88,0x88,0x70,0x40,0x40,
+       0x40,0x40,0x40,0x40,0xc0,0x40,0xf8,0x80,
+       0x40,0x30,0x08,0x08,0x88,0x70,0x70,0x88,
+       0x08,0x08,0x30,0x08,0x88,0x70,0x10,0x10,
+       0xf8,0x90,0x50,0x50,0x30,0x10,0x70,0x88,
+       0x08,0x08,0xf0,0x80,0x80,0xf8,0x70,0x88,
+       0x88,0xc8,0xb0,0x80,0x88,0x70,0x40,0x40,
+       0x20,0x20,0x10,0x10,0x08,0xf8,0x70,0x88,
+       0x88,0x88,0x70,0x88,0x88,0x70,0x70,0x88,
+       0x08,0x68,0x98,0x88,0x88,0x70,0x80,0x00,
+       0x00,0x00,0x00,0x80,0x80,0x40,0x40,0x00,
+       0x00,0x00,0x00,0x40,0x20,0x40,0x80,0x40,
+       0x20,0xf0,0x00,0xf0,0x80,0x40,0x20,0x40,
+       0x80,0x40,0x00,0x40,0x40,0x20,0x10,0x90,
+       0x60,0x3e,0x00,0x40,0x00,0x9b,0x00,0xa4,
+       0x80,0xa4,0x80,0xa2,0x40,0x92,0x40,0x4d,
+       0x40,0x20,0x80,0x1f,0x00,0x82,0x82,0x7c,
+       0x44,0x28,0x28,0x10,0x10,0xf0,0x88,0x88,
+       0x88,0xf0,0x88,0x88,0xf0,0x78,0x84,0x80,
+       0x80,0x80,0x80,0x84,0x78,0xf0,0x88,0x84,
+       0x84,0x84,0x84,0x88,0xf0,0xf8,0x80,0x80,
+       0x80,0xf8,0x80,0x80,0xf8,0x80,0x80,0x80,
+       0x80,0xf0,0x80,0x80,0xf8,0x74,0x8c,0x84,
+       0x8c,0x80,0x80,0x84,0x78,0x84,0x84,0x84,
+       0x84,0xfc,0x84,0x84,0x84,0x80,0x80,0x80,
+       0x80,0x80,0x80,0x80,0x80,0x60,0x90,0x10,
+       0x10,0x10,0x10,0x10,0x10,0x88,0x88,0x90,
+       0x90,0xe0,0xa0,0x90,0x88,0xf0,0x80,0x80,
+       0x80,0x80,0x80,0x80,0x80,0x92,0x92,0x92,
+       0xaa,0xaa,0xc6,0xc6,0x82,0x8c,0x8c,0x94,
+       0x94,0xa4,0xa4,0xc4,0xc4,0x78,0x84,0x84,
+       0x84,0x84,0x84,0x84,0x78,0x80,0x80,0x80,
+       0x80,0xf0,0x88,0x88,0xf0,0x02,0x7c,0x8c,
+       0x94,0x84,0x84,0x84,0x84,0x78,0x88,0x88,
+       0x88,0x88,0xf0,0x88,0x88,0xf0,0x70,0x88,
+       0x88,0x08,0x70,0x80,0x88,0x70,0x20,0x20,
+       0x20,0x20,0x20,0x20,0x20,0xf8,0x78,0x84,
+       0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x28,
+       0x28,0x44,0x44,0x44,0x82,0x82,0x22,0x00,
+       0x22,0x00,0x22,0x00,0x55,0x00,0x49,0x00,
+       0x49,0x00,0x88,0x80,0x88,0x80,0x88,0x88,
+       0x50,0x50,0x20,0x50,0x88,0x88,0x10,0x10,
+       0x10,0x28,0x28,0x44,0x44,0x82,0xf8,0x80,
+       0x40,0x20,0x20,0x10,0x08,0xf8,0xc0,0x80,
+       0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xc0,
+       0x20,0x20,0x40,0x40,0x40,0x40,0x80,0x80,
+       0xc0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+       0x40,0xc0,0x88,0x50,0x50,0x20,0x20,0xfc,
+       0x80,0x80,0x40,0x68,0x90,0x90,0x70,0x10,
+       0xe0,0xb0,0xc8,0x88,0x88,0xc8,0xb0,0x80,
+       0x80,0x60,0x90,0x80,0x80,0x90,0x60,0x68,
+       0x98,0x88,0x88,0x98,0x68,0x08,0x08,0x60,
+       0x90,0x80,0xf0,0x90,0x60,0x40,0x40,0x40,
+       0x40,0x40,0xe0,0x40,0x30,0x70,0x08,0x68,
+       0x98,0x88,0x88,0x98,0x68,0x88,0x88,0x88,
+       0x88,0xc8,0xb0,0x80,0x80,0x80,0x80,0x80,
+       0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,
+       0x80,0x80,0x80,0x80,0x00,0x80,0x90,0x90,
+       0xa0,0xc0,0xa0,0x90,0x80,0x80,0x80,0x80,
+       0x80,0x80,0x80,0x80,0x80,0x80,0x92,0x92,
+       0x92,0x92,0x92,0xec,0x88,0x88,0x88,0x88,
+       0xc8,0xb0,0x70,0x88,0x88,0x88,0x88,0x70,
+       0x80,0x80,0xb0,0xc8,0x88,0x88,0xc8,0xb0,
+       0x08,0x08,0x68,0x98,0x88,0x88,0x98,0x68,
+       0x80,0x80,0x80,0x80,0xc0,0xa0,0x60,0x90,
+       0x10,0x60,0x90,0x60,0x60,0x40,0x40,0x40,
+       0x40,0xe0,0x40,0x40,0x70,0x90,0x90,0x90,
+       0x90,0x90,0x20,0x20,0x50,0x50,0x88,0x88,
+       0x28,0x28,0x54,0x54,0x92,0x92,0x88,0x88,
+       0x50,0x20,0x50,0x88,0x80,0x40,0x40,0x60,
+       0xa0,0xa0,0x90,0x90,0xf0,0x80,0x40,0x20,
+       0x10,0xf0,0x20,0x40,0x40,0x40,0x40,0x80,
+       0x40,0x40,0x40,0x20,0x80,0x80,0x80,0x80,
+       0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,
+       0x40,0x40,0x40,0x20,0x40,0x40,0x40,0x80,
+       0x98,0x64,0x80,0x80,0x80,0x80,0x80,0x80,
+       0x00,0x80,0x40,0x70,0xa8,0xa0,0xa0,0xa8,
+       0x70,0x10,0xb0,0x48,0x40,0x40,0xe0,0x40,
+       0x48,0x30,0x90,0x60,0x90,0x90,0x60,0x90,
+       0x20,0xf8,0x20,0xf8,0x50,0x50,0x88,0x88,
+       0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x80,
+       0x80,0x80,0x70,0x88,0x18,0x70,0xc8,0x98,
+       0x70,0xc0,0x88,0x70,0xa0,0x38,0x44,0x9a,
+       0xa2,0x9a,0x44,0x38,0xe0,0x00,0xa0,0x20,
+       0xe0,0x28,0x50,0xa0,0x50,0x28,0x08,0x08,
+       0xf8,0xe0,0x38,0x44,0xaa,0xb2,0xba,0x44,
+       0x38,0xe0,0x60,0x90,0x90,0x60,0xf8,0x00,
+       0x20,0x20,0xf8,0x20,0x20,0xe0,0x40,0xa0,
+       0x60,0xc0,0x20,0x40,0xe0,0x80,0x40,0x80,
+       0x80,0xf0,0x90,0x90,0x90,0x90,0x90,0x28,
+       0x28,0x28,0x28,0x28,0x68,0xe8,0xe8,0xe8,
+       0x7c,0xc0,0xc0,0x40,0x40,0x40,0xc0,0x40,
+       0xe0,0x00,0xe0,0xa0,0xe0,0xa0,0x50,0x28,
+       0x50,0xa0,0x21,0x00,0x17,0x80,0x13,0x00,
+       0x09,0x00,0x48,0x00,0x44,0x00,0xc4,0x00,
+       0x42,0x00,0x27,0x12,0x15,0x0b,0x48,0x44,
+       0xc4,0x42,0x21,0x00,0x17,0x80,0x13,0x00,
+       0x09,0x00,0xc8,0x00,0x24,0x00,0x44,0x00,
+       0xe2,0x00,0x60,0x90,0x80,0x40,0x20,0x20,
+       0x00,0x20,0x82,0x82,0x7c,0x44,0x28,0x28,
+       0x10,0x10,0x00,0x10,0x20,0x82,0x82,0x7c,
+       0x44,0x28,0x28,0x10,0x10,0x00,0x10,0x08,
+       0x82,0x82,0x7c,0x44,0x28,0x28,0x10,0x10,
+       0x00,0x28,0x10,0x82,0x82,0x7c,0x44,0x28,
+       0x28,0x10,0x10,0x00,0x28,0x14,0x82,0x82,
+       0x7c,0x44,0x28,0x28,0x10,0x10,0x00,0x28,
+       0x82,0x82,0x7c,0x44,0x28,0x28,0x10,0x10,
+       0x10,0x28,0x10,0x8f,0x80,0x88,0x00,0x78,
+       0x00,0x48,0x00,0x2f,0x80,0x28,0x00,0x18,
+       0x00,0x1f,0x80,0x30,0x10,0x78,0x84,0x80,
+       0x80,0x80,0x80,0x84,0x78,0xf8,0x80,0x80,
+       0x80,0xf8,0x80,0x80,0xf8,0x00,0x20,0x40,
+       0xf8,0x80,0x80,0x80,0xf8,0x80,0x80,0xf8,
+       0x00,0x20,0x10,0xf8,0x80,0x80,0xf8,0x80,
+       0x80,0x80,0xf8,0x00,0x50,0x20,0xf8,0x80,
+       0x80,0x80,0xf8,0x80,0x80,0xf8,0x00,0x50,
+       0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+       0x00,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
+       0x80,0x80,0x80,0x00,0x80,0x40,0x40,0x40,
+       0x40,0x40,0x40,0x40,0x40,0x40,0x00,0xa0,
+       0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+       0x40,0x00,0xa0,0x78,0x44,0x42,0x42,0xf2,
+       0x42,0x44,0x78,0x8c,0x8c,0x94,0x94,0xa4,
+       0xa4,0xc4,0xc4,0x00,0x50,0x28,0x78,0x84,
+       0x84,0x84,0x84,0x84,0x84,0x78,0x00,0x10,
+       0x20,0x78,0x84,0x84,0x84,0x84,0x84,0x84,
+       0x78,0x00,0x10,0x08,0x78,0x84,0x84,0x84,
+       0x84,0x84,0x84,0x78,0x00,0x28,0x10,0x78,
+       0x84,0x84,0x84,0x84,0x84,0x84,0x78,0x00,
+       0x50,0x28,0x78,0x84,0x84,0x84,0x84,0x84,
+       0x84,0x78,0x00,0x48,0x88,0x50,0x20,0x50,
+       0x88,0x80,0x78,0xc4,0xa4,0xa4,0x94,0x94,
+       0x8c,0x78,0x04,0x78,0x84,0x84,0x84,0x84,
+       0x84,0x84,0x84,0x00,0x10,0x20,0x78,0x84,
+       0x84,0x84,0x84,0x84,0x84,0x84,0x00,0x20,
+       0x10,0x78,0x84,0x84,0x84,0x84,0x84,0x84,
+       0x84,0x00,0x28,0x10,0x78,0x84,0x84,0x84,
+       0x84,0x84,0x84,0x84,0x00,0x48,0x10,0x10,
+       0x10,0x28,0x28,0x44,0x44,0x82,0x00,0x10,
+       0x08,0x80,0x80,0xf0,0x88,0x88,0xf0,0x80,
+       0x80,0xa0,0x90,0x90,0x90,0xa0,0x90,0x90,
+       0x60,0x68,0x90,0x90,0x70,0x10,0xe0,0x00,
+       0x20,0x40,0x68,0x90,0x90,0x70,0x10,0xe0,
+       0x00,0x20,0x10,0x68,0x90,0x90,0x70,0x10,
+       0xe0,0x00,0x50,0x20,0x68,0x90,0x90,0x70,
+       0x10,0xe0,0x00,0xa0,0x50,0x68,0x90,0x90,
+       0x70,0x10,0xe0,0x00,0x50,0x68,0x90,0x90,
+       0x70,0x10,0xe0,0x20,0x50,0x20,0x6c,0x92,
+       0x90,0x7e,0x12,0xec,0x60,0x20,0x60,0x90,
+       0x80,0x80,0x90,0x60,0x60,0x90,0x80,0xf0,
+       0x90,0x60,0x00,0x20,0x40,0x60,0x90,0x80,
+       0xf0,0x90,0x60,0x00,0x40,0x20,0x60,0x90,
+       0x80,0xf0,0x90,0x60,0x00,0x50,0x20,0x60,
+       0x90,0x80,0xf0,0x90,0x60,0x00,0x50,0x40,
+       0x40,0x40,0x40,0x40,0x40,0x00,0x40,0x80,
+       0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x80,
+       0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
+       0xa0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+       0x00,0xa0,0x70,0x88,0x88,0x88,0x88,0x78,
+       0x90,0x60,0x50,0x90,0x90,0x90,0x90,0x90,
+       0xe0,0x00,0xa0,0x50,0x70,0x88,0x88,0x88,
+       0x88,0x70,0x00,0x20,0x40,0x70,0x88,0x88,
+       0x88,0x88,0x70,0x00,0x20,0x10,0x70,0x88,
+       0x88,0x88,0x88,0x70,0x00,0x50,0x20,0x70,
+       0x88,0x88,0x88,0x88,0x70,0x00,0x50,0x28,
+       0x70,0x88,0x88,0x88,0x88,0x70,0x00,0x50,
+       0x20,0x00,0xf8,0x00,0x20,0x70,0x88,0xc8,
+       0xa8,0x98,0x74,0x70,0x90,0x90,0x90,0x90,
+       0x90,0x00,0x20,0x40,0x70,0x90,0x90,0x90,
+       0x90,0x90,0x00,0x40,0x20,0x70,0x90,0x90,
+       0x90,0x90,0x90,0x00,0x50,0x20,0x70,0x90,
+       0x90,0x90,0x90,0x90,0x00,0x50,0x80,0x40,
+       0x40,0x60,0xa0,0xa0,0x90,0x90,0x00,0x20,
+       0x10,0x80,0x80,0xb0,0xc8,0x88,0x88,0xc8,
+       0xb0,0x80,0x80,0x80,0x40,0x40,0x60,0xa0,
+       0xa0,0x90,0x90,0x00,0x50,
+};
+
+FontDataBLF blf_font_helv10 = {
+       -1, -2,
+       10, 11,
+       {
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0, 0, 0, 0, 12, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0, 0, 0, 0, 3, -1},
+               {1, 8, -1, 0, 3, 0},
+               {3, 2, -1, -6, 4, 8},
+               {6, 7, 0, 0, 6, 10},
+               {5, 9, 0, 1, 6, 17},
+               {8, 8, 0, 0, 9, 26},
+               {6, 8, -1, 0, 8, 34},
+               {2, 3, -1, -5, 3, 42},
+               {3, 10, 0, 2, 4, 45},
+               {3, 10, -1, 2, 4, 55},
+               {3, 3, 0, -5, 4, 65},
+               {5, 5, 0, -1, 6, 68},
+               {2, 3, 0, 2, 3, 73},
+               {5, 1, -1, -3, 7, 76},
+               {1, 1, -1, 0, 3, 77},
+               {3, 8, 0, 0, 3, 78},
+               {5, 8, 0, 0, 6, 86},
+               {2, 8, -1, 0, 6, 94},
+               {5, 8, 0, 0, 6, 102},
+               {5, 8, 0, 0, 6, 110},
+               {5, 8, 0, 0, 6, 118},
+               {5, 8, 0, 0, 6, 126},
+               {5, 8, 0, 0, 6, 134},
+               {5, 8, 0, 0, 6, 142},
+               {5, 8, 0, 0, 6, 150},
+               {5, 8, 0, 0, 6, 158},
+               {1, 6, -1, 0, 3, 166},
+               {2, 8, 0, 2, 3, 172},
+               {3, 5, -1, -1, 6, 180},
+               {4, 3, 0, -2, 5, 185},
+               {3, 5, -1, -1, 6, 188},
+               {4, 8, -1, 0, 6, 193},
+               {10, 10, 0, 2, 11, 201},
+               {7, 8, 0, 0, 7, 221},
+               {5, 8, -1, 0, 7, 229},
+               {6, 8, -1, 0, 8, 237},
+               {6, 8, -1, 0, 8, 245},
+               {5, 8, -1, 0, 7, 253},
+               {5, 8, -1, 0, 6, 261},
+               {6, 8, -1, 0, 8, 269},
+               {6, 8, -1, 0, 8, 277},
+               {1, 8, -1, 0, 3, 285},
+               {4, 8, 0, 0, 5, 293},
+               {5, 8, -1, 0, 7, 301},
+               {4, 8, -1, 0, 6, 309},
+               {7, 8, -1, 0, 9, 317},
+               {6, 8, -1, 0, 8, 325},
+               {6, 8, -1, 0, 8, 333},
+               {5, 8, -1, 0, 7, 341},
+               {7, 9, -1, 1, 8, 349},
+               {5, 8, -1, 0, 7, 358},
+               {5, 8, -1, 0, 7, 366},
+               {5, 8, 0, 0, 5, 374},
+               {6, 8, -1, 0, 8, 382},
+               {7, 8, 0, 0, 7, 390},
+               {9, 8, 0, 0, 9, 398},
+               {5, 8, -1, 0, 7, 414},
+               {7, 8, 0, 0, 7, 422},
+               {5, 8, -1, 0, 7, 430},
+               {2, 10, -1, 2, 3, 438},
+               {3, 8, 0, 0, 3, 448},
+               {2, 10, 0, 2, 3, 456},
+               {5, 5, 0, -3, 6, 466},
+               {6, 1, 0, 2, 6, 471},
+               {2, 3, 0, -5, 3, 472},
+               {5, 6, 0, 0, 5, 475},
+               {5, 8, 0, 0, 6, 481},
+               {4, 6, 0, 0, 5, 489},
+               {5, 8, 0, 0, 6, 495},
+               {4, 6, 0, 0, 5, 503},
+               {4, 8, 0, 0, 4, 509},
+               {5, 8, 0, 2, 6, 517},
+               {5, 8, 0, 0, 6, 525},
+               {1, 8, 0, 0, 2, 533},
+               {1, 9, 0, 1, 2, 541},
+               {4, 8, 0, 0, 5, 550},
+               {1, 8, 0, 0, 2, 558},
+               {7, 6, 0, 0, 8, 566},
+               {5, 6, 0, 0, 6, 572},
+               {5, 6, 0, 0, 6, 578},
+               {5, 8, 0, 2, 6, 584},
+               {5, 8, 0, 2, 6, 592},
+               {3, 6, 0, 0, 4, 600},
+               {4, 6, 0, 0, 5, 606},
+               {3, 8, 0, 0, 4, 612},
+               {4, 6, 0, 0, 5, 620},
+               {5, 6, 0, 0, 6, 626},
+               {7, 6, 0, 0, 8, 632},
+               {5, 6, 0, 0, 6, 638},
+               {4, 8, 0, 2, 5, 644},
+               {4, 6, 0, 0, 5, 652},
+               {3, 10, 0, 2, 3, 658},
+               {1, 10, -1, 2, 3, 668},
+               {3, 10, 0, 2, 3, 678},
+               {6, 2, 0, -3, 7, 688},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0,0,0,0,0, -1},
+               {0, 0, 0, 0, 3, -1},
+               {1, 8, -1, 2, 3, 690},
+               {5, 8, 0, 1, 6, 698},
+               {5, 8, 0, 0, 6, 706},
+               {4, 6, 0, -1, 5, 714},
+               {5, 8, 0, 0, 6, 720},
+               {1, 10, -1, 2, 3, 728},
+               {5, 10, 0, 2, 6, 738},
+               {3, 1, 0, -7, 3, 748},
+               {7, 7, -1, 0, 9, 749},
+               {3, 5, 0, -3, 4, 756},
+               {5, 5, 0, 0, 6, 761},
+               {5, 3, -1, -2, 7, 766},
+               {3, 1, 0, -3, 4, 769},
+               {7, 7, -1, 0, 9, 770},
+               {3, 1, 0, -7, 3, 777},
+               {4, 4, 0, -3, 4, 778},
+               {5, 7, 0, 0, 6, 782},
+               {3, 4, 0, -3, 3, 789},
+               {3, 4, 0, -3, 3, 793},
+               {2, 2, 0, -6, 3, 797},
+               {4, 8, 0, 2, 5, 799},
+               {6, 10, 0, 2, 6, 807},
+               {2, 1, 0, -3, 3, 817},
+               {2, 2, 0, 2, 3, 818},
+               {2, 4, 0, -3, 3, 820},
+               {3, 5, 0, -3, 4, 824},
+               {5, 5, 0, 0, 6, 829},
+               {9, 8, 0, 0, 9, 834},
+               {8, 8, 0, 0, 9, 850},
+               {9, 8, 0, 0, 9, 858},
+               {4, 8, -1, 2, 6, 874},
+               {7, 11, 0, 0, 7, 882},
+               {7, 11, 0, 0, 7, 893},
+               {7, 11, 0, 0, 7, 904},
+               {7, 11, 0, 0, 7, 915},
+               {7, 10, 0, 0, 7, 926},
+               {7, 11, 0, 0, 7, 936},
+               {9, 8, 0, 0, 10, 947},
+               {6, 10, -1, 2, 8, 963},
+               {5, 11, -1, 0, 7, 973},
+               {5, 11, -1, 0, 7, 984},
+               {5, 11, -1, 0, 7, 995},
+               {5, 10, -1, 0, 7, 1006},
+               {2, 11, 0, 0, 3, 1016},
+               {2, 11, -1, 0, 3, 1027},
+               {3, 11, 0, 0, 3, 1038},
+               {3, 10, 0, 0, 3, 1049},
+               {7, 8, 0, 0, 8, 1059},
+               {6, 11, -1, 0, 8, 1067},
+               {6, 11, -1, 0, 8, 1078},
+               {6, 11, -1, 0, 8, 1089},
+               {6, 11, -1, 0, 8, 1100},
+               {6, 11, -1, 0, 8, 1111},
+               {6, 10, -1, 0, 8, 1122},
+               {5, 5, 0, -1, 6, 1132},
+               {6, 10, -1, 1, 8, 1137},
+               {6, 11, -1, 0, 8, 1147},
+               {6, 11, -1, 0, 8, 1158},
+               {6, 11, -1, 0, 8, 1169},
+               {6, 10, -1, 0, 8, 1180},
+               {7, 11, 0, 0, 7, 1190},
+               {5, 8, -1, 0, 7, 1201},
+               {4, 8, 0, 0, 5, 1209},
+               {5, 9, 0, 0, 5, 1217},
+               {5, 9, 0, 0, 5, 1226},
+               {5, 9, 0, 0, 5, 1235},
+               {5, 9, 0, 0, 5, 1244},
+               {5, 8, 0, 0, 5, 1253},
+               {5, 9, 0, 0, 5, 1261},
+               {7, 6, 0, 0, 8, 1270},
+               {4, 8, 0, 2, 5, 1276},
+               {4, 9, 0, 0, 5, 1284},
+               {4, 9, 0, 0, 5, 1293},
+               {4, 9, 0, 0, 5, 1302},
+               {4, 8, 0, 0, 5, 1311},
+               {2, 9, 1, 0, 2, 1319},
+               {2, 9, 0, 0, 2, 1328},
+               {3, 9, 1, 0, 2, 1337},
+               {3, 8, 0, 0, 2, 1346},
+               {5, 9, 0, 0, 6, 1354},
+               {4, 9, 0, 0, 5, 1363},
+               {5, 9, 0, 0, 6, 1372},
+               {5, 9, 0, 0, 6, 1381},
+               {5, 9, 0, 0, 6, 1390},
+               {5, 9, 0, 0, 6, 1399},
+               {5, 8, 0, 0, 6, 1408},
+               {5, 5, 0, -1, 6, 1416},
+               {6, 6, 0, 0, 6, 1421},
+               {4, 9, 0, 0, 5, 1427},
+               {4, 9, 0, 0, 5, 1436},
+               {4, 9, 0, 0, 5, 1445},
+               {4, 8, 0, 0, 5, 1454},
+               {4, 11, 0, 2, 5, 1462},
+               {5, 10, 0, 2, 6, 1473},
+               {4, 10, 0, 2, 5, 1483},
+       },
+       helv10_bitmap_data,
+       0
+};
+
+#endif /* BLF_FONT_HELV10_H */
diff --git a/source/blender/blenfont/intern/blf_internal.c b/source/blender/blenfont/intern/blf_internal.c
new file mode 100644 (file)
index 0000000..f3a74db
--- /dev/null
@@ -0,0 +1,289 @@
+/**
+ * $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>
+
+#ifdef WITH_FREETYPE2
+
+#include <ft2build.h>
+
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#endif /* WITH_FREETYPE2 */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+#include "DNA_vec_types.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_linklist.h"      /* linknode */
+#include "BLI_string.h"
+#include "BLI_arithb.h"
+
+#include "BIF_gl.h"
+#include "BLF_api.h"
+
+#include "blf_internal_types.h"
+#include "blf_internal.h"
+#include "blf_font_helv10.h"
+
+
+int blf_internal_get_texture(FontBLF *font)
+{
+       FontDataBLF *data;
+       CharDataBLF *cd;
+       int width;
+       int height;
+       int c_rows, c_cols, c_width, c_height;
+       int i_width, i_height;
+       GLubyte *img, *img_row, *chr_row, *img_pxl;
+       int base_line, i, cell_x, cell_y, y, x;
+       int byte_idx, bit_idx;
+
+       data= (FontDataBLF *)font->engine;
+       if (data->texid != 0)
+               return(0);
+
+       width= data->xmax - data->xmin;
+       height= data->ymax - data->ymin;
+       c_rows= 16;
+       c_cols= 16;
+       c_width= 16;
+       c_height= 16;
+       i_width= c_cols * c_width;
+       i_height= c_rows * c_height;
+       base_line= -(data->ymin);
+       img= (GLubyte *)malloc(i_height * i_width);
+       memset((void *)img, 0, i_height * i_width);
+
+       if (width >= 16 || height >= 16) {
+               printf("Warning: Bad font size for: %s\n", font->name);
+               return(-1);
+       }
+
+       for (i= 0; i < 256; i++) {
+               cd= &data->chars[i];
+
+               if (cd->data_offset != -1) {
+                       cell_x= i%16;
+                       cell_y= i/16;
+
+                       for (y= 0; y < cd->height; y++) {
+                               img_row = &img[(cell_y*c_height + y + base_line - cd->yorig)*i_width];
+                               chr_row = &data->bitmap_data[cd->data_offset + ((cd->width+7)/8)*y];
+
+                               for (x= 0; x < cd->width; x++) {
+                                       img_pxl= &img_row[(cell_x*c_width + x - cd->xorig)];
+                                       byte_idx= x/8;
+                                       bit_idx= 7 - (x%8);
+
+                                       if (chr_row[byte_idx]&(1<<bit_idx)) {
+                                               img_pxl[0]= 255;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       glGenTextures(1, &data->texid);
+       glBindTexture(GL_TEXTURE_2D, data->texid);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA4, i_width, i_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, img);
+       if (glGetError()) {
+               glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE4_ALPHA4, i_width, i_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, img);
+       }
+       
+       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       free((void *)img);
+       return(0);
+}
+
+void blf_internal_size(FontBLF *font, int size, int dpi)
+{
+       return;
+}
+
+void blf_internal_draw(FontBLF *font, char *str)
+{
+       FontDataBLF *data;
+       CharDataBLF *cd;
+       unsigned char c;
+       float pos, cell_x, cell_y, x, y, z;
+       int base_line;
+       GLint cur_tex;
+
+       data= (FontDataBLF *)font->engine;
+       base_line= -(data->ymin);
+       pos= 0;
+       x= 0.0f;
+       y= 0.0f;
+       z= 0.0f;
+
+       glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex);
+       if (cur_tex != data->texid)
+               glBindTexture(GL_TEXTURE_2D, data->texid);
+
+       glBegin(GL_QUADS);
+       while ((c= (unsigned char) *str++)) {
+               cd= &data->chars[c];
+
+               if (cd->data_offset != -1) {
+                       cell_x= (c%16)/16.0;
+                       cell_y= (c/16)/16.0;
+
+                       glTexCoord2f(cell_x + 1.0/16.0, cell_y);
+                       glVertex3f(x + pos + 16.0, -base_line + y + 0.0, z);
+
+                       glTexCoord2f(cell_x + 1.0/16.0, cell_y + 1.0/16.0);
+                       glVertex3f(x + pos + 16.0, -base_line + y + 16.0, z);
+
+                       glTexCoord2f(cell_x, cell_y + 1.0/16.0);
+                       glVertex3f(x + pos + 0.0, -base_line + y + 16.0, z);
+
+                       glTexCoord2f(cell_x, cell_y);
+                       glVertex3f(x + pos + 0.0, -base_line + y + 0.0, z);
+               }
+               
+               pos += cd->advance;
+       }
+       glEnd();
+}
+
+void blf_internal_boundbox(FontBLF *font, char *str, rctf *box)
+{
+       FontDataBLF *data;
+       unsigned char c;
+       int length= 0;
+       int ascent= 0;
+       int descent= 0;
+
+       data= (FontDataBLF *)font->engine;
+       while ((c= (unsigned char) *str++)) {
+               length += data->chars[c].advance;
+               int d = data->chars[c].yorig;
+               int a = data->chars[c].height - data->chars[c].yorig;
+               if (a > ascent)
+                       ascent= a;
+               if (d > descent)
+                       descent= d;
+       }
+       box->xmin = (float)0;
+       box->ymin = (float)-descent;
+       box->xmax = (float)length;
+       box->ymax = (float)ascent;
+}
+
+float blf_internal_width(FontBLF *font, char *str)
+{
+       FontDataBLF *data;
+       unsigned char c;
+       int length= 0;
+
+       data= (FontDataBLF *)font->engine;
+       while ((c= (unsigned char) *str++)) {
+               length += data->chars[c].advance;
+       }
+
+       return((float)(length * font->aspect));
+}
+
+float blf_internal_height(FontBLF *font, char *str)
+{
+       FontDataBLF *data;
+
+       data= (FontDataBLF *)font->engine;
+       return(((float)(data->ymax - data->ymin)) * font->aspect);
+}
+
+void blf_internal_free(FontBLF *font)
+{
+       MEM_freeN(font->name);
+       MEM_freeN(font);
+}
+
+FontBLF *blf_internal_new(char *name)
+{
+       FontBLF *font;
+
+       font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_internal_new");
+       font->name= BLI_strdup(name);
+       font->filename= NULL;
+
+       if (!strcmp(name, "helv10")) {
+               font->engine= (void *)&blf_font_helv10;
+               font->size= 10;
+       }
+       else
+               font->engine= NULL;
+
+       if (!font->engine) {
+               MEM_freeN(font->name);
+               MEM_freeN(font);
+               return(NULL);
+       }
+
+       font->type= BLF_FONT_INTERNAL;
+       font->ref= 1;
+       font->aspect= 1.0f;
+       font->pos[0]= 0.0f;
+       font->pos[1]= 0.0f;
+       font->angle= 0.0f;
+       Mat4One(font->mat);
+       font->clip_rec.xmin= 0.0f;
+       font->clip_rec.xmax= 0.0f;
+       font->clip_rec.ymin= 0.0f;
+       font->clip_rec.ymax= 0.0f;
+       font->flags= 0;
+       font->dpi= 72;
+       font->cache.first= NULL;
+       font->cache.last= NULL;
+       font->glyph_cache= NULL;
+       glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);
+
+       font->size_set= blf_internal_size;
+       font->draw= blf_internal_draw;
+       font->boundbox_get= blf_internal_boundbox;
+       font->width_get= blf_internal_width;
+       font->height_get= blf_internal_height;
+       font->free= blf_internal_free;
+
+       if (blf_internal_get_texture(font) != 0) {
+               MEM_freeN(font->name);
+               MEM_freeN(font);
+               return(NULL);
+       }
+
+       return(font);
+}
index d160df67f18b582f4d02d4bb9ccd07c8cceb4610..87d5938db9c917d5c5f55eae305548a662fe66f1 100644 (file)
@@ -38,6 +38,8 @@ int blf_dir_split(const char *str, char *file, int *size);
 int blf_font_init(void);
 void blf_font_exit(void);
 
+FontBLF *blf_internal_new(char *name);
+
 #ifdef WITH_FREETYPE2
 
 FontBLF *blf_font_new(char *name, char *filename);
index 7313eb97426ef3a04f7ba0b50cd06e8f4fc4ed85..9df04522b1fbfad57ff51b4284c027e4121313c4 100644 (file)
@@ -171,6 +171,24 @@ typedef struct FontBLF {
        void (*free)(struct FontBLF *);
 } FontBLF;
 
+typedef struct CharDataBLF {
+       signed char width, height;
+       signed char xorig, yorig;
+       signed char advance;
+       
+       short data_offset;
+} CharDataBLF;
+
+typedef struct FontDataBLF {
+       int xmin, ymin;
+       int xmax, ymax;
+
+       CharDataBLF chars[256];
+       unsigned char *bitmap_data;
+
+       GLuint texid;
+} FontDataBLF;
+
 typedef struct DirBLF {
        struct DirBLF *next;
        struct DirBLF *prev;