Write Direct Paragraph Indent & Spacing
Overview
Writer has a Indents & spacing dialog tab.
The ooodev.format.writer.direct.para.indent_space.Indent
, ooodev.format.writer.direct.para.indent_space.Spacing
,
and ooodev.format.writer.direct.para.indent_space.LineSpacing
classes are used to set the indent, spacing, and line spacing of a paragraph.
Setup
General function used to run these examples.
from ooodev.office.write import Write
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.writer.direct.para.indent_space import Indent, Spacing, ModeKind, LineSpacing
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)
indent = Indent(before=22.0, after=20.0, first=8.0)
Write.append_para(cursor=cursor, text=p_txt, styles=[indent])
Write.append_para(cursor=cursor, text=p_txt)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
sys.exit(main())
Indent Class
The ooodev.format.writer.direct.para.indent_space.Indent
class is used to set the indent of a paragraph.
Example
# ... other code
indent = Indent(before=22.0, after=20.0, first=8.0)
Write.append_para(cursor=cursor, text=p_txt, styles=[indent])
Write.append_para(cursor=cursor, text=p_txt)
Spacing Class
The ooodev.format.writer.direct.para.indent_space.Spacing
class is used to set the spacing of a paragraph.
Example
# ... other code
spacing = Spacing(above=8.0, below=10.0)
Write.append_para(cursor=cursor, text=p_txt, styles=[spacing])
Write.append_para(cursor=cursor, text=p_txt)
LineSpacing Class
The ooodev.format.writer.direct.para.indent_space.LineSpacing
class is used to set the spacing of a paragraph.
Example
# ... other code
ln_spc = LineSpacing(mode=ModeKind.PROPORTIONAL, value=85)
Write.append_para(cursor=cursor, text=p_txt, styles=[ln_spc])
Write.append_para(cursor=cursor, text=p_txt)
Other Examples
Apply to start of document
See also: 6.4 Applying Styles to Paragraphs (and Characters).
# ... other code
# get the XTextRange of the document
xtext_range = doc.getText().getStart()
# Created the spacing values apply them to the text range.
ln_spc = LineSpacing(mode=ModeKind.PROPORTIONAL, value=85)
indent = Indent(before=8.0, after=8.0, first=8.0)
Styler.apply(xtext_range, ln_spc, indent)
cursor = Write.get_cursor(doc)
Write.append_para(cursor=cursor, text=p_txt)
Write.append_para(cursor=cursor, text=p_txt)
Resetting paragraph styles
Restting paragraph styles is done by applying the Para.default
styles to the cursor
as seen in Resetting Paragraph Style to Default.
from ooodev.format.writer.style import Para as StylePara
# ... other code
# get the XTextRange of the document
xtext_range = doc.getText().getStart()
# Created the spacing values apply them to the text range.
ln_spc = LineSpacing(mode=ModeKind.PROPORTIONAL, value=85)
indent = Indent(before=8.0, after=8.0, first=8.0)
Styler.apply(xtext_range, ln_spc, indent)
cursor = Write.get_cursor(doc)
Write.append_para(cursor=cursor, text=p_txt)
# reset the paragraph styles
StylePara.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)