Skip to content

Commit a40a1c3

Browse files
authored
Merge f381622 into b94415e
2 parents b94415e + f381622 commit a40a1c3

6 files changed

Lines changed: 106 additions & 3 deletions

File tree

source/braille.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
ReportTableHeaders,
4747
OutputMode,
4848
)
49-
from config.featureFlagEnums import ReviewRoutingMovesSystemCaretFlag
49+
from config.featureFlagEnums import ReviewRoutingMovesSystemCaretFlag, FontAttributesBrailleModeFlag
5050
from logHandler import log
5151
import controlTypes
5252
import api
@@ -327,6 +327,12 @@
327327
#: Unicode braille indicator at the end of untranslated braille input.
328328
INPUT_END_IND = " ⣹"
329329

330+
# Delimiters for the start and end of format tags.
331+
FORMAT_TAG_START_IND = "⣏"
332+
"""Unicode braille indicator at the start of a formatt tag."""
333+
FORMAT_TAG_END_IND = "⣙"
334+
"""Unicode braille indicator at the end of a formatt tag."""
335+
330336
# used to separate chunks of text when programmatically joined
331337
TEXT_SEPARATOR = " "
332338

@@ -1124,11 +1130,59 @@ def getFormatFieldBraille(field, fieldCache, isAtStart, formatConfig):
11241130
# Translators: brailled when text contains a bookmark
11251131
text = _("bkmk")
11261132
textList.append(text)
1133+
1134+
if (
1135+
config.conf["braille"]["fontAttributeDisplay"].calculated() == FontAttributesBrailleModeFlag.TAGS
1136+
and (formattingTags := _getFormattingTags(field, fieldCache, formatConfig)) is not None
1137+
):
1138+
textList.append(formattingTags)
1139+
11271140
fieldCache.clear()
11281141
fieldCache.update(field)
11291142
return TEXT_SEPARATOR.join([x for x in textList if x])
11301143

11311144

1145+
def _getFormattingTags(field: dict[str, str], fieldCache: dict[str, str], formatConfig: dict[str, bool]) -> str | None:
1146+
"""
1147+
Get the formatting tags for the given field and cache.
1148+
1149+
Args:
1150+
field: The format field.
1151+
fieldCache (dict): The previous format field.
1152+
formatConfig: The user's format config.
1153+
1154+
Returns:
1155+
The formatting tag as a string, or None if no formatting is applied.
1156+
"""
1157+
textList = []
1158+
bold = field.get("bold", False)
1159+
oldBold = fieldCache.get("bold", False) if fieldCache is not None else False
1160+
if bold and not oldBold:
1161+
textList.append("⠃")
1162+
elif oldBold and not bold:
1163+
textList.append("⡃")
1164+
italics = field.get("italic", False)
1165+
oldItalics = fieldCache.get("italic", False) if fieldCache is not None else False
1166+
if italics and not oldItalics:
1167+
textList.append("⠊")
1168+
elif oldItalics and not italics:
1169+
textList.append("⡊")
1170+
underline = field.get("underline", False)
1171+
oldUnderline = fieldCache.get("underline", False) if fieldCache is not None else False
1172+
if underline and not oldUnderline:
1173+
textList.append("⠥")
1174+
elif oldUnderline and not underline:
1175+
textList.append("⡥")
1176+
strikethrough = field.get("strikethrough", False)
1177+
oldStrikethrough = fieldCache.get("strikethrough", False) if fieldCache is not None else False
1178+
if strikethrough and not oldStrikethrough:
1179+
textList.append("⠎")
1180+
elif oldStrikethrough and not strikethrough:
1181+
textList.append("⡎")
1182+
if len(textList) > 0:
1183+
return f"{FORMAT_TAG_START_IND}{''.join(textList)}{FORMAT_TAG_END_IND}"
1184+
1185+
11321186
class TextInfoRegion(Region):
11331187
pendingCaretUpdate = False #: True if the cursor should be updated for this region on the display
11341188
allowPageTurns = True #: True if a page turn should be tried when a TextInfo cannot move anymore and the object supports page turns.
@@ -1174,7 +1228,13 @@ def _setCursor(self, info: textInfos.TextInfo):
11741228

11751229
def _getTypeformFromFormatField(self, field, formatConfig):
11761230
typeform = louis.plain_text
1177-
if not (formatConfig["fontAttributeReporting"] & OutputMode.BRAILLE):
1231+
if not (
1232+
(formatConfig["fontAttributeReporting"] & OutputMode.BRAILLE)
1233+
and (
1234+
config.conf["braille"]["fontAttributeDisplay"].calculated()
1235+
== FontAttributesBrailleModeFlag.LIBLOUIS
1236+
)
1237+
):
11781238
return typeform
11791239
if field.get("bold", False):
11801240
typeform |= louis.bold

