epublishing/ePublishing/journals.xba

1627 lines
No EOL
57 KiB
XML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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="journals" script:language="StarBasic">Private sub journalsMark31
End sub
Dim templateName As String
Dim EIFN As String
Dim PHA As String
Dim PQ As String
Dim imagesRelativePath As String
Dim allImagesRelativePath As String
Dim path As String
Dim sectionName As String
Private Sub makeUpIssue
turnOffTracking
Dim description As String
Dim i As Integer
Dim statusIndicator as Object
Dim oViewCursor As Object
Dim oTextCursor As Object
Dim articleEndPosition As Object
Dim page As String
Dim firstPage As String
Dim tmp As String
Dim nSections As Long
description = getTranslation(&quot;complileJournalIssueConfirmation&quot;)
If NOT confirm(description) Then
Exit Sub
EndIf
EIFN = &quot;ЭиФН&quot;
PHA = &quot;ФА&quot;
PQ = &quot;ВФ&quot;
imagesRelativePath = &quot;/Links/Header/&quot;
allImagesRelativePath = &quot;/Links/Header-icons/&quot;
statusIndicator = ThisComponent.getCurrentController.StatusIndicator
oViewCursor = ThisComponent.CurrentController.getViewCursor()
sectionName = &quot;&quot;
oFilename = ThisComponent.Location
&apos;Exit if no sections in document or document not saved
If oFilename = &quot;&quot; Then
MsgBox getTranslation(&quot;compileJournalIssueNoCurFilename&quot;)
Exit Sub
End If
templateName = &quot;&quot;
Dim docUserProperties As Object
docUserProperties = ThisComponent.DocumentProperties.UserDefinedProperties
If docUserProperties.getPropertySetInfo.hasPropertyByName(&quot;template&quot;) Then
templateName = docUserProperties.template
EndIf
GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
path=DirectoryNameoutofPath(ThisComponent.getURL(),&quot;/&quot;)
&apos; Add article for each section
&apos;Go to article first page
page = findFirstPageNumberWithStyle(&quot;Первая страница статьи&quot;)
firstPage = page
oViewCursor.jumpToPage(page)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
statusIndicator.Start(getTranslation(&quot;compileJournalIssueStatusInProgerss&quot;),30)
For i = 1 To 50
&apos;Find section file
FilePath = findArticleFile(path,i)
If FilePath=&quot;&quot; Then
Exit For
EndIF
&apos;Add Article
If FileExists(FilePath) Then
oViewCursor.goToRange(oTextCursor,false)
&apos;Вставить разрыв страницы, если его не было.
oTextCursor.BreakType = 4
&apos;Задать стиль первой страницы
If NOT IsEmpty(oTextCursor.NumberingRules) Then
noNumbering
EndIf
setArticlePageStyles(i)
setAritclePageHeaders(i)
page = oViewCursor.getPage()
InsertArticle(FilePath)
turnOffTracking
statusIndicator.setValue(i)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oViewCursor.Text.insertControlCharacter(oTextCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
oTextCursor.collapseToEnd()
&apos;set page to next article page number
&apos;oViewCursor.goToRange(oTextCursor,false)
End If
fileType = Right(FilePath, 3)
&apos;Go to first page
oViewCursor.jumpToPage(page)
If fileType = &quot;doc&quot; Then
&apos;Remove blank page at start
sendRM()
End If
sectionName = getSectionX(sectionName)
setArticleUniqPageStyles(i)
oViewCursor.jumpToPage(page)
setAtricleVars(i)
oViewCursor.jumpToPage(page)
takeWidowLinesIn()
oViewCursor.jumpToPage(page)
&apos; takeWidowOrphans()
&apos;Set section name
If templateName = &quot;&quot; Then
updateUserField(&quot;leftHeader&quot; + i , sectionName )
ElseIf templateName = PHA Then
updateUserField(&quot;leftHeader&quot; + i , sectionName )
ElseIf templateName = EIFN Then
updateUserField(&quot;rightHeader&quot; + i , getArticleHeader() )
updateUserField(&quot;leftHeader&quot; + i , getAuthor )
EndIf
Next i
statusIndicator.setValue(26)
&apos;remove last empty page
oViewCursor.jumpToPage(page)
oViewCursor.jumpToPage(lastPageNum(i))
removeEmptyPage()
statusIndicator.setValue(28)
&apos;Set pageNums
setPageNumbers()
statusIndicator.setValue(29)
&apos;Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
&apos; Mri oViewCursor
&apos;Задать нумерацию сносок на каждую главу
&apos;ThisComponent.FootnoteSettings.FootnoteCounting=1
&apos;setHeadingsOutlineLevels
statusIndicator.end()
MsgBox getTranslation(&quot;compileJournalIssueFinished&quot;)
End Sub
Private Sub setPageNumbers()
updateLastPageFields()
End Sub
Private Sub setPageNumbersDeprecated()
Dim oVeiwCursor As Object
Dim pageNum as Integer
Dim firstPage as String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumpToFirstPage()
firstPage = findFirstPageNumberWithStyle(&quot;Статья 1 стр.1&quot;)
oViewCursor.jumpToPage(firstPage)
For i = 1 To 25
pageNum = lastPageNum(i)
&apos;msgBox pageNum
If pageNum = -1 Then
Exit For
End If
updateUserField(&quot;article&quot; + i + &quot;LastPage&quot;, CStr(pageNum) )
Next i
End Sub
Private Sub setAtricleVars(i As Integer)
&apos;updateUserField(&quot;article&quot; + i + &quot;LastPage&quot;, CStr(getArticleLastPage()) )
updateUserField(&quot;article&quot; + i + &quot;UDK&quot;, getUDK())
updateUserField(&quot;author&quot; + i + &quot;Copyright&quot;, getCopyright() )
&apos;updateUserField(&quot;rightHeader&quot; + i , getTitleHeader() )
End Sub
Private Function lastPageNum(i As Integer)
Dim docLastPage As Integer
Dim curPageNum As Integer
Dim oViewCursor As Object
curPageNum = -1
oViewCursor = ThisComponent.CurrentController.getViewCursor()
Dim oSavePosition As Object
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oViewCursor.jumpToLastPage()
oViewCursor.jumpToEndOfPage()
docLastPage = CInt(oViewCursor.getPage())
oViewCursor.goToRange(oSavePosition,false)
If CInt(oViewCursor.getPage()) = docLastPage Then
lastPageNum = -1
Exit Function
End If
Dim curPageStyleName As String
curPageStyleName = oViewCursor.PageStyleName
Do Until InStr(curPageStyleName,&quot;Статья &quot; + CStr(i)) = 0
curPageNum = CInt(oViewCursor.getPage())
If curPageNum = docLastPage Then
Exit Do
End If
If curPageNum = 0 Then
MsgBox getTranslation(&quot;lastPageNumNotFound&quot;)
Exit Do
End If
oViewCursor.jumpToNextPage()
curPageStyleName = getNextPageStyleName()
If InStr(curPageStyleName,&quot;Статья &quot; + CStr(i+1) + &quot; стр.1&quot;) = 1 Then
Exit Do
End If
Loop
lastPageNum = curPageNum
End Function
Private Function getUDK()
&apos;Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim title As String
Dim foundUDK As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oViewCursor.jumpToStartOfPage()
getFirstTextInStyle(&quot;УДК&quot;)
foundUDK = oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()
If foundUDK = &quot;&quot; Then
getUDK = getTranslation(&quot;compileJournalIssueSetUDKDummyText&quot;)
Else
getUDK = foundUDK
backspace
sendRM
End If
Thiscomponent.CurrentController.select(oSavePosition)
End Function
Private Function getCopyright()
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim authors As String
Dim finalName As String
Dim tmpStr As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
getFirstTextInStyle(&quot;Автор&quot;)
authors = oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()
If authors &lt;&gt; &quot;&quot; Then
finalName = Trim(authors)
If Len(finalName) &gt;= 1 Then
If Right(finalName, 1) = &quot;.&quot; Then
getCopyright = &quot;© &quot; + finalName
oViewCursor.goToRange(oSavePosition, false)
Exit Function
EndIf
EndIf
If Len(authors) &gt;= 4 Then
leftSide = Right(authors,Len(authors)-4)
rightSide = Left(authors,4)
finalName = Trim(leftSide) + &quot; &quot; + rightSide
If Right(finalName, 1) &lt;&gt; &quot;.&quot; Then
getCopyright = &quot;© &quot; + Trim(authors)
Else
getCopyright = &quot;© &quot; + finalName
EndIf
oViewCursor.goToRange(oSavePosition, false)
Exit Function
Else
getCopyright = getTranslation(&quot;compileJournalIssueCopyrightDummyText&quot;)
EndIf
End If
oViewCursor.goToRange(oSavePosition, false)
End Function
Private Function getAuthor()
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim authors As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
getFirstTextInStyle(&quot;Автор&quot;)
authors = oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()
If authors &lt;&gt; &quot;&quot; Then
getAuthor = authors
Else
getAuthor = getTranslation(&quot;compileJournalIssueAuthorDummyText&quot;)
End If
oViewCursor.goToRange(oSavePosition, false)
End Function
Private Function getArticleHeader()
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim authors As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
getFirstTextInStyle(&quot;Заголовок 2&quot;)
articleHeader = oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()
If articleHeader &lt;&gt; &quot;&quot; Then
getArticleHeader = articleHeader
Else
getArticleHeader = getTranslation(&quot;compileJournalIssueArticleTitleDummyText&quot;)
End If
oViewCursor.goToRange(oSavePosition, false)
End Function
Private Function getSectionX(section As String)
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim startPage As String
Dim endPage As String
If section = &quot;&quot; Then
section = getTranslation(&quot;compileJournalIssueSectionDummyText&quot;)
End If
oViewCursor = ThisComponent.CurrentController.getViewCursor()
startPage = oViewcursor.getPage()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
getFirstTextInStyle(&quot;Заголовок 1&quot;)
endPage = oViewCursor.getPage()
If CInt(startPage) &lt;= CInt(endPage) Then
If Len(oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()) &gt; 1 Then
section = oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()
End If
section = UCase(Left(section, 1)) + LCase(Right(section,Len(section)-1))
End If
getSectionX = section
oViewCursor.goToRange(oSavePosition, false)
End Function
Private Function getTitleHeader()
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim title As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
getFirstTextInStyle(&quot;Автор&quot;)
authors = oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()
getFirstTextInStyle(&quot;Заголовок 2&quot;)
title = oViewCursor.Text.createTextCursorByRange(oViewCursor).getString()
getTitleHeader = authors + &quot; &quot; + title
oViewCursor.goToRange(oSavePosition, false)
getUDK = title
End Function
Private Sub setArticlePageStyles(i As Integer)
Dim oViewCursor As Object
Dim oTextCursor As Object
Dim oText As Object
Dim page As String
Dim pageNum As Long
Dim pageStyles As Object
Dim articleFirstPageStyle As Object
Dim newPageStyleName As String
Dim articleFirstPageStyleName As String
Dim curStyle As Object
Dim tmpStyleName As String
Dim firstName As String
Dim newName As String
Dim newFirstName As String
pageStyles = ThisComponent.StyleFamilies.getByName(&quot;PageStyles&quot;)
firstName = &quot;Первая страница статьи&quot;
newName = &quot;Статья &quot; + CStr(i)
newFirstName = newName + &quot; стр.1&quot;
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;set starndard first page style name (need for cloning)
oTextCursor.PageDescName = firstName
&apos;clone starndard first page style
createPageStyleByExample(newFirstName)
&apos; set cloned style to first page
oTextCursor.PageDescName = newFirstName
&apos;get current first page style name
curStyle = pageStyles.getByName(oViewCursor.pageStyleName)
setFirstPageMetadata(curStyle,i)
&apos;1 left/right style
&apos; create new para for next page
oTextCursor.Text.insertControlCharacter(oTextCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
oTextCursor.BreakType = 4
&apos;clone 1 left/right style
createPageStyleByExample(newName)
&apos;set followStyle to previous style
curStyle.FollowStyle = newName
&apos;set new curStyle
curStyle = pageStyles.getByName(oViewCursor.pageStyleName)
oTextCursor.goLeft(1,true)
oTextCursor.String = &quot;&quot;
End Sub
Private Sub setFirstPageMetadata(curStyle As Object,i As Integer)
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim savePageName As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
savePageName = oSavePosition.PageStyleName
oViewCursor.Text.insertControlCharacter(oViewCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oTextCursor.BreakType = 4
oTextCursor.PageDescName = savePageName
If templateName = &quot;&quot; Then
setDefaultFirstPageMetadata(curStyle,i)
ElseIf templateName = PHA Then
setPHAFirstPageMetadata(curStyle,i)
ElseIf templateName = EIFN Then
setEIFNFirstPageMetadata(curStyle,i)
EndIf
oViewCursor.goToRange(oSavePosition, false)
oViewCursor.jumpToPreviousPage()
sendRM()
End Sub
Private Sub setDefaultFirstPageMetadata(curStyle As Object,i As Integer)
Dim oViewCursor As Object
Dim oHeaderTable As Object
Dim oFooterTable As Object
Dim rightHeaderCell As Object
Dim leftHeaderCell As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
&apos;curStyle.HeaderText
oHeaderTable = curStyle.HeaderText.CreateEnumeration().nextElement
&apos;leftHeaderCell
leftHeaderCell = oHeaderTable.getCellByPosition(0,0).getStart()
oViewCursor.goToRange(leftHeaderCell, false)
&apos;go to page number place
oViewCursor.gotoEndOfLine(false)
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; + i + &quot;LastPage&quot;,&quot;00&quot; )
oViewCursor.goright(1,false)
&apos;Добавить УДК
insertUserField(oViewCursor,&quot;article&quot; + i + &quot;UDK&quot;,&quot;УДК &quot;+ i + &quot;.&quot; + i)
&apos;rightHeaderCell
rightHeaderCell = oHeaderTable.getCellByPosition(1,0).getStart()
oViewCursor.goToRange(rightHeaderCell, false)
&apos;go to page number 1st place
oViewCursor.gotoEndOfLine(false)
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; + i + &quot;LastPage&quot;,&quot;00&quot; )
&apos; go to page number 2nd place
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; + i + &quot;LastPage&quot;,&quot;00&quot; )
&apos;Footer without table
oViewCursor.goToRange(curStyle.FooterText.End, false)
insertUserField(oViewCursor,&quot;author&quot; + i + &quot;Copyright&quot;,getTranslation(&quot;compileJournalIssueCopyrightDummyText&quot;) &amp; i )
End Sub
Private Sub setPHAFirstPageMetadata(curStyle As Object,i As Integer)
Dim oViewCursor As Object
Dim oHeader As Object
Dim oFooterTable As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oHeader = curStyle.HeaderText.CreateEnumeration().nextElement
If oHeader.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
oAnchor = oHeader.getCellByPosition(0,0).getStart()
Else
oAnchor = oHeader
EndIf
oViewCursor.goToRange(oAnchor, false)
&apos;go to page number place
oViewCursor.gotoEndOfLine(false)
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; + i + &quot;LastPage&quot;,&quot;00&quot; )
oViewCursor.goright(1,false)
&apos;Добавить УДК
insertUserField(oViewCursor,&quot;article&quot; + i + &quot;UDK&quot;,&quot;УДК &quot;+ i + &quot;.&quot; + i)
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; + i + &quot;LastPage&quot;,&quot;00&quot; )
oViewCursor.goToRange(curStyle.FooterText.End, false)
insertUserField(oViewCursor,&quot;author&quot; &amp; i &amp; &quot;Copyright&quot;,getTranslation(&quot;compileJournalIssueCopyrightDummyText&quot;) &amp; i )
End Sub
Private Sub setEIFNFirstPageMetadata(curStyle,i)
Dim oViewCursor As Object
Dim oHeaderTable As Object
Dim oFooterTable As Object
Dim rightHeaderCell As Object
Dim leftHeaderCell As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
&apos;curStyle.HeaderText
oHeaderTable = curStyle.HeaderText.CreateEnumeration().nextElement
&apos;leftHeaderCell
leftHeaderCell = oHeaderTable.getCellByPosition(0,0).getStart()
oViewCursor.goToRange(leftHeaderCell, false)
&apos;go to page number place
oViewCursor.gotoEndOfLine(false)
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; &amp; i &amp; &quot;LastPage&quot;,&quot;00&quot; )
oViewCursor.goright(1,false)
&apos;Добавить УДК
insertUserField(oViewCursor,&quot;article&quot; &amp; i &amp; &quot;UDK&quot;,&quot;УДК &quot;+ i + &quot;.&quot; + i)
&apos;rightHeaderCell
rightHeaderCell = oHeaderTable.getCellByPosition(1,0).getStart()
oViewCursor.goToRange(rightHeaderCell, false)
&apos;go to page number 1st place
oViewCursor.gotoEndOfLine(false)
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; &amp; i &amp; &quot;LastPage&quot;,&quot;00&quot; )
&apos; go to page number 2nd place
oViewCursor.goright(1,false)
oViewCursor.gotoEndOfLine(false)
insertUserField(oViewCursor,&quot;article&quot; &amp; i * &quot;Num&quot;,&quot;&quot; &amp; i )
oFooterTableLeft = curStyle.FooterTextLeft.CreateEnumeration().nextElement
rightHeaderCell = oFooterTableLeft.getCellByPosition(1,0).getStart()
oViewCursor.goToRange(rightHeaderCell, false)
insertUserField(oViewCursor,&quot;author&quot; &amp; i &amp; &quot;Copyright&quot;,getTranslation(&quot;compileJournalIssueCopyrightDummyText&quot;) &amp; i )
&apos;TODO!!!!SECOND PAGE
oFooterTableRight = curStyle.FooterTextRight.CreateEnumeration().nextElement
leftHeaderCell = oFooterTableRight.getCellByPosition(0,0).getStart()
oViewCursor.goToRange(leftHeaderCell, false)
insertUserField(oViewCursor,&quot;author&quot; &amp; i &amp; &quot;Copyright&quot;,getTranslation(&quot;compileJournalIssueCopyrightDummyText&quot;) &amp; i )
End Sub
Private Sub setAritclePageHeaders(i)
Dim oViewCursor As Object
Dim oSavePosition As Object
Dim rightHeaderTable As Object
Dim leftHeaderTable As Object
Dim headerCell As Object
Dim leftHeaderCell As Object
Dim curStyleName As String
Dim curStyle As Object
Dim page As Integer
Dim pageStyles As Object
Dim articleStartPosition As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
pageStyles = ThisComponent.StyleFamilies.getByName(&quot;PageStyles&quot;)
page = findFirstPageNumberWithStyle(&quot;Статья &quot; &amp; i &amp; &quot; стр.1&quot;)
oViewCursor.jumpToPage(page)
articleStartPosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;create new para for next page
oViewCursor.Text.insertControlCharacter(oViewCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;insert page break
oTextCursor.BreakType = 4
&apos;create new para for next page
oViewCursor.Text.insertControlCharacter(oViewCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;insert page break
oTextCursor.BreakType = 4
If templateName &lt;&gt; PQ Then
If templateName = EIFN Then
copySectionIcon(i)
EndIf
curStyle = pageStyles.getByName(oViewCursor.pageStyleName)
rightHeaderTable = curStyle.HeaderTextRight.CreateEnumeration().nextElement
leftHeaderTable = curStyle.HeaderTextLeft.CreateEnumeration().nextElement
rightHeaderCell = rightHeaderTable.getCellByPosition(0,0).getStart()
oViewCursor.goToRange(rightHeaderCell, false)
If templateName = &quot;&quot; Then
insertUserField(oViewCursor,&quot;rightHeader&quot; &amp; i ,getTranslation(&quot;compileJournalIssueAuthorDummyText&quot;) &amp; &quot; &quot; &amp; getTranslation(&quot;compileJournalIssueArticleTitleDummyText&quot;) &amp; i )
ElseIf templateName = PHA Then
insertUserField(oViewCursor,&quot;rightHeader&quot; &amp; i ,getTranslation(&quot;compileJournalIssueAuthorDummyText&quot;) &amp; &quot; &quot; &amp; getTranslation(&quot;compileJournalIssueArticleTitleDummyText&quot;) &amp; i )
ElseIf templateName = EIFN Then
insertUserField(oViewCursor,&quot;rightHeader&quot; &amp; i ,getTranslation(&quot;compileJournalIssueArticleTitleDummyText&quot;) &amp; &quot; &quot; + i )
rightHeaderCell = rightHeaderTable.getCellByPosition(2,0).getStart()
oViewCursor.goToRange(rightHeaderCell, false)
insertLinkedImage(CStr(i),&quot;headerImageRight&quot;)
oViewCursor.jumpToStartOfPage()
EndIf
If templateName = &quot;&quot; Then
leftHeaderCell = leftHeaderTable.getCellByPosition(1,0).getStart()
oViewCursor.goToRange(leftHeaderCell, false)
insertUserField(oViewCursor,&quot;leftHeader&quot; &amp; i ,getTranslation(&quot;compileJournalIssueSectionDummyText&quot;) &amp; i )
ElseIf templateName = PHA Then
leftHeaderCell = leftHeaderTable.getCellByPosition(1,0).getStart()
oViewCursor.goToRange(leftHeaderCell, false)
insertUserField(oViewCursor,&quot;leftHeader&quot; &amp; i ,getTranslation(&quot;compileJournalIssueSectionDummyText&quot;) &amp; i )
ElseIf templateName = EIFN Then
leftHeaderCell = leftHeaderTable.getCellByPosition(2,0).getStart()
oViewCursor.goToRange(leftHeaderCell, false)
insertUserField(oViewCursor,&quot;leftHeader&quot; &amp; i ,getTranslation(&quot;compileJournalIssueInitialsAuthorDummyText&quot;) &amp; i )
leftHeaderCell = leftHeaderTable.getCellByPosition(0,0).getStart()
oViewCursor.goToRange(leftHeaderCell, false)
insertLinkedImage(CStr(i),&quot;headerImageLeft&quot;)
oViewCursor.jumpToStartOfPage()
EndIf
EndIf
oViewCursor.goToRange(articleStartPosition, false)
backspace()
backspace()
backspace()
oViewCursor.goToRange(oSavePosition, false)
End Sub
Private Sub setArticleUniqPageStyles(i)
Dim firstPageName As String
Dim pageName As String
Dim curPageNum As Integer
Dim prevPageNum As String
Dim leftPageNum As Long
Dim docPages As Long
Dim articlePages As Long
Dim previousPageStyle As Object
Dim pageStyles As Object
Dim curPageStyle As Object
Dim curPageStyleName As String
Dim nextStyle As Object
Dim clonedStyle As Object
Dim clonedStyleName As String
Dim oViewCursor As Object
Dim newPageName As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
pageStyles = ThisComponent.StyleFamilies.getByName(&quot;PageStyles&quot;)
&apos;Constants
articlePageNum = 1
pageName = &quot;Статья &quot; + CStr(i)
firstPageName = pageName + &quot; стр.1&quot;
curPageStyleName = oViewCursor.PageStyleName
Do Until InStr(curPageStyleName,pageName) = 0
newPageName = pageName + &quot; стр.&quot; + articlePageNum
curPageNum = CInt(oViewCursor.getPage())
&apos; Если мы находимся на первой странице статьи
If InStr(curPageStyleName, firstPageName) = 1 Then
curPageStyle = pageStyles.getByName(curPageStyleName)
previousPageStyle = curPageStyle
ElseIf InStr(curPageStyleName, pageName) = 1 Then
createPageStyleByExample(newPageName)
previousPageStyle.FollowStyle = newPageName
curPageStyle = pageStyles.getByName(newPageName)
curPageStyle.FollowStyle = pageName
previousPageStyle = curPageStyle
ElseIf oViewCursor.getPage() &lt;&gt; curPageNum Then
&apos;Пришли в конец.
&apos;MsgBox &quot;Статья закончилась!&quot;
Exit Sub
Else
Exit Sub
End If
&apos;Iterate article page number
articlePageNum = articlePageNum + 1
&apos;GO TO NEXT PAGE
oViewCursor.jumpToNextPage()
curPageStyleName = getNextPageStyleName()
Loop
End Sub
Private Sub takeWidowLinesIn
Dim oViewCursor As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
curPageStyleName = getNextPageStyleName()
Do Until InStr(curPageStyleName,&quot;Статья&quot;) = 0
takeLineIn()
oViewCursor.jumpToNextPage()
curPageStyleName = getNextPageStyleName()
Loop
End Sub
Private Sub takeDownOrpahns
Dim oViewCursor As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
curPageStyleName = getNextPageStyleName()
Do Until InStr(curPageStyleName,&quot;Статья&quot;) = 0
takeLineIn
oViewCursor.jumpToNextPage()
curPageStyleName = getNextPageStyleName()
Loop
End Sub
Private Sub takeLineIn
Dim oViewCursor As Object
Dim oTextCursor As Object
dim oEndPage As Object
Dim lineCounter As Integer
lineCounter = 0
oViewCursor = ThisComponent.CurrentController.getViewCursor()
&apos;If page is less than 4 rows then shrink content
oViewCursor.jumpToEndOfPage()
oEnd = oViewCursor.getPosition()
oViewCursor.jumpToStartOfPage()
&apos;Если в таблице - выходим
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
If NOT IsEmpty(oTextCursor.TextTable) Then
Exit Sub
End If
oViewCursor.jumpToStartOfPage()
&apos; Идем конец строки, закончился ли параграф
lineCounter = lineCounter + 1
Do Until lineCounter = 4
&apos;Test for empty line at 3 row
oViewCursor.goToEndOfLine(false)
If oEnd.X = oViewCursor.getPosition().X AND oEnd.Y = oViewCursor.getPosition().Y Then
shrinkPageContent()
Exit Sub
End If
oViewCursor.goRight(1,false)
&apos;If empty para then remove it and shrink content
If oEnd.X = oViewCursor.getPosition().X AND oEnd.Y = oViewCursor.getPosition().Y Then
oViewCursor.goLeft(1,false)
&apos;sendRM()
shrinkPageContent()
Exit Sub
End If
lineCounter = lineCounter + 1
Loop
&apos;Count page lines
oViewCursor.jumpToStartOfPage()
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;If It is a start of paragraph then there is no line to take in
If oTextCursor.isStartOfParagraph() Then
&apos;Nothing to Do
Exit Sub
End If
oViewCursor.goToEndOfLine(false)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;If it is a last line of paragraph
If oTextCursor.isEndOfParagraph() Then
shrinkPageContent()
Exit Sub
End If
oViewCursor.goToEndOfLine(false)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;If it is a last line of paragraph
If oTextCursor.isEndOfParagraph() Then
shrinkPageContent()
Exit Sub
End If
End Sub
Private Function getNextPageStyleName()
dim curPageStyleName as String
dim startPageStyleName as String
dim startPageStyle as Object
dim pageStyles as Object
dim followStyle as String
dim oViewCursor as Object
dim oTextCursor as Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
pageStyles = ThisComponent.StyleFamilies.getByName(&quot;PageStyles&quot;)
startPageStyleName = oViewCursor.PageStyleName
startPageStyle = pageStyles.getByName(startPageStyleName)
followStyle = startPageStyle.FollowStyle
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
If oTextCursor.isStartOfParagraph() Then
getNextPageStyleName = oViewCursor.PageStyleName
Exit Function
EndIf
oViewCursor.Text.insertControlCharacter(oViewCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oTextCursor.goRight(1,false)
oViewCursor.goToRange(oTextCursor,false)
getNextPageStyleName = oViewCursor.pageStyleName
oViewCursor.goLeft(1,false)
backspace()
End Function
Private Function findArticleFile(path,i)
Dim NextFile As String
Dim TestName As String
Dim endChars(2) As String
endChars(0) = &quot;_&quot;
endChars(1) = &quot;.&quot;
endChars(2) = &quot; &quot;
Dim FoundPosition As Long
Dim EndChar As String
NextFile = Dir(path+&quot;/&quot;, 0)
While NextFile &lt;&gt; &quot;&quot;
For j = LBound(endChars) To UBound(endChars)
TestName = CStr(i)+endChars(j)
FoundPosition = InStr(NextFile, TestName)
If FoundPosition = 1 Then
findArticleFile = path+&quot;/&quot;+NextFile
Exit Function
End If
Next
NextFile = Dir
Wend
findArticleFile = &quot;&quot;
End Function
Private Function InsertArticle(oFileName)
Dim document as Object
Dim dispatcher as object
Dim fileType as String
Dim oFilter as String
Dim args2(1) as new com.sun.star.beans.PropertyValue
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
fileType = Right(oFileName, 3)
If fileType = &quot;odt&quot; Then
oFilter = &quot;writer8&quot;
ElseIf fileType = &quot;doc&quot; Then
oFilter = &quot;MS Word 97&quot;
End If
args2(0).Name = &quot;Name&quot;
args2(0).Value = oFileName
args2(1).Name = &quot;Filter&quot;
args2(1).Value = oFilter
dispatcher.executeDispatch(document, &quot;.uno:InsertDoc&quot;, &quot;&quot;, 0, args2())
End Function
Private Sub getChapter
Dim testText As String
testText = getFirstTextInStyle(&quot;Заголовок 1&quot;)
End Sub
Private Function getFirstTextInStyle(styleName)
Dim oViewCursor As Object
Dim curPage As Long
Dim foundPage As Long
oViewCursor = ThisComponent.CurrentController.getViewCursor()
curPage = oViewCursor.getPage
getFirstTextInStyleDispatch(styleName)
foundPage = oViewCursor.getPage
If foundPage &gt;= curPage Then
getFirstTextInStyle = oViewCursor.String
Exit Function
End If
getFirstTextInStyle = &quot;&quot;
End Function
Private Sub setHeadingsOutlineLevels
setHeadingOutlineLevel(1,&quot;Заголовок 1&quot;)
setHeadingOutlineLevel(2,&quot;Заголовок 2&quot;)
End Sub
Sub setHeadingOutlineLevel(num,targetStyleName)
Dim oViewCursor As Object
Dim oText As Object
Dim curText As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumpToFirstPage
getFirstTextInStyleDispatch(targetStyleName)
While True
curText = oViewCursor.Text.createTextCursorByRange(oViewCursor)
If IsNull(oText) Then
oText = curText
ElseIf oText.Text.compareRegionStarts(oText,curText) = 0 AND oText.Text.compareRegionEnds(oText,curText) = 0 Then
Exit Sub
End If
oViewCursor.OutlineLevel = num
getFirstTextInStyleDispatch(targetStyleName)
Wend
End Sub
Private sub getFirstTextInStyleDispatch(styleName)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args1(21) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;SearchItem.StyleFamily&quot;
args1(0).Value = 2
args1(1).Name = &quot;SearchItem.CellType&quot;
args1(1).Value = 0
args1(2).Name = &quot;SearchItem.RowDirection&quot;
args1(2).Value = true
args1(3).Name = &quot;SearchItem.AllTables&quot;
args1(3).Value = false
args1(4).Name = &quot;SearchItem.SearchFiltered&quot;
args1(4).Value = false
args1(5).Name = &quot;SearchItem.Backward&quot;
args1(5).Value = false
args1(6).Name = &quot;SearchItem.Pattern&quot;
args1(6).Value = true
args1(7).Name = &quot;SearchItem.Content&quot;
args1(7).Value = false
args1(8).Name = &quot;SearchItem.AsianOptions&quot;
args1(8).Value = false
args1(9).Name = &quot;SearchItem.AlgorithmType&quot;
args1(9).Value = 0
args1(10).Name = &quot;SearchItem.SearchFlags&quot;
args1(10).Value = 65536
args1(11).Name = &quot;SearchItem.SearchString&quot;
args1(11).Value = styleName
args1(12).Name = &quot;SearchItem.ReplaceString&quot;
args1(12).Value = styleName
args1(13).Name = &quot;SearchItem.Locale&quot;
args1(13).Value = 255
args1(14).Name = &quot;SearchItem.ChangedChars&quot;
args1(14).Value = 2
args1(15).Name = &quot;SearchItem.DeletedChars&quot;
args1(15).Value = 2
args1(16).Name = &quot;SearchItem.InsertedChars&quot;
args1(16).Value = 2
args1(17).Name = &quot;SearchItem.TransliterateFlags&quot;
args1(17).Value = 1280
args1(18).Name = &quot;SearchItem.Command&quot;
args1(18).Value = 0
args1(19).Name = &quot;SearchItem.SearchFormatted&quot;
args1(19).Value = false
args1(20).Name = &quot;SearchItem.AlgorithmType2&quot;
args1(20).Value = 1
args1(21).Name = &quot;Quiet&quot;
args1(21).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ExecuteSearch&quot;, &quot;&quot;, 0, args1())
end Sub
Private sub insertLinkedImage(articleNum,styleName)
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args2(3) as new com.sun.star.beans.PropertyValue
args2(0).Name = &quot;FileName&quot;
args2(0).Value = path + imagesRelativePath + articleNum + &quot;.jpg&quot;
args2(1).Name = &quot;FilterName&quot;
args2(1).Value = &quot;&lt;Все форматы&gt;&quot;
args2(2).Name = &quot;AsLink&quot;
args2(2).Value = true
args2(3).Name = &quot;Style&quot;
args2(3).Value = styleName
dispatcher.executeDispatch(document, &quot;.uno:InsertGraphic&quot;, &quot;&quot;, 0, args2())
end sub
Private Sub copySectionIcon(articleNum)
FileCopy( path + allImagesRelativePath + getImageFileName(), path + imagesRelativePath + articleNum + &quot;.jpg&quot;)
End Sub
Private Function getImageFileName()
Select Case UCase(sectionName)
Case &quot;АРХИВ&quot;
getImageFileName = &quot;ARCHIVE.jpg&quot;
Case &quot;СИТУАЦИОННЫЕ ИССЛЕДОВАНИЯ&quot;
getImageFileName = &quot;CASE_STUDIES.jpg&quot;
Case &quot;МЕЖДИСЦИПЛИНАРНЫЕ ИССЛЕДОВАНИЯ&quot;
getImageFileName = &quot;INTERDISCIPLINARY.jpg&quot;
Case &quot;ПАНЕЛЬНАЯ ДИСКУССИЯ&quot;
getImageFileName = &quot;PANEL_DISCUSSION.jpg&quot;
Case &quot;ОБЗОРЫ КНИГ&quot;
getImageFileName = &quot;BOOK_REVIEWS.jpg&quot;
Case &quot;РЕДАКЦИОННАЯ СТАТЬЯ&quot;
getImageFileName = &quot;EDITORIAL.jpg&quot;
Case &quot;ЯЗЫК И СОЗНАНИЕ&quot;
getImageFileName = &quot;LANGUAGE.jpg&quot;
Case &quot;ПЕРСПЕКТИВА&quot;
getImageFileName = &quot;VISTA.jpg&quot;
Case &quot;ЭПИСТЕМОЛОГИЯ И ПОЗНАНИЕ&quot;
getImageFileName = &quot;EPISTEMOLOGY.jpg&quot;
Case Else
getImageFileName = &quot;EDITORIAL.jpg&quot;
End Select
End Function
Private sub noNumbering
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
Wait 500
dispatcher.executeDispatch(document, &quot;.uno:RemoveBullets&quot;, &quot;&quot;, 0, args1())
Wait 500
end sub
Private Sub updateLastPageFields
Dim enum1Element As Object
Dim enum1 As Object
Dim enum2 As Object
Dim thisPortion As Object
Dim footnoteText As Object
Dim label As String
Dim labelNum As Integer
Dim i As Integer
Dim cell As Object
Dim cellEnum As Object
Dim cellEnum2 As Object
Dim pageStyleName As String
Dim articleName As String
Dim articleNamePrefix As String
Dim articleNamePostfix As String
Dim strPos As Integer
Dim articleNum As Integer
Dim curNum As Integer
Dim pageNum As String
Dim textCursor As Object
Dim lastPages%( 100 )
For i = 0 to 100
lastPages%(i) = 0
next i
articleNum = 0
articleName = &quot;0&quot;
articleNamePrefix = &quot;Статья &quot;
articleNamePostfix = &quot; &quot;
Dim statusIndicator as Object
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;compileJournalIssueStatusUpdateLastPageNumbers&quot;),30)
enum1 = ThisComponent.Text.createEnumeration
While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
pageStyleName = getPageStyleNameFromEnum(enum1Element)
If Len(pageStyleName) &gt; 0 Then
strPos = InStr(pageStyleName, articleNamePrefix)
If strPos &lt;&gt; 0 Then
articleName = Right(pageStyleName, Len(pageStyleName)-Len(articleNamePrefix))
strPos = InStr(articleName, articleNamePostfix)
If strPos &gt; 0 Then
articleName = Left(articleName,strPos)
EndIf
&apos;If first article reached
If articleNum = 0 Then
articleNum = CInt(Trim(articleName))
EndIf
Else
articleName = &quot;0&quot;
EndIf
If articleNum &gt; 0 Then
curNum = CInt(Trim(articleName))
If articleNum &lt;&gt; curNum Then
pageNum = getPageNumber(enum1Element.Start)
lastPages(articleNum) = CInt(pageNum) - 1
articleNum = curNum
EndIf
EndIf
EndIf
EndIf
&apos;TODO:
&apos;OR enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;)
Wend
For i = LBound(lastPages) to UBound(lastPages)
If lastPages%(i) &lt;&gt; 0 Then
updateUserField(&quot;article&quot; + i + &quot;LastPage&quot;,lastPages%(i))
EndIf
next i
statusIndicator.end()
End Sub
Function insertUserField(cursor,fieldName,fieldValue)
Dim oField As Object &apos;Field to insert
Dim oFieldMaster As Object
Dim oMasters As Object
oTextCursor = cursor.Text.createTextCursorByRange(cursor.Start)
oField = ThisComponent.createInstance(&quot;com.sun.star.text.textfield.User&quot;)
oMasters = ThisComponent.getTextFieldMasters()
If oMasters.hasByName(&quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; fieldName) Then
oFieldMaster = oMasters.getByName(&quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; fieldName)
oFieldMaster.Name = fieldName
oFieldMaster.Content = fieldValue
Else
oFieldMaster = ThisComponent.createInstance(&quot;com.sun.star.text.FieldMaster.User&quot;)
oFieldMaster.Name = fieldName
oFieldMaster.Content = fieldValue
EndIf
oField.attachTextFieldMaster(oFieldMaster)
oTextCursor.Text.insertTextContent(oTextCursor, oField, False)
End Function
Function updateUserField(fieldName,fieldValue)
Dim oFieldMaster As Object
Dim oMasters As Object
oMasters = ThisComponent.getTextFieldMasters()
If oMasters.hasByName(&quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; fieldName) Then
oFieldMaster = oMasters.getByName(&quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; fieldName)
oFieldMaster.Content = fieldValue
EndIf
End Function
Sub createPageStyleByExample(newName)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;Param&quot;
args1(0).Value = newName
args1(1).Name = &quot;Family&quot;
args1(1).Value = 8
dispatcher.executeDispatch(document, &quot;.uno:StyleNewByExample&quot;, &quot;&quot;, 0, args1())
end Sub
sub sendRM
dim document as Object
dim dispatcher as Object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Delete&quot;, &quot;&quot;, 0, Array())
end Sub
sub backspace
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:SwBackspace&quot;, &quot;&quot;, 0, Array())
end Sub
Sub shrinkPageContent
Dim oViewCursor As Object &apos;View cursor
Dim oTextCursor As Object &apos;Text cursor
Dim oViewCurInitPosition As Object
Dim oSaveEndSelection &apos;Text cursor
Dim oEnum &apos;Cursor enumeration
Dim oPar &apos;Current paragraph
Dim sTextContent$ &apos;Service name for text content.
Dim scaleWidthShrinkValue As Integer
Dim scaleCharHeight As Integer
Dim scaleIntervalHeight As Integer
Dim kernShrinkValue As Integer
Dim startOfPara As Boolean
&apos;saveCurrentVersion
kernShrinkValue = 8
scaleWidthShrinkValue = 7
scaleCharHeight = 2
scaleIntervalHeight = 3
sTextContent = &quot;com.sun.star.text.TextContent&quot;
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCurInitPosition = oViewcursor.Text.createTextCursorByRange(oViewCursor)
&apos;Check if we are at start of paragraph go to the end of previous paragraph
If oViewCursor.Text.createTextCursorByRange(oViewCursor).isStartOfParagraph() Then
oViewCursor.goLeft(1,false)
If Len(oViewCursor.String) &lt;&gt; 1 Then
oViewCursor.goRight(1,false)
End If
End If
&apos;Move right to select left and right characters and save position to the right
oViewCursor.goRight(1,false)
oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;Select last 2 characters
oViewCursor.goLeft(2,true)
If Len(oViewCursor.String) = 2 Then
oLastChars = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;Insert hyphen if needed
insertHyphen(oLastChars,oViewCursor)
End If
&apos;Return to initial position
oViewCursor.gotoRange(oSaveEndSelection,false) &apos;Go to end of text to check page changes
oViewCursor.goLeft(1,false)
&apos;Set saved position to initial state
oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oViewCursor.jumpToPreviousPage()
oViewCursor.jumpToStartOfPage()
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;If one of textRanges is Footnote or Endnote we can&apos;t select them so it is better to exit now
If oTextCursor.Text.supportsService(&quot;com.sun.star.text.Endnote&quot;) OR oTextCursor.Text.supportsService(&quot;com.sun.star.text.Footnote&quot;) Or oTextCursor.Text.supportsService(&quot;com.sun.star.text.CellProperties&quot;) Then
shrinkPageContent = false
oViewCursor.gotoRange(oViewCurInitPosition,false)
Exit Sub
EndIf
If oSaveEndSelection.Text.supportsService(&quot;com.sun.star.text.Endnote&quot;) OR oSaveEndSelection.Text.supportsService(&quot;com.sun.star.text.Footnote&quot;) Or oTextCursor.Text.supportsService(&quot;com.sun.star.text.CellProperties&quot;) Then
shrinkPageContent = false
oViewCursor.gotoRange(oViewCurInitPosition,false)
Exit Sub
EndIf
oTextCursor.gotoRange(oSaveEndSelection,true)
oViewCursor.gotoRange(oSaveEndSelection,false) &apos;Go to end of text to check page changes
If shrinkIntervalHeight(oTextCursor,oViewCursor,scaleIntervalHeight) Then
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
If oTextCursor.isEndOfParagraph() Then
pos1 = oViewCursor.getPage()
oViewCursor.goRight(1,false)
pos2 = oViewCursor.getPage()
&apos;If we moved right to the next para and page haven&apos;t changed insert pageBreak
If pos1 = pos2 Then
insertPageBreak
End If
Else
insertPageBreak
If Not IsNull(oTextCursor.ParaFirstLineIndent) Then
oTextCursor.ParaFirstLineIndent = 0
End If
End If
Exit Sub
End If
If shrinkCharHeight(oTextCursor,oViewCursor,scaleCharHeight) Then
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
If oTextCursor.isEndOfParagraph() Then
pos1 = oViewCursor.getPage()
oViewCursor.goRight(1,false)
pos2 = oViewCursor.getPage()
&apos;If we moved right to the next para and page haven&apos;t changed insert pageBreak
If pos1 = pos2 Then
insertPageBreak
End If
Else
insertPageBreak
If Not IsNull(oTextCursor.ParaFirstLineIndent) Then
oTextCursor.ParaFirstLineIndent = 0
End If
End If
Exit Sub
End If
If shrinkKern(oTextCursor,oViewCursor,kernShrinkValue) Then
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
If oTextCursor.isEndOfParagraph() Then
pos1 = oViewCursor.getPage()
oViewCursor.goRight(1,false)
pos2 = oViewCursor.getPage()
&apos;If we moved right to the next para and page haven&apos;t changed insert pageBreak
If pos1 = pos2 Then
insertPageBreak
End If
Else
insertPageBreak
If Not IsNull(oTextCursor.ParaFirstLineIndent) Then
oTextCursor.ParaFirstLineIndent = 0
End If
End If
Exit Sub
End If
End Sub
Sub splitPages
Dim oViewCursor As Object &apos;View cursor
Dim oText &apos;Text object in current document
Dim oSaveEndSelection &apos;Text cursor
&apos;saveCurrentVersion
oViewCursor = ThisComponent.CurrentController.getViewCursor()
Dim saveFirstLineIndent As Boolean
&apos;Check if we are at start of paragraph go to the end of previous paragraph
If oViewCursor.Text.createTextCursorByRange(oViewCursor).isEndOfParagraph() Then
oViewCursor.goRight(1,false)
End If
If oViewCursor.Text.createTextCursorByRange(oViewCursor).isStartOfParagraph() Then
saveFirstLineIndent = true
Else
saveFirstLineIndent = false
End If
oViewCursor.goRight(1,false)
oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;Select last 2 characters
oViewCursor.goLeft(2,true)
If Len(oViewCursor.String) = 2 Then
&apos;Insert hyphen if needed
oLastChars = oViewCursor.Text.createTextCursorByRange(oViewCursor)
insertHyphen(oLastChars,oViewCursor)
End If
&apos;Return to initial position
oViewCursor.gotoRange(oSaveEndSelection,false) &apos;Go to end of text to check page changes
oViewCursor.goLeft(1,false)
insertPageBreak
If Not saveFirstLineIndent Then
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
If Not IsNull(oTextCursor.ParaFirstLineIndent) Then
oTextCursor.ParaFirstLineIndent = 0
End If
End If
End Sub
Function shrinkScaleWidth(oTextCursor,oViewCursor,iterations) As Boolean
Dim oParEnum &apos;paragraph enumeration
Dim oPar &apos;current paragraph
Dim oSecEnum &apos;sections enumeration
Dim oParSection &apos;paragraph text section
Dim pageNum As Integer
pageNum = oViewCursor.getPage()
For i = 1 To iterations Step 1
oParEnum = oTextCursor.createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
If oPar.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
oPar.charScaleWidth = 100 - i
If pageNum &lt;&gt; oViewCursor.getPage() Then
shrinkScaleWidth = true
Exit Function
End If
End If
Loop
Next i
shrinkScaleWidth = false
End Function
Function shrinkKern(oTextCursor,oViewCursor,iterations) As Boolean
Dim oParEnum &apos;paragraph enumeration
Dim oPar &apos;current paragraph
Dim oSecEnum &apos;sections enumeration
Dim oParSection &apos;paragraph text section
Dim pageNum As Integer
pageNum = oViewCursor.getPage()
For i = 2 To iterations Step 2
oParEnum = oTextCursor.createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
If oPar.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
oPar.CharKerning = 0 - i
If pageNum &lt;&gt; oViewCursor.getPage() Then
shrinkKern = true
Exit Function
End If
End If
Loop
Next i
shrinkKern = false
End Function
Function shrinkCharHeight(oTextCursor,oViewCursor,iterations) As Boolean
Dim oParEnum &apos;paragraph enumeration
Dim oPar &apos;current paragraph
Dim oSecEnum &apos;sections enumeration
Dim oParSection &apos;paragraph text section
Dim pageNum As Integer
Dim parCursor As Object
pageNum = oViewCursor.getPage()
For i = 1 To iterations Step 1
oParEnum = oTextCursor.createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
If oPar.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
parCursor = oTextCursor.Text.createTextCursorByRange(oPar)
parCursor.charHeight = roundHeight(parCursor.charHeight) - 0.1
If pageNum &lt;&gt; oViewCursor.getPage() Then
shrinkCharHeight = true
Exit Function
End If
End If
Loop
Next i
shrinkCharHeight = false
End Function
Function roundHeight(nHeight)
Dim lHeight As Double
Dim hHeight As Double
lHeight = Int(nHeight)
hHeight = Int(nHeight)
Dim i%
i=1
Do While lHeight &lt; nHeight And hHeight &lt; nHeight
lHeight = + i/10 + 0.001
hHeight = + (i+0.5)/10
i=i+1
Loop
roundHeight=lHeight
End Function
Function shrinkIntervalHeight(oTextCursor,oViewCursor,iterations) As Boolean
Dim oParEnum &apos;paragraph enumeration
Dim oPar &apos;current paragraph
Dim oSecEnum &apos;sections enumeration
Dim oParSection &apos;paragraph text section
Dim pageNum As Integer
Dim lineSpacing
pageNum = oViewCursor.getPage()
For i = 1 To iterations Step 1
oParEnum = oTextCursor.createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
If oPar.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
lineSpacing = oPar.ParaLineSpacing
If lineSpacing.Mode = 3 Then
lineSpacing.Height = lineSpacing.Height * 0.98
oPar.ParaLineSpacing = lineSpacing
End If
If pageNum &lt;&gt; oViewCursor.getPage() Then
shrinkIntervalHeight = true
Exit Function
End If
End If
Loop
Next i
shrinkIntervalHeight = false
End Function
Sub savecursor
Dim oViewCursor As Object &apos;View cursor
Dim oTextCursor &apos;Text cursor
Dim oSaveEndSelection &apos;Text cursor
Dim oEnum &apos;Cursor enumeration
Dim oText &apos;Text object in current document
Dim oPar &apos;Current paragraph
Dim sTextContent$ &apos;Service name for text content.
sTextContent = &quot;com.sun.star.text.TextContent&quot;
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor)
REM oViewCursor.getText.insertString(oViewCursor.getStart(), CHR$(257), False)
&apos;If Not oViewCursor.jumpToPreviousPage() Then Exit Sub
oViewCursor.jumpToPreviousPage()
oViewCursor.jumpToStartOfPage()
&apos;oViewCursor.goUp(10,true)
&apos;oViewCursor.getPage()
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;oTextCursor.gotoStart(false)
oTextCursor.gotoRange(oSaveEndSelection,true)
oParEnum = oTextCursor.createEnumeration()
Do While oParEnum.hasMoreElements()
Dim oSubSection
Dim oSecEnum
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
oPar.charScaleWidth = oPar.charScaleWidth - 1
Dim charHeight
charHeight= oPar.charHeight
Dim lineSpacing
lineSpacing = oPar.ParaLineSpacing
MsgBox lineSpacing.Mode &amp; lineSpacing.Height
If oPar.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
nPars = nPars + 1
oSecEnum = oPar.createEnumeration()
s = s &amp; nPars &amp; &quot;:&quot;
Do While oSecEnum.hasMoreElements()
oParSection = oSecEnum.nextElement()
oParSection.charScaleWidth = oParSection.charScaleWidth - 1
oParSection.CharHeight = oParSection.CharHeight * 0.99
s = s &amp; oParSection.TextPortionType &amp; &quot; Scale &quot; &amp; oParSection.CharScaleWidth &amp; &quot; Scale &quot; &amp; oParSection.CharHeight &amp; &quot;:&quot;
Loop
s = s &amp; CHR$(10)
If nPars MOD 10 = 0 Then
MsgBox s, 0, &quot;Paragraph Text Sections&quot;
s = &quot;&quot;
End If
End If
Loop
Loop
End Sub
sub insertPageBreak
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, &quot;.uno:InsertPagebreak&quot;, &quot;&quot;, 0, Array())
end sub
Sub insertHyphen(oTextCursor,oViewCursor)
Dim lastChars
&apos;lastChars = oTextCursor.getString()
replacementhyp
&apos;MsgBox lastChars
End Sub
sub replacementhyp
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
rem ----------------------------------------------------------------------
dim args1(21) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;SearchItem.StyleFamily&quot;
args1(0).Value = 2
args1(1).Name = &quot;SearchItem.CellType&quot;
args1(1).Value = 0
args1(2).Name = &quot;SearchItem.RowDirection&quot;
args1(2).Value = true
args1(3).Name = &quot;SearchItem.AllTables&quot;
args1(3).Value = false
args1(4).Name = &quot;SearchItem.SearchFiltered&quot;
args1(4).Value = false
args1(5).Name = &quot;SearchItem.Backward&quot;
args1(5).Value = false
args1(6).Name = &quot;SearchItem.Pattern&quot;
args1(6).Value = false
args1(7).Name = &quot;SearchItem.Content&quot;
args1(7).Value = false
args1(8).Name = &quot;SearchItem.AsianOptions&quot;
args1(8).Value = false
args1(9).Name = &quot;SearchItem.AlgorithmType&quot;
args1(9).Value = 1
args1(10).Name = &quot;SearchItem.SearchFlags&quot;
args1(10).Value = 71680
args1(11).Name = &quot;SearchItem.SearchString&quot;
args1(11).Value = &quot;([a-zA-Zа-яА-Я])([a-zA-Zа-яА-Я])&quot;
args1(12).Name = &quot;SearchItem.ReplaceString&quot;
args1(12).Value = &quot;$1­$2&quot;
args1(13).Name = &quot;SearchItem.Locale&quot;
args1(13).Value = 255
args1(14).Name = &quot;SearchItem.ChangedChars&quot;
args1(14).Value = 2
args1(15).Name = &quot;SearchItem.DeletedChars&quot;
args1(15).Value = 2
args1(16).Name = &quot;SearchItem.InsertedChars&quot;
args1(16).Value = 2
args1(17).Name = &quot;SearchItem.TransliterateFlags&quot;
args1(17).Value = 1024
args1(18).Name = &quot;SearchItem.Command&quot;
args1(18).Value = 3
args1(19).Name = &quot;SearchItem.SearchFormatted&quot;
args1(19).Value = false
args1(20).Name = &quot;SearchItem.AlgorithmType2&quot;
args1(20).Value = 2
args1(21).Name = &quot;Quiet&quot;
args1(21).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ExecuteSearch&quot;, &quot;&quot;, 0, args1())
end sub
sub saveCurrentVersion
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;VersionComment&quot;
args1(0).Value = getTranslation(&quot;saveVersionCommentInsertPageBreak&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, args1())
end sub
Sub removeEmptyPage
Dim oViewCursor As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumpToStartOfPage()
Dim oTextCursor As Object
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oViewCursor.jumpToEndOfPage()
oViewCursor.goToRange(oTextCursor,true)
If oViewCursor.isCollapsed Then
oViewCursor.goLeft(1,false)
SendRM()
Else
oViewCursor.jumpToEndOfPage()
End If
oViewCursor.collapseToEnd()
End Sub
Function getPageStyleNameFromEnum(enumElement)
If enumElement.pageDescName = &quot;&quot; AND Not IsEmpty(enumElement.getPropertyValue(&quot;PageStyleName&quot;)) Then
getPageStyleNameFromEnum = enumElement.pageStyleName
Else
getPageStyleNameFromEnum = enumElement.pageDescName
EndIf
End Function
Function getPageNumber(cursor As Object) As String
Dim oField As Object
Dim oTextCursor As Object
oTextCursor = cursor.Text.createTextCursorByRange(cursor.Start)
oField = ThisComponent.createInstance(&quot;com.sun.star.text.textfield.PageNumber&quot;)
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
</script:module>