1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
14 from com
.sun
.star
.awt
.FontWeight
import BOLD
15 from com
.sun
.star
.style
.BreakType
import PAGE_AFTER
16 from com
.sun
.star
.style
.ParagraphAdjust
import CENTER
18 NEW_STYLE_NAME
= "myheading"
21 def create_style(component
):
22 properties
= component
.createInstance("com.sun.star.style.ParagraphStyle")
23 properties
.setPropertyValue("CharFontName", "Liberation Sans")
24 print("set name of the font to 'Liberation Sans'")
26 properties
.setPropertyValue("CharHeight", float(36))
27 print("Change the height of th font to 36")
29 properties
.setPropertyValue("CharWeight", float(BOLD
))
30 print("set the font attribute 'Bold'")
32 properties
.setPropertyValue("CharAutoKerning", True)
33 print("set the paragraph attribute 'AutoKerning'")
35 properties
.setPropertyValue("ParaAdjust", CENTER
)
36 print("set the paragraph adjust to LEFT")
38 properties
.setPropertyValue("ParaFirstLineIndent", 0)
39 print("set the first line indent to 0 cm")
41 properties
.setPropertyValue("BreakType", PAGE_AFTER
)
42 print("set the paragraph attribute Breaktype to PageAfter")
44 # insert the new Paragraph style in the Paragraph style collection
45 style_families
= component
.getStyleFamilies()
46 paragraph_style_col
= style_families
["ParagraphStyles"]
47 paragraph_style_col
[NEW_STYLE_NAME
] = properties
48 print("create new paragraph style, with the values from the Propertyset")
51 def apply_style(component
):
52 text_range
= component
.getText().getStart()
53 # change the value from the property 'ParaStyle' to apply the Paragraph style
54 # To run the sample with StarOffice 5.2 you'll have to change
55 # 'ParaStyleName' to 'ParaStyle' in the next line
56 text_range
.setPropertyValue("ParaStyleName", NEW_STYLE_NAME
)
57 print("apply the new paragraph style")
63 remote_context
= officehelper
.bootstrap()
64 srv_mgr
= remote_context
.getServiceManager()
66 print("Can't create a desktop. No connection, no remote office servicemanager available!")
68 desktop
= srv_mgr
.createInstanceWithContext("com.sun.star.frame.Desktop", remote_context
)
76 desktop
= get_desktop()
81 doc
= desktop
.loadComponentFromURL("private:factory/swriter", "_blank", 0, tuple())
91 if __name__
== "__main__":
94 # vim: set shiftwidth=4 softtabstop=4 expandtab: