Skip to content

Commit

Permalink
Add more character support
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Feb 13, 2024
1 parent 7b7725f commit 966ad1e
Showing 2 changed files with 33 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/Code/Converters/SccConverter.php
Original file line number Diff line number Diff line change
@@ -235,12 +235,12 @@ protected static function textToSccText($lines)
'94d0', // 2th from the bottom line
'9470', // bottom line
];
$line_output = '';
$codes = '';
foreach ($lines as $k => $line) {
$line_output .= ' ' . $positions[4 - $count + $k]; // aligns text to the bottom
$line_output .= ' ' . self::lineToText($line);
$codes .= ' ' . $positions[4 - $count + $k]; // aligns text to the bottom
$codes .= ' ' . self::lineToCodes($line);
}
return trim($line_output);
return trim($codes);
}

// makes max 4 lines with up to 32 characters each
@@ -273,28 +273,28 @@ public static function splitLongLines($lines)
return $new_lines;
}

protected static function lineToText($line)
protected static function lineToCodes($line)
{
$reversed_characters = array_flip(self::$characters);
// $reversed_special = array_flip(self::$special_chars);
// $reversed_extended = array_flip(self::$extended_chars);
$reversed_special = array_flip(self::$special_chars);
$reversed_extended = array_flip(self::$extended_chars);
$codes = '';
$length = mb_strlen($line, 'UTF-8');
for ($i = 0; $i < $length; $i++) {
$character = mb_substr($line, $i, 1, 'UTF-8');
if (isset($reversed_characters[$character])) {
$codes .= $reversed_characters[$character];

// } elseif (isset($reversed_special[$character])) {
// if (strlen($codes) % 4 === 2) {
// $codes .= '80'; // fill
// }
// $codes .= $reversed_special[$character];
// } elseif (isset($reversed_extended[$character])) {
// if (strlen($codes) % 4 === 2) {
// $codes .= '80'; // fill
// }
// $codes .= $reversed_extended[$character];
} elseif (isset($reversed_special[$character])) {
if (strlen($codes) % 4 === 2) {
$codes .= '80'; // fill
}
$codes .= $reversed_special[$character];
} elseif (isset($reversed_extended[$character])) {
if (strlen($codes) % 4 === 2) {
$codes .= '80'; // fill
}
$codes .= $reversed_extended[$character];
} else {
$codes .= $reversed_characters['#']; // no symbol
}
16 changes: 16 additions & 0 deletions tests/formats/SccTest.php
Original file line number Diff line number Diff line change
@@ -67,6 +67,22 @@ public function testFromSccMoreCharacters()
$this->assertInternalFormatsEqual($expected, $actual, 1000); // 1000 - don't check timestamps
}

public function testMoreCharactersToCss()
{
$expected = "Scenarist_SCC V1.0
00:00:00;00\t94ae 9420 94d0 91b0 9470 9220 942f
00:00:10;00\t942c
";

$actual = (new Subtitles())
->add(0, 10, ['®', 'Á', '', ''])
->content('scc');
$this->assertEquals($expected, $actual);
}

public function testParsesUppercaseLetters()
{
$string = "Scenarist_SCC V1.0

0 comments on commit 966ad1e

Please sign in to comment.