From 85e11b73a56dc88fc23b1b9da8543e47517f21dc Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Tue, 23 Jun 2020 13:58:46 +0200 Subject: [PATCH] Fixed headings settings while working with archive --- Addons.xcu | 18 +++ ePublishing/Archive.xba | 237 +++++++++++++++++++++++++++++++++++---- ePublishing/journals.xba | 2 + 3 files changed, 237 insertions(+), 20 deletions(-) diff --git a/Addons.xcu b/Addons.xcu index 525251f..78dc454 100644 --- a/Addons.xcu +++ b/Addons.xcu @@ -323,6 +323,24 @@ Oporavak prekida stranice + + + macro:///ePublishing.Archive.configureHeadings + + + _self + + + + Configure headings + Настроить заголовки + Configurer les en-têtes + Конфигурише заглавља + Konfiguriranje naslova + Konfiguriranje naslova + + + diff --git a/ePublishing/Archive.xba b/ePublishing/Archive.xba index d872008..a46188f 100644 --- a/ePublishing/Archive.xba +++ b/ePublishing/Archive.xba @@ -1,6 +1,6 @@ -Sub archMark11 +Sub archMark14 End Sub @@ -142,10 +142,13 @@ sub convertIndesignPageBreaks Dim firstBreak As Boolean firstBreak = true Dim charNum As Long - Dim character As String + Dim prevParaLastCharacter As String Dim oFound As Object Dim pageNumber As Integer Dim prevPageNumber As Integer + Dim nextPara As Object + Dim prevPara As Object + Dim nextParaFirstCharacter As String firstLowercase = false oSearch = ThisComponent.createSearchDescriptor() @@ -161,10 +164,12 @@ sub convertIndesignPageBreaks oTextCursor.goRight(1,true) oTextCursor.String = "" oTextCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE + 'Go to Start of new paragraph to shrink prev page if necessary oViewCursor.goToRange(oTextCursor.End,false) oViewCursor.goLeft(1,false) + ' Wait 100 - pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End) + pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End)) If firstBreak Then firstBreak = false prevPageNumber = pageNumber @@ -172,34 +177,42 @@ sub convertIndesignPageBreaks If pageNumber - prevPageNumber > 1 Then shrinkPageContent Wait 100 - pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End) + pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End)) EndIf 'check first character oTextCursor.goRight(1,true) - If (isLowerCase(oTextCursor.getString())) Then - oTextCursor.ParaFirstLineIndent = 0 + nextPara = oTextCursor.End + nextParaFirstCharacter = oTextCursor.getString() + If (isLowerCase(nextParaFirstCharacter)) Then + adjustFirstLine(nextPara) firstLowercase = true End If 'check last character oTextCursor.goLeft(2,false) + prevPara = oTextCursor.Start oTextCursor.goLeft(1,true) - character = oTextCursor.getString() + prevParaLastCharacter = oTextCursor.getString() - If (character = " ") Then + If (prevParaLastCharacter = " ") Then ' oTextCursor.String="" 'last paragraph - adjustLastLine(oTextCursor) - + adjustLastLine(prevPara) + adjustFirstLine(nextPara) EndIf - If (isLowerCase(character)) Then + If (isLowerCase(prevParaLastCharacter)) Then If firstLowercase Then oTextCursor.collapseToEnd() oTextCursor.setString("-") oTextCursor.collapseToEnd() - adjustLastLine(oTextCursor) - adjustFirstLine(oTextCursor) + adjustLastLine(prevPara) + adjustFirstLine(nextPara) EndIf End If + + If pageNumber - prevPageNumber < 2 Then + ' stretchPrevPage(prevPara) + EndIf + prevPageNumber = pageNumber oFound = ThisComponent.findNext(oFound.End, oSearch) Loop @@ -207,15 +220,199 @@ sub convertIndesignPageBreaks MsgBox getTranslation("convertIndesignPageBreaksFinish") end Sub -Sub adjustLastLine(oTextCursor As Object) - oTextCursor.ParaAdjust = 2 - oTextCursor.ParaLastLineAdjust = 2 - balancePara(oTextCursor) +Sub configureHeadings + configureArchiveHeading1 + configureOtherArchiveHeadings End Sub -Sub adjustFirstLine(oTextCursor As Object) - oTextCursor.goRight(1,false) - oTextCursor.ParaFirstLineIndent = 0 + +Sub configureArchiveHeading1 + 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 >= 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 <> 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 > outline1(i).ParaBottomMargin) Then + Exit Do + EndIf + Loop + If outline1(i).ParaTopMargin >= 100 Then + outline1(i).ParaTopMargin = outline1(i).ParaTopMargin - 100 + EndIf + EndIf + Next i + Next j + oViewCursor.goToRange(oSavePosition,false) +End Sub + + +Sub stretchPrevPage() + '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) + 'oViewCursor.goToStartOfLine(false) + pageNumberCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor) + pageNumberCursor.goToStartOfWord(false) + 'Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) + '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) > -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 >= 100 Then + outline1(i).ParaTopMargin = outline1(i).ParaTopMargin - 100 + EndIf + Next i + Exit Sub + EndIf + + If UBound(outline2) > -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 > outline2(i).ParaBottomMargin Then + Exit Do + EndIf + Next i + Loop + For i = LBound(outline2) To UBound(outline2) + If outline2(i).ParaTopMargin >= 100 Then + outline2(i).ParaTopMargin = outline2(i).ParaTopMargin - 100 + EndIf + Next i + Exit Sub + EndIf + + 'Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) + 'Mri curPara + Dim paraLineSpacing As Object + Dim tmpPageNum As Integer + tmpPageNum = getPageNumber(pageNumberCursor) + If UBound(paragraphs) > -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 > 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 diff --git a/ePublishing/journals.xba b/ePublishing/journals.xba index ec27b95..b764d76 100644 --- a/ePublishing/journals.xba +++ b/ePublishing/journals.xba @@ -1615,6 +1615,8 @@ Function getPageNumber(cursor As Object) As String oField.NumberingType = 4 oField.SubType = com.sun.star.text.PageNumberType.CURRENT oTextCursor.Text.insertTextContent(oTextCursor, oField, False) + oField.Anchor.CharHidden = False + oField.Anchor.CharHidden = True getPageNumber = oField.getPresentation(false) oTextCursor.Text.removeTextContent(oField) End Function