Пример #1
0
/**
 * When loading a new userdef from file,
 * or when exiting Blender.
 */
void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts)
{
#define U _invalid_access_ /* ensure no accidental global access */
#ifdef U                   /* quiet warning */
#endif

  userdef_free_keymaps(userdef);
  userdef_free_keyconfig_prefs(userdef);
  userdef_free_user_menus(userdef);
  userdef_free_addons(userdef);

  if (clear_fonts) {
    for (uiFont *font = userdef->uifonts.first; font; font = font->next) {
      BLF_unload_id(font->blf_id);
    }
    BLF_default_set(-1);
  }

  BLI_freelistN(&userdef->autoexec_paths);

  BLI_freelistN(&userdef->uistyles);
  BLI_freelistN(&userdef->uifonts);
  BLI_freelistN(&userdef->themes);

#undef U
}
Пример #2
0
void BKE_userdef_free(void)
{
	wmKeyMap *km;
	wmKeyMapItem *kmi;
	wmKeyMapDiffItem *kmdi;
	bAddon *addon, *addon_next;
	uiFont *font;

	for (km = U.user_keymaps.first; km; km = km->next) {
		for (kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) {
			if (kmdi->add_item) {
				keymap_item_free(kmdi->add_item);
				MEM_freeN(kmdi->add_item);
			}
			if (kmdi->remove_item) {
				keymap_item_free(kmdi->remove_item);
				MEM_freeN(kmdi->remove_item);
			}
		}

		for (kmi = km->items.first; kmi; kmi = kmi->next)
			keymap_item_free(kmi);

		BLI_freelistN(&km->diff_items);
		BLI_freelistN(&km->items);
	}
	
	for (addon = U.addons.first; addon; addon = addon_next) {
		addon_next = addon->next;
		if (addon->prop) {
			IDP_FreeProperty(addon->prop);
			MEM_freeN(addon->prop);
		}
		MEM_freeN(addon);
	}

	for (font = U.uifonts.first; font; font = font->next) {
		BLF_unload_id(font->blf_id);
	}

	BLF_default_set(-1);

	BLI_freelistN(&U.autoexec_paths);

	BLI_freelistN(&U.uistyles);
	BLI_freelistN(&U.uifonts);
	BLI_freelistN(&U.themes);
	BLI_freelistN(&U.user_keymaps);
}
/* 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);
}
Пример #4
0
/* 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);
}