Code Monkey home page Code Monkey logo

ppf.datamatrix's Issues

Encoding invalid characters

Trying to encode a character which is not supported by a codec will raise an exception (=> good). However, the error message is a bit misleading in some cases.

Example:

'ä'.encode('datamatrix.EDIFACT')

UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 0: ordinal not in range(128)
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
/InteractiveInput-1 in <module>
----> 1 'ä'.encode('datamatrix.EDIFACT')

~/Projects/ppf.datamatrix/src/ppf/datamatrix/codec_edifact.py in encode_to_edifact(msg)
     46     elif n_rest == 1:
     47         if len(msg) < 2:
---> 48             enc = (b'\xF0' + pack(msg.encode('ascii'), b'\x1F\x00\x00'))
     49         else:
     50             enc = (b'\xF0' +

UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 0: ordinal not in range(128)

Note that we are trying to encode in 'datamatrix.EDIFACT'. But the error message says there is a failure when encoding to 'ascii'. We should catch this exception and re-raise an exception that say 'ä' is an invalid datamatrix.EDIFACT character.

Similar things happen in other codecs.

Issue when importing in Flask this: from ppf.datamatrix import DataMatrix

Hi Adrian,
I really appreciated how you built the package. I tested on Python Console of my Mac OS and it works fine.

The issue come when I want to use it in my flask app by importing this: from ppf.datamatrix import DataMatrix , Flask pop up the error: NO MODULE FOUND named ppf.

Why did you put a dot and really, how can I do to fix that. I'm stuck since your last release of this code.

Tthanks

SVG not working in Openscad or FreeCAD

Hello,
I have almost no knowledge in SVG.
I want to 3D print Datamatrix barcodes.
So the plan was to generate SVGs and then use them in FreeCAD or openscad to extrude them into 3D objects.
But in FreeCAD it shows up as horizontal lines and in openscad, it looks almost like a datamatrix, but it isn't.
I opened the file in Inkscape and it works fine there.

I guess this is a limitation of how the file is generated. Can you maybe explain why? Can this be changed? etc.
Here is the genrated SVG
letters
And here the openscad extrude
openscad

6 digit code results in 12x12 data matrix instead of 10x10

I am doing a project for which I want to generate data-matrixes of 10x10, which stores six integers. In the webdemo, six digits results in a 10x10 data-matrix, but in this ported package, it returns a 12x12 data matrix. Do you perhaps have a fix for this? Thanks!

Wrong Code Generation

DataMatrix class does not provide a valid code

Steps to Reproduce

data = "B|BID|54C64-234F1"
myDataMatrix = DataMatrix(data)

Expected Behavior

barcode

Current Behavior

bitmap

Add viewbox to allow to scale via CSS

Hello,

the SVG cannot be scaled via CSS since the path is absolute. If you add viewBox="0 0 W H" (e.g. viewBox="0 0 18 18" if the width and height is 18), scaling works very well.

Rectangular Datamatrix with garabage at the end are generated for short texts

Firstly, thank you for this excellent library. While attempting to implement a datamatrix code in labelprinterkit with this library, I encountered an issue.

This is a small example code:

from ppf.datamatrix import DataMatrix
dm = DataMatrix('Hello World!', rect=True)
with open('/tmp/test.svg', 'w') as fh:
    fh.write(dm.svg())

I am using the current develop branch (a9e292c) on Python 3.11.4.

The code above gives this result:
defect datamatrix code

My barcode reader is giving the following output: "Hello World!gmlqqy[)>�06���". As you can see, there is some garbage at the end of the line.

Generating the same string with the tools from https://www.bcgen.com/datamatrix-barcode-creator.html gives a bit different output:
working datamatrix code

Which is read fine by my barcode reader.

I don't know if this is a bug or if something is broken in my setup. Maybe someone can try to confirm this issue?

Wrong message in DataMatrix

Example code:

from ppf.datamatrix import DataMatrix
from cairosvg import svg2png
from IPython.display import Image, display

s = 'SD0000-REF-C0-I0'
myDataMatrix = DataMatrix(s).svg()
svg = svg2png(myDataMatrix,write_to=None,output_width=100,output_height=100)
display(Image(svg))

Result:
image

This image decodes to "SD0000-REF-C0-I0 U03" and some non-printable characters.

Expected result (from demo https://datalog.github.io/demo/datamatrix-svg/):
datamatrix-20230518-072157
Which decodes correctly, with any message.

I noticed that a "small" change in message results in the correct datamatrix - 'SD0000-R-C0-I0' works well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.