1 /* convertfonts.c - converts fonts in a style file to fontconfig format
3 * WindowMaker window manager
5 * Copyright (c) 2004 Dan Pascu
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #define _GNU_SOURCE /* getopt_long */
34 #include <WINGs/WUtil.h>
36 #include "../src/wconfig.h"
41 char *FontOptions
[] = {
54 extern char *__progname
;
57 static void print_help(int print_usage
, int exitval
)
59 printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", __progname
);
61 puts("Converts fonts in a style file into fontconfig format");
63 puts(" -h, --help display this help and exit");
64 puts(" -v, --version output version information and exit");
65 puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
66 puts(" to the font name. This property is not used by the fontconfig");
67 puts(" matching engine to find the font, but it is useful as a hint");
68 puts(" about what the original font was to allow hand tuning the");
69 puts(" result or restoring the xlfd. The default is to not add it");
70 puts(" as it results in long, unreadable and confusing names.");
75 int main(int argc
, char **argv
)
77 WMPropList
*style
, *key
, *val
;
78 char *file
= NULL
, *oldfont
, *newfont
;
80 Bool keepXLFD
= False
;
83 struct option longopts
[] = {
84 { "version", no_argument
, NULL
, 'v' },
85 { "help", no_argument
, NULL
, 'h' },
86 { "keep-xlfd", no_argument
, &keepXLFD
, True
},
90 while ((ch
= getopt_long(argc
, argv
, "hv", longopts
, NULL
)) != -1)
93 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
114 if (stat(file
, &st
) != 0) {
119 if (!S_ISREG(st
.st_mode
)) { /* maybe symlink too? */
120 fprintf(stderr
, "%s: `%s' is not a regular file\n", __progname
, file
);
124 /* we need this in order for MB_CUR_MAX to work */
125 /* this contradicts big time with getstyle */
126 setlocale(LC_ALL
, "");
128 WMPLSetCaseSensitive(False
);
130 style
= WMReadPropListFromFile(file
);
133 printf("%s: could not load style file\n", __progname
);
137 if (!WMIsPLDictionary(style
)) {
138 printf("%s: '%s' is not a well formatted style file\n", __progname
, file
);
142 for (i
= 0; FontOptions
[i
] != NULL
; i
++) {
143 key
= WMCreatePLString(FontOptions
[i
]);
144 val
= WMGetFromPLDictionary(style
, key
);
146 oldfont
= WMGetFromPLString(val
);
147 newfont
= convertFont(oldfont
, keepXLFD
);
148 if (oldfont
!= newfont
) {
149 val
= WMCreatePLString(newfont
);
150 WMPutInPLDictionary(style
, key
, val
);
151 WMReleasePropList(val
);
155 WMReleasePropList(key
);
158 WMWritePropListToFile(style
, file
);