• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Seretos / tcpdf-markdown / 17508958800

06 Sep 2025 02:47AM UTC coverage: 67.411% (-25.7%) from 93.103%
17508958800

push

github

Seretos
add first tcpdf implementations

1 of 211 new or added lines in 7 files covered. (0.47%)

513 of 761 relevant lines covered (67.41%)

21.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Tcpdf/TcpdfStyle.php
1
<?php
2
declare(strict_types=1);
3
/**
4
 * author:  aappen
5
 * project: tcpdf-markdown
6
 */
7

8
namespace seretos\TCPDFMarkdown\Tcpdf;
9

10
use Exception;
11

12
class TcpdfStyle
13
{
14
    private ?array $backgroundColor = null;
15
    private ?array $foregroundColor = null;
16
    private bool $trimLines = false;
17
    private float $marginLeft = .0;
18
    private float $marginRight = .0;
19
    private float $marginBottom = .0;
20
    private float $marginTop = .0;
21
    private bool $strikethrough = false;
22
    private bool $unserline = false;
23
    private string $link = '';
24

25
    public function __construct(
26
        private readonly string $family = 'helvetica',
27
        private float $size = 9,
28
        private bool $bold = false,
29
        private bool $italic = false)
30
    {
NEW
31
    }
×
32

33
    public function setSize(float $size = 9): static {
NEW
34
        $this->size = $size;
×
NEW
35
        return $this;
×
36
    }
37

38
    public function setMargin(float $left = .0, float $right = .0, float $top = .0, float $bottom = .0): static {
NEW
39
        $this->marginLeft = $left;
×
NEW
40
        $this->marginRight = $right;
×
NEW
41
        $this->marginTop = $top;
×
NEW
42
        $this->marginBottom = $bottom;
×
NEW
43
        return $this;
×
44
    }
45

46
    public function getMarginLeft(): float {
NEW
47
        return $this->marginLeft;
×
48
    }
49

50
    public function getMarginRight(): float {
NEW
51
        return $this->marginRight;
×
52
    }
53

54
    public function getMarginTop(): float {
NEW
55
        return $this->marginTop;
×
56
    }
57

58
    public function getMarginBottom(): float {
NEW
59
        return $this->marginBottom;
×
60
    }
61

62
    public function setTrimLines(bool $trim = true): static {
NEW
63
        $this->trimLines = $trim;
×
NEW
64
        return $this;
×
65
    }
66

67
    public function isTrimLines(): bool {
NEW
68
        return $this->trimLines;
×
69
    }
70

71
    public function getFamily(): string {
NEW
72
        return $this->family;
×
73
    }
74

75
    public function getSize(): float {
NEW
76
        return $this->size;
×
77
    }
78

79
    public function getFontStyle(): string {
NEW
80
        $style = '';
×
NEW
81
        if($this->bold)
×
NEW
82
            $style .= 'B';
×
NEW
83
        if($this->italic)
×
NEW
84
            $style .= 'I';
×
NEW
85
        if($this->strikethrough)
×
NEW
86
            $style .= 'D';
×
NEW
87
        if($this->unserline)
×
NEW
88
            $style .= 'U';
×
NEW
89
        return $style;
×
90
    }
91

92
    public function setBold(bool $bold = true): static {
NEW
93
        $this->bold = $bold;
×
NEW
94
        return $this;
×
95
    }
96

97
    public function setItalic(bool $italic = true): static {
NEW
98
        $this->italic = $italic;
×
NEW
99
        return $this;
×
100
    }
101

102
    public function setUnderline(bool $underline = true): static {
NEW
103
        $this->unserline = $underline;
×
NEW
104
        return $this;
×
105
    }
106

107
    public function getBackgroundColor(): ?array {
NEW
108
        return $this->backgroundColor;
×
109
    }
110

111
    public function getForegroundColor(): ?array {
NEW
112
        return $this->foregroundColor;
×
113
    }
114

115
    public function getRectangleStyle(): string {
NEW
116
        $style = '';
×
NEW
117
        if($this->backgroundColor !== null)
×
NEW
118
            $style .= 'F';
×
NEW
119
        return $style;
×
120
    }
121

122
    public function getRectangleBorderStyle(): array {
NEW
123
        return [];
×
124
        //return ['all' => ['width' => 1,'color' => $this->hex2rgb('#000000'),'cap' => 'butt', 'join' => 'miter', 'dash' => 0]];
125
    }
126

127
    /**
128
     * @throws Exception
129
     */
130
    public function setBackgroundColor(?string $color): static {
NEW
131
        if($color !== null)
×
NEW
132
            $this->backgroundColor = $this->hex2rgb($color);
×
133
        else
NEW
134
            $this->backgroundColor = null;
×
NEW
135
        return $this;
×
136
    }
137

138
    public function setForegroundColor(?string $color): static {
NEW
139
        if($color !== null)
×
NEW
140
            $this->foregroundColor = $this->hex2rgb($color);
×
141
        else
NEW
142
            $this->foregroundColor = null;
×
NEW
143
        return $this;
×
144
    }
145

146
    /**
147
     * @throws Exception
148
     */
149
    private function hex2rgb($hex): array
150
    {
NEW
151
        $hex = ltrim($hex, '#');
×
152

NEW
153
        if (strlen($hex) == 3) {
×
NEW
154
            $r = hexdec(str_repeat($hex[0], 2));
×
NEW
155
            $g = hexdec(str_repeat($hex[1], 2));
×
NEW
156
            $b = hexdec(str_repeat($hex[2], 2));
×
NEW
157
        } else if (strlen($hex) == 6) {
×
NEW
158
            $r = hexdec(substr($hex, 0, 2));
×
NEW
159
            $g = hexdec(substr($hex, 2, 2));
×
NEW
160
            $b = hexdec(substr($hex, 4, 2));
×
161
        } else {
NEW
162
            throw new Exception("invalid color: $hex");
×
163
        }
164

NEW
165
        return [$r, $g, $b];
×
166
    }
167

168
    public function setStrikethrough(bool $strikethrough = true): static
169
    {
NEW
170
        $this->strikethrough = $strikethrough;
×
NEW
171
        return $this;
×
172
    }
173

174
    public function setLink(string $link = ''): static {
NEW
175
        $this->link = $link;
×
NEW
176
        return $this;
×
177
    }
178

179
    public function getLink(): string {
NEW
180
        return $this->link;
×
181
    }
182
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc