diff --git a/src/nflxmultisubs.js b/src/nflxmultisubs.js index c616755..0486b1f 100644 --- a/src/nflxmultisubs.js +++ b/src/nflxmultisubs.js @@ -419,6 +419,116 @@ const buildSecondarySubtitleElement = (options) => { }; +// ----------------------------------------------------------------------------- + + +class PrimaryImageTransformer { + constructor() { + } + + transform(svgElem, controlsActive, forceRender) { + let unscaledImgs = svgElem.querySelectorAll('image:not(.nflxmultisubs-scaled)'); + if (unscaledImgs.length > 0) { + const viewBox = svgElem.getAttributeNS(null, 'viewBox'); + const [ extentWidth, extentHeight ] = viewBox.split(' ').slice(-2).map(n => parseInt(n)); + + // TODO: if there's no secondary subtitle, center the primary on baseline + const options = gRenderOptions; + const centerLine = extentHeight * options.centerLinePos; + const topBaseline = extentHeight * options.topBaselinePos; + const btmBaseline = extentHeight * options.btmBaselinePos; + const scale = options.primaryImageScale; + const opacity = options.primaryImageOpacity; + + [].forEach.call(unscaledImgs, img => { + img.classList.add('nflxmultisubs-scaled'); + const left = parseInt(img.getAttributeNS(null, 'x')); + const top = parseInt(img.getAttributeNS(null, 'y')); + const width = parseInt(img.getAttributeNS(null, 'width')); + const height = parseInt(img.getAttributeNS(null, 'height')); + const [ newWidth, newHeight ] = [ width * scale, height * scale ]; + const newLeft = (left + 0.5 * (width - newWidth)); + const newTop = (top <= centerLine) ? (topBaseline - newHeight) : (btmBaseline - newHeight); + img.setAttributeNS(null, 'width', newWidth); + img.setAttributeNS(null, 'height', newHeight); + img.setAttributeNS(null, 'x', newLeft); + img.setAttributeNS(null, 'y', newTop); + img.setAttributeNS(null, 'opacity', opacity); + }); + } + } +} + + +class PrimaryTextTransformer { + constructor() { + } + + transform(divElem, controlsActive) { + let parentNode = divElem.parentNode; + if (!parentNode.classList.contains('nflxmultisubs-primary-wrapper')) { + // let's use `