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(FEC-10844): advanced caption settings custom caption is always marked even when choose sample #525

Merged
merged 7 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 34 additions & 18 deletions src/track/text-style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @flow
import * as Utils from '../utils/util';

/**
* We use this number to calculate the scale of the text. so it will be : 1 + 0.25 * FontSizes.value
* So, if the user selects 400% the scale would be: 1 + 0.25 * 4 = 2. so the font size should be multiplied by 2.
Expand Down Expand Up @@ -138,17 +140,31 @@ class TextStyle {
return 'rgba(' + color.concat(opacity).join(',') + ')';
}

static get defaultValues(): PKTextStyleObject {
Yuvalke marked this conversation as resolved.
Show resolved Hide resolved
return {
fontEdge: TextStyle.EdgeStyles.NONE,
fontSize: '100%',
fontScale: 1,
fontColor: TextStyle.StandardColors.WHITE,
fontOpacity: TextStyle.StandardOpacities.OPAQUE,
backgroundColor: TextStyle.StandardColors.BLACK,
backgroundOpacity: TextStyle.StandardOpacities.OPAQUE,
fontFamily: TextStyle.FontFamily.SANS_SERIF
};
}

static fromJson(setting: PKTextStyleObject): TextStyle {
let clonedTextStyle = new TextStyle();
clonedTextStyle.fontEdge = setting.fontEdge || clonedTextStyle.fontEdge;
clonedTextStyle.fontSize = setting.fontSize || clonedTextStyle.fontSize;
clonedTextStyle.fontScale = setting.fontScale || clonedTextStyle.fontScale;
clonedTextStyle.fontColor = setting.fontColor || clonedTextStyle.fontColor;
clonedTextStyle.fontOpacity = setting.fontOpacity || clonedTextStyle.fontOpacity;
clonedTextStyle.backgroundColor = setting.backgroundColor || clonedTextStyle.backgroundColor;
clonedTextStyle.backgroundOpacity = setting.backgroundOpacity || clonedTextStyle.backgroundOpacity;
clonedTextStyle.fontFamily = setting.fontFamily || clonedTextStyle.fontFamily;
return clonedTextStyle;
const currentSetting = Utils.Object.mergeDeep(TextStyle.defaultValues, setting);
Yuvalke marked this conversation as resolved.
Show resolved Hide resolved
let textStyle = new TextStyle();
textStyle.fontEdge = currentSetting.fontEdge;
textStyle.fontSize = currentSetting.fontSize;
textStyle.fontScale = currentSetting.fontScale;
textStyle.fontColor = currentSetting.fontColor;
textStyle.fontOpacity = currentSetting.fontOpacity;
textStyle.backgroundColor = currentSetting.backgroundColor;
textStyle.backgroundOpacity = currentSetting.backgroundOpacity;
textStyle.fontFamily = currentSetting.fontFamily;
return textStyle;
Yuvalke marked this conversation as resolved.
Show resolved Hide resolved
}

static toJson(text: TextStyle): PKTextStyleObject {
Expand All @@ -168,41 +184,41 @@ class TextStyle {
* Font size, such as 1, 2, 3...
* @type {number}
*/
fontSize: string = '100%';
fontSize: string = TextStyle.defaultValues.fontSize;

fontScale: number = 1;
fontScale: number = TextStyle.defaultValues.fontScale;

/**
* @type {TextStyle.FontFamily}
*/
fontFamily: string = TextStyle.FontFamily.SANS_SERIF;
fontFamily: string = TextStyle.defaultValues.fontFamily;

/**
* @type {TextStyle.StandardColors}
*/
fontColor: Array<number> = TextStyle.StandardColors.WHITE;
fontColor: Array<number> = TextStyle.defaultValues.fontColor;

/**
* @type {TextStyle.StandardOpacities}
* @expose
*/
fontOpacity: number = TextStyle.StandardOpacities.OPAQUE;
fontOpacity: number = TextStyle.defaultValues.fontOpacity;

