diff --git a/changelog.md b/changelog.md index eaf4ffd..9b06ac7 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [v2.2.2] + +### Fixed +- Using 0-255 grayscale scale, instead 0-100, which was changed since 2.2.0 + ## [v2.2.1] ### Fixed @@ -45,7 +50,8 @@ All notable changes to this project will be documented in this file. ### Fixes - "U" style did not actually underline the text. -[Unreleased]: https://github.com/DocnetUK/tfpdf/compare/v2.2.1...HEAD +[Unreleased]: https://github.com/DocnetUK/tfpdf/compare/v2.2.2...HEAD +[v2.2.2]: https://github.com/DocnetUK/tfpdf/compare/v2.2.1...v2.2.2 [v2.2.1]: https://github.com/DocnetUK/tfpdf/compare/v2.2.0...v2.2.1 [v2.2.0]: https://github.com/DocnetUK/tfpdf/compare/v2.1.1...v2.2.0 [v2.1.1]: https://github.com/DocnetUK/tfpdf/compare/v2.1.0...v2.1.1 diff --git a/src/tFPDF/PDF.php b/src/tFPDF/PDF.php index c2eec05..391da2f 100755 --- a/src/tFPDF/PDF.php +++ b/src/tFPDF/PDF.php @@ -851,30 +851,37 @@ public function PageNo() } /** - * @param int $int_red - * @param int|null $int_green - * @param int|null $int_blue + * @param array $args + * @return string */ - public function SetDrawColor() + protected function getColourString($args) { - // Set color for all stroking operations - $args = func_get_args(); - if (count($args) and is_array($args[0])) { + if (count($args) && is_array($args[0])) { $args = $args[0]; } switch (count($args)) { case 1: - $this->str_draw_color = sprintf('%.3f G', $args[0] / 100); - break; + return sprintf('%.3f g', $args[0] / 255); case 3: - $this->str_draw_color = sprintf('%.3f %.3f %.3f RG', $args[0] / 255, $args[1] / 255, $args[2] / 255); - break; + return sprintf('%.3f %.3f %.3f rg', $args[0] / 255, $args[1] / 255, $args[2] / 255); case 4: - $this->str_draw_color = sprintf('%.3f %.3f %.3f %.3f K', $args[0] / 100, $args[1] / 100, $args[2] / 100, $args[3] / 100); - break; + return sprintf('%.3f %.3f %.3f %.3f k', $args[0] / 100, $args[1] / 100, $args[2] / 100, $args[3] / 100); default: - $this->str_draw_color = '0 G'; + return '0 g'; } + } + + /** + * @param int $int_red + * @param int|null $int_green + * @param int|null $int_blue + */ + public function SetDrawColor() + { + // Set color for all stroking operations + $args = func_get_args(); + // Setting draw colour (unlike any other colours) requires it to be uppercase + $this->str_draw_color = strtoupper($this->getColourString($args)); if ($this->int_page > 0) { $this->Out($this->str_draw_color); } @@ -889,22 +896,7 @@ public function SetFillColor() { // Set color for all filling operations $args = func_get_args(); - if (count($args) and is_array($args[0])) { - $args = $args[0]; - } - switch (count($args)) { - case 1: - $this->str_fill_color = sprintf('%.3f g', $args[0] / 100); - break; - case 3: - $this->str_fill_color = sprintf('%.3f %.3f %.3f rg', $args[0] / 255, $args[1] / 255, $args[2] / 255); - break; - case 4: - $this->str_fill_color = sprintf('%.3f %.3f %.3f %.3f k', $args[0] / 100, $args[1] / 100, $args[2] / 100, $args[3] / 100); - break; - default: - $this->str_fill_color = '0 g'; - } + $this->str_fill_color = $this->getColourString($args); $this->bol_fill_text_differ = ($this->str_fill_color != $this->str_text_color); if ($this->int_page > 0) { $this->Out($this->str_fill_color); @@ -920,22 +912,7 @@ public function SetTextColor() { // Set color for text $args = func_get_args(); - if (count($args) and is_array($args[0])) { - $args = $args[0]; - } - switch (count($args)) { - case 1: - $this->str_text_color = sprintf('%.3f g', $args[0] / 100); - break; - case 3: - $this->str_text_color = sprintf('%.3f %.3f %.3f rg', $args[0] / 255, $args[1] / 255, $args[2] / 255); - break; - case 4: - $this->str_text_color = sprintf('%.3f %.3f %.3f %.3f k', $args[0] / 100, $args[1] / 100, $args[2] / 100, $args[3] / 100); - break; - default: - $this->str_text_color = '0 g'; - } + $this->str_text_color = $this->getColourString($args); $this->bol_fill_text_differ = ($this->str_fill_color != $this->str_text_color); } diff --git a/tests/PDFGeneratedTest.php b/tests/PDFGeneratedTest.php index 53fd1d1..1b7fd66 100644 --- a/tests/PDFGeneratedTest.php +++ b/tests/PDFGeneratedTest.php @@ -27,7 +27,7 @@ public function testFileIsGenerated() $pdfLibrary->SetTextColor(255, 0, 0); $pdfLibrary->Write(5, "Hello Red Courier World"); $pdfLibrary->Ln(10); - $pdfLibrary->SetTextColor(50); + $pdfLibrary->SetTextColor(122.5); $pdfLibrary->Write(5, "Hello Gray Courier World"); $pdfLibrary->SetFont('Courier', 'U', 14); $pdfLibrary->Ln(10); @@ -36,6 +36,22 @@ public function testFileIsGenerated() $pdfLibrary->Ln(10); + // Set draw color example + $pdfLibrary->SetLineWidth(2); + $pdfLibrary->SetDrawColor(122.5); + $pdfLibrary->Line(20, $pdfLibrary->GetY(), 200, $pdfLibrary->GetY()); + $pdfLibrary->Ln(10); + + // Set fill color example + $pdfLibrary->SetFillColor(122.5); + $pdfLibrary->Rect(20, $pdfLibrary->GetY(), 180, 20, 'F'); + $pdfLibrary->Ln(30); + + // Set text color example + $pdfLibrary->SetFont('Courier', '', 14); + $pdfLibrary->SetTextColor(122.5); + $pdfLibrary->Text(20, $pdfLibrary->GetY(), 'Test text'); + $file = $pdfLibrary->output(); if (empty($file)) {