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"
38 char *FontOptions
[] = {
51 extern char *__progname
;
53 extern char *convertFont(char *font
, Bool keepXLFD
);
55 void print_help(int print_usage
, int exitval
)
57 printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", __progname
);
59 puts("Converts fonts in a style file into fontconfig format");
61 puts(" -h, --help display this help and exit");
62 puts(" -v, --version output version information and exit");
63 puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
64 puts(" to the font name. This property is not used by the fontconfig");
65 puts(" matching engine to find the font, but it is useful as a hint");
66 puts(" about what the original font was to allow hand tuning the");
67 puts(" result or restoring the xlfd. The default is to not add it");
68 puts(" as it results in long, unreadable and confusing names.");
73 int main(int argc
, char **argv
)
75 WMPropList
*style
, *key
, *val
;
76 char *file
= NULL
, *oldfont
, *newfont
;
78 Bool keepXLFD
= False
;
81 struct option longopts
[] = {
82 { "version", no_argument
, NULL
, 'v' },
83 { "help", no_argument
, NULL
, 'h' },
84 { "keep-xlfd", no_argument
, &keepXLFD
, True
},
88 while ((ch
= getopt_long(argc
, argv
, "hv", longopts
, NULL
)) != -1)
91 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
112 if (stat(file
, &st
) != 0) {
117 if (!S_ISREG(st
.st_mode
)) { /* maybe symlink too? */
118 fprintf(stderr
, "%s: `%s' is not a regular file\n", __progname
, file
);
122 /* we need this in order for MB_CUR_MAX to work */
123 /* this contradicts big time with getstyle */
124 setlocale(LC_ALL
, "");
126 WMPLSetCaseSensitive(False
);
128 style
= WMReadPropListFromFile(file
);
131 printf("%s: could not load style file\n", __progname
);
135 if (!WMIsPLDictionary(style
)) {
136 printf("%s: '%s' is not a well formatted style file\n", __progname
, file
);
140 for (i
= 0; FontOptions
[i
] != NULL
; i
++) {
141 key
= WMCreatePLString(FontOptions
[i
]);
142 val
= WMGetFromPLDictionary(style
, key
);
144 oldfont
= WMGetFromPLString(val
);
145 newfont
= convertFont(oldfont
, keepXLFD
);
146 if (oldfont
!= newfont
) {
147 val
= WMCreatePLString(newfont
);
148 WMPutInPLDictionary(style
, key
, val
);
149 WMReleasePropList(val
);
153 WMReleasePropList(key
);
156 WMWritePropListToFile(style
, file
);