[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18884] branches/blender2.5/blender/source /blender/blenfont: Just commit so I can continue tomorrow from work.

Diego Borghetti bdiego at gmail.com
Mon Feb 9 08:15:22 CET 2009


Revision: 18884
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18884
Author:   bdiego
Date:     2009-02-09 08:15:22 +0100 (Mon, 09 Feb 2009)

Log Message:
-----------
Just commit so I can continue tomorrow from work.

All the code have #if 0 / #endif so nothing to worry about.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_dir.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h

Modified: branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/BLF_api.h	2009-02-09 07:08:35 UTC (rev 18883)
+++ branches/blender2.5/blender/source/blender/blenfont/BLF_api.h	2009-02-09 07:15:22 UTC (rev 18884)
@@ -49,4 +49,20 @@
 /* Return the code string for the specified language code. */
 char *BLF_lang_find_code(short langid);
 
+#if 0
+
+/* Add a path to the font dir paths. */
+void BLF_dir_add(const char *path);
+
+/* Remove a path from the font dir paths. */
+void BLF_dir_rem(const char *path);
+
+/* Return an array with all the font dir (this can be used for filesel) */
+char **BLF_dir_get(int *ndir);
+
+/* Free the data return by BLF_dir_get. */
+void BLF_dir_free(char **dirs, int count);
+
+#endif /* zero!! */
+
 #endif /* BLF_API_H */

Added: branches/blender2.5/blender/source/blender/blenfont/intern/blf_dir.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_dir.c	                        (rev 0)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_dir.c	2009-02-09 07:15:22 UTC (rev 18884)
@@ -0,0 +1,171 @@
+/**
+ * $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 *****
+ */
+
+#if 0
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_linklist.h"	/* linknode */
+#include "BLI_string.h"
+
+#include "blf_internal_types.h"
+
+static ListBase global_font_dir= { NULL, NULL };
+
+DirBLF *blf_dir_find(const char *path)
+{
+	DirBLF *p;
+	
+	p= global_font_dir.first;
+	while (p) {
+		if (!strcmp(p->path, path))
+			return(p);
+		p= p->next;
+	}
+	return(NULL);
+}
+
+void BLF_dir_add(const char *path)
+{
+	DirBLF *dir;
+	
+	dir= blf_dir_find(path);
+	if (dir) /* already in the list ? just return. */
+		return;
+	
+	dir= (DirBLF *)MEM_mallocN(sizeof(DirBLF), "BLF_dir_add");
+	dir->path= BLI_strdup(path);
+	BLI_addhead(&global_font_dir, dir);
+}
+
+void BLF_dir_rem(const char *path)
+{
+	DirBLF *dir;
+	
+	dir= blf_dir_find(path);
+	if (dir) {
+		BLI_remlink(&global_font_dir, dir);
+		MEM_freeN(dir->path);
+		MEM_freeN(dir);
+	}
+}
+
+char **BLF_dir_get(int *ndir)
+{
+	DirBLF *p;
+	char **dirs;
+	char *path;
+	int i, count;
+	
+	count= BLI_countlist(&global_font_dir);
+	if (!count)
+		return(NULL);
+	
+	dirs= (char **)MEM_mallocN(sizeof(char *) * count, "BLF_dir_get");
+	p= global_font_dir.first;
+	i= 0;
+	while (p) {
+		path= BLI_strdup(p->path);
+		dirs[i]= path;
+		p= p->next;
+	}
+	*ndir= i;
+	return(dirs);
+}
+
+void BLF_dir_free(char **dirs, int count)
+{
+	char *path;
+	int i;
+	
+	for (i= 0; i < count; i++) {
+		path= dirs[i];
+		MEM_freeN(path);
+	}
+	MEM_freeN(dirs);
+}
+
+char *blf_dir_search(char *file)
+{
+	DirBLF *dir;
+	char full_path[FILE_MAXDIR+FILE_MAXFILE];
+	char *s;
+	
+	dir= global_font_dir.first;
+	s= NULL;
+	while (dir) {
+		BLI_join_dirfile(full_path, dir->path, file);
+		if (BLI_exist(full_path)) {
+			s= (char *)MEM_mallocN(strlen(full_path)+1,"blf_dir_search");
+			strcpy(s, full_path);
+			break;
+		}
+		dir= dir->next;
+	}
+	
+	if (!s) {
+		/* check the current directory, why not ? */
+		if (BLI_exist(file))
+			s= BLI_strdup(file);
+	}
+	
+	return(s);
+}
+
+int blf_dir_split(const char *str, char *file, int *size)
+{
+	char *s, i, len;
+	
+	/* Window, Linux or Mac, this is always / */
+	s= strrchr(str, '/');
+	if (s) {
+		len= s - str;
+		for (i= 0; i < len; i++)
+			file[i]= str[i];
+
+		file[i]= '.';
+		file[i+1]= 't';
+		file[i+2]= 't';
+		file[i+3]= 'f';
+		file[i+4]= '\0';
+		s++;
+		*size= atoi(s);
+		return(1);
+	}
+	return(0);
+}
+
+#endif /* zero!! */

