Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented rectangular data matrix barcode #678

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

w512work
Copy link

Implemented support for rectangular data matrix code. Corrected values in code definition table and corrected modulo 254 operation in function get253StateCodeword.

remicollet and others added 23 commits September 6, 2023 08:51
…#620)

Tested and confirmed working in PHP 7.4 and PHP 8.2
* README: tone down the warning about tc-lib-pdf

Signed-off-by: Ruben Barkow-Kuder <github@r.z11.de>

* Update README.md

Co-authored-by: William Desportes <williamdes@wdes.fr>

---------

Signed-off-by: Ruben Barkow-Kuder <github@r.z11.de>
Co-authored-by: William Desportes <williamdes@wdes.fr>
* Fix of Deprecation warning with php 8.1 tecnickcom#614

* Update include/barcodes/qrcode.php

Co-authored-by: William Desportes <williamdes@wdes.fr>

---------

Co-authored-by: Robert Johnson Nallori <rnallori@evoketechnologies.com>
Co-authored-by: johnson361 <johnson361@users.noreply.github.com>
Co-authored-by: William Desportes <williamdes@wdes.fr>
…om#633)

* Update tcpdf_fonts.php

Fixes "use of "self" in callables is deprecated" warning is arising from tcpdf_fonts.php when using PHP >= 8.2

* Update tcpdf_fonts.php for PHP 5.3-8.2 compatibility

PHP 8.2 "use of "self" in callables is deprecated" yet some ways of fixing this breaks for PHP 5.3. This approach works, tested PHP 5.3.29 - 8.2.0

* Update tcpdf_fonts.php

Spaces added back in before arguments

* Update tcpdf_fonts.php using get_called_class()

Maneuvers compatibility of callables inside array_map() between PHP 5.3 and 8.2 - tested.

---------

Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
* Fix composite glyph output

* Pad zeros before checksum calulation

---------

Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
* fix for tecnickcom#583

* fix fix

---------

Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
* Fix non-numeric value warning

Fixes this warning on generating PDF:
Warning: A non-numeric value encountered in /tcpdf/tcpdf.php on line 5473

* Better fix for non-numeric value warning

Fixes this warning on generating PDF after calling `Text` with a non-numeric value for `$fstroke`:
Warning: A non-numeric value encountered in /tcpdf/tcpdf.php on line 5470

* Update tcpdf.php

Co-authored-by: William Desportes <williamdes@wdes.fr>

---------

Co-authored-by: William Desportes <williamdes@wdes.fr>
Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
This was already fixed in tc-lib-barcode.
* Fix return type annotation

* BC with tools that do not support PHPStan annotations

Co-authored-by: William Desportes <williamdes@wdes.fr>

---------

Co-authored-by: William Desportes <williamdes@wdes.fr>
Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
tecnickcom#598)

* Typehints for get/setHeaderMargin are inconstent

* Add typehints for header/footer margin properties

---------

Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
* Bump actions/checkout and add PHP 8.3

* Update the composer json tests

* Remove PHP 5.3 and 5.4 from the matrix

* add permission entry

Restrict GitHub actions access

---------

Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
@CLAassistant
Copy link

CLAassistant commented Jan 19, 2024

CLA assistant check
All committers have signed the CLA.

@williamdes
Copy link
Contributor

Do you have an ouput to show here and some example code ?
It would be great to have a new example in the examples/ folder

