[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33336] trunk/blender/source/blender: change monospace font to be an extern, not good final design but better then loading the same font 3 times.
Campbell Barton
ideasman42 at gmail.com
Fri Nov 26 17:33:42 CET 2010
Revision: 33336
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33336
Author: campbellbarton
Date: 2010-11-26 17:33:42 +0100 (Fri, 26 Nov 2010)
Log Message:
-----------
change monospace font to be an extern, not good final design but better then loading the same font 3 times.
need to load twice still because render may use the font in a thread.
Modified Paths:
--------------
trunk/blender/source/blender/blenfont/BLF_api.h
trunk/blender/source/blender/blenkernel/intern/image.c
trunk/blender/source/blender/blenkernel/intern/image_gen.c
trunk/blender/source/blender/editors/interface/interface_style.c
trunk/blender/source/blender/editors/space_info/textview.c
trunk/blender/source/blender/editors/space_text/text_draw.c
Modified: trunk/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_api.h 2010-11-26 16:30:43 UTC (rev 33335)
+++ trunk/blender/source/blender/blenfont/BLF_api.h 2010-11-26 16:33:42 UTC (rev 33336)
@@ -179,4 +179,8 @@
#define BLF_SHADOW (1<<2)
#define BLF_KERNING_DEFAULT (1<<3)
+// XXX, bad design
+extern int blf_mono_font;
+extern int blf_mono_font_render; // dont mess drawing with render threads.
+
#endif /* BLF_API_H */
Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c 2010-11-26 16:30:43 UTC (rev 33335)
+++ trunk/blender/source/blender/blenkernel/intern/image.c 2010-11-26 16:33:42 UTC (rev 33336)
@@ -985,29 +985,13 @@
}
}
-// XXX - Bad level call.
-extern int datatoc_bmonofont_ttf_size;
-extern char datatoc_bmonofont_ttf[];
-
-// XXX - copied from text_font_begin ! Change all the BLF_* here
-static int mono= -1;
-
-int stamp_font_begin(int size)
-{
- if (mono == -1)
- mono= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
-
- BLF_aspect(mono, 1.0);
- BLF_size(mono, size, 72);
- return(mono); // XXX This is for image_gen.c!!
-}
-
void BKE_stamp_buf(Scene *scene, unsigned char *rect, float *rectf, int width, int height, int channels)
{
struct StampData stamp_data;
float w, h, pad;
int x, y;
float h_fixed;
+ const int mono= blf_mono_font_render; // XXX
if (!rect && !rectf)
return;
@@ -1018,8 +1002,10 @@
if(scene->r.stamp_font_id < 8)
scene->r.stamp_font_id= 12;
- stamp_font_begin(scene->r.stamp_font_id);
-
+ /* set before return */
+ BLF_aspect(mono, 1.0);
+ BLF_size(mono, scene->r.stamp_font_id, 72);
+
BLF_buffer(mono, rectf, rect, width, height, channels);
BLF_buffer_col(mono, scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0);
pad= BLF_width(mono, "--");
Modified: trunk/blender/source/blender/blenkernel/intern/image_gen.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image_gen.c 2010-11-26 16:30:43 UTC (rev 33335)
+++ trunk/blender/source/blender/blenkernel/intern/image_gen.c 2010-11-26 16:33:42 UTC (rev 33336)
@@ -298,16 +298,17 @@
}
/* defined in image.c */
-extern int stamp_font_begin(int size);
static void checker_board_text(unsigned char *rect, float *rect_float, int width, int height, int step, int outline)
{
- int x, y, mono;
+ int x, y;
int pen_x, pen_y;
char text[3]= {'A', '1', '\0'};
+ const int mono= blf_mono_font;
- /* hard coded size! */
- mono= stamp_font_begin(54);
+ BLF_aspect(mono, 1.0);
+ BLF_size(mono, 54, 72); /* hard coded size! */
+
BLF_buffer(mono, rect_float, rect, width, height, 4);
for(y= 0; y < height; y+=step)
Modified: trunk/blender/source/blender/editors/interface/interface_style.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_style.c 2010-11-26 16:30:43 UTC (rev 33335)
+++ trunk/blender/source/blender/editors/interface/interface_style.c 2010-11-26 16:33:42 UTC (rev 33336)
@@ -264,6 +264,9 @@
BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
}
+int blf_mono_font= -1;
+int blf_mono_font_render= -1;
+
/* ************** init exit ************************ */
/* called on each startup.blend read */
@@ -314,6 +317,20 @@
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);
+
+ BLF_aspect(blf_mono_font, 1.0);
+ BLF_size(blf_mono_font, 12, 72);
+
+ /* second for rendering else we get threading problems */
+ if (blf_mono_font_render == -1)
+ blf_mono_font_render= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
+
+ BLF_aspect(blf_mono_font_render, 1.0);
+ BLF_size(blf_mono_font_render, 12, 72);
}
void uiStyleFontSet(uiFontStyle *fs)
Modified: trunk/blender/source/blender/editors/space_info/textview.c
===================================================================
--- trunk/blender/source/blender/editors/space_info/textview.c 2010-11-26 16:30:43 UTC (rev 33335)
+++ trunk/blender/source/blender/editors/space_info/textview.c 2010-11-26 16:33:42 UTC (rev 33336)
@@ -39,18 +39,10 @@
#include "textview.h"
-
-static int mono= -1; // XXX needs proper storage and change all the BLF_* here!
-
-
static void console_font_begin(TextViewContext *sc)
{
- if(mono == -1) {
- mono= BLF_load_mem("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
- }
-
- BLF_aspect(mono, 1.0);
- BLF_size(mono, sc->lheight-2, 72);
+ BLF_aspect(blf_mono_font, 1.0);
+ BLF_size(blf_mono_font, sc->lheight-2, 72);
}
typedef struct ConsoleDrawContext {
@@ -95,6 +87,7 @@
int rct_ofs= cdc->lheight/4;
int tot_lines = (str_len/cdc->console_width)+1; /* total number of lines for wrapping */
int y_next = (str_len > cdc->console_width) ? cdc->xy[1]+cdc->lheight*tot_lines : cdc->xy[1]+cdc->lheight;
+ const int mono= blf_mono_font;
/* just advance the height */
if(cdc->draw==0) {
@@ -228,6 +221,7 @@
int xy[2], y_prev;
int sel[2]= {-1, -1}; /* defaults disabled */
unsigned char fg[3], bg[3];
+ const int mono= blf_mono_font;
console_font_begin(tvc);
Modified: trunk/blender/source/blender/editors/space_text/text_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_draw.c 2010-11-26 16:30:43 UTC (rev 33335)
+++ trunk/blender/source/blender/editors/space_text/text_draw.c 2010-11-26 16:33:42 UTC (rev 33336)
@@ -56,13 +56,11 @@
#include "text_intern.h"
/******************** text font drawing ******************/
-static int mono= -1; // XXX needs proper storage and change all the BLF_* here
+// XXX, fixme
+#define mono blf_mono_font
static void text_font_begin(SpaceText *st)
{
- if(mono == -1)
- mono= BLF_load_mem("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
-
BLF_aspect(mono, 1.0);
BLF_size(mono, st->lheight, 72);
}
More information about the Bf-blender-cvs
mailing list