-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this 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
.
src/main/js/html.js
Outdated
@@ -114,6 +129,20 @@ | |||
rootcontainer.style.right = 0; | |||
rootcontainer.style.zIndex = 0; | |||
|
|||
if (options) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 9116902.
src/main/js/html.js
Outdated
@@ -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 || {} |
There was a problem hiding this comment.
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:
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]); | |
} | |
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
options: options || {} | |
options: Object.assign({}, options) || {}, | |
}; |
There was a problem hiding this comment.
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
:-(
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK done in 13dc9a5
Should this not be merged into the branch smp-master and not master? |
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... |
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? |
Is this PR ready to merge? |
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. |
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 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. |
Could we update the BBC-CHANGELOG in this PR? |
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.
af659e3
to
2864dbd
Compare
This pull request does the following:
imscHtml.render()
This allows the following presentation characteristics to be modified by multiplying by a scale factor:
It also allows the following to be overridden
Finally it allows colour values to be mapped to different values for each of:
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).