Footnote area calculations
This commit is contained in:
parent
f8887020b9
commit
eb6427e657
2 changed files with 261 additions and 0 deletions
|
@ -19,6 +19,249 @@ Sub decrementKern()
|
||||||
changeKern(-2)
|
changeKern(-2)
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Sub balanceDoublePagesFootnotes
|
||||||
|
Dim oViewCursor As Object
|
||||||
|
oViewCursor = Thiscomponent.currentController.getViewCursor()
|
||||||
|
Dim leftHeight As Long
|
||||||
|
Dim rightHeight As Long
|
||||||
|
Dim odd As Integer
|
||||||
|
Dim rightPageNum As Integer
|
||||||
|
Dim leftPageNum As Integer
|
||||||
|
Dim startPage As Integer
|
||||||
|
Dim docPages As Integer
|
||||||
|
startPage = oViewCursor.getPage()
|
||||||
|
docPages = thiscomponent.currentController.pageCount
|
||||||
|
odd = startPage Mod 2
|
||||||
|
If startPage <> 1 AND (startPage <> docPages Or odd = 1) Then
|
||||||
|
If odd = 1 Then
|
||||||
|
rightPageNum = startPage
|
||||||
|
leftPageNum = startPage - 1
|
||||||
|
Else
|
||||||
|
leftPageNum = startPage
|
||||||
|
rightPageNum = startPage + 1
|
||||||
|
EndIf
|
||||||
|
If pageHasNotes(leftPageNum) And pageHasNotes(rightPageNum) Then
|
||||||
|
leftHeight = getFootnoteAreaHeight(leftPageNum)
|
||||||
|
rightHeight = getFootnoteAreaHeight(rightPageNum)
|
||||||
|
EndIf
|
||||||
|
MsgBox leftHeight & " " & rightHeight
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
|
Function getFootnoteAreaHeight(pageNumber As Integer)
|
||||||
|
Dim oViewCursor As Object
|
||||||
|
Dim fnAreaEnd As Object
|
||||||
|
Dim pageStyleName As String
|
||||||
|
Dim oStyles As Object
|
||||||
|
Dim newHeight As Integer
|
||||||
|
Dim initialHeight As Integer
|
||||||
|
oStyles = ThisComponent.StyleFamilies
|
||||||
|
Dim pageSTyles As Object
|
||||||
|
pageStyles = oStyles.getByName(oStyles.elementNames(2))
|
||||||
|
Dim pageStyle As Object
|
||||||
|
Dim decrement As Integer
|
||||||
|
Dim tmpPageNum As Integer
|
||||||
|
decrement = 10000
|
||||||
|
oViewCursor = Thiscomponent.currentController.getViewCursor()
|
||||||
|
oViewCursor.jumpToPage(pageNumber)
|
||||||
|
pageStyleName = getCurPageStyleName()
|
||||||
|
pageStyle = pageStyles.getByName(pageStyleName)
|
||||||
|
initialHeight = pageStyle.FootnoteHeight
|
||||||
|
If pageStyle.FootnoteHeight = 0 Then
|
||||||
|
pageStyle.FootnoteHeight = pageStyle.Height - pageStyle.TopMargin - pageStyle.BottomMargin
|
||||||
|
EndIf
|
||||||
|
'TODO ADD CHECK IF THERE IS A FOOTNOTE AREA ON PAGE
|
||||||
|
fnAreaEnd = getFNAreaEnd(pageNumber)
|
||||||
|
Dim savePageHeight As Long
|
||||||
|
savePageHeight = pageStyle.Height
|
||||||
|
Do While pageStyle.FootnoteHeight > 10
|
||||||
|
Do While pageStyle.FootnoteHeight < decrement
|
||||||
|
decrement = decrement / 2
|
||||||
|
Loop
|
||||||
|
newHeight = pageStyle.FootnoteHeight - decrement
|
||||||
|
pageStyle.FootnoteHeight = newHeight
|
||||||
|
tmpPageNum = getPageNumberVCurs(fnAreaEnd)
|
||||||
|
If tmpPageNum <> pageNumber Then
|
||||||
|
If decrement < 4 Then
|
||||||
|
pageStyle.FootnoteHeight = pageStyle.FootnoteHeight + decrement * 2
|
||||||
|
'Hack to force libreoffice to refresh page layout
|
||||||
|
tmpPageNum = getPageNumberVCurs(fnAreaEnd)
|
||||||
|
If tmpPageNum <> pageNumber Then
|
||||||
|
pageStyle.Height = savePageHeight + 100
|
||||||
|
pageStyle.Height = savePageHeight
|
||||||
|
EndIf
|
||||||
|
Exit Do
|
||||||
|
Else
|
||||||
|
newHeight = pageStyle.FootnoteHeight + decrement
|
||||||
|
decrement = decrement / 2
|
||||||
|
pageStyle.FootnoteHeight = newHeight
|
||||||
|
'Hack to force libreoffice to refresh page layout
|
||||||
|
tmpPageNum = getPageNumberVCurs(fnAreaEnd)
|
||||||
|
If tmpPageNum <> pageNumber Then
|
||||||
|
pageStyle.Height = savePageHeight + 100
|
||||||
|
pageStyle.Height = savePageHeight
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
Loop
|
||||||
|
|
||||||
|
tmpPageNum = getPageNumberVCurs(fnAreaEnd)
|
||||||
|
If tmpPageNum <> pageNumber Then
|
||||||
|
pageStyle.FootnoteHeight = 0
|
||||||
|
MsgBox "Error"
|
||||||
|
Stop
|
||||||
|
EndIf
|
||||||
|
getFootnoteAreaHeight = pageStyle.FootnoteHeight
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
sub pageDialog
|
||||||
|
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("com.sun.star.frame.DispatchHelper")
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------------
|
||||||
|
dispatcher.executeDispatch(document, ".uno:PageSettingDialog", "", 0, Array())
|
||||||
|
|
||||||
|
|
||||||
|
end sub
|
||||||
|
|
||||||
|
Function getPageNumberVCurs(cursor As object) As Integer
|
||||||
|
Dim oViewCursor As Object
|
||||||
|
Dim oSavePosition As Object
|
||||||
|
oViewCursor = Thiscomponent.currentController.getViewCursor()
|
||||||
|
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||||
|
oViewCursor.goToRange(cursor.Start,false)
|
||||||
|
getPageNumberVCurs = oViewCursor.getPage()
|
||||||
|
oViewCursor.goToRange(oViewCursor, false)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
Function pageHasNotes(pageNumber As Integer) As Boolean
|
||||||
|
Dim allNotes As Object
|
||||||
|
allNotes = thisComponent.FootNotes
|
||||||
|
Dim curNote As Object
|
||||||
|
Dim noteStartPage As Integer
|
||||||
|
Dim noteEndPage As Integer
|
||||||
|
Dim oEnum As Object
|
||||||
|
' Dim noteStartCursor As Object
|
||||||
|
Dim endtText As Object
|
||||||
|
pageHasNotes = false
|
||||||
|
Dim x As Integer
|
||||||
|
For x = 0 to allNotes.Count -1
|
||||||
|
curNote = allNotes.getByIndex(x)
|
||||||
|
noteEndPage = getPageNumberVCurs(curNote.Text.End)
|
||||||
|
If noteEndPage >= pageNumber Then
|
||||||
|
noteStartPage = getPageNumberVCurs(curNote.Text.Start)
|
||||||
|
If pageNumber = noteStartPage Or (noteStartPage < pageNumber And noteEndPage >= pageNumber) Then
|
||||||
|
pageHasNotes = true
|
||||||
|
Exit function
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
Next x
|
||||||
|
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function getFNAreaEnd(pageNumber As Integer)
|
||||||
|
Dim allNotes As Object
|
||||||
|
allNotes = thisComponent.FootNotes
|
||||||
|
Dim curNote As Object
|
||||||
|
Dim noteStartPage As Integer
|
||||||
|
Dim noteEndPage As Integer
|
||||||
|
Dim prevNote As Object
|
||||||
|
Dim oEnum As Object
|
||||||
|
' Dim noteStartCursor As Object
|
||||||
|
Dim endtText As Object
|
||||||
|
Dim pageHasNotes As Boolean
|
||||||
|
pageHasNotes = false
|
||||||
|
Dim x As Integer
|
||||||
|
For x = 0 to allNotes.Count -1
|
||||||
|
curNote = allNotes.getByIndex(x)
|
||||||
|
noteEndPage = getPageNumberVCurs(curNote.Text.End)
|
||||||
|
If noteEndPage >= pageNumber Then
|
||||||
|
noteStartPage = getPageNumberVCurs(curNote.Text.Start)
|
||||||
|
If pageNumber = noteStartPage Or (noteStartPage < pageNumber And noteEndPage >= pageNumber) Then
|
||||||
|
pageHasNotes = true
|
||||||
|
EndIf
|
||||||
|
If pageHasNotes AND pageNumber < noteStartPage Then
|
||||||
|
getFNAreaEnd = prevNote.Text.createTextCursorByRange(prevNote.Text.End)
|
||||||
|
Exit function
|
||||||
|
Endif
|
||||||
|
If pageHasNotes AND pageNumber < noteEndPage Then
|
||||||
|
getFNAreaEnd = getFNAreaEndInFootnote(curNote,pageNumber)
|
||||||
|
Exit function
|
||||||
|
EndIf
|
||||||
|
prevNote = curNote
|
||||||
|
EndIf
|
||||||
|
Next x
|
||||||
|
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function getFNAreaEndInFootnote(note As Object, pageNum As Integer)
|
||||||
|
Dim oViewCursor As Object
|
||||||
|
Dim oSavePosition As Object
|
||||||
|
Dim tmpPageNum As Integer
|
||||||
|
|
||||||
|
If getPageNumber(note.Text.Start) > pageNum Then
|
||||||
|
'ERROR Footnote starts after this page number
|
||||||
|
Exit Function
|
||||||
|
EndIf
|
||||||
|
oViewCursor = Thiscomponent.currentController.getViewCursor()
|
||||||
|
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||||
|
oViewCursor.goToRange(note.Text.End,false)
|
||||||
|
Do
|
||||||
|
oViewCursor.gotoStartOfLine(false)
|
||||||
|
tmpPageNum = getPageNumber(oViewCursor)
|
||||||
|
If tmpPageNum <= pageNum Then
|
||||||
|
Exit Do
|
||||||
|
EndIf
|
||||||
|
oViewCursor.goLeft(1,false)
|
||||||
|
tmpPageNum = getPageNumber(oViewCursor)
|
||||||
|
Loop While tmpPageNum > pageNum
|
||||||
|
getFNAreaEndInFootnote = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||||
|
oViewCursor.goToRange(oSavePosition,false)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
Sub getFNAreaStart
|
||||||
|
Dim pageNumber As Integer
|
||||||
|
pageNumber = getPageNumber(Thiscomponent.currentController.getViewCursor())
|
||||||
|
Dim allNotes As Object
|
||||||
|
allNotes = thisComponent.FootNotes
|
||||||
|
Dim aNote As Object
|
||||||
|
Dim oEnum As Object
|
||||||
|
Dim noteStart As Object
|
||||||
|
Dim noteEnd As Object
|
||||||
|
Dim x As Integer
|
||||||
|
For x = 0 to allNotes.Count -1
|
||||||
|
aNote = allNotes.getByIndex(x)
|
||||||
|
'oEnum = aNote.Text.createEnumeration()
|
||||||
|
noteStart = aNote.Text.createTextCursorByRange(aNote.Text.Start)
|
||||||
|
noteEnd = aNote.Text.createTextCursorByRange(aNote.Text.End)
|
||||||
|
If pageNumber = getPageNumber(noteStart) Then
|
||||||
|
MsgBox "Starts here " & x & " page number " & pageNumber
|
||||||
|
Exit sub
|
||||||
|
Endif
|
||||||
|
If pageNumber = getPageNumber(noteEnd) Then
|
||||||
|
MsgBox "ends here " + x
|
||||||
|
Exit sub
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
'Do While oEnum.hasMoreElements()
|
||||||
|
' oCurPar = oEnum.nextElement()
|
||||||
|
'Loop
|
||||||
|
Next
|
||||||
|
'Globalscope.BasicLibraries.LoadLibrary("MRILib")
|
||||||
|
'mri ThisComponent
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
Function changeCharWidth(delta) As Boolean
|
Function changeCharWidth(delta) As Boolean
|
||||||
Dim oViewCursor As Object
|
Dim oViewCursor As Object
|
||||||
|
@ -46,4 +289,21 @@ Function changeKern(delta) As Boolean
|
||||||
End If
|
End If
|
||||||
oViewCursor.CharKerning = kerning + delta
|
oViewCursor.CharKerning = kerning + delta
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
sub undoUno
|
||||||
|
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("com.sun.star.frame.DispatchHelper")
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------------
|
||||||
|
dispatcher.executeDispatch(document, ".uno:Undo", "", 0, Array())
|
||||||
|
|
||||||
|
|
||||||
|
end sub
|
||||||
</script:module>
|
</script:module>
|
|
@ -628,6 +628,7 @@ Private Sub setArticleUniqPageStyles(i)
|
||||||
Dim clonedStyle As Object
|
Dim clonedStyle As Object
|
||||||
Dim clonedStyleName As String
|
Dim clonedStyleName As String
|
||||||
Dim oViewCursor As Object
|
Dim oViewCursor As Object
|
||||||
|
Dim newPageName As String
|
||||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||||
pageStyles = ThisComponent.StyleFamilies.getByName("PageStyles")
|
pageStyles = ThisComponent.StyleFamilies.getByName("PageStyles")
|
||||||
'Constants
|
'Constants
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue