Write Direct Character FontEffects Class
The ooodev.format.writer.direct.char.font.FontEffects
class gives you the same options
as Writer’s Font Effects Dialog, but without the dialog. as seen in Fig. 917.
Setting the style
from ooodev.format.writer.direct.char.font import (
FontOnly, FontEffects, FontLine, FontUnderlineEnum
)
from ooodev.office.write import Write
from ooodev.utils.color import CommonColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
def main() -> int:
with Lo.Loader(Lo.ConnectPipe()):
doc = Write.create_doc()
GUI.set_visible(doc=doc)
Lo.delay(300)
GUI.zoom(GUI.ZoomEnum.PAGE_WIDTH)
cursor = Write.get_cursor(doc)
font_style = FontOnly(name="Liberation Serif", size=20)
font_effects = FontEffects(
color=CommonColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=CommonColor.BLUE),
shadowed=True,
)
Write.append_para(
cursor=cursor, text="Hello World!", styles=[font_style, font_effects]
)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
sys.exit(main())
Running the above code will produce the following output in Fig. 918.
The results can be seen in dialog show in Fig. 919.
Getting the font effects from the document
Continuing from the code example above, we can get the font effect from the document.
A paragraph cursor object is used to select the first paragraph in the document. The paragraph cursor is then used to get the style.
# ... other code
para_cursor = Write.get_paragraph_cursor(cursor)
para_cursor.gotoPreviousParagraph(False)
para_cursor.gotoEndOfParagraph(True)
font_effects = FontEffects.from_obj(para_cursor)
assert font_effects.prop_color == CommonColor.RED
assert font_effects.prop_underline.line == FontUnderlineEnum.SINGLE
assert font_effects.prop_underline.color == CommonColor.BLUE
para_cursor.gotoEnd(False)