Added: branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c	                        (rev 0)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c	2009-02-09 07:15:22 UTC (rev 18884)
@@ -0,0 +1,134 @@
+/**
+ * $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 *****
+ */
+
+#if 0
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ft2build.h>
+
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_linklist.h"	/* linknode */
+#include "BLI_string.h"
+
+#include "blf_internal_types.h"
+
+
+/* freetype2 handle. */
+FT_Library global_ft_lib;
+
+int blf_font_init(void)
+{
+	return(FT_Init_FreeType(&global_ft_lib));
+}
+
+void blf_font_exit(void)
+{
+	FT_Done_Freetype(global_ft_lib);
+}
+
+FontBLF *blf_font_new(char *name)
+{
+	FontBLF *font;
+	FT_Error err;
+
+	font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
+	err= FT_New_Face(global_ft_lib, name, 0, &font->face);
+	if (err) {
+		MEM_freeN(font);
+		return(NULL);
+	}
+
+	err= FT_Select_Charmap(font->face, ft_encoding_unicode);
+	if (err) {
+		printf("Warning: FT_Select_Charmap fail!!\n");
+		FT_Done_Face(font->face);
+		MEM_freeN(font);
+		return(NULL);
+	}
+
+	font->name= MEM_strdup(name);
+	font->ref= 1;
+	font->aspect= 1.0f;
+	font->pos[0]= 0.0f;
+	font->pos[1]= 0.0f;
+	font->angle[0]= 0.0f;
+	font->angle[1]= 0.0f;
+	font->angle[2]= 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->clip_mode= BLF_CLIP_DISABLE;
+	font->dpi= 0;
+	font->size= 0;
+	font->cache.first= NULL;
+	font->cache.last= NULL;
+	font->glyph_cache= NULL;
+	glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);
+	return(font);
+}
+
+void blf_font_size(FontBLF *font, int size, int dpi)
+{
+	GlyphCacheBLF *gc;
+	FT_Error err;
+	
+	err= FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi);
+	if (err) {
+		/* FIXME: here we can go through the fixed size and choice a close one */
+		printf("Warning: The current face don't support the size (%d) and dpi (%d)\n", size, dpi);
+		return;
+	}
+
+	font->size= size;
+	font->dpi= dpi;
+
+	gc= blf_glyph_cache_find(font, size, dpi);
+	if (gc)
+		font->glyph_cache= gc;
+	else {
+		gc= blf_glyph_cache_new(font);
+		if (gc)
+			font->glyph_cache= gc;
+	}
+}
+
+#endif /* zero!! */

Added: branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c	                        (rev 0)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c	2009-02-09 07:15:22 UTC (rev 18884)
@@ -0,0 +1,268 @@
+/**
+ * $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 *****
+ */
+
+#if 0
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ft2build.h>
+
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_linklist.h"	/* linknode */
+#include "BLI_string.h"
+
+#include "blf_internal_types.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;
+
+	p= (GlyphCacheBLF *)font->cache.first;
+	while (p) {
+		if (p->size == size && p->dpi == dpi)
+			return(p);
+		p= p->next;
+	}
+	return(NULL);
+}
+
+/* Create a new glyph cache for the current size and dpi. */
+GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
+{
+	GlyphCacheBLF *gc;
+	int i;
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list