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
This commit is contained in:
Harley Acheson 2022-09-23 17:36:49 -07:00
parent 88a602bc64
commit cd1631b17d
Notes: blender-bot 2023-02-14 09:48:25 +01:00
Referenced by commit 72933ebe96, BLF: Correctly Set Default Font Size
Referenced by issue #92770, Interface resolution get bigger if set the resolution scale to 0.99 and not change if set to 1.01
34 changed files with 71 additions and 84 deletions

View File

@ -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);
/**

View File

@ -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,

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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,

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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,

View File

@ -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))) {

View File

@ -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));

View File

@ -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. */

View File

@ -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 {

View File

@ -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);
}

View File

@ -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;

View File

@ -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]);

View File

@ -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);

View File

@ -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]);

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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 {

View File

@ -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);

View File

@ -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;
}

View File

@ -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))

View File

@ -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).

View File

@ -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);

View File

@ -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*** */

View File

@ -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;
}

View File

@ -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) |

View File

@ -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);

View File

@ -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;

View File

@ -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)