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

TextBlob error when I want to control the horizontal spacing of fonts #200

Closed
haoxurt opened this issue Aug 18, 2023 · 7 comments
Closed

Comments

@haoxurt
Copy link

haoxurt commented Aug 18, 2023

I want to control the horizontal spacing of fonts , and I do not find corresponding control parameters. I find TextBlob that can input position list , however,it occurs error when I test with Chinese characters.
blob = skia.TextBlob("一二", font, [(0, 0), (40.5, 0)])
ValueError: len(text) = 6 does not match len(pos) = 2
What should I do? Looking forward to your reply!

@HinTak
Copy link
Collaborator

HinTak commented Aug 18, 2023

You need to count characters (2), not bytes (6). Also, this kind of question is not related to skia-python. Use stackoverflow or just search on Google

@HinTak HinTak closed this as completed Aug 18, 2023
@kyamagu
Copy link
Owner

kyamagu commented Aug 19, 2023

Right, this could be a bug in skia-python. The following size check does not correctly consider character encoding for non-ascii characters.

if (text.size() != pos_.size())

@kyamagu kyamagu reopened this Aug 19, 2023
@HinTak
Copy link
Collaborator

HinTak commented Aug 19, 2023

Hmm, every len check in that file is wrong. It is not friendly, but skia returns null when it fails so there is really no need for the check before passing to skia.

@HinTak
Copy link
Collaborator

HinTak commented Aug 19, 2023

There is another one of the same. #153

@HinTak
Copy link
Collaborator

HinTak commented Aug 19, 2023

Skia itself counts and valid input https://github.com/google/skia/blob/cc4f9b3469b92c6fcf87a5f151f9441da6652086/src/core/SkTextBlob.cpp#L793 and returns null if the input cannot be parsed. Why are checks scattered all over the place? It is just unnecessary code...

@HinTak
Copy link
Collaborator

HinTak commented Aug 19, 2023

Fixed in b79ef6a . Build from source or wait for 117b3.

>>> import skia
>>> tf = skia.Typeface.MakeFromFile("/usr/share/fonts/adobe-source-han-sans-tw/SourceHanSansTW-Normal.otf")
>>> font = skia.Font(tf, 100)
>>> blob = skia.TextBlob("一二", font, [(0, 0), (40.5, 0)])
>>> bounds = blob.bounds()
>>> bounds
Rect(-100, -180.8, 333.3, 104.8)

@HinTak HinTak closed this as completed Aug 19, 2023
@kyamagu
Copy link
Owner

kyamagu commented Aug 21, 2023

@HinTak Thanks!

HinTak added a commit to HinTak/skia-python that referenced this issue Sep 22, 2023
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

No branches or pull requests

3 participants