new BLF functions

- BLF_height_max
- BLF_width_max
- BLF_descender
- BLF_ascender

use for tooltip and image stamp.
This commit is contained in:
Campbell Barton 2011-05-04 15:09:48 +00:00
parent d000103e80
commit 015a32d01c
5 changed files with 97 additions and 50 deletions

View File

@ -90,6 +90,14 @@ void BLF_boundbox(int fontid, const char *str, struct rctf *box);
float BLF_width(int fontid, const char *str);
float BLF_height(int fontid, const char *str);
/*
* Return dimensions of the font without any sample text.
*/
float BLF_height_max(int fontid);
float BLF_width_max(int fontid);
float BLF_descender(int fontid);
float BLF_ascender(int fontid);
/*
* The following function return the width and height of the string, but
* just in one call, so avoid extra freetype2 stuff.

View File

@ -580,6 +580,54 @@ float BLF_height(int fontid, const char *str)
return(0.0f);
}
float BLF_height_max(int fontid)
{
FontBLF *font;
font= BLF_get(fontid);
if (font) {
if(font->glyph_cache)
return(font->glyph_cache->max_glyph_height);
}
return(0.0f);
}
float BLF_width_max(int fontid)
{
FontBLF *font;
font= BLF_get(fontid);
if (font) {
if(font->glyph_cache)
return(font->glyph_cache->max_glyph_width);
}
return(0.0f);
}
float BLF_descender(int fontid)
{
FontBLF *font;
font= BLF_get(fontid);
if (font) {
if(font->glyph_cache)
return(font->glyph_cache->descender);
}
return(0.0f);
}
float BLF_ascender(int fontid)
{
FontBLF *font;
font= BLF_get(fontid);
if (font) {
if(font->glyph_cache)
return(font->glyph_cache->ascender);
}
return(0.0f);
}
float BLF_height_default(const char *str)
{
float height;

View File

@ -1011,7 +1011,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
int x, y, y_ofs;
float h_fixed;
const int mono= blf_mono_font_render; // XXX
#define BUFF_MARGIN_X 2
#define BUFF_MARGIN_Y 1
if (!rect && !rectf)
return;
@ -1026,23 +1029,11 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
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, "--");
pad= BLF_width_max(mono);
/* use 'h_fixed' rather then 'h', aligns better */
// BLF_width_and_height(mono, "^|/_AgPpJjlYy", &w, &h_fixed);
{
rctf box;
float baseline;
BLF_boundbox(mono, "^|/_AgPpJjlYy", &box);
h_fixed= box.ymax - box.ymin;
/* crude way to get the decent line from A->j*/
BLF_boundbox(mono, "A", &box);
baseline= box.ymin;
BLF_boundbox(mono, "j", &box);
y_ofs = (int)(baseline - box.ymin);
if(y_ofs < 0) y_ofs= 0; /* should never happen */
}
h_fixed= BLF_height_max(mono);
y_ofs = -BLF_descender(mono);
x= 0;
y= height;
@ -1053,14 +1044,14 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
y -= h;
/* also a little of space to the background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, w+3, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and draw the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.file);
/* the extra pixel for background. */
y -= 5;
y -= BUFF_MARGIN_Y * 2;
}
/* Top left corner, below File */
@ -1069,13 +1060,13 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
y -= h;
/* and space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.note);
/* the extra pixel for background. */
y -= 5;
y -= BUFF_MARGIN_Y * 2;
}
/* Top left corner, below File (or Note) */
@ -1084,13 +1075,13 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
y -= h;
/* and space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.date);
/* the extra pixel for background. */
y -= 5;
y -= BUFF_MARGIN_Y * 2;
}
/* Top left corner, below File, Date or Note */
@ -1099,7 +1090,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
y -= h;
/* and space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.rendertime);
@ -1113,7 +1104,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
BLF_width_and_height(mono, stamp_data.marker, &w, &h); h= h_fixed;
/* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, w+2, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
@ -1128,7 +1119,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
BLF_width_and_height(mono, stamp_data.time, &w, &h); h= h_fixed;
/* extra space for background */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
@ -1142,7 +1133,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
BLF_width_and_height(mono, stamp_data.frame, &w, &h); h= h_fixed;
/* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
@ -1156,7 +1147,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
BLF_width_and_height(mono, stamp_data.camera, &w, &h); h= h_fixed;
/* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.camera);
@ -1168,7 +1159,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h= h_fixed;
/* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.cameralens);
}
@ -1180,7 +1171,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
x= width - w - 2;
/* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+3, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y+y_ofs, 0.0);
@ -1195,7 +1186,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
y= height - h;
/* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, x+w+pad, y+h+2);
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.strip);
@ -1203,6 +1194,9 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
/* cleanup the buffer. */
BLF_buffer(mono, NULL, NULL, 0, 0, 0);
#undef BUFF_MARGIN_X
#undef BUFF_MARGIN_Y
}
void BKE_stamp_info(Scene *scene, Object *camera, struct ImBuf *ibuf)

