7#include "testing/testing.h"
16 blender::tests::flags_test_asset_dir().c_str(),
19 return std::string(path);
37 EXPECT_TRUE(
id != -1);
41TEST(blf_load, font_is_loaded_path)
45 const int id =
BLF_load(path.c_str());
50TEST(blf_load, font_is_loaded_id)
57TEST(blf_load, display_name_from_file)
66TEST(blf_load, display_name_from_id)
80 EXPECT_TRUE(has_glyph);
84TEST(blf_metrics, get_vfont_metrics)
87 float ascend_ratio = 0.0f;
88 float em_ratio = 0.0f;
91 EXPECT_TRUE(has_metrics);
92 EXPECT_TRUE(ascend_ratio == 0.8f);
93 EXPECT_TRUE(em_ratio == 1.0f);
94 EXPECT_TRUE(
scale == 0.001f);
98TEST(blf_metrics, default_weight)
102 EXPECT_TRUE(weight == 400);
106TEST(blf_metrics, has_variable_weight)
110 EXPECT_TRUE(has_variable_weight);
114TEST(blf_metrics, variable_weight)
117 const char sample[] =
"MM";
123 EXPECT_TRUE(width_wide > width_thin);
132 EXPECT_TRUE(width == 100.0f);
136TEST(blf_dimensions, height_max)
141 EXPECT_TRUE(height == 100.0f);
150 EXPECT_TRUE(descender == -20);
159 EXPECT_TRUE(ascender == 80);
163TEST(blf_dimensions, fixed_width)
169 EXPECT_TRUE(width == 56.0f);
176 const char sample[] =
"XX";
180 EXPECT_TRUE(width == 200.0f);
187 const char sample[] =
"X";
191 EXPECT_TRUE(width == 100.0f);
198 const char sample[] =
"X";
202 EXPECT_NEAR(width, 100.0f, 0.000001f);
206TEST(blf_wrapping_minimal, wrap_overflow_ascii)
210 "xxxxxxxxxxxxxxxxxxx!\"#$%&\'()*+,-./"
211 "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
217 id,
sample,
int(
float(width) * 0.05f));
218 EXPECT_TRUE(wrapped.
size() == 1);
222TEST(blf_wrapping_minimal, wrap_space)
225 const char sample[] =
"x xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx ";
230 id,
sample,
int(
float(width) * 0.7f));
231 EXPECT_TRUE(wrapped.
size() == 2 && wrapped[0].back() ==
' ' && wrapped[1].substr(0, 1) !=
" ");
235TEST(blf_wrapping_minimal, wrap_linefeed)
238 const char sample[] =
"x\nxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxx\n";
243 id,
sample,
int(
float(width) * 0.7f));
244 EXPECT_TRUE(wrapped.
size() == 4 && wrapped[2].
is_empty());
248TEST(blf_wrapping_minimal, wrap_hardlimit)
251 const char sample[] =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
257 EXPECT_TRUE(wrapped.
size() == 2);
261TEST(blf_wrapping_path, wrap_path_overflow_ascii)
265 "xxxxxxxxxxxxxxxxxxx!\"#$\'()*+,"
266 "0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^`abcdefghijklmnopqrstuvwxyz{|}~";
273 EXPECT_TRUE(wrapped.
size() == 1);
277TEST(blf_wrapping_path, wrap_path_space)
280 const char sample[] =
"x xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx ";
286 EXPECT_TRUE(wrapped.
size() == 2);
290TEST(blf_wrapping_path, wrap_path_separators_underscore)
296 const char sample[] =
"x_xx_xxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxx_";
300 EXPECT_TRUE(wrapped.
size() == 2);
304TEST(blf_wrapping_path, wrap_path_separators_slash)
310 const char sample[] =
"xxxxxxxxxx" SEP_STR "xxxxxxxxxxxxxxxxxxxxxx";
314 EXPECT_TRUE(wrapped.
size() == 2);
318TEST(blf_wrapping_path, wrap_path_hardlimit)
321 const char sample[] =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
328 int(
float(width) * 0.7f),
330 EXPECT_TRUE(wrapped.
size() == 2);
334TEST(blf_wrapping_typographical, wrap_typographical_thinspace)
337 const char sample[] =
"xxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
343 EXPECT_TRUE(wrapped.
size() == 2);
347TEST(blf_wrapping_typographical, wrap_typographical_backslash)
350 const char sample[] =
"xxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
356 EXPECT_TRUE(wrapped.
size() == 2);
360TEST(blf_wrapping_typographical, wrap_typographical_underscore)
363 const char sample[] =
"xxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
369 EXPECT_TRUE(wrapped.
size() == 2);
373TEST(blf_wrapping_typographical, wrap_typographical_forward_slash)
376 const char sample[] =
"xxxxxxxxxxxxxx/xx3/xxxxxxxxxxxxxxxxxxxxx";
382 EXPECT_TRUE(wrapped.
size() == 2 && wrapped[0].back() !=
'3');
386TEST(blf_wrapping_typographical, wrap_typographical_dash)
389 const char sample[] =
"xxxxxxxxxxxxxx-xx /xxxxxxxxxxxxxxxxxxxxx";
395 EXPECT_TRUE(wrapped.
size() == 2 && wrapped[0].back() !=
' ');
399TEST(blf_wrapping_typographical, wrap_typographical_CJK)
405 "xxxxxxxxxxxxxxxxxxxxx";
411 EXPECT_TRUE(wrapped.
size() == 2);
415TEST(blf_wrapping_typographical, wrap_typographical_Tibetan)
421 "xxxxxxxxxxxxxxxxxxxxx";
427 EXPECT_TRUE(wrapped.
size() == 2);
431TEST(blf_wrapping_typographical, wrap_typographical_hardlimit)
434 const char sample[] =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
441 int(
float(width) * 0.7f),
443 EXPECT_TRUE(wrapped.
size() == 2);
bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT
void BLF_size(int fontid, float size)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
blender::Vector< blender::StringRef > BLF_string_wrap(int fontid, blender::StringRef str, const int max_pixel_width, BLFWrapMode mode=BLFWrapMode::Minimal)
int BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT
float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
bool BLF_is_loaded_id(int fontid) ATTR_WARN_UNUSED_RESULT
char * BLF_display_name_from_id(int fontid)
bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale)
int BLF_default_weight(int fontid) ATTR_WARN_UNUSED_RESULT
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
int BLF_glyph_advance(int fontid, const char *str)
int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
bool BLF_unload_id(int fontid)
bool BLF_has_variable_weight(int fontid) ATTR_WARN_UNUSED_RESULT
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
char * BLF_display_name_from_file(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT
void BLF_character_weight(int fontid, int weight)
#define BLI_path_join(...)
void MEM_freeN(void *vmemh)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
static std::string font_path(std::string font_name)
static void close_font(int id)
static int open_font(std::string font_name)