Skip to content

Conversation

@Caellian
Copy link
Collaborator

@Caellian Caellian commented Feb 2, 2024

I started adding PDF417 utility method, and then did a few other things. One day later:

  • Allowed passing Options to Zint.
    • A lot of codes weren't constructible previously because they require additional configuration.
  • Added utility functions for configuration.
    • This makes it easier and safer to use right Options values.
  • Documented majority of barcode encoders in the manual.
  • Replaced anyhow with thiserror to provide descriptive error messages.
    • Old ones were a single word that would be a pain to pin down in a lot of normal use cases.
  • Removed some unused derives to speed up compilation.
    • e.g. Options don't need Serialize as they'll never be passed back to typst; Errors almost never require Clone and Copy, and adding them imposes restrictions that can't be satisfied in a lot of cases; ...
  • Moved simple functions to typst and used composition to reduce code complexity.
  • Marked Symbology as #[non_exhaustive] in bindings as it depends on Zint values.
    • Doesn't affect the current code, but ensures that future code will have to handle any unimplemented values in some way, in case Zint updates and the bindings don't (yet).
  • Made Options fields public to allow testing and Options default constructible to simplify use from Rust code.
    • I faced some weird errors while trying to use Zint (my fault), so I tried writing tests and it was impossible to do so, so I fixed the API a little.
  • Added a few constants to lib.typ to allow dependants to use named values instead of magic numbers.
    • I think these are mostly fine, but I'm not sure what DM_ISO_144 and ULTRA_COMPRESSION do so I just left them in case they're needed.
  • Fixed errors copying Options strings into C buffers.
    • Previously used copy_from_slice expected source and destination buffers to be of same size which caused the library to panic when any of the string options were set.
  • Add more flexible Color deserialization logic.
    • The field can now deserialize form a hex string, or a byte array, or a dictionary.
  • Turned Option3 into an union so that it matches Zint better - the actual meaning of the value is determined by the Options object.
  • Added more flexible Option3 deserialization - accepts either a valid int value (any of) or a textual representation.
  • Made enum discriminants match the values they were representing.
    • This makes it very easy to do typst-rust-c conversion in any direction and makes things more consistent.
    • Used serde aliases to handle legacy names so this part is still backwards compatible.
  • Use hex crate for faster Color conversion.
    • hex was needed for parsing/deserializing the colors, so I used it for string generation as well as it's faster and generates less code than std format! macro.
  • Added a table with Options names and values to the manual so people can look it up there instead of having to look at the sources.

This closes #1.

Future Work

  • I left some more complicated barcodes commented out in the docs, they should be documented at some point, but it's a lot of work tracking down all the details and I'm short on time atm.
    • I made sure to include one of them anyway for reference.
  • I left a few TODO comments in places where I didn't know what to do.

Allow passing options to Zint.
Add utility functions for configuration.
Document majority of barcode encoders in the manual.
Reduce boilerplate in manual.
Replace anyhow with thiserror to provide descriptive error messages.
Remove some unused derives to speed up compilation.
Move simple functions to typst and use composition to reduce code
complexity.
Mark Symbology as non_exhaustive in bindings as it depends on Zint
values.
Make Options fields public to allow testing.
Make Options default constructible to simplify use from Rust code.
Make serde error when unknown fields are passed to Options.
Add constants to lib.typ to allow dependants to use named values instead
of magic numbers.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
@Caellian Caellian changed the title General improvements (add PDF417) Sturdy up the API and add PDF417 Feb 2, 2024
@Caellian Caellian marked this pull request as draft February 2, 2024 20:36
@Caellian Caellian marked this pull request as ready for review February 3, 2024 12:41
Add more flexible Color deserialization logic.
Cleanup Option3 semantics.
Add more flexible Option3 deserialization.
Make enums directly store represented data.
Use hex crate for faster Color conversion.
Add more details to manual.
Fix some minor consistency issues.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
@Enter-tainer
Copy link
Owner

looks cool! i'm busy with work these days but i will take a look within a week. thank you for such a big improvement!

@Caellian
Copy link
Collaborator Author

Caellian commented Feb 3, 2024

You're welcome. Let me know if there's any change you don't like or want more info on when you get at it.

Copy link
Owner

@Enter-tainer Enter-tainer left a comment

Choose a reason for hiding this comment

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

LGTM, this is definitely a huge improvement to this packge!

Replace into_zint_symbol with a Symbol constructor.
Use bitflags for bitflag options.
Add more detailed error messages and better edge-case handling.
Improve deserialization of options and move related code from Typst into WASM.
Use kebab-case deserialization for typst plugin.
Use transparent background color by default.
Fully document available options in the manual.
Add links to manual.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Fix a typo (decent -> descent).
Set white background for manual and update README.
Add license information to Rust crates.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
@Caellian Caellian merged commit 04cca85 into Enter-tainer:master Feb 4, 2024
@Enter-tainer
Copy link
Owner

thank you! i will publish a new version when i leave work

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.

Add remaining zint generators (pdf417)

2 participants