diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2012-01-05 10:02:42 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2012-01-05 10:02:42 +0400 |
commit | 8d55b7bf0e43b655a9e74e4325ee835cc84355bb (patch) | |
tree | 65ba986a6be974802cc0bd58c5c44445121cc428 /source/gameengine/Ketsji/KX_FontObject.cpp | |
parent | cce9c432953a73afef0c2105c8ff2341d86c0d3e (diff) |
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.
Diffstat (limited to 'source/gameengine/Ketsji/KX_FontObject.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_FontObject.cpp | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp index c20015945aa..8cce9471587 100644 --- a/source/gameengine/Ketsji/KX_FontObject.cpp +++ b/source/gameengine/Ketsji/KX_FontObject.cpp @@ -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 @@ std::vector<STR_String> split_string(STR_String str) return text; } + KX_FontObject::KX_FontObject( void* sgReplicationInfo, SG_Callbacks callbacks, RAS_IRenderTools* rendertools, @@ -77,20 +88,9 @@ KX_FontObject::KX_FontObject( void* sgReplicationInfo, 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 @@ void KX_FontObject::ProcessReplica() 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 */ |