Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / bin / listfont.cpp
blob6daf02547ad7b811476fffdb0417ad7148d452c9
1 /*
2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Copyright 2004, François Revol. All rights reserved.
4 * Distributed under the terms of the MIT License.
5 */
8 #include <getopt.h>
9 #include <stdio.h>
11 #include <Application.h>
12 #include <Font.h>
13 #include <String.h>
16 static struct option const kLongOptions[] = {
17 {"styles", no_argument, 0, 's'},
18 {"long", no_argument, 0, 'l'},
19 {"tuned", no_argument, 0, 't'},
20 {"help", no_argument, 0, 'h'},
21 {NULL}
24 extern const char *__progname;
25 static const char *sProgramName = __progname;
28 void
29 usage(void)
31 printf("%s [-s] [-l]\n", sProgramName);
32 printf("lists currently installed font families.\n");
33 printf("\t-s --styles list styles for each family\n");
34 printf("\t-l --long long listing with more info (spacing, encoding,\n"
35 "\t\t\theight (ascent/descent/leading), ...)\n");
36 printf("\t-t --tuned display tuned fonts\n");
37 #ifndef __HAIKU__
38 printf("\t-u update font families\n");
39 #endif
43 int
44 main(int argc, char **argv)
46 // parse command line parameters
48 bool displayStyles = false;
49 bool displayLong = false;
50 bool displayTuned = false;
51 #ifndef __HAIKU__
52 bool updateFamilies = false;
53 #endif
55 int c;
56 while ((c = getopt_long(argc, argv, "sltuh", kLongOptions, NULL)) != -1) {
57 switch (c) {
58 case 0:
59 break;
60 case 'h':
61 usage();
62 return 0;
63 default:
64 usage();
65 return 1;
67 case 't':
68 displayTuned = true;
69 case 'l':
70 displayLong = true;
71 case 's':
72 displayStyles = true;
73 break;
74 #ifndef __HAIKU__
75 case 'u':
76 updateFamilies = true;
77 break;
78 #endif
82 BApplication app("application/x-vnd.Haiku-listfont");
84 #ifndef __HAIKU__
85 if (updateFamilies) {
86 bool changed = update_font_families(true);
87 printf("font families %s.\n", changed ? "changed" : "did not change");
88 return 0;
90 #endif
92 int32 familyCount = count_font_families();
94 if (displayLong) {
95 printf("name/style face spc. enc. "
96 "height (a, d, l) flags\n\n");
99 for (int32 f = 0; f < familyCount; f++) {
100 font_family family;
101 if (get_font_family(f, &family) < B_OK)
102 continue;
103 if (!displayStyles) {
104 printf("%s\n", family);
105 continue;
108 int32 styleCount = count_font_styles(family);
110 for (int32 s = 0; s < styleCount; s++) {
111 font_style style;
112 uint16 face;
113 uint32 flags;
114 if (get_font_style(family, s, &style, &face, &flags) < B_OK)
115 continue;
117 if (!displayLong) {
118 printf("%s/%s\n", family, style);
119 continue;
122 BString fontName;
123 fontName << family << "/" << style;
124 printf("%-37s", fontName.String());
126 BFont font;
127 font.SetFamilyAndStyle(family, style);
128 printf(" 0x%02x %-4d %-4d", face, font.Spacing(), font.Encoding());
130 font_height fh;
131 font.GetHeight(&fh);
132 printf(" %5.2f, %4.2f, %4.2f ", fh.ascent, fh.descent, fh.leading);
133 if ((flags & B_IS_FIXED) != 0)
134 printf("fixed");
136 #if B_BEOS_VERSION == B_BEOS_VERSION_5
137 /* seems R5 is broken there :-( locks up on 'a> recv' */
138 printf("\t%s", (flags & B_HAS_TUNED_FONT) != 0 ? "hastuned " : "");
139 #else
140 if ((flags & B_HAS_TUNED_FONT) != 0) {
141 if (displayTuned)
142 printf("\n ");
143 else if ((flags & B_IS_FIXED) != 0)
144 printf(", ");
146 int32 tunedCount = font.CountTuned();
147 printf("%ld tuned", tunedCount);
149 if (displayTuned) {
150 printf(":");
151 for (int32 i = 0; i < tunedCount; i++) {
152 tuned_font_info info;
153 font.GetTunedInfo(i, &info);
154 printf("\n\t(size %4.1f, shear %5.3f, rot. %5.3f, flags 0x%lx, face 0x%x)",
155 info.size,
156 info.shear, info.rotation, info.flags, info.face);
160 #endif
161 putchar('\n');
164 return 0;