Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

libjass.deserialize dialogue style changes not work #107

Open
jokerrider007 opened this issue May 30, 2018 · 2 comments
Open

libjass.deserialize dialogue style changes not work #107

jokerrider007 opened this issue May 30, 2018 · 2 comments

Comments

@jokerrider007
Copy link

jokerrider007 commented May 30, 2018

Previously, I'm ask the way to generate ASS object from JSON object. I have some problem. The problem is when i try to change styles Map object generate from libjass.deserialize. Then call render.resize() style property in dialogue don't change.

var result = libjass.deserialize(JSON.stringify(data));
var renderer = new libjass.renderers.DefaultRenderer(video, result);
renderer.resize(width, height, left, top) ;

var style = renderer.ass.styles.get("Default");
style._fontSize = 80;
renderer.ass.styles.set("Default",style);
renderer.resize(width, height, left, top) ;
cosoole.log(renderer.ass.styles.get("Default")._fontSize ); // fontSize = 80
console.log(renderer.ass.dialogue[0].style._fontSize ); // fontSize = 50

I use libjass.deserialize to create ASS object and render. Then i try to change property in 'Default' styles. when i change _fontSize and call render.resize(). Dialogue use 'Default' style _fontSize not change.

So I tested with libjass.ASS.fromUrl. it's work, when i I change styles Map and call render.resize() dialogue style property has change. I'm very confused. how can i change dialogue style from libjass.deserialize object render?

@jokerrider007 jokerrider007 changed the title Changes style map from deserialize object render not work Changes style from styles Map object not work May 30, 2018
@jokerrider007 jokerrider007 changed the title Changes style from styles Map object not work Dialogues style changes not work May 30, 2018
@jokerrider007 jokerrider007 changed the title Dialogues style changes not work libjass.deserialize dialogues style changes not work May 30, 2018
@jokerrider007 jokerrider007 changed the title libjass.deserialize dialogues style changes not work libjass.deserialize dialogue style changes not work May 30, 2018
@Arnavion
Copy link
Owner

Arnavion commented May 30, 2018

Yes, every Dialogue serializes its own copy of a Style object, so the deserialized Dialogue has an independent Style object unrelated to the one deserialized into ASS.styles.

One way to fix it is to to change serialize() to use an instance toJSON() if it exists (similar to how deserialize uses a static fromJSON() if it exists), and Dialogue should implement toJSON to only serialize the style name and fromJSON to look up the style based on the name.

But that won't actually work, since the ass object doesn't exist when the Dialogue objects are being deserialized, so there's nothing to look up the style from.


The immediate solution is to do something like:

var result = libjass.deserialize(JSON.stringify(data));
for (const dialogue of result.dialogues) {
    dialogue._style = result.styles.get(dialogue.style.name);
}

var renderer = new libjass.renderers.DefaultRenderer(video, result);
/* ... */

to reset the Dialogue.style object to the same one that's in the ASS.styles map.


Also, in

var style = renderer.ass.styles.get("Default");
style._fontSize = 80;
renderer.ass.styles.set("Default",style);

you don't need the third line. Style is an object so mutating the value you get from Map.get() will mutate the value that's in the Map.

@Arnavion
Copy link
Owner

I'll keep this open since it's a bug. You can unsubscribe from it if you don't want notifications.

@Arnavion Arnavion reopened this May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants