From 3f8fd4f186ba635717f49009b741640e68fe02cb Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Thu, 12 Mar 2020 17:48:36 +0100 Subject: [PATCH] Bugfixes --- ePublishing/Hyphenations.xba | 44 +++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/ePublishing/Hyphenations.xba b/ePublishing/Hyphenations.xba index 8e218e0..b32ff68 100644 --- a/ePublishing/Hyphenations.xba +++ b/ePublishing/Hyphenations.xba @@ -1,10 +1,9 @@ -Private Sub markHyph2 +Private Sub markHyph3 End sub Private Sub convertHyphInDoc() - Dim description As String Dim allNotes As Object dim aNote As Object @@ -69,26 +68,32 @@ Private Sub convertHyphInText(textElement) End Sub Private Sub convertParaHyphens(para) - Dim lineEnd As String + Dim lineEnds() As Object Dim autoHyphens() As Object Dim autoBreaks() As Object Dim lineNumbers() As Integer +' Dim lineShifts() As Integer Dim charNum as Integer Dim lineLength As Integer Dim i As Integer + Dim vCurs As Object + Dim tCurs As Object + Dim lineCurs As Object 'No hyphenation needed If para.ParaIsHyphenation = false Then Exit Sub EndIf vCurs = ThisComponent.currentController.getViewCursor() - vCurs.goToRange(para.Anchor,false) - tCurs = vCurs.Text.createTextCursorByRange(vCurs) + vCurs.goToRange(para.Start,false) + tCurs = para.Text.createTextCursorByRange(vCurs) tCurs.goToStartOfParagraph(false) vCurs.goToRange(tCurs,false) i = 0 Do While NOT tCurs.isEndOfParagraph() OR NOT tCurs.isStartOfParagraph() - vCurs.gotoEndOfLine(true) - lineLength = Len(vCurs.String) + vCurs.gotoEndOfLine(false) + lineCursor = para.Text.createTextCursorByRange(vCurs.End) + lineCursor.goToRange(tCurs,true) + lineLength = Len(lineCursor.String) vCurs.collapseToEnd() i = i + 1 tCurs.goToRange(vCurs.End,false) @@ -110,10 +115,15 @@ Private Sub convertParaHyphens(para) If needHyphen(lastChar,nextChar,lineLength) Then addToArray(autoHyphens(),tCurs.Text.createTextCursorByRange(tCurs)) addToArray(lineNumbers(),i) + ' addToArray(lineShifts(),1) 'replaceHyphen(tCurs,vCurs) ElseIf needLineBreak(lastChar,newChar) Then addToArray(autoBreaks(),tCurs.Text.createTextCursorByRange(tCurs)) + ' addToArray(lineShifts(),1) + Else + ' addToArray(lineShifts(),0) EndIf + addToArray(lineEnds(),tCurs.Text.createTextCursorByRange(tCurs)) tCurs.goRight(1,false) vCurs.goToRange(tCurs,false) Loop @@ -129,9 +139,27 @@ Private Sub convertParaHyphens(para) replaceHyphen(autoHyphens(i),lineNumbers(i)) Next i EndIf +' verifyHyphenation(lineEnds,lineShifts) End Sub +Private Sub verifyHyphenation(lineEnds() As Object) + Dim i As Integer + If Lbound(lineEnds) > Ubound(lineEnds) Then + Exit Sub + EndIf + Dim vCurs As Object + vCurs = ThisComponent.currentController.getViewCursor() + For i = (Lbound(lineEnds)) To (Ubound(lineEnds)) + vCurs.goToRange(lineEnds(i),false) + If NOT (vCurs.isAtEndOfLine() OR vCurs.isAtStartOfLine()) Then + MsgBox "Конвертация прервана. Обратитесь к разработчику." + Stop + EndIf + Next i +End Sub + + Private Sub insertBreak(tCursor As Object) 'U+200B Zero length space tCursor.String = "​" @@ -384,4 +412,4 @@ Private Function confirm(description) EndIf End Function - \ No newline at end of file +