Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.62% |
11 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SoundAction | |
84.62% |
11 / 13 |
|
66.67% |
2 / 3 |
7.18 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getActionType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
81.82% |
9 / 11 |
|
0.00% |
0 / 1 |
5.15 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Action; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfBoolean; |
| 8 | use Phpdftk\Pdf\Core\PdfNumber; |
| 9 | use Phpdftk\Pdf\Core\PdfReference; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | use Phpdftk\Pdf\Core\DeprecatedPdfFeature; |
| 13 | |
| 14 | /** |
| 15 | * Sound action (/S /Sound) — ISO 32000-2 §12.6.4.8. |
| 16 | * Plays a sound stream. |
| 17 | */ |
| 18 | #[RequiresPdfVersion(PdfVersion::V1_5)] |
| 19 | #[DeprecatedPdfFeature(since: '2.0', replacement: 'RenditionAction', removedIn: '2.0')] |
| 20 | class SoundAction extends Action |
| 21 | { |
| 22 | public PdfReference $sound; // /Sound - required, stream |
| 23 | public ?float $volume = null; // /Volume [-1.0 .. 1.0] |
| 24 | public ?bool $synchronous = null; // /Synchronous |
| 25 | public ?bool $repeat = null; // /Repeat |
| 26 | public ?bool $mix = null; // /Mix |
| 27 | |
| 28 | public function __construct(PdfReference $sound) |
| 29 | { |
| 30 | $this->sound = $sound; |
| 31 | } |
| 32 | |
| 33 | public function getActionType(): string |
| 34 | { |
| 35 | return 'Sound'; |
| 36 | } |
| 37 | |
| 38 | public function toPdf(): string |
| 39 | { |
| 40 | $dict = $this->baseDictionary(); |
| 41 | $dict->set('Sound', $this->sound); |
| 42 | if ($this->volume !== null) { |
| 43 | $dict->set('Volume', new PdfNumber($this->volume)); |
| 44 | } |
| 45 | if ($this->synchronous !== null) { |
| 46 | $dict->set('Synchronous', new PdfBoolean($this->synchronous)); |
| 47 | } |
| 48 | if ($this->repeat !== null) { |
| 49 | $dict->set('Repeat', new PdfBoolean($this->repeat)); |
| 50 | } |
| 51 | if ($this->mix !== null) { |
| 52 | $dict->set('Mix', new PdfBoolean($this->mix)); |
| 53 | } |
| 54 | return $dict->toPdf(); |
| 55 | } |
| 56 | } |