source/config/configSpec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
interruptSpeechWhileScrolling = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
9090
showSelection = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
9191
reportLiveRegions = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
92+
fontAttributeDisplay = featureFlag(optionsEnum="FontAttributesBrailleModeFlag", behaviorOfDefault="LIBLOUIS")
9293
[[auto]]
9394
excludedDisplays = string_list(default=list())
9495

source/config/featureFlagEnums.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ def _displayStringLabels(self):
122122
NOTIFICATIONS = enum.auto()
123123

124124

125+
class FontAttributesBrailleModeFlag(DisplayStringEnum):
126+
"""Enumeration containing the possible ways to display formatting changes in braille."""
127+
128+
DEFAULT = enum.auto()
129+
LIBLOUIS = enum.auto()
130+
TAGS = enum.auto()
131+
132+
@property
133+
def _displayStringLabels(self) -> dict["FontAttributesBrailleModeFlag", str]:
134+
return {
135+
# Translators: The label for a braille mode
136+
FontAttributesBrailleModeFlag.LIBLOUIS: _("Liblouis"),
137+
# Translators: The label for a braille mode
138+
FontAttributesBrailleModeFlag.TAGS: _("Tags"),
139+
}
140+
141+
125142
def getAvailableEnums() -> typing.Generator[typing.Tuple[str, FlagValueEnum], None, None]:
126143
for name, value in globals().items():
127144
if (

source/gui/settingsDialogs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,6 +4428,14 @@ def makeSettings(self, settingsSizer):
44284428
)
44294429
self.bindHelpEvent("BrailleSettingsInterruptSpeech", self.brailleInterruptSpeechCombo)
44304430

4431+
self.formattingDisplayCombo = sHelper.addLabeledControl(
4432+
labelText=_("Formatting display"),
4433+
wxCtrlClass=nvdaControls.FeatureFlagCombo,
4434+
keyPath=("braille", "fontAttributeDisplay"),
4435+
conf=config.conf,
4436+
)
4437+
self.bindHelpEvent("BrailleSettingsFormattingDisplay", self.formattingDisplayCombo)
4438+
44314439
if gui._isDebug():
44324440
log.debug("Finished making settings, now at %.2f seconds from start" % (time.time() - startTime))
44334441

@@ -4466,6 +4474,7 @@ def onSave(self):
44664474
]
44674475
self.brailleInterruptSpeechCombo.saveCurrentValueToConf()
44684476
self.brailleShowSelectionCombo.saveCurrentValueToConf()
4477+
self.formattingDisplayCombo.saveCurrentValueToConf()
44694478

44704479
def onShowCursorChange(self, evt):
44714480
self.cursorBlinkCheckBox.Enable(evt.IsChecked())

user_docs/en/changes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
### New Features
88

9-
* Enhanced Microsoft Word comment command: press twice to present comment content in browsable message. (#16800, @Cary-Rowen)
109
* NVDA can now be configured to report font attributes in speech and braille separately. (#16755)
10+
* It is now possible to change the way NVDA displays certain text formatting attributes in braille. The available options are:
11+
* Liblouis: Uses formatting markers defined in your selected braille table.
12+
* Enhanced Microsoft Word comment command: press twice to present comment content in browsable message. (#16800, @Cary-Rowen)
1113

1214

1315
### Bug Fixes

user_docs/en/userGuide.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,6 +2243,20 @@ Disabling this option may improve readability.
22432243

22442244
To toggle show selection from anywhere, please assign a custom gesture using the [Input Gestures dialog](#InputGestures).
22452245

2246+
##### Formatting display {#BrailleSettingsFormattingDisplay}
2247+
2248+
| . {.hideHeaderRow} |.|
2249+
|---|---|
2250+
| Options | Default, Liblouis |
2251+
| Default | Liblouis |
2252+
2253+
This setting determines how NVDA will display text formatting. This option only has an effect if NVDA is set to display font attributes in braille. The following options are supported:
2254+
2255+
| Option | Description |
2256+
|---|---|
2257+
| Default | The default setting, as specified by NVDA. |
2258+
| Liblouis | Use native Braille formatting. Note that this option will only indicate bold, italic and underlined text, and only if the selected braille table supports indicating these attributes. |
2259+
22462260
#### Select Braille Display {#SelectBrailleDisplay}
22472261

22482262
<!-- KC:setting -->

0 commit comments

Comments
 (0)