[Bf-blender-cvs] [ccaab726857] master: BLF: use 'int' for internal glyph x, y bearing

Campbell Barton noreply at git.blender.org
Sun May 3 10:02:15 CEST 2020


Commit: ccaab7268572f1640411309463009b3a3453b247
Author: Campbell Barton
Date:   Sun May 3 17:55:39 2020 +1000
Branches: master
https://developer.blender.org/rBccaab7268572f1640411309463009b3a3453b247

BLF: use 'int' for internal glyph x,y bearing

These were stored as float but were originally cast from an int
and were often cast back to int.

Also use int pairs for dimensions values.

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

M	source/blender/blenfont/BLF_api.h
M	source/blender/blenfont/intern/blf.c
M	source/blender/blenfont/intern/blf_font.c
M	source/blender/blenfont/intern/blf_glyph.c
M	source/blender/blenfont/intern/blf_internal.h
M	source/blender/blenfont/intern/blf_internal_types.h
M	source/blender/blenfont/intern/blf_thumbs.c
M	source/blender/editors/interface/interface_handlers.c
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 2158596745a..ddb88cf61ed 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -121,7 +121,7 @@ typedef bool (*BLF_GlyphBoundsFn)(const char *str,
                                   const struct rcti *glyph_step_bounds,
                                   const int glyph_advance_x,
                                   const struct rctf *glyph_bounds,
-                                  const float glyph_bearing[2],
+                                  const int glyph_bearing[2],
                                   void *user_data);
 
 void BLF_boundbox_foreach_glyph_ex(int fontid,
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 394704e1c20..2f7d5a60a6f 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -946,8 +946,8 @@ void BLF_buffer(int fontid,
   if (font) {
     font->buf_info.fbuf = fbuf;
     font->buf_info.cbuf = cbuf;
-    font->buf_info.w = w;
-    font->buf_info.h = h;
+    font->buf_info.dims[0] = w;
+    font->buf_info.dims[1] = h;
     font->buf_info.ch = nch;
     font->buf_info.display = display;
   }
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 0eee887efa6..e5e03418073 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -613,28 +613,28 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
       BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
     }
 
-    chx = pen_x + ((int)g->pos_x);
-    chy = pen_y_basis + g->height;
+    chx = pen_x + ((int)g->pos[0]);
+    chy = pen_y_basis + g->dims[1];
 
     if (g->pitch < 0) {
-      pen_y = pen_y_basis + (g->height - (int)g->pos_y);
+      pen_y = pen_y_basis + (g->dims[1] - g->pos[1]);
     }
     else {
-      pen_y = pen_y_basis - (g->height - (int)g->pos_y);
+      pen_y = pen_y_basis - (g->dims[1] - g->pos[1]);
     }
 
-    if ((chx + g->width) >= 0 && chx < buf_info->w && (pen_y + g->height) >= 0 &&
-        pen_y < buf_info->h) {
+    if ((chx + g->dims[0]) >= 0 && chx < buf_info->dims[0] && (pen_y + g->dims[1]) >= 0 &&
+        pen_y < buf_info->dims[1]) {
       /* don't draw beyond the buffer bounds */
-      int width_clip = g->width;
-      int height_clip = g->height;
-      int yb_start = g->pitch < 0 ? 0 : g->height - 1;
+      int width_clip = g->dims[0];
+      int height_clip = g->dims[1];
+      int yb_start = g->pitch < 0 ? 0 : g->dims[1] - 1;
 
-      if (width_clip + chx > buf_info->w) {
-        width_clip -= chx + width_clip - buf_info->w;
+      if (width_clip + chx > buf_info->dims[0]) {
+        width_clip -= chx + width_clip - buf_info->dims[0];
       }
-      if (height_clip + pen_y > buf_info->h) {
-        height_clip -= pen_y + height_clip - buf_info->h;
+      if (height_clip + pen_y > buf_info->dims[1]) {
+        height_clip -= pen_y + height_clip - buf_info->dims[1];
       }
 
       /* drawing below the image? */
@@ -652,7 +652,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
             if (a_byte) {
               const float a = (a_byte / 255.0f) * b_col_float[3];
               const size_t buf_ofs = (((size_t)(chx + x) +
-                                       ((size_t)(pen_y + y) * (size_t)buf_info->w)) *
+                                       ((size_t)(pen_y + y) * (size_t)buf_info->dims[0])) *
                                       (size_t)buf_info->ch);
               float *fbuf = buf_info->fbuf + buf_ofs;
 
@@ -689,7 +689,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
             if (a_byte) {
               const float a = (a_byte / 255.0f) * b_col_float[3];
               const size_t buf_ofs = (((size_t)(chx + x) +
-                                       ((size_t)(pen_y + y) * (size_t)buf_info->w)) *
+                                       ((size_t)(pen_y + y) * (size_t)buf_info->dims[0])) *
                                       (size_t)buf_info->ch);
               unsigned char *cbuf = buf_info->cbuf + buf_ofs;
 
@@ -1246,13 +1246,13 @@ static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
     }
 
     gbox.xmin = pen_x;
-    gbox.xmax = gbox.xmin + MIN2(g->advance_i, g->width);
+    gbox.xmax = gbox.xmin + MIN2(g->advance_i, g->dims[0]);
     gbox.ymin = pen_y;
-    gbox.ymax = gbox.ymin - g->height;
+    gbox.ymax = gbox.ymin - g->dims[1];
 
     pen_x += g->advance_i;
 
-    if (user_fn(str, i_curr, &gbox, g->advance_i, &g->box, &g->pos_x, user_data) == false) {
+    if (user_fn(str, i_curr, &gbox, g->advance_i, &g->box, g->pos, user_data) == false) {
       break;
     }
 
@@ -1365,8 +1365,8 @@ static void blf_font_fill(FontBLF *font)
 
   font->buf_info.fbuf = NULL;
   font->buf_info.cbuf = NULL;
-  font->buf_info.w = 0;
-  font->buf_info.h = 0;
+  font->buf_info.dims[0] = 0;
+  font->buf_info.dims[1] = 0;
   font->buf_info.ch = 0;
   font->buf_info.col_init[0] = 0;
   font->buf_info.col_init[1] = 0;
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index a38cb323777..e6726735db6 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -327,26 +327,26 @@ GlyphBLF *blf_glyph_add(FontBLF *font, GlyphCacheBLF *gc, unsigned int index, un
   g->c = c;
   g->idx = (FT_UInt)index;
   bitmap = slot->bitmap;
-  g->width = (int)bitmap.width;
-  g->height = (int)bitmap.rows;
+  g->dims[0] = (int)bitmap.width;
+  g->dims[1] = (int)bitmap.rows;
 
-  if (g->width && g->height) {
+  if (g->dims[0] && g->dims[1]) {
     if (font->flags & BLF_MONOCHROME) {
       /* Font buffer uses only 0 or 1 values, Blender expects full 0..255 range */
       int i;
-      for (i = 0; i < (g->width * g->height); i++) {
+      for (i = 0; i < (g->dims[0] * g->dims[1]); i++) {
         bitmap.buffer[i] = bitmap.buffer[i] ? 255 : 0;
       }
     }
 
-    g->bitmap = (unsigned char *)MEM_mallocN((size_t)g->width * (size_t)g->height, "glyph bitmap");
-    memcpy((void *)g->bitmap, (void *)bitmap.buffer, (size_t)g->width * (size_t)g->height);
+    g->bitmap = MEM_mallocN((size_t)g->dims[0] * (size_t)g->dims[1], "glyph bitmap");
+    memcpy(g->bitmap, (void *)bitmap.buffer, (size_t)g->dims[0] * (size_t)g->dims[1]);
   }
 
   g->advance = ((float)slot->advance.x) / 64.0f;
   g->advance_i = (int)g->advance;
-  g->pos_x = (float)slot->bitmap_left;
-  g->pos_y = (float)slot->bitmap_top;
+  g->pos[0] = slot->bitmap_left;
+  g->pos[1] = slot->bitmap_top;
   g->pitch = slot->bitmap.pitch;
 
   FT_Outline_Get_CBox(&(slot->outline), &bbox);
@@ -431,10 +431,10 @@ static void blf_texture3_draw(const unsigned char color_in[4],
 
 static void blf_glyph_calc_rect(rctf *rect, GlyphBLF *g, float x, float y)
 {
-  rect->xmin = floorf(x + g->pos_x);
-  rect->xmax = rect->xmin + (float)g->width;
-  rect->ymin = floorf(y + g->pos_y);
-  rect->ymax = rect->ymin - (float)g->height;
+  rect->xmin = floorf(x + (float)g->pos[0]);
+  rect->xmax = rect->xmin + (float)g->dims[0];
+  rect->ymin = floorf(y + (float)g->pos[1]);
+  rect->ymax = rect->ymin - (float)g->dims[1];
 }
 
 static void blf_glyph_calc_rect_test(rctf *rect, GlyphBLF *g, float x, float y)
@@ -443,9 +443,9 @@ static void blf_glyph_calc_rect_test(rctf *rect, GlyphBLF *g, float x, float y)
    * width used by BLF_width. This allows that the text slightly
    * overlaps the clipping border to achieve better alignment. */
   rect->xmin = floorf(x);
-  rect->xmax = rect->xmin + MIN2(g->advance, (float)g->width);
+  rect->xmax = rect->xmin + MIN2(g->advance, (float)g->dims[0]);
   rect->ymin = floorf(y);
-  rect->ymax = rect->ymin - (float)g->height;
+  rect->ymax = rect->ymin - (float)g->dims[1];
 }
 
 static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y, FontBLF *font)
@@ -455,7 +455,7 @@ static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y
 
 void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, float y)
 {
-  if ((!g->width) || (!g->height)) {
+  if ((!g->dims[0]) || (!g->dims[1])) {
     return;
   }
 
@@ -466,7 +466,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
 
     g->offset = gc->bitmap_len;
 
-    int buff_size = g->width * g->height;
+    int buff_size = g->dims[0] * g->dims[1];
     int bitmap_len = gc->bitmap_len + buff_size;
 
     if (bitmap_len > gc->bitmap_len_alloc) {
@@ -514,7 +514,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
 
     if (font->shadow == 0) {
       blf_texture_draw(font->shadow_color,
-                       (int[2]){g->width, g->height},
+                       g->dims,
                        g->offset,
                        rect_ofs.xmin,
                        rect_ofs.ymin,
@@ -523,7 +523,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
     }
     else if (font->shadow <= 4) {
       blf_texture3_draw(font->shadow_color,
-                        (int[2]){g->width, g->height},
+                        g->dims,
                         g->offset,
                         rect_ofs.xmin,
                         rect_ofs.ymin,
@@ -532,7 +532,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
     }
     else {
       blf_texture5_draw(font->shadow_color,
-                        (int[2]){g->width, g->height},
+                        g->dims,
                         g->offset,
                         rect_ofs.xmin,
                         rect_ofs.ymin,
@@ -547,39 +547,18 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
 #if BLF_BLUR_ENABLE
   switch (font->blur) {
     case 3:
-      blf_texture3_draw(font->color,
-                        (int[2]){g->width, g->height},
-                        g->offset,
-                        rect.xmin,
-                        rect.ymin,
-                        rect.xmax,
-                        rect.ymax);
+      blf_texture3_draw(
+          font->color, g->dims, g->offset, rect.xmin, rect.ymin, rect.xmax, rect.

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list