Skip to content

Commit

Permalink
QR code now converts line breaks to actual line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
finwe committed Sep 29, 2017
1 parent 04dda02 commit 1a17723
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Backward incompatible changes
- Changed names to camelCase without underscores and to `computeBezierBoundingBox`
- Security: Embedded files via `<annotation>` custom tag must be explicitly allowed via `allowAnnotationFiles` configuration key
- `fontDir` property of Mpdf class is private and must be accessed via configuration variable with array of paths or `AddFontDirectory` method
- QR code `<barcode>` element now treats `\r\n` and `\n` as actual line breaks


Removed features
Expand Down Expand Up @@ -92,6 +93,7 @@ New features
- PDF/A-3 associated files + additional xmp rdf (by @chab in #130)
- Additional font directories can be added via `addFontDir` method
- Introduced `cleanup` method which restores original `mb_` encoding settings (see #421)
- QR code `<barcode>` element now treats `\r\n` and `\n` as actual line breaks


Git repository enhancements
Expand Down
74 changes: 63 additions & 11 deletions src/Mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7153,34 +7153,86 @@ function printobjectbuffer($is_table = false, $blockdir = false)
}
}

/* -- BARCODES -- */
// BARCODE
if ($objattr['type'] == 'barcode') {
if ($objattr['type'] === 'barcode') {

$bgcol = $this->colorConverter->convert(255, $this->PDFAXwarnings);

if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
$bgcol = $objattr['bgcolor'];
}

$col = $this->colorConverter->convert(0, $this->PDFAXwarnings);

if (isset($objattr['color']) && $objattr['color']) {
$col = $objattr['color'];
}

$this->SetFColor($bgcol);
$this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
$this->SetFColor($this->colorConverter->convert(255, $this->PDFAXwarnings));

if (isset($objattr['BORDER-WIDTH'])) {
$this->PaintImgBorder($objattr, $is_table);
}
if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
$this->WriteBarcode($objattr['code'], $objattr['showtext'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], 0, 0, 0, 0, 0, $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['bsupp'], (isset($objattr['bsupp_code']) ? $objattr['bsupp_code'] : ''), $k);
} // QR-code
elseif ($objattr['btype'] == 'QR') {
$this->qrcode = new QrCode\QrCode($objattr['code'], $objattr['errorlevel']);
$this->qrcode->displayFPDF($this, $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'] * 25, [255, 255, 255], [0, 0, 0]);



$barcodeTypes = ['EAN13', 'ISBN', 'ISSN', 'UPCA', 'UPCE', 'EAN8'];
if (in_array($objattr['btype'], $barcodeTypes, true)) {

$this->WriteBarcode(
$objattr['code'],
$objattr['showtext'],
$objattr['INNER-X'],
$objattr['INNER-Y'],
$objattr['bsize'],
0,
0,
0,
0,
0,
$objattr['bheight'],
$bgcol,
$col,
$objattr['btype'],
$objattr['bsupp'],
(isset($objattr['bsupp_code']) ? $objattr['bsupp_code'] : ''),
$k
);

} elseif ($objattr['btype'] === 'QR') {

$barcodeContent = str_replace('\r\n', "\r\n", $objattr['code']);
$barcodeContent = str_replace('\n', "\n", $barcodeContent);

$this->qrcode = new QrCode\QrCode($barcodeContent, $objattr['errorlevel']);

$this->qrcode->displayFPDF(
$this,
$objattr['INNER-X'],
$objattr['INNER-Y'],
$objattr['bsize'] * 25,
[255, 255, 255],
[0, 0, 0]
);

} else {
$this->WriteBarcode2($objattr['code'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k);

$this->WriteBarcode2(
$objattr['code'],
$objattr['INNER-X'],
$objattr['INNER-Y'],
$objattr['bsize'],
$objattr['bheight'],
$bgcol,
$col,
$objattr['btype'],
$objattr['pr_ratio'],
$k
);

}
}
/* -- END BARCODES -- */

// TEXT CIRCLE
if ($objattr['type'] == 'textcircle') {
Expand Down

1 comment on commit 1a17723

@cpu4you
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @finwe, QRCodes with \r\n work like charm now. 👍

Please sign in to comment.