|
46 | 46 | ReportTableHeaders, |
47 | 47 | OutputMode, |
48 | 48 | ) |
49 | | -from config.featureFlagEnums import ReviewRoutingMovesSystemCaretFlag |
| 49 | +from config.featureFlagEnums import ReviewRoutingMovesSystemCaretFlag, FontAttributesBrailleModeFlag |
50 | 50 | from logHandler import log |
51 | 51 | import controlTypes |
52 | 52 | import api |
|
327 | 327 | #: Unicode braille indicator at the end of untranslated braille input. |
328 | 328 | INPUT_END_IND = " ⣹" |
329 | 329 |
|
| 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 | + |
330 | 336 | # used to separate chunks of text when programmatically joined |
331 | 337 | TEXT_SEPARATOR = " " |
332 | 338 |
|
@@ -1124,11 +1130,59 @@ def getFormatFieldBraille(field, fieldCache, isAtStart, formatConfig): |
1124 | 1130 | # Translators: brailled when text contains a bookmark |
1125 | 1131 | text = _("bkmk") |
1126 | 1132 | 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 | + |
1127 | 1140 | fieldCache.clear() |
1128 | 1141 | fieldCache.update(field) |
1129 | 1142 | return TEXT_SEPARATOR.join([x for x in textList if x]) |
1130 | 1143 |
|
1131 | 1144 |
|
| 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 | + |
1132 | 1186 | class TextInfoRegion(Region): |
1133 | 1187 | pendingCaretUpdate = False #: True if the cursor should be updated for this region on the display |
1134 | 1188 | 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): |
1174 | 1228 |
|
1175 | 1229 | def _getTypeformFromFormatField(self, field, formatConfig): |
1176 | 1230 | 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 | + ): |
1178 | 1238 | return typeform |
1179 | 1239 | if field.get("bold", False): |
1180 | 1240 | typeform |= louis.bold |
|
0 commit comments