View File

@ -1144,16 +1144,9 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode)
switch (p->sa->spacetype) {
case SPACE_VIEW3D:
{
View3D *v3d= p->sa->spacedata.first;
RegionView3D *rv3d= p->ar->regiondata;
float rvec[3];
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
view3d_calc_camera_border(p->scene, p->ar, NULL, v3d, &p->subrect_data, -1); /* negative shift */
p->subrect= &p->subrect_data;
}
/* get reference point for 3d space placement */
gp_get_3d_reference(p, rvec);
initgrabz(rv3d, rvec[0], rvec[1], rvec[2]);

View File

@ -485,18 +485,17 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
data->fstyle.align= UI_STYLE_TEXT_CENTER;
uiStyleFontSet(&data->fstyle);
/* clipping is very strict & gives problems in some cases [#27218]
* use the tallest line height. */
h= 0;
for(a=0; a<data->totline; a++) {
int h_tmp= BLF_height(data->fstyle.uifont_id, data->lines[a]);
h= MAX2(h, h_tmp);
}
/* these defines may need to be tweaked depending on font */
#define TIP_MARGIN_Y 2
#define TIP_BORDER_X 16.0f
#define TIP_BORDER_Y 6.0f
h= BLF_height_max(data->fstyle.uifont_id);
for(a=0, fontw=0, fonth=0; a<data->totline; a++) {
w= BLF_width(data->fstyle.uifont_id, data->lines[a]);
fontw= MAX2(fontw, w);
fonth += (a == 0)? h: h+5;
fonth += (a == 0)? h: h+TIP_MARGIN_Y;
}
fontw *= aspect;
@ -505,17 +504,22 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
data->toth= fonth;
data->lineh= h;
data->spaceh= 5;
data->spaceh= TIP_MARGIN_Y;
/* compute position */
ofsx= (but->block->panel)? but->block->panel->ofsx: 0;
ofsy= (but->block->panel)? but->block->panel->ofsy: 0;
x1f= (but->x1+but->x2)/2.0f + ofsx - 16.0f*aspect;
x2f= x1f + fontw + 16.0f*aspect;
y2f= but->y1 + ofsy - 15.0f*aspect;
y1f= y2f - fonth*aspect - 15.0f*aspect;
x1f= (but->x1 + but->x2) * 0.5f + ofsx - (TIP_BORDER_X * aspect);
x2f= x1f + fontw + (TIP_BORDER_X * aspect);
y2f= but->y1 + ofsy - (TIP_BORDER_Y * aspect);
y1f= y2f - fonth*aspect - (TIP_BORDER_Y * aspect);
#undef TIP_MARGIN_Y
#undef TIP_BORDER_X
#undef TIP_BORDER_Y
/* copy to int, gets projected if possible too */
x1= x1f; y1= y1f; x2= x2f; y2= y2f;