mirror of
https://github.com/samsonjs/media.git
synced 2026-04-04 11:05:47 +00:00
Address code review comments
This commit is contained in:
parent
4be774aaac
commit
475b1fe3de
2 changed files with 10 additions and 14 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 "";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue