mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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 =
|
style =
|
||||||
createIfNull(style)
|
createIfNull(style)
|
||||||
.setTextEmphasis(TextEmphasis.parse(Util.toLowerInvariant(attributeValue)));
|
.setTextEmphasis(TextEmphasis.parse(Util.toLowerInvariant(attributeValue)));
|
||||||
|
break;
|
||||||
case TtmlNode.ATTR_TTS_SHEAR:
|
case TtmlNode.ATTR_TTS_SHEAR:
|
||||||
style = createIfNull(style);
|
style = createIfNull(style).setShearPercentage(parseShear(attributeValue));
|
||||||
try {
|
|
||||||
parseShear(attributeValue, style);
|
|
||||||
} catch (SubtitleDecoderException e) {
|
|
||||||
Log.w(TAG, "Failed parsing shear value: " + attributeValue);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// ignore
|
// ignore
|
||||||
|
|
@ -764,25 +760,25 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void parseShear(String expression, TtmlStyle out) throws
|
private static float parseShear(String expression) {
|
||||||
SubtitleDecoderException {
|
|
||||||
Matcher matcher = SIGNED_PERCENTAGE.matcher(expression);
|
Matcher matcher = SIGNED_PERCENTAGE.matcher(expression);
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
try {
|
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
|
// 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
|
// 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.
|
// interpreted as if 100% were specified with the appropriate sign.
|
||||||
value = Math.max(-100f, value);
|
value = Math.max(-100f, value);
|
||||||
value = Math.min(100f, value);
|
value = Math.min(100f, value);
|
||||||
out.setShearPercentage(value);
|
return value;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new SubtitleDecoderException("Invalid expression for shear: '" + expression + "'.",
|
Log.w(TAG, "NumberFormatException while parsing shear: " + expression);
|
||||||
e);
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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 =
|
String direction =
|
||||||
(cue.verticalType == Cue.VERTICAL_TYPE_LR || cue.verticalType == Cue.VERTICAL_TYPE_RL) ?
|
(cue.verticalType == Cue.VERTICAL_TYPE_LR || cue.verticalType == Cue.VERTICAL_TYPE_RL) ?
|
||||||
"skewY" : "skewX";
|
"skewY" : "skewX";
|
||||||
return Util.formatInvariant(" %s(%.2fdeg)", direction, cue.shearDegrees);
|
return Util.formatInvariant("%s(%.2fdeg)", direction, cue.shearDegrees);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue