Created
February 11, 2025 11:18
-
-
Save shantanuo/0589d6b08137e9e755dc6d26eddbd008 to your computer and use it in GitHub Desktop.
LIbreoffice writer Style to format Marathi text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub myStyle() | |
' Get access to the document | |
Dim document As Object | |
Dim styleFamilies As Object | |
Dim paraStyles As Object | |
Dim newStyle As Object | |
Dim styleName As String | |
Dim cursor As Object | |
document = ThisComponent | |
' Define new style name | |
styleName = "MyJustifiedStyle" | |
' Get access to paragraph styles | |
styleFamilies = document.StyleFamilies | |
paraStyles = styleFamilies.getByName("ParagraphStyles") | |
' Check if style already exists, otherwise create it | |
If Not paraStyles.hasByName(styleName) Then | |
newStyle = document.createInstance("com.sun.star.style.ParagraphStyle") | |
newStyle.ParentStyle = "Default Paragraph Style" ' Inherit properties | |
' Paragraph formatting | |
newStyle.ParaAdjust = com.sun.star.style.ParagraphAdjust.BLOCK ' Justified alignment | |
newStyle.ParaIsHyphenation = True ' Enable automatic hyphenation | |
newStyle.ParaFirstLineIndent = 700 ' First line indent (0.5 cm, in 1/100 mm) | |
newStyle.ParaBottomMargin = 500 ' Set "Below Paragraph" spacing to 0.50 cm | |
newStyle.ParaContextMargin = True ' "Do not add space between paragraphs of the same style" | |
' Apply font settings | |
newStyle.CharFontNameComplex = "Shobhika Regular" ' Apply to Complex (CTL) text only | |
newStyle.CharHeightComplex = 12 ' Font size 12 pt for Complex text | |
paraStyles.insertByName(styleName, newStyle) ' Add new style | |
End If | |
' Get the text body and select all text | |
cursor = document.Text.createTextCursor() | |
cursor.gotoStart(False) ' Move cursor to start | |
cursor.gotoEnd(True) ' Select entire document | |
' Apply the new paragraph style | |
cursor.ParaStyleName = styleName | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment