- Changed fallback font to 'sans serif:pixelsize=12'
[wmaker-crm.git] / util / convertfonts.c
blobc233951438c43d6b9f622f316e928ac8ec764a08
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 <WINGs/WUtil.h>
32 #include "../src/wconfig.h"
35 char *FontOptions[] = {
36 "IconTitleFont",
37 "ClipTitleFont",
38 "DisplayFont",
39 "LargeDisplayFont",
40 "MenuTextFont",
41 "MenuTitleFont",
42 "WindowTitleFont",
43 "SystemFont",
44 "BoldSystemFont",
45 NULL
49 char *ProgName;
51 extern char* convertFont(char *font, Bool keepXLFD);
54 void
55 print_help()
57 printf("\nUsage: %s <style_file>\n\n", ProgName);
58 puts("Converts fonts in a style file into fontconfig format");
59 puts("");
60 puts(" --help display this help and exit");
61 puts(" --version output version information and exit");
62 puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
63 puts(" to the font name. This property is not used by the fontconfig");
64 puts(" matching engine to find the font, but it is useful as a hint");
65 puts(" about what the original font was to allow hand tuning the");
66 puts(" result or restoring the xlfd. The default is to not add it");
67 puts(" as it results in long, unreadable and confusing names.");
68 puts("");
71 // replace --sets-too with something better
72 int
73 main(int argc, char **argv)
75 WMPropList *style, *key, *val;
76 char *file = NULL, *oldfont, *newfont;
77 struct stat statbuf;
78 Bool keepXLFD = False;
79 int i;
81 ProgName = argv[0];
83 if (argc<2) {
84 print_help();
85 exit(0);
88 for (i=1; i < argc; i++) {
89 if (strcmp("--version", argv[i])==0) {
90 puts(PROG_VERSION);
91 exit(0);
92 } else if (strcmp("--help", argv[i])==0) {
93 print_help();
94 exit(0);
95 } else if (strcmp("--keep-xlfd", argv[i])==0) {
96 keepXLFD = True;;
97 } else if (argv[i][0]=='-') {
98 printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
99 printf("Try '%s --help' for more information\n", ProgName);
100 exit(1);
101 } else {
102 file = argv[i];
106 /* we need this in order for MB_CUR_MAX to work */
107 setlocale(LC_ALL, "");
109 WMPLSetCaseSensitive(False);
111 if (stat(file, &statbuf) < 0) {
112 perror(file);
113 exit(1);
116 style = WMReadPropListFromFile(file);
117 if (!style) {
118 perror(file);
119 printf("%s: could not load style file.\n", ProgName);
120 exit(1);
123 if (!WMIsPLDictionary(style)) {
124 printf("%s: '%s' is not a well formatted style file\n", ProgName, file);
125 exit(1);
128 for (i=0; FontOptions[i]!=NULL; i++) {
129 key = WMCreatePLString(FontOptions[i]);
130 val = WMGetFromPLDictionary(style, key);
131 if (val) {
132 oldfont = WMGetFromPLString(val);
133 newfont = convertFont(oldfont, keepXLFD);
134 if (oldfont != newfont) {
135 val = WMCreatePLString(newfont);
136 WMPutInPLDictionary(style, key, val);
137 WMReleasePropList(val);
138 wfree(newfont);
141 WMReleasePropList(key);
144 WMWritePropListToFile(style, file, True);
146 exit(0);