Draw Direct Shape Text Character
Character like Draw Direct Shape Text Paragraph formatting can be applied by getting the shape text cursor and using the append()
, append_para()
or
any method that supports setting styles.
This is similar behavior to Writer Direct Character Text. See Writer Format Direct Character for more information.
Code Example
from __future__ import annotations
import uno
from ooodev.draw import Draw, DrawDoc, ZoomKind
from ooodev.format.draw.direct.position_size.position_size import Position
from ooodev.format.writer.direct.char.font import Font, FontEffects
from ooodev.format.writer.direct.para.indent_space import Indent, Spacing
from ooodev.format.writer.direct.char.highlight import Highlight
from ooodev.utils.color import StandardColor
from ooodev.loader.lo import Lo
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 = 100
height = 80
x = 0
y = 0
rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
pos = Position(0, 0)
pos.apply(rect.component)
cursor = rect.get_shape_text_cursor()
cursor.append_para(
"Hello World!",
[
Font(b=True, color=StandardColor.GREEN),
FontEffects(color=StandardColor.RED),
Highlight(color=StandardColor.YELLOW),
Indent(first=3.5),
Spacing(below=2.5),
],
)
cursor.append_para(
"Wonderful Day!",
[
Font(b=False, i=True, color=StandardColor.BLUE_DARK2),
Highlight(color=StandardColor.GREEN_LIGHT1),
Spacing(below=2.5),
],
)
Lo.delay(1_000)
doc.close_doc()
return 0
if __name__ == "__main__":
raise SystemExit(main())
The results of running the above code is seen in Fig. 850.