1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/* convertfonts.c - converts fonts in a style file to fontconfig format
*
* WindowMaker window manager
*
* Copyright (c) 2004 Dan Pascu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef __GLIBC__
#define _GNU_SOURCE /* getopt_long */
#endif
#include "config.h"
#include <sys/stat.h>
#include <getopt.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STDNORETURN
#include <stdnoreturn.h>
#endif
#include <WINGs/WUtil.h>
#include "../src/wconfig.h"
#include "common.h"
char *FontOptions[] = {
"IconTitleFont",
"ClipTitleFont",
"LargeDisplayFont",
"MenuTextFont",
"MenuTitleFont",
"WindowTitleFont",
"SystemFont",
"BoldSystemFont",
NULL
};
static const char *prog_name;
static noreturn void print_help(int print_usage, int exitval)
{
printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", prog_name);
if (print_usage) {
puts("Converts fonts in a style file into fontconfig format");
puts("");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
puts(" to the font name. This property is not used by the fontconfig");
puts(" matching engine to find the font, but it is useful as a hint");
puts(" about what the original font was to allow hand tuning the");
puts(" result or restoring the xlfd. The default is to not add it");
puts(" as it results in long, unreadable and confusing names.");
}
exit(exitval);
}
int main(int argc, char **argv)
{
WMPropList *style, *key, *val;
char *file = NULL, *oldfont, *newfont;
struct stat st;
Bool keepXLFD = False;
int i, ch;
struct option longopts[] = {
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ "keep-xlfd", no_argument, &keepXLFD, True },
{ NULL, 0, NULL, 0 }
};
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) {
case 'v':
printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0;
/* NOTREACHED */
case 'h':
print_help(1, 0);
/* NOTREACHED */
case 0:
break;
default:
print_help(0, 1);
/* NOTREACHED */
}
argc -= optind;
argv += optind;
if (argc != 1)
print_help(0, 1);
file = argv[0];
if (stat(file, &st) != 0) {
perror(file);
return 1;
}
if (!S_ISREG(st.st_mode)) { /* maybe symlink too? */
fprintf(stderr, "%s: `%s' is not a regular file\n", prog_name, file);
return 1;
}
/* we need this in order for MB_CUR_MAX to work */
/* this contradicts big time with getstyle */
setlocale(LC_ALL, "");
WMPLSetCaseSensitive(False);
style = WMReadPropListFromFile(file);
if (!style) {
perror(file);
printf("%s: could not load style file\n", prog_name);
return 1;
}
if (!WMIsPLDictionary(style)) {
printf("%s: '%s' is not a well formatted style file\n", prog_name, file);
return 1;
}
for (i = 0; FontOptions[i] != NULL; i++) {
key = WMCreatePLString(FontOptions[i]);
val = WMGetFromPLDictionary(style, key);
if (val) {
oldfont = WMGetFromPLString(val);
newfont = convertFont(oldfont, keepXLFD);
if (oldfont != newfont) {
val = WMCreatePLString(newfont);
WMPutInPLDictionary(style, key, val);
WMReleasePropList(val);
wfree(newfont);
}
}
WMReleasePropList(key);
}
WMWritePropListToFile(style, file);
return 0;
}
|