Merge pull request #592 from bm-rana/bold-rtl-fix

Add RTL support for bold/italic text
This commit is contained in:
Eric Lapouyade 2025-05-02 15:58:19 +02:00 committed by GitHub
commit 685425095b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,6 +38,8 @@ class RichText(object):
strike=False, strike=False,
font=None, font=None,
url_id=None, url_id=None,
rtl=False,
lang=None,
): ):
# If a RichText is added # If a RichText is added
@ -73,8 +75,12 @@ class RichText(object):
prop += '<w:vertAlign w:val="superscript"/>' prop += '<w:vertAlign w:val="superscript"/>'
if bold: if bold:
prop += "<w:b/>" prop += "<w:b/>"
if rtl:
prop += '<w:bCs/>'
if italic: if italic:
prop += "<w:i/>" prop += "<w:i/>"
if rtl:
prop += '<w:iCs/>'
if underline: if underline:
if underline not in [ if underline not in [
"single", "single",
@ -98,7 +104,10 @@ class RichText(object):
prop += '<w:rFonts w:ascii="{font}" w:hAnsi="{font}" w:cs="{font}"{regional_font}/>'.format( prop += '<w:rFonts w:ascii="{font}" w:hAnsi="{font}" w:cs="{font}"{regional_font}/>'.format(
font=font, regional_font=regional_font font=font, regional_font=regional_font
) )
if rtl:
prop += '<w:rtl w:val="true"/>'
if lang:
prop += '<w:lang w:val="%s"/>' % lang
xml = "<w:r>" xml = "<w:r>"
if prop: if prop:
xml += "<w:rPr>%s</w:rPr>" % prop xml += "<w:rPr>%s</w:rPr>" % prop