Skip to content

jaws: Cut braille text to fit a JAWS script call - #187

Merged
ethindp merged 1 commit into
ethindp:masterfrom
Oire:jaws-braille-length
Nov 14, 2026
Merged

ethindp merged 1 commit into
ethindp:masterfrom
Oire:jaws-braille-length

Conversation

@Menelion

Copy link
Copy Markdown
Contributor

JAWS does not run a script call longer than 255 UTF-16 code units, but IJawsApi::RunFunction still returns VARIANT_TRUE for it. The JAWS backend brailles through RunFunction("BrailleString(\"...\")"), and the wrapper takes 17 of those units, so any Braille text longer than 238 units never reaches the display, while prism_backend_braille and prism_backend_output report success.

Measured with JAWS 2027.2610.428 on Windows 11 (10.0.26300, x64), by sending texts of growing length through RunFunction and reading the display. Texts of up to 238 characters appear, and longer ones never do. RunFunction returned true every time. The limit is in characters, not bytes: English, Ukrainian and Hebrew texts all stop at 238, though 238 Ukrainian or Hebrew characters are about 410 bytes in UTF-8.

The backend now cuts the text to the first 238 UTF-16 code units before building the call. It never cuts inside a code point, so a character outside the BMP is kept or dropped whole instead of splitting into a lone surrogate. Speech is not impacted by this change.

The cut length is computed by utf8_prefix_within_utf16_units in source/backends/jaws_braille.h, header-only so it can be tested without JAWS. tests/win32/jaws_braille covers ASCII, two- and three-byte characters, and a surrogate pair at and across the limit. It passes with -DPRISM_ENABLE_TESTS=ON -DBUILD_SHARED_LIBS=OFF (MSVC 14.51, Debug), and clang-tidy with the repository's .clang-tidy reports nothing for the changed files.
The backend notes in the manual describe the cut.

How to Reproduce (PowerShell 7, JAWS running with a Braille display):

$jaws = New-Object -ComObject FreedomSci.JawsApi
$filler = 'the quick brown fox jumps over the lazy dog '
foreach ($length in 200, 237, 238, 239, 240, 300, 500) {
    $text = "Length $length. "
    while ($text.Length -lt $length) { $text += $filler }
    $text = $text.Substring(0, $length)
    $accepted = $jaws.RunFunction("BrailleString(`"$text`")")
    Write-Output "length $length, accepted $accepted"
    Start-Sleep -Seconds 4
}

@ethindp

ethindp commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Hi there,

Please don't define a function like this in a header file. Instead define it in the TU where thE JAWS backend is defined.

That said, is there some way we can chunk the text and queue it, or will we just have to deal with the text loss?

@Menelion

Copy link
Copy Markdown
Contributor Author

@ethindp Thanks for your reply! I deleted the header and moved the function to jaws.cpp.

On chunking… unfortunately, I don't believe we could do anything to it. I've tested it now, and second and all sequential messages do replace the first message on the Braille display. A timer could probably help, but then we'd impose our pace to the reader: the reader would either wait for too long, or not be able to read the previous chunk fast enough.
I'm a JAWS beta tester, so I've sent them a report already. The thing is that JAWS API has no braille() function, hence we have to use that RunFunction() trick, and it caps us at 255 characters for some reason.
If you have better ideas, I'm all ears because I need it for my software also. Thanks!

@ethindp

ethindp commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@Menelion I sadly don't have many ideas beyodn this one, having little knowledge to how braille displays work or the protocols they expose to system software. I theorize that Prism implementing it's own braille communications engine may create some path to resolution, but doing so would be incredibly difficult, time consuming and would probably be a version 2.x thing.

Re: characters. Your initial post says:

The limit is in characters, not bytes [...]

I would recommend you use what simdutf provides instead of handwriting utf8_prefix_within_utf16_units.

JAWS does not run a script call longer than 255 UTF-16 code units, yet
IJawsApi::RunFunction still returns true for it. The JAWS backend
brailles through RunFunction("BrailleString(\"...\")"), whose wrapper
takes 17 of those units, so a braille text longer than 238 units never
reached the display while braille and output reported success.

Convert the text to UTF-16 first, then cut it to fit, letting simdutf's
trim_partial_utf16 drop a high surrogate left at the cut, so the
display shows the start of a long text instead of nothing. Speech is
not cut. The limit was measured with JAWS 2027 and is counted in
characters, not bytes: English, Ukrainian and Hebrew texts all stop at
238.

Signed-off-by: André Polykanine <[email protected]>
@Menelion
Menelion force-pushed the jaws-braille-length branch from c78bb7e to 2a08720 Compare November 14, 2026 00:42
@Menelion

Menelion commented Nov 14, 2026 via email

Copy link
Copy Markdown
Contributor Author

@ethindp

ethindp commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@Menelion Alright, let's see what the linters think. If they have nothing to say, we'll merge. Otherwise, the routine is to fix all lints found, following the contributing guidelines, and once done we merge. Thank you for finding and reporting this!

@ethindp
ethindp merged commit d4c24ff into ethindp:master Nov 14, 2026
81 checks passed
@Menelion
Menelion deleted the jaws-braille-length branch November 21, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants