1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# Grammalecte for Writer
# License: MPL 2
# A derivative work of Lightproof from László Németh (http://cgit.freedesktop.org/libreoffice/lightproof/)
import json
import re
import sys
import traceback
from collections import deque
from operator import itemgetter
from bisect import bisect_left
import uno
import unohelper
from com.sun.star.linguistic2 import XProofreader, XSupportedLocales
from com.sun.star.linguistic2 import ProofreadingResult
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# Grammalecte for Writer
# License: MPL 2
# A derivative work of Lightproof from László Németh (http://cgit.freedesktop.org/libreoffice/lightproof/)
import json
import re
import sys
import traceback
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect_right
import uno
import unohelper
from com.sun.star.linguistic2 import XProofreader, XSupportedLocales
from com.sun.star.linguistic2 import ProofreadingResult
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
|
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
def convertErrorsPosition (self, sText, aErrors):
"change position of errors, returns offset"
# last char position of the last error
# To see if errors position is correct, try with:
# J'en ai mare, 𝐴𝐴𝐴𝐴𝐴, je vient, (𝑉ᵣ = 𝐴·𝑣H). C'est sa, mais oui... Je suis très fâchés.
# Qu'il sais, 𝐴𝐴𝐴, je vient, (𝑉ᵣ = 𝐴·𝑣H). Oui... Je suis fâchés
nCheckEnd = 0
for xErr in aErrors:
nCheckEnd = max(xErr.nErrorStart + xErr.nErrorLength, nCheckEnd)
# list thresholds of offsets
lThresholds = []
for iCursor in range(nCheckEnd):
if ord(sText[iCursor]) > 65535: # \U00010000: each chars beyond this point has a length of 2
lThresholds.append(iCursor + 1) # +1 because only chars after are shifted
# modify errors position according to thresholds
for xErr in aErrors:
nErrorEnd = xErr.nErrorStart + xErr.nErrorLength
xErr.nErrorStart += bisect_left(lThresholds, xErr.nErrorStart)
nErrorEnd += bisect_left(lThresholds, nErrorEnd)
xErr.nErrorLength = nErrorEnd - xErr.nErrorStart
return len(lThresholds)
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(Grammalecte, "org.openoffice.comp.pyuno.Lightproof."+gce.pkg, ("com.sun.star.linguistic2.Proofreader",),)
# g_ImplementationHelper.addImplementation( opt_handler.LightproofOptionsEventHandler, \
# "org.openoffice.comp.pyuno.LightproofOptionsEventHandler." + gce.pkg, ("com.sun.star.awt.XContainerWindowEventHandler",),)
|
|
>
>
|
|
>
>
>
>
|
|
>
|
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
def convertErrorsPosition (self, sText, aErrors):
"change position of errors, returns offset"
# last char position of the last error
# To see if errors position is correct, try with:
# J'en ai mare, 𝐴𝐴𝐴𝐴𝐴, je vient, (𝑉ᵣ = 𝐴·𝑣H). C'est sa, mais oui... Je suis très fâchés.
# Qu'il sais, 𝐴𝐴𝐴, je vient, (𝑉ᵣ = 𝐴·𝑣H). Oui... Je suis fâchés
# C’est ça. Ça existe sur 𝐴 (activer option “ponctuation en fin de ligne”)
nCheckEnd = 0
for xErr in aErrors:
nCheckEnd = max(xErr.nErrorStart + xErr.nErrorLength, nCheckEnd)
nCheckEnd = min(nCheckEnd+10, len(sText))
# list thresholds of offsets
lThresholds = []
for iCursor in range(nCheckEnd):
try:
if ord(sText[iCursor]) > 65535: # \U00010000: each chars beyond this point has a length of 2
lThresholds.append(iCursor+1) # +1 because only chars after are shifted
except:
traceback.print_exc()
# modify errors position according to thresholds
print(lThresholds)
for xErr in aErrors:
print(xErr.nErrorStart, xErr.nErrorLength, "->", end=" ")
nErrorEnd = xErr.nErrorStart + xErr.nErrorLength
xErr.nErrorStart += bisect_right(lThresholds, xErr.nErrorStart)
nErrorEnd += bisect_right(lThresholds, nErrorEnd)
xErr.nErrorLength = nErrorEnd - xErr.nErrorStart
print(xErr.nErrorStart, xErr.nErrorLength)
return len(lThresholds)
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(Grammalecte, "org.openoffice.comp.pyuno.Lightproof."+gce.pkg, ("com.sun.star.linguistic2.Proofreader",),)
# g_ImplementationHelper.addImplementation( opt_handler.LightproofOptionsEventHandler, \
# "org.openoffice.comp.pyuno.LightproofOptionsEventHandler." + gce.pkg, ("com.sun.star.awt.XContainerWindowEventHandler",),)
|