1// LAF Library
2// Copyright (c) 2019-2020 Igara Studio S.A.
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#include "os/os.h"
8
9#include <cassert>
10#include <cstdio>
11
12static const char* to_str(os::FontStyle::Weight weight)
13{
14 switch (weight) {
15 case os::FontStyle::Weight::Invisible: return "Invisible";
16 case os::FontStyle::Weight::Thin: return "Thin";
17 case os::FontStyle::Weight::ExtraLight: return "ExtraLight";
18 case os::FontStyle::Weight::Light: return "Light";
19 case os::FontStyle::Weight::Normal: return "Normal";
20 case os::FontStyle::Weight::Medium: return "Medium";
21 case os::FontStyle::Weight::SemiBold: return "SemiBold";
22 case os::FontStyle::Weight::Bold: return "Bold";
23 case os::FontStyle::Weight::ExtraBold: return "ExtraBold";
24 case os::FontStyle::Weight::Black: return "Black";
25 case os::FontStyle::Weight::ExtraBlack: return "ExtraBlack";
26 }
27 return "";
28}
29
30static const char* to_str(os::FontStyle::Width width)
31{
32 switch (width) {
33 case os::FontStyle::Width::UltraCondensed: return "UltraCondensed";
34 case os::FontStyle::Width::ExtraCondensed: return "ExtraCondensed";
35 case os::FontStyle::Width::Condensed: return "Condensed";
36 case os::FontStyle::Width::SemiCondensed: return "SemiCondensed";
37 case os::FontStyle::Width::Normal: return "Normal";
38 case os::FontStyle::Width::SemiExpanded: return "SemiExpanded";
39 case os::FontStyle::Width::Expanded: return "Expanded";
40 case os::FontStyle::Width::ExtraExpanded: return "ExtraExpanded";
41 case os::FontStyle::Width::UltraExpanded: return "UltraExpanded";
42 }
43 return "";
44}
45
46static const char* to_str(os::FontStyle::Slant slant)
47{
48 switch (slant) {
49 case os::FontStyle::Slant::Upright: return "Upright";
50 case os::FontStyle::Slant::Italic: return "Italic";
51 case os::FontStyle::Slant::Oblique: return "Oblique";
52 }
53 return "";
54}
55
56static void print_set(const std::string& name, os::FontStyleSet* set)
57{
58 for (int j=0; j<set->count(); ++j) {
59 os::FontStyle style;
60 std::string styleName;
61 set->getStyle(j, style, styleName);
62 std::printf(" * %s (%s %s %s)\n",
63 name.c_str(),
64 to_str(style.weight()),
65 to_str(style.width()),
66 to_str(style.slant()));
67 }
68}
69
70int app_main(int argc, char* argv[])
71{
72 os::SystemRef system = os::make_system();
73 system->setAppMode(os::AppMode::CLI);
74
75 auto fm = system->fontManager();
76 if (!fm) {
77 std::printf("There is no font manager in your platform\n");
78 return 1;
79 }
80
81 if (argc > 1) {
82 for (int i=1; i<argc; ++i) {
83 std::string name = argv[i];
84 std::printf("%s\n", name.c_str());
85 auto set = fm->matchFamily(name);
86 if (!set) {
87 std::printf("Font family '%s' not found\n", argv[i]);
88 return 1;
89 }
90 print_set(name, set.get());
91 }
92 }
93 // Print all font families
94 else {
95 const int n = fm->countFamilies();
96 for (int i=0; i<n; ++i) {
97 std::string name = fm->familyName(i);
98 std::printf("%s\n", name.c_str());
99
100 auto fnset = fm->matchFamily(name);
101 auto set = fm->familyStyleSet(i);
102 assert(fnset->count() == set->count());
103
104 print_set(name, set.get());
105 }
106 }
107 return 0;
108}
109