Unique page styles
This commit is contained in:
parent
15a423b3c4
commit
59c5e6396c
5 changed files with 271 additions and 40 deletions
38
Addons.xcu
38
Addons.xcu
|
@ -238,29 +238,6 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node oor:name="Submenu">
|
||||
<node oor:name="booksMenu" oor:op="replace">
|
||||
<prop oor:name="Title" oor:type="xs:string">
|
||||
<value xml:lang="en">Books</value>
|
||||
<value xml:lang="ru">Книги</value>
|
||||
</prop>
|
||||
<node oor:name="Submenu">
|
||||
<node oor:name="UniquePageStylesItem" oor:op="replace">
|
||||
<prop oor:name="URL" oor:type="xs:string">
|
||||
<value>macro:///ePublishing.Books.setUniqPageStyles</value>
|
||||
</prop>
|
||||
<prop oor:name="Target" oor:type="xs:string">
|
||||
<value>_self</value>
|
||||
</prop>
|
||||
<prop oor:name="Title" oor:type="xs:string">
|
||||
<value/>
|
||||
<value xml:lang="en">Make page styles unique</value>
|
||||
<value xml:lang="ru">Сделать стили страниц уникальными</value>
|
||||
</prop>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node oor:name="Submenu">
|
||||
<node oor:name="archiveMenu" oor:op="replace">
|
||||
<prop oor:name="Title" oor:type="xs:string">
|
||||
|
@ -298,6 +275,21 @@
|
|||
</node>
|
||||
</node>
|
||||
<node oor:name="Submenu">
|
||||
<node oor:name="uniquePageStyles" oor:op="replace">
|
||||
<prop oor:name="Context" oor:type="xs:string">
|
||||
<value>com.sun.star.text.TextDocument,com.sun.star.text.WebDocument</value>
|
||||
</prop>
|
||||
<prop oor:name="Title" oor:type="xs:string">
|
||||
<value xml:lang="en">Set unique style for each page</value>
|
||||
<value xml:lang="ru">Каждой странице уникальный стиль</value>
|
||||
</prop>
|
||||
<prop oor:name="URL" oor:type="xs:string">
|
||||
<value>macro:///ePublishing.Books.setUniqPageStyles</value>
|
||||
</prop>
|
||||
<prop oor:name="Target" oor:type="xs:string">
|
||||
<value>_self</value>
|
||||
</prop>
|
||||
</node>
|
||||
<node oor:name="cleanConfigure" oor:op="replace">
|
||||
<prop oor:name="Context" oor:type="xs:string">
|
||||
<value>com.sun.star.text.TextDocument,com.sun.star.text.WebDocument</value>
|
||||
|
|
|
@ -494,15 +494,15 @@ Sub replaceParaStyle
|
|||
|
||||
End Sub
|
||||
|
||||
Function getIndex(a, v)
|
||||
Function getIndex(array As variant, value As variant) As Integer
|
||||
Dim id As Integer
|
||||
Dim nRight As Integer
|
||||
Dim nLen As Integer
|
||||
id = 0
|
||||
nRight = uBound(a)
|
||||
nLen = len(v)
|
||||
nRight = uBound(array)
|
||||
nLen = len(value)
|
||||
while id <= nRight
|
||||
if a(id) = v then
|
||||
If array(id) = value Then
|
||||
getIndex = id
|
||||
exit Function
|
||||
Else
|
||||
|
|
|
@ -1,25 +1,249 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Books" script:language="StarBasic" script:moduleType="normal">Sub markBooks3
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Books" script:language="StarBasic" script:moduleType="normal">Sub markBooks5
|
||||
End Sub
|
||||
|
||||
Sub makeUniquePages
|
||||
Sub setUniqPageStyles
|
||||
Dim pageStyleBreaks As Variant
|
||||
Dim filteredDupStyles As Variant
|
||||
pageStyleBreaks = getPageStyleBreaks()
|
||||
Dim pageCount As Integer
|
||||
Dim i As Integer
|
||||
Dim pageStyleNames() As String
|
||||
Dim pageNumbers() As Integer
|
||||
Dim pageStarts() As Object
|
||||
Dim pageCounter As Integer
|
||||
pageStyleNames = pageStyleBreaks(0)
|
||||
pageNumbers = pageStyleBreaks(1)
|
||||
pageStarts = pageStyleBreaks(2)
|
||||
'Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
pageCount = thiscomponent.currentController.pageCount
|
||||
Dim styleNames(pageCount - 1) As String
|
||||
For i = 0 To pageCount - 1
|
||||
If i = 0 Then
|
||||
|
||||
Dim fullChain(pageCount - 1) As String
|
||||
Dim dupNames() As String
|
||||
Dim dupCounters() As Integer
|
||||
Dim chainNum As Integer
|
||||
Dim pageStyleFamily As Object
|
||||
Dim pageStyle As Object
|
||||
pageStyleFamily = ThisComponent.StyleFamilies.getByName("PageStyles")
|
||||
chainNum = 0
|
||||
For pageCounter = 1 To pageCount
|
||||
If pageNumbers(chainNum) = pageCounter Then
|
||||
fullChain(pageCounter - 1) = pageStyleNames(chainNum)
|
||||
If Ubound(pageNumbers) > chainNum Then
|
||||
chainNum = chainNum + 1
|
||||
EndIf
|
||||
Else
|
||||
pageStyle = pageStyleFamily.getByName(fullChain(pageCounter - 1 - 1))
|
||||
fullChain(pageCounter - 1) = pageStyle.FollowStyle
|
||||
EndIf
|
||||
Next i
|
||||
Dim dupPosition As Integer
|
||||
dupPosition = getIndex(dupNames, fullChain(pageCounter - 1) )
|
||||
If dupPosition = -1 Then
|
||||
addToArray(dupNames, fullChain(pageCounter - 1))
|
||||
addToArray(dupCounters, 1)
|
||||
Else
|
||||
dupCounters(dupPosition) = dupCounters(dupPosition) + 1
|
||||
EndIf
|
||||
Next pageCounter
|
||||
|
||||
filteredDupStyles = filterPageStyleNames(dupNames,dupCounters)
|
||||
filteredDupStyles = createDupNames(filteredDupStyles)
|
||||
Dim duplicateNames() As String
|
||||
Dim initNames() As String
|
||||
Dim dupName As String
|
||||
duplicateNames = filteredDupStyles(2)
|
||||
initNames = filteredDupStyles(0)
|
||||
createPageStyleClones(filteredDupStyles)
|
||||
|
||||
chainNum = 0
|
||||
Dim curName As String
|
||||
Dim pageStart As Object
|
||||
Dim prevPageStyle As Object
|
||||
Dim index As Integer
|
||||
For pageCounter = 1 To pageCount
|
||||
If pageNumbers(chainNum) = pageCounter Then
|
||||
index = getIndex(initNames, pageStyleNames(chainNum))
|
||||
If index > -1 Then
|
||||
pageStart = pageStarts(chainNum)
|
||||
dupName = getDuplicate(duplicateNames(index))
|
||||
pageStart.pageDescName = dupName
|
||||
fullChain(pageCounter - 1) = dupName
|
||||
EndIf
|
||||
If Ubound(pageNumbers) > chainNum Then
|
||||
chainNum = chainNum + 1
|
||||
EndIf
|
||||
Else
|
||||
curName = fullChain(pageCounter - 1)
|
||||
index = getIndex(initNames, curName)
|
||||
If index > -1 Then
|
||||
dupName = getDuplicate(duplicateNames(index))
|
||||
prevPageStyle = pageStyleFamily.getByName(fullChain(pageCounter - 1 - 1))
|
||||
prevPageStyle.FollowStyle = dupName
|
||||
fullChain(pageCounter - 1) = dupName
|
||||
EndIf
|
||||
EndIf
|
||||
Next pageCounter
|
||||
MsgBox getTranslation(allPagesHaveUniqPageStyle)
|
||||
End Sub
|
||||
|
||||
Function getDuplicate(duplicateNames() As String) As String
|
||||
Dim index As Integer
|
||||
Dim dupName As String
|
||||
For index = LBound(duplicateNames) To Ubound(duplicateNames)
|
||||
dupName = duplicateNames(index)
|
||||
If dupName <> "" Then
|
||||
getDuplicate = dupName
|
||||
duplicateNames(index) = ""
|
||||
Exit Function
|
||||
EndIf
|
||||
Next index
|
||||
End Function
|
||||
|
||||
|
||||
Sub createPageStyleClones(filteredDupStyles As Variant)
|
||||
'Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
Dim oViewCursor As Object
|
||||
Dim initialNames() As String
|
||||
Dim dupNames() As Variant
|
||||
Dim initialName As String
|
||||
Dim style As Object
|
||||
initialNames = filteredDupStyles(0)
|
||||
dupNames = filteredDupStyles(2)
|
||||
Dim pageStyleFamily As Object
|
||||
pageStyleFamily = ThisComponent.StyleFamilies.getByName("PageStyles")
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewCursor.goToEnd(False)
|
||||
Dim index As Integer
|
||||
Dim dupInedx As Integer
|
||||
insertPageBreak()
|
||||
Dim duplicates() As String
|
||||
Dim duplicate As String
|
||||
Dim pageStyleOriginals As Integer
|
||||
Dim newStyle As Object
|
||||
For index = LBound(initialNames) To Ubound(initialNames)
|
||||
initialName = initialNames(index)
|
||||
style = pageStyleFamily.getByName(initialName)
|
||||
oViewCursor.PageDescName = style.Name
|
||||
duplicates = dupNames(index)
|
||||
For dupIndex = LBound(duplicates) To Ubound(duplicates)
|
||||
duplicate = duplicates(dupIndex)
|
||||
createPageStyleByExample(duplicate)
|
||||
newStyle = pageStyleFamily.getByName(duplicate)
|
||||
newStyle.FollowStyle = style.Name
|
||||
Next
|
||||
Next
|
||||
backspace
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Function createDupNames(dupStyles As Variant) As Variant
|
||||
Dim newDupStyles(2) As Variant
|
||||
Dim counters() As Integer
|
||||
Dim initNames() As String
|
||||
Dim initName As String
|
||||
initNames = dupStyles(0)
|
||||
counters = dupStyles(1)
|
||||
Dim newDupNames() As Variant
|
||||
Dim i As Integer
|
||||
Dim nameIt As Integer
|
||||
For i = LBound(counters) To UBound(counters)
|
||||
ReDim newNames(counters(i) - 1) As String
|
||||
addToArray(newDupNames, newNames)
|
||||
|
||||
initName = initNames(i)
|
||||
For nameIt = LBound(newNames) To UBound(newNames)
|
||||
newNames(nameIt) = createDupName(initName, newDupNames)
|
||||
newDupNames(UBound(newDupNames)) = newNames
|
||||
Next nameIt
|
||||
|
||||
Next i
|
||||
|
||||
newDupStyles(0) = initNames
|
||||
newDupStyles(1) = counters
|
||||
newDupStyles(2) = newDupNames
|
||||
createDupNames = newDupStyles
|
||||
End Function
|
||||
|
||||
Function createDupName(initName As String, newDupNames As Variant )
|
||||
Dim pageStyleFamily As Object
|
||||
pageStyleFamily = ThisComponent.StyleFamilies.getByName("PageStyles")
|
||||
Dim proposeName As String
|
||||
Dim i As Integer
|
||||
Dim postfix As String
|
||||
Dim prefixName As String
|
||||
prefixName = getPrefixName(initName)
|
||||
For i = 1 To 10000
|
||||
proposeName = prefixName & i
|
||||
If NOT pageStyleFamily.hasByName(proposeName) And Not IsInArrays(newDupNames, proposeName) Then
|
||||
createDupName = proposeName
|
||||
Exit Function
|
||||
EndIf
|
||||
Next i
|
||||
|
||||
End Function
|
||||
|
||||
Function getPrefixName(initName As String) As String
|
||||
Dim num As Integer
|
||||
Dim tmpName As String
|
||||
tmpName = Trim(initName)
|
||||
If tmpName = "" Then
|
||||
getPrefixName = ""
|
||||
Exit Function
|
||||
EndIf
|
||||
num = Asc(Right(tmpName, 1))
|
||||
Do while num >= 48 AND num <= 57
|
||||
tmpName = Trim(Left(tmpName, Len(tmpName) - 1))
|
||||
If tmpName = "" Then
|
||||
getPrefixName = ""
|
||||
Exit Function
|
||||
EndIf
|
||||
num = Asc(Right(tmpName, 1))
|
||||
Loop
|
||||
If tmpName = "Статья" Then
|
||||
Dim result As String
|
||||
result = Trim(initName) & " стр."
|
||||
getPrefixName = result
|
||||
Exit Function
|
||||
EndIf
|
||||
If Len(tmpName) > 4 AND Right(tmpName,4) = "стр." Then
|
||||
getPrefixName = tmpName
|
||||
Exit Function
|
||||
EndIf
|
||||
getPrefixName = tmpName & " "
|
||||
End Function
|
||||
|
||||
|
||||
Function IsInArrays(newDupNames As Variant, proposeName As String) As Boolean
|
||||
'Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
Dim i As Integer
|
||||
Dim names() As String
|
||||
For i = LBound(newDupNames) To Ubound(newDupNames)
|
||||
names = newDupNames(i)
|
||||
If getIndex(names, proposeName) > -1 Then
|
||||
IsInArrays = True
|
||||
Exit Function
|
||||
EndIf
|
||||
Next i
|
||||
IsInArrays = False
|
||||
End Function
|
||||
|
||||
Function filterPageStyleNames(names() As String, counters() As Integer) As Variant
|
||||
Dim i As Integer
|
||||
Dim filteredNames() As String
|
||||
Dim filteredCounters() As Integer
|
||||
For i=Lbound(counters) To Ubound(counters)
|
||||
If counters(i) > 1 Then
|
||||
addToArray(filteredNames, names(i))
|
||||
addToArray(filteredCounters, counters(i))
|
||||
EndIf
|
||||
Next i
|
||||
Dim filteredDups(1) As Variant
|
||||
filteredDups(0) = filteredNames
|
||||
filteredDups(1) = filteredCounters
|
||||
filterPageStyleNames = filteredDups
|
||||
End Function
|
||||
|
||||
|
||||
Function getPageStyleBreaks()
|
||||
|
||||
Dim enum1 As Object
|
||||
|
@ -30,12 +254,13 @@ Function getPageStyleBreaks()
|
|||
Dim oViewCursor As Object
|
||||
Dim anchor As Object
|
||||
Dim oSavePosition As Object
|
||||
Dim pageStyleBreaks(1) As Variant
|
||||
Dim pageStyleBreaks(2) As Variant
|
||||
Dim pageStyleNames() As String
|
||||
Dim pageNumbers() As Integer
|
||||
Dim pageStarts() As Object
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
|
||||
enum1 = ThisComponent.Text.createEnumeration()
|
||||
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
Dim i As Integer
|
||||
i = 0
|
||||
Dim first As Boolean
|
||||
|
@ -43,15 +268,22 @@ Function getPageStyleBreaks()
|
|||
While enum1.hasMoreElements
|
||||
enum1Element = enum1.nextElement
|
||||
If enum1Element.supportsService("com.sun.star.text.Paragraph") OR enum1Element.supportsService("com.sun.star.text.TextTable") Then
|
||||
If enum1Element.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE AND NOT IsMissing(enum1Element.PageDescName) AND NOT IsNull(enum1Element.PageDescName) AND NOT IsEmpty(enum1Element.PageDescName) Then
|
||||
' MRi enum1Element
|
||||
If NOT isEmpty(enum1Element.PageDescName) And enum1Element.PageDescName <> "" Then
|
||||
pageStyleName = enum1Element.PageStyleName
|
||||
addToArray(pageStyleNames(),pageStyleName)
|
||||
oViewCursor.goToRange(enum1Element.Anchor,false)
|
||||
If enum1Element.supportsService("com.sun.star.text.Paragraph") Then
|
||||
oViewCursor.goToRange(enum1Element.Anchor,false)
|
||||
ElseIf enum1Element.supportsService("com.sun.star.text.TextTable") Then
|
||||
oViewCursor.goToRange(enum1Element.getCellByPosition(0,0).getStart(),false)
|
||||
EndIf
|
||||
addToArray(pageNumbers(),CInt(oViewCursor.Page))
|
||||
addToArray(pageStarts(),enum1Element)
|
||||
first = false
|
||||
ElseIf first Then
|
||||
addToArray(pageStyleNames(), enum1Element.PageStyleName)
|
||||
addToArray(pageNumbers(),1)
|
||||
addToArray(pageStarts(),enum1Element)
|
||||
first = false
|
||||
EndIf
|
||||
|
||||
|
@ -60,10 +292,11 @@ Function getPageStyleBreaks()
|
|||
Wend
|
||||
pageStyleBreaks(0) = pageStyleNames
|
||||
pageStyleBreaks(1) = pageNumbers
|
||||
pageStyleBreaks(2) = pageStarts
|
||||
getPageStyleBreaks = pageStyleBreaks
|
||||
End Function
|
||||
|
||||
Sub setUniqPageStyles
|
||||
Sub setUniqPageStylesDEPRECATED
|
||||
Dim prevPageName As String
|
||||
Dim firstPageName As String
|
||||
Dim pageName As String
|
||||
|
|
|
@ -234,6 +234,9 @@ Function getRussian(identifier As String) As String
|
|||
Exit Function
|
||||
Case "PageConfigMM"
|
||||
getRussian = "мм"
|
||||
Exit Function
|
||||
Case "allPagesHaveUniqPageStyle"
|
||||
getRussian = "Каждой странице в документе назначен уникальный стиль"
|
||||
Exit Function
|
||||
Case Else
|
||||
getRussian = "Перевод не найден"
|
||||
|
@ -461,6 +464,9 @@ Function getEnglish(identifier As String) As String
|
|||
Exit Function
|
||||
Case "PageConfigMM"
|
||||
getEnglish = "mm"
|
||||
Exit Function
|
||||
Case "allPagesHaveUniqPageStyle"
|
||||
getEnglish = "Every page in document now have unique page style"
|
||||
Exit Function
|
||||
Case Else
|
||||
getEnglish = "No translation"
|
||||
|
|
BIN
translations.ods
BIN
translations.ods
Binary file not shown.
Loading…
Add table
Reference in a new issue