Gimp/app/text/gimp-fonts.c
Michael Natterer 28d6f0a241 app/core/gimpedit.[ch] app/core/gimpmodules.[ch] app/core/gimpunits.[ch]
2003-09-15  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpedit.[ch]
	* app/core/gimpmodules.[ch]
	* app/core/gimpunits.[ch]
	* app/text/gimpfonts.[ch]: removed...

	* app/core/gimp-edit.[ch]
	* app/core/gimp-modules.[ch]
	* app/core/gimp-units.[ch]
	* app/text/gimp-fonts.[ch]: ...and added with new names because
	these files operate on members of a Gimp instance and are
	therefore methods of the Gimp object.

	* app/core/Makefile.am
	* app/text/Makefile.am
	* app/display/gimpdisplayshell-dnd.c
	* app/gui/edit-commands.c
	* app/gui/module-browser.c
	* app/gui/preferences-dialog.c
	* app/widgets/gimpbufferview.c
	* app/widgets/gimpdocumentview.c
	* app/widgets/gimptoolbox-dnd.c
	* app/app_procs.c
	* tools/pdbgen/pdb/edit.pdb
	* tools/pdbgen/pdb/fonts.pdb: changed accordingly.

	* app/pdb/edit_cmds.c
	* app/pdb/fonts_cmds.c: regenerated.

	* app/core/gimp.c (gimp_init): don't create gimp->fonts.
	(gimp_initialize): call gimp_fonts_init().
	(gimp_restore): call gimp_fonts_load() instead of _init().

	* app/text/gimp-fonts.c (gimp_fonts_init): don't call
	gimp_fonts_load(), just create gimp->fonts and connect to
	"notify::font-path" of gimp->config.
2003-09-15 17:26:28 +00:00

151 lines
3.7 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis and others
*
* text.c
* Copyright (C) 2003 Manish Singh <yosh@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include <pango/pangoft2.h>
/* PangoFT2 is assumed, so we should have this in our cflags */
#include <fontconfig/fontconfig.h>
#include "libgimpbase/gimpbase.h"
#include "text-types.h"
#include "config/gimpconfig-path.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "gimp-fonts.h"
#include "gimpfontlist.h"
#define CONF_FNAME "fonts.conf"
static gboolean gimp_fonts_load_fonts_conf (FcConfig *config,
gchar *fonts_conf);
static void gimp_fonts_add_directories (FcConfig *config,
const gchar *path_str);
void
gimp_fonts_init (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->fonts = gimp_font_list_new (72.0, 72.0);
gimp_object_set_name (GIMP_OBJECT (gimp->fonts), "fonts");
g_signal_connect_swapped (gimp->config, "notify::font-path",
G_CALLBACK (gimp_fonts_load), gimp);
}
void
gimp_fonts_load (Gimp *gimp)
{
FcConfig *config;
gchar *fonts_conf;
gchar *path;
g_return_if_fail (GIMP_IS_FONT_LIST (gimp->fonts));
gimp_set_busy (gimp);
gimp_container_clear (GIMP_CONTAINER (gimp->fonts));
config = FcInitLoadConfig ();
if (! config)
return;
fonts_conf = gimp_personal_rc_file (CONF_FNAME);
if (! gimp_fonts_load_fonts_conf (config, fonts_conf))
return;
fonts_conf = g_build_filename (gimp_sysconf_directory (), CONF_FNAME, NULL);
if (! gimp_fonts_load_fonts_conf (config, fonts_conf))
return;
path = gimp_config_path_expand (gimp->config->font_path, TRUE, NULL);
gimp_fonts_add_directories (config, path);
g_free (path);
if (! FcConfigBuildFonts (config))
{
FcConfigDestroy (config);
return;
}
FcConfigSetCurrent (config);
gimp_font_list_restore (GIMP_FONT_LIST (gimp->fonts));
gimp_unset_busy (gimp);
}
void
gimp_fonts_reset (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* We clear the default config here, so any subsequent fontconfig use will
* reinit the library with defaults. (Maybe we should call FcFini here too?)
*/
FcConfigSetCurrent (NULL);
}
static gboolean
gimp_fonts_load_fonts_conf (FcConfig *config,
gchar *fonts_conf)
{
gboolean ret = TRUE;
if (! FcConfigParseAndLoad (config, fonts_conf, FcFalse))
{
FcConfigDestroy (config);
ret = FALSE;
}
g_free (fonts_conf);
return ret;
}
static void
gimp_fonts_add_directories (FcConfig *config,
const gchar *path_str)
{
GList *path;
GList *list;
g_return_if_fail (config != NULL);
g_return_if_fail (path_str != NULL);
path = gimp_path_parse (path_str, 256, TRUE, NULL);
for (list = path; list; list = list->next)
FcConfigAppFontAddDir (config, (gchar *) list->data);
gimp_path_free (path);
}