Skip to content

Commit

Permalink
Putting \r tags before others (#15)
Browse files Browse the repository at this point in the history
Putting \r tags before others

This fixes the case when \r tag at the end cancels effect of other tags
  • Loading branch information
notorca authored Sep 12, 2023
1 parent 223816b commit ce3d6b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/decompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function decompileText(dia, style) {
.filter((slice) => slice.fragments.length)
.map((slice, idx) => {
const sliceCopy = JSON.parse(JSON.stringify(slice));
const { tag } = sliceCopy.fragments[0];
const tag = {};
if (idx) {
tag.r = slice.style === dia.style ? '' : slice.style;
} else {
Expand All @@ -87,6 +87,8 @@ export function decompileText(dia, style) {
}
});
}
// make sure additional tags are first
sliceCopy.fragments[0].tag = Object.assign(tag, sliceCopy.fragments[0].tag);
return sliceCopy;
})
.map(decompileSlice)
Expand Down
24 changes: 23 additions & 1 deletion test/decompiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { decompile, decompileDrawing, decompileTag } from '../src/decompiler.js';
import { decompile, decompileDrawing, decompileTag, decompileText } from '../src/decompiler.js';
import { compiled, decompiled, compiled2, decompiled2 } from './fixtures/decompiler.js';

describe('ASS decompiler', () => {
Expand Down Expand Up @@ -127,4 +127,26 @@ describe('ASS decompiler', () => {
})).to.deep.equal('\\t(1,2,3,\\clip(11,21,12,22))\\t(4,5,6,\\b1\\fr30)');
});
});
describe('text decompiler', () => {
it('should put \\r to the beginning of tags', () => {
expect(decompileText({
alignment: 1,
slices: [{
style: 'Default',
fragments: [{
text: 'Hello',
tag: { t: [{ t1: 0, t2: 1000, accel: 1, tag: { c1: 'FF' } }] },
}],
}, {
style: 'Nondefault',
fragments: [{
text: 'World',
tag: { t: [{ t1: 1000, t2: 2000, accel: 1, tag: { c1: 'FFFF' } }] },
}],
}],
}, {
Alignment: 1,
})).to.equal('{\\t(0,1000,1,\\1c&HFF&)}Hello{\\rNondefault\\t(1000,2000,1,\\1c&HFFFF&)}World');
});
});
});

0 comments on commit ce3d6b2

Please sign in to comment.