scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.37k stars 513 forks source link

Change font name not working for asian characters. #768

Open bigheadsnake opened 2 years ago

bigheadsnake commented 2 years ago

I found that if I change font name in a table or paragraph, it only works for the latin charaters and numbers, this is my code.

    p = text_frame.paragraphs[0]
    run = p.add_run()
    font = run.font
    font.size = Pt(20)
    font.name = "STKaiti"
    font.text = "测试abc123"

The attribute font size worked for all the characters in the text, but the font style STKaiti only worked for "abc123", the Asian word "测试" keeped the default Style, but if you select the word, the font attributes was already changed, if you type "enter" in the font sytle, it changed immediately.

scanny commented 2 years ago

check out this issue in the python-docx package and see if it helps you: https://github.com/python-openxml/python-docx/issues/154

East-Asia font is specified separately and there is no API support for that, but others have gotten it to work using the information in that issue and a PR that is linked from it.

DaiDai-Dad commented 2 years ago

I have solved this problem by editing xml. https://zhuanlan.zhihu.com/p/548039429