-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feature: Font.name_far_east #154
Comments
|
The name that Word uses for some fonts is unpredictable. In general, if it doesn't work the way it's spelled in the Word UI, the most direct approach is to use Word to apply the font to some text in a very small document (like a single word in a single paragraph), save the file, and then use opc-diag to examine the document.xml part. $ opc browse test-doc.docx document.xmlThe proper name to use will appear there, something like this: <w:r w:rsidRPr="00392E92">
<w:rPr>
<w:rFonts w:ascii="ヒラギノ角ゴ ProN W3" w:eastAsia="ヒラギノ角ゴ ProN W3" w:hAnsi="ヒラギノ角ゴ ProN W3"/>
</w:rPr>
<w:t>Foobar.</w:t>
</w:r>
If they differ, you want the one in |
|
I find the 'w:ascii' and use the name. It still doesn't work. My code as follow: run = paragraphs[3].add_run(namea1)
run.bold = True #It works.
run.font.size = Pt(19) #It works.
run.font.name = "Adobe 楷体 Std R" #It doesn't work.I will try other way to solve it. |
|
What do you find when you compare the XML produced by python-docx and that produced by Word? It could be that Word is using the font in the |
|
Excited! You remind me! <w:rFonts w:ascii="Adobe 楷体 Std R" w:eastAsia="Adobe 楷体 Std R" w:hAnsi="宋体" w:hint="eastAsia"/>The w:ascii and w:eastAsia are correct But the w:hAnsi was INCORRECT. This line was appear before the WORDS that I want to change. The followe line was the WORDS and the attribute are correct. But didn't have the w:hAnsi attribute, But display INCORRECT. |
|
You should be able to add a from docx.oxml.ns import qn
run = paragraphs[3].add_run(namea1)
run.font.name = "Adobe 楷体 Std R"
r = run._element
r.rPr.rFonts.set(qn('w:eastAsia'), 'Adobe 楷体 Std R') |
|
Thanks a lot. It works. |
|
Ah, yes, of course, thanks @Taerg-L, I've corrected that. I'm reopening this issue to act as a feature request to add |
|
Hey @scanny , this problem can be easily patched by PR #329 . Unfortunately, @leonzhu211 forgot to update the unit test. More info at Travis. |
I find in there http://python-docx.readthedocs.org/en/latest/api/text.html#docx.text.run.Font
the font object has a name attribute, and i want to use a custome font. Where should i put the font's file(.otf)?
run.font.name = "Adobe 楷体 Std R"#this the font's name. Should i use the font's file name to replace the font's name ?
I try use it, but useless. What should I do?
Thanks.
The text was updated successfully, but these errors were encountered: