Overview
| Comment: | [fr][oxt] formateur de texte: table de remplacement séparée |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk | fr |
| Files: | files | file ages | folders |
| SHA3-256: |
58cdb431b875aa6f69a1de2d216d4db6 |
| User & Date: | olr on 2017-06-27 13:38:07 |
| Original Comment: | [fr][oxt] formateur de texte: tablede remplacement séparée |
| Other Links: | manifest | tags |
Context
|
2017-06-27
| ||
| 13:57 | [fr][oxt] table de remplacement pour le formateur de texte check-in: 36321ba3ed user: olr tags: trunk, fr | |
| 13:38 | [fr][oxt] formateur de texte: table de remplacement séparée check-in: 58cdb431b8 user: olr tags: trunk, fr | |
| 08:49 | [fr][bug] formateur de texte: URL check-in: 001f5897d2 user: olr tags: trunk, fr | |
Changes
Modified gc_lang/fr/config.ini from [c79f625391] to [2a6b6ad1cb].
| ︙ | ︙ | |||
70 71 72 73 74 75 76 77 78 79 80 81 | # ContextMenu oxt/ContextMenu/ContextMenu.py = ContextMenu.py oxt/ContextMenu/jobs.xcu = config/jobs.xcu # TextFormatter oxt/TextFormatter/TextFormatter.py = pythonpath/TextFormatter.py oxt/TextFormatter/tf_strings.py = pythonpath/tf_strings.py oxt/TextFormatter/tf_options.py = pythonpath/tf_options.py # Conjugueur oxt/Conjugueur/Conjugueur.py = pythonpath/Conjugueur.py # Modify author oxt/ChangeAuthor/Author.py = pythonpath/Author.py oxt/ChangeAuthor/ca_strings.py = pythonpath/ca_strings.py | > | 70 71 72 73 74 75 76 77 78 79 80 81 82 | # ContextMenu oxt/ContextMenu/ContextMenu.py = ContextMenu.py oxt/ContextMenu/jobs.xcu = config/jobs.xcu # TextFormatter oxt/TextFormatter/TextFormatter.py = pythonpath/TextFormatter.py oxt/TextFormatter/tf_strings.py = pythonpath/tf_strings.py oxt/TextFormatter/tf_options.py = pythonpath/tf_options.py oxt/TextFormatter/tf_tabrep.py = pythonpath/tf_tabrep.py # Conjugueur oxt/Conjugueur/Conjugueur.py = pythonpath/Conjugueur.py # Modify author oxt/ChangeAuthor/Author.py = pythonpath/Author.py oxt/ChangeAuthor/ca_strings.py = pythonpath/ca_strings.py |
Modified gc_lang/fr/oxt/TextFormatter/TextFormatter.py from [63b9caa31e] to [6fb58f6672].
| ︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import time
if sys.version_info.major == 3:
import imp
import tf_strings
import tf_options
import helpers
from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener
| > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import time
if sys.version_info.major == 3:
import imp
import tf_strings
import tf_options
import tf_tabrep
import helpers
from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener
|
| ︙ | ︙ | |||
429 430 431 432 433 434 435 |
# NOTE: A LOT OF REGEX COULD BE MERGED IF ICU ENGINE WAS NOT SO BUGGY
# "([;?!…])(?=[:alnum:])" => "$1 " doesn’t work properly
# "(?<=[:alnum:])([;?!…])" => " $1 " doesn’t work properly
self.pbar.ProgressValue = 0
# Restructuration
if self.struct.State:
if self.struct1.State:
| | | | | < < < | | | < | < | < | < < < < < < < < < < < < | < < < < < < < < < < < < < < | < < < < < < < | < < < | < < < | < | | | | < | < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < | < | < < < < < < < < | | < < < < < < < < < < < < < < < < < < | < < | < < < | < < < | < < < < | < < < | < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# NOTE: A LOT OF REGEX COULD BE MERGED IF ICU ENGINE WAS NOT SO BUGGY
# "([;?!…])(?=[:alnum:])" => "$1 " doesn’t work properly
# "(?<=[:alnum:])([;?!…])" => " $1 " doesn’t work properly
self.pbar.ProgressValue = 0
# Restructuration
if self.struct.State:
if self.struct1.State:
n = self._replaceList(xElem, "struct1")
self.struct1_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.struct2.State:
n = self._replaceList(xElem, "struct2")
n += self._replaceHyphenAtEndOfParagraphs(xElem) # EOP
self.struct2_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.struct3.State:
n = self._mergeContiguousParagraphs(xElem)
self.struct3_res.Label = str(n)
self.pbar.ProgressValue += 1
self.struct.State = False
self._switchCheckBox(self.struct)
self.pbar.ProgressValue = 3
# espaces surnuméraires
if self.ssp.State:
if self.ssp3.State:
n = self._replaceList(xElem, "ssp3")
self.ssp3_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.ssp2.State:
n = self._replaceList(xElem, "ssp2")
self.ssp2_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.ssp1.State:
n = self._replaceList(xElem, "ssp1")
self.ssp1_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.ssp4.State:
n = self._replaceList(xElem, "ssp4")
self.ssp4_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.ssp5.State:
n = self._replaceList(xElem, "ssp5")
self.ssp5_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.ssp6.State:
n = self._replaceList(xElem, "ssp6")
self.ssp6_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.ssp7.State:
n = self._replaceList(xElem, "ssp7")
self.ssp7_res.Label = str(n)
self.pbar.ProgressValue += 1
self.ssp.State = False
self._switchCheckBox(self.ssp)
self.pbar.ProgressValue = 10
# espaces typographiques
if self.nbsp.State:
if self.nbsp1.State:
if self.nnbsp1.State:
# espaces insécables fines
n = self._replaceList(xElem, "nnbsp1")
else:
# espaces insécables
n = self._replaceList(xElem, "nbsp1")
# réparations
n -= self._replaceList(xElem, "nbsp1_fix")
self.nbsp1_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.nbsp2.State:
if self.nnbsp2.State:
# espaces insécables fines
n = self._replaceList(xElem, "nnbsp2")
else:
# espaces insécables
n = self._replaceList(xElem, "nbsp2")
self.nbsp2_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.nbsp3.State:
n = self._replaceList(xElem, "nbsp3")
self.nbsp3_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.nbsp4.State:
if self.nnbsp4.State:
# espaces insécables fines
n = self._replaceList(xElem, "nnbsp4")
else:
# espaces insécables
n = self._replaceList(xElem, "nbsp4")
self.nbsp4_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.nbsp5.State:
n = self._replaceList(xElem, "nbsp5")
self.nbsp5_res.Label = str(n)
self.pbar.ProgressValue += 1
if False:
n = self._replaceList(xElem, "nbsp6")
self.nbsp3_res.Label = str(n)
self.pbar.ProgressValue += 1
self.nbsp.State = False
self._switchCheckBox(self.nbsp)
self.pbar.ProgressValue = 15
# points médians
if self.typo.State:
if self.typo6.State:
n = self._replaceList(xElem, "typo6")
self.typo6_res.Label = str(n)
self.pbar.ProgressValue += 1
# espaces manquants
if self.space.State:
if self.space1.State:
n = self._replaceList(xElem, "space1")
# réparations
n -= self._replaceList(xElem, "space1_fix")
self.space1_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.space2.State:
n = self._replaceList(xElem, "space2")
self.space2_res.Label = str(n)
self.pbar.ProgressValue += 1
self.space.State = False
self._switchCheckBox(self.space)
self.pbar.ProgressValue = 17
# Suppression
if self.delete.State:
if self.delete1.State:
n = self._replaceList(xElem, "delete1")
self.delete1_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.delete2.State:
n = self._replaceBulletsByEmDash(xElem)
self.delete2_res.Label = str(n)
self.pbar.ProgressValue += 1
self.delete.State = False
self._switchCheckBox(self.delete)
self.pbar.ProgressValue = 20
# signes typographiques
if self.typo.State:
if self.typo1.State:
n = self._replaceList(xElem, "typo1")
self.typo1_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.typo2.State:
n = self._replaceList(xElem, "typo2")
self.typo2_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.typo3.State:
if self.typo3b.State:
# demi-cadratin
n = self._replaceList(xElem, "typo3b")
else:
# cadratin
n = self._replaceList(xElem, "typo3a")
self.typo3_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.typo4.State:
if self.typo4a.State:
# cadratin
n = self._replaceList(xElem, "typo4a")
else:
# demi-cadratin
n = self._replaceList(xElem, "typo4b")
self.typo4_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.typo5.State:
n = self._replaceList(xElem, "typo5")
self.typo5_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.typo7.State:
n = self._replaceList(xElem, "typo7")
self.typo7_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.typo8.State:
# ligatures typographiques : fi, fl, ff, ffi, ffl, ft, st
n = 0
if self.typo8a.State:
if self.typo_ffi.State:
|
| ︙ | ︙ | |||
814 815 816 817 818 819 820 |
self.typo.State = False
self._switchCheckBox(self.typo)
self.pbar.ProgressValue = 28
# divers
if self.misc.State:
if self.misc1.State:
if self.misc1a.State:
| < < < < < < < < < < | < < < < < < < < < | < | < | < < < < < < < < < < < < < < | | < < < < < < < < | < < < < < < < < > > > > > > > > > > > > > > | | > > | | | < | | | | | | | | | | | | | | | | | > > | < < > > | > > | | | | < < | 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 |
self.typo.State = False
self._switchCheckBox(self.typo)
self.pbar.ProgressValue = 28
# divers
if self.misc.State:
if self.misc1.State:
if self.misc1a.State:
n = self._replaceList(xElem, "misc1a")
else:
n = self._replaceList(xElem, "misc1b")
self.misc1_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.misc2.State:
n = self._replaceList(xElem, "misc2")
self.misc2_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.misc3.State:
n = self._replaceList(xElem, "misc3")
self.misc3_res.Label = str(n)
self.pbar.ProgressValue += 1
if self.misc5.State:
n = self._replaceList(xElem, "misc5a")
if self.misc5b.State:
n += self._replaceList(xElem, "misc5b")
if self.misc5c.State:
n += self._replaceList(xElem, "misc5c")
self.misc5_res.Label = str(n)
self.pbar.ProgressValue += 1
self.misc.State = False
self._switchCheckBox(self.misc)
self.pbar.ProgressValue = self.pbar.ProgressValueMax
# end of processing
xPointer.setType(uno.getConstantByName("com.sun.star.awt.SystemPointer.ARROW"))
xWindowPeer.setPointer(xPointer)
for x in xWindowPeer.Windows:
x.setPointer(xPointer)
self.xContainer.setVisible(True) # seems necessary to refresh the dialog box and text widgets (why?)
nEndTime = time.clock()
self.time_res.Label = getTimeRes(nEndTime-nStartTime)
except:
traceback.print_exc()
def _replaceList (self, xElem, sList):
if sList not in tf_tabrep.dTableRepl:
print("# Error. List <"+sList+"> not found")
return 0
n = 0
try:
for sPattern, sRepl, bRegex, bCaseSensitive in tf_tabrep.dTableRepl[sList]:
n += self._replaceText(xElem, sPattern, sRepl, bRegex, bCaseSensitive)
except:
print("# Error with "+sList)
traceback.print_exc()
return n
def _replaceText (self, xElem, sPattern, sRepl, bRegex, bCaseSensitive=False):
try:
xRD = xElem.createReplaceDescriptor()
xRD.SearchString = sPattern
xRD.ReplaceString = sRepl
xRD.SearchRegularExpression = bRegex
xRD.SearchCaseSensitive = bCaseSensitive
return xElem.replaceAll(xRD)
except:
traceback.print_exc()
return 0
def _replaceHyphenAtEndOfParagraphs (self, xDoc):
self._replaceText(xDoc, "-[ ]+$", "-", True) # remove spaces at end of paragraphs if - is the last character
n = 0
try:
xHunspell = self.xSvMgr.createInstanceWithContext("com.sun.star.linguistic2.SpellChecker", self.ctx)
xCursor = xDoc.Text.createTextCursor()
xCursor.gotoStart(False)
while xCursor.gotoNextParagraph(False):
xCursor.goLeft(2, True)
if xCursor.String.startswith("-"):
xCursor.gotoStartOfWord(False)
xLocale = xCursor.CharLocale
xCursor.gotoEndOfWord(True)
sWord1 = xCursor.String
xCursor.gotoNextParagraph(False)
xCursor.gotoEndOfWord(True)
sWord2 = xCursor.String
if sWord1 and sWord2 and xHunspell.isValid(sWord1+sWord2, xLocale, ()):
xCursor.gotoStartOfParagraph(False)
xCursor.goLeft(2, True)
xCursor.setString("")
n += 1
else:
xCursor.goRight(2, False)
except:
traceback.print_exc()
return n
def _mergeContiguousParagraphs (self, xDoc):
self._replaceText(xDoc, "^[ ]+$", "", True) # clear empty paragraphs
n = 0
try:
xCursor = xDoc.Text.createTextCursor()
xCursor.gotoStart(False)
while xCursor.gotoNextParagraph(False):
xCursor.gotoEndOfParagraph(True)
if xCursor.String != "":
xCursor.gotoStartOfParagraph(False)
xCursor.goLeft(1, True)
xCursor.setString(" ")
n += 1
except:
traceback.print_exc()
self._replaceText(xDoc, " +", " ", True)
return n
def _replaceBulletsByEmDash (self, xDoc):
xCursor = xDoc.Text.createTextCursor()
#helpers.xray(xCursor)
n = 0
try:
xCursor.gotoStart(False)
sParaStyleName = ""
if not self.delete2c.State:
sParaStyleName = "Standard" if self.delete2a.State else "Text body"
if xCursor.NumberingStyleName != "":
xCursor.NumberingStyleName = ""
if sParaStyleName:
xCursor.ParaStyleName = sParaStyleName
xDoc.Text.insertString(xCursor, "— ", False)
n += 1
while xCursor.gotoNextParagraph(False):
|
| ︙ | ︙ |
Modified make.py from [78de6b4826] to [14dcb35490].
| ︙ | ︙ | |||
26 27 28 29 30 31 32 |
def getConfig (sLang):
xConfig = configparser.SafeConfigParser()
xConfig.optionxform = str
try:
xConfig.read("gc_lang/" + sLang + "/config.ini", encoding="utf-8")
except:
| | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
def getConfig (sLang):
xConfig = configparser.SafeConfigParser()
xConfig.optionxform = str
try:
xConfig.read("gc_lang/" + sLang + "/config.ini", encoding="utf-8")
except:
print("# Error. Can’t read config file [" + sLang + "]")
exit()
return xConfig
def createOptionsLabelProperties (dOptLbl):
sContent = ""
for sOpt, tLabel in dOptLbl.items():
|
| ︙ | ︙ |
Modified tests/fr/formateur_de_texte.odt from [0fbb935ea9] to [d7d8a124ac].
cannot compute difference between binary files