[Bf-blender-cvs] [0d65520f05e] master: BLF: add new arguments to BLF_GlyphBoundsFn

Campbell Barton noreply at git.blender.org
Sun May 3 09:08:21 CEST 2020


Commit: 0d65520f05ec5474e62d453aa62eb06efa3981d7
Author: Campbell Barton
Date:   Sun May 3 16:51:34 2020 +1000
Branches: master
https://developer.blender.org/rB0d65520f05ec5474e62d453aa62eb06efa3981d7

BLF: add new arguments to BLF_GlyphBoundsFn

- glyph_bounds: to get the character width.
- glyph_bearing: lower left character starting point.

These values are needed for more precise glyph calculations.

===================================================================

M	source/blender/blenfont/BLF_api.h
M	source/blender/blenfont/intern/blf_font.c
M	source/blender/blenfont/intern/blf_internal.h
M	source/blender/editors/interface/interface_widgets.c

===================================================================

diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index f6f1393bd21..2158596745a 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -117,9 +117,11 @@ void BLF_draw_ascii(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
 int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) ATTR_NONNULL(2);
 
 typedef bool (*BLF_GlyphBoundsFn)(const char *str,
-                                  const size_t str_ofs,
-                                  const struct rcti *glyph_bounds,
+                                  const size_t str_step_ofs,
+                                  const struct rcti *glyph_step_bounds,
                                   const int glyph_advance_x,
+                                  const struct rctf *glyph_bounds,
+                                  const float glyph_bearing[2],
                                   void *user_data);
 
 void BLF_boundbox_foreach_glyph_ex(int fontid,
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index ed92e9aaff2..0eee887efa6 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -1252,7 +1252,7 @@ static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
 
     pen_x += g->advance_i;
 
-    if (user_fn(str, i_curr, &gbox, g->advance_i, user_data) == false) {
+    if (user_fn(str, i_curr, &gbox, g->advance_i, &g->box, &g->pos_x, user_data) == false) {
       break;
     }
 
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 98ada87d16d..a8c874b19ec 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -103,9 +103,11 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
                                      const char *str,
                                      size_t len,
                                      bool (*user_fn)(const char *str,
-                                                     const size_t str_ofs,
-                                                     const struct rcti *glyph_bounds,
+                                                     const size_t str_step_ofs,
+                                                     const struct rcti *glyph_step_bounds,
                                                      const int glyph_advance_x,
+                                                     const struct rctf *glyph_bounds,
+                                                     const float glyph_bearing[2],
                                                      void *user_data),
                                      void *user_data,
                                      struct ResultBLF *r_info);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 0142f3b38e0..e927d259926 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2095,15 +2095,17 @@ static void widget_draw_text_ime_underline(const uiFontStyle *fstyle,
 #endif /* WITH_INPUT_IME */
 
 static bool widget_draw_text_underline_calc_center_x(const char *UNUSED(str),
-                                                     const size_t str_ofs,
-                                                     const rcti *glyph_bounds,
+                                                     const size_t str_step_ofs,
+                                                     const rcti *glyph_step_bounds,
                                                      const int glyph_advance_x,
+                                                     const rctf *UNUSED(glyph_bounds),
+                                                     const float UNUSED(glyph_bearing[2]),
                                                      void *user_data)
 {
   /* The index of the character to get, set to the x-position. */
   int *ul_data = user_data;
-  if (ul_data[0] == (int)str_ofs) {
-    ul_data[1] = glyph_bounds->xmin + (glyph_advance_x / 2);
+  if (ul_data[0] == (int)str_step_ofs) {
+    ul_data[1] = glyph_step_bounds->xmin + (glyph_advance_x / 2);
     /* Early exit. */
     return false;
   }



More information about the Bf-blender-cvs mailing list