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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24 #define _GNU_SOURCE /* getopt_long */
35 #include <WINGs/WUtil.h>
37 #include "../src/wconfig.h"
39 char *FontOptions
[] = {
52 extern char *__progname
;
54 extern char *convertFont(char *font
, Bool keepXLFD
);
56 void print_help(int print_usage
, int exitval
)
58 printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", __progname
);
60 puts("Converts fonts in a style file into fontconfig format");
62 puts(" -h, --help display this help and exit");
63 puts(" -v, --version output version information and exit");
64 puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
65 puts(" to the font name. This property is not used by the fontconfig");
66 puts(" matching engine to find the font, but it is useful as a hint");
67 puts(" about what the original font was to allow hand tuning the");
68 puts(" result or restoring the xlfd. The default is to not add it");
69 puts(" as it results in long, unreadable and confusing names.");
74 int main(int argc
, char **argv
)
76 WMPropList
*style
, *key
, *val
;
77 char *file
= NULL
, *oldfont
, *newfont
;
79 Bool keepXLFD
= False
;
82 struct option longopts
[] = {
83 { "version", no_argument
, NULL
, 'v' },
84 { "help", no_argument
, NULL
, 'h' },
85 { "keep-xlfd", no_argument
, &keepXLFD
, True
},
89 while ((ch
= getopt_long(argc
, argv
, "hv", longopts
, NULL
)) != -1)
92 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
113 if (stat(file
, &st
) != 0) {
118 if (!S_ISREG(st
.st_mode
)) { /* maybe symlink too? */
119 fprintf(stderr
, "%s: `%s' is not a regular file\n", __progname
, file
);
123 /* we need this in order for MB_CUR_MAX to work */
124 /* this contradicts big time with getstyle */
125 setlocale(LC_ALL
, "");
127 WMPLSetCaseSensitive(False
);
129 style
= WMReadPropListFromFile(file
);
132 printf("%s: could not load style file\n", __progname
);
136 if (!WMIsPLDictionary(style
)) {
137 printf("%s: '%s' is not a well formatted style file\n", __progname
, file
);
141 for (i
= 0; FontOptions
[i
] != NULL
; i
++) {
142 key
= WMCreatePLString(FontOptions
[i
]);
143 val
= WMGetFromPLDictionary(style
, key
);
145 oldfont
= WMGetFromPLString(val
);
146 newfont
= convertFont(oldfont
, keepXLFD
);
147 if (oldfont
!= newfont
) {
148 val
= WMCreatePLString(newfont
);
149 WMPutInPLDictionary(style
, key
, val
);
150 WMReleasePropList(val
);
154 WMReleasePropList(key
);
157 WMWritePropListToFile(style
, file
);