Skip to content

kn: Add support for experimental writer api #764

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

Merged
merged 14 commits into from
May 8, 2024
Merged

Conversation

ISNing
Copy link
Contributor

@ISNing ISNing commented Apr 10, 2024

No description provided.

ISNing added 2 commits April 10, 2024 20:56
Example:
```kotlin
val barcode = BarcodeReader.read(iv)
```
```kotlin
val barcode = BarcodeReader.read(iv, opts)
```
@ISNing ISNing force-pushed the master branch 2 times, most recently from 5f1be8f to 450e02e Compare April 10, 2024 14:13
@ISNing ISNing marked this pull request as ready for review April 10, 2024 14:20
@ISNing
Copy link
Contributor Author

ISNing commented Apr 10, 2024

@axxel
Copy link
Collaborator

axxel commented Apr 11, 2024

I think you must give this a look as I think this is not the best practice, if you have any idea about modeling this, please tell me:

I don't like that either. While Image is derived from ImageView in c++, this is not the case (or intransparent) in the C-API. While it would make sense to model it like that in k/n as well to support passing the result of a barcode creation directly back to the reader, this is not really useful in non-testing use cases, so not a priority in my eyes. What I definitively not want to merge is a rename of the public facing ImageView type to ImageViewImplNoCopy. If we deem this subclassing worthwhile then we need to introduce something like ImageViewBase or IImageView and then have Image and ImageView implement that.

I did not have much time to really go through the PR in detail, though.

@ISNing
Copy link
Contributor Author

ISNing commented Apr 12, 2024

I think the current version makes more sens.

Copy link
Collaborator

@axxel axxel left a comment

Choose a reason for hiding this comment

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

Thanks. I think this can be further simplified. See below. Sorry for being a bit slow nowerdays.


@ExperimentalWriterApi
@OptIn(ExperimentalForeignApi::class)
class BarcodeWriter : WriterOptions() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at this, I'd like to question the utility of the BarcodeWriter class. Why not implement the toSVG/toImage members of Barcode directly calling the c-API and completely remove this class? With the above constructor idea the usecase could then look like

val svg = Barcode("some test", BarcodeFormat.QRCode).toSVG();

Could you add something like this to the README.md? I'd like to always start from the client side usability and strive for a native feeling API. See also my current .NET and Rust README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's best to keep the BarcodeWriter class because it serves as a logical place to apply writer options. Moreover, this aligns with Java's style, even though it may not be the most convenient approach.

Regarding the toSVG and toImage methods, they have already been implemented in the code, as seen here:
https://github.com/zxing-cpp/zxing-cpp/pull/764/files#diff-108ceccf4e8d9a00451a5f5cca9c48695f005ddcc552c009530799a244f037a1R152-R157

By providing both methods for converting the barcode, users have the flexibility to choose the one that best suits their needs and preferences.

I will add the usage of toSVG and toImage later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The logical place to apply the options to is WriterOptions. Given my stance that BarcodeWriter is useless here, I thought about the reason for the existence of BarcodeReader. Why not have a Barcode constructor that takes an image? The answer is, the reader returns multiple objects, which a constructor can't.

What do you mean by "Java's style"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I understand that kotlin is more suited to java styles (a bunch of controllers, managers, blabla) because it influences the style of code that comes from java, and of course, in my experience, kotlin is more suited to functional programming, so I think both options are fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, so why don't we change BarcodeReader to something like ImageView.readBarcodes(opts) or sth?
Dont you think that it's wierd there's Reader but not a Writer?

Copy link
Contributor Author

@ISNing ISNing May 4, 2024

Choose a reason for hiding this comment

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

I think maybe we're influenced by the design of original ZXing java, I don't know...

ISNing added 4 commits April 26, 2024 22:07
This commit addresses the use of fromText and fromBytes methods for constructing objects from strings or byte arrays. The changes include:

Replacing fromText and fromBytes with overloaded constructors that take either a String or ByteArray parameter directly
Removing the companion object since the secondary constructors handle the different input types
Improves code clarity by using language features like function overloading instead of specially named methods
These updates simplify the API by leveraging Kotlin's capabilities for constructor overloading based on parameter types. It makes the code more idiomatic and readable.
@ISNing
Copy link
Contributor Author

ISNing commented Apr 26, 2024

I've checked all the comments and pushed related changes.

Sorry for late responding...

@ISNing ISNing requested a review from axxel April 26, 2024 15:17

@ExperimentalWriterApi
@OptIn(ExperimentalForeignApi::class)
class BarcodeWriter : WriterOptions() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The logical place to apply the options to is WriterOptions. Given my stance that BarcodeWriter is useless here, I thought about the reason for the existence of BarcodeReader. Why not have a Barcode constructor that takes an image? The answer is, the reader returns multiple objects, which a constructor can't.

What do you mean by "Java's style"?

@ISNing ISNing requested a review from axxel May 4, 2024 06:38
@axxel axxel merged commit d0c1f34 into zxing-cpp:master May 8, 2024
@axxel
Copy link
Collaborator

axxel commented May 8, 2024

Thanks for your continued dedication to maintain your contributed code base. Much appreciated.

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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy