This commit is contained in:
Georgy Litvinov 2020-03-12 13:01:19 +01:00
commit 9fa7e795a3
12 changed files with 456 additions and 0 deletions

32
Addons.xcu Normal file
View file

@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office">
<node oor:name="AddonUI">
<node oor:name="OfficeMenuBar">
<node oor:name="pro.litvinovg.epublishing.menu" oor:op="replace">
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.GlobalDocument,com.sun.star.text.TextDocument,com.sun.star.text.WebDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en">ePublishing</value>
</prop>
<node oor:name="Submenu">
<node oor:name="HyphenationsConversion" oor:op="replace">
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.GlobalDocument,com.sun.star.text.TextDocument,com.sun.star.text.WebDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en">Convert authHyphenations to manual</value>
<value xml:lang="ru">Конвертация автоматических переносов в ручные</value>
</prop>
<prop oor:name="URL" oor:type="xs:string">
<value>macro:///ePublishing.Hyphenations.convertAutoHyphToManual</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
</node>
</node>
</node>
</node>
</oor:component-data>

5
META-INF/manifest.xml Normal file
View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest>
<manifest:file-entry manifest:full-path="ePublishing/" manifest:media-type="application/vnd.sun.star.basic-library"/>
<manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
</manifest:manifest>

37
description.xml Normal file
View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://openoffice.org/extensions/description/2006"
xmlns:dep="http://openoffice.org/extensions/description/2006"
xmlns:xlink="http://www.w3.org/1999/xlink">
<identifier value="pro.litvinovg.epublishing" />
<version value="0.0.1" />
<platform value="all" />
<display-name>
<name lang="ru">Инструменты для создания электронных изданий</name>
<name lang="en">Instruments for digital publishing creation </name>
</display-name>
<registration>
<simple-license accept-by="admin" suppress-on-update="true" suppress-if-required="true" >
<license-text xlink:href="license_en.txt" lang="en" />
<license-text xlink:href="license_ru.txt" lang="ru" />
</simple-license>
</registration>
<dependencies>
<OpenOffice.org-minimal-version value="4.1" dep:name="OpenOffice.org, LibreOffice 4.1 or later" />
</dependencies>
<publisher>
<name xlink:href="mailto:public@litvinovg.pro" lang="en">Georgy Litvinov</name>
</publisher>
<release-notes>
<src xlink:href="releasenotes.txt" lang="en" />
</release-notes>
<extension-description>
<src xlink:href="description/description_ru.txt" lang="ru" />
<src xlink:href="description/description_en.txt" lang="en" />
</extension-description>
<icon>
<default xlink:href="icons/addon_icon.png" />
<high-contrast xlink:href="icons/addon_icon.png" />
</icon>
</description>

View file

@ -0,0 +1 @@
Extenstion for digital publishing in HTML and EPUB with pagingation.

View file

@ -0,0 +1,2 @@
Расширение для верстки документов в html и epub с сохранением пагинации.
Предоставляет различные инструменты для автоматизации подготовки документа к публикации.

View file

