fix: refactoring and fixes for working with archive

This commit is contained in:
Georgy Litvinov 2021-08-29 16:44:00 +02:00
parent 82c63c82ca
commit fe1fc573eb
3 changed files with 72 additions and 60 deletions

View file

@ -83,6 +83,26 @@
<value>_self</value>
</prop>
</node>
<node oor:name="balanceTail" 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="ru">Балансировка хвоста</value>
<value xml:lang="fr">Équilibrer la dernière ligne</value>
<value xml:lang="en">Balance the last line </value>
<value xml:lang="sr">Уравнотежите последњу линију</value>
<value xml:lang="hr">Uravnotežite posljednji redak</value>
<value xml:lang="bs">Uravnotežite posljednji redak</value>
</prop>
<prop oor:name="URL" oor:type="xs:string">
<value>macro:///ePublishing.Archive.adjustLastLineCurPara</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
</node>
</node>
</node>
@ -169,26 +189,6 @@
<value>_self</value>
</prop>
</node>
<node oor:name="balanceTail" 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="ru">Балансировка хвоста</value>
<value xml:lang="fr">Équilibrer la dernière ligne</value>
<value xml:lang="en">Balance the last line </value>
<value xml:lang="sr">Уравнотежите последњу линију</value>
<value xml:lang="hr">Uravnotežite posljednji redak</value>
<value xml:lang="bs">Uravnotežite posljednji redak</value>
</prop>
<prop oor:name="URL" oor:type="xs:string">
<value>macro:///ePublishing.Archive.adjustLastLineCurPara</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
</node>
</node>
</node>

View file

@ -1,6 +1,6 @@
<?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="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark25
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark26
End Sub
@ -274,14 +274,16 @@ end Sub
Sub configureHeadings
configureArchiveHeading1
configureOtherArchiveHeadings
configureArchiveHeadings()
End Sub
Sub configureArchiveHeading1
Dim outline1() As Object
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim initPosition As Object
Dim initPageNum As Integer
fixViewCursor()
oViewCursor = thisComponent.getCurrentController.getViewCursor
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
outline1 = getHeadingWithLevel(1)
@ -289,33 +291,35 @@ Sub configureArchiveHeading1
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)
initPosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
initPageNum = oViewcursor.getPage()
Do While startViewPageNum = getPageNumber(pageNumberCursor) And initialPageCount = ThisComponent.currentController.pageCount
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin + 100
Do While Not isContentPageChanged(initPosition, initPageNum) AND outline1(i).ParaBottomMargin &lt; 10000
outline1(i).ParaBottomMargin = outline1(i).ParaBottomMargin + 100
Loop
If outline1(i).ParaTopMargin &gt;= 100 Then
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin - 100
Do While isContentPageChanged(initPosition, initPageNum)
If outline1(i).ParaBottomMargin &lt; 0 Then
Exit Do
EndIf
outline1(i).ParaBottomMargin = outline1(i).ParaBottomMargin - 100
Loop
Next i
oViewCursor.goToRange(oSavePosition,false)
End Sub
Sub configureOtherArchiveHeadings
Sub configureArchiveHeadings()
Dim outline1() As Object
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim initPosition As Object
Dim initPageNum As Integer
Dim savePosition As Object
fixViewCursor()
oViewCursor = thisComponent.getCurrentController.getViewCursor
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
savePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
Dim startViewPageNum As Integer
Dim pageNumberCursor As Object
Dim i As Integer
Dim j As Integer
@ -327,23 +331,25 @@ Sub configureOtherArchiveHeadings
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)
initPosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
initPageNum = oViewcursor.getPage()
Do While startViewPageNum = getPageNumber(pageNumberCursor) And initialPageCount = ThisComponent.currentController.pageCount
Do While Not isContentPageChanged(initPosition, initPageNum)
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
Do While isContentPageChanged(initPosition, initPageNum)
If outline1(i).ParaBottomMargin &lt; 0 Then
Exit Do
EndIf
outline1(i).ParaTopMargin = outline1(i).ParaTopMargin - 100
Loop
EndIf
Next i
Next j
oViewCursor.goToRange(oSavePosition,false)
oViewCursor.goToRange(savePosition,false)
End Sub
@ -449,10 +455,6 @@ Sub stretchPrevPage()
Next i
Exit Sub
EndIf
oViewCursor.goToRange(oSavePosition,false)
End Sub
@ -463,6 +465,7 @@ Sub adjustLastLineCurPara()
Dim success As Boolean
Dim adjustType As Integer
Dim hyph As Boolean
fixViewCursor()
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oTextCursor = oViewCursor.Text.CreateTextCursorByRange(oViewCursor)
paraEnd = getParaEnd(oTextCursor)

View file

@ -1141,16 +1141,11 @@ Sub configureCursorPositionForContentShrink()
Dim oViewCursor As Object
Dim oTextCursor As Object
Dim curSelection As Object
Dim selectionTextRange
Dim selectionTextRange As Object
Dim nextChar As String
Dim prefChar As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
curSelection = ThisComponent.getCurrentSelection()
If Not curSelection.supportsService(&quot;com.sun.star.text.TextRanges&quot;) Then
selectionTextRange = curSelection.Anchor
oViewCursor.JumpToFirstPage(false)
oViewCursor.goToRange(selectionTextRange,false)
EndIf
fixViewCursor()
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;At start of Para
oTextCursor.collapseToEnd()
@ -1160,14 +1155,28 @@ Sub configureCursorPositionForContentShrink()
oViewCursor.goToRange(oTextCursor,false)
End Sub
Function isShrinkPageSucceded(initPosition As Object,initPageNum As String) As Boolean
Sub fixViewCursor()
Dim oViewCursor As Object
Dim curSelection As Object
Dim selectionTextRange As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
curSelection = ThisComponent.getCurrentSelection()
If Not curSelection.supportsService(&quot;com.sun.star.text.TextRanges&quot;) Then
selectionTextRange = curSelection.Anchor
oViewCursor.JumpToFirstPage(false)
oViewCursor.goToRange(selectionTextRange,false)
EndIf
End Sub
Function isContentPageChanged(initPosition As Object,initPageNum As String) As Boolean
Dim oViewCursor As Object
Dim oTextCursor As Object
isShrinkPageSucceded = false
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.goToRange(initPosition,false)
If (oViewCursor.getPage &lt;&gt; initPageNum) Then
isShrinkPageSucceded = true
isContentPageChanged = true
EndIf
End Function
@ -1295,7 +1304,7 @@ Function shrinkPageContent() As Boolean
targetContent = selectContentToShrink(initPosition,startPosition)
For i = LBound(targetContent) To Ubound(targetContent)
shrinkContentSpacing(targetContent(i))
If isShrinkPageSucceded(initPosition, initPageNum) Then
If isContentPageChanged(initPosition, initPageNum) Then
Exit Function
EndIf
Next i
@ -1309,7 +1318,7 @@ Function shrinkPageContent() As Boolean
If shrinkContentWithKerning(targetContent(i)) Then
balanceContentTail(targetContent(i))
EndIf
If isShrinkPageSucceded(initPosition, initPageNum) Then
If isContentPageChanged(initPosition, initPageNum) Then
Exit Function
EndIf
Next i
@ -1317,7 +1326,7 @@ Function shrinkPageContent() As Boolean
For j = 1 To roundsLineHeight
For i = LBound(targetContent) To Ubound(targetContent)
decreaseIntervalHeight(targetContent(i))
If isShrinkPageSucceded(initPosition, initPageNum) Then
If isContentPageChanged(initPosition, initPageNum) Then
Exit Function
EndIf
Next i