Chart2 Direct Title/Subtitle Font Effects
Overview
The style_font_effect()
method is used to apply font effects to the Title and Subtitle of a Chart.
as Fig. 818 Font Effects Dialog, but without the dialog.
Setup
General setup for this example.
from __future__ import annotations
from pathlib import Path
import uno
from ooo.dyn.awt.gradient_style import GradientStyle
from ooo.dyn.awt.font_underline import FontUnderlineEnum
from ooodev.calc import CalcDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.utils.color import StandardColor
from ooodev.utils.data_type.color_range import ColorRange
from ooodev.format.inner.direct.write.char.font.font_effects import FontLine
def main() -> int:
with Lo.Loader(connector=Lo.ConnectPipe()):
fnm = Path.cwd() / "tmp" / "piechart.ods"
doc = CalcDoc.open_doc(fnm=fnm, visible=True)
Lo.delay(500)
doc.zoom(ZoomKind.ZOOM_100_PERCENT)
sheet = doc.sheets[0]
sheet["A1"].goto()
chart_table = sheet.charts[0]
chart_doc = chart_table.chart_doc
_ = chart_doc.style_border_line(
color=StandardColor.PURPLE_DARK1,
width=0.7,
)
_ = chart_doc.style_area_gradient(
step_count=64,
style=GradientStyle.SQUARE,
angle=45,
grad_color=ColorRange(
StandardColor.BLUE_DARK1,
StandardColor.PURPLE_LIGHT2,
),
)
title = chart_doc.get_title()
if title is None:
raise ValueError("Title not found")
title.style_font_effect(
color=StandardColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE),
shadowed=True,
)
Lo.delay(1_000)
doc.close()
return 0
if __name__ == "__main__":
SystemExit(main())
Apply the font effects to the data labels
The style_font_effect()
method is used to apply the font effects to the Title and Subtitle.
Before formatting the chart is seen in Fig. 832.
Apply to Title
from ooo.dyn.awt.font_underline import FontUnderlineEnum
from ooodev.format.inner.direct.write.char.font.font_effects import FontLine
# ... other code
title = chart_doc.get_title()
if title is None:
raise ValueError("Title not found")
title.style_font_effect(
color=StandardColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE),
shadowed=True,
)
Running the above code will produce the following output in Fig. 636 and Fig. 637.
Apply to Subtitle
from ooo.dyn.awt.font_underline import FontUnderlineEnum
from ooodev.format.inner.direct.write.char.font.font_effects import FontLine
# ... other code
sub_title = chart_doc.first_diagram.get_title()
if sub_title is None:
raise ValueError("Title not found")
sub_title.style_font_effect(
color=StandardColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE),
shadowed=True,
)
Running the above code will produce the following output in Fig. 638.