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

Text() function doesn't support unicode strings #25

Open
MamaShip opened this issue Jul 1, 2021 · 0 comments
Open

Text() function doesn't support unicode strings #25

MamaShip opened this issue Jul 1, 2021 · 0 comments

Comments

@MamaShip
Copy link

MamaShip commented Jul 1, 2021

I was trying to print Chinese/Japanese words on my model. But only blank squares are drawn:
Snipaste_2021-07-01_16-01-22

I'm pretty sure PIL package supports Chinese font and strings. So I guess there is a problem with sdf implementation.

sample code

from sdf import *

base = rectangle((100, 100)).extrude_to(
    rectangle((100, 100)), 100, ease.linear
)
base = base.translate((100 / 2, 100 / 2, 100 / 2))

FONT = "simsunb.ttf"
TEXT_ENGLISH = "test"
w, h = measure_text(FONT, TEXT_ENGLISH)
text_test = (
            text(FONT, TEXT_ENGLISH, 8 * (w / h), 8)
            .extrude(h)
            .translate((10 + w + 10, 100 / 2, h / 2))
        )
text_test = text_test.orient(Y)

TEXT_CHINESE = "中文测试"
w, h = measure_text(FONT, TEXT_CHINESE)
text_error = (
            text(FONT, TEXT_CHINESE, 8 * (w / h), 8)
            .extrude(h)
            .translate((10 + w + 10, 140 / 2, h / 2))
        )
text_error = text_error.orient(Y)

f= base | text_test | text_error

f.save('out.stl', step=0.1)

Environment

OS: win10
Python 3.9.1
sdf version: commit 2a17d2f (HEAD -> main, origin/main, origin/HEAD)

Appendix: PIL works fine with Chinese

from PIL import Image, ImageDraw, ImageFont

image= Image.new('RGB', (559, 320),(255,255,255))
draw = ImageDraw.Draw(image)

TEXT_CHINESE = "中文测试"

# draw.text()
font = ImageFont.truetype("simsun.ttc", 40)  
draw.text((100, 50), TEXT_CHINESE, fill = 255, font = font)

image.show()

output:
PIL_output

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

1 participant