Address code review comments

This commit is contained in:
Denise LaFayette 2021-03-25 11:59:28 -07:00
parent 4be774aaac
commit 475b1fe3de
2 changed files with 10 additions and 14 deletions

View file

@ -615,13 +615,9 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
style =
createIfNull(style)
.setTextEmphasis(TextEmphasis.parse(Util.toLowerInvariant(attributeValue)));
break;
case TtmlNode.ATTR_TTS_SHEAR:
style = createIfNull(style);
try {
parseShear(attributeValue, style);
} catch (SubtitleDecoderException e) {
Log.w(TAG, "Failed parsing shear value: " + attributeValue);
}
style = createIfNull(style).setShearPercentage(parseShear(attributeValue));
break;
default:
// ignore
@ -764,25 +760,25 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
}
}
private static void parseShear(String expression, TtmlStyle out) throws
SubtitleDecoderException {
private static float parseShear(String expression) {
Matcher matcher = SIGNED_PERCENTAGE.matcher(expression);
if (matcher.matches()) {
try {
float value = Float.parseFloat(matcher.group(1));
String percentage = Assertions.checkNotNull(matcher.group(1));
float value = Float.parseFloat(percentage);
// https://www.w3.org/TR/2018/REC-ttml2-20181108/#semantics-style-procedures-shear
// If the absolute value of the specified percentage is greater than 100%, then it must be
// interpreted as if 100% were specified with the appropriate sign.
value = Math.max(-100f, value);
value = Math.min(100f, value);
out.setShearPercentage(value);
return value;
} catch (NumberFormatException e) {
throw new SubtitleDecoderException("Invalid expression for shear: '" + expression + "'.",
e);
Log.w(TAG, "NumberFormatException while parsing shear: " + expression);
}
} else {
throw new SubtitleDecoderException("Invalid expression for shear: '" + expression + "'.");
Log.w(TAG, "Invalid value for shear: " + expression);
}
return 0f;
}
/**

View file

@ -326,7 +326,7 @@ import java.util.Map;
String direction =
(cue.verticalType == Cue.VERTICAL_TYPE_LR || cue.verticalType == Cue.VERTICAL_TYPE_RL) ?
"skewY" : "skewX";
return Util.formatInvariant(" %s(%.2fdeg)", direction, cue.shearDegrees);
return Util.formatInvariant("%s(%.2fdeg)", direction, cue.shearDegrees);
}
return "";
}