Index: intern/bmfont/BMF_Api.h =================================================================== --- intern/bmfont/BMF_Api.h (revision 10795) +++ intern/bmfont/BMF_Api.h (working copy) @@ -89,13 +89,27 @@ int BMF_GetStringWidth(BMF_Font* font, char* str); /** + * Returns the bounding box of a string of characters. + * @param font The font to use. + * @param str The string. + * @param llx Lower left near x coord + * @param lly Lower left near y coord + * @param llz Lower left near z coord + * @param urx Upper right far x coord + * @param ury Upper right far y coord + * @param urz Upper right far z coord + */ +void BMF_GetStringBoundingBox(BMF_Font* font, char* str, float*llx, float *lly, float *llz, float *urx, float *ury, float *urz); + + +/** * Returns the bounding box of the font. The width and * height represent the bounding box of the union of * all glyps. The minimum and maximum values of the * box represent the extent of the font and its positioning * about the origin. */ -void BMF_GetBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r); +void BMF_GetFontBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r); /** * Convert the given @a font to a texture, and return the GL texture Index: intern/bmfont/intern/BMF_Api.cpp =================================================================== --- intern/bmfont/intern/BMF_Api.cpp (revision 10795) +++ intern/bmfont/intern/BMF_Api.cpp (working copy) @@ -150,11 +150,18 @@ return ((BMF_BitmapFont*)font)->GetStringWidth(str); } +void BMF_GetStringBoundingBox(BMF_Font* font, char* str, float*llx, float *lly, float *llz, float *urx, float *ury, float *urz){ + if (!font){ + *llx = *lly = *llz = *urx = *ury = *urz = 0; + }else{ + ((BMF_BitmapFont*)font)->GetStringBoundingBox(str, llx, lly, llz, urx, ury, urz); + } +} -void BMF_GetBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r) +void BMF_GetFontBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r) { if (!font) return; - ((BMF_BitmapFont*)font)->GetBoundingBox(*xmin_r, *ymin_r, *xmax_r, *ymax_r); + ((BMF_BitmapFont*)font)->GetFontBoundingBox(*xmin_r, *ymin_r, *xmax_r, *ymax_r); } int BMF_GetFontTexture(BMF_Font* font) { Index: intern/bmfont/intern/BMF_BitmapFont.cpp =================================================================== --- intern/bmfont/intern/BMF_BitmapFont.cpp (revision 10795) +++ intern/bmfont/intern/BMF_BitmapFont.cpp (working copy) @@ -107,7 +107,7 @@ return length; } -void BMF_BitmapFont::GetBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax) +void BMF_BitmapFont::GetFontBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax) { xMin = m_fontData->xmin; yMin = m_fontData->ymin; @@ -115,6 +115,29 @@ yMax = m_fontData->ymax; } +void BMF_BitmapFont::GetStringBoundingBox(char* str, float*llx, float *lly, float *llz, float *urx, float *ury, float *urz) +{ + unsigned char c; + int length = 0; + int ascent = 0; + int descent = 0; + + while ( (c = (unsigned char) *str++) ) { + length += m_fontData->chars[c].advance; + int d = m_fontData->chars[c].yorig; + int a = m_fontData->chars[c].height - m_fontData->chars[c].yorig; + if(a > ascent) ascent = a; + if(d > descent) descent = d; + } + *llx = (float)0; + *lly = (float)-descent; + *llz = (float)0; + *urx = (float)length; + *ury = (float)ascent; + *urz = (float)0; +} + + int BMF_BitmapFont::GetTexture() { int fWidth = m_fontData->xmax - m_fontData->xmin; Index: intern/bmfont/intern/BMF_BitmapFont.h =================================================================== --- intern/bmfont/intern/BMF_BitmapFont.h (revision 10795) +++ intern/bmfont/intern/BMF_BitmapFont.h (working copy) @@ -76,8 +76,22 @@ * box represent the extent of the font and its positioning * about the origin. */ - void GetBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax); + void GetFontBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax); + + /** + * Returns the bounding box of a string of characters. + * @param font The font to use. + * @param str The string. + * @param llx Lower left near x coord + * @param lly Lower left near y coord + * @param llz Lower left near z coord + * @param urx Upper right far x coord + * @param ury Upper right far y coord + * @param urz Upper right far z coord + */ + void GetStringBoundingBox(char* str, float*llx, float *lly, float *llz, float *urx, float *ury, float *urz); + /** * Convert the font to a texture, and return the GL texture * ID of the texture. If the texture ID is bound, text can Index: source/blender/ftfont/FTF_Api.h =================================================================== --- source/blender/ftfont/FTF_Api.h (revision 10795) +++ source/blender/ftfont/FTF_Api.h (working copy) @@ -106,12 +106,12 @@ /** * Get Bounding Box - * @param llx - * @param lly - * @param llz - * @param urx - * @param ury - * @param urz + * @param llx Lower left near x coord + * @param lly Lower left near y coord + * @param llz Lower left near z coord + * @param urx Upper right far x coord + * @param ury Upper right far y coord + * @param urz Upper right far z coord * @param mode flag to forward to FTF_TransConvString() * not test yet. */ Index: source/blender/ftfont/intern/FTF_TTFont.h =================================================================== --- source/blender/ftfont/intern/FTF_TTFont.h (revision 10795) +++ source/blender/ftfont/intern/FTF_TTFont.h (working copy) @@ -78,6 +78,17 @@ float GetStringWidth(char* str, unsigned int flag); + /** + * Get the bounding box for a string. + * + * @param str The string + * @param llx Lower left near x coord + * @param lly Lower left near y coord + * @param llz Lower left near z coord + * @param urx Upper right far x coord + * @param ury Upper right far y coord + * @param urz Upper right far z coord + */ void GetBoundingBox(char* str, float *llx, float *lly, float *llz, float *urx, float *ury, float *urz, unsigned int flag); /** Index: source/blender/include/BIF_language.h =================================================================== --- source/blender/include/BIF_language.h (revision 10795) +++ source/blender/include/BIF_language.h (working copy) @@ -47,6 +47,7 @@ int BIF_DrawString(struct BMF_Font* font, char *str, int translate); float BIF_GetStringWidth(struct BMF_Font* font, char *str, int translate); +void BIF_GetBoundingBox(struct BMF_Font* font, char* str, int translate, float*llx, float *lly, float *llz, float *urx, float *ury, float *urz); void BIF_RasterPos(float x, float y); void BIF_SetScale(float aspect); Index: source/blender/src/interface.c =================================================================== --- source/blender/src/interface.c (revision 10795) +++ source/blender/src/interface.c (working copy) @@ -4805,31 +4805,19 @@ { uiOverDraw *od; float x1, x2, y1, y2; + + /* names: lu lower/upper, lr left/right, x/y/z */ + float llx,lly,llz,urx,ury,urz; + BIF_GetBoundingBox(but->font, but->tip, (U.transopts & USER_TR_TOOLTIPS), &llx, &lly, &llz, &urx, &ury, &urz); + + x1= (but->x1+but->x2)/2; + /* 8 adds a little padding at the end of the string */ + x2= 8+x1+but->aspect*(urx-llx); + /* 2 shifts the backbox to the tooltip upwards a little */ + y2= but->y1-2; + y1= y2-(2+ury+(ury-lly)); -#ifdef INTERNATIONAL - if(G.ui_international == TRUE) { - float llx,lly,llz,urx,ury,urz; //for FTF_GetBoundingBox() - if(U.transopts & USER_TR_TOOLTIPS) { - FTF_GetBoundingBox(but->tip, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8); - - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_USE_GETTEXT | FTF_INPUT_UTF8); //BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12; - } else { - FTF_GetBoundingBox(but->tip, &llx,&lly,&llz,&urx,&ury,&urz, FTF_NO_TRANSCONV | FTF_INPUT_UTF8); - - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_NO_TRANSCONV | FTF_INPUT_UTF8); //BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12; - } - } else { - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-30; y2= but->y1-12; - } -#else - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-30; y2= but->y1-12; -#endif - /* for pulldown menus it doesnt work */ if(mywinget()==G.curscreen->mainwin); else { Index: source/blender/src/language.c =================================================================== --- source/blender/src/language.c (revision 10795) +++ source/blender/src/language.c (working copy) @@ -134,7 +134,21 @@ return rt; } +void BIF_GetBoundingBox(struct BMF_Font* font, char* str, int translate, float*llx, float *lly, float *llz, float *urx, float *ury, float *urz){ +#ifdef INTERNATIONAL + if(G.ui_international == TRUE) + if(translate && (U.transopts & USER_TR_BUTTONS)) + FTF_GetBoundingBox(str, llx, lly, llz, urx, ury, urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8); + else + FTF_GetBoundingBox(str, llx, lly, llz, urx, ury, urz, FTF_NO_TRANSCONV | FTF_INPUT_UTF8); + else + BMF_GetStringBoundingBox(font, str, llx, lly, llz, urx, ury, urz); +#else + BMF_GetStringBoundingBox(font, str, llx, lly, llz, urx, ury, urz); +#endif +} + #ifdef INTERNATIONAL char *fontsize_pup(void)