Write Direct Shape Area Hatch

The ooodev.format.writer.direct.shape.area.Hatch class is used to modify the values seen in Fig. 838 of a shape.

Setup

import uno
from ooodev.format.writer.direct.shape.area import Hatch as ShapeHatch
from ooodev.format.writer.direct.shape.area import PresetHatchKind
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.office.write import Write
from ooodev.office.draw import Draw


def main() -> int:
    """Main Entry Point"""

    with Lo.Loader(Lo.ConnectPipe()):
        doc = Write.create_doc()
        GUI.set_visible(doc=doc)
        Lo.delay(300)
        GUI.zoom(GUI.ZoomEnum.ENTIRE_PAGE)

        page = Write.get_draw_page(doc)
        rect = Draw.draw_rectangle(slide=page, x=10, y=10, width=100, height=100)
        style = ShapeHatch.from_preset(preset=PresetHatchKind.GREEN_30_DEGREES)
        style.apply(rect)
        page.add(rect)

        f_style = ShapeHatch.from_obj(rect)
        assert f_style

        Lo.delay(1_000)

        Lo.close_doc(doc)

    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Fill Shape Hatch

Add a fill hatch to the shape

Adding a fill hatch to the shape is done by using the ShapeHatch class. The ShapeHatch class has a method from_preset() takes a preset as a parameter. The PresetHatchKind class is used to get the preset of the hatch.

from ooodev.format.writer.direct.shape.area import Hatch as ShapeHatch
# ... other code

style = ShapeHatch.from_preset(preset=PresetHatchKind.GREEN_30_DEGREES)
style.apply(rect)
page.add(rect)

The results of the setting the shape fill hatch can be seen in Fig. 1005.

Shape with fill Hatch

Fig. 1005 Shape with fill Hatch

Get Shape Hatch

We can get the fill hatch of the shape by using the ShapeHatch.from_obj() method.

from ooodev.format.writer.direct.shape.area import Hatch as ShapeHatch
# ... other code

# get the gradient from the shape
f_style = ShapeHatch.from_obj(rect)
assert f_style