2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2009-04-09 18:11:18 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-04-09 18:11:18 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/interface/interface_style.c
|
|
|
|
* \ingroup edinterface
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2009-04-09 18:11:18 +00:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
#include "BLI_rect.h"
|
|
|
|
#include "BLI_string.h"
|
2011-09-27 19:04:27 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "BLF_api.h"
|
2011-09-20 07:39:25 +00:00
|
|
|
#include "BLF_translation.h"
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
|
|
#include "ED_datafiles.h"
|
|
|
|
|
|
|
|
#include "interface_intern.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* style + theme + layout-engine = UI */
|
|
|
|
|
|
|
|
/*
|
2012-03-03 16:31:46 +00:00
|
|
|
* This is a complete set of layout rules, the 'state' of the Layout
|
|
|
|
* Engine. Multiple styles are possible, defined via C or Python. Styles
|
|
|
|
* get a name, and will typically get activated per region type, like
|
|
|
|
* "Header", or "Listview" or "Toolbar". Properties of Style definitions
|
|
|
|
* are:
|
|
|
|
*
|
2012-03-04 04:35:12 +00:00
|
|
|
* - default column properties, internal spacing, aligning, min/max width
|
2012-03-03 16:31:46 +00:00
|
|
|
* - button alignment rules (for groups)
|
|
|
|
* - label placement rules
|
|
|
|
* - internal labeling or external labeling default
|
|
|
|
* - default minimum widths for buttons/labels (in amount of characters)
|
|
|
|
* - font types, styles and relative sizes for Panel titles, labels, etc.
|
|
|
|
*/
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ********************************************** */
|
|
|
|
|
2011-07-22 14:14:28 +00:00
|
|
|
static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id)
|
2009-04-09 18:11:18 +00:00
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
uiStyle *style = MEM_callocN(sizeof(uiStyle), "new style");
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
BLI_addtail(styles, style);
|
|
|
|
BLI_strncpy(style->name, name, MAX_STYLE_NAME);
|
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
style->panelzoom = 1.0; /* unused */
|
|
|
|
|
|
|
|
style->paneltitle.uifont_id = uifont_id;
|
|
|
|
style->paneltitle.points = 12;
|
|
|
|
style->paneltitle.kerning = 1;
|
|
|
|
style->paneltitle.shadow = 1;
|
|
|
|
style->paneltitle.shadx = 0;
|
|
|
|
style->paneltitle.shady = -1;
|
|
|
|
style->paneltitle.shadowalpha = 0.15f;
|
|
|
|
style->paneltitle.shadowcolor = 1.0f;
|
|
|
|
|
|
|
|
style->grouplabel.uifont_id = uifont_id;
|
|
|
|
style->grouplabel.points = 12;
|
|
|
|
style->grouplabel.kerning = 1;
|
|
|
|
style->grouplabel.shadow = 3;
|
|
|
|
style->grouplabel.shadx = 0;
|
|
|
|
style->grouplabel.shady = -1;
|
|
|
|
style->grouplabel.shadowalpha = 0.25f;
|
|
|
|
|
|
|
|
style->widgetlabel.uifont_id = uifont_id;
|
|
|
|
style->widgetlabel.points = 11;
|
|
|
|
style->widgetlabel.kerning = 1;
|
|
|
|
style->widgetlabel.shadow = 3;
|
|
|
|
style->widgetlabel.shadx = 0;
|
|
|
|
style->widgetlabel.shady = -1;
|
|
|
|
style->widgetlabel.shadowalpha = 0.15f;
|
|
|
|
style->widgetlabel.shadowcolor = 1.0f;
|
|
|
|
|
|
|
|
style->widget.uifont_id = uifont_id;
|
|
|
|
style->widget.points = 11;
|
|
|
|
style->widget.kerning = 1;
|
|
|
|
style->widget.shadowalpha = 0.25f;
|
|
|
|
|
|
|
|
style->columnspace = 8;
|
|
|
|
style->templatespace = 5;
|
|
|
|
style->boxspace = 5;
|
|
|
|
style->buttonspacex = 8;
|
|
|
|
style->buttonspacey = 2;
|
|
|
|
style->panelspace = 8;
|
|
|
|
style->panelouter = 4;
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uiFont *uifont_to_blfont(int id)
|
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
uiFont *font = U.uifonts.first;
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
for (; font; font = font->next) {
|
|
|
|
if (font->uifont_id == id) {
|
2009-04-09 18:11:18 +00:00
|
|
|
return font;
|
|
|
|
}
|
|
|
|
}
|
2009-04-15 14:43:54 +00:00
|
|
|
return U.uifonts.first;
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* *************** draw ************************ */
|
|
|
|
|
2010-12-14 02:38:29 +00:00
|
|
|
|
|
|
|
void uiStyleFontDrawExt(uiFontStyle *fs, rcti *rect, const char *str,
|
2012-03-30 01:51:25 +00:00
|
|
|
float *r_xofs, float *r_yofs)
|
2009-04-09 18:11:18 +00:00
|
|
|
{
|
|
|
|
float height;
|
2012-03-30 01:51:25 +00:00
|
|
|
int xofs = 0, yofs;
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2009-04-10 14:06:24 +00:00
|
|
|
uiStyleFontSet(fs);
|
2011-08-06 06:38:18 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
height = BLF_ascender(fs->uifont_id);
|
2012-08-20 23:06:17 +00:00
|
|
|
yofs = ceil(0.5f * (BLI_RCT_SIZE_Y(rect) - height));
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
if (fs->align == UI_STYLE_TEXT_CENTER) {
|
2012-08-20 23:06:17 +00:00
|
|
|
xofs = floor(0.5f * (BLI_RCT_SIZE_X(rect) - BLF_width(fs->uifont_id, str)));
|
2011-04-15 01:32:37 +00:00
|
|
|
/* don't center text if it chops off the start of the text, 2 gives some margin */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (xofs < 2) {
|
2012-03-30 01:51:25 +00:00
|
|
|
xofs = 2;
|
2011-04-15 01:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-30 01:51:25 +00:00
|
|
|
else if (fs->align == UI_STYLE_TEXT_RIGHT) {
|
2012-08-20 23:06:17 +00:00
|
|
|
xofs = BLI_RCT_SIZE_X(rect) - BLF_width(fs->uifont_id, str) - 1;
|
2011-04-15 01:32:37 +00:00
|
|
|
}
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2009-04-10 14:06:24 +00:00
|
|
|
/* clip is very strict, so we give it some space */
|
2012-03-30 01:51:25 +00:00
|
|
|
BLF_clipping(fs->uifont_id, rect->xmin - 1, rect->ymin - 4, rect->xmax + 1, rect->ymax + 4);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_CLIPPING);
|
2012-03-30 01:51:25 +00:00
|
|
|
BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f);
|
2009-04-10 14:06:24 +00:00
|
|
|
|
2009-06-23 16:27:35 +00:00
|
|
|
if (fs->shadow) {
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_SHADOW);
|
|
|
|
BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
|
|
|
|
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
|
2009-06-23 16:27:35 +00:00
|
|
|
}
|
|
|
|
|
2009-07-10 22:16:25 +00:00
|
|
|
if (fs->kerning == 1)
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
|
2009-07-10 22:16:25 +00:00
|
|
|
|
2012-01-11 12:33:51 +00:00
|
|
|
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_CLIPPING);
|
2009-06-23 16:27:35 +00:00
|
|
|
if (fs->shadow)
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_SHADOW);
|
2009-07-10 22:16:25 +00:00
|
|
|
if (fs->kerning == 1)
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
|
2010-12-14 02:38:29 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
*r_xofs = xofs;
|
|
|
|
*r_yofs = yofs;
|
2010-12-14 02:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, const char *str)
|
|
|
|
{
|
|
|
|
float xofs, yofs;
|
|
|
|
uiStyleFontDrawExt(fs, rect, str,
|
2012-03-30 01:51:25 +00:00
|
|
|
&xofs, &yofs);
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 03:54:30 +00:00
|
|
|
/* drawn same as above, but at 90 degree angle */
|
2010-12-03 17:05:21 +00:00
|
|
|
void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str)
|
2009-10-19 03:54:30 +00:00
|
|
|
{
|
|
|
|
float height;
|
|
|
|
int xofs, yofs;
|
|
|
|
float angle;
|
|
|
|
rcti txtrect;
|
|
|
|
|
|
|
|
uiStyleFontSet(fs);
|
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
height = BLF_ascender(fs->uifont_id);
|
2009-10-19 03:54:30 +00:00
|
|
|
/* becomes x-offset when rotated */
|
2012-08-20 23:06:17 +00:00
|
|
|
xofs = ceil(0.5f * (BLI_RCT_SIZE_Y(rect) - height));
|
2009-10-19 03:54:30 +00:00
|
|
|
|
|
|
|
/* ignore UI_STYLE, always aligned to top */
|
|
|
|
|
|
|
|
/* rotate counter-clockwise for now (assumes left-to-right language)*/
|
2012-03-30 01:51:25 +00:00
|
|
|
xofs += height;
|
|
|
|
yofs = BLF_width(fs->uifont_id, str) + 5;
|
|
|
|
angle = 90.0f;
|
2009-10-19 03:54:30 +00:00
|
|
|
|
|
|
|
/* translate rect to vertical */
|
2012-08-20 23:06:17 +00:00
|
|
|
txtrect.xmin = rect->xmin - BLI_RCT_SIZE_Y(rect);
|
|
|
|
txtrect.ymin = rect->ymin - BLI_RCT_SIZE_X(rect);
|
2012-03-24 02:51:46 +00:00
|
|
|
txtrect.xmax = rect->xmin;
|
|
|
|
txtrect.ymax = rect->ymin;
|
2009-10-19 03:54:30 +00:00
|
|
|
|
|
|
|
/* clip is very strict, so we give it some space */
|
|
|
|
/* clipping is done without rotation, so make rect big enough to contain both positions */
|
2012-03-30 01:51:25 +00:00
|
|
|
BLF_clipping(fs->uifont_id, txtrect.xmin - 1, txtrect.ymin - yofs - xofs - 4, rect->xmax + 1, rect->ymax + 4);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_CLIPPING);
|
2012-03-30 01:51:25 +00:00
|
|
|
BLF_position(fs->uifont_id, txtrect.xmin + xofs, txtrect.ymax - yofs, 0.0f);
|
2009-10-19 03:54:30 +00:00
|
|
|
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_ROTATION);
|
|
|
|
BLF_rotation(fs->uifont_id, angle);
|
2009-10-19 03:54:30 +00:00
|
|
|
|
|
|
|
if (fs->shadow) {
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_SHADOW);
|
|
|
|
BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
|
|
|
|
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
|
2009-10-19 03:54:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fs->kerning == 1)
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
|
2009-10-19 03:54:30 +00:00
|
|
|
|
2012-01-11 12:33:51 +00:00
|
|
|
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_ROTATION);
|
|
|
|
BLF_disable(fs->uifont_id, BLF_CLIPPING);
|
2009-10-19 03:54:30 +00:00
|
|
|
if (fs->shadow)
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_SHADOW);
|
2009-10-19 03:54:30 +00:00
|
|
|
if (fs->kerning == 1)
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
|
2009-10-19 03:54:30 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 16:30:28 +00:00
|
|
|
/* ************** helpers ************************ */
|
2011-07-29 17:42:53 +00:00
|
|
|
/* XXX: read a style configure */
|
2012-03-30 01:51:25 +00:00
|
|
|
uiStyle *UI_GetStyle(void)
|
2011-07-16 18:28:24 +00:00
|
|
|
{
|
2011-07-22 14:14:28 +00:00
|
|
|
uiStyle *style = NULL;
|
|
|
|
/* offset is two struct uiStyle pointers */
|
2012-09-03 02:41:12 +00:00
|
|
|
/* style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2) */;
|
2011-07-22 14:14:28 +00:00
|
|
|
return (style != NULL) ? style : U.uistyles.first;
|
2011-07-16 18:28:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 16:30:28 +00:00
|
|
|
/* temporarily, does widget font */
|
2010-11-17 09:45:45 +00:00
|
|
|
int UI_GetStringWidth(const char *str)
|
2009-04-10 16:30:28 +00:00
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
uiStyle *style = UI_GetStyle();
|
|
|
|
uiFontStyle *fstyle = &style->widget;
|
2010-04-02 11:15:37 +00:00
|
|
|
int width;
|
2009-04-10 16:30:28 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
if (fstyle->kerning == 1) /* for BLF_width */
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
|
2010-04-02 11:15:37 +00:00
|
|
|
|
|
|
|
uiStyleFontSet(fstyle);
|
2012-03-30 01:51:25 +00:00
|
|
|
width = BLF_width(fstyle->uifont_id, str);
|
2010-04-02 11:15:37 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
if (fstyle->kerning == 1)
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
|
2010-04-02 11:15:37 +00:00
|
|
|
|
|
|
|
return width;
|
2009-04-10 16:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* temporarily, does widget font */
|
2010-11-17 09:45:45 +00:00
|
|
|
void UI_DrawString(float x, float y, const char *str)
|
2009-04-10 16:30:28 +00:00
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
uiStyle *style = UI_GetStyle();
|
2009-04-10 16:30:28 +00:00
|
|
|
|
2010-11-07 18:01:32 +00:00
|
|
|
if (style->widget.kerning == 1)
|
|
|
|
BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
|
|
|
|
|
2009-04-10 16:30:28 +00:00
|
|
|
uiStyleFontSet(&style->widget);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_position(style->widget.uifont_id, x, y, 0.0f);
|
2012-01-11 12:33:51 +00:00
|
|
|
BLF_draw(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
|
2010-11-07 18:01:32 +00:00
|
|
|
|
|
|
|
if (style->widget.kerning == 1)
|
|
|
|
BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
|
2009-04-10 16:30:28 +00:00
|
|
|
}
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
/* ************** init exit ************************ */
|
|
|
|
|
2010-07-15 11:51:43 +00:00
|
|
|
/* called on each startup.blend read */
|
2009-04-09 18:11:18 +00:00
|
|
|
/* reading without uifont will create one */
|
|
|
|
void uiStyleInit(void)
|
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
uiFont *font = U.uifonts.first;
|
|
|
|
uiStyle *style = U.uistyles.first;
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
/* recover from uninitialized dpi */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (U.dpi == 0)
|
2012-03-30 01:51:25 +00:00
|
|
|
U.dpi = 72;
|
2011-03-29 14:39:39 +00:00
|
|
|
CLAMP(U.dpi, 48, 128);
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
/* default builtin */
|
2012-03-30 01:51:25 +00:00
|
|
|
if (font == NULL) {
|
|
|
|
font = MEM_callocN(sizeof(uiFont), "ui font");
|
2009-04-09 18:11:18 +00:00
|
|
|
BLI_addtail(&U.uifonts, font);
|
|
|
|
|
2011-09-26 16:53:04 +00:00
|
|
|
BLI_strncpy(font->filename, "default", sizeof(font->filename));
|
2012-03-30 01:51:25 +00:00
|
|
|
font->uifont_id = UIFONT_DEFAULT;
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
for (font = U.uifonts.first; font; font = font->next) {
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
if (font->uifont_id == UIFONT_DEFAULT) {
|
2011-09-26 10:35:47 +00:00
|
|
|
#ifdef WITH_INTERNATIONAL
|
2012-03-30 01:51:25 +00:00
|
|
|
int font_size = datatoc_bfont_ttf_size;
|
|
|
|
unsigned char *font_ttf = (unsigned char *)datatoc_bfont_ttf;
|
2011-09-21 15:15:30 +00:00
|
|
|
static int last_font_size = 0;
|
|
|
|
|
|
|
|
/* use unicode font for translation */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (U.transopts & USER_DOTRANSLATE) {
|
2012-03-30 01:51:25 +00:00
|
|
|
font_ttf = BLF_get_unifont(&font_size);
|
2011-09-21 15:15:30 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!font_ttf) {
|
2011-09-21 15:15:30 +00:00
|
|
|
/* fall back if not found */
|
2012-03-30 01:51:25 +00:00
|
|
|
font_size = datatoc_bfont_ttf_size;
|
|
|
|
font_ttf = (unsigned char *)datatoc_bfont_ttf;
|
2011-09-21 15:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* relload only if needed */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (last_font_size != font_size) {
|
2011-09-21 15:15:30 +00:00
|
|
|
BLF_unload("default");
|
|
|
|
last_font_size = font_size;
|
|
|
|
}
|
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
font->blf_id = BLF_load_mem("default", font_ttf, font_size);
|
2011-09-17 20:50:22 +00:00
|
|
|
#else
|
2012-03-30 01:51:25 +00:00
|
|
|
font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
|
2011-09-17 20:50:22 +00:00
|
|
|
#endif
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-30 01:51:25 +00:00
|
|
|
font->blf_id = BLF_load(font->filename);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (font->blf_id == -1)
|
2012-03-30 01:51:25 +00:00
|
|
|
font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
2009-04-23 21:57:41 +00:00
|
|
|
|
2010-01-22 06:48:29 +00:00
|
|
|
if (font->blf_id == -1) {
|
2012-03-31 00:59:17 +00:00
|
|
|
if (G.debug & G_DEBUG)
|
2011-09-27 17:04:38 +00:00
|
|
|
printf("%s: error, no fonts available\n", __func__);
|
2010-01-22 06:48:29 +00:00
|
|
|
}
|
2009-04-09 18:11:18 +00:00
|
|
|
else {
|
2009-04-23 21:57:41 +00:00
|
|
|
/* ? just for speed to initialize?
|
2009-05-05 23:10:32 +00:00
|
|
|
* Yes, this build the glyph cache and create
|
|
|
|
* the texture.
|
2009-04-23 21:57:41 +00:00
|
|
|
*/
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_size(font->blf_id, 11, U.dpi);
|
|
|
|
BLF_size(font->blf_id, 12, U.dpi);
|
|
|
|
BLF_size(font->blf_id, 14, U.dpi);
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-16 18:28:24 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
if (style == NULL) {
|
|
|
|
ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT);
|
2011-07-16 18:28:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* XXX, this should be moved into a style, but for now best only load the monospaced font once. */
|
2010-11-26 16:33:42 +00:00
|
|
|
if (blf_mono_font == -1)
|
2012-03-30 01:51:25 +00:00
|
|
|
blf_mono_font = BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
|
2010-11-26 16:33:42 +00:00
|
|
|
|
|
|
|
BLF_size(blf_mono_font, 12, 72);
|
|
|
|
|
|
|
|
/* second for rendering else we get threading problems */
|
|
|
|
if (blf_mono_font_render == -1)
|
2012-03-30 01:51:25 +00:00
|
|
|
blf_mono_font_render = BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
|
2010-11-26 16:33:42 +00:00
|
|
|
|
|
|
|
BLF_size(blf_mono_font_render, 12, 72);
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 14:06:24 +00:00
|
|
|
void uiStyleFontSet(uiFontStyle *fs)
|
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
uiFont *font = uifont_to_blfont(fs->uifont_id);
|
2009-04-10 14:06:24 +00:00
|
|
|
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_size(font->blf_id, fs->points, U.dpi);
|
2009-04-10 14:06:24 +00:00
|
|
|
}
|
|
|
|
|