Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly map region height/width when applying anchors #7105

Merged
merged 1 commit into from
Jul 26, 2024
Merged
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
27 changes: 15 additions & 12 deletions lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -481,32 +481,35 @@ 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
let top = region.viewportAnchorY / 75 * 100;
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 &&
Expand Down
Loading