diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index ed78baad73..64402ee0d2 100644 --- a/lib/text/ui_text_displayer.js +++ b/lib/text/ui_text_displayer.js @@ -471,8 +471,8 @@ shaka.text.UITextDisplayer = class { const linesUnit = shaka.text.CueRegion.units.LINES; const percentageUnit = shaka.text.CueRegion.units.PERCENTAGE; const pixelUnit = shaka.text.CueRegion.units.PX; - const heightUnit = region.heightUnits == percentageUnit ? '%' : 'px'; - const widthUnit = region.widthUnits == percentageUnit ? '%' : 'px'; + let heightUnit = region.heightUnits == percentageUnit ? '%' : 'px'; + let widthUnit = region.widthUnits == percentageUnit ? '%' : 'px'; const viewportAnchorUnit = region.viewportAnchorUnits == percentageUnit ? '%' : 'px'; @@ -481,16 +481,19 @@ shaka.text.UITextDisplayer = class { regionElement.style.position = 'absolute'; + let regionHeight = region.height; + let regionWidth = region.width; + if (region.heightUnits === linesUnit) { - regionElement.style.height = region.height * lineHeightMultiple + '%'; - } else { - regionElement.style.height = region.height + heightUnit; + regionHeight = region.height * lineHeightMultiple; + heightUnit = '%'; } if (region.widthUnits === linesUnit) { - regionElement.style.width = region.width * lineWidthMultiple + '%'; - } else { - regionElement.style.width = region.width + widthUnit; + regionWidth = region.width * lineWidthMultiple; + widthUnit = '%'; } + regionElement.style.height = regionHeight + heightUnit; + regionElement.style.width = regionWidth + widthUnit; if (region.viewportAnchorUnits === linesUnit) { // from https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/608toVTT.html#positioning-in-cea-708 @@ -498,15 +501,15 @@ shaka.text.UITextDisplayer = class { const windowWidth = this.aspectRatio_ === 4/3 ? 160 : 210; let left = region.viewportAnchorX / windowWidth * 100; // adjust top and left values based on the region anchor and window size - top -= region.regionAnchorY * region.height * lineHeightMultiple / 100; - left -= region.regionAnchorX * region.width * lineWidthMultiple / 100; + top -= region.regionAnchorY * regionHeight / 100; + left -= region.regionAnchorX * regionWidth / 100; regionElement.style.top = top + '%'; regionElement.style.left = left + '%'; } else { regionElement.style.top = region.viewportAnchorY - - region.regionAnchorY * region.height / 100 + viewportAnchorUnit; + region.regionAnchorY * regionHeight / 100 + viewportAnchorUnit; regionElement.style.left = region.viewportAnchorX - - region.regionAnchorX * region.width / 100 + viewportAnchorUnit; + region.regionAnchorX * regionWidth / 100 + viewportAnchorUnit; } if (region.heightUnits !== pixelUnit && region.widthUnits !== pixelUnit &&