Skip to content

Commit

Permalink
Putting \r tags before others
Browse files Browse the repository at this point in the history
This fixes the case when \r tag at the end cancels effect of other tags
  • Loading branch information
notorca committed Aug 25, 2023
1 parent 223816b commit fbeeba6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dist/ass-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,7 @@
.filter(function (slice) { return slice.fragments.length; })
.map(function (slice, idx) {
var sliceCopy = JSON.parse(JSON.stringify(slice));
var ref = sliceCopy.fragments[0];
var tag = ref.tag;
var tag = {};
if (idx) {
tag.r = slice.style === dia.style ? '' : slice.style;
} else {
Expand All @@ -1102,6 +1101,7 @@
}
});
}
sliceCopy.fragments[0].tag = Object.assign(tag, sliceCopy.fragments[0].tag);
return sliceCopy;
})
.map(decompileSlice)
Expand Down
2 changes: 1 addition & 1 deletion dist/ass-compiler.min.js

Large diffs are not rendered by default.

3 changes: 2 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,7 @@ export function decompileText(dia, style) {
}
});
}
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 fbeeba6

Please sign in to comment.