Commit f5377d9b by ibaker Committed by Oliver Woodman

Encode WebVTT size computation in WebvttCue.java

Relevant part of the spec:
https://www.w3.org/TR/webvtt1/#processing-cue-settings

PiperOrigin-RevId: 277523694
parent d29d4526
...@@ -163,6 +163,8 @@ public final class WebvttCue extends Cue { ...@@ -163,6 +163,8 @@ public final class WebvttCue extends Cue {
positionAnchor = derivePositionAnchor(textAlignment); positionAnchor = derivePositionAnchor(textAlignment);
} }
width = Math.min(width, deriveMaxSize(positionAnchor, position));
return new WebvttCue( return new WebvttCue(
startTime, startTime,
endTime, endTime,
...@@ -290,5 +292,24 @@ public final class WebvttCue extends Cue { ...@@ -290,5 +292,24 @@ public final class WebvttCue extends Cue {
return null; return null;
} }
} }
// Step 2 here: https://www.w3.org/TR/webvtt1/#processing-cue-settings
private static float deriveMaxSize(@AnchorType int positionAnchor, float position) {
switch (positionAnchor) {
case Cue.ANCHOR_TYPE_START:
return 1.0f - position;
case Cue.ANCHOR_TYPE_END:
return position;
case Cue.ANCHOR_TYPE_MIDDLE:
if (position <= 0.5f) {
return position * 2;
} else {
return (1.0f - position) * 2;
}
case Cue.TYPE_UNSET:
default:
throw new IllegalStateException(String.valueOf(positionAnchor));
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment