You can download all the artefacts included in this comment from Bug 158728: Feature Request: Add a facility to create a `ott’ template that includes ALL the “default” style definitions; .
You can also download vanilla-odt-styles.pdf. (I was not able to upload the pdf
in this thread file due to restriction on attachment sizes)
The attached file vanilla-odt-styles.odt
contains all vanilla styles available on my LO installation
vanilla-odt-styles.odt (60.4 KB)
The odt
file contains
- a TOC of style families and associated styles
- an alphabetical index of style families and associated styles
The above odt
file is created in Safe Mode
, on following version of LibreOffice
Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 2a217a80bf383ddab0a5e0959ab2fd907dfd3406
CPU threads: 4; OS: Linux 6.4; UI render: default; VCL: gtk3
Locale: en-IN (en_IN); UI: en-US
Calc: threaded
Here is a Basic
script used to create the above odt
file … The main entry point is CreateODTFileWithAllFactoryStyles
. (Link: https://github.com/kjambunathan/org-mode-ox-odt/blob/eaef4ea87d671fbf601ba3f3aa6784931eccd59f/contrib/odt/LibreOffice/src/OrgModeUtilities.bas#L287)
Sub CreateIndexMark(oText, oCursor, bodyText, primaryKey, markEntry, alphaIndex)
oText.insertString( oCursor, bodyText, True )
' Create Index Mark
indexMark = ThisComponent.createInstance("com.sun.star.text.DocumentIndexMark")
indexMark.PrimaryKey = primaryKey
' markEntry = bodyText
indexMark.setMarkEntry(markEntry)
' Insert the Index Mark
oText.InsertTextContent(oCursor, indexMark, False)
' No more text range
oCursor.collapseToEnd()
End Sub
Function RepeatText(text, times)
bigText = ""
For i = 0 To times
bigText = bigText & text
Next i
RepeatText = bigText
End Function
Function AnchoringParaText(i, Optional n)
text = ""
Select Case i
Case 0:
text = " xxxxxxxx yyyyyyyy"
If IsMissing(n) Then
n = 9
End If
Case 1:
text = " aaaaaaaa bbbbbbbb"
If IsMissing(n) Then
n = 15
End If
Case Else
text = "Id amet, velit fugiat sunt mollit dolor. Fugiat laborum deserunt cillum aliqua magna voluptate mollit. Nulla in qui ad elit, duis sit sit. Dolor et cupidatat in eiusmod ex. Occaecat culpa dolor et magna sed do culpa. "
If IsMissing(n) Then
n = 1
End If
End Select
AnchoringParaText = RepeatText(text, n)
End Function
Sub AddPageNumber
Doc = ThisComponent
PageNumber = Doc.createInstance("com.sun.star.text.textfield.PageNumber")
PageNumber.NumberingType = com.sun.star.style.NumberingType.ARABIC
PageStyles = Doc.StyleFamilies.getByName("PageStyles")
StdPage = PageStyles("Default")
StdPage.FooterIsOn = True
FooterCursor = StdPage.FooterTextLeft.Text.createTextCursor()
FooterCursor.ParaAdjust = com.sun.star.style.ParagraphAdjust.CENTER
StdPage.FooterTextLeft.Text.insertTextContent(FooterCursor, PageNumber, False)
End Sub
Sub ApplyTableTemplate(templateName)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Template"
args1(0).Value = templateName
args1(1).Name = "Family"
args1(1).Value = 32
dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args1())
End Sub
Sub ApplyTableTemplates
inDoc = ThisComponent
oTables = inDoc.getTextTables()
If oTables.hasElements() Then
For i = 0 To oTables.getCount() - 1
oTable = oTables.getByIndex(i)
inDoc.getCurrentController().select(oTable)
ApplyTableTemplate(oTable.Name)
Next
End If
End Sub
Sub CreateODTFileWithAllFactoryStyles
Dim inDoc
Dim interactive
' BasicLibraries.loadLibrary("XrayTool")
' LoadMriLibrary()
' BasicLibraries.loadLibrary("MRILib")
Dim oProps(0) as New com.sun.star.beans.PropertyValue
oProps(0).Name = "Hidden"
oProps(0).Value = False
inDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() )
fileURL = ConvertToURL("/home/kjambunathan/vanilla-styles.odt")
AddPageNumber()
StyleFamilies = inDoc.StyleFamilies
ParagraphStyles = StyleFamilies.getByName("ParagraphStyles")
' Create a Paragraph Style for Family Style Names and Insert it in
' to the StyleSheet
myFamilyStyle = inDoc.createInstance("com.sun.star.style.ParagraphStyle")
myFamilyStyle.Name = "My Family Style"
myFamilyStyle.CharColor = RGB(255, 0, 0)
myFamilyStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
ParagraphStyles.insertByName("My Family Style", myFamilyStyle)
' Create a Paragraph Style for Style Names and Insert it in
' to the StyleSheet
myStyle = inDoc.createInstance("com.sun.star.style.ParagraphStyle")
myStyle.Name = "My Style"
myStyle.CharColor = RGB(6, 154, 46)
myStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
ParagraphStyles.insertByName("My Style", myStyle)
' Obtain Text and Text Cursor
oText = inDoc.getText()
oCursor = oText.createTextCursor()
' Create and Configure TOC
toc = inDoc.createInstance("com.sun.star.text.ContentIndex")
toc.Title = "Table of Style Families & Styles"
toc.CreateFromOutline = False
toc.CreateFromLevelParagraphStyles = True
oText.insertTextContent(oCursor, toc, False)
oLevelParagraphStyles = toc.LevelParagraphStyles
oLevelParagraphStyles.replaceByIndex(0, Array("My Family Style"))
oLevelParagraphStyles.replaceByIndex(1, Array("My Style"))
' Create an Alphbhetical Index of Style Families & Style Names
' userIndex = inDoc.createInstance("com.sun.star.text.UserIndex")
' userIndex.CreateFromMarks = True
alphaIndex = ThisComponent.createInstance("com.sun.star.text.DocumentIndex")
alphaIndex.UseCombinedEntries = False
oText.insertTextContent(oCursor, alphaIndex, FALSE)
' Create Dummy User Index Marks
styleFamilyNames = inDoc.StyleFamilies.getElementNames()
' For each StyleFamily
For i = LBound(styleFamilyNames) To UBound(styleFamilyNames)
styleFamilyName = styleFamilyNames(i)
styleNames = inDoc.StyleFamilies.getByName(styleFamilyName).getElementNames()
oText.insertString( oCursor, "STYLE FAMILY: " & styleFamilyName, False )
oCursor.ParaStyleName = "My Family Style"
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCursor.ParaStyleName = "Standard"
' For each StyleName in StyleFamily
For j = LBound(styleNames) To UBound(styleNames)
styleName = styleNames(j)
xxx = inDoc.StyleFamilies.getByName(styleFamilyName).getByName(styleName)
oCursor.CharWeight = com.sun.star.awt.FontWeight.NORMAL
' Print styleFamilyName & ": " & styleName
' oCursor.CharStyleName = "Standard"
Select Case styleFamilyName
Case "PageStyles":
Case Else
CreateIndexMark(oText, oCursor, "", styleFamilyName, styleName, alphaIndex)
End Select
Select Case styleFamilyName
Case "CharacterStyles":
' Insert Style Name
oCursor.CharStyleName = styleName
oCursor.ParaStyleName = "My Style"
oText.insertString( oCursor, styleName, False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCursor.CharStyleName = "Standard"
Case "ParagraphStyles":
' Insert Style Name
oCursor.ParaStyleName = "My Style"
oText.insertString( oCursor, styleName, False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCursor.ParaStyleName = "Standard"
' Insert a big Paragraph
oCursor.ParaStyleName = styleName
oText.insertString( oCursor, AnchoringParaText(2), False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCursor.ParaStyleName = "Standard"
Case "NumberingStyles":
bodyText = styleName
' Insert Style Name
oCursor.ParaStyleName = "My Style"
oText.insertString( oCursor, bodyText, False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCursor.ParaStyleName = "Standard"
nCount = xxx.NumberingRules.getCount()
For k = 0 To nCount - 1
oCursor.NumberingLevel = k
oCursor.NumberingStyleName = styleName
oCursor.CharColor = RGB(0,0,255)
bodyText = styleName & " [Level " & k & "]"
oText.insertString( oCursor, bodyText, True )
' oCursor.CharStyleName = "Standard"
oCursor.collapseToEnd()
oCursor.CharStyleName = "Standard"
bodyText = " " & AnchoringParaText(2)
oText.insertString( oCursor, bodyText, False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
Next k
oCursor.NumberingLevel = 0
oCursor.NumberingStyleName = ""
oCursor.ParaStyleName = "Standard"
Case "CellStyles1":
oTable = inDoc.createInstance( "com.sun.star.text.TextTable" )
oTable.initialize(1, 1) 'Single Cell
oTable.TableName = styleName
oInsertPoint = ThisComponent.Text.getEnd()
oInsertPoint.getText().insertTextContent(oInsertPoint , oTable, False)
oCursor.ParaStyleName = "My Style"
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oTableCell = oTable.getCellByPosition(0,0)
oTableCell.setString(styleName & " {" & styleFamilyName & "}")
' TODO: Don't know how to associate oTableCell with the corresponding xxx
Case "TableStyles":
oCursor.ParaStyleName = "My Style"
oText.insertString( oCursor, styleName, False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCursor.ParaStyleName = "Standard"
oTable = inDoc.createInstance( "com.sun.star.text.TextTable" )
oTable.initialize(6, 6) 'Two rows, three columns
oTable.TableName = styleName
' Setting "TableTemplateName" doesn't give fancy tables
' oTable.setPropertyValue("TableTemplateName", styleName)
oInsertPoint = ThisComponent.Text.getEnd()
oInsertPoint.getText().insertTextContent(oInsertPoint , oTable, False)
' Invoking `autoformat' gives a fancy table, but
' the Table Template definition doesn't land in
' the `styles.xml'.
' oTable.autoformat(styleName)
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oTableCell = oTable.getCellByPosition(0,0)
oTableCell.setString(styleName & " {" & styleFamilyName & "}")
Case "FrameStyles":
' Push the style
oCursor.ParaStyleName = "My Style"
' Caption the Frame, and style it with 'My Style'
' Emit LineBreaks around the caption to create some breathing space.
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.LINE_BREAK, False )
oText.insertString( oCursor, styleName & " {" & styleFamilyName & "}", False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.LINE_BREAK, False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
' Pop the style
oCursor.ParaStyleName = "Standard"
' Insert some text before the Frame
bodyText = "^^^PARA BEGIN: " & styleName & AnchoringParaText(0) & RepeatText("+", 8)
oText.insertString( oCursor, bodyText , False )
' Create and Insert the Text Frame
oFrame = ThisComponent.createInstance( "com.sun.star.text.TextFrame" )
oText.insertTextContent( oCursor, oFrame, false )
' Insert some text after the Frame
bodyText = RepeatText("-", 8) + AnchoringParaText(1) & styleName & " :PARA END$$$$"
oText.insertString(oCursor, bodyText, False)
' Insert Paragraph Break
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
' Configure the Frame
oFrame.FrameStyleName = styleName
oFrame.Name = styleName
If j = -1 Then
xray oFrame
End If
oFrame.Width = 4000
' Fill the Frame
annotation = ""
If oFrame.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH Then
annotation = annotation & " [" & styleName & "@at-paragraph" & "]"
ElseIf oFrame.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER Then
annotation = annotation & " [" & styleName & "@as-character" & "]"
ElseIf oFrame.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE Then
annotation = annotation & " [" & styleName & "@at-page" & "]"
ElseIf oFrame.AnchorType = com.sun.star.text.TextContentAnchorType.AT_FRAME Then
annotation = annotation & " [" & styleName & "@at-frame" & "]"
ElseIf oFrame.AnchorType = com.sun.star.text.TextContentAnchorType.AT_CHARACTER Then
annotation = annotation & " [" & styleName & "@at-character" & "]"
Else
MsgBox "This shouldn't happen"
End If
oFrame.BackColor = RGB(255, 255, 215)
oFrame.Text.String = RepeatText(annotation, 2)
Case "PageStyles":
oText.insertString(oCursor, "" & styleName & " {" & styleFamilyName & "}", False)
oCursor.PageDescName = styleName
oCursor.ParaStyleName = "My Style"
oCursor.breakType = com.sun.star.style.BreakType.PAGE_BEFORE
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCursor.ParaStyleName = "Standard"
oCursor.PageDescName = "Standard"
CreateIndexMark(oText, oCursor, "", styleFamilyName, styleName, alphaIndex)
' oText.insertString( oCursor, styleName & " {" & styleFamilyName & "}", False )
' oCursor.ParaStyleName = "My Style"
Case Else
' MsgBox "You haven't handled " & styleName & "[" & styleFamilyName & "]"
oCursor.ParaStyleName = "My Style"
oText.insertString( oCursor, styleName & " {" & styleFamilyName & "}", False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
End Select
Next j
oText.insertString(oCursor, "--- END STYLE FAMILY `" & styleFamilyName & "' ---", False)
oCursor.breakType = com.sun.star.style.BreakType.PAGE_AFTER
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
Next i
ApplyTableTemplates()
If (inDoc.isModified() AND inDoc.hasLocation() AND (Not inDoc.isReadOnly())) Then
inDoc.store()
End If
Dim xProps(0) as New com.sun.star.beans.PropertyValue
xProps(0).Name = "Overwrite"
xProps(0).Value = True
' inDoc.storeAsUrl(fileURL, xProps)
toc.update()
alphaIndex.update()
End Sub