Draw Direct Shape Corner and Caps

The ooodev.format.draw.direct.line.CornerCaps class is used to modify the values seen in Fig. 853 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.line import CornerCaps, LineJoint, LineCap


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)

        rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
        style = CornerCaps(
            corner_style=LineJoint.MIDDLE,
            cap_style=LineCap.SQUARE,
        )
        style.apply(rect.component)

        f_style = CornerCaps.from_obj(rect.component)
        assert f_style is not None
        assert f_style.prop_corner_style == LineJoint.MIDDLE
        assert f_style.prop_cap_style == LineCap.SQUARE

        Lo.delay(1_000)
        doc.close_doc()
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
Shape Corner and Caps Dialog

Fig. 853 Shape Corner and Caps Dialog

Add a Corner and Caps style to the shape

Adding a Corner and Caps style to the shape is done by using the CornerCaps class.

from ooodev.format.draw.direct.line import CornerCaps, LineJoint, LineCap
# ... other code

rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
style = CornerCaps(
    corner_style=LineJoint.MIDDLE,
    cap_style=LineCap.SQUARE,
)
style.apply(rect.component)

The results of the setting the shape corner and cap style can be seen in Fig. 854.

Shape Corner and Caps Dialog

Fig. 854 Shape Corner and Caps Dialog

Get Shape Corner and Caps style

We can get the corner and caps style of the shape by using the CornerCaps.from_obj() method.

from ooodev.format.draw.direct.line import CornerCaps
# ... other code

# get the properties from the shape
f_style = CornerCaps.from_obj(rect.component)
assert f_style.prop_corner_style == LineJoint.MIDDLE
assert f_style.prop_cap_style == LineCap.SQUARE