fixed some bugs
[wmaker-crm.git] / util / convertfonts.c
blob80ddfc12b4370e12f6eb01b01315c6b6e59e1049
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,
20 * USA.
24 #define PROG_VERSION "convertfonts (Window Maker) 1.0"
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <sys/stat.h>
29 #include <string.h>
30 #include <locale.h>
31 #include <WINGs/WUtil.h>
33 #include "../src/wconfig.h"
36 char *FontOptions[] = {
37 "IconTitleFont",
38 "ClipTitleFont",
39 "DisplayFont",
40 "LargeDisplayFont",
41 "MenuTextFont",
42 "MenuTitleFont",
43 "WindowTitleFont",
44 "SystemFont",
45 "BoldSystemFont",
46 NULL
50 char *ProgName;
52 extern char* convertFont(char *font, Bool keepXLFD);
55 void
56 print_help()
58 printf("\nUsage: %s <style_file>\n\n", ProgName);
59 puts("Converts fonts in a style file into fontconfig format");
60 puts("");
61 puts(" --help display this help and exit");
62 puts(" --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.");
69 puts("");
73 int
74 main(int argc, char **argv)
76 WMPropList *style, *key, *val;
77 char *file = NULL, *oldfont, *newfont;
78 struct stat statbuf;
79 Bool keepXLFD = False;
80 int i;
82 ProgName = argv[0];
84 if (argc<2) {
85 print_help();
86 exit(0);
89 for (i=1; i < argc; i++) {
90 if (strcmp("--version", argv[i])==0) {
91 puts(PROG_VERSION);
92 exit(0);
93 } else if (strcmp("--help", argv[i])==0) {
94 print_help();
95 exit(0);
96 } else if (strcmp("--keep-xlfd", argv[i])==0) {
97 keepXLFD = True;;
98 } else if (argv[i][0]=='-') {
99 printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
100 printf("Try '%s --help' for more information\n", ProgName);
101 exit(1);
102 } else {
103 file = argv[i];
107 /* we need this in order for MB_CUR_MAX to work */
108 setlocale(LC_ALL, "");
110 WMPLSetCaseSensitive(False);
112 if (stat(file, &statbuf) < 0) {
113 perror(file);
114 exit(1);
117 style = WMReadPropListFromFile(file);
118 if (!style) {
119 perror(file);
120 printf("%s: could not load style file.\n", ProgName);
121 exit(1);
124 if (!WMIsPLDictionary(style)) {
125 printf("%s: '%s' is not a well formatted style file\n", ProgName, file);
126 exit(1);
129 for (i=0; FontOptions[i]!=NULL; i++) {
130 key = WMCreatePLString(FontOptions[i]);
131 val = WMGetFromPLDictionary(style, key);
132 if (val) {
133 oldfont = WMGetFromPLString(val);
134 newfont = convertFont(oldfont, keepXLFD);
135 if (oldfont != newfont) {
136 val = WMCreatePLString(newfont);
137 WMPutInPLDictionary(style, key, val);
138 WMReleasePropList(val);
139 wfree(newfont);
142 WMReleasePropList(key);
145 WMWritePropListToFile(style, file, True);
147 exit(0);