Skip to content

Commit e687938

Browse files
authored
Merge 198250f into 613994a
2 parents 613994a + 198250f commit e687938

5 files changed

Lines changed: 36 additions & 21 deletions

File tree

source/braille.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,20 +499,20 @@ def update(self):
499499
mode |= louis.compbrlAtCursor
500500

501501
converter: UnicodeNormalizationOffsetConverter | None = None
502-
if config.conf["braille"]["unicodeNormalization"] and not isUnicodeNormalized(self.rawText):
503-
converter = UnicodeNormalizationOffsetConverter(self.rawText)
502+
textToTranslate = self.rawText
503+
textToTranslateTypeforms = self.rawTextTypeforms
504+
cursorPos = self.cursorPos
505+
if config.conf["braille"]["unicodeNormalization"] and not isUnicodeNormalized(textToTranslate):
506+
converter = UnicodeNormalizationOffsetConverter(textToTranslate)
504507
textToTranslate = converter.encoded
505-
# Typeforms must be adapted to represent normalized characters.
506-
textToTranslateTypeforms = [
507-
self.rawTextTypeforms[strOffset] for strOffset in converter.computedEncodedToStrOffsets
508-
]
509-
# Convert the cursor position to a normalized offset.
510-
cursorPos = converter.strToEncodedOffsets(self.cursorPos)
511-
else:
512-
textToTranslate = self.rawText
513-
textToTranslateTypeforms = self.rawTextTypeforms
514-
cursorPos = self.cursorPos
515-
508+
if textToTranslateTypeforms is not None:
509+
# Typeforms must be adapted to represent normalized characters.
510+
textToTranslateTypeforms = [
511+
textToTranslateTypeforms[strOffset] for strOffset in converter.computedEncodedToStrOffsets
512+
]
513+
if cursorPos is not None:
514+
# Convert the cursor position to a normalized offset.
515+
cursorPos = converter.strToEncodedOffsets(cursorPos)
516516
self.brailleCells, brailleToRawPos, rawToBraillePos, self.brailleCursorPos = louisHelper.translate(
517517
[handler.table.fileName, "braille-patterns.cti"],
518518
textToTranslate,

source/config/configSpec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# symbolLevel: One of the characterProcessing.SymbolLevel values.
3636
symbolLevel = integer(default=100)
3737
trustVoiceLanguage = boolean(default=true)
38-
unicodeNormalization = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="disabled")
38+
unicodeNormalization = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
3939
includeCLDR = boolean(default=True)
4040
beepSpeechModePitch = integer(default=10000,min=50,max=11025)
4141
outputDevice = string(default=default)
@@ -83,7 +83,7 @@
8383
optionsEnum="ReviewRoutingMovesSystemCaretFlag", behaviorOfDefault="NEVER")
8484
readByParagraph = boolean(default=false)
8585
wordWrap = boolean(default=true)
86-
unicodeNormalization = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="disabled")
86+
unicodeNormalization = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
8787
focusContextPresentation = option("changedContext", "fill", "scroll", default="changedContext")
8888
interruptSpeechWhileScrolling = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
8989
showSelection = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")

source/textUtils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,24 @@ def _calculateOffsets(self) -> tuple[tuple[int], tuple[int]]:
478478
# and still matches the beginning of the normalized buffer.
479479
for i in range(len(originBuffer)):
480480
originPart = originBuffer[: (i + 1)]
481+
originPartLen = len(originPart)
481482
normalizedPart = unicodedata.normalize(self.normalizationForm, originPart)
483+
normalizedPartLen = len(normalizedPart)
482484
if (
483485
originPart == normalizedPart
484486
or not normalizedBuffer.startswith(normalizedPart)
485487
):
486488
continue
487-
originPartLen = len(originPart)
488489
originBuffer = originBuffer[originPartLen:]
489-
normalizedPartLen = len(normalizedPart)
490490
normalizedBuffer = normalizedBuffer[normalizedPartLen:]
491491
break
492+
else:
493+
# No normalizable characters in originBuffer.
494+
# All characters are now copied to originPart and normalizedPart.
495+
assert originBuffer == originPart
496+
assert normalizedBuffer == normalizedPart
497+
# Reset buffers to ensure the while loop doesn't run next time.
498+
originBuffer = normalizedBuffer = ""
492499
# Map the original indices to the normalized indices.
493500
# originMultiplier is used to multiply indices in origin
494501
# when a character takes more space in origin than in normalized.

tests/unit/test_textUtils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,11 @@ def test_normalizedOffsetsDifferentOrder(self):
268268
self.assertSequenceEqual(converter.computedStrToEncodedOffsets, expectedStrToEncoded)
269269
expectedEncodedToStr = (0, 2, 1, 3, 4, 5, 6, 8, 7, 9, 10)
270270
self.assertSequenceEqual(converter.computedEncodedToStrOffsets, expectedEncodedToStr)
271+
272+
def test_normalizedOffsetsMixedSpaces(self):
273+
text = "\xa0 "
274+
converter = UnicodeNormalizationOffsetConverter(text, "NFKC")
275+
expectedStrToEncoded = (0, 1)
276+
self.assertSequenceEqual(converter.computedStrToEncodedOffsets, expectedStrToEncoded)
277+
expectedEncodedToStr = (0, 1)
278+
self.assertSequenceEqual(converter.computedEncodedToStrOffsets, expectedEncodedToStr)

user_docs/en/userGuide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,8 +1809,8 @@ If you find that NVDA is reading punctuation in the wrong language for a particu
18091809
##### Unicode normalization {#SpeechUnicodeNormalization}
18101810
| . {.hideHeaderRow} |.|
18111811
|---|---|
1812-
|Options |Default (Disabled), Enabled, Disabled|
1813-
|Default |Disabled|
1812+
|Options |Default (Enabled), Enabled, Disabled|
1813+
|Default |Enabled|
18141814

18151815
When this option is enabled, unicode normalization is performed on the text that is spoken by NVDA.
18161816
This is beneficial when speaking characters that can be represented in several forms.
@@ -2071,8 +2071,8 @@ Enabling this may allow for more fluent reading, but generally requires you to s
20712071
##### Unicode normalization {#BrailleUnicodeNormalization}
20722072
| . {.hideHeaderRow} |.|
20732073
|---|---|
2074-
|Options |Default (Disabled), Enabled, Disabled|
2075-
|Default |Disabled|
2074+
|Options |Default (Enabled), Enabled, Disabled|
2075+
|Default |Enabled|
20762076

20772077
When this option is enabled, unicode normalization is performed on the text that is brailled on the braille display.
20782078
This is beneficial when coming across characters in braille that are unknown in a particular braille table and which have a compatible alternative, like the bold and italic characters commonly used on social media.

0 commit comments

Comments
 (0)