2011-02-23 10:52:22 +00:00
|
|
|
/*
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2011-02-25 13:35:59 +00:00
|
|
|
|
|
|
|
/** \file gameengine/Ketsji/KX_FontObject.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
#include "KX_FontObject.h"
|
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
#include "KX_Scene.h"
|
|
|
|
#include "KX_PythonInit.h"
|
2011-01-04 21:27:44 +00:00
|
|
|
#include "BLI_math.h"
|
2012-01-04 21:40:00 +00:00
|
|
|
#include "StringValue.h"
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
|
2012-01-05 06:02:42 +00:00
|
|
|
/* 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"
|
|
|
|
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
extern "C" {
|
|
|
|
#include "BLF_api.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BGE_FONT_RES 100
|
|
|
|
|
2012-01-05 06:02:42 +00:00
|
|
|
/* proptotype */
|
|
|
|
int GetFontId(VFont *font);
|
|
|
|
|
2012-09-16 00:22:55 +00:00
|
|
|
static std::vector<STR_String> split_string(STR_String str)
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
{
|
|
|
|
std::vector<STR_String> text = std::vector<STR_String>();
|
|
|
|
|
|
|
|
/* Split the string upon new lines */
|
|
|
|
int begin=0, end=0;
|
|
|
|
while (end < str.Length())
|
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (str.GetAt(end) == '\n')
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
{
|
|
|
|
text.push_back(str.Mid(begin, end-begin));
|
|
|
|
begin = end+1;
|
|
|
|
}
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
//Now grab the last line
|
|
|
|
text.push_back(str.Mid(begin, end-begin));
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2012-01-05 06:02:42 +00:00
|
|
|
|
2012-09-16 00:22:55 +00:00
|
|
|
KX_FontObject::KX_FontObject(void* sgReplicationInfo,
|
|
|
|
SG_Callbacks callbacks,
|
|
|
|
RAS_IRenderTools* rendertools,
|
2013-07-19 22:54:02 +00:00
|
|
|
Object *ob,
|
|
|
|
bool do_color_management):
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
KX_GameObject(sgReplicationInfo, callbacks),
|
|
|
|
m_object(ob),
|
|
|
|
m_dpi(72),
|
|
|
|
m_resolution(1.f),
|
2013-07-19 22:54:02 +00:00
|
|
|
m_rendertools(rendertools),
|
|
|
|
m_do_color_management(do_color_management)
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
{
|
|
|
|
Curve *text = static_cast<Curve *> (ob->data);
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
m_text = split_string(text->str);
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
m_fsize = text->fsize;
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
m_line_spacing = text->linedist;
|
|
|
|
m_offset = MT_Vector3(text->xof, text->yof, 0);
|
2012-01-05 06:02:42 +00:00
|
|
|
|
|
|
|
m_fontid = GetFontId(text->vfont);
|
|
|
|
|
2011-01-04 21:27:44 +00:00
|
|
|
/* initialize the color with the object color and store it in the KX_Object class
|
2012-03-09 18:28:30 +00:00
|
|
|
* This is a workaround waiting for the fix:
|
|
|
|
* [#25487] BGE: Object Color only works when it has a keyed frame */
|
2011-01-04 21:27:44 +00:00
|
|
|
copy_v4_v4(m_color, (const float*) ob->col);
|
|
|
|
this->SetObjectColor((const MT_Vector4&) m_color);
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KX_FontObject::~KX_FontObject()
|
|
|
|
{
|
|
|
|
//remove font from the scene list
|
|
|
|
//it's handled in KX_Scene::NewRemoveObject
|
|
|
|
}
|
|
|
|
|
2012-02-25 16:49:59 +00:00
|
|
|
CValue* KX_FontObject::GetReplica()
|
|
|
|
{
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
KX_FontObject* replica = new KX_FontObject(*this);
|
|
|
|
replica->ProcessReplica();
|
|
|
|
return replica;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KX_FontObject::ProcessReplica()
|
|
|
|
{
|
|
|
|
KX_GameObject::ProcessReplica();
|
|
|
|
KX_GetActiveScene()->AddFont(this);
|
|
|
|
}
|
|
|
|
|
2013-03-25 02:41:30 +00:00
|
|
|
int GetFontId(VFont *vfont)
|
2012-02-25 16:49:59 +00:00
|
|
|
{
|
2012-01-05 06:02:42 +00:00
|
|
|
PackedFile *packedfile=NULL;
|
|
|
|
int fontid = -1;
|
|
|
|
|
2012-08-03 22:12:57 +00:00
|
|
|
if (vfont->packedfile) {
|
|
|
|
packedfile= vfont->packedfile;
|
|
|
|
fontid= BLF_load_mem(vfont->name, (unsigned char*)packedfile->data, packedfile->size);
|
2012-01-05 06:02:42 +00:00
|
|
|
|
|
|
|
if (fontid == -1) {
|
2012-08-03 22:12:57 +00:00
|
|
|
printf("ERROR: packed font \"%s\" could not be loaded.\n", vfont->name);
|
2012-01-05 06:02:42 +00:00
|
|
|
fontid = BLF_load("default");
|
|
|
|
}
|
|
|
|
return fontid;
|
|
|
|
}
|
|
|
|
|
2012-08-03 22:12:57 +00:00
|
|
|
/* once we have packed working we can load the builtin font */
|
|
|
|
const char *filepath = vfont->name;
|
|
|
|
if (BKE_vfont_is_builtin(vfont)) {
|
2012-01-05 06:02:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
void KX_FontObject::DrawText()
|
|
|
|
{
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
/* Allow for some logic brick control */
|
2012-03-24 07:52:14 +00:00
|
|
|
if (this->GetProperty("Text"))
|
2011-12-31 09:37:19 +00:00
|
|
|
m_text = split_string(this->GetProperty("Text")->GetText());
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
/* only draws the text if visible */
|
2012-03-24 07:52:14 +00:00
|
|
|
if (this->GetVisible() == 0) return;
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
|
2011-01-04 21:27:44 +00:00
|
|
|
/* update the animated color */
|
|
|
|
this->GetObjectColor().getValue(m_color);
|
|
|
|
|
2013-07-19 22:54:02 +00:00
|
|
|
/* Font Objects don't use the glsl shader, this color management code is copied from gpu_shader_material.glsl */
|
|
|
|
float color[4];
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (m_do_color_management) {
|
|
|
|
float c = m_color[i];
|
|
|
|
if(c < 0.0031308)
|
|
|
|
c = (c < 0.0) ? 0.0: c * 12.92;
|
|
|
|
else
|
|
|
|
c = 1.055 * pow(c, 1.0/2.4) - 0.055;
|
|
|
|
color[i] = c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color[i] = m_color[i];
|
|
|
|
}
|
|
|
|
color[3] = m_color[3];
|
|
|
|
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
/* HARDCODED MULTIPLICATION FACTOR - this will affect the render resolution directly */
|
2012-02-10 07:52:21 +00:00
|
|
|
const float RES = BGE_FONT_RES * m_resolution;
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
|
2012-02-10 07:52:21 +00:00
|
|
|
const float size = m_fsize * this->NodeGetWorldScaling()[0] * RES;
|
|
|
|
const float aspect = m_fsize / size;
|
2011-01-04 21:27:44 +00:00
|
|
|
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
/* Get a working copy of the OpenGLMatrix to use */
|
|
|
|
double mat[16];
|
|
|
|
memcpy(mat, this->GetOpenGLMatrix(), sizeof(double)*16);
|
|
|
|
|
|
|
|
/* Account for offset */
|
|
|
|
MT_Vector3 offset = this->NodeGetWorldOrientation() * m_offset * this->NodeGetWorldScaling();
|
|
|
|
mat[12] += offset[0]; mat[13] += offset[1]; mat[14] += offset[2];
|
|
|
|
|
|
|
|
/* Orient the spacing vector */
|
|
|
|
MT_Vector3 spacing = MT_Vector3(0, m_fsize*m_line_spacing, 0);
|
|
|
|
spacing = this->NodeGetWorldOrientation() * spacing * this->NodeGetWorldScaling()[1];
|
|
|
|
|
|
|
|
/* Draw each line, taking spacing into consideration */
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<m_text.size(); ++i)
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
{
|
|
|
|
if (i!=0)
|
|
|
|
{
|
|
|
|
mat[12] -= spacing[0];
|
|
|
|
mat[13] -= spacing[1];
|
|
|
|
mat[14] -= spacing[2];
|
|
|
|
}
|
2013-07-19 22:54:02 +00:00
|
|
|
m_rendertools->RenderText3D(m_fontid, m_text[i], int(size), m_dpi, color, mat, aspect);
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
}
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python Integration Hooks */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
PyTypeObject KX_FontObject::Type = {
|
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
|
|
|
"KX_FontObject",
|
|
|
|
sizeof(PyObjectPlus_Proxy),
|
|
|
|
0,
|
|
|
|
py_base_dealloc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
py_base_repr,
|
|
|
|
0,
|
|
|
|
&KX_GameObject::Sequence,
|
|
|
|
&KX_GameObject::Mapping,
|
|
|
|
0,0,0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&KX_GameObject::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_FontObject::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
|
|
|
PyAttributeDef KX_FontObject::Attributes[] = {
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
//KX_PYATTRIBUTE_STRING_RW("text", 0, 280, false, KX_FontObject, m_text[0]), //arbitrary limit. 280 = 140 unicode chars in unicode
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("text", KX_FontObject, pyattr_get_text, pyattr_set_text),
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("size", 0.0001f, 10000.0f, KX_FontObject, m_fsize),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("resolution", 0.0001f, 10000.0f, KX_FontObject, m_resolution),
|
|
|
|
/* KX_PYATTRIBUTE_INT_RW("dpi", 0, 10000, false, KX_FontObject, m_dpi), */// no real need for expose this I think
|
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_FontObject::pyattr_get_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_FontObject* self = static_cast<KX_FontObject*>(self_v);
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
STR_String str = STR_String();
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<self->m_text.size(); ++i)
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (i!=0)
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
str += '\n';
|
|
|
|
str += self->m_text[i];
|
|
|
|
}
|
2011-12-30 12:44:16 +00:00
|
|
|
return PyUnicode_From_STR_String(str);
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KX_FontObject::pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_FontObject* self = static_cast<KX_FontObject*>(self_v);
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!PyUnicode_Check(value))
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
char* chars = _PyUnicode_AsString(value);
|
2012-01-04 21:40:00 +00:00
|
|
|
|
|
|
|
/* Allow for some logic brick control */
|
|
|
|
CValue* tprop = self->GetProperty("Text");
|
2012-03-24 07:52:14 +00:00
|
|
|
if (tprop) {
|
2012-01-04 21:40:00 +00:00
|
|
|
CValue *newstringprop = new CStringValue(STR_String(chars), "Text");
|
|
|
|
self->SetProperty("Text", newstringprop);
|
|
|
|
newstringprop->Release();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self->m_text = split_string(STR_String(chars));
|
|
|
|
}
|
|
|
|
|
cucumber merge, multiline font object:
revisions: 38384,38387,38403,38404,38407,42997,42998
#42998 by dfelinto
BGE Font Object - fix for offset
(scaling also has to be taken into account here)
#42997 by dfelinto
Font Object Multiline fix.
The offset was totally wrong when object had scale[1] != 1
#38407 by kupoman
Changing the "text" property of a KX_FontObject now changes the text. This allows for control of a FontObject through logic bricks.
#38404 by kupoman
KX_FontObject now supports the x and y offset options.
#38403 by kupoman
KX_FontObject now makes use of the font's line spacing option, and correctly accounts for rotation and font size when applying the spacing.
#38387 by kupoman
The KX_FontObject text attribute is working again.
#38384 by kupoman
Primitive support for the new line character added to KX_FontObjects. The line spacing is fixed, and does not work when the FontObject is rotated. Also, the text attribute has been temporarily disabled, as it needs some updating to support the multiline changes.
2011-12-30 12:28:51 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/
Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have)
The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.
Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)
[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF.
So instead of:
BLF_draw(fontid, (char *)text, strlen(text));
We would do:
MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.
Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
a) constructor: load the font of the object, and store other values.
b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API
*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.
Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
|
|
|
#endif // WITH_PYTHON
|