/* reading without uifont will create one */ void uiStyleInit(void) { uiFont *font; uiStyle *style = U.uistyles.first; int monofont_size = datatoc_bmonofont_ttf_size; unsigned char *monofont_ttf = (unsigned char *)datatoc_bmonofont_ttf; /* recover from uninitialized dpi */ if (U.dpi == 0) U.dpi = 72; CLAMP(U.dpi, 48, 144); for (font = U.uifonts.first; font; font = font->next) { BLF_unload_id(font->blf_id); } if (blf_mono_font != -1) { BLF_unload_id(blf_mono_font); blf_mono_font = -1; } if (blf_mono_font_render != -1) { BLF_unload_id(blf_mono_font_render); blf_mono_font_render = -1; } font = U.uifonts.first; /* default builtin */ if (font == NULL) { font = MEM_callocN(sizeof(uiFont), "ui font"); BLI_addtail(&U.uifonts, font); } if (U.font_path_ui[0]) { BLI_strncpy(font->filename, U.font_path_ui, sizeof(font->filename)); font->uifont_id = UIFONT_CUSTOM1; } else { BLI_strncpy(font->filename, "default", sizeof(font->filename)); font->uifont_id = UIFONT_DEFAULT; } for (font = U.uifonts.first; font; font = font->next) { if (font->uifont_id == UIFONT_DEFAULT) { #ifdef WITH_INTERNATIONAL int font_size = datatoc_bfont_ttf_size; unsigned char *font_ttf = (unsigned char *)datatoc_bfont_ttf; static int last_font_size = 0; /* use unicode font for translation */ if (U.transopts & USER_DOTRANSLATE) { font_ttf = BLF_get_unifont(&font_size); if (!font_ttf) { /* fall back if not found */ font_size = datatoc_bfont_ttf_size; font_ttf = (unsigned char *)datatoc_bfont_ttf; } } /* relload only if needed */ if (last_font_size != font_size) { BLF_unload("default"); last_font_size = font_size; } font->blf_id = BLF_load_mem("default", font_ttf, font_size); #else font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); #endif } else { font->blf_id = BLF_load(font->filename); if (font->blf_id == -1) { font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); } } BLF_default_set(font->blf_id); if (font->blf_id == -1) { if (G.debug & G_DEBUG) printf("%s: error, no fonts available\n", __func__); } else { /* ? just for speed to initialize? * Yes, this build the glyph cache and create * the texture. */ BLF_size(font->blf_id, 11 * U.pixelsize, U.dpi); BLF_size(font->blf_id, 12 * U.pixelsize, U.dpi); BLF_size(font->blf_id, 14 * U.pixelsize, U.dpi); } } if (style == NULL) { ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT); } #ifdef WITH_INTERNATIONAL /* use unicode font for text editor and interactive console */ if (U.transopts & USER_DOTRANSLATE) { monofont_ttf = BLF_get_unifont_mono(&monofont_size); if (!monofont_ttf) { /* fall back if not found */ monofont_size = datatoc_bmonofont_ttf_size; monofont_ttf = (unsigned char *)datatoc_bmonofont_ttf; } } #endif /* XXX, this should be moved into a style, but for now best only load the monospaced font once. */ BLI_assert(blf_mono_font == -1); if (U.font_path_ui_mono[0]) { blf_mono_font = BLF_load_unique(U.font_path_ui_mono); } if (blf_mono_font == -1) { blf_mono_font = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); } BLF_size(blf_mono_font, 12 * U.pixelsize, 72); /* Set default flags based on UI preferences (not render fonts) */ { int flag_disable = BLF_MONOCHROME | BLF_HINTING_NONE | BLF_HINTING_SLIGHT | BLF_HINTING_FULL; int flag_enable = 0; if (U.text_render & USER_TEXT_HINTING_NONE) { flag_enable |= BLF_HINTING_NONE; } else if (U.text_render & USER_TEXT_HINTING_SLIGHT) { flag_enable |= BLF_HINTING_SLIGHT; } else if (U.text_render & USER_TEXT_HINTING_FULL) { flag_enable |= BLF_HINTING_FULL; } if (U.text_render & USER_TEXT_DISABLE_AA) { flag_enable |= BLF_MONOCHROME; } for (font = U.uifonts.first; font; font = font->next) { if (font->blf_id != -1) { BLF_disable(font->blf_id, flag_disable); BLF_enable(font->blf_id, flag_enable); } } if (blf_mono_font != -1) { BLF_disable(blf_mono_font, flag_disable); BLF_enable(blf_mono_font, flag_enable); } } /** * Second for rendering else we get threading problems, * * \note This isn't good that the render font depends on the preferences, * keep for now though, since without this there is no way to display many unicode chars. */ if (blf_mono_font_render == -1) blf_mono_font_render = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72); }
/* reading without uifont will create one */ void uiStyleInit(void) { uiFont *font; uiStyle *style = U.uistyles.first; int monofont_size = datatoc_bmonofont_ttf_size; unsigned char *monofont_ttf = (unsigned char *)datatoc_bmonofont_ttf; /* recover from uninitialized dpi */ if (U.dpi == 0) U.dpi = 72; CLAMP(U.dpi, 48, 144); for (font = U.uifonts.first; font; font = font->next) { BLF_unload_id(font->blf_id); } font = U.uifonts.first; /* default builtin */ if (font == NULL) { font = MEM_callocN(sizeof(uiFont), "ui font"); BLI_addtail(&U.uifonts, font); } if (U.font_path_ui[0]) { BLI_strncpy(font->filename, U.font_path_ui, sizeof(font->filename)); font->uifont_id = UIFONT_CUSTOM1; } else { BLI_strncpy(font->filename, "default", sizeof(font->filename)); font->uifont_id = UIFONT_DEFAULT; } for (font = U.uifonts.first; font; font = font->next) { if (font->uifont_id == UIFONT_DEFAULT) { #ifdef WITH_INTERNATIONAL int font_size = datatoc_bfont_ttf_size; unsigned char *font_ttf = (unsigned char *)datatoc_bfont_ttf; static int last_font_size = 0; /* use unicode font for translation */ if (U.transopts & USER_DOTRANSLATE) { font_ttf = BLF_get_unifont(&font_size); if (!font_ttf) { /* fall back if not found */ font_size = datatoc_bfont_ttf_size; font_ttf = (unsigned char *)datatoc_bfont_ttf; } } /* relload only if needed */ if (last_font_size != font_size) { BLF_unload("default"); last_font_size = font_size; } font->blf_id = BLF_load_mem("default", font_ttf, font_size); #else font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); #endif } else { font->blf_id = BLF_load(font->filename); if (font->blf_id == -1) { font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); } } BLF_default_set(font->blf_id); if (font->blf_id == -1) { if (G.debug & G_DEBUG) printf("%s: error, no fonts available\n", __func__); } else { /* ? just for speed to initialize? * Yes, this build the glyph cache and create * the texture. */ BLF_size(font->blf_id, 11 * U.pixelsize, U.dpi); BLF_size(font->blf_id, 12 * U.pixelsize, U.dpi); BLF_size(font->blf_id, 14 * U.pixelsize, U.dpi); } } if (style == NULL) { ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT); } #ifdef WITH_INTERNATIONAL /* use unicode font for text editor and interactive console */ if (U.transopts & USER_DOTRANSLATE) { monofont_ttf = BLF_get_unifont_mono(&monofont_size); if (!monofont_ttf) { /* fall back if not found */ monofont_size = datatoc_bmonofont_ttf_size; monofont_ttf = (unsigned char *)datatoc_bmonofont_ttf; } } /* reload */ BLF_unload("monospace"); blf_mono_font = -1; blf_mono_font_render = -1; #endif /* XXX, this should be moved into a style, but for now best only load the monospaced font once. */ if (blf_mono_font == -1) blf_mono_font = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); BLF_size(blf_mono_font, 12 * U.pixelsize, 72); /* second for rendering else we get threading problems */ if (blf_mono_font_render == -1) blf_mono_font_render = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72); }
/* reading without uifont will create one */ void uiStyleInit(void) { uiFont *font= U.uifonts.first; uiStyle *style= U.uistyles.first; /* recover from uninitialized dpi */ if(U.dpi == 0) U.dpi= 72; CLAMP(U.dpi, 48, 128); /* default builtin */ if(font==NULL) { font= MEM_callocN(sizeof(uiFont), "ui font"); BLI_addtail(&U.uifonts, font); strcpy(font->filename, "default"); font->uifont_id= UIFONT_DEFAULT; } for(font= U.uifonts.first; font; font= font->next) { if(font->uifont_id==UIFONT_DEFAULT) { font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); } else { font->blf_id= BLF_load(font->filename); if(font->blf_id == -1) font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); } if (font->blf_id == -1) { if (G.f & G_DEBUG) printf("uiStyleInit error, no fonts available\n"); } else { /* ? just for speed to initialize? * Yes, this build the glyph cache and create * the texture. */ BLF_size(font->blf_id, 11, U.dpi); BLF_size(font->blf_id, 12, U.dpi); BLF_size(font->blf_id, 14, U.dpi); } } if(style==NULL) { ui_style_new(&U.uistyles, "Default Style"); } // XXX, this should be moved into a style, but for now best only load the monospaced font once. if (blf_mono_font == -1) blf_mono_font= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); BLF_size(blf_mono_font, 12, 72); /* second for rendering else we get threading problems */ if (blf_mono_font_render == -1) blf_mono_font_render= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); BLF_size(blf_mono_font_render, 12, 72); }