Skip to content

Return Unknown for unassigned codepoints instead of raising - #72

Open
nagieeb0 wants to merge 1 commit into
jbowtie:masterfrom
nagieeb0:fix-unknown-codepoints
Open

Return Unknown for unassigned codepoints instead of raising#72
nagieeb0 wants to merge 1 commit into
jbowtie:masterfrom
nagieeb0:fix-unknown-codepoints

Conversation

@nagieeb0

Copy link
Copy Markdown

Scripts.txt only lists assigned codepoints, and script_from_codepoint/1 generates one clause per range with no fallback. Any codepoint outside the bundled data raises FunctionClauseError, so a caller that merely passed along a recent character crashes rather than degrading.

U+20C1 SAUDI RIYAL SIGN (Unicode 16.0) is a common way to hit this — it takes down OpenType.Layout.detect_script/1 for any string containing a Saudi Riyal amount:

iex> UnicodeData.script_from_codepoint(0x20C1)
** (FunctionClauseError) no function clause matching in UnicodeData.Script.script_from_codepoint/1

Changes

  1. A final clause returning "Unknown" — the UCD's documented @missing default for Script. That value is already handled everywhere it lands: script_to_tag/1 maps it to "zzzz", and detect_script/1 filters it out alongside Common and Inherited. Nothing downstream needs to change.

  2. Scripts.txt refreshed from Unicode 12.0 (2019) to 17.0, so codepoints added since then get their real script rather than Unknown. U+20C1 becomes Common.

Verification

Existing suite passes unchanged, plus two new cases covering U+20C1 and the unassigned fallback.

Note: mix test needed excoveralls dropped locally to run at all — the pinned version fails to compile on OTP 28. That is out of scope here, but happy to send a separate PR modernising the dev deps if useful.

🤖 Generated with Claude Code

Scripts.txt only lists assigned codepoints, and script_from_codepoint/1
generates one clause per range with no fallback. Any codepoint outside
the bundled data raises FunctionClauseError, so a caller that merely
passed along a recent character crashes rather than degrading.

U+20C1 SAUDI RIYAL SIGN (Unicode 16.0) is a common way to hit this: it
takes down OpenType.Layout.detect_script/1 for any string containing a
Saudi Riyal amount.

Adds the UCD's documented @missing default (Unknown) as a final clause.
That value is already handled everywhere it lands — script_to_tag/1 maps
it to "zzzz", and detect_script/1 filters it out with Common and
Inherited — so nothing downstream needs to change.

Also refreshes Scripts.txt from Unicode 12.0 (2019) to 17.0, which gives
codepoints added since then their real script rather than Unknown.
U+20C1 becomes Common, as it should be.
nagieeb0 added a commit to nagieeb0/qalam that referenced this pull request Jul 30, 2026
A brand face rarely covers everything, and what it misses is usually a
currency sign or a second script sitting mid-sentence. Before this, such
a codepoint rendered as an empty .notdef box with no way to fix it short
of editing the font.

Qalam.line/4 now takes a list of fonts. Runs are split again wherever
the covering face changes, so no run spans two faces, and each carries
the index of the face that should draw it. Coverage is a cmap lookup,
not a shaping pass. Measurement follows the same split, so widths still
match what lands on the page.

A codepoint no face covers stays on the primary and renders as a visible
box — silently dropping text is the worse failure.

Also documents the unicode_data override needed until
jbowtie/unicode_data#72 lands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant