Fixed headings settings while working with archive

This commit is contained in:
Georgy Litvinov 2020-06-23 13:58:46 +02:00
parent 8fab22ff8c
commit 85e11b73a5
3 changed files with 237 additions and 20 deletions

View file

@ -323,6 +323,24 @@
<value xml:lang="bs">Oporavak prekida stranice</value> <value xml:lang="bs">Oporavak prekida stranice</value>
</prop> </prop>
</node> </node>
<node oor:name="ConfigureArchiveHeadings" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>macro:///ePublishing.Archive.configureHeadings</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">Configure headings</value>
<value xml:lang="ru">Настроить заголовки</value>
<value xml:lang="fr">Configurer les en-têtes</value>
<value xml:lang="sr">Конфигурише заглавља</value>
<value xml:lang="hr">Konfiguriranje naslova</value>
<value xml:lang="bs">Konfiguriranje naslova</value>
</prop>
</node>
</node> </node>
</node> </node>
</node> </node>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark11 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark14
End Sub End Sub
@ -142,10 +142,13 @@ sub convertIndesignPageBreaks
Dim firstBreak As Boolean Dim firstBreak As Boolean
firstBreak = true firstBreak = true
Dim charNum As Long Dim charNum As Long
Dim character As String Dim prevParaLastCharacter As String
Dim oFound As Object Dim oFound As Object
Dim pageNumber As Integer Dim pageNumber As Integer
Dim prevPageNumber As Integer Dim prevPageNumber As Integer
Dim nextPara As Object
Dim prevPara As Object
Dim nextParaFirstCharacter As String
firstLowercase = false firstLowercase = false
oSearch = ThisComponent.createSearchDescriptor() oSearch = ThisComponent.createSearchDescriptor()
@ -161,10 +164,12 @@ sub convertIndesignPageBreaks
oTextCursor.goRight(1,true) oTextCursor.goRight(1,true)
oTextCursor.String = &quot;&quot; oTextCursor.String = &quot;&quot;
oTextCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE oTextCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE
&apos;Go to Start of new paragraph to shrink prev page if necessary
oViewCursor.goToRange(oTextCursor.End,false) oViewCursor.goToRange(oTextCursor.End,false)
oViewCursor.goLeft(1,false) oViewCursor.goLeft(1,false)
&apos;
Wait 100 Wait 100
pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End) pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End))
If firstBreak Then If firstBreak Then
firstBreak = false firstBreak = false
prevPageNumber = pageNumber prevPageNumber = pageNumber
@ -172,34 +177,42 @@ sub convertIndesignPageBreaks
If pageNumber - prevPageNumber &gt; 1 Then If pageNumber - prevPageNumber &gt; 1 Then
shrinkPageContent shrinkPageContent
Wait 100 Wait 100
pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End) pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End))
EndIf EndIf
&apos;check first character &apos;check first character
oTextCursor.goRight(1,true) oTextCursor.goRight(1,true)
If (isLowerCase(oTextCursor.getString())) Then nextPara = oTextCursor.End
oTextCursor.ParaFirstLineIndent = 0 nextParaFirstCharacter = oTextCursor.getString()
If (isLowerCase(nextParaFirstCharacter)) Then
adjustFirstLine(nextPara)
firstLowercase = true firstLowercase = true
End If End If
&apos;check last character &apos;check last character
oTextCursor.goLeft(2,false) oTextCursor.goLeft(2,false)
prevPara = oTextCursor.Start
oTextCursor.goLeft(1,true) oTextCursor.goLeft(1,true)
character = oTextCursor.getString() prevParaLastCharacter = oTextCursor.getString()
If (character = &quot; &quot;) Then If (prevParaLastCharacter = &quot; &quot;) Then
&apos; oTextCursor.String=&quot;&quot; &apos; oTextCursor.String=&quot;&quot;
&apos;last paragraph &apos;last paragraph
adjustLastLine(oTextCursor) adjustLastLine(prevPara)
adjustFirstLine(nextPara)
EndIf EndIf
If (isLowerCase(character)) Then If (isLowerCase(prevParaLastCharacter)) Then
If firstLowercase Then If firstLowercase Then
oTextCursor.collapseToEnd() oTextCursor.collapseToEnd()
oTextCursor.setString(&quot;-&quot;) oTextCursor.setString(&quot;-&quot;)
oTextCursor.collapseToEnd() oTextCursor.collapseToEnd()
adjustLastLine(oTextCursor) adjustLastLine(prevPara)
adjustFirstLine(oTextCursor) adjustFirstLine(nextPara)
EndIf EndIf
End If End If
If pageNumber - prevPageNumber &lt; 2 Then
&apos; stretchPrevPage(prevPara)
EndIf
prevPageNumber = pageNumber prevPageNumber = pageNumber
oFound = ThisComponent.findNext(oFound.End, oSearch) oFound = ThisComponent.findNext(oFound.End, oSearch)
Loop Loop
@ -207,15 +220,199 @@ sub convertIndesignPageBreaks
MsgBox getTranslation(&quot;convertIndesignPageBreaksFinish&quot;) MsgBox getTranslation(&quot;convertIndesignPageBreaksFinish&quot;)
end Sub end Sub
Sub adjustLastLine(oTextCursor As Object) Sub configureHeadings
oTextCursor.ParaAdjust = 2 configureArchiveHeading1
oTextCursor.ParaLastLineAdjust = 2 configureOtherArchiveHeadings
balancePara(oTextCursor)
End Sub End Sub
Sub adjustFirstLine(oTextCursor As Object)
oTextCursor.goRight(1,false) Sub configureArchiveHeading1
oTextCursor.ParaFirstLineIndent = 0 Dim outline1() As Object
Dim oViewCursor As Object
Dim oSavePosition As Object
oViewCursor = thisComponent.getCurrentController.getViewCursor
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
outline1 = getHeadingWithLevel(1)
Dim startViewPageNum As Integer
Dim pageNumberCursor As Object
Dim i As Integer
Dim j As Integer
Dim initialPageCount As Integer
initialPageCount = ThisComponent.currentController.pageCount
For i = LBound(outline1) To UBound(outline1)
oViewCursor.goToRange(outline1(i), false)
oViewCursor.jumpToEndOfPage()
pageNumberCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
pageNumberCursor.goToStartOfWord(false)
startViewPageNum = getPageNumber(pageNumberCursor)
Do While startViewPageNum = getPageNumber(pageNumberCursor) And initialPageCount = ThisComponent.currentController.pageCount
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin + 100
Loop
If outline1(i).ParaTopMargin &gt;= 100 Then
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin - 100
EndIf
Next i
oViewCursor.goToRange(oSavePosition,false)
End Sub
Sub configureOtherArchiveHeadings
Dim outline1() As Object
Dim oViewCursor As Object
Dim oSavePosition As Object
oViewCursor = thisComponent.getCurrentController.getViewCursor
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
Dim startViewPageNum As Integer
Dim pageNumberCursor As Object
Dim i As Integer
Dim j As Integer
Dim initialPageCount As Integer
initialPageCount = ThisComponent.currentController.pageCount
For j = 2 To 10
outline1 = getHeadingWithLevel(j)
For i = LBound(outline1) To UBound(outline1)
If outline1(i).BreakType &lt;&gt; 4 Then
oViewCursor.goToRange(outline1(i), false)
oViewCursor.jumpToEndOfPage()
pageNumberCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
pageNumberCursor.goToStartOfWord(false)
startViewPageNum = getPageNumber(pageNumberCursor)
Do While startViewPageNum = getPageNumber(pageNumberCursor) And initialPageCount = ThisComponent.currentController.pageCount
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin + 100
If (outline1(i).ParaTopMargin &gt; outline1(i).ParaBottomMargin) Then
Exit Do
EndIf
Loop
If outline1(i).ParaTopMargin &gt;= 100 Then
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin - 100
EndIf
EndIf
Next i
Next j
oViewCursor.goToRange(oSavePosition,false)
End Sub
Sub stretchPrevPage()
&apos;Assumption hard breaks at start of stretching page and at start of next page
Dim pageCount As Integer
Dim curViewPageNum As Integer
Dim startViewPageNum As Integer
Dim successOperation As Boolean
Dim paragraphs() As Object
Dim outline1() As Object
Dim outline2() As Object
initialPageCount = thiscomponent.currentController.pageCount
Dim oViewCursor As Object
Dim textCursor As Object
Dim pageNumberCursor As Object
Dim oSavePosition As Object
Dim pageStartPosition As Object
Dim i As Integer
Dim curPara As Object
oViewCursor = thisComponent.getCurrentController.getViewCursor
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oViewCursor.goToRange(prevPara, false)
&apos;oViewCursor.goToStartOfLine(false)
pageNumberCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
pageNumberCursor.goToStartOfWord(false)
&apos;Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
&apos;MRI pageNumberCursor
oViewCursor.jumpToStartOfPage()
startViewPageNum = getPageNumber(pageNumberCursor)
textCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
Do While oViewCursor.getPage() = startViewPageNum
curPara = textCursor.textParagraph
If curPara.outlineLevel = 1 Then
addToArray(outline1, curPara)
ElseIf curPara.outlineLevel = 2 Then
addToArray(outline2, curPara)
Else
addToArray(paragraphs, curPara)
EndIf
successOperation = textCursor.goToNextParagraph(false)
If NOT successOperation Then
Exit Do
EndIf
oViewCursor.goToRange(textCursor,false)
Loop
If UBound(outline1) &gt; -1 Then
Do While startViewPageNum = getPageNumber(pageNumberCursor)
For i = LBound(outline1) To UBound(outline1)
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin + 100
Next i
Loop
For i = LBound(outline1) To UBound(outline1)
If outline1(i).ParaTopMargin &gt;= 100 Then
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin - 100
EndIf
Next i
Exit Sub
EndIf
If UBound(outline2) &gt; -1 Then
Do While startViewPageNum = getPageNumber(pageNumberCursor)
For i = LBound(outline2) To UBound(outline2)
outline2(i).ParaTopMargin = outline2(i).ParaTopMargin + 100
If outline2(i).ParaTopMargin &gt; outline2(i).ParaBottomMargin Then
Exit Do
EndIf
Next i
Loop
For i = LBound(outline2) To UBound(outline2)
If outline2(i).ParaTopMargin &gt;= 100 Then
outline2(i).ParaTopMargin = outline2(i).ParaTopMargin - 100
EndIf
Next i
Exit Sub
EndIf
&apos;Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
&apos;Mri curPara
Dim paraLineSpacing As Object
Dim tmpPageNum As Integer
tmpPageNum = getPageNumber(pageNumberCursor)
If UBound(paragraphs) &gt; -1 Then
Dim iterations As Integer
iterations = 0
Do While startViewPageNum = getPageNumber(pageNumberCursor)
For i = LBound(paragraphs) To UBound(paragraphs)
paraLineSpacing = paragraphs(i).paraLineSpacing
paraLineSpacing.Height = paraLineSpacing.Height + 5
paragraphs(i).paraLineSpacing = paraLineSpacing
Next i
iterations = iterations + 1
If iterations &gt; 4 Then
Exit Do
EndIf
tmpPageNum = getPageNumber(pageNumberCursor)
Loop
For i = LBound(paragraphs) To UBound(paragraphs)
paraLineSpacing = paragraphs(i).paraLineSpacing
paraLineSpacing.Height = paraLineSpacing.Height - 5
paragraphs(i).paraLineSpacing = paraLineSpacing
Next i
Exit Sub
EndIf
oViewCursor.goToRange(oSavePosition,false)
End Sub
Sub adjustLastLine(anchor As Object)
anchor.ParaAdjust = 2
anchor.ParaLastLineAdjust = 2
balancePara(anchor)
End Sub
Sub adjustFirstLine(anchor As Object)
anchor.ParaFirstLineIndent = 0
End Sub End Sub

View file

@ -1615,6 +1615,8 @@ Function getPageNumber(cursor As Object) As String
oField.NumberingType = 4 oField.NumberingType = 4
oField.SubType = com.sun.star.text.PageNumberType.CURRENT oField.SubType = com.sun.star.text.PageNumberType.CURRENT
oTextCursor.Text.insertTextContent(oTextCursor, oField, False) oTextCursor.Text.insertTextContent(oTextCursor, oField, False)
oField.Anchor.CharHidden = False
oField.Anchor.CharHidden = True
getPageNumber = oField.getPresentation(false) getPageNumber = oField.getPresentation(false)
oTextCursor.Text.removeTextContent(oField) oTextCursor.Text.removeTextContent(oField)
End Function End Function