Draw Direct Shape Position Size - Adapt
The ooodev.format.draw.direct.position_size.position_size.Adapt
class is used to modify the values seen in Fig. 862 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.position_size.position_size import Adapt
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = DrawDoc(Draw.create_draw_doc())
doc.set_visible()
Lo.delay(500)
doc.zoom(ZoomKind.ZOOM_75_PERCENT)
slide = doc.get_slide()
width = 36
height = 36
x = round(width / 2)
y = round(height / 2)
text = slide.draw_text(msg="Hello World", x=x, y=y, width=width, height=height)
style = Adapt(fit_height=True, fit_width=True)
style.apply(text.component)
f_style = Adapt.from_obj(text.component)
assert f_style is not None
Lo.delay(1_000)
doc.close_doc()
return 0
if __name__ == "__main__":
raise SystemExit(main())
Set Adaption of a Shape
Setting Adapt of the shape is done by using the Adapt
class.
from ooodev.format.draw.direct.position_size.position_size import Adapt
# ... other code
text = slide.draw_text(
msg="Hello World", x=x, y=y, width=width, height=height
)
style = Adapt(fit_height=True, fit_width=True)
style.apply(text.component)
The results of the setting the shape adaption can be seen in Fig. 861.
Note
Adapt only applies to text shapes.
Get Shape Adapt
We can get the Adapt properties of the shape by using the Adapt.from_obj()
method.
from ooodev.format.draw.direct.position_size.position_size import Adapt
# ... other code
# get the properties from the shape
f_style = Adapt.from_obj(text.component)
assert f_style is not None