[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43151] trunk/blender/source/gameengine/ Ketsji/KX_FontObject.cpp: BGE Font Object: fix for relative path not working AND packed fonts not working
Dalai Felinto
dfelinto at gmail.com
Thu Jan 5 07:02:53 CET 2012
Revision: 43151
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43151
Author: dfelinto
Date: 2012-01-05 06:02:42 +0000 (Thu, 05 Jan 2012)
Log Message:
-----------
BGE Font Object: fix for relative path not working AND packed fonts not working
[I don't think anyone has ever reported those, what makes me slightly sad but carry on ;)]
Those fixes introduce a more generic function to load a font before calling BLF_load.
I think it should move to be part of Blender util routines or BLF itself.
For the time being here will make it. Once we get <builtin> font working we go for this.
Thanks Diego Borghetti for the usual assistance with blf.
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_FontObject.cpp
Modified: trunk/blender/source/gameengine/Ketsji/KX_FontObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_FontObject.cpp 2012-01-05 05:43:35 UTC (rev 43150)
+++ trunk/blender/source/gameengine/Ketsji/KX_FontObject.cpp 2012-01-05 06:02:42 UTC (rev 43151)
@@ -36,12 +36,22 @@
#include "BLI_math.h"
#include "StringValue.h"
+/* paths needed for font load */
+#include "BLI_blenlib.h"
+#include "BKE_global.h"
+#include "BKE_font.h"
+#include "BKE_main.h"
+#include "DNA_packedFile_types.h"
+
extern "C" {
#include "BLF_api.h"
}
#define BGE_FONT_RES 100
+/* proptotype */
+int GetFontId(VFont *font);
+
std::vector<STR_String> split_string(STR_String str)
{
std::vector<STR_String> text = std::vector<STR_String>();
@@ -62,6 +72,7 @@
return text;
}
+
KX_FontObject::KX_FontObject( void* sgReplicationInfo,
SG_Callbacks callbacks,
RAS_IRenderTools* rendertools,
@@ -77,20 +88,9 @@
m_fsize = text->fsize;
m_line_spacing = text->linedist;
m_offset = MT_Vector3(text->xof, text->yof, 0);
-
- /* FO_BUILTIN_NAME != "default" */
- /* I hope at some point Blender (2.5x) can have a single font */
- /* with unicode support for ui and OB_FONT */
- /* once we have packed working we can load the FO_BUILTIN_NAME font */
- const char* filepath = text->vfont->name;
- if (strcmp(FO_BUILTIN_NAME, filepath) == 0)
- filepath = "default";
-
- /* XXX - if it's packed it will not work. waiting for bdiego (Diego) fix for that. */
- m_fontid = BLF_load(filepath);
- if (m_fontid == -1)
- m_fontid = BLF_load("default");
-
+
+ m_fontid = GetFontId(text->vfont);
+
/* initialize the color with the object color and store it in the KX_Object class
This is a workaround waiting for the fix:
[#25487] BGE: Object Color only works when it has a keyed frame */
@@ -116,6 +116,50 @@
KX_GetActiveScene()->AddFont(this);
}
+int GetFontId (VFont *font) {
+ PackedFile *packedfile=NULL;
+ int fontid = -1;
+
+ if (font->packedfile) {
+ packedfile= font->packedfile;
+ fontid= BLF_load_mem(font->name, (unsigned char*)packedfile->data, packedfile->size);
+
+ if (fontid == -1) {
+ printf("ERROR: packed font \"%s\" could not be loaded.\n", font->name);
+ fontid = BLF_load("default");
+ }
+ return fontid;
+ }
+
+ /* once we have packed working we can load the FO_BUILTIN_NAME font */
+ const char *filepath = font->name;
+ if (strcmp(FO_BUILTIN_NAME, filepath) == 0) {
+ fontid = BLF_load("default");
+
+ /* XXX the following code is supposed to work (after you add get_builtin_packedfile to BKE_font.h )
+ * unfortunately it's crashing on blf_glyph.c:173 because gc->max_glyph_width is 0
+ */
+ // packedfile=get_builtin_packedfile();
+ // fontid= BLF_load_mem(font->name, (unsigned char*)packedfile->data, packedfile->size);
+ // return fontid;
+
+ return BLF_load("default");
+ }
+
+ /* convert from absolute to relative */
+ char expanded[256]; // font names can be bigger than FILE_MAX (240)
+ BLI_strncpy(expanded, filepath, 256);
+ BLI_path_abs(expanded, G.main->name);
+
+ fontid = BLF_load(expanded);
+
+ /* fallback */
+ if (fontid == -1)
+ fontid = BLF_load("default");
+
+ return fontid;
+}
+
void KX_FontObject::DrawText()
{
/* Allow for some logic brick control */
More information about the Bf-blender-cvs
mailing list