From 369bca652c8bfdbdf0e2264a143e98bb7572ad17 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Sat, 26 Nov 2022 19:15:58 +0100 Subject: [PATCH 1/2] MDL-76495 lib: test for qrcode in TCPDF --- lib/tests/pdflib_test.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/tests/pdflib_test.php b/lib/tests/pdflib_test.php index fb8cf0777ff..fea0e2dc34b 100644 --- a/lib/tests/pdflib_test.php +++ b/lib/tests/pdflib_test.php @@ -36,4 +36,34 @@ class pdflib_test extends \advanced_testcase { $producer = TCPDF_STATIC::getTCPDFProducer(); $this->assertEquals('TCPDF (http://www.tcpdf.org)', $producer); } + + public function test_qrcode() { + global $CFG; + require_once($CFG->libdir.'/pdflib.php'); + + $this->resetAfterTest(); + + $pdf = new \pdf(); + $pdf->AddPage('P', [500, 500]); + $pdf->SetMargins(10, 0, 10); + + $style = [ + 'border' => 0, + 'vpadding' => 'auto', + 'hpadding' => 'auto', + 'fgcolor' => [0, 0, 0], + 'bgcolor' => [255, 255, 255], + 'module_width' => 1, + 'module_height' => 1 + ]; + + $pdf->setCellPaddings(0, 0, 0, 0); + $pdf->write2DBarcode('https://www.example.com/moodle/admin/search.php', + 'QRCODE,M', null, null, 35, 35, $style, 'N'); + $pdf->SetFillColor(255, 255, 255); + $res = $pdf->Output('output', 'S'); + + $this->assertGreaterThan(100000, strlen($res)); + $this->assertLessThan(120000, strlen($res)); + } } From 2d0b8c92829eb928d1ac566fa5d0ed6a8dda198a Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 28 Nov 2022 16:01:47 +0100 Subject: [PATCH 2/2] MDL-76495 libs: patch TCPDF for PHP 8.1 compatibility --- lib/tcpdf/include/barcodes/qrcode.php | 4 ++-- lib/tcpdf/readme_moodle.txt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tcpdf/include/barcodes/qrcode.php b/lib/tcpdf/include/barcodes/qrcode.php index 2e7f2f57681..b1b9aae5f5b 100644 --- a/lib/tcpdf/include/barcodes/qrcode.php +++ b/lib/tcpdf/include/barcodes/qrcode.php @@ -884,14 +884,14 @@ class QRcode { protected function getCode() { if ($this->count < $this->dataLength) { $row = $this->count % $this->blocks; - $col = $this->count / $this->blocks; + $col = (int)($this->count / $this->blocks); if ($col >= $this->rsblocks[0]['dataLength']) { $row += $this->b1; } $ret = $this->rsblocks[$row]['data'][$col]; } elseif ($this->count < $this->dataLength + $this->eccLength) { $row = ($this->count - $this->dataLength) % $this->blocks; - $col = ($this->count - $this->dataLength) / $this->blocks; + $col = (int)(($this->count - $this->dataLength) / $this->blocks); $ret = $this->rsblocks[$row]['ecc'][$col]; } else { return 0; diff --git a/lib/tcpdf/readme_moodle.txt b/lib/tcpdf/readme_moodle.txt index 7a9bb1e1936..23832673775 100644 --- a/lib/tcpdf/readme_moodle.txt +++ b/lib/tcpdf/readme_moodle.txt @@ -6,6 +6,8 @@ Description of TCPDF library import * remove all fonts that were not already present * visit http://127.0.0.1/lib/tests/other/pdflibtestpage.php and view the pdf * modify getTCPDFProducer lib/tcpdf/include/tcpdf_static.php to remove the version number +* Check the status of https://github.com/tecnickcom/TCPDF/pull/548 , apply if it is still + not included or delete this entry Important ---------