Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions lib/vtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ function CueStyleBox(window, cue, styleOptions) {
// have inline positioning and will function as the cue background box.
this.cueDiv = parseContent(window, cue.text);
var styles = {
color: "rgba(255, 255, 255, 1)",
backgroundColor: "rgba(0, 0, 0, 0.8)",
color: styleOptions.color || "inherit",
backgroundColor: styleOptions.backgroundColor || "inherit",
position: "relative",
left: 0,
right: 0,
Expand All @@ -565,7 +565,10 @@ function CueStyleBox(window, cue, styleOptions) {
: "vertical-rl",
unicodeBidi: "plaintext",
textAlign: cue.align === "middle" ? "center" : cue.align,
font: styleOptions.font,
font: styleOptions.font || "inherit",
fontVariant: styleOptions.fontVariant || "inherit",
textShadow: styleOptions.textShadow || "inherit",
backgroundColor: styleOptions.windowColor || "inherit",
whiteSpace: "pre-line",
position: "absolute"
};
Expand Down Expand Up @@ -923,18 +926,23 @@ WebVTT.convertCueToDOMTree = function(window, cuetext) {
return parseContent(window, cuetext);
};

var FONT_SIZE_PERCENT = 0.05;
var FONT_STYLE = "sans-serif";
var CUE_BACKGROUND_PADDING = "1.5%";
var DEFAULT_FONT_SIZE_PERCENT = 5; // 5% of the height of the video window
var DEFAULT_FONT_STYLE = "sans-serif";
var DEFAULT_CUE_BACKGROUND_PADDING = "1.5%";
var DEFAULT_FOREGROUND_COLOR = "rgba(255, 255, 255, 1)"; White, 100% opaque
var DEFAULT_BACKGROUND_COLOR = "rgba(0, 0, 0, 0.8)"; Black, 80% opaque
var DEFAULT_WINDOW_COLOR = "rgba(0, 0, 0, 0.0)"; Black, translucent

// Runs the processing model over the cues and regions passed to it.
// @param overlay A block level element (usually a div) that the computed cues
// and regions will be placed into.
WebVTT.processCues = function(window, cues, overlay) {
WebVTT.processCues = function(window, cues, overlay, styles) {
if (!window || !cues || !overlay) {
return null;
}

styles = styles || {};

// Remove all previous children.
while (overlay.firstChild) {
overlay.removeChild(overlay.firstChild);
Expand All @@ -946,7 +954,7 @@ WebVTT.processCues = function(window, cues, overlay) {
paddedOverlay.style.right = "0";
paddedOverlay.style.top = "0";
paddedOverlay.style.bottom = "0";
paddedOverlay.style.margin = CUE_BACKGROUND_PADDING;
paddedOverlay.style.margin = styles.cueBackgroundMargin || DEFAULT_CUE_BACKGROUND_PADDING;
overlay.appendChild(paddedOverlay);

// Determine if we need to compute the display states of the cues. This could
Expand All @@ -971,11 +979,21 @@ WebVTT.processCues = function(window, cues, overlay) {

var boxPositions = [],
containerBox = BoxPosition.getSimpleBoxPosition(paddedOverlay),
fontSize = Math.round(containerBox.height * FONT_SIZE_PERCENT * 100) / 100;
fontSize = Math.round(containerBox.height * ((styles.fontSizePercent || 100.0) / 100.0) * DEFAULT_FONT_SIZE_PERCENT) / 100;
var styleOptions = {
font: fontSize + "px " + FONT_STYLE
color: styles.color || DEFAULT_FOREGROUND_COLOR,
backgroundColor: styles.backgroundColor || DEFAULT_BACKGROUND_COLOR,
windowColor: styles.windowColor || DEFAULT_WINDOW_COLOR,
font: fontSize + "px " + (styles.fontStyle || DEFAULT_FONT_STYLE)
};

if (styles.fontVariant) {
styleOptions.fontVariant = styles.fontVariant;
}
if (styles.textShadow) {
styleOptions.textShadow = styles.textShadow;
}

(function() {
var styleBox, cue;

Expand Down