@@ -121,6 +122,12 @@ class Datamatrix {
*/
protected $last_enc = ENC_ASCII;

/**
* Store whether the code is rectangular or not (square).
* @protected
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @protected
* @protected
* @var bool

@@ -230,38 +237,62 @@ class Datamatrix {
* This is the class constructor.
* Creates a datamatrix object
* @param string $code Code to represent using Datamatrix.
* @param string $shape Shape of datamatrix code (R = rectangular, S = square)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param string $shape Shape of datamatrix code (R = rectangular, S = square)
* @param string $shape Shape of datamatrix code (R = rectangular, S = square)
* @phpstan-param 'R'|'S' $shape

Copy link
Author

Choose a reason for hiding this comment

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

@williamdes Just saw your comment recommendations. Unfortunately only after I added the latest change -> Update will follow...
I've never used phpstan. Is the last line there to specify the parameters for automated testing?

Copy link
Contributor

Choose a reason for hiding this comment

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

You should check out phpstan, it is for static analysis

Here is an example of what my proposal would do https://phpstan.org/r/f04d0c5e-0a40-4959-b03a-fdee4430a29a

Copy link
Author

Choose a reason for hiding this comment

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

If I understand correctly, this does not generate an automatic verification script.
As you may have seen, I have extended the parameter so that you can specify the desired dimensions (e.g. 48x48). Can this also be specified in a kind of wildcard form, or would each valid combination have to be specified separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this does not generate an automatic verification script.

This is used by automatic tools, in this repo:

run: ./vendor/bin/phpstan --memory-limit=6G

But for people that will integrate TCPDF, it will also throw warnings if they use phpstan and pass something else than the values you did set

Copy link
Contributor

@williamdes williamdes left a comment

Choose a reason for hiding this comment

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

The code looks good

@nicolaasuni
Copy link
Member

This feature is already present in https://github.com/tecnickcom/tc-lib-barcode that is already integrated with tc-lib-pdf.
The current datamatrix implementation in TCPDF is not maintained and contains other bugs.
If you want to use datamatrix with TCPDF it is easier to import the tc-lib-barcode and integrate it like in tc-lib-pdf.

@williamdes
Copy link
Contributor

@w512work it is probably best that you migrate to the new library for data matrix and close this PR

@w512work
Copy link
Author

Thank you @nicolaasuni for the hint.

I do not only need barcodes. If I have understood correctly, tc-lib-pdf is the top level for generating comprehensive PDFs. In its readme it says at the top that the library is not yet ready.
I would have liked to take a look at the examples of this version to get an idea of the current status. I installed the current version of the lib via composer and tried for about an hour without success to get the example script in the examples folder displayed im my browser. I failed because the autoloader could not be loaded.
I'm not sure if it's a good idea to change everything at this point without causing various other problems that will significantly increase the development and maintenance effort of my project...

Can I view the examples anywhere on the net without spending 2 hours coding, like on https://tcpdf.org/examples/ ?

@w512work
Copy link
Author

Can I view the examples anywhere on the net without spending 2 hours coding, like on https://tcpdf.org/examples/ ?

Just tried the command make server mentioned in the readme. Unfortunately it gives me the error:

Directory example does not exist.
make: *** [Makefile:250: server] Error 1

The manual approach php -t examples -S 10.0.0.251:8888 throws another error when I try to access from the browser:

[Fri Jan 26 09:55:16 2024] PHP Fatal error: Uncaught Com\Tecnick\Pdf\Font\Exception: unable to read file: helvetica.json in /var/www/html/test-uw/tc-lib-pdf/vendor/tecnickcom/tc-lib-pdf-font/src/Stack.php:183
Stack trace:
#0 /var/www/html/test-uw/tc-lib-pdf/vendor/tecnickcom/tc-lib-pdf/examples/index.php(46): Com\Tecnick\Pdf\Font\Stack->insert()
#1 {main}
thrown in /var/www/html/test-uw/tc-lib-pdf/vendor/tecnickcom/tc-lib-pdf-font/src/Stack.php on line 183
[Fri Jan 26 09:55:16 2024] 10.0.2.121:49293 [500]: GET / - Uncaught Com\Tecnick\Pdf\Font\Exception: unable to read file: helvetica.json in /var/www/html/test-uw/tc-lib-pdf/vendor/tecnickcom/tc-lib-pdf-font/src/Stack.php:183
Stack trace:
#0 /var/www/html/test-uw/tc-lib-pdf/vendor/tecnickcom/tc-lib-pdf/examples/index.php(46): Com\Tecnick\Pdf\Font\Stack->insert()
#1 {main}
thrown in /var/www/html/test-uw/tc-lib-pdf/vendor/tecnickcom/tc-lib-pdf-font/src/Stack.php on line 183

@nicolaasuni
Copy link
Member

Please try to resolve the conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet