sanity.c 6.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * 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"

21
#include <glib.h>
22
23
24
#include <fontconfig/fontconfig.h>
#include <pango/pangoft2.h>

25
26
#include "libgimpbase/gimpenv.h"

27
28
#include "core/gimp-utils.h"

29
30
#include "sanity.h"

31
32
#include "gimp-intl.h"

33

34
35
36
37
38
static gchar * sanity_check_glib              (void);
static gchar * sanity_check_fontconfig        (void);
static gchar * sanity_check_freetype          (void);
static gchar * sanity_check_filename_encoding (void);

39

40
/*  public functions  */
41

42
const gchar *
43
sanity_check (void)
44
{
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  gchar *abort_message = sanity_check_glib ();

  if (! abort_message)
    abort_message = sanity_check_fontconfig ();

  if (! abort_message)
    abort_message = sanity_check_freetype ();

  if (! abort_message)
    abort_message = sanity_check_filename_encoding ();

  return abort_message;
}


/*  private functions  */

static gchar *
sanity_check_glib (void)
{
  const gchar *mismatch;

#define GLIB_REQUIRED_MAJOR 2
#define GLIB_REQUIRED_MINOR 4
#define GLIB_REQUIRED_MICRO 5

  mismatch = gimp_check_glib_version (GLIB_REQUIRED_MAJOR,
                                      GLIB_REQUIRED_MINOR,
                                      GLIB_REQUIRED_MICRO);

  if (mismatch)
    {
      return g_strdup_printf
        ("%s\n\n"
         "The GIMP requires GLib+ version %d.%d.%d or later.\n"
         "Installed GLib+ version is %d.%d.%d.\n\n"
         "Somehow you or your software packager managed\n"
         "to install The GIMP with an older GLib+ version.\n\n"
         "Please upgrade to GLib+ version %d.%d.%d or later.",
         mismatch,
         GLIB_REQUIRED_MAJOR, GLIB_REQUIRED_MINOR, GLIB_REQUIRED_MICRO,
         glib_major_version, glib_minor_version, glib_micro_version,
         GLIB_REQUIRED_MAJOR, GLIB_REQUIRED_MINOR, GLIB_REQUIRED_MICRO);
    }
89

90
91
92
93
94
95
96
97
98
99
#undef GLIB_REQUIRED_MAJOR
#undef GLIB_REQUIRED_MINOR
#undef GLIB_REQUIRED_MICRO

  return NULL;
}

static gchar *
sanity_check_fontconfig (void)
{
100
101
102
103
  gint   fc_version       = FcGetVersion ();
  gint   fc_major_version = fc_version / 100 / 100;
  gint   fc_minor_version = fc_version / 100 % 100;
  gint   fc_micro_version = fc_version % 100;
104
105
106
107
108

#define FC_REQUIRED_MAJOR 2
#define FC_REQUIRED_MINOR 2
#define FC_REQUIRED_MICRO 0

109
110
111
112
  if (fc_version < ((FC_REQUIRED_MAJOR * 10000) +
                    (FC_REQUIRED_MINOR *   100) +
                    (FC_REQUIRED_MICRO *     1)))
    {
113
      return g_strdup_printf
114
115
116
117
118
119
120
121
122
        ("The Fontconfig version being used is too old!\n\n"
         "The GIMP requires Fontconfig version %d.%d.%d or later.\n"
         "The Fontconfig version loaded by The GIMP is %d.%d.%d.\n\n"
         "This may be caused by another instance of libfontconfig.so.1\n"
         "being installed in the system, probably in /usr/X11R6/lib.\n"
         "Please correct the situation or report it to someone who can.",
         FC_REQUIRED_MAJOR, FC_REQUIRED_MINOR, FC_REQUIRED_MICRO,
         fc_major_version, fc_minor_version, fc_micro_version);
    }
123
124
125
126

#undef FC_REQUIRED_MAJOR
#undef FC_REQUIRED_MINOR
#undef FC_REQUIRED_MICRO
127

128
129
  return NULL;
}
130

131
132
133
134
135
136
137
138
static gchar *
sanity_check_freetype (void)
{
  FT_Library ft_library;
  FT_Int     ft_major_version;
  FT_Int     ft_minor_version;
  FT_Int     ft_micro_version;
  FT_Int     ft_version;
139
140
141
142
143

#define FT_REQUIRED_MAJOR 2
#define FT_REQUIRED_MINOR 1
#define FT_REQUIRED_MICRO 7

144
145
146
147
148
149
150
  if (FT_Init_FreeType (&ft_library) != 0)
    g_error ("FT_Init_FreeType() failed");

  FT_Library_Version (ft_library,
                      &ft_major_version,
                      &ft_minor_version,
                      &ft_micro_version);
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  if (FT_Done_FreeType (ft_library) != 0)
    g_error ("FT_Done_FreeType() failed");

  ft_version = (ft_major_version * 10000 +
                ft_minor_version *   100 +
                ft_micro_version *     1);

  if (ft_version < ((FT_REQUIRED_MAJOR * 10000) +
                    (FT_REQUIRED_MINOR *   100) +
                    (FT_REQUIRED_MICRO *     1)))
    {
      return g_strdup_printf
        ("FreeType version too old!\n\n"
         "The GIMP requires FreeType version %d.%d.%d or later.\n"
         "Installed FreeType version is %d.%d.%d.\n\n"
         "Somehow you or your software packager managed\n"
         "to install The GIMP with an older FreeType version.\n\n"
         "Please upgrade to FreeType version %d.%d.%d or later.",
         FT_REQUIRED_MAJOR, FT_REQUIRED_MINOR, FT_REQUIRED_MICRO,
         ft_major_version, ft_minor_version, ft_micro_version,
         FT_REQUIRED_MAJOR, FT_REQUIRED_MINOR, FT_REQUIRED_MICRO);
    }
174
175
176
177
178

#undef FT_REQUIRED_MAJOR
#undef FT_REQUIRED_MINOR
#undef FT_REQUIRED_MICRO

179
  return NULL;
180
}
181
182
183
184
185
186
187

static gchar *
sanity_check_filename_encoding (void)
{
  gchar  *result;
  GError *error = NULL;

188
  result = g_filename_to_utf8 ("", -1, NULL, NULL, &error);
189

190
  if (! result)
191
    {
192
193
194
195
196
197
198
199
200
      gchar *msg =
        g_strdup_printf
        (_("The configured filename encoding cannot be converted to UTF-8: "
           "%s\n\n"
           "Please check the value of the environment variable "
           "G_FILENAME_ENCODING."),
         error->message);

      g_error_free (error);
201

202
      return msg;
203
    }
204
205
206
207
208
209

  g_free (result);

  result = g_filename_to_utf8 (gimp_directory (), -1, NULL, NULL, &error);

  if (! result)
210
211
212
    {
      gchar *msg =
        g_strdup_printf
213
214
215
216
217
218
        (_("The name of the directory holding the GIMP user configuration "
           "cannot be converted to UTF-8: "
           "%s\n\n"
           "Most probably your filesystem stores files in an encoding "
           "different from UTF-8 and you didn't tell GLib about this. "
           "Please set the environment variable G_FILENAME_ENCODING."),
219
220
221
222
223
224
         error->message);

      g_error_free (error);

      return msg;
    }
225
226
227
228

  g_free (result);

  return NULL;
229
}