diff options
author | Xiao Xiangquan <xiaoxiangquan@gmail.com> | 2011-06-02 15:22:22 +0400 |
---|---|---|
committer | Xiao Xiangquan <xiaoxiangquan@gmail.com> | 2011-06-02 15:22:22 +0400 |
commit | a40e1302ae68ff4a5ce3078bdacb43653ba5e1af (patch) | |
tree | e48fd29988ec9e7fd2a9df320219ccc97c30f5ec | |
parent | b0cc5b9d4c47625864272654197c4c6ff3f50976 (diff) |
Almost complete the i18n system, including:
Copy unifont..ttf.gz from source tree to target datafile path( now ONLY works with cmake );
Set the locale the same with system's setting;
If need unicode font, unzip and load unifont when init ui styles;
Apply gettext() to labels in space_info.py, who are the main menu items.
Each of these should have been commit one by one. As they work well according to my tests, so I just lazily send a long list.
-rw-r--r-- | release/scripts/startup/bl_ui/space_info.py | 161 | ||||
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 6 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 4 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_lang.c | 15 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_fileops.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 4 | ||||
-rw-r--r-- | source/blender/editors/datafiles/CMakeLists.txt | 7 | ||||
-rwxr-xr-x | source/blender/editors/datafiles/bunifont.ttf.c | 40 | ||||
-rw-r--r-- | source/blender/editors/include/ED_datafiles.h | 3 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 57 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 7 | ||||
-rw-r--r-- | source/creator/CMakeLists.txt | 12 | ||||
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 4 |
15 files changed, 241 insertions, 99 deletions
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py index 1fb2e5b735e..4254ec3c9ab 100644 --- a/release/scripts/startup/bl_ui/space_info.py +++ b/release/scripts/startup/bl_ui/space_info.py @@ -18,6 +18,7 @@ # <pep8 compliant> import bpy +from blf import gettext as _ class INFO_HT_header(bpy.types.Header): @@ -44,7 +45,7 @@ class INFO_HT_header(bpy.types.Header): sub.menu("INFO_MT_help") if window.screen.show_fullscreen: - layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous") + layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text=_("Back to Previous")) layout.separator() else: layout.template_ID(context.window, "screen", new="screen.new", unlink="screen.delete") @@ -70,11 +71,11 @@ class INFO_HT_header(bpy.types.Header): """ sinfo = context.space_data row = layout.row(align=True) - row.prop(sinfo, "show_report_debug", text="Debug") - row.prop(sinfo, "show_report_info", text="Info") - row.prop(sinfo, "show_report_operator", text="Operators") - row.prop(sinfo, "show_report_warning", text="Warnings") - row.prop(sinfo, "show_report_error", text="Errors") + row.prop(sinfo, "show_report_debug", text=_("Debug")) + row.prop(sinfo, "show_report_info", text=_("Info")) + row.prop(sinfo, "show_report_operator", text=_("Operators")) + row.prop(sinfo, "show_report_warning", text=_("Warnings")) + row.prop(sinfo, "show_report_error", text=_("Errors")) row = layout.row() row.enabled = sinfo.show_report_operator @@ -85,7 +86,7 @@ class INFO_HT_header(bpy.types.Header): class INFO_MT_report(bpy.types.Menu): - bl_label = "Report" + bl_label = _("Report") def draw(self, context): layout = self.layout @@ -97,31 +98,31 @@ class INFO_MT_report(bpy.types.Menu): class INFO_MT_file(bpy.types.Menu): - bl_label = "File" + bl_label = _("File"); def draw(self, context): layout = self.layout layout.operator_context = 'EXEC_AREA' - layout.operator("wm.read_homefile", text="New", icon='NEW') + layout.operator("wm.read_homefile", text=_("New"), icon='NEW') layout.operator_context = 'INVOKE_AREA' - layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER') + layout.operator("wm.open_mainfile", text=_("Open..."), icon='FILE_FOLDER') layout.menu("INFO_MT_file_open_recent") layout.operator("wm.recover_last_session", icon='RECOVER_LAST') - layout.operator("wm.recover_auto_save", text="Recover Auto Save...") + layout.operator("wm.recover_auto_save", text=_("Recover Auto Save...")) layout.separator() layout.operator_context = 'INVOKE_AREA' - layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK').check_existing = False + layout.operator("wm.save_mainfile", text=_("Save"), icon='FILE_TICK').check_existing = False layout.operator_context = 'INVOKE_AREA' - layout.operator("wm.save_as_mainfile", text="Save As...") + layout.operator("wm.save_as_mainfile", text=_("Save As...")) layout.operator_context = 'INVOKE_AREA' - layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True + layout.operator("wm.save_as_mainfile", text=_("Save Copy...")).copy = True layout.separator() - layout.operator("screen.userpref_show", text="User Preferences...", icon='PREFERENCES') + layout.operator("screen.userpref_show", text=_("User Preferences..."), icon='PREFERENCES') layout.operator_context = 'EXEC_AREA' layout.operator("wm.save_homefile") @@ -130,8 +131,8 @@ class INFO_MT_file(bpy.types.Menu): layout.separator() layout.operator_context = 'INVOKE_AREA' - layout.operator("wm.link_append", text="Link") - props = layout.operator("wm.link_append", text="Append") + layout.operator("wm.link_append", text=_("Link")) + props = layout.operator("wm.link_append", text=_("Append")) props.link = False props.instance_groups = False @@ -147,12 +148,12 @@ class INFO_MT_file(bpy.types.Menu): layout.separator() layout.operator_context = 'EXEC_AREA' - layout.operator("wm.quit_blender", text="Quit", icon='QUIT') + layout.operator("wm.quit_blender", text=_("Quit"), icon='QUIT') class INFO_MT_file_import(bpy.types.Menu): bl_idname = "INFO_MT_file_import" - bl_label = "Import" + bl_label = _("Import") def draw(self, context): if hasattr(bpy.types, "WM_OT_collada_import"): @@ -161,7 +162,7 @@ class INFO_MT_file_import(bpy.types.Menu): class INFO_MT_file_export(bpy.types.Menu): bl_idname = "INFO_MT_file_export" - bl_label = "Export" + bl_label = _("Export") def draw(self, context): if hasattr(bpy.types, "WM_OT_collada_export"): @@ -169,13 +170,13 @@ class INFO_MT_file_export(bpy.types.Menu): class INFO_MT_file_external_data(bpy.types.Menu): - bl_label = "External Data" + bl_label = _("External Data") def draw(self, context): layout = self.layout - layout.operator("file.pack_all", text="Pack into .blend file") - layout.operator("file.unpack_all", text="Unpack into Files") + layout.operator("file.pack_all", text=_("Pack into .blend file")) + layout.operator("file.unpack_all", text=_("Unpack into Files")) layout.separator() @@ -187,41 +188,41 @@ class INFO_MT_file_external_data(bpy.types.Menu): class INFO_MT_mesh_add(bpy.types.Menu): bl_idname = "INFO_MT_mesh_add" - bl_label = "Mesh" + bl_label = _("Mesh") def draw(self, context): layout = self.layout layout.operator_context = 'INVOKE_REGION_WIN' - layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane") - layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube") - layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle") - layout.operator("mesh.primitive_uv_sphere_add", icon='MESH_UVSPHERE', text="UV Sphere") - layout.operator("mesh.primitive_ico_sphere_add", icon='MESH_ICOSPHERE', text="Icosphere") - layout.operator("mesh.primitive_cylinder_add", icon='MESH_CYLINDER', text="Cylinder") - layout.operator("mesh.primitive_cone_add", icon='MESH_CONE', text="Cone") + layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text=_("Plane")) + layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text=_("Cube")) + layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text=_("Circle")) + layout.operator("mesh.primitive_uv_sphere_add", icon='MESH_UVSPHERE', text=_("UV Sphere")) + layout.operator("mesh.primitive_ico_sphere_add", icon='MESH_ICOSPHERE', text=_("Icosphere")) + layout.operator("mesh.primitive_cylinder_add", icon='MESH_CYLINDER', text=_("Cylinder")) + layout.operator("mesh.primitive_cone_add", icon='MESH_CONE', text=_("Cone")) layout.separator() - layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid") - layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey") - layout.operator("mesh.primitive_torus_add", text="Torus", icon='MESH_TORUS') + layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text=_("Grid")) + layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text=_("Monkey")) + layout.operator("mesh.primitive_torus_add", text=_("Torus"), icon='MESH_TORUS') class INFO_MT_curve_add(bpy.types.Menu): bl_idname = "INFO_MT_curve_add" - bl_label = "Curve" + bl_label = _("Curve") def draw(self, context): layout = self.layout layout.operator_context = 'INVOKE_REGION_WIN' - layout.operator("curve.primitive_bezier_curve_add", icon='CURVE_BEZCURVE', text="Bezier") - layout.operator("curve.primitive_bezier_circle_add", icon='CURVE_BEZCIRCLE', text="Circle") - layout.operator("curve.primitive_nurbs_curve_add", icon='CURVE_NCURVE', text="Nurbs Curve") - layout.operator("curve.primitive_nurbs_circle_add", icon='CURVE_NCIRCLE', text="Nurbs Circle") - layout.operator("curve.primitive_nurbs_path_add", icon='CURVE_PATH', text="Path") + layout.operator("curve.primitive_bezier_curve_add", icon='CURVE_BEZCURVE', text=_("Bezier")) + layout.operator("curve.primitive_bezier_circle_add", icon='CURVE_BEZCIRCLE', text=_("Circle")) + layout.operator("curve.primitive_nurbs_curve_add", icon='CURVE_NCURVE', text=_("Nurbs Curve")) + layout.operator("curve.primitive_nurbs_circle_add", icon='CURVE_NCIRCLE', text=_("Nurbs Circle")) + layout.operator("curve.primitive_nurbs_path_add", icon='CURVE_PATH', text=_("Path")) class INFO_MT_edit_curve_add(bpy.types.Menu): bl_idname = "INFO_MT_edit_curve_add" - bl_label = "Add" + bl_label = _("Add") def draw(self, context): is_surf = context.active_object.type == 'SURFACE' @@ -237,71 +238,71 @@ class INFO_MT_edit_curve_add(bpy.types.Menu): class INFO_MT_surface_add(bpy.types.Menu): bl_idname = "INFO_MT_surface_add" - bl_label = "Surface" + bl_label = _("Surface") def draw(self, context): layout = self.layout layout.operator_context = 'INVOKE_REGION_WIN' - layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text="NURBS Curve") - layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text="NURBS Circle") - layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text="NURBS Surface") - layout.operator("surface.primitive_nurbs_surface_cylinder_add", icon='SURFACE_NCYLINDER', text="NURBS Cylinder") - layout.operator("surface.primitive_nurbs_surface_sphere_add", icon='SURFACE_NSPHERE', text="NURBS Sphere") - layout.operator("surface.primitive_nurbs_surface_torus_add", icon='SURFACE_NTORUS', text="NURBS Torus") + layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text=_("NURBS Curve")) + layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text=_("NURBS Circle")) + layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text=_("NURBS Surface")) + layout.operator("surface.primitive_nurbs_surface_cylinder_add", icon='SURFACE_NCYLINDER', text=_("NURBS Cylinder")) + layout.operator("surface.primitive_nurbs_surface_sphere_add", icon='SURFACE_NSPHERE', text=_("NURBS Sphere")) + layout.operator("surface.primitive_nurbs_surface_torus_add", icon='SURFACE_NTORUS', text=_("NURBS Torus")) class INFO_MT_armature_add(bpy.types.Menu): bl_idname = "INFO_MT_armature_add" - bl_label = "Armature" + bl_label = _("Armature") def draw(self, context): layout = self.layout layout.operator_context = 'INVOKE_REGION_WIN' - layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA') + layout.operator("object.armature_add", text=_("Single Bone"), icon='BONE_DATA') class INFO_MT_add(bpy.types.Menu): - bl_label = "Add" + bl_label = _("Add") def draw(self, context): layout = self.layout layout.operator_context = 'EXEC_SCREEN' - #layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH') + #layout.operator_menu_enum("object.mesh_add", "type", text=_("Mesh"), icon='OUTLINER_OB_MESH') layout.menu("INFO_MT_mesh_add", icon='OUTLINER_OB_MESH') - #layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE') + #layout.operator_menu_enum("object.curve_add", "type", text=_("Curve"), icon='OUTLINER_OB_CURVE') layout.menu("INFO_MT_curve_add", icon='OUTLINER_OB_CURVE') - #layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE') + #layout.operator_menu_enum("object.surface_add", "type", text=_("Surface"), icon='OUTLINER_OB_SURFACE') layout.menu("INFO_MT_surface_add", icon='OUTLINER_OB_SURFACE') - layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META') + layout.operator_menu_enum("object.metaball_add", "type", text=_("Metaball"), icon='OUTLINER_OB_META') layout.operator_context = 'INVOKE_REGION_WIN' - layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT') + layout.operator("object.text_add", text=_("Text"), icon='OUTLINER_OB_FONT') layout.separator() layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE') - layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE' - layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY' + layout.operator("object.add", text=_("Lattice"), icon='OUTLINER_OB_LATTICE').type = 'LATTICE' + layout.operator("object.add", text=_("Empty"), icon='OUTLINER_OB_EMPTY').type = 'EMPTY' layout.separator() - layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA') + layout.operator("object.camera_add", text=_("Camera"), icon='OUTLINER_OB_CAMERA') layout.operator_context = 'EXEC_SCREEN' - layout.operator_menu_enum("object.lamp_add", "type", text="Lamp", icon='OUTLINER_OB_LAMP') + layout.operator_menu_enum("object.lamp_add", "type", text=_("Lamp"), icon='OUTLINER_OB_LAMP') layout.separator() - layout.operator_menu_enum("object.effector_add", "type", text="Force Field", icon='OUTLINER_OB_EMPTY') + layout.operator_menu_enum("object.effector_add", "type", text=_("Force Field"), icon='OUTLINER_OB_EMPTY') layout.separator() if(len(bpy.data.groups) > 10): layout.operator_context = 'INVOKE_DEFAULT' - layout.operator("object.group_instance_add", text="Group Instance...", icon='OUTLINER_OB_EMPTY') + layout.operator("object.group_instance_add", text=_("Group Instance..."), icon='OUTLINER_OB_EMPTY') else: - layout.operator_menu_enum("object.group_instance_add", "group", text="Group Instance", icon='OUTLINER_OB_EMPTY') + layout.operator_menu_enum("object.group_instance_add", "group", text=_("Group Instance"), icon='OUTLINER_OB_EMPTY') class INFO_MT_game(bpy.types.Menu): - bl_label = "Game" + bl_label = _("Game") def draw(self, context): layout = self.layout @@ -322,18 +323,18 @@ class INFO_MT_game(bpy.types.Menu): class INFO_MT_render(bpy.types.Menu): - bl_label = "Render" + bl_label = _("Render") def draw(self, context): layout = self.layout - layout.operator("render.render", text="Render Image", icon='RENDER_STILL') - layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION').animation = True + layout.operator("render.render", text=_("Render Image"), icon='RENDER_STILL') + layout.operator("render.render", text=_("Render Animation"), icon='RENDER_ANIMATION').animation = True layout.separator() - layout.operator("render.opengl", text="OpenGL Render Image") - layout.operator("render.opengl", text="OpenGL Render Animation").animation = True + layout.operator("render.opengl", text=_("OpenGL Render Image")) + layout.operator("render.opengl", text=_("OpenGL Render Animation")).animation = True layout.separator() @@ -342,34 +343,34 @@ class INFO_MT_render(bpy.types.Menu): class INFO_MT_help(bpy.types.Menu): - bl_label = "Help" + bl_label = _("Help") def draw(self, context): import sys layout = self.layout - layout.operator("wm.url_open", text="Manual", icon='HELP').url = 'http://wiki.blender.org/index.php/Doc:Manual' - layout.operator("wm.url_open", text="Release Log", icon='URL').url = 'http://www.blender.org/development/release-logs/blender-257/' + layout.operator("wm.url_open", text=_("Manual"), icon='HELP').url = 'http://wiki.blender.org/index.php/Doc:Manual' + layout.operator("wm.url_open", text=_("Release Log"), icon='URL').url = 'http://www.blender.org/development/release-logs/blender-257/' layout.separator() - layout.operator("wm.url_open", text="Blender Website", icon='URL').url = 'http://www.blender.org/' - layout.operator("wm.url_open", text="Blender e-Shop", icon='URL').url = 'http://www.blender.org/e-shop' - layout.operator("wm.url_open", text="Developer Community", icon='URL').url = 'http://www.blender.org/community/get-involved/' - layout.operator("wm.url_open", text="User Community", icon='URL').url = 'http://www.blender.org/community/user-community/' + layout.operator("wm.url_open", text=_("Blender Website"), icon='URL').url = 'http://www.blender.org/' + layout.operator("wm.url_open", text=_("Blender e-Shop"), icon='URL').url = 'http://www.blender.org/e-shop' + layout.operator("wm.url_open", text=_("Developer Community"), icon='URL').url = 'http://www.blender.org/community/get-involved/' + layout.operator("wm.url_open", text=_("User Community"), icon='URL').url = 'http://www.blender.org/community/user-community/' layout.separator() - layout.operator("wm.url_open", text="Report a Bug", icon='URL').url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse' + layout.operator("wm.url_open", text=_("Report a Bug"), icon='URL').url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse' layout.separator() - layout.operator("wm.url_open", text="Python API Reference", icon='URL').url = bpy.types.WM_OT_doc_view._prefix + layout.operator("wm.url_open", text=_("Python API Reference"), icon='URL').url = bpy.types.WM_OT_doc_view._prefix layout.operator("help.operator_cheat_sheet", icon='TEXT') layout.operator("wm.sysinfo", icon='TEXT') layout.separator() if sys.platform[:3] == "win": layout.operator("wm.console_toggle", icon='CONSOLE') layout.separator() - layout.operator("anim.update_data_paths", text="FCurve/Driver Version fix", icon='HELP') + layout.operator("anim.update_data_paths", text=_("FCurve/Driver Version fix"), icon='HELP') layout.separator() layout.operator("wm.splash", icon='BLENDER') @@ -379,7 +380,7 @@ class INFO_MT_help(bpy.types.Menu): class HELP_OT_operator_cheat_sheet(bpy.types.Operator): bl_idname = "help.operator_cheat_sheet" - bl_label = "Operator Cheat Sheet" + bl_label = _("Operator Cheat Sheet") def execute(self, context): op_strings = [] diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 79c8c3b9a1a..05f383cdace 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -188,6 +188,8 @@ void BLF_lang_init(void); /* Set the current locale. */ void BLF_lang_set(const char *); +/* Get the current locale. */ +char* BLF_lang_get(void); /* Set the current encoding name. */ void BLF_lang_encoding_name(const char *str); @@ -218,4 +220,8 @@ void BLF_dir_free(char **dirs, int count); extern int blf_mono_font; extern int blf_mono_font_render; // dont mess drawing with render threads. +// XXX, me, too +extern int blf_unifont; +extern int blf_unifont_render; // dont mess drawing with render threads. + #endif /* BLF_API_H */ diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 1d2ac298af4..b5ad6ab8ae9 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -76,6 +76,10 @@ static int global_font_dpi= 72; int blf_mono_font= -1; int blf_mono_font_render= -1; +// XXX, should these be made into global_font_'s too? +int blf_unifont= -1; +int blf_unifont_render= -1; + static FontBLF *BLF_get(int fontid) { if (fontid >= 0 && fontid < BLF_MAX_FONT) diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index e7f9d1746ad..6a3e5b1f2ef 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -89,6 +89,7 @@ void BLF_lang_set(const char *str) #if defined (_WIN32) || defined(__APPLE__) BLI_setenv("LANG", str); + BLI_strncpy(global_language, BLI_getenv("LANG"), sizeof(global_language)); #else char *locreturn= setlocale(LC_ALL, str); if (locreturn == NULL) { @@ -101,14 +102,12 @@ void BLF_lang_set(const char *str) MEM_freeN(lang); } - + BLI_strncpy(global_language, locreturn, sizeof(global_language)); setlocale(LC_NUMERIC, "C"); #endif textdomain(DOMAIN_NAME); bindtextdomain(DOMAIN_NAME, global_messagepath); /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */ - BLI_strncpy(global_language, str, sizeof(global_language)); - } } @@ -118,6 +117,11 @@ void BLF_lang_encoding(const char *str) /* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */ } +char* BLF_lang_get(void) +{ + return global_language; +} + #else /* ! INTERNATIONAL */ void BLF_lang_init(void) @@ -137,4 +141,9 @@ void BLF_lang_set(const char *str) return; } +char* BLF_lang_get(void) +{ + return ""; +} + #endif /* INTERNATIONAL */ diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 59c01348c07..27b1a67b32c 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -53,6 +53,7 @@ int BLI_exists(const char *file); int BLI_copy_fileops(const char *file, const char *to); int BLI_rename(const char *from, const char *to); int BLI_gzip(const char *from, const char *to); +int BLI_ungzip_to_mem(const char *from_file, char *to_mem, const int size); int BLI_delete(const char *file, int dir, int recursive); int BLI_move(const char *file, const char *to); int BLI_touch(const char *file); diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 81fc8a50db6..3b27e4dafa0 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -98,6 +98,7 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check); #endif void BLI_setenv(const char *env, const char *val); +char *BLI_getenv(const char *env); void BLI_setenv_if_new(const char *env, const char* val); void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file); diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 2e0f4b483b1..b72f31dd128 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -102,6 +102,24 @@ int BLI_gzip(const char *from, const char *to) { return rval; } +/* gzip the file in from_file and write it to memery to_mem, at most size bytes. + return the unziped size + */ +int BLI_ungzip_to_mem(const char *from_file, char *to_mem, const int size) +{ + gzFile gzfile; + int readsize; + + gzfile = gzopen( from_file, "rb" ); + readsize = gzread( gzfile, to_mem, size); + + if (readsize < 0) + readsize = EOF; + + return readsize; +} + + /* return 1 when file can be written */ int BLI_is_writable(const char *filename) { diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index e0a08d0b890..6d85fd33953 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1205,6 +1205,10 @@ void BLI_setenv(const char *env, const char*val) #endif } +char *BLI_getenv(const char *env) +{ + return getenv(env); +} /** Only set an env var if already not there. diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt index a359b0ef6f5..b0c74ca12fc 100644 --- a/source/blender/editors/datafiles/CMakeLists.txt +++ b/source/blender/editors/datafiles/CMakeLists.txt @@ -19,8 +19,10 @@ # # ***** END GPL LICENSE BLOCK ***** -set(INC "") - +set(INC + ../../blenlib + ../../../../intern/guardedalloc +) set(SRC Bfont.c add.png.c @@ -29,6 +31,7 @@ set(SRC blob.png.c blur.png.c bmonofont.ttf.c + bunifont.ttf.c clay.png.c clone.png.c crease.png.c diff --git a/source/blender/editors/datafiles/bunifont.ttf.c b/source/blender/editors/datafiles/bunifont.ttf.c new file mode 100755 index 00000000000..dd2acb0cb52 --- /dev/null +++ b/source/blender/editors/datafiles/bunifont.ttf.c @@ -0,0 +1,40 @@ +/** \file blender/editors/datafiles/bunifont.ttf.c + * \ingroup eddatafiles + */ +/* DataToC output of file <bfont_ttf> */ + +#include <zlib.h> +#include <stdio.h> +#include "BLI_path_util.h" +#include "BLI_string.h" +#include "BLI_fileops.h" +#include "BLI_memarena.h" +#include "MEM_guardedalloc.h" + +const int datatoc_bunifont_ttf_size = 16336376; +static char* datatoc_bunifont_ttf = 0; + +static char unifont_path[1024]; +static char unifont_filename[]="unifont-5.1.20080907.ttf.zip"; + +char *get_datatoc_bunifont_ttf(void) +{ + if( datatoc_bunifont_ttf==NULL ) + { + char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); + BLI_snprintf( unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename ); + + if( BLI_exists(unifont_path) ) + { + datatoc_bunifont_ttf = (char*)MEM_mallocN( datatoc_bunifont_ttf_size, "get_datatoc_bunifont_ttf" ); + BLI_ungzip_to_mem( unifont_path, datatoc_bunifont_ttf, datatoc_bunifont_ttf_size ); + } + } + return datatoc_bunifont_ttf; +} + +void free_datatoc_bunifont_ttf(void) +{ + if( datatoc_bunifont_ttf!=NULL ) + MEM_freeN( datatoc_bunifont_ttf ); +} diff --git a/source/blender/editors/include/ED_datafiles.h b/source/blender/editors/include/ED_datafiles.h index ee29df3fffb..6831f80092c 100644 --- a/source/blender/editors/include/ED_datafiles.h +++ b/source/blender/editors/include/ED_datafiles.h @@ -56,6 +56,9 @@ extern char datatoc_bfont_ttf[]; extern int datatoc_bmonofont_ttf_size; extern char datatoc_bmonofont_ttf[]; +extern int datatoc_bunifont_ttf_size; +extern char* get_datatoc_bunifont_ttf(); + /* Brush icon datafiles */ /* TODO: this could be simplified by putting all the brush icons in one file */ diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 2e4106b3c04..9ebf7c9cd4f 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -76,7 +76,7 @@ /* ********************************************** */ -static uiStyle *ui_style_new(ListBase *styles, const char *name) +static uiStyle *ui_style_new(ListBase *styles, const char *name, short fontid) { uiStyle *style= MEM_callocN(sizeof(uiStyle), "new style"); @@ -85,7 +85,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->panelzoom= 1.0; - style->paneltitle.uifont_id= UIFONT_DEFAULT; + style->paneltitle.uifont_id= fontid; style->paneltitle.points= 12; style->paneltitle.kerning= 1; style->paneltitle.shadow= 1; @@ -94,7 +94,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->paneltitle.shadowalpha= 0.15f; style->paneltitle.shadowcolor= 1.0f; - style->grouplabel.uifont_id= UIFONT_DEFAULT; + style->grouplabel.uifont_id= fontid; style->grouplabel.points= 12; style->grouplabel.kerning= 1; style->grouplabel.shadow= 3; @@ -102,7 +102,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->grouplabel.shady= -1; style->grouplabel.shadowalpha= 0.25f; - style->widgetlabel.uifont_id= UIFONT_DEFAULT; + style->widgetlabel.uifont_id= fontid; style->widgetlabel.points= 11; style->widgetlabel.kerning= 1; style->widgetlabel.shadow= 3; @@ -111,7 +111,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->widgetlabel.shadowalpha= 0.15f; style->widgetlabel.shadowcolor= 1.0f; - style->widget.uifont_id= UIFONT_DEFAULT; + style->widget.uifont_id= fontid; style->widget.points= 11; style->widget.kerning= 1; style->widget.shadowalpha= 0.25f; @@ -295,6 +295,7 @@ void uiStyleInit(void) { uiFont *font= U.uifonts.first; uiStyle *style= U.uistyles.first; + char *lang_set= BLF_lang_get(); /* recover from uninitialized dpi */ if(U.dpi == 0) @@ -335,11 +336,7 @@ void uiStyleInit(void) BLF_size(font->blf_id, 14, U.dpi); } } - - if(style==NULL) { - ui_style_new(&U.uistyles, "Default Style"); - } - + // XXX, this should be moved into a style, but for now best only load the monospaced font once. if (blf_mono_font == -1) blf_mono_font= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); @@ -351,6 +348,46 @@ void uiStyleInit(void) blf_mono_font_render= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); BLF_size(blf_mono_font_render, 12, 72); + + /* XXX Maybe it's bad to do this */ + if(style==NULL) { + if( strcmp(lang_set,"hr.UTF-8")==0 + || strcmp(lang_set,"ar.UTF-8")==0 + || strcmp(lang_set,"bg.UTF-8")==0 + || strcmp(lang_set,"ca.UTF-8")==0 + || strcmp(lang_set,"cs.UTF-8")==0 + || strcmp(lang_set,"de.UTF-8")==0 + || strcmp(lang_set,"el.UTF-8")==0 + || strcmp(lang_set,"es.UTF-8")==0 + || strcmp(lang_set,"fi.UTF-8")==0 + || strcmp(lang_set,"fr.UTF-8")==0 + || strcmp(lang_set,"it.UTF-8")==0 + || strcmp(lang_set,"ja.UTF-8")==0 + || strcmp(lang_set,"ko.UTF-8")==0 + || strcmp(lang_set,"pl.UTF-8")==0 + || strcmp(lang_set,"ro.UTF-8")==0 + || strcmp(lang_set,"ru.UTF-8")==0 + || strcmp(lang_set,"sr.UTF-8")==0 + || strcmp(lang_set,"sv.UTF-8")==0 + || strcmp(lang_set,"uk.UTF-8")==0 + || strcmp(lang_set,"zh_CN.UTF-8")==0 + ) + { + // load unifont only when need. It takes 15MB memories + // get_datatoc_bunifont_ttf() may return null, BLF_load_mem_unique() will handle it + if( blf_unifont == -1 ) + blf_unifont= BLF_load_mem_unique("unifont", (unsigned char *)get_datatoc_bunifont_ttf(), datatoc_bunifont_ttf_size); + if( blf_unifont != -1 ) + { + BLF_size(blf_unifont, 12, 72); + ui_style_new(&U.uistyles, "Unifont Style", blf_unifont ); + } + else + ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT ); + } + else + ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT ); + } } void uiStyleFontSet(uiFontStyle *fs) diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 2e4148ca51d..a27be49af43 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -139,6 +139,10 @@ void WM_init(bContext *C, int argc, const char **argv) BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */ BLF_lang_init(); + // use default settings + BLF_lang_encoding(""); + BLF_lang_set(""); + /* get the default database, plus a wm */ WM_read_homefile(C, NULL, G.factory_startup); @@ -337,6 +341,7 @@ extern void free_anim_copybuf(void); extern void free_anim_drivers_copybuf(void); extern void free_fmodifiers_copybuf(void); extern void free_posebuf(void); +extern void free_datatoc_bunifont_ttf(void); /* called in creator.c even... tsk, split this! */ void WM_exit(bContext *C) @@ -375,7 +380,7 @@ void WM_exit(bContext *C) BIF_freeTemplates(C); free_ttfont(); /* bke_font.h */ - + free_datatoc_bunifont_ttf(); /* bunifont.ttf.c */ free_openrecent(); BKE_freecubetable(); diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index aea48d88b47..4bb0437ed6f 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -346,7 +346,9 @@ if(UNIX AND NOT APPLE) ) install( - DIRECTORY ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale + DIRECTORY + ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale + ${CMAKE_SOURCE_DIR}/release/datafiles/fonts DESTINATION ${TARGETDIR_VER}/datafiles PATTERN ".svn" EXCLUDE ) @@ -421,7 +423,9 @@ elseif(WIN32) DESTINATION ${TARGETDIR_VER}/config ) install( - DIRECTORY ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale + DIRECTORY + ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale + ${CMAKE_SOURCE_DIR}/release/datafiles/fonts DESTINATION ${TARGETDIR_VER}/datafiles PATTERN ".svn" EXCLUDE ) @@ -677,7 +681,9 @@ elseif(APPLE) ) install_dir( - ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale/ + DIRECTORY + ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale + ${CMAKE_SOURCE_DIR}/release/datafiles/fonts \${TARGETDIR_VER}/datafiles/locale ) endif() diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 7a98c7e09b0..522efb0cd8e 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -413,6 +413,10 @@ int main(int argc, char** argv) // Setup builtin font for BLF (mostly copied from creator.c, wm_init_exit.c and interface_style.c) BLF_init(11, U.dpi); BLF_lang_init(); + // use default settings + BLF_lang_encoding(""); + BLF_lang_set(""); + BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); // Parse command line options |