@ -0,0 +1,356 @@
<?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="Hyphenations" script:language="StarBasic">sub markHyph1
End sub
Sub convertHyphInDoc()
Dim statusIndicator as Object
statusIndicator = ThisComponent.getCurrentController.StatusIndicator
statusIndicator.Start(&quot;Конвертация переносов, подождите&quot;,10)
AcceptAllTrackedChanges
convertHyphInText(ThisComponent.Text)
&apos; Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
statusIndicator.Start(&quot;Конвертация переносов, подождите&quot;,70)
allNotes = ThisComponent.FootNotes
For x = 0 to allNotes.Count -1
aNote = allNotes.getByIndex(x)
convertHyphInText(aNote.Text)
Next
&apos;disableAutoHyph()
statusIndicator.end()
MsgBox &quot;Конвертация переносов успешно завершена.&quot;
End Sub
sub disableAutoHyph()
Dim propertySetInfo As Object
Dim oPositionOfMatch As Long
oFamilies = ThisComponent.StyleFamilies
sElements() = oFamilies.getElementNames()
oFamily = oFamilies.getByName(sElements(1))
For j = 0 to oFamily.getCount -1
oStyle = oFamily.getByIndex(j)
propertySetInfo = oStyle.getPropertySetInfo()
If propertySetInfo.hasPropertyByName(&quot;ParaIsHyphenation&quot;) Then
oStyle.ParaIsHyphenation = false
EndIf
Next
End Sub
Sub convertHyphInText(textElement)
Dim enum1Element As Object
Dim enum1 As Object
Dim i As Integer
Dim cell As Object
enum1 = textElement.createEnumeration()
While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
convertParaHyphens(enum1Element)
ElseIf enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
cellNames = enum1Element.cellNames
For i = LBound(cellNames) To Ubound(cellNames)
cell = enum1Element.getCellByName(cellNames(i))
cellText = cell.getText()
convertHyphInText(cellText)
Next i
Else
EndIf
Wend
End Sub
Sub convertParaHyphens(para)
Dim lineEnd As String
Dim autoHyphens() As Object
Dim autoBreaks() As Object
Dim lineNumbers() As Integer
Dim charNum as Integer
Dim lineLength As Integer
Dim i As Integer
&apos;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)
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.collapseToEnd()
i = i + 1
tCurs.goToRange(vCurs.End,false)
If (tCurs.isEndOfParagraph()) Then
Exit Do
EndIf
lastChar = getPrevChar(tCurs)
nextChar = getNextChar(tCurs)
If Len(nextChar) &gt; 0 Then
charNum = Asc(nextChar)
If charNum &gt; 767 AND charNum &lt; 880 THen
tCurs.goRight(1,false)
lastChar = getPrevChar(tCurs)
nextChar = getNextChar(tCurs)
EndIf
EndIf
If needHyphen(lastChar,nextChar,lineLength) Then
addToArray(autoHyphens(),tCurs.Text.createTextCursorByRange(tCurs))
addToArray(lineNumbers(),i)
&apos;replaceHyphen(tCurs,vCurs)
ElseIf needLineBreak(lastChar,newChar) Then
addToArray(autoBreaks(),tCurs.Text.createTextCursorByRange(tCurs))
EndIf
tCurs.goRight(1,false)
vCurs.goToRange(tCurs,false)
Loop
If Ubound(autoBreaks) &lt;&gt; -1 Then
For i = 0 To (Ubound(autoBreaks))
insertBreak(autoBreaks(i))
Next i
EndIf
para.ParaIsHyphenation = false
If Ubound(autoHyphens) &lt;&gt; -1 Then
For i = 0 To (Ubound(autoHyphens))
replaceHyphen(autoHyphens(i),lineNumbers(i))
Next i
EndIf
End Sub
Sub insertBreak(tCursor As Object)
&apos;U+200B Zero length space
tCursor.String = &quot;&quot;
End Sub
Function getPrevChar(tCurs As Object)
tCurs.goLeft(1,true)
getPrevChar = tCurs.getString()
tCurs.goRight(1,false)
End Function
Function getNextChar(tCurs As Object)
tCurs.goRight(1,true)
getNextChar = tCurs.getString()
tCurs.goLeft(1,false)
End Function
Sub replaceHyphen(tCurs As Object,lineNumber As Integer)
Dim curLineNum As Integer
Dim vCurs As Object
Dim tLine As Object
vCurs = ThisComponent.currentController.getViewCursor()
&apos;insert soft hyphen character U+00AD
tCurs.Text.insertControlCharacter(tCurs.End,com.sun.star.text.ControlCharacter.SOFT_HYPHEN,true)
vCurs.goToRange(tCurs.End,false)
If vCurs.isAtEndOfLine() = false AND vCurs.isAtStartOfLine() = false Then
curLineNum = getParaLineNumber(vCurs)
If curLineNum &gt; lineNumber Then
compressLine(tCurs)
Else
stretchLine(tCurs)
EndIf
EndIf
If vCurs.isAtEndOfLine() = false AND vCurs.isAtStartOfLine() = false Then
MsgBox &quot;Конвертация переносов не выполнена. Алгоритм нуждается в доработке. Обратитесь к разработчику.&quot;
Stop
EndIf
End Sub
Sub compressLine(tCurs As Object)
Dim vCurs As Object
Dim tLine As Object
Dim kerning As Integer
Dim lineLength As Integer
Dim portions As Integer
Dim portionSize As Integer
Dim textPortions() As Object
Dim startPosition As Object
Dim tPortion As Object
portions = 4
vCurs = ThisComponent.currentController.getViewCursor()
vCurs.goToRange(tCurs,false)
vCurs.goToStartOfLine(true)
vCurs.goLeft(1,true)
vCurs.goToStartOfLine(true)
tLine = vCurs.Text.createTextCursorByRange(vCurs)
lineLength = Len(tLine.String)
startPosition = tLine.End
If lineLength &gt;= 20 Then
portionSize = lineLength/portions
For i = 0 To portions - 2
tPortion = vCurs.Text.createTextCursorByRange(startPosition)
tPortion.goLeft(portionSize,true)
addToArray(textPortions(),tPortion)
startPosition = tPortion.End
Next i
tPortion = vCurs.Text.createTextCursorByRange(startPosition)
tPortion.goToRange(tLine.Start,true)
addToArray(textPortions(),tPortion)
EndIf
vCurs.goToRange(tCurs,false)
kerning = 10
tLine.CharKerning = kerning
If lineLength &gt; 8 Then
Do While vCurs.isAtEndOfLine() = false AND vCurs.isAtStartOfLine() = false
kerning = kerning - 1
For i = (Lbound(textPortions)) To (Ubound(textPortions))
textPortions(i).CharKerning = kerning
vCurs.goToRange(tCurs,false)
If vCurs.isAtEndOfLine() = true OR vCurs.isAtStartOfLine() = true Then
Exit Do
EndIf
Next i
If kerning &lt; -15 Then
Exit Do
EndIf
Loop
Else
Do While vCurs.isAtEndOfLine() = false AND vCurs.isAtStartOfLine() = false
kerning = kerning - 1
tLine.CharKerning = kerning
vCurs.goToRange(tCurs,false)
If kerning &lt; -15 Then
Exit Do
EndIf
Loop
EndIf
End Sub
Sub stretchLine(tCurs As Object)
Dim vCurs As Object
Dim tLine As Object
Dim kerning As Integer
vCurs = ThisComponent.currentController.getViewCursor()
vCurs.goToRange(tCurs,false)
vCurs.goToStartOfLine(true)
tLine = vCurs.Text.createTextCursorByRange(vCurs)
vCurs.goToRange(tCurs,false)
kerning = -10
tLine.CharKerning = kerning
Do While vCurs.isAtEndOfLine() = false AND vCurs.isAtStartOfLine() = false
kerning = kerning + 1
tLine.CharKerning = kerning
vCurs.goToRange(tCurs,false)
If tLine.CharKerning &gt; 15 Then
Exit Do
EndIf
Loop
End Sub
Function getParaLineNumber(vCursor As Object)
Dim lineNumber As Integer
Dim oSavePosition As Object
Dim tCursor As Object
oSavePosition = vCursor.Text.createTextCursorByRange(vCursor)
tCursor = vCursor.Text.createTextCursorByRange(vCursor)
lineNumber = 1
vCursor.gotoStartOfLine(false)
tCursor.gotoRange(vCursor,false)
Do While NOT tCursor.isStartOfParagraph()
vCursor.goLeft(1,false)
vCursor.gotoStartOfLine(false)
tCursor.gotoRange(vCursor,false)
lineNumber = lineNumber + 1
Loop
vCursor.goToRange(oSavePosition,false)
getParaLineNumber = lineNumber
End Function
Function needLineBreak(before,after)
needLineBreak = false
If before = &quot;/&quot; Then
If after &lt;&gt; &quot; &quot; AND after &lt;&gt; Chr(10) Then
needLineBreak = true
EndIf
EndIf
End Function
Sub insertLineBreak(tCurs)
tCurs.Text.insertControlCharacter(tCurs.End,com.sun.star.text.ControlCharacter.LINE_BREAK,False)
End Sub
Function needHyphen(before As String, after As String,lineLength As Integer)
Dim charNumBefore as Integer
Dim charNumAfter as Integer
needHyphen = true
If lineLength &lt; 2 Then
needHyphen = false
EndIf
&apos;MsgBox Asc(newChar)
&apos;Both are numbers
If Len(before) &gt; 0 Then
charNumBefore = Asc(before)
If charNumBefore &gt; 47 AND charNumBefore &lt; 58 Then
If Len(after) &gt; 0 Then
charNumAfter = Asc(after)
If charNumAfter &gt; 47 AND charNumAfter &lt; 58 Then
needHyphen = false
EndIf
EndIf
EndIf
EndIf
Select Case before
Case &quot; &quot;
needHyphen = false
&apos;U+002D Hyphen minus
Case &quot;-&quot;
needHyphen = false
&apos;U+2010 Hyphen
Case &quot;&quot;
needHyphen = false
Case &quot;­&quot;
needHyphen = false
&apos;U+2014 Em dash
Case &quot;—&quot;
needHyphen = false
&apos;U+2013 En dash
Case &quot;&quot;
needHyphen = false
&apos;U+2012 Figure Dash
Case &quot;&quot;
needHyphen = false
Case &quot;…&quot;
needHyphen = false
Case &quot;/&quot;
needHyphen = false
End Select
Select Case after
Case &quot; &quot;
needHyphen = false
Case &quot;-&quot;
needHyphen = false
Case &quot;­&quot;
needHyphen = false
&apos;newline U+000A
Case Chr(10)
needHyphen = false
End Select
End Function
sub AcceptAllTrackedChanges
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:AcceptAllTrackedChanges&quot;, &quot;&quot;, 0, Array())
end sub
</script:module>

6
ePublishing/script.xlb Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="ePublishing" library:readonly="false" library:passwordprotected="false">
<library:element library:name="Hyphenations"/>
</library:library>

BIN
icons/addon_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

BIN
icons/clean.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

BIN
icons/validate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

10
license_en.txt Normal file
View file

@ -0,0 +1,10 @@
The author of this extension is:
Georgy Litvinov (public@litvinovg.pro)
Copyright 2019.
This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3 of the License.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library. If not, see <http://www.gnu.org/licenses/>.

7
license_ru.txt Normal file
View file

@ -0,0 +1,7 @@
Автор расширения:
Георгий Литвинов (public@litvinovg.pro)
Copyright 2019.
Это расширение является свободным программным обеспечением, вы можете распространять и/или модифицировать его в соответствии с лицензией GNU Lesser General Public License версии 3.0, опубликованной Free Software Foundation.
Это расширение распространяется в надежде, что оно будет полезным, но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ; даже без подразумеваемых гарантий КОММЕРЧЕСКОЙ ЦЕННОСТИ или ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ. См. GNU Lesser General Public License для более детальной информации: http://www.gnu.org/licenses/