Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ButtonField
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
5.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
4.03
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Interactive\Form;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfVersion;
11use Phpdftk\Pdf\Core\RequiresPdfVersion;
12
13/**
14 * Button field (/FT /Btn) - covers push buttons, check boxes, and radio buttons.
15 */
16#[RequiresPdfVersion(PdfVersion::V1_2)]
17class ButtonField extends Field
18{
19    public ?PdfName $h = null;           // /H - highlight mode
20    public ?PdfDictionary $mk = null;    // /MK - appearance characteristics
21    public ?PdfArray $opt = null;        // /Opt
22
23    public function __construct()
24    {
25        $this->ft = new PdfName('Btn');
26    }
27
28    public function toPdf(): string
29    {
30        $dict = $this->buildFieldDictionary();
31
32        if ($this->h !== null) {
33            $dict->set('H', $this->h);
34        }
35        if ($this->mk !== null) {
36            $dict->set('MK', $this->mk);
37        }
38        if ($this->opt !== null) {
39            $dict->set('Opt', $this->opt);
40        }
41
42        return $dict->toPdf();
43    }
44}