-
-
Notifications
You must be signed in to change notification settings - Fork 47
Deterministic rendering of the extras charmap sample #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pelson
merged 1 commit into
ipython:master
from
pelson:feature/deterministic-rendering-of-extras
Apr 30, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| """ | ||
| import os | ||
| import re | ||
| import sys | ||
| import unicodedata | ||
|
|
||
| import matplotlib | ||
|
|
@@ -43,19 +44,48 @@ | |
| (0x0180, 0x0250, "Latin Extended-B"), | ||
| (0x0300, 0x0370, "Combining Diacritical Marks"), | ||
| (0x0370, 0x0400, "Greek and Coptic"), | ||
| (0x2018, 0x2040, "General Punctuation"), | ||
| (0x1E00, 0x1F00, "Latin Extended Additional"), | ||
| (0x2000, 0x2070, "General Punctuation"), | ||
| (0x2190, 0x2200, "Arrows"), | ||
| (0x2200, 0x2300, "Mathematical Operators"), | ||
| ] | ||
|
|
||
| COLS = 16 | ||
| COMBINING_CATS = {'Mn', 'Mc', 'Me'} | ||
|
|
||
| # Any font glyphs not covered by the defined blocks go in a catch-all block. | ||
| # Explicit ordered list of codepoints that fall outside all named blocks above. | ||
| # Order here controls layout in the "Non-Latin / Other" charmap table. | ||
| # If the font contains a glyph outside every named block that is not listed | ||
| # here, the script errors and tells you to add it. | ||
| # Use None to reserve a slot (renders as a blank cell) so that removing a | ||
| # character doesn't shift subsequent entries and cause a noisy table diff. | ||
| EXTRAS_ORDER = [ | ||
| 0x025B, # ɛ LATIN SMALL LETTER OPEN E | ||
| 0x1F382, # 🎂 BIRTHDAY CAKE | ||
| ] | ||
|
|
||
| block_covered = set() | ||
| for start, end, _ in BLOCKS: | ||
| block_covered.update(range(start, end)) | ||
| extras = sorted(cp for cp in present if cp not in block_covered) | ||
|
|
||
| extras_in_block = [cp for cp in EXTRAS_ORDER if cp is not None and cp in block_covered] | ||
| if extras_in_block: | ||
| lines = [f" U+{cp:04X} {unicodedata.name(chr(cp), '(unknown)')}" for cp in extras_in_block] | ||
| raise ValueError( | ||
| "EXTRAS_ORDER contains codepoints already covered by a named block:\n" | ||
| + "\n".join(lines) | ||
| ) | ||
|
|
||
| extras_cps = set(cp for cp in EXTRAS_ORDER if cp is not None) | ||
| uncovered = sorted(cp for cp in present if cp not in block_covered and cp not in extras_cps) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #82 we had to exclude non-visible characters. If we make any change in this PR, then perhaps do that here too. |
||
| if uncovered: | ||
| lines = [f" U+{cp:04X} {unicodedata.name(chr(cp), '(unknown)')}" for cp in uncovered] | ||
| raise ValueError( | ||
| "Font contains codepoints not in any named block or EXTRAS_ORDER.\n" | ||
| "Add them to EXTRAS_ORDER in gen_charmap.py:\n" + "\n".join(lines) | ||
| ) | ||
|
|
||
| extras = list(EXTRAS_ORDER) | ||
| if extras: | ||
| BLOCKS = list(BLOCKS) + [(None, None, "Non-Latin / Other")] | ||
|
|
||
|
|
@@ -134,14 +164,18 @@ def render_block(label, rows): | |
| y_bottom = y_top - CELL_H | ||
| y_center = (y_top + y_bottom) / 2 | ||
|
|
||
| hex_tag = f'U+{cps[0]:04X}' if cps else '' | ||
| first_cp = next((c for c in cps if c is not None), None) | ||
| hex_tag = f'U+{first_cp:04X}' if first_cp is not None else '' | ||
| ax.text(LABEL_W - 0.05, y_center, hex_tag, | ||
| ha='right', va='center', fontproperties=fp_tiny, color='#555555') | ||
|
|
||
| for col, cp in enumerate(cps): | ||
| x_left = LABEL_W + col * CELL_W | ||
| x_center = x_left + CELL_W / 2 | ||
|
|
||
| if cp is None: | ||
| continue | ||
|
|
||
| try: | ||
| cat = unicodedata.category(chr(cp)) | ||
| except (ValueError, OverflowError): | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it makes sense here to reserve N rows (e.g. 6 rows) to avoid later resizing noise.