Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set font size and rtl

Using docx, I am trying to define for a run multiple attributes. When I set color, rtl, it works fine. But when I add also font size, it is ignored. If I set only font size, it works fine.

This works fine (font color changes and run is right-to-left):

run = p.add_run(line)
font = run.font
font.rtl = True
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)

This also works fine (font size is modified):

run = p.add_run(line)
font = run.font
font.size = Pt(8)
#font.rtl = True # commented out

But this does not change the font's size:

run = p.add_run(line)
font = run.font
font.size = Pt(8)
font.rtl = True

I tried different order of the commands, but nothing works.

like image 280
OritK Avatar asked Nov 11 '18 08:11

OritK


People also ask

How does the system choose an RTL image?

The system chooses an image named file.layoutdir-rtl.png when the app runtime language (see Understand user profile languages and app manifest languages) is set to an RTL language. This approach may be necessary when some part of the image is flipped, but another part isn't.

How do I use the languagefont class?

Use the LanguageFont font-mapping class for programmatic access to the recommended font family, size, weight, and style for a particular language. The LanguageFont class provides access to the correct font info for various categories of content including UI headers, notifications, body text, and user-editable document body fonts.

How do I change the default font size in Google Chrome?

From the Chrome menu, choose Settings. Scroll down to Appearance and choose the menu next to Font size to make font bigger on every site you visit. You can also adjust the default page zoom so that everything on the page appears larger by default.

What is RTL (Right-to-left) reading order?

And languages such as Arabic and Hebrew require that layout panels and text elements be laid out in right-to-left (RTL) reading order. Because of these variations in the metrics of translated text, we recommend that you don't bake absolute positioning, fixed widths, or fixed heights into your user interface (UI).


1 Answers

ok, found it! It turns out that in word, the font size for such a case has to include complex script instructions. It means that you have to add

<w:szCs w:val="???"/> 

instead (or in addition to) the normal

<w:sz w:val="??"/> 

I had to add a new attribute to the font in the docx library and it now works fine. The change is in 3 docs files:

text/font.py
oxml/__init.py__
oxml/text/font.py

and the usage in my view:

run = p.add_run(line)
font = run.font
#font.size = Pt(8) This line is redundant - but you can leave it
font.cs_size = Pt(8)
font.rtl = True

Added a fork to docx library. In https://github.com/Oritk/python-docx

like image 129
OritK Avatar answered Sep 27 '22 16:09

OritK