* Applied our coding style.

* Made output much more readable and useful (especially with 80 characters).
* Removed useless -u option when built for Haiku.
* Added a new option -t that shows the tunables.
* Removed the hack to let be_app run - it works fine without on BeOS.
* Improved parameter parsing (now uses getopt_long()), also added long names
  for all options.
* I'm all for removing BeOS/Dano support completely from this app.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22825 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-11-04 14:21:12 +00:00
parent 21599cafab
commit 888514b231
+127 -75
View File
@@ -1,113 +1,165 @@
/* /*
* listfont * Copyright 2007, Axel Dörfler, [email protected]. All rights reserved.
* (c) 2004, François Revol. * Copyright 2004, François Revol. All rights reserved.
* Distributed under the terms of the MIT License.
*/ */
#include <getopt.h>
#include <stdio.h> #include <stdio.h>
#include <Application.h> #include <Application.h>
#include <Font.h> #include <Font.h>
#include <String.h> #include <String.h>
int32 th(void *)
{
be_app->Lock();
be_app->Run();
return B_OK;
}
int usage(int ret) static struct option const kLongOptions[] = {
{"styles", no_argument, 0, 's'},
{"long", no_argument, 0, 'l'},
{"tuned", no_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
{NULL}
};
extern const char *__progname;
static const char *sProgramName = __progname;
void
usage(void)
{ {
printf("listfont [-s] [-l]\n"); printf("%s [-s] [-l]\n", sProgramName);
printf("lists currently installed font families.\n"); printf("lists currently installed font families.\n");
printf("\t-s list styles for each family\n"); printf("\t-s --styles list styles for each family\n");
printf("\t-l long listing with more info\n"); printf("\t-l --long long listing with more info (spacing, encoding,\n"
printf("\t-u update font families\n"); "\t\t\theight (ascent/descent/leading), ...)\n");
return ret; printf("\t-t --tuned display tuned fonts\n");
#ifndef __HAIKU__
printf("\t-u update font families\n");
#endif
} }
int main(int argc, char **argv)
int
main(int argc, char **argv)
{ {
int32 family_count, f; // parse command line parameters
font_family family;
int32 style_count, s; bool displayStyles = false;
font_style style; bool displayLong = false;
uint16 face; bool displayTuned = false;
uint32 flags; #ifndef __HAIKU__
int i; bool updateFamilies = false;
bool display_styles = false; #endif
bool display_long = false;
bool update_families = false; int c;
for (i = 1; i < argc; i++) { while ((c = getopt_long(argc, argv, "sltuh", kLongOptions, NULL)) != -1) {
if (!strcmp(argv[i], "-u")) switch (c) {
update_families = true; case 0:
else if (!strcmp(argv[i], "-s")) break;
display_styles = true; case 'h':
else if (!strcmp(argv[i], "-l")) { usage();
display_long = true; return 0;
display_styles = true; default:
} else usage();
return usage(1); return 1;
case 't':
displayTuned = true;
case 'l':
displayLong = true;
case 's':
displayStyles = true;
break;
#ifndef __HAIKU__
case 'u':
updateFamilies = true;
break;
#endif
}
} }
BApplication app("application/x-vnd.mmu_man.listfont");
resume_thread(spawn_thread(th, "be_app", B_NORMAL_PRIORITY, NULL)); BApplication app("application/x-vnd.Haiku-listfont");
be_app->Unlock();
if (update_families) { #ifndef __HAIKU__
if (updateFamilies) {
bool changed = update_font_families(true); bool changed = update_font_families(true);
printf("font families %schanged.\n", changed?"":"didn't "); printf("font families %s.\n", changed ? "changed" : "did not change");
return 0; return 0;
} }
family_count = count_font_families(); #endif
for (f = 0; f < family_count; f++) {
int32 familyCount = count_font_families();
if (displayLong) {
printf("name/style face spc. enc. "
"height (a, d, l) flags\n\n");
}
for (int32 f = 0; f < familyCount; f++) {
font_family family;
if (get_font_family(f, &family) < B_OK) if (get_font_family(f, &family) < B_OK)
continue; continue;
if (!display_styles) { if (!displayStyles) {
printf("%s\n", family); printf("%s\n", family);
continue; continue;
} }
style_count = count_font_styles(family);
for (s = 0; s < style_count; s++) { int32 styleCount = count_font_styles(family);
for (int32 s = 0; s < styleCount; s++) {
font_style style;
uint16 face;
uint32 flags;
if (get_font_style(family, s, &style, &face, &flags) < B_OK) if (get_font_style(family, s, &style, &face, &flags) < B_OK)
continue; continue;
if (!display_long) {
if (!displayLong) {
printf("%s/%s\n", family, style); printf("%s/%s\n", family, style);
continue; continue;
} }
BString fname;
fname << family << "/" << style; BString fontName;
printf("%-30s", fname.String()); fontName << family << "/" << style;
BFont fnt; printf("%-37s", fontName.String());
fnt.SetFamilyAndStyle(family, style);
//fnt.PrintToStream(); BFont font;
printf("\tface=%08x ", face); font.SetFamilyAndStyle(family, style);
printf(" 0x%02x %-4d %-4d", face, font.Spacing(), font.Encoding());
font_height fh; font_height fh;
fnt.GetHeight(&fh); font.GetHeight(&fh);
printf("\theight={%f %f %f} ", fh.ascent, fh.descent, fh.leading); printf(" %5.2f, %4.2f, %4.2f ", fh.ascent, fh.descent, fh.leading);
printf("\t%s", (flags & B_IS_FIXED)?"fixed ":""); if ((flags & B_IS_FIXED) != 0)
#ifndef B_BEOS_VERSION_DANO printf("fixed");
#if B_BEOS_VERSION == B_BEOS_VERSION_5
/* seems R5 is broken there :-( locks up on 'a> recv' */ /* seems R5 is broken there :-( locks up on 'a> recv' */
printf("\t%s", (flags & B_HAS_TUNED_FONT)?"hastuned ":""); printf("\t%s", (flags & B_HAS_TUNED_FONT) != 0 ? "hastuned " : "");
#else #else
if (flags & B_HAS_TUNED_FONT) { if ((flags & B_HAS_TUNED_FONT) != 0) {
int32 tunedcount = fnt.CountTuned(); if (displayTuned)
printf("%ld tuned: ", tunedcount); printf("\n ");
//puts(""); else if ((flags & B_IS_FIXED) != 0)
#if 1 printf(", ");
for (i = 0; i < tunedcount; i++) {
tuned_font_info tfi; int32 tunedCount = font.CountTuned();
fnt.GetTunedInfo(i, &tfi); printf("%ld tuned", tunedCount);
printf("{%f, %f, %f, %08lx, %x} ", tfi.size, tfi.shear, tfi.rotation, tfi.flags, tfi.face);
//puts(""); if (displayTuned) {
printf(":");
for (int32 i = 0; i < tunedCount; i++) {
tuned_font_info info;
font.GetTunedInfo(i, &info);
printf("\n\t(size %4.1f, shear %5.3f, rot. %5.3f, flags 0x%lx, face 0x%x)",
info.size,
info.shear, info.rotation, info.flags, info.face);
}
} }
#endif
} }
#endif #endif
//printf("\tFlags=%08lx ", fnt.Flags()); putchar('\n');
printf("\tspacing=%d ", fnt.Spacing());
printf("\tencoding=%d ", fnt.Encoding());
puts("");
} }
} }
be_app->Lock();
be_app->Quit();
return 0; return 0;
} }