Improved archive macro

This commit is contained in:
Georgy Litvinov 2020-06-22 22:29:58 +02:00
parent 07624d0907
commit f8887020b9

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 archMark10 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark11
End Sub End Sub
@ -124,34 +124,32 @@ End Function
sub convertIndesignPageBreaks sub convertIndesignPageBreaks
Dim description As String Dim description As String
Dim pageBreakMarker As String
pageBreakMarker = &quot;---XYXYX---&quot;
description = getTranslation(&quot;convertIndesignPageBreaksConfirmation&quot;) description = getTranslation(&quot;convertIndesignPageBreaksConfirmation&quot;)
If NOT confirm(description) Then If NOT confirm(description) Then
Exit Sub Exit Sub
EndIf EndIf
Dim document As Object turnOffTracking()
document = ThisComponent.CurrentController.Frame
Dim dispatcher As Object
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
Dim oViewCursor As Object Dim oViewCursor As Object
oViewCursor = thisComponent.getCurrentController.getViewCursor oViewCursor = thisComponent.getCurrentController.getViewCursor
oViewCursor.jumpToFirstPage oViewCursor.jumpToFirstPage
Dim args(0) as new com.sun.star.beans.PropertyValue
rem Turn off tracking changes to prevent infinite
args(0).Name = &quot;TrackChanges&quot;
args(0).Value = false
dispatcher.executeDispatch(document, &quot;.uno:TrackChanges&quot;, &quot;&quot;, 0, args())
Dim oSearch As Object Dim oSearch As Object
Dim oTextCursor As Object Dim oTextCursor As Object
Dim firstLowercase As Boolean Dim firstLowercase As Boolean
Dim firstBreak As Boolean
firstBreak = true
Dim charNum As Long Dim charNum As Long
Dim character As String Dim character As String
Dim oFound As Object Dim oFound As Object
Dim pageNumber As Integer
Dim prevPageNumber As Integer
firstLowercase = false firstLowercase = false
oSearch = ThisComponent.createSearchDescriptor() oSearch = ThisComponent.createSearchDescriptor()
oSearch.SearchString = &quot;---XYXYX---&quot; oSearch.SearchString = pageBreakMarker
oSearch.SearchRegularExpression=True oSearch.SearchRegularExpression=True
oSearch.searchAll=True oSearch.searchAll=True
oFound = ThisComponent.findFirst(oSearch) oFound = ThisComponent.findFirst(oSearch)
@ -163,7 +161,19 @@ 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
oViewCursor.goToRange(oTextCursor.End,false)
oViewCursor.goLeft(1,false)
Wait 100
pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End)
If firstBreak Then
firstBreak = false
prevPageNumber = pageNumber
EndIf
If pageNumber - prevPageNumber &gt; 1 Then
shrinkPageContent
Wait 100
pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End)
EndIf
&apos;check first character &apos;check first character
oTextCursor.goRight(1,true) oTextCursor.goRight(1,true)
If (isLowerCase(oTextCursor.getString())) Then If (isLowerCase(oTextCursor.getString())) Then
@ -174,10 +184,12 @@ sub convertIndesignPageBreaks
oTextCursor.goLeft(2,false) oTextCursor.goLeft(2,false)
oTextCursor.goLeft(1,true) oTextCursor.goLeft(1,true)
character = oTextCursor.getString() character = oTextCursor.getString()
If (character = &quot; &quot;) Then If (character = &quot; &quot;) Then
oTextCursor.String=&quot;&quot; &apos; oTextCursor.String=&quot;&quot;
&apos;last paragraph
adjustLastLine(oTextCursor) adjustLastLine(oTextCursor)
adjustFirstLine(oTextCursor)
EndIf EndIf
If (isLowerCase(character)) Then If (isLowerCase(character)) Then
If firstLowercase Then If firstLowercase Then
@ -188,8 +200,10 @@ sub convertIndesignPageBreaks
adjustFirstLine(oTextCursor) adjustFirstLine(oTextCursor)
EndIf EndIf
End If End If
prevPageNumber = pageNumber
oFound = ThisComponent.findNext(oFound.End, oSearch) oFound = ThisComponent.findNext(oFound.End, oSearch)
Loop Loop
setUniqPageStyles
MsgBox getTranslation(&quot;convertIndesignPageBreaksFinish&quot;) MsgBox getTranslation(&quot;convertIndesignPageBreaksFinish&quot;)
end Sub end Sub
@ -259,7 +273,7 @@ Sub balancePara(targetPara As Object)
Do Do
&apos;Not first iteration &apos;Not first iteration
If minLastLineLength &lt;&gt; 0 Then If minLastLineLength &lt;&gt; 0 Then
If oPara.CharKerning &lt; 30 Then If oPara.CharKerning &lt; 50 Then
If(IsEmpty(oPara.CharKerning)) Then If(IsEmpty(oPara.CharKerning)) Then
oPara.CharKerning = 0 oPara.CharKerning = 0
Else Else