Cleanup: BLF FontFlags enum type safety, move enums to separate header
- BLF font flags were an untyped enum; change to actual enum and update usages from int to that. - Move all BLF API enums to their own header, so that if something needs just the enums they don't have to include whole BLF_api.hh Pull Request: https://projects.blender.org/blender/blender/pulls/143692
This commit is contained in:
committed by
Aras Pranckevicius
parent
c67040771e
commit
77eec34973
@@ -8,6 +8,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLF_enums.hh"
|
||||
|
||||
#include "BLI_array.hh"
|
||||
#include "BLI_bounds_types.hh"
|
||||
#include "BLI_compiler_attrs.h"
|
||||
@@ -34,20 +36,6 @@ class Display;
|
||||
} // namespace blender::ocio
|
||||
using ColorManagedDisplay = blender::ocio::Display;
|
||||
|
||||
enum class FontShadowType {
|
||||
None = 0,
|
||||
Blur3x3 = 3,
|
||||
Blur5x5 = 5,
|
||||
Outline = 6,
|
||||
};
|
||||
|
||||
enum class BLFWrapMode : int {
|
||||
Minimal = 0, /* Only on ASCII space and line feed. Legacy and invariant. */
|
||||
Typographical = 1 << 0, /* Multilingual, informed by Unicode Standard Annex #14. */
|
||||
Path = 1 << 1, /* Wrap on file path separators, space, underscores. */
|
||||
HardLimit = 1 << 2, /* Line break at limit. */
|
||||
};
|
||||
|
||||
int BLF_init();
|
||||
void BLF_exit();
|
||||
|
||||
@@ -332,8 +320,8 @@ blender::Vector<blender::StringRef> BLF_string_wrap(int fontid,
|
||||
const int max_pixel_width,
|
||||
BLFWrapMode mode = BLFWrapMode::Minimal);
|
||||
|
||||
void BLF_enable(int fontid, int option);
|
||||
void BLF_disable(int fontid, int option);
|
||||
void BLF_enable(int fontid, FontFlags flag);
|
||||
void BLF_disable(int fontid, FontFlags flag);
|
||||
|
||||
/**
|
||||
* Is this font part of the default fonts in the fallback stack?
|
||||
@@ -433,43 +421,6 @@ void BLF_load_font_stack();
|
||||
void BLF_state_print(int fontid);
|
||||
#endif
|
||||
|
||||
/** #FontBLF.flags. */
|
||||
enum {
|
||||
BLF_ROTATION = 1 << 0,
|
||||
BLF_CLIPPING = 1 << 1,
|
||||
BLF_SHADOW = 1 << 2,
|
||||
// BLF_FLAG_UNUSED_3 = 1 << 3, /* dirty */
|
||||
// BLF_MATRIX = 1 << 4,
|
||||
BLF_ASPECT = 1 << 5,
|
||||
BLF_WORD_WRAP = 1 << 6,
|
||||
/** No anti-aliasing. */
|
||||
BLF_MONOCHROME = 1 << 7,
|
||||
BLF_HINTING_NONE = 1 << 8,
|
||||
BLF_HINTING_SLIGHT = 1 << 9,
|
||||
BLF_HINTING_FULL = 1 << 10,
|
||||
BLF_BOLD = 1 << 11,
|
||||
BLF_ITALIC = 1 << 12,
|
||||
/** Intended USE is monospaced, regardless of font type. */
|
||||
BLF_MONOSPACED = 1 << 13,
|
||||
/** A font within the default stack of fonts. */
|
||||
BLF_DEFAULT = 1 << 14,
|
||||
/** Must only be used as last font in the stack. */
|
||||
BLF_LAST_RESORT = 1 << 15,
|
||||
/** Failure to load this font. Don't try again. */
|
||||
BLF_BAD_FONT = 1 << 16,
|
||||
/** This font is managed by the FreeType cache subsystem. */
|
||||
BLF_CACHED = 1 << 17,
|
||||
/**
|
||||
* At small sizes glyphs are rendered at multiple sub-pixel positions.
|
||||
*
|
||||
* \note Can be checked without checking #BLF_MONOSPACED which can be assumed to be disabled.
|
||||
*/
|
||||
BLF_RENDER_SUBPIXELAA = 1 << 18,
|
||||
|
||||
/* Do not look in other fonts when a glyph is not found in this font. */
|
||||
BLF_NO_FALLBACK = 1 << 19,
|
||||
};
|
||||
|
||||
#define BLF_DRAW_STR_DUMMY_MAX 1024
|
||||
|
||||
/* XXX, bad design */
|
||||
|
||||
63
source/blender/blenfont/BLF_enums.hh
Normal file
63
source/blender/blenfont/BLF_enums.hh
Normal file
@@ -0,0 +1,63 @@
|
||||
/* SPDX-FileCopyrightText: 2025 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup blf
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
enum class FontShadowType {
|
||||
None = 0,
|
||||
Blur3x3 = 3,
|
||||
Blur5x5 = 5,
|
||||
Outline = 6,
|
||||
};
|
||||
|
||||
enum class BLFWrapMode : int {
|
||||
Minimal = 0, /* Only on ASCII space and line feed. Legacy and invariant. */
|
||||
Typographical = 1 << 0, /* Multilingual, informed by Unicode Standard Annex #14. */
|
||||
Path = 1 << 1, /* Wrap on file path separators, space, underscores. */
|
||||
HardLimit = 1 << 2, /* Line break at limit. */
|
||||
};
|
||||
|
||||
enum FontFlags {
|
||||
BLF_NONE = 0,
|
||||
BLF_ROTATION = 1 << 0,
|
||||
BLF_CLIPPING = 1 << 1,
|
||||
BLF_SHADOW = 1 << 2,
|
||||
// BLF_FLAG_UNUSED_3 = 1 << 3, /* dirty */
|
||||
// BLF_MATRIX = 1 << 4,
|
||||
BLF_ASPECT = 1 << 5,
|
||||
BLF_WORD_WRAP = 1 << 6,
|
||||
/** No anti-aliasing. */
|
||||
BLF_MONOCHROME = 1 << 7,
|
||||
BLF_HINTING_NONE = 1 << 8,
|
||||
BLF_HINTING_SLIGHT = 1 << 9,
|
||||
BLF_HINTING_FULL = 1 << 10,
|
||||
BLF_BOLD = 1 << 11,
|
||||
BLF_ITALIC = 1 << 12,
|
||||
/** Intended USE is monospaced, regardless of font type. */
|
||||
BLF_MONOSPACED = 1 << 13,
|
||||
/** A font within the default stack of fonts. */
|
||||
BLF_DEFAULT = 1 << 14,
|
||||
/** Must only be used as last font in the stack. */
|
||||
BLF_LAST_RESORT = 1 << 15,
|
||||
/** Failure to load this font. Don't try again. */
|
||||
BLF_BAD_FONT = 1 << 16,
|
||||
/** This font is managed by the FreeType cache subsystem. */
|
||||
BLF_CACHED = 1 << 17,
|
||||
/**
|
||||
* At small sizes glyphs are rendered at multiple sub-pixel positions.
|
||||
*
|
||||
* \note Can be checked without checking #BLF_MONOSPACED which can be assumed to be disabled.
|
||||
*/
|
||||
BLF_RENDER_SUBPIXELAA = 1 << 18,
|
||||
|
||||
/* Do not look in other fonts when a glyph is not found in this font. */
|
||||
BLF_NO_FALLBACK = 1 << 19,
|
||||
};
|
||||
ENUM_OPERATORS(FontFlags, BLF_NO_FALLBACK);
|
||||
@@ -20,6 +20,7 @@ set(SRC
|
||||
intern/blf_glyph.cc
|
||||
intern/blf_thumbs.cc
|
||||
BLF_api.hh
|
||||
BLF_enums.hh
|
||||
intern/blf_internal.hh
|
||||
intern/blf_internal_types.hh
|
||||
)
|
||||
|
||||
@@ -317,21 +317,21 @@ void BLF_addref_id(int fontid)
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_enable(int fontid, int option)
|
||||
void BLF_enable(int fontid, FontFlags flag)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->flags |= option;
|
||||
font->flags |= flag;
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_disable(int fontid, int option)
|
||||
void BLF_disable(int fontid, FontFlags flag)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->flags &= ~option;
|
||||
font->flags &= ~flag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1665,7 +1665,7 @@ static void blf_font_fill(FontBLF *font)
|
||||
font->clip_rec.xmax = 0;
|
||||
font->clip_rec.ymin = 0;
|
||||
font->clip_rec.ymax = 0;
|
||||
font->flags = 0;
|
||||
font->flags = BLF_NONE;
|
||||
font->size = 0;
|
||||
font->char_weight = 400;
|
||||
font->char_slant = 0.0f;
|
||||
|
||||
@@ -371,7 +371,7 @@ struct FontBLF {
|
||||
int tex_size_max;
|
||||
|
||||
/** Font options. */
|
||||
int flags;
|
||||
FontFlags flags;
|
||||
|
||||
/**
|
||||
* List of glyph caches (#GlyphCacheBLF) for this font for size, DPI, bold, italic.
|
||||
|
||||
@@ -133,7 +133,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs,
|
||||
ResultBLF *r_info)
|
||||
{
|
||||
int xofs = 0, yofs;
|
||||
int font_flag = BLF_CLIPPING;
|
||||
FontFlags font_flag = BLF_CLIPPING;
|
||||
|
||||
UI_fontstyle_set(fs);
|
||||
|
||||
@@ -213,7 +213,7 @@ void UI_fontstyle_draw_multiline_clipped_ex(const uiFontStyle *fs,
|
||||
ResultBLF *r_info)
|
||||
{
|
||||
int xofs = 0, yofs;
|
||||
int font_flag = BLF_CLIPPING;
|
||||
FontFlags font_flag = BLF_CLIPPING;
|
||||
|
||||
/* Recommended for testing: Results should be the same with or without BLF clipping since the
|
||||
* string is wrapped and shortened to fit. Disabling it can help spot issues. */
|
||||
@@ -540,9 +540,9 @@ void uiStyleInit()
|
||||
|
||||
/* Set default flags based on UI preferences (not render fonts) */
|
||||
{
|
||||
const int flag_disable = (BLF_MONOCHROME | BLF_HINTING_NONE | BLF_HINTING_SLIGHT |
|
||||
BLF_HINTING_FULL | BLF_RENDER_SUBPIXELAA);
|
||||
int flag_enable = 0;
|
||||
const FontFlags flag_disable = (BLF_MONOCHROME | BLF_HINTING_NONE | BLF_HINTING_SLIGHT |
|
||||
BLF_HINTING_FULL | BLF_RENDER_SUBPIXELAA);
|
||||
FontFlags flag_enable = BLF_NONE;
|
||||
|
||||
if (U.text_render & USER_TEXT_HINTING_NONE) {
|
||||
flag_enable |= BLF_HINTING_NONE;
|
||||
|
||||
@@ -1373,7 +1373,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
rcti rect_i;
|
||||
int font_flag = 0;
|
||||
FontFlags font_flag = BLF_NONE;
|
||||
|
||||
/* Create area region. */
|
||||
ARegion *region = ui_region_temp_add(CTX_wm_screen(C));
|
||||
|
||||
@@ -324,7 +324,7 @@ static PyObject *py_blf_disable(PyObject * /*self*/, PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BLF_disable(fontid, option);
|
||||
BLF_disable(fontid, FontFlags(option));
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@@ -349,7 +349,7 @@ static PyObject *py_blf_enable(PyObject * /*self*/, PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BLF_enable(fontid, option);
|
||||
BLF_enable(fontid, FontFlags(option));
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* \ingroup sequencer
|
||||
*/
|
||||
|
||||
#include "BLF_enums.hh"
|
||||
|
||||
#include "BLI_array.hh"
|
||||
#include "BLI_math_color.h"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
@@ -146,6 +148,6 @@ static void apply_effect_op(const OpT &op, const ImBuf *src1, const ImBuf *src2,
|
||||
}
|
||||
|
||||
TextVarsRuntime *text_effect_calc_runtime(const Strip *strip, int font, const int2 image_size);
|
||||
int text_effect_font_init(const RenderData *context, const Strip *strip, int font_flags);
|
||||
int text_effect_font_init(const RenderData *context, const Strip *strip, FontFlags font_flags);
|
||||
|
||||
} // namespace blender::seq
|
||||
|
||||
@@ -786,7 +786,7 @@ static int text_effect_line_size_get(const RenderData *context, const Strip *str
|
||||
return size_scale * data->text_size;
|
||||
}
|
||||
|
||||
int text_effect_font_init(const RenderData *context, const Strip *strip, int font_flags)
|
||||
int text_effect_font_init(const RenderData *context, const Strip *strip, FontFlags font_flags)
|
||||
{
|
||||
TextVars *data = static_cast<TextVars *>(strip->effectdata);
|
||||
int font = blf_mono_font_render;
|
||||
@@ -1029,8 +1029,8 @@ static ImBuf *do_text_effect(const RenderData *context,
|
||||
|
||||
const char *display_device = context->scene->display_settings.display_device;
|
||||
const ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
|
||||
const int font_flags = ((data->flag & SEQ_TEXT_BOLD) ? BLF_BOLD : 0) |
|
||||
((data->flag & SEQ_TEXT_ITALIC) ? BLF_ITALIC : 0);
|
||||
const FontFlags font_flags = ((data->flag & SEQ_TEXT_BOLD) ? BLF_BOLD : BLF_NONE) |
|
||||
((data->flag & SEQ_TEXT_ITALIC) ? BLF_ITALIC : BLF_NONE);
|
||||
|
||||
/* Guard against parallel accesses to the fonts map. */
|
||||
std::lock_guard lock(g_font_map.mutex);
|
||||
|
||||
@@ -609,8 +609,8 @@ float2 transform_image_raw_size_get(const Scene *scene, const Strip *strip)
|
||||
|
||||
if (strip->type == STRIP_TYPE_TEXT) {
|
||||
const TextVars *data = static_cast<TextVars *>(strip->effectdata);
|
||||
const int font_flags = ((data->flag & SEQ_TEXT_BOLD) ? BLF_BOLD : 0) |
|
||||
((data->flag & SEQ_TEXT_ITALIC) ? BLF_ITALIC : 0);
|
||||
const FontFlags font_flags = ((data->flag & SEQ_TEXT_BOLD) ? BLF_BOLD : BLF_NONE) |
|
||||
((data->flag & SEQ_TEXT_ITALIC) ? BLF_ITALIC : BLF_NONE);
|
||||
const int font = text_effect_font_init(nullptr, strip, font_flags);
|
||||
|
||||
const TextVarsRuntime *runtime = text_effect_calc_runtime(
|
||||
|
||||
Reference in New Issue
Block a user