Write Modify Paragraph Font

The ooodev.format.writer.modify.para.font.FontOnly, class is used to set the paragraph style font Fig. 1087.

Writer dialog Paragraph Font default

Fig. 1087 Writer dialog Paragraph Font default

Setting the font

from ooodev.format.writer.modify.para.font import FontOnly, FontLang
from ooodev.format.writer.modify.para.font import StyleParaKind
from ooodev.write import Write, WriteDoc, ZoomKind
from ooodev.loader.lo import Lo

def main() -> int:
    with Lo.Loader(Lo.ConnectPipe()):
        doc = WriteDoc(Write.create_doc())
        doc.set_visible()
        Lo.delay(300)
        doc.zoom(ZoomKind.ENTIRE_PAGE)

        para_font_style = FontOnly(
            name="Arial",
            size=20,
            lang=FontLang().french_switzerland,
            style_name=StyleParaKind.STANDARD,
        )
        doc.apply_styles(font_style)

        Lo.delay(1_000)

        Lo.close_doc(doc)
    return 0

if __name__ == "__main__":
    SystemExit(main())

Running the above code will produce the following results in the Writer dialog. Note: that the language is changed to French (Switzerland), this is optional via the FontLang class.

Writer dialog Paragraph Font style changed

Fig. 1088 Writer dialog Paragraph Font style changed

Getting font from a style

# ... other code

f_style = FontOnly.from_style(
    doc=doc.component, style_name=StyleParaKind.STANDARD
)
assert f_style.prop_style_name == str(StyleParaKind.STANDARD)