public T match(int desiredWeight, IdentValue style) {
if (_fontDescriptions == null) {
throw new RuntimeException("fontDescriptions is null");
}
List<T> candidates = new ArrayList<T>();
for (T description : _fontDescriptions) {
if (description.getStyle() == style) {
candidates.add(description);
}
}
if (candidates.size() == 0) {
if (style == IdentValue.ITALIC) {
return match(desiredWeight, IdentValue.OBLIQUE);
} else if (style == IdentValue.OBLIQUE) {
return match(desiredWeight, IdentValue.NORMAL);
} else {
candidates.addAll(_fontDescriptions);
}
}
T result = findByWeight(candidates, desiredWeight, SM_EXACT);
if (result != null) {
return result;
} else {
if (desiredWeight <= 500) {
return findByWeight(candidates, desiredWeight, SM_LIGHTER_OR_DARKER);
} else {
return findByWeight(candidates, desiredWeight, SM_DARKER_OR_LIGHTER);
}
}
}