From f8887020b91a4853f547ed3c92a9b83593fcc62b Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Mon, 22 Jun 2020 22:29:58 +0200 Subject: [PATCH] Improved archive macro --- ePublishing/Archive.xba | 48 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/ePublishing/Archive.xba b/ePublishing/Archive.xba index 6ff92c5..d872008 100644 --- a/ePublishing/Archive.xba +++ b/ePublishing/Archive.xba @@ -1,6 +1,6 @@ -Sub archMark10 +Sub archMark11 End Sub @@ -124,34 +124,32 @@ End Function sub convertIndesignPageBreaks Dim description As String + Dim pageBreakMarker As String + pageBreakMarker = "---XYXYX---" description = getTranslation("convertIndesignPageBreaksConfirmation") If NOT confirm(description) Then Exit Sub EndIf - Dim document As Object - document = ThisComponent.CurrentController.Frame - Dim dispatcher As Object - dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") + turnOffTracking() + Dim oViewCursor As Object oViewCursor = thisComponent.getCurrentController.getViewCursor oViewCursor.jumpToFirstPage - Dim args(0) as new com.sun.star.beans.PropertyValue - - rem Turn off tracking changes to prevent infinite - args(0).Name = "TrackChanges" - args(0).Value = false - dispatcher.executeDispatch(document, ".uno:TrackChanges", "", 0, args()) - + Dim oSearch As Object Dim oTextCursor As Object Dim firstLowercase As Boolean + Dim firstBreak As Boolean + firstBreak = true Dim charNum As Long Dim character As String Dim oFound As Object + Dim pageNumber As Integer + Dim prevPageNumber As Integer firstLowercase = false oSearch = ThisComponent.createSearchDescriptor() - oSearch.SearchString = "---XYXYX---" + oSearch.SearchString = pageBreakMarker oSearch.SearchRegularExpression=True oSearch.searchAll=True oFound = ThisComponent.findFirst(oSearch) @@ -163,7 +161,19 @@ sub convertIndesignPageBreaks oTextCursor.goRight(1,true) oTextCursor.String = "" 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 > 1 Then + shrinkPageContent + Wait 100 + pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End) + EndIf 'check first character oTextCursor.goRight(1,true) If (isLowerCase(oTextCursor.getString())) Then @@ -174,10 +184,12 @@ sub convertIndesignPageBreaks oTextCursor.goLeft(2,false) oTextCursor.goLeft(1,true) character = oTextCursor.getString() + If (character = " ") Then - oTextCursor.String="" + ' oTextCursor.String="" + 'last paragraph adjustLastLine(oTextCursor) - adjustFirstLine(oTextCursor) + EndIf If (isLowerCase(character)) Then If firstLowercase Then @@ -188,8 +200,10 @@ sub convertIndesignPageBreaks adjustFirstLine(oTextCursor) EndIf End If + prevPageNumber = pageNumber oFound = ThisComponent.findNext(oFound.End, oSearch) Loop + setUniqPageStyles MsgBox getTranslation("convertIndesignPageBreaksFinish") end Sub @@ -259,7 +273,7 @@ Sub balancePara(targetPara As Object) Do 'Not first iteration If minLastLineLength <> 0 Then - If oPara.CharKerning < 30 Then + If oPara.CharKerning < 50 Then If(IsEmpty(oPara.CharKerning)) Then oPara.CharKerning = 0 Else