/**
* @type {TextStyle.StandardColors}
*/
backgroundColor: Array<number> = TextStyle.StandardColors.BLACK;
backgroundColor: Array<number> = TextStyle.defaultValues.backgroundColor;

/**
* @type {TextStyle.StandardOpacities}
*/
backgroundOpacity: number = TextStyle.StandardOpacities.OPAQUE;
backgroundOpacity: number = TextStyle.defaultValues.backgroundOpacity;

/**
* @type {TextStyle.EdgeStyles}
* @expose
*/
fontEdge: Array<Array<number>> = TextStyle.EdgeStyles.NONE;
fontEdge: Array<Array<number>> = TextStyle.defaultValues.fontEdge;

getTextShadow(): string {
// A given edge effect may be implemented with multiple shadows.
Expand Down
40 changes: 36 additions & 4 deletions test/src/player.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,14 +1216,46 @@ describe('Player', function () {

it('should change style setting', () => {
let textStyle = new TextStyle();
textStyle.backgroundColor = TextStyle.StandardColors.RED;
textStyle.fontColor = TextStyle.StandardColors.CYAN;
textStyle.fontEdge = TextStyle.EdgeStyles.RAISED;
textStyle.fontSize = '75%';
textStyle.fontScale = '3';
textStyle.fontColor = TextStyle.StandardColors.CYAN;
textStyle.fontOpacity = TextStyle.StandardOpacities.SEMI_LOW;
textStyle.backgroundOpacity = TextStyle.StandardOpacities.SEMI_LOW;
textStyle.fontFamily = TextStyle.FontFamily.ARIAL;
textStyle.backgroundColor = TextStyle.StandardColors.RED;
player.textStyle = textStyle;
const currentTextStyle = player.textStyle;
currentTextStyle.backgroundColor.should.deep.equal(textStyle.backgroundColor);
currentTextStyle.fontColor.should.deep.equal(textStyle.fontColor);
currentTextStyle.fontEdge.should.deep.equal(textStyle.fontEdge);
currentTextStyle.fontSize.should.equal(textStyle.fontSize);
currentTextStyle.fontScale.should.equal(textStyle.fontScale);
currentTextStyle.fontColor.should.deep.equal(textStyle.fontColor);
currentTextStyle.fontOpacity.should.equal(textStyle.fontOpacity);
currentTextStyle.backgroundOpacity.should.equal(textStyle.backgroundOpacity);
currentTextStyle.fontFamily.should.equal(textStyle.fontFamily);
currentTextStyle.backgroundColor.should.deep.equal(textStyle.backgroundColor);
});

it('should create fromJson set the correct value', () => {
const settings = {
fontEdge: TextStyle.EdgeStyles.RAISED,
fontSize: '75%',
fontScale: '3',
fontColor: TextStyle.StandardColors.CYAN,
fontOpacity: TextStyle.StandardOpacities.SEMI_LOW,
backgroundOpacity: TextStyle.StandardOpacities.SEMI_LOW,
fontFamily: TextStyle.FontFamily.ARIAL,
backgroundColor: TextStyle.StandardColors.RED
};
const textStyle = TextStyle.fromJson(settings);
textStyle.fontEdge.should.deep.equal(settings.fontEdge);
textStyle.fontSize.should.equal(settings.fontSize);
textStyle.fontScale.should.equal(settings.fontScale);
textStyle.fontColor.should.deep.equal(settings.fontColor);
textStyle.fontOpacity.should.equal(settings.fontOpacity);
textStyle.backgroundOpacity.should.equal(settings.backgroundOpacity);
textStyle.fontFamily.should.equal(settings.fontFamily);
textStyle.backgroundColor.should.deep.equal(settings.backgroundColor);
});

it('should fromJson return an object equal to explicit set object', () => {
Expand Down