Draw Direct Shape Text - Spacing
The ooodev.format.draw.direct.text.text.Spacing
class is used to modify the values seen in Fig. 869 of a shape.
Setup
from __future__ import annotations
import uno
from ooodev.draw import Draw, DrawDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.format.draw.direct.text.text import Spacing as TextSpacing
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = DrawDoc(Draw.create_draw_doc())
doc.set_visible()
Lo.delay(700)
doc.zoom(ZoomKind.ZOOM_75_PERCENT)
slide = doc.get_slide()
width = 50
height = 50
x = 10
y = 10
rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
cursor = rect.get_shape_text_cursor()
cursor.append_para("Hello World!")
txt_spacing = TextSpacing(left=2.5, right=0.75, top=2.0, bottom=1.7)
txt_spacing.apply(rect.component)
f_style = TextSpacing.from_obj(rect.component)
assert f_style is not None
# rect.component.TextContourFrame = True # type: ignore
# rect.component.TextFitToSize = TextFitToSizeType.PROPORTIONAL # type: ignore
Lo.delay(1_000)
doc.close_doc()
return 0
if __name__ == "__main__":
raise SystemExit(main())
Set Spacing of Shape Text
Setting spacing of the shape text is done by using the Spacing
class.
from ooodev.format.draw.direct.text.text import Spacing as TextSpacing
# ... other code
rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
# ... other code
txt_spacing = TextSpacing(left=2.5, right=0.75, top=2.0, bottom=1.7)
txt_spacing.apply(rect.component)
The results of the setting the shape size can be seen in Fig. 870.
Get Shape Text Spacing
We can get the text spacing of the shape by using the TextSpacing.from_obj()
method.
from ooodev.format.draw.direct.text.text import Spacing as TextSpacing
# ... other code
# get the properties from the shape
f_style = TextSpacing.from_obj(rect.component)
assert f_style is not None