Refactor: arguments specify font pattern
This commit is contained in:
parent
f1ee0d12e1
commit
1c1f22a98f
27
main.cpp
27
main.cpp
|
@ -15,27 +15,38 @@ FcChar8 * toFcChar8(const char * sc) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
void print_help(const string & program_name) {
|
||||||
|
cout << "Usage: " << program_name << "\"Font Pattern\"" << endl;
|
||||||
|
cout << "Note: better to quote all your pattern," << endl;
|
||||||
|
cout << " since bash will split them into multi word if not" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char ** argv) {
|
||||||
FcPattern * fcp = FcPatternCreate();
|
FcPattern * fcp = FcPatternCreate();
|
||||||
|
|
||||||
string line;
|
if (argc != 2) {
|
||||||
getline(cin, line);
|
cout << "Wrong usage!" << endl;
|
||||||
|
print_help(argv[0]);
|
||||||
|
|
||||||
line += ',';
|
exit(-1);
|
||||||
size_t l = 0, r = line.find(",", 0);
|
}
|
||||||
|
|
||||||
|
string patterns = argv[1];
|
||||||
|
|
||||||
|
patterns += ',';
|
||||||
|
size_t l = 0, r = patterns.find(",", 0);
|
||||||
while (r != string::npos) {
|
while (r != string::npos) {
|
||||||
FcChar8 * queryName = toFcChar8(line.substr(l, r - l).c_str());
|
FcChar8 * queryName = toFcChar8(patterns.substr(l, r - l).c_str());
|
||||||
FcPatternAddString(fcp, FC_FAMILY, queryName);
|
FcPatternAddString(fcp, FC_FAMILY, queryName);
|
||||||
delete[] queryName;
|
delete[] queryName;
|
||||||
|
|
||||||
l = r + 1;
|
l = r + 1;
|
||||||
r = line.find(",", l + 1);
|
r = patterns.find(",", l + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
FcChar8 * resultName = nullptr;
|
FcChar8 * resultName = nullptr;
|
||||||
FcConfigSubstitute(nullptr, fcp, FcMatchPattern);
|
FcConfigSubstitute(nullptr, fcp, FcMatchPattern);
|
||||||
|
|
||||||
cout << "========================" << endl;
|
|
||||||
for (int i = 0; FcPatternGetString(fcp, FC_FAMILY, i, &resultName) == FcResultMatch; ++i) {
|
for (int i = 0; FcPatternGetString(fcp, FC_FAMILY, i, &resultName) == FcResultMatch; ++i) {
|
||||||
cout << resultName << endl;
|
cout << resultName << endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue