diff --git a/lib/cea/cea708_service.js b/lib/cea/cea708_service.js index df3312658b..06211e279a 100644 --- a/lib/cea/cea708_service.js +++ b/lib/cea/cea708_service.js @@ -169,24 +169,16 @@ shaka.cea.Cea708Service = class { const firstByte = dtvccPacket.readByte().value; const secondByte = dtvccPacket.readByte().value; - const isTextBlock = (b) => { - return (b >= 0x20 && b <= 0x7f) || (b >= 0xa0 && b <= 0xff); + const toHexString = (byteArray) => { + return byteArray.map((byte) => { + return ('0' + (byte & 0xFF).toString(16)).slice(-2); + }).join(''); }; - - if (isTextBlock(firstByte) && isTextBlock(secondByte)) { - const toHexString = (byteArray) => { - return byteArray.map((byte) => { - return ('0' + (byte & 0xFF).toString(16)).slice(-2); - }).join(''); - }; - const unicode = toHexString([firstByte, secondByte]); - // Takes a unicode hex string and creates a single character. - const char = String.fromCharCode(parseInt(unicode, 16)); - this.currentWindow_.setCharacter(char); - return null; - } else { - dtvccPacket.rewind(2); - } + const unicode = toHexString([firstByte, secondByte]); + // Takes a unicode hex string and creates a single character. + const char = String.fromCharCode(parseInt(unicode, 16)); + this.currentWindow_.setCharacter(char); + return null; } const window = this.currentWindow_; diff --git a/test/cea/cea708_service_unit.js b/test/cea/cea708_service_unit.js index fbc0a768e7..fcb69278fe 100644 --- a/test/cea/cea708_service_unit.js +++ b/test/cea/cea708_service_unit.js @@ -121,8 +121,7 @@ describe('Cea708Service', () => { expect(captions).toEqual(expectedCaptions); }); - - it('decodes multibyte unstyled caption text', () => { + it('decodes multibyte unstyled caption text (Korean)', () => { const controlCodes = [ ...defineWindow, // Series of C0 control codes that add multi-byte text. @@ -150,6 +149,34 @@ describe('Cea708Service', () => { expect(captions).toEqual(expectedCaptions); }); + it('decodes multibyte unstyled caption text (Polish)', () => { + const controlCodes = [ + ...defineWindow, + // Series of C0 control codes that add multi-byte text. + 0x18, 0x01, 0x7c, 0xF3, 0x18, 0x01, 0x42, 0x18, 0x01, 0x07, // ż, ó, ł, ć + ]; + + const packet1 = createCea708PacketFromBytes(controlCodes, startTime); + const packet2 = createCea708PacketFromBytes(hideWindow, endTime); + + const text = 'żółć'; // cspell:ignore żółć + const topLevelCue = CeaUtils.createWindowedCue(startTime, endTime, '', + serviceNumber, windowId, rowCount, colCount, anchorId); + topLevelCue.nestedCues = [ + CeaUtils.createDefaultCue(startTime, endTime, /* payload= */ text), + ]; + + const expectedCaptions = [ + { + stream, + cue: topLevelCue, + }, + ]; + + const captions = getCaptionsFromPackets(service, packet1, packet2); + expect(captions).toEqual(expectedCaptions); + }); + it('setPenLocation sets the pen location correctly', () => { const controlCodes = [ ...defineWindow,