Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarley Acheson <harley.acheson@gmail.com>2022-09-24 03:36:49 +0300
committerHarley Acheson <harley.acheson@gmail.com>2022-09-24 03:36:49 +0300
commitcd1631b17dd0e25a8a398fb00a982ca5f0633558 (patch)
treeee8d9cdb560c815ea86d952ef2f053c6435865c1
parent88a602bc64fc2a86411d67881439a04486f95030 (diff)
BLF: Refactor of DPI
Correction of U.dpi to hold actual monitor DPI. Simplify font sizing by omitting DPI as API argument, always using 72 internally. See D15961 for more details. Differential Revision: https://developer.blender.org/D15961 Reviewed by Campbell Barton
-rw-r--r--source/blender/blenfont/BLF_api.h3
-rw-r--r--source/blender/blenfont/intern/blf.c7
-rw-r--r--source/blender/blenfont/intern/blf_default.c10
-rw-r--r--source/blender/blenfont/intern/blf_font.c16
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c9
-rw-r--r--source/blender/blenfont/intern/blf_internal.h9
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h6
-rw-r--r--source/blender/blenfont/intern/blf_thumbs.c3
-rw-r--r--source/blender/blenkernel/intern/image.cc2
-rw-r--r--source/blender/blenkernel/intern/image_gen.c2
-rw-r--r--source/blender/draw/intern/draw_manager_text.c2
-rw-r--r--source/blender/editors/interface/interface_icons_event.c2
-rw-r--r--source/blender/editors/interface/interface_panel.cc2
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.cc4
-rw-r--r--source/blender/editors/interface/interface_style.cc2
-rw-r--r--source/blender/editors/mesh/editmesh_bevel.c2
-rw-r--r--source/blender/editors/mesh/editmesh_knife.c8
-rw-r--r--source/blender/editors/object/object_remesh.cc2
-rw-r--r--source/blender/editors/screen/area.c2
-rw-r--r--source/blender/editors/space_clip/clip_dopesheet_draw.c2
-rw-r--r--source/blender/editors/space_clip/clip_draw.c2
-rw-r--r--source/blender/editors/space_image/image_draw.c2
-rw-r--r--source/blender/editors/space_info/textview.c2
-rw-r--r--source/blender/editors/space_node/node_draw.cc2
-rw-r--r--source/blender/editors/space_spreadsheet/space_spreadsheet.cc4
-rw-r--r--source/blender/editors/space_text/text_draw.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_ruler.c2
-rw-r--r--source/blender/editors/util/ed_draw.c2
-rw-r--r--source/blender/python/generic/blf_py_api.c17
-rw-r--r--source/blender/sequencer/intern/effects.c2
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c2
-rw-r--r--source/blender/windowmanager/intern/wm_playanim.c2
-rw-r--r--source/blender/windowmanager/intern/wm_window.c17
34 files changed, 71 insertions, 84 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index d3226a8f609..992107a30e9 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -69,7 +69,7 @@ void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size);
void BLF_aspect(int fontid, float x, float y, float z);
void BLF_position(int fontid, float x, float y, float z);
-void BLF_size(int fontid, float size, int dpi);
+void BLF_size(int fontid, float size);
/* Goal: small but useful color API. */
@@ -303,7 +303,6 @@ void BLF_thumb_preview(const char *filepath,
/* blf_default.c */
-void BLF_default_dpi(int dpi);
void BLF_default_size(float size);
void BLF_default_set(int fontid);
/**
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 9d9cc51ebcc..4e904768f79 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -63,8 +63,6 @@ int BLF_init(void)
global_font[i] = NULL;
}
- BLF_default_dpi(72);
-
return blf_font_init();
}
@@ -361,12 +359,12 @@ void BLF_position(int fontid, float x, float y, float z)
}
}
-void BLF_size(int fontid, float size, int dpi)
+void BLF_size(int fontid, float size)
{
FontBLF *font = blf_get(fontid);
if (font) {
- blf_font_size(font, size, dpi);
+ blf_font_size(font, size);
}
}
@@ -912,7 +910,6 @@ void BLF_state_print(int fontid)
printf("fontid %d %p\n", fontid, (void *)font);
printf(" name: '%s'\n", font->name);
printf(" size: %f\n", font->size);
- printf(" dpi: %u\n", font->dpi);
printf(" pos: %d %d %d\n", UNPACK3(font->pos));
printf(" aspect: (%d) %.6f %.6f %.6f\n",
(font->flags & BLF_ROTATION) != 0,
diff --git a/source/blender/blenfont/intern/blf_default.c b/source/blender/blenfont/intern/blf_default.c
index a1f1b84636f..a521d65fe30 100644
--- a/source/blender/blenfont/intern/blf_default.c
+++ b/source/blender/blenfont/intern/blf_default.c
@@ -20,15 +20,9 @@
/* Default size and dpi, for BLF_draw_default. */
static int global_font_default = -1;
-static int global_font_dpi = 72;
/* Keep in sync with `UI_DEFAULT_TEXT_POINTS` */
static float global_font_size = 11.0f;
-void BLF_default_dpi(int dpi)
-{
- global_font_dpi = dpi;
-}
-
void BLF_default_size(float size)
{
global_font_size = size;
@@ -51,7 +45,7 @@ int BLF_set_default(void)
{
ASSERT_DEFAULT_SET;
- BLF_size(global_font_default, global_font_size, global_font_dpi);
+ BLF_size(global_font_default, global_font_size);
return global_font_default;
}
@@ -59,7 +53,7 @@ int BLF_set_default(void)
void BLF_draw_default(float x, float y, float z, const char *str, const size_t str_len)
{
ASSERT_DEFAULT_SET;
- BLF_size(global_font_default, global_font_size, global_font_dpi);
+ BLF_size(global_font_default, global_font_size * U.dpi_fac);
BLF_position(global_font_default, x, y, z);
BLF_draw(global_font_default, str, str_len);
}
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index fcded5a13cd..3d7e83bc22f 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -1300,7 +1300,6 @@ static void blf_font_fill(FontBLF *font)
font->clip_rec.ymin = 0;
font->clip_rec.ymax = 0;
font->flags = 0;
- font->dpi = 0;
font->size = 0;
BLI_listbase_clear(&font->cache);
font->kerning_cache = NULL;
@@ -1613,8 +1612,8 @@ void blf_ensure_size(FontBLF *font)
scaler.width = 0;
scaler.height = round_fl_to_uint(font->size * 64.0f);
scaler.pixel = 0;
- scaler.x_res = font->dpi;
- scaler.y_res = font->dpi;
+ scaler.x_res = BLF_DPI;
+ scaler.y_res = BLF_DPI;
if (FTC_Manager_LookupSize(ftc_manager, &scaler, &font->ft_size) == FT_Err_Ok) {
font->ft_size->generic.data = (void *)font;
font->ft_size->generic.finalizer = blf_size_finalizer;
@@ -1624,7 +1623,7 @@ void blf_ensure_size(FontBLF *font)
BLI_assert_unreachable();
}
-bool blf_font_size(FontBLF *font, float size, uint dpi)
+bool blf_font_size(FontBLF *font, float size)
{
if (!blf_ensure_face(font)) {
return false;
@@ -1635,15 +1634,15 @@ bool blf_font_size(FontBLF *font, float size, uint dpi)
/* Adjust our new size to be on even 64ths. */
size = (float)ft_size / 64.0f;
- if (font->size != size || font->dpi != dpi) {
+ if (font->size != size) {
if (font->flags & BLF_CACHED) {
FTC_ScalerRec scaler = {0};
scaler.face_id = font;
scaler.width = 0;
scaler.height = ft_size;
scaler.pixel = 0;
- scaler.x_res = dpi;
- scaler.y_res = dpi;
+ scaler.x_res = BLF_DPI;
+ scaler.y_res = BLF_DPI;
if (FTC_Manager_LookupSize(ftc_manager, &scaler, &font->ft_size) != FT_Err_Ok) {
return false;
}
@@ -1651,7 +1650,7 @@ bool blf_font_size(FontBLF *font, float size, uint dpi)
font->ft_size->generic.finalizer = blf_size_finalizer;
}
else {
- if (FT_Set_Char_Size(font->face, 0, ft_size, dpi, dpi) != FT_Err_Ok) {
+ if (FT_Set_Char_Size(font->face, 0, ft_size, BLF_DPI, BLF_DPI) != FT_Err_Ok) {
return false;
}
font->ft_size = font->face->size;
@@ -1659,7 +1658,6 @@ bool blf_font_size(FontBLF *font, float size, uint dpi)
}
font->size = size;
- font->dpi = dpi;
return true;
}
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index c08d52307b7..4704199c8a1 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -63,11 +63,11 @@ static FT_Fixed to_16dot16(double val)
/** \name Glyph Cache
* \{ */
-static GlyphCacheBLF *blf_glyph_cache_find(const FontBLF *font, const float size, uint dpi)
+static GlyphCacheBLF *blf_glyph_cache_find(const FontBLF *font, const float size)
{
GlyphCacheBLF *gc = (GlyphCacheBLF *)font->cache.first;
while (gc) {
- if (gc->size == size && gc->dpi == dpi && (gc->bold == ((font->flags & BLF_BOLD) != 0)) &&
+ if (gc->size == size && (gc->bold == ((font->flags & BLF_BOLD) != 0)) &&
(gc->italic == ((font->flags & BLF_ITALIC) != 0)) &&
(gc->char_weight == font->char_weight) && (gc->char_slant == font->char_slant) &&
(gc->char_width == font->char_width) && (gc->char_spacing == font->char_spacing)) {
@@ -85,7 +85,6 @@ static GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
gc->next = NULL;
gc->prev = NULL;
gc->size = font->size;
- gc->dpi = font->dpi;
gc->bold = ((font->flags & BLF_BOLD) != 0);
gc->italic = ((font->flags & BLF_ITALIC) != 0);
gc->char_weight = font->char_weight;
@@ -122,7 +121,7 @@ GlyphCacheBLF *blf_glyph_cache_acquire(FontBLF *font)
{
BLI_mutex_lock(&font->glyph_cache_mutex);
- GlyphCacheBLF *gc = blf_glyph_cache_find(font, font->size, font->dpi);
+ GlyphCacheBLF *gc = blf_glyph_cache_find(font, font->size);
if (!gc) {
gc = blf_glyph_cache_new(font);
@@ -967,7 +966,7 @@ static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font,
int fixed_width)
{
if (glyph_font != settings_font) {
- blf_font_size(glyph_font, settings_font->size, settings_font->dpi);
+ blf_font_size(glyph_font, settings_font->size);
}
blf_ensure_size(glyph_font);
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 39d3af22562..e1001cfc1ba 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -25,6 +25,13 @@ struct rcti;
/* Maximum number of bytes to use for cached data nodes. 0 is default of 200,000. */
#define BLF_CACHE_BYTES 400000
+/* We assume square pixels at a fixed DPI of 72, scaling only the size. Therefore
+ * font size = points = pixels, i.e. a size of 20 will result in a 20-pixel EM square.
+ * Although we could use the actual monitor DPI instead, we would then have to scale
+ * the size to cancel that out. Other libraries like Skia use this same fixed value.
+ */
+#define BLF_DPI 72
+
extern struct FontBLF *global_font[BLF_MAX_FONT];
void blf_batch_draw_begin(struct FontBLF *font);
@@ -70,7 +77,7 @@ void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, si
/**
* Change font's output size. Returns true if successful in changing the size.
*/
-bool blf_font_size(struct FontBLF *font, float size, unsigned int dpi);
+bool blf_font_size(struct FontBLF *font, float size);
void blf_font_draw(struct FontBLF *font,
const char *str,
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index d64bd9c5452..cc4be9f7f0e 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -142,9 +142,6 @@ typedef struct GlyphCacheBLF {
/** Font size. */
float size;
- /** DPI. */
- unsigned int dpi;
-
float char_weight;
float char_slant;
float char_width;
@@ -300,9 +297,6 @@ typedef struct FontBLF {
/** The width to wrap the text, see #BLF_WORD_WRAP. */
int wrap_width;
- /** Font DPI (default 72). */
- unsigned int dpi;
-
/** Font size. */
float size;
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index 1670674ebba..cba4bb96f73 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -40,7 +40,6 @@ void BLF_thumb_preview(const char *filepath,
const int h,
const int channels)
{
- const uint dpi = 72;
const int font_size_min = 6;
int font_size_curr;
/* shrink 1/th each line */
@@ -84,7 +83,7 @@ void BLF_thumb_preview(const char *filepath,
int draw_str_i18_count = 0;
CLAMP_MIN(font_size_curr, font_size_min);
- if (!blf_font_size(font, (float)font_size_curr, dpi)) {
+ if (!blf_font_size(font, (float)font_size_curr)) {
break;
}
diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index 2edc51f6329..3cc0727a94a 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -1999,7 +1999,7 @@ void BKE_image_stamp_buf(Scene *scene,
}
/* set before return */
- BLF_size(mono, scene->r.stamp_font_id, 72);
+ BLF_size(mono, scene->r.stamp_font_id);
BLF_wordwrap(mono, width - (BUFF_MARGIN_X * 2));
BLF_buffer(mono, rectf, rect, width, height, channels, display);
diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c
index 5a299582890..32795baaa37 100644
--- a/source/blender/blenkernel/intern/image_gen.c
+++ b/source/blender/blenkernel/intern/image_gen.c
@@ -355,7 +355,7 @@ static void checker_board_text(
char text[3] = {'A', '1', '\0'};
const int mono = blf_mono_font_render;
- BLF_size(mono, 54.0f, 72); /* hard coded size! */
+ BLF_size(mono, 54.0f); /* hard coded size! */
/* OCIO_TODO: using NULL as display will assume using sRGB display
* this is correct since currently generated images are assumed to be in sRGB space,
diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c
index 203276e63ef..8987a6e2b20 100644
--- a/source/blender/draw/intern/draw_manager_text.c
+++ b/source/blender/draw/intern/draw_manager_text.c
@@ -125,7 +125,7 @@ static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region)
const uiStyle *style = UI_style_get();
- BLF_size(font_id, style->widget.points * U.pixelsize, U.dpi);
+ BLF_size(font_id, style->widget.points * U.dpi_fac);
BLI_memiter_iter_init(dt->cache_strings, &it);
while ((vos = BLI_memiter_iter_step(&it))) {
diff --git a/source/blender/editors/interface/interface_icons_event.c b/source/blender/editors/interface/interface_icons_event.c
index e892a989191..b5cbc92741e 100644
--- a/source/blender/editors/interface/interface_icons_event.c
+++ b/source/blender/editors/interface/interface_icons_event.c
@@ -66,7 +66,7 @@ static void icon_draw_rect_input_text(
BLF_batch_draw_flush();
const int font_id = BLF_default();
BLF_color4fv(font_id, color);
- BLF_size(font_id, font_size * U.pixelsize, U.dpi);
+ BLF_size(font_id, font_size * U.dpi_fac);
float width, height;
BLF_width_and_height(font_id, str, BLF_DRAW_STR_DUMMY_MAX, &width, &height);
const float x = trunc(rect->xmin + (((rect->xmax - rect->xmin) - width) / 2.0f));
diff --git a/source/blender/editors/interface/interface_panel.cc b/source/blender/editors/interface/interface_panel.cc
index 745a2201dc1..90572c45e8b 100644
--- a/source/blender/editors/interface/interface_panel.cc
+++ b/source/blender/editors/interface/interface_panel.cc
@@ -1343,7 +1343,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
BLF_enable(fontid, BLF_ROTATION);
BLF_rotation(fontid, M_PI_2);
ui_fontscale(&fstyle_points, aspect);
- BLF_size(fontid, fstyle_points * U.pixelsize, U.dpi);
+ BLF_size(fontid, fstyle_points * U.dpi_fac);
/* Check the region type supports categories to avoid an assert
* for showing 3D view panels in the properties space. */
diff --git a/source/blender/editors/interface/interface_region_tooltip.cc b/source/blender/editors/interface/interface_region_tooltip.cc
index a6e37d3f36f..2c4d13e0717 100644
--- a/source/blender/editors/interface/interface_region_tooltip.cc
+++ b/source/blender/editors/interface/interface_region_tooltip.cc
@@ -254,7 +254,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region
UI_fontstyle_set(&fstyle_mono);
/* XXX: needed because we don't have mono in 'U.uifonts'. */
- BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi);
+ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.dpi_fac);
rgb_float_to_uchar(drawcol, tip_colors[static_cast<int>(field->format.color_id)]);
UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params);
}
@@ -1133,7 +1133,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
int font_id;
if (field->format.style == uiTooltipFormat::Style::Mono) {
- BLF_size(blf_mono_font, data->fstyle.points * U.pixelsize, U.dpi);
+ BLF_size(blf_mono_font, data->fstyle.points * U.dpi_fac);
font_id = blf_mono_font;
}
else {
diff --git a/source/blender/editors/interface/interface_style.cc b/source/blender/editors/interface/interface_style.cc
index 904765f6dc4..3895a687033 100644
--- a/source/blender/editors/interface/interface_style.cc
+++ b/source/blender/editors/interface/interface_style.cc
@@ -496,5 +496,5 @@ void UI_fontstyle_set(const uiFontStyle *fs)
{
uiFont *font = uifont_to_blfont(fs->uifont_id);
- BLF_size(font->blf_id, fs->points * U.pixelsize, U.dpi);
+ BLF_size(font->blf_id, fs->points * U.dpi_fac);
}
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index 0a6feeb3665..c78279b7971 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -260,7 +260,7 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
int otype = RNA_enum_get(op->ptr, "offset_type");
opdata->value_mode = (otype == BEVEL_AMT_PERCENT) ? OFFSET_VALUE_PERCENT : OFFSET_VALUE;
opdata->segments = (float)RNA_int_get(op->ptr, "segments");
- float pixels_per_inch = U.dpi * U.pixelsize;
+ float pixels_per_inch = U.dpi;
for (int i = 0; i < NUM_VALUE_KINDS; i++) {
opdata->shift_value[i] = -1.0f;
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index 156698be567..d364aa2274f 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -495,7 +495,7 @@ static void knifetool_draw_visible_distances(const KnifeTool_OpData *kcd)
float numstr_size[2];
float posit[2];
const float bg_margin = 4.0f * U.dpi_fac;
- const float font_size = 14.0f * U.pixelsize;
+ const float font_size = 14.0f;
const int distance_precision = 4;
/* Calculate distance and convert to string. */
@@ -516,7 +516,7 @@ static void knifetool_draw_visible_distances(const KnifeTool_OpData *kcd)
}
BLF_enable(blf_mono_font, BLF_ROTATION);
- BLF_size(blf_mono_font, font_size, U.dpi);
+ BLF_size(blf_mono_font, font_size * U.dpi_fac);
BLF_rotation(blf_mono_font, 0.0f);
BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
@@ -565,7 +565,7 @@ static void knifetool_draw_angle(const KnifeTool_OpData *kcd,
const float arc_size = 64.0f * U.dpi_fac;
const float bg_margin = 4.0f * U.dpi_fac;
const float cap_size = 4.0f * U.dpi_fac;
- const float font_size = 14.0f * U.pixelsize;
+ const float font_size = 14.0f;
const int angle_precision = 3;
/* Angle arc in 3d space. */
@@ -646,7 +646,7 @@ static void knifetool_draw_angle(const KnifeTool_OpData *kcd,
}
BLF_enable(blf_mono_font, BLF_ROTATION);
- BLF_size(blf_mono_font, font_size, U.dpi);
+ BLF_size(blf_mono_font, font_size * U.dpi_fac);
BLF_rotation(blf_mono_font, 0.0f);
BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc
index adc07d0b411..4fe4b087042 100644
--- a/source/blender/editors/object/object_remesh.cc
+++ b/source/blender/editors/object/object_remesh.cc
@@ -357,7 +357,7 @@ static void voxel_size_edit_draw(const bContext *C, ARegion *UNUSED(ar), void *a
GPU_matrix_push();
GPU_matrix_mul(cd->text_mat);
- BLF_size(fontid, 10.0f * fstyle_points, U.dpi);
+ BLF_size(fontid, 10.0f * fstyle_points * U.dpi_fac);
BLF_color3f(fontid, 1.0f, 1.0f, 1.0f);
BLF_width_and_height(fontid, str, strdrawlen, &strwidth, &strheight);
BLF_position(fontid, -0.5f * strwidth, -0.5f * strheight, 0.0f);
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 25e16bee558..39e3c7a2f0a 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -3794,7 +3794,7 @@ void ED_region_cache_draw_curfra_label(const int framenr, const float x, const f
float font_dims[2] = {0.0f, 0.0f};
/* frame number */
- BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
+ BLF_size(fontid, 11.0f * U.dpi_fac);
BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
diff --git a/source/blender/editors/space_clip/clip_dopesheet_draw.c b/source/blender/editors/space_clip/clip_dopesheet_draw.c
index 8f876f6a8a3..b7ca6334e35 100644
--- a/source/blender/editors/space_clip/clip_dopesheet_draw.c
+++ b/source/blender/editors/space_clip/clip_dopesheet_draw.c
@@ -343,7 +343,7 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *region)
/* second pass: text */
y = (float)CHANNEL_FIRST;
- BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
+ BLF_size(fontid, 11.0f * U.dpi_fac);
for (channel = dopesheet->channels.first; channel; channel = channel->next) {
float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index b9bd97260ef..ea286fd2c2d 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -1034,7 +1034,7 @@ static void draw_marker_texts(SpaceClip *sc,
return;
}
- BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
+ BLF_size(fontid, 11.0f * U.dpi_fac);
fontsize = BLF_height_max(fontid);
if (marker->flag & MARKER_DISABLED) {
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 8a934396229..09bb895cffb 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -168,7 +168,7 @@ void ED_image_draw_info(Scene *scene,
GPU_blend(GPU_BLEND_NONE);
- BLF_size(blf_mono_font, 11.0f * U.pixelsize, U.dpi);
+ BLF_size(blf_mono_font, 11.0f * U.dpi_fac);
BLF_color3ub(blf_mono_font, 255, 255, 255);
SNPRINTF(str, "X:%-4d Y:%-4d |", x, y);
diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c
index 9aa2b84169e..aee72860a0a 100644
--- a/source/blender/editors/space_info/textview.c
+++ b/source/blender/editors/space_info/textview.c
@@ -25,7 +25,7 @@
static void textview_font_begin(const int font_id, const int lheight)
{
/* Font size in relation to line height. */
- BLF_size(font_id, 0.8f * lheight, 72);
+ BLF_size(font_id, 0.8f * lheight);
}
typedef struct TextViewDrawState {
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 937db9951b4..98f10bfdfe5 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -2714,7 +2714,7 @@ static void frame_node_draw_label(const bNodeTree &ntree,
BLF_enable(fontid, BLF_ASPECT);
BLF_aspect(fontid, aspect, aspect, 1.0f);
/* clamp otherwise it can suck up a LOT of memory */
- BLF_size(fontid, MIN2(24.0f, font_size) * U.pixelsize, U.dpi);
+ BLF_size(fontid, MIN2(24.0f, font_size) * U.dpi_fac);
/* title color */
int color_id = node_get_colorid(node);
diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index 435436611c5..5fce0709d10 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -327,7 +327,7 @@ static float get_column_width(const ColumnValues &values)
{
float data_width = get_default_column_width(values);
const int fontid = UI_style_get()->widget.uifont_id;
- BLF_size(fontid, UI_DEFAULT_TEXT_POINTS, U.dpi);
+ BLF_size(fontid, UI_DEFAULT_TEXT_POINTS * U.dpi_fac);
const StringRefNull name = values.name();
const float name_width = BLF_width(fontid, name.data(), name.size());
return std::max<float>(name_width / UI_UNIT_X + 1.0f, data_width);
@@ -341,7 +341,7 @@ static float get_column_width_in_pixels(const ColumnValues &values)
static int get_index_column_width(const int tot_rows)
{
const int fontid = UI_style_get()->widget.uifont_id;
- BLF_size(fontid, UI_style_get_dpi()->widget.points * U.pixelsize, U.dpi);
+ BLF_size(fontid, UI_style_get_dpi()->widget.points * U.dpi_fac);
return std::to_string(std::max(0, tot_rows - 1)).size() * BLF_width(fontid, "0", 1) +
UI_UNIT_X * 0.75;
}
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index a976bb6c34b..3cff9a25bba 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -57,7 +57,7 @@ static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
static void text_font_begin(const TextDrawContext *tdc)
{
- BLF_size(tdc->font_id, (float)tdc->lheight_px, 72);
+ BLF_size(tdc->font_id, (float)tdc->lheight_px);
}
static void text_font_end(const TextDrawContext *UNUSED(tdc))
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
index 73ac3f3a1d8..70afb0eaff1 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
@@ -118,7 +118,7 @@ static void gizmo_axis_draw(const bContext *C, wmGizmo *gz)
font.id = BLF_default();
BLF_disable(font.id, BLF_ROTATION | BLF_SHADOW | BLF_MATRIX | BLF_ASPECT | BLF_WORD_WRAP);
BLF_enable(font.id, BLF_BOLD);
- BLF_size(font.id, AXIS_TEXT_SIZE, 72);
+ BLF_size(font.id, AXIS_TEXT_SIZE);
BLF_position(font.id, 0, 0, 0);
/* Calculate the inverse of the (matrix_final * matrix_offset).
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index d95d49dd982..2f5ca79a660 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -647,7 +647,7 @@ static void gizmo_ruler_draw(const bContext *C, wmGizmo *gz)
GPU_line_width(1.0f);
BLF_enable(blf_mono_font, BLF_ROTATION);
- BLF_size(blf_mono_font, 14.0f * U.pixelsize, U.dpi);
+ BLF_size(blf_mono_font, 14.0f * U.dpi_fac);
BLF_rotation(blf_mono_font, 0.0f);
UI_GetThemeColor3ubv(TH_TEXT, color_text);
diff --git a/source/blender/editors/util/ed_draw.c b/source/blender/editors/util/ed_draw.c
index 7ec3d3c1ef4..0477f4dcf76 100644
--- a/source/blender/editors/util/ed_draw.c
+++ b/source/blender/editors/util/ed_draw.c
@@ -768,7 +768,7 @@ void ED_region_image_metadata_draw(
GPU_matrix_translate_2f(x, y);
GPU_matrix_scale_2f(zoomx, zoomy);
- BLF_size(blf_mono_font, style->widgetlabel.points * 1.5f * U.pixelsize, U.dpi);
+ BLF_size(blf_mono_font, style->widgetlabel.points * U.dpi_fac);
/* *** upper box*** */
diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c
index 11b71256327..979a581463e 100644
--- a/source/blender/python/generic/blf_py_api.c
+++ b/source/blender/python/generic/blf_py_api.c
@@ -48,27 +48,32 @@ static PyObject *py_blf_position(PyObject *UNUSED(self), PyObject *args)
}
PyDoc_STRVAR(py_blf_size_doc,
- ".. function:: size(fontid, size, dpi)\n"
+ ".. function:: size(fontid, size, dpi=72)\n"
"\n"
- " Set the size and DPI for drawing text.\n"
+ " Set the size for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg size: Point size of the font.\n"
" :type size: float\n"
- " :arg dpi: dots per inch value to use for drawing.\n"
+ " :arg dpi: DEPRECATED: Defaults to 72 when omitted.\n"
" :type dpi: int\n");
static PyObject *py_blf_size(PyObject *UNUSED(self), PyObject *args)
{
- int fontid, dpi;
+ int fontid, dpi = -1;
float size;
- if (!PyArg_ParseTuple(args, "ifi:blf.size", &fontid, &size, &dpi)) {
+ if (!PyArg_ParseTuple(args, "if|i:blf.size", &fontid, &size, &dpi)) {
return NULL;
}
- BLF_size(fontid, size, dpi);
+ if (dpi != -1) {
+ size *= (float)dpi / 72.0f;
+ PyErr_WarnEx(PyExc_DeprecationWarning, "'dpi' is deprecated and assumed to be always 72.", 1);
+ }
+
+ BLF_size(fontid, size);
Py_RETURN_NONE;
}
diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c
index 25a6acb8975..cab77d93be7 100644
--- a/source/blender/sequencer/intern/effects.c
+++ b/source/blender/sequencer/intern/effects.c
@@ -3348,7 +3348,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context,
}
/* set before return */
- BLF_size(font, proxy_size_comp * data->text_size, 72);
+ BLF_size(font, proxy_size_comp * data->text_size);
const int font_flags = BLF_WORD_WRAP | /* Always allow wrapping. */
((data->flag & SEQ_TEXT_BOLD) ? BLF_BOLD : 0) |
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 259730513be..09e64db6416 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2521,7 +2521,7 @@ static void radial_control_paint_cursor(bContext *UNUSED(C), int x, int y, void
immUnbindProgram();
- BLF_size(fontid, 1.75f * fstyle_points * U.pixelsize, U.dpi);
+ BLF_size(fontid, 1.75f * fstyle_points * U.dpi_fac);
UI_GetThemeColor4fv(TH_TEXT_HI, text_color);
BLF_color4fv(fontid, text_color);
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index e768d18960b..73c7c0a2435 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -1556,7 +1556,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
BLF_init();
BLF_load_font_stack();
ps.fontid = BLF_load_mono_default(false);
- BLF_size(ps.fontid, 11.0f, 72);
+ BLF_size(ps.fontid, 11.0f);
ps.ibufx = ibuf->x;
ps.ibufy = ibuf->y;
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 8d091a02eb5..436087e1cf3 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -503,27 +503,22 @@ void WM_window_set_dpi(const wmWindow *win)
* while Windows and Linux use DPI 96. GHOST assumes a default 96 so we
* remap the DPI to Blender's convention. */
auto_dpi *= GHOST_GetNativePixelSize(win->ghostwin);
- int dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f);
+ U.dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f);
/* Automatically set larger pixel size for high DPI. */
- int pixelsize = max_ii(1, (int)(dpi / 64));
+ int pixelsize = max_ii(1, (int)(U.dpi / 64));
/* User adjustment for pixel size. */
pixelsize = max_ii(1, pixelsize + U.ui_line_width);
/* Set user preferences globals for drawing, and for forward compatibility. */
U.pixelsize = pixelsize;
- U.dpi = dpi / pixelsize;
U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE;
- U.dpi_fac = ((U.pixelsize * (float)U.dpi) / 72.0f);
+ U.dpi_fac = U.dpi / 72.0f;
U.inv_dpi_fac = 1.0f / U.dpi_fac;
- /* Set user preferences globals for drawing, and for forward compatibility. */
- U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72;
- /* If line thickness differs from scaling factor then adjustments need to be made */
- U.widget_unit += 2 * ((int)U.pixelsize - (int)U.dpi_fac);
-
- /* update font drawing */
- BLF_default_dpi(U.pixelsize * U.dpi);
+ /* Widget unit is 20 pixels at 1X scale. This consists of 18 user-scaled units plus
+ * left and right borders of line-width (pixelsize). */
+ U.widget_unit = (int)roundf(18.0f * U.dpi_fac) + (2 * pixelsize);
}
static void wm_window_update_eventstate(wmWindow *win)