* 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

View File

@ -1,113 +1,165 @@
/*
* listfont
* (c) 2004, François Revol.
* Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2004, François Revol. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <getopt.h>
#include <stdio.h>
#include <Application.h>
#include <Font.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("\t-s list styles for each family\n");
printf("\t-l long listing with more info\n");
printf("\t-s --styles list styles for each family\n");
printf("\t-l --long long listing with more info (spacing, encoding,\n"
"\t\t\theight (ascent/descent/leading), ...)\n");
printf("\t-t --tuned display tuned fonts\n");
#ifndef __HAIKU__
printf("\t-u update font families\n");
return ret;
#endif
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
int32 family_count, f;
font_family family;
int32 style_count, s;
font_style style;
uint16 face;
uint32 flags;
int i;
bool display_styles = false;
bool display_long = false;
bool update_families = false;
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-u"))
update_families = true;
else if (!strcmp(argv[i], "-s"))
display_styles = true;
else if (!strcmp(argv[i], "-l")) {
display_long = true;
display_styles = true;
} else
return usage(1);
// parse command line parameters
bool displayStyles = false;
bool displayLong = false;
bool displayTuned = false;
#ifndef __HAIKU__
bool updateFamilies = false;
#endif
int c;
while ((c = getopt_long(argc, argv, "sltuh", kLongOptions, NULL)) != -1) {
switch (c) {
case 0:
break;
case 'h':
usage();
return 0;
default:
usage();
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));
be_app->Unlock();
if (update_families) {
}
BApplication app("application/x-vnd.Haiku-listfont");
#ifndef __HAIKU__
if (updateFamilies) {
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;
}
family_count = count_font_families();
for (f = 0; f < family_count; f++) {
#endif
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)
continue;
if (!display_styles) {
if (!displayStyles) {
printf("%s\n", family);
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)
continue;
if (!display_long) {
if (!displayLong) {
printf("%s/%s\n", family, style);
continue;
}
BString fname;
fname << family << "/" << style;
printf("%-30s", fname.String());
BFont fnt;
fnt.SetFamilyAndStyle(family, style);
//fnt.PrintToStream();
printf("\tface=%08x ", face);
BString fontName;
fontName << family << "/" << style;
printf("%-37s", fontName.String());
BFont font;
font.SetFamilyAndStyle(family, style);
printf(" 0x%02x %-4d %-4d", face, font.Spacing(), font.Encoding());
font_height fh;
fnt.GetHeight(&fh);
printf("\theight={%f %f %f} ", fh.ascent, fh.descent, fh.leading);
printf("\t%s", (flags & B_IS_FIXED)?"fixed ":"");
#ifndef B_BEOS_VERSION_DANO
font.GetHeight(&fh);
printf(" %5.2f, %4.2f, %4.2f ", fh.ascent, fh.descent, fh.leading);
if ((flags & B_IS_FIXED) != 0)
printf("fixed");
#if B_BEOS_VERSION == B_BEOS_VERSION_5
/* 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
if (flags & B_HAS_TUNED_FONT) {
int32 tunedcount = fnt.CountTuned();
printf("%ld tuned: ", tunedcount);
//puts("");
#if 1
for (i = 0; i < tunedcount; i++) {
tuned_font_info tfi;
fnt.GetTunedInfo(i, &tfi);
printf("{%f, %f, %f, %08lx, %x} ", tfi.size, tfi.shear, tfi.rotation, tfi.flags, tfi.face);
//puts("");
if ((flags & B_HAS_TUNED_FONT) != 0) {
if (displayTuned)
printf("\n ");
else if ((flags & B_IS_FIXED) != 0)
printf(", ");
int32 tunedCount = font.CountTuned();
printf("%ld tuned", tunedCount);
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
//printf("\tFlags=%08lx ", fnt.Flags());
printf("\tspacing=%d ", fnt.Spacing());
printf("\tencoding=%d ", fnt.Encoding());
puts("");
putchar('\n');
}
}
be_app->Lock();
be_app->Quit();
return 0;
}