Skip to content

Commit 0775b80

Browse files
Merge pull request #34 from YetiForceCompany/developer
0.1.40
2 parents 158b2f7 + 0f5f451 commit 0775b80

19 files changed

+109
-93
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
root = true
2+
23
[*]
4+
charset = utf-8
5+
indent_style = tab
6+
indent_size = 4
37
end_of_line = lf
48
insert_final_newline = true
59
trim_trailing_whitespace = true
10+
max_line_length = 120
11+
12+
13+
[**/*.json]
14+
charset = utf-8
15+
indent_style = space
16+
indent_size = 2
17+
end_of_line = lf
18+
trim_trailing_whitespace = true

.php_cs.dist

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
$config = \PhpCsFixer\Config::create()
44
->setRiskyAllowed(true)
55
->setIndent("\t")
6-
->setUsingCache(false)
6+
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache')
77
->setRules([
8-
'@PHP56Migration' => true,
9-
'@PHPUnit60Migration:risky' => true,
8+
'@PHP74Migration' => true,
9+
'@PHP74Migration:risky' => true,
10+
'@PHP80Migration' => true,
11+
'@PHP80Migration:risky' => true,
1012
'@PhpCsFixer' => true,
1113
'@PhpCsFixer:risky' => true,
12-
'list_syntax' => ['syntax' => 'short'],
1314
'@PSR2' => true,
15+
'list_syntax' => ['syntax' => 'short'],
1416
'align_multiline_comment' => true,
1517
'array_syntax' => ['syntax' => 'short'],
1618
'blank_line_after_namespace' => true,
@@ -27,6 +29,7 @@ $config = \PhpCsFixer\Config::create()
2729
],
2830
'explicit_string_variable' => false,
2931
'declare_equal_normalize' => true,
32+
'declare_strict_types' => false,
3033
'dir_constant' => false,
3134
'doctrine_annotation_braces' => true,
3235
'doctrine_annotation_indentation' => true,
@@ -145,13 +148,14 @@ $config = \PhpCsFixer\Config::create()
145148
'switch_case_space' => true,
146149
'ternary_operator_spaces' => true,
147150
'ternary_to_null_coalescing' => true,
148-
'trailing_comma_in_multiline_array' => false,
151+
'trailing_comma_in_multiline' => ['after_heredoc' => false, 'elements' => []],
149152
'trim_array_spaces' => true,
150153
'unary_operator_spaces' => true,
151154
'visibility_required' => [
152155
'property',
153156
'method',
154157
],
158+
'void_return' => false,
155159
'whitespace_after_comma_in_array' => true,
156160
])
157161
->setFinder(PhpCsFixer\Finder::create()

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=7.3",
20+
"php": ">=7.4",
2121
"ext-mbstring": "*",
2222
"ext-dom": "*",
2323
"ext-libxml": "*",
2424
"ext-bcmath": "*",
2525
"ext-zlib": "*",
2626
"ext-gd": "*",
2727
"ext-filter": "*",
28-
"phenx/php-font-lib": "^0.5.1",
29-
"guzzlehttp/guzzle": "^7.0",
30-
"composer/ca-bundle": "^1.1",
31-
"milon/barcode": "^8.0.0",
32-
"sabberworm/php-css-parser": "^8.3"
28+
"phenx/php-font-lib": "^0.5",
29+
"guzzlehttp/guzzle": "^7",
30+
"composer/ca-bundle": "^1",
31+
"milon/barcode": "^9",
32+
"sabberworm/php-css-parser": "^8"
3333
},
3434
"autoload": {
3535
"psr-4": {

lib/Catalog.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ public function render(): string
4242
{
4343
return implode("\n", [
4444
$this->getRawId() . ' obj',
45-
'<<',
46-
' /Type /Catalog',
47-
' /Pages ' . $this->document->getPagesObject()->getReference(),
48-
'>>',
45+
'<</Type /Catalog/Pages ' . $this->document->getPagesObject()->getReference() . '>>',
4946
'endobj',
5047
]);
5148
}

lib/Document.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ public function fixPageNumbers()
688688
*/
689689
protected function getDocumentHeader(): string
690690
{
691-
return "%PDF-1.7\n%âăĎÓ\n";
691+
return "%PDF-1.4\n%âăĎÓ\n";
692692
}
693693

694694
/**
@@ -893,11 +893,11 @@ public function render(): string
893893
$trailer = (new \YetiForcePDF\Objects\Trailer())
894894
->setDocument($this)->setRootObject($this->catalog)->setSize($objectSize);
895895
$this->buffer .= $trailer->render() . "\n";
896-
$this->buffer .= implode("\n", [
897-
'startxref',
898-
$offset,
899-
'',
900-
]);
896+
// $this->buffer .= implode("\n", [
897+
// 'startxref',
898+
// $offset,
899+
// '',
900+
// ]);
901901
$this->buffer .= $this->getDocumentFooter();
902902
$this->removeObject($trailer);
903903
return $this->buffer;

lib/Layout/TableBox.php

+30-29
Original file line numberDiff line numberDiff line change
@@ -294,36 +294,37 @@ public function setUpWidths(string $availableSpace)
294294
{
295295
foreach ($this->getChildren() as $rowGroup) {
296296
foreach ($rowGroup->getChildren() as $row) {
297-
$columns = $row->getChildren();
298-
foreach ($columns as $columnIndex => $column) {
299-
$cell = $column->getFirstChild();
300-
$cellStyle = $cell->getStyle();
301-
$columnInnerWidth = $cell->getDimensions()->getMaxWidth();
302-
$styleWidth = $column->getStyle()->getRules('width');
303-
$this->contentWidths[$columnIndex] = Math::max($this->contentWidths[$columnIndex] ?? '0', $columnInnerWidth);
304-
$minColumnWidth = $cell->getDimensions()->getMinWidth();
305-
if ($column->getColSpan() > 1) {
306-
$minColumnWidth = Math::div($minColumnWidth, (string) $column->getColSpan());
307-
}
308-
$this->minWidths[$columnIndex] = Math::max($this->minWidths[$columnIndex] ?? '0', $minColumnWidth);
309-
if ('auto' !== $styleWidth && false === strpos($styleWidth, '%')) {
297+
if ($columns = $row->getChildren()) {
298+
foreach ($columns as $columnIndex => $column) {
299+
$cell = $column->getFirstChild();
300+
$cellStyle = $cell->getStyle();
301+
$columnInnerWidth = $cell->getDimensions()->getMaxWidth();
302+
$styleWidth = $column->getStyle()->getRules('width');
303+
$this->contentWidths[$columnIndex] = Math::max($this->contentWidths[$columnIndex] ?? '0', $columnInnerWidth);
304+
$minColumnWidth = $cell->getDimensions()->getMinWidth();
310305
if ($column->getColSpan() > 1) {
311-
$styleWidth = Math::div($styleWidth, (string) $column->getColSpan());
306+
$minColumnWidth = Math::div($minColumnWidth, (string) $column->getColSpan());
312307
}
313-
$preferred = Math::max($styleWidth, $minColumnWidth);
314-
$this->minWidths[$columnIndex] = $preferred;
315-
} elseif (strpos($styleWidth, '%') > 0) {
316-
$preferred = Math::max($this->preferredWidths[$columnIndex] ?? '0', $columnInnerWidth);
317-
$this->percentages[$columnIndex] = Math::max($this->percentages[$columnIndex] ?? '0', trim($styleWidth, '%'));
318-
} else {
319-
$preferred = Math::max($this->preferredWidths[$columnIndex] ?? '0', $columnInnerWidth);
308+
$this->minWidths[$columnIndex] = Math::max($this->minWidths[$columnIndex] ?? '0', $minColumnWidth);
309+
if ('auto' !== $styleWidth && false === strpos($styleWidth, '%')) {
310+
if ($column->getColSpan() > 1) {
311+
$styleWidth = Math::div($styleWidth, (string) $column->getColSpan());
312+
}
313+
$preferred = Math::max($styleWidth, $minColumnWidth);
314+
$this->minWidths[$columnIndex] = $preferred;
315+
} elseif (strpos($styleWidth, '%') > 0) {
316+
$preferred = Math::max($this->preferredWidths[$columnIndex] ?? '0', $columnInnerWidth);
317+
$this->percentages[$columnIndex] = Math::max($this->percentages[$columnIndex] ?? '0', trim($styleWidth, '%'));
318+
} else {
319+
$preferred = Math::max($this->preferredWidths[$columnIndex] ?? '0', $columnInnerWidth);
320+
}
321+
$this->preferredWidths[$columnIndex] = $preferred;
320322
}
321-
$this->preferredWidths[$columnIndex] = $preferred;
323+
$this->borderWidth = Math::add($this->borderWidth, $cellStyle->getHorizontalBordersWidth());
324+
$this->minWidth = Math::add($this->minWidth, $this->minWidths[$columnIndex]);
325+
$this->contentWidth = Math::add($this->contentWidth, $this->contentWidths[$columnIndex]);
326+
$this->preferredWidth = Math::add($this->preferredWidth, $this->preferredWidths[$columnIndex]);
322327
}
323-
$this->borderWidth = Math::add($this->borderWidth, $cellStyle->getHorizontalBordersWidth());
324-
$this->minWidth = Math::add($this->minWidth, $this->minWidths[$columnIndex]);
325-
$this->contentWidth = Math::add($this->contentWidth, $this->contentWidths[$columnIndex]);
326-
$this->preferredWidth = Math::add($this->preferredWidth, $this->preferredWidths[$columnIndex]);
327328
}
328329
}
329330
if ('collapse' !== $this->getParent()->getStyle()->getRules('border-collapse')) {
@@ -358,9 +359,9 @@ protected function setUpSizingTypes()
358359
foreach ($this->getChildren() as $rowGroup) {
359360
foreach ($rowGroup->getChildren() as $row) {
360361
foreach ($row->getChildren() as $columnIndex => $column) {
361-
if ('percent' === $columnSizingTypes[$columnIndex]) {
362+
if (isset($columnSizingTypes[$columnIndex]) && 'percent' === $columnSizingTypes[$columnIndex]) {
362363
$this->percentColumns[$columnIndex][] = $column;
363-
} elseif ('pixel' === $columnSizingTypes[$columnIndex]) {
364+
} elseif (isset($columnSizingTypes[$columnIndex]) && 'pixel' === $columnSizingTypes[$columnIndex]) {
364365
$this->pixelColumns[$columnIndex][] = $column;
365366
} else {
366367
$this->autoColumns[$columnIndex][] = $column;
@@ -1287,7 +1288,7 @@ public function measureHeight(bool $afterPageDividing = false)
12871288
}
12881289
// column that is spanned with more than 1 row must have height that is equal to all spanned rows height
12891290
foreach ($rows as $rowIndex => $row) {
1290-
$currentRowMax = $maxRowHeights[$rowGroupIndex][$rowIndex];
1291+
$currentRowMax = $maxRowHeights[$rowGroupIndex][$rowIndex] ?? '0';
12911292
foreach ($row->getChildren() as $column) {
12921293
$rowSpan = $column->getRowSpan();
12931294
if ($rowSpan > 1) {

lib/Math.php

-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public static function add(string ...$numbers)
7171
foreach ($numbers as $number) {
7272
$result = bcadd($result, $number, static::$scale);
7373
}
74-
7574
return $result;
7675
}
7776

@@ -172,7 +171,6 @@ public static function max(string ...$numbers)
172171
foreach ($numbers as $number) {
173172
$result = 1 === bccomp($number, $result, static::$scale) ? $number : $result;
174173
}
175-
176174
return $result;
177175
}
178176

lib/Objects/Basic/DictionaryObject.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public function render(): string
114114
foreach ($this->values as $value) {
115115
$values[] = ' ' . implode(' ', $value);
116116
}
117-
$values[] = ">>\nendobj";
117+
$values[] = '>>';
118+
$values[] = 'endobj';
118119
return implode("\n", $values);
119120
}
120121
}

lib/Objects/Basic/StreamObject.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,10 @@ public function render(): string
9595
if ('FlateDecode' === $this->filter) {
9696
$stream = gzcompress($stream);
9797
}
98-
$filter = $this->filter ? ' /Filter /' . $this->filter : '';
98+
$filter = $this->filter ? '/Filter /' . $this->filter : '';
9999
return implode("\n", [
100100
$this->getRawId() . ' obj',
101-
'<<',
102-
' /Length ' . mb_strlen($stream, '8bit'),
103-
' /Lenght1 ' . $sizeBefore,
104-
$filter,
105-
'>>',
106-
'stream',
101+
'<</Length ' . mb_strlen($stream, '8bit') . '/Lenght1 ' . $sizeBefore . $filter . '>>stream',
107102
$stream,
108103
'endstream',
109104
'endobj',

lib/Objects/Font.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,7 @@ protected function loadFontData()
777777
public function render(): string
778778
{
779779
return implode("\n", [$this->getRawId() . ' obj',
780-
'<<',
781-
' /Type /Font',
782-
' /Subtype /CIDFontType2',
780+
'<</Type /Font/Subtype /CIDFontType2',
783781
' /BaseFont /' . $this->getFullName(),
784782
' /FontDescriptor ' . $this->fontDescriptor->getReference(),
785783
' /DW 500',

lib/Objects/FontEncoding.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public function render(): string
3232
{
3333
return implode("\n", [
3434
$this->getRawId() . ' obj',
35-
'<<',
36-
' /Type Encoding',
35+
'<</Type Encoding',
3736
' /BaseEncoding /' . $this->encoding,
3837
'>>',
3938
'endobj',

lib/Objects/TextStream.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ public function render(): string
150150
$stream = $this->getRawStream();
151151
return implode("\n", [
152152
$this->getRawId() . ' obj',
153-
'<<',
154-
' /Length ' . \strlen($stream),
155-
'>>',
156-
'stream',
153+
'<</Length ' . \strlen($stream) . '>>stream',
157154
$stream,
158155
'endstream',
159156
'endobj',

lib/Objects/Trailer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public function render(): string
7474
'trailer',
7575
'<<',
7676
' /Root ' . $this->root->getReference(),
77-
' /Size ' . $this->size,
7877
' /Info ' . $this->document->getMeta()->getReference(),
78+
' /Size ' . $this->size,
7979
'>>',
8080
]);
8181
}

lib/Page.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class Page extends \YetiForcePDF\Objects\Basic\DictionaryObject
487487
/**
488488
* Initialisation.
489489
*
490-
* @return $this|\YetiForcePDF\Objects\PdfObject
490+
* @return $this
491491
*/
492492
public function init()
493493
{

lib/Style/Color.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
*/
2121
class Color
2222
{
23-
/**
24-
* Color names hash values.
25-
*
26-
* @var array
27-
*/
23+
/** @var string[] Color names hash values. */
2824
protected static $colorNames = [
2925
'aliceblue' => '#f0f8ff',
3026
'antiquewhite' => '#faebd7',
@@ -176,14 +172,19 @@ class Color
176172
'yellowgreen' => '#9acd32',
177173
];
178174

175+
/** @var array Color names rgba values. */
176+
protected static $colorCustomNames = [
177+
'transparent' => [0, 0, 0, 0.1]
178+
];
179+
179180
/**
180181
* Get rgba array from color name.
181182
*
182183
* @param string $colorName
183184
*
184185
* @return string[]
185186
*/
186-
public static function fromName(string $colorName)
187+
public static function fromName(string $colorName): array
187188
{
188189
$colorName = strtolower($colorName);
189190
if (isset(static::$colorNames[$colorName])) {
@@ -199,7 +200,7 @@ public static function fromName(string $colorName)
199200
*
200201
* @return string[]
201202
*/
202-
public static function fromHash(string $hashColor)
203+
public static function fromHash(string $hashColor): array
203204
{
204205
$color = substr($hashColor, 1);
205206
if (3 === \strlen($color)) {
@@ -233,7 +234,7 @@ public static function fromHash(string $hashColor)
233234
*
234235
* @return string[] rgb/a
235236
*/
236-
public static function fromRGBA(string $rgbColor)
237+
public static function fromRGBA(string $rgbColor): array
237238
{
238239
$matches = [];
239240
preg_match_all('/rgb\(([0-9]+)\s?\,\s?([0-9]+)\s?\,\s?([0-9]+)\s?([0-9]+)?\s?\)/ui', str_replace("\n\t\r ", '', $rgbColor), $matches);
@@ -253,7 +254,7 @@ public static function fromRGBA(string $rgbColor)
253254
*
254255
* @return int[]
255256
*/
256-
public static function toRGBA($colorInput, bool $inPDFColorSpace = false)
257+
public static function toRGBA($colorInput, bool $inPDFColorSpace = false): array
257258
{
258259
$colorInput = trim(strtolower($colorInput));
259260
if ($colorInput) {
@@ -263,6 +264,8 @@ public static function toRGBA($colorInput, bool $inPDFColorSpace = false)
263264
$color = static::fromRGBA($colorInput);
264265
} elseif (\array_key_exists($colorInput, static::$colorNames)) {
265266
$color = static::fromName($colorInput);
267+
} elseif (isset(static::$colorCustomNames[$colorInput])) {
268+
return static::$colorCustomNames[$colorInput];
266269
}
267270
$r = $inPDFColorSpace ? Math::div($color[0], '255') : $color[0];
268271
$g = $inPDFColorSpace ? Math::div($color[1], '255') : $color[1];
@@ -280,7 +283,7 @@ public static function toRGBA($colorInput, bool $inPDFColorSpace = false)
280283
*
281284
* @return string
282285
*/
283-
public static function toPdfString(string $colorInput)
286+
public static function toPdfString(string $colorInput): string
284287
{
285288
$color = static::toRGBA($colorInput);
286289
return "{$color[0]} {$color[1]} {$color[2]} RG";

0 commit comments

Comments
 (0)