Write Direct Paragraph DropCaps Class

Overview

The ooodev.format.writer.direct.para.drop_caps.DropCaps class can apply the same formatting as Writer’s Drop Caps Dialog, Fig. 955.

Note: DropCaps class uses Dispatch Commands. This means the DropCaps class is not suitable in Headless mode.

Drop Caps dialog screenshot

Fig. 955 Drop Caps dialog screenshot

Setting the style

General function used to run these examples.

from ooodev.office.write import Write
from ooodev.utils.color import CommonColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.writer.direct.para.drop_caps import DropCaps, StyleCharKind

def main() -> int:
    p_txt = (
        "To Sherlock Holmes she is always THE woman. I have seldom heard"
        " him mention her under any other name. In his eyes she eclipses"
        " and predominates the whole of her sex. It was not that he felt"
        " any emotion akin to love for Irene Adler. All emotions, and that"
        " one particularly, were abhorrent to his cold, precise but"
        " admirably balanced mind. He was, I take it, the most perfect"
        " reasoning and observing machine that the world has seen, but as a"
        " lover he would have placed himself in a false position. He never"
        " spoke of the softer passions, save with a gibe and a sneer. They"
        " were admirable things for the observer--excellent for drawing the"
        " veil from men's motives and actions. But for the trained reasoner"
        " to admit such intrusions into his own delicate and finely"
        " adjusted temperament was to introduce a distracting factor which"
        " might throw a doubt upon all his mental results. Grit in a"
        " sensitive instrument, or a crack in one of his own high-power"
        " lenses, would not be more disturbing than a strong emotion in a"
        " nature such as his. And yet there was but one woman to him, and"
        " that woman was the late Irene Adler, of dubious and questionable memory."
    )

with Lo.Loader(Lo.ConnectSocket()):
    doc = Write.create_doc()
    GUI.set_visible(True, doc)
    Lo.delay(500)
    GUI.zoom(GUI.ZoomEnum.ENTIRE_PAGE)

    cursor = Write.get_cursor(doc)
    dc = DropCaps(count=1)
    Write.append_para(cursor=cursor, text=p_txt, styles=[dc])

    Lo.delay(1_000)
    Lo.close_doc(doc)
return 0
if __name__ == “__main__”:

SystemExit(main())

Examples

Simple Drop Caps

cursor = Write.get_cursor(doc)
dc = DropCaps(count=1)
Write.append_para(cursor=cursor, text=p_txt, styles=[dc])
Drop Caps screenshot

Fig. 956 Drop Caps screenshot

Drop Caps dialog screenshot

Fig. 957 Drop Caps dialog screenshot

Apply to Whole Word

cursor = Write.get_cursor(doc)
dc = DropCaps(count=1, whole_word=True)
Write.append_para(cursor=cursor, text=p_txt, styles=[dc])
Drop Caps screenshot

Fig. 958 Drop Caps screenshot

Drop Caps dialog screenshot

Fig. 959 Drop Caps dialog screenshot

Increase Drop Caps Spacing

cursor = Write.get_cursor(doc)
dc = DropCaps(count=1, style=StyleCharKind.DROP_CAPS, spaces=5.0)
Write.append_para(cursor=cursor, text=p_txt, styles=[dc])
Drop Caps screenshot

Fig. 960 Drop Caps screenshot

Drop Caps dialog screenshot

Fig. 961 Drop Caps dialog screenshot

Get the Drop Caps Style from a Paragraph

Continuing from the code example above, we can get the Drop Caps from the document.

A paragraph cursor object is used to select the first paragraph in the document. The paragraph cursor is then used to get the style.

# ... other code
para_cursor = Write.get_paragraph_cursor(cursor)
para_cursor.gotoPreviousParagraph(False)
para_cursor.gotoEndOfParagraph(True)

dc = DropCaps.from_obj(para_cursor)
assert dc.prop_inner.prop_count == 1