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 */
36 #ifdef HAVE_STDNORETURN
37 #include <stdnoreturn.h>
40 #include <WINGs/WUtil.h>
42 #include "../src/wconfig.h"
47 char *FontOptions
[] = {
59 static const char *prog_name
;
62 static noreturn
void print_help(int print_usage
, int exitval
)
64 printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", prog_name
);
66 puts("Converts fonts in a style file into fontconfig format");
68 puts(" -h, --help display this help and exit");
69 puts(" -v, --version output version information and exit");
70 puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
71 puts(" to the font name. This property is not used by the fontconfig");
72 puts(" matching engine to find the font, but it is useful as a hint");
73 puts(" about what the original font was to allow hand tuning the");
74 puts(" result or restoring the xlfd. The default is to not add it");
75 puts(" as it results in long, unreadable and confusing names.");
80 int main(int argc
, char **argv
)
82 WMPropList
*style
, *key
, *val
;
83 char *file
= NULL
, *oldfont
, *newfont
;
85 Bool keepXLFD
= False
;
88 struct option longopts
[] = {
89 { "version", no_argument
, NULL
, 'v' },
90 { "help", no_argument
, NULL
, 'h' },
91 { "keep-xlfd", no_argument
, &keepXLFD
, True
},
96 while ((ch
= getopt_long(argc
, argv
, "hv", longopts
, NULL
)) != -1)
99 printf("%s (Window Maker %s)\n", prog_name
, VERSION
);
120 if (stat(file
, &st
) != 0) {
125 if (!S_ISREG(st
.st_mode
)) { /* maybe symlink too? */
126 fprintf(stderr
, "%s: `%s' is not a regular file\n", prog_name
, file
);
130 /* we need this in order for MB_CUR_MAX to work */
131 /* this contradicts big time with getstyle */
132 setlocale(LC_ALL
, "");
134 WMPLSetCaseSensitive(False
);
136 style
= WMReadPropListFromFile(file
);
139 printf("%s: could not load style file\n", prog_name
);
143 if (!WMIsPLDictionary(style
)) {
144 printf("%s: '%s' is not a well formatted style file\n", prog_name
, file
);
148 for (i
= 0; FontOptions
[i
] != NULL
; i
++) {
149 key
= WMCreatePLString(FontOptions
[i
]);
150 val
= WMGetFromPLDictionary(style
, key
);
152 oldfont
= WMGetFromPLString(val
);
153 newfont
= convertFont(oldfont
, keepXLFD
);
154 if (oldfont
!= newfont
) {
155 val
= WMCreatePLString(newfont
);
156 WMPutInPLDictionary(style
, key
, val
);
157 WMReleasePropList(val
);
161 WMReleasePropList(key
);
164 WMWritePropListToFile(style
, file
);