Write Direct Character FontPosition Class
The ooodev.format.writer.direct.char.font.FontPosition
class is used to set the position of the character.
The class gives you the same options as Writer’s Positon Dialog, but without the dialog. as seen in Fig. 923.
Setup
from ooodev.format.writer.direct.char.font import FontPosition
from ooodev.format.writer.direct.char.font import CharSpacingKind
from ooodev.office.write import Write
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
with Lo.Loader(Lo.ConnectPipe()):
doc = Write.create_doc()
GUI.set_visible(doc=doc)
Lo.delay(300)
GUI.zoom(GUI.ZoomEnum.ZOOM_150_PERCENT)
cursor = Write.get_cursor(doc)
fp_style = FontPosition().superscript
cursor = Write.get_cursor(doc)
Write.append(cursor, "hello")
Write.style(pos=0, length=1, styles=[fp_style], cursor=cursor)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Examples
Set Character to Superscript
Setting a character to superscript can be done by using the superscript property of the FontPosition class.
# ... other code
cursor = Write.get_cursor(doc)
fp_style = FontPosition().superscript
cursor = Write.get_cursor(doc)
Write.append(cursor, "hello")
Write.style(pos=0, length=1, styles=[fp_style], cursor=cursor)
Set Character to Subscript
Setting a character to subscript can be done by using the subscript property of the FontPosition class.
# ... other code
cursor = Write.get_cursor(doc)
fp_style = FontPosition().subscript
cursor = Write.get_cursor(doc)
Write.append(cursor, "hello")
Write.style(pos=4, length=1, styles=[fp_style], cursor=cursor)
Set Character to Normal
Setting a character to normal is done by using the normal property of the FontPosition class.
# ... other code
cursor = Write.get_cursor(doc)
fp_style = FontPosition().subscript
cursor = Write.get_cursor(doc)
Write.append(cursor, "hello")
Write.style(pos=4, length=1, styles=[fp_style], cursor=cursor)
# set back to normal position by using the normal property
Write.style(pos=4, length=1, styles=[fp_style.normal], cursor=cursor)
Set Character Rotation
Setting characters rotation can be done by using one of the rotation properties of the FontPosition class or by using the rotation argument in the constructor.
# ... other code
cursor = Write.get_cursor(doc)
fp_style = FontPosition().rotation_270
# alternative
# fp_style = FontPosition(rotation=270)
cursor = Write.get_cursor(doc)
Write.append(cursor, "Hello", styles=[fp_style])
Write.append(cursor, "World", styles=[fp_style.rotation_90])
Set Character Spacing
Character Spacing Tight
# ... other code
cursor = Write.get_cursor(doc)
fp_style = FontPosition(spacing=CharSpacingKind.TIGHT, pair=False)
cursor = Write.get_cursor(doc)
Write.append(cursor, "Hello", styles=[fp_style])
Character Spacing Very Loose
# ... other code
cursor = Write.get_cursor(doc)
fp_style = FontPosition(spacing=CharSpacingKind.VERY_LOOSE, pair=True)
cursor = Write.get_cursor(doc)
Write.append(cursor, "Hello", styles=[fp_style])