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

Binding the skparagraph module #225

Open
HinTak opened this issue Dec 26, 2023 · 11 comments · May be fixed by #258
Open

Binding the skparagraph module #225

HinTak opened this issue Dec 26, 2023 · 11 comments · May be fixed by #258
Labels
enhancement New feature or request

Comments

@HinTak
Copy link
Collaborator

HinTak commented Dec 26, 2023

Underline and strikeout were removed as SkPaint style some years ago, but seem to have been re-added in the skparagraph module as a settable text decoration style.

See #224 also

@olebedev
Copy link

olebedev commented Aug 8, 2024

Hi @HinTak,
The SkParagraph is a really useful module. Is there a chance you can share some insights on what is the current state of this issue, is it being worked on or what sort of help is required to push it forward?

Kind regards,
Oleg

@HinTak
Copy link
Collaborator Author

HinTak commented Aug 8, 2024

@olebedev nothing has been done so far. As you see this issue is more one or two statements of what possible benefits skparagraph module brings. I just had a quick look at the upstream code, and it is a pretty large module. It is probably a good idea to identify a good usage example in c (or other language?) for it and start adding those as a small usable subset? You can use the svg module as an example to see what's done and how https://github.com/kyamagu/skia-python/blob/main/src/skia/SVGDOM.cpp . That's the only module we bind so far - we also provide a few (one, I think) methods in the TextBlob class which accesses the skshaper module:

std::unique_ptr<SkShaper> shaper = SkShaper::Make();
. (I have some not-pushed code snippet doing a python skia.shaper class but decided that wasn't needed) . So probably either approaches: exposing SkParagraph as a python skia.Paragraph class etc, or additional methods to some of the other existing classes.

If you have a business need you can always get in touch privately about funding/ commissioning the work...

@HinTak
Copy link
Collaborator Author

HinTak commented Aug 8, 2024

The most recent changes in the svg module binding was to make this example work : https://github.com/rougier/freetype-py/blob/da3c14961f2e672bf487264e1e77dcbdb2344816/examples/skia_ot_svg_module.py#L96
https://github.com/rougier/freetype-py/blob/da3c14961f2e672bf487264e1e77dcbdb2344816/examples/skia_ot_svg_module.py#L126

The c version of this python code is at https://github.com/HinTak/freetype2-demos-skia . Historically it exists before the python one, only as a patch to freetype2-demos, posted at https://github.com/HinTak/harfbuzz-python-demos/tree/master/skia-adventure . The repository to host the patch is created more recently. That's how I came to skia-python a year ago.

@HinTak
Copy link
Collaborator Author

HinTak commented Aug 8, 2024

AFAIC only three modules are non-experimental at the moment: svg, skottie, and skresources. SkShaper and SkUnicode are with a stable API. (Look for SK_API, SK_SPI and ..._API in the code). That said, svg was included in the m87 series before it was declared non-experimental (in m88). That's not a forbidding point on skparagraph, but we just should only expose to python what is used/ maintained, rather than doing any wholesale addition, as the api of skparagraph is likely still subjected to substantial changes.

@olebedev
Copy link

olebedev commented Aug 9, 2024

I see, thank you for the comprehensive explanation, @HinTak.

Understood. I will have to try to resolve my multiline rendering with the existing API and if I see I get blocked without have SkParagraph in place I will try to bring it in and contribute upstream. And thanks for the guidance, btw!

Best,
Oleg

@HinTak
Copy link
Collaborator Author

HinTak commented Aug 9, 2024

@olebedev an appropriate example in c++ trying to port to python is https://github.com/google/skia/blob/main/example/external_client/src/shape_text.cpp , I think. That would come to 3x to 5x the size of https://github.com/kyamagu/skia-python/blob/main/src/skia/SVGDOM.cpp .

HinTak added a commit to HinTak/skia-python that referenced this issue Aug 11, 2024
@HinTak HinTak linked a pull request Aug 11, 2024 that will close this issue
@HinTak
Copy link
Collaborator Author

HinTak commented Aug 11, 2024

@olebedev example python code based on the upstream c++ example, and the pull in #258 . You'll need to install the python wheels when CI finishes https://github.com/kyamagu/skia-python/actions/runs/10337416324 to try it out, of course. Consider making a donation with the link in my profile https://hintak.github.io/ , especially if you want this for a business need and / or want to go further either yourself or have questions.

#258 will likely get merged in a about 2 months' time - we typically make a release N or N +1 (if updating skia-python N to N+1 is simple) when upstream N+1 comes out. Since we just did 128 a week after upstream 128, we'll be doing either 129 or 130 when upstream 130 comes out.

Note this is subjected to how upstream responds to
https://issues.skia.org/358587937 - basically NONE of skparagraph is meant to be used by non-google software at the moment!

@olebedev
Copy link

olebedev commented Aug 12, 2024

Hi @HinTak, this is awesome, thank you so much for the effort!

I am not sure at the moment if we are going to use the SkParagraph, as I mentioned earlier, however, I would be more than happy to put yourself onto a list of open-source projects/contributors to support to, when the next round of sponsorship proposals will be announced within @Canva.

@HinTak
Copy link
Collaborator Author

HinTak commented Aug 12, 2024

@olebedev after spending a good part of the weekend with skparagraph, I think it is quite neat - the c++ example is quite comprehensive, and it gets better with the python port as one can add/change rendering options quickly to try out without recompile. Justified / left / right / centred multi-line text, with decorations (under/over/strikethrough lines, dash, wavy, colored etc). The python example is the main "documentation" at the moment. Upstream documentation is quite sparse, actually, but having the c++ example useful.

At the moment the python code uses platform fonts (while the c++ original example is capable of loading specific font file) - I think using platform fonts is sufficient, but the specific font file capability is probably useful for pixel-accurate agreement across platforms. I think I can add that soon. Anyway, #258 will grow a bit and #256 get included when we move to release m129/130 in about 2 months.

@HinTak
Copy link
Collaborator Author

HinTak commented Aug 12, 2024

Added the single font loading code as well as updated the example and comments within.

@HinTak
Copy link
Collaborator Author

HinTak commented Aug 12, 2024

The example is called shaped_text, and is able to do multi-line paragraphs in Arabic correctly...

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

Successfully merging a pull request may close this issue.

2 participants