|
15 | 15 | use LibreSign\XObjectTemplate\Pdf\TemplateDocumentBuilder; |
16 | 16 | use PHPUnit\Framework\Attributes\DataProvider; |
17 | 17 | use PHPUnit\Framework\TestCase; |
| 18 | +use ReflectionMethod; |
18 | 19 |
|
19 | 20 | final class TemplateDocumentBuilderTest extends TestCase |
20 | 21 | { |
@@ -483,6 +484,88 @@ public function testBuildContentStreamRendersFillOnlyStrokeOnlyAndEmptyDecoratio |
483 | 484 | $this->assertStringNotContainsString(' RG', $emptyStream); |
484 | 485 | } |
485 | 486 |
|
| 487 | + public function testBuildDecorationCommandRequiresStrokeColorAndPositiveStrokeWidth(): void |
| 488 | + { |
| 489 | + $builder = new TemplateDocumentBuilder(); |
| 490 | + $method = new ReflectionMethod($builder, 'buildDecorationCommand'); |
| 491 | + |
| 492 | + self::assertSame( |
| 493 | + 'q\nQ', |
| 494 | + $method->invoke( |
| 495 | + $builder, |
| 496 | + new LayoutDecoration(x: 1.0, y: 2.0, width: 5.0, height: 6.0, strokeWidth: 1.5), |
| 497 | + ), |
| 498 | + ); |
| 499 | + self::assertSame( |
| 500 | + 'q\nQ', |
| 501 | + $method->invoke( |
| 502 | + $builder, |
| 503 | + new LayoutDecoration(x: 1.0, y: 2.0, width: 5.0, height: 6.0, strokeColor: '', strokeWidth: 1.5), |
| 504 | + ), |
| 505 | + ); |
| 506 | + self::assertSame( |
| 507 | + 'q\nQ', |
| 508 | + $method->invoke($builder, new LayoutDecoration( |
| 509 | + x: 1.0, |
| 510 | + y: 2.0, |
| 511 | + width: 5.0, |
| 512 | + height: 6.0, |
| 513 | + strokeColor: '#040506', |
| 514 | + strokeWidth: 0.0, |
| 515 | + )), |
| 516 | + ); |
| 517 | + } |
| 518 | + |
| 519 | + public function testBuildDecorationPathClampsRadiusByWidthHalfOnNarrowDecorations(): void |
| 520 | + { |
| 521 | + $builder = new TemplateDocumentBuilder(); |
| 522 | + $method = new ReflectionMethod($builder, 'buildDecorationPath'); |
| 523 | + |
| 524 | + self::assertSame( |
| 525 | + implode("\n", [ |
| 526 | + '4.000000 0.000000 m', |
| 527 | + '4.000000 0.000000 l', |
| 528 | + '6.209139 0.000000 8.000000 1.790861 8.000000 4.000000 c', |
| 529 | + '8.000000 16.000000 l', |
| 530 | + '8.000000 18.209139 6.209139 20.000000 4.000000 20.000000 c', |
| 531 | + '4.000000 20.000000 l', |
| 532 | + '1.790861 20.000000 0.000000 18.209139 0.000000 16.000000 c', |
| 533 | + '0.000000 4.000000 l', |
| 534 | + '0.000000 1.790861 1.790861 0.000000 4.000000 0.000000 c', |
| 535 | + 'h', |
| 536 | + ]), |
| 537 | + $method->invoke( |
| 538 | + $builder, |
| 539 | + new LayoutDecoration(x: 0.0, y: 0.0, width: 8.0, height: 20.0, borderRadius: 10.0), |
| 540 | + ), |
| 541 | + ); |
| 542 | + } |
| 543 | + |
| 544 | + public function testBuildDecorationPathClampsRadiusByHeightHalfOnShortDecorations(): void |
| 545 | + { |
| 546 | + $builder = new TemplateDocumentBuilder(); |
| 547 | + $method = new ReflectionMethod($builder, 'buildDecorationPath'); |
| 548 | + |
| 549 | + self::assertSame( |
| 550 | + implode("\n", [ |
| 551 | + '4.000000 0.000000 m', |
| 552 | + '16.000000 0.000000 l', |
| 553 | + '18.209139 0.000000 20.000000 1.790861 20.000000 4.000000 c', |
| 554 | + '20.000000 4.000000 l', |
| 555 | + '20.000000 6.209139 18.209139 8.000000 16.000000 8.000000 c', |
| 556 | + '4.000000 8.000000 l', |
| 557 | + '1.790861 8.000000 0.000000 6.209139 0.000000 4.000000 c', |
| 558 | + '0.000000 4.000000 l', |
| 559 | + '0.000000 1.790861 1.790861 0.000000 4.000000 0.000000 c', |
| 560 | + 'h', |
| 561 | + ]), |
| 562 | + $method->invoke( |
| 563 | + $builder, |
| 564 | + new LayoutDecoration(x: 0.0, y: 0.0, width: 20.0, height: 8.0, borderRadius: 10.0), |
| 565 | + ), |
| 566 | + ); |
| 567 | + } |
| 568 | + |
486 | 569 | public function testBuildResourcesExposesImageDictionaryAndCustomFontsFromDerivedBuilder(): void |
487 | 570 | { |
488 | 571 | $builder = (new TemplateDocumentBuilder())->withFontResources([ |
|
0 commit comments