Encode WebVTT size computation in WebvttCue.java
Relevant part of the spec: https://www.w3.org/TR/webvtt1/#processing-cue-settings PiperOrigin-RevId: 277523694
This commit is contained in:
parent
d29d452617
commit
f5377d9b11
@ -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 {
|
|||||||
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user