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

Add customisation options #2

Merged
merged 14 commits into from
Jan 28, 2021
Merged

Add customisation options #2

merged 14 commits into from
Jan 28, 2021

Conversation

nigelmegitt
Copy link
Collaborator

@nigelmegitt nigelmegitt commented Jan 5, 2021

This pull request does the following:

  1. Adds a customisation options parameter to imscHtml.render()

This allows the following presentation characteristics to be modified by multiplying by a scale factor:

  • Size
  • Opacity of every region
  • Opacity of the background on span
  • Opacity of the text colour

It also allows the following to be overridden

  • textOutline
  • fontFamily

Finally it allows colour values to be mapped to different values for each of:

  • text color
  • span backgroundColor
  • p backgroundColor
  • div backgroundColor
  • body backgroundColor
  • region backgroundColor

It therefore implements all of the IMSC-specific adjustments listed in CTA-CEB35 (note that there are some possible adjustments omitted from that document, for example fontStyle for italic/oblique and textDecoration for underline and line-through).

Copy link

@jlks jlks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good, I just have the one bit of feedback on the mutation of options.

@@ -114,6 +129,20 @@
rootcontainer.style.right = 0;
rootcontainer.style.zIndex = 0;

if (options) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this section of code move to below the definition of options inside context (setting context.options.colorAdjust) to avoid mutating the options object?

The use case is that a library user has the same options they want to pass into the function on each call and after the first call the colorAdjust properties are mutated and can't be read by imscUtils.parseColor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9116902.

@@ -133,9 +148,24 @@
bpd: null, /* block progression direction (lr, rl, tb) */
ruby: null, /* is ruby present in a <p> */
textEmphasis: null, /* is textEmphasis present in a <p> */
rubyReserve: null /* is rubyReserve applicable to a <p> */
rubyReserve: null, /* is rubyReserve applicable to a <p> */
options: options || {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9116902 still appears to mutate the existing options. I think this should do it:

Suggested change
options: options || {}
options: {}
};
if (options) {
if (options.colorAdjust)
context.options.colorAdjust = preprocessColorMapOptions(options.colorAdjust);
var bgcColorElements = ['region', 'body', 'div', 'p', 'span'];
var propName;
for (var bgcei in bgcColorElements)
{
propName = bgcColorElements[bgcei] + backgroundColorAdjustSuffix;
if (options[propName])
context.options[propName] = preprocessColorMapOptions(options[propName]);
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh. That suggestion would trash all the other options settings that aren't colour adjustments, so that wouldn't work either. We need to work on a copy that isn't a reference. Or I could make the keys for the preprocessed colour maps a different value to the passed-in ones instead of the same value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bdd8530 should do it, but I don't like it!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've got a compromise. This will copy the initial *colorAdjust references but then overwrite them when preprocessColorMapOptions happens. It also removes the need to copy across the other properties added in bdd8530.

Suggested change
options: options || {}
options: Object.assign({}, options) || {},
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of that too @jlks but it breaks on build I think because the grunt script is set to refuse ES6-only features, which includes Object.assign :-(

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I don't get any grunt:build errors. I see Object.entries() being used inside preprocessColorMapOptions does that need to change too? I see it gets added as a polyfill in the minified distribution just the same as using Object.assign.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, okay, maybe I didn't actually try it, but just assumed it would fail. I'll make this fix (tomorrow) - it will definitely clean things up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK done in 13dc9a5

@robertbryer
Copy link
Collaborator

Should this not be merged into the branch smp-master and not master?

@robertbryer
Copy link
Collaborator

Actually, I have no idea why I set it up as smp-master and not master in the first place... maybe just go ahead and I'll change the default branch...

@nigelmegitt
Copy link
Collaborator Author

Oh yeah, I don't know either - maybe you want a special SMP branch for SMP use and everyone else can choose master or make their own special main branch?

@jlks
Copy link

jlks commented Jan 14, 2021

Is this PR ready to merge?

@nigelmegitt
Copy link
Collaborator Author

It has no "approve" reviews, so I'd argue no! I think only one would be required. I think the approach to the mutable options object should be changed though, to put the canonical values into a separate child object rather than breaking the one sent in.

@nigelmegitt
Copy link
Collaborator Author

In 13dc9a5 I attempted (again) to fix the mutating options object problem - hopefully this time it'll work?!

I also added a multiplier adjustment for tts:lineHeight, and tweaked fontFamily and fontSize to apply to p elements. This has the effect that, for our subtitle files, which specify those attributes above the span level in the TTML tree, they are specified as CSS styles on the HTML p element.

At least in my experiments this results in the line spacing being computed to the expected value from the TTML. Further detail in https://codepen.io/nigelmegitt/pen/qBaJZOv and also the related issues w3c/ttml2#1215 and sandflow#201.

@domjacks domjacks requested a review from a team January 26, 2021 16:36
@domjacks
Copy link

Could we update the BBC-CHANGELOG in this PR?

@nigelmegitt nigelmegitt changed the base branch from master to smp-master January 28, 2021 10:49
nigelmegitt and others added 13 commits January 28, 2021 11:31
Allows rendered text size to be modified by some scale value
If we want to add other config options that can be done without an API change. Also made it so that if the options are omitted as per previous API, everything still works.
* color mapping adjustment
* fontFamily override
* region opacity multipler
* text outline
Addresses review feedback
Should stop the options from mutating. There must be a better way though, this is horrible.
@domjacks domjacks changed the title Update to upstream and add customisation options Add customisation options Jan 28, 2021
@robertbryer robertbryer merged commit 9201ec9 into smp-master Jan 28, 2021
@robertbryer robertbryer deleted the nm-size-adjust branch January 28, 2021 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants