diff --git a/php/src/ProFileGenerator.php b/php/src/ProFileGenerator.php index a682931..a0b52f5 100644 --- a/php/src/ProFileGenerator.php +++ b/php/src/ProFileGenerator.php @@ -161,9 +161,13 @@ final class ProFileGenerator { $elements = []; if (isset($slideData['text'])) { - $elements[] = self::buildSlideElement('Orginal', (string) $slideData['text']); - if (isset($slideData['translation']) && $slideData['translation'] !== null) { - $elements[] = self::buildSlideElement('Deutsch', (string) $slideData['translation']); + $hasTranslation = isset($slideData['translation']) && $slideData['translation'] !== null; + + if ($hasTranslation) { + $elements[] = self::buildSlideElement('Orginal', (string) $slideData['text'], self::buildOriginalBounds()); + $elements[] = self::buildSlideElement('Deutsch', (string) $slideData['translation'], self::buildTranslationBounds()); + } else { + $elements[] = self::buildSlideElement('Orginal', (string) $slideData['text']); } } @@ -263,12 +267,12 @@ final class ProFileGenerator return $action; } - private static function buildSlideElement(string $name, string $text): SlideElement + private static function buildSlideElement(string $name, string $text, ?Rect $bounds = null): SlideElement { $graphicsElement = new GraphicsElement(); $graphicsElement->setUuid(self::newUuid()); $graphicsElement->setName($name); - $graphicsElement->setBounds(self::buildBounds()); + $graphicsElement->setBounds($bounds ?? self::buildBounds()); $graphicsElement->setOpacity(1.0); $graphicsElement->setPath(self::buildPath()); $graphicsElement->setFill(self::buildFill()); @@ -306,6 +310,40 @@ final class ProFileGenerator return $rect; } + private static function buildOriginalBounds(): Rect + { + $origin = new Point(); + $origin->setX(150); + $origin->setY(99.543); + + $size = new Size(); + $size->setWidth(1620); + $size->setHeight(182.946); + + $rect = new Rect(); + $rect->setOrigin($origin); + $rect->setSize($size); + + return $rect; + } + + private static function buildTranslationBounds(): Rect + { + $origin = new Point(); + $origin->setX(150); + $origin->setY(303.166); + + $size = new Size(); + $size->setWidth(1620); + $size->setHeight(113.889); + + $rect = new Rect(); + $rect->setOrigin($origin); + $rect->setSize($size); + + return $rect; + } + private static function buildPath(): Path { $path = new Path(); diff --git a/php/tests/ProFileGeneratorTest.php b/php/tests/ProFileGeneratorTest.php index 27be41f..0ad15a3 100644 --- a/php/tests/ProFileGeneratorTest.php +++ b/php/tests/ProFileGeneratorTest.php @@ -541,4 +541,82 @@ class ProFileGeneratorTest extends TestCase $this->assertNotNull($selectedArrangement); $this->assertSame('custom', $selectedArrangement->getName()); } + + #[Test] + public function testTranslatedSlideHasCorrectDualBounds(): void + { + $song = ProFileGenerator::generate( + 'TranslateTest', + [ + [ + 'name' => 'V1', + 'color' => [0, 0, 0, 1], + 'slides' => [ + ['text' => 'Amazing Grace', 'translation' => 'Erstaunliche Gnade'], + ], + ], + ], + [ + ['name' => 'normal', 'groupNames' => ['V1']], + ], + ); + + $filePath = $this->tmpDir . '/translate-test.pro'; + ProFileWriter::write($song, $filePath); + $readSong = ProFileReader::read($filePath); + $slides = $readSong->getSlides(); + $elements = $slides[0]->getAllElements(); + + $this->assertCount(2, $elements); + $this->assertSame('Orginal', $elements[0]->getName()); + $this->assertSame('Deutsch', $elements[1]->getName()); + + $bounds0 = $elements[0]->getGraphicsElement()->getBounds(); + $bounds1 = $elements[1]->getGraphicsElement()->getBounds(); + + // Check heights differ and match expected values + $this->assertEqualsWithDelta(182.946, $bounds0->getSize()->getHeight(), 0.01); + $this->assertEqualsWithDelta(113.889, $bounds1->getSize()->getHeight(), 0.01); + + // Check Y positions + $this->assertEqualsWithDelta(99.543, $bounds0->getOrigin()->getY(), 0.01); + $this->assertEqualsWithDelta(303.166, $bounds1->getOrigin()->getY(), 0.01); + } + + #[Test] + public function testNonTranslatedSlideHasSingleFullBounds(): void + { + $song = ProFileGenerator::generate( + 'NoTranslateTest', + [ + [ + 'name' => 'V1', + 'color' => [0, 0, 0, 1], + 'slides' => [ + ['text' => 'Amazing Grace'], + ], + ], + ], + [ + ['name' => 'normal', 'groupNames' => ['V1']], + ], + ); + + $filePath = $this->tmpDir . '/no-translate-test.pro'; + ProFileWriter::write($song, $filePath); + $readSong = ProFileReader::read($filePath); + $slides = $readSong->getSlides(); + $elements = $slides[0]->getAllElements(); + + $this->assertCount(1, $elements); + $this->assertSame('Orginal', $elements[0]->getName()); + + $bounds = $elements[0]->getGraphicsElement()->getBounds(); + + // Check full-size bounds + $this->assertEqualsWithDelta(880, $bounds->getSize()->getHeight(), 0.01); + $this->assertEqualsWithDelta(1620, $bounds->getSize()->getWidth(), 0.01); + $this->assertEqualsWithDelta(100, $bounds->getOrigin()->getY(), 0.01); + $this->assertEqualsWithDelta(150, $bounds->getOrigin()->getX(), 0.01); + } }