Skip to content

Commit 8760054

Browse files
Copilotshai-almog
andauthored
Handle unsupported material icon codepoints (#4763)
Agent-Logs-Url: https://github.com/codenameone/CodenameOne/sessions/0f71a736-b34d-4114-adcd-bd340003c957 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: shai-almog <67850168+shai-almog@users.noreply.github.com>
1 parent 7a09587 commit 8760054

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

.github/scripts/update_material_icons.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929
CONSTANT_RE = re.compile(r"^\s*public static final char MATERIAL_")
3030
SENTINEL = " private static Font materialDesignFont;"
31+
MAX_JAVA_CHAR_CODEPOINT = 0xFFFF
3132

3233

3334
def download_text(url: str) -> str:
@@ -61,13 +62,28 @@ def parse_codepoints(codepoints_text: str) -> list[tuple[str, str]]:
6162
return out
6263

6364

64-
def generate_constants_block(entries: list[tuple[str, str]]) -> str:
65+
def java_char_literal(codepoint: str) -> str | None:
66+
value = int(codepoint, 16)
67+
if value > MAX_JAVA_CHAR_CODEPOINT:
68+
return None
69+
return f"\\u{value:04X}"
70+
71+
72+
def generate_constants_block(entries: list[tuple[str, str]]) -> tuple[str, list[tuple[str, str]]]:
6573
lines: list[str] = []
74+
skipped: list[tuple[str, str]] = []
6675
for icon_name, codepoint in entries:
6776
const_name = material_constant_name(icon_name)
77+
char_literal = java_char_literal(codepoint)
78+
if char_literal is None:
79+
skipped.append((const_name, codepoint.upper()))
80+
lines.append(
81+
f" // {const_name} omitted: U+{codepoint.upper()} is outside the Java char range."
82+
)
83+
continue
6884
lines.append(CONSTANT_DOC.rstrip("\n"))
69-
lines.append(f" public static final char {const_name} = '\\u{codepoint.upper()}';")
70-
return "\n".join(lines) + "\n"
85+
lines.append(f" public static final char {const_name} = '{char_literal}';")
86+
return "\n".join(lines) + "\n", skipped
7187

7288

7389
def is_material_constant_doc_line(line: str) -> bool:
@@ -126,7 +142,15 @@ def main() -> int:
126142
remote_font = download_bytes(MATERIAL_FONT_URL)
127143
codepoints = download_text(MATERIAL_CODEPOINTS_URL)
128144
entries = parse_codepoints(codepoints)
129-
constants_block = generate_constants_block(entries)
145+
constants_block, skipped = generate_constants_block(entries)
146+
if skipped:
147+
skipped_names = ", ".join(
148+
f"{const_name} (U+{codepoint})" for const_name, codepoint in skipped
149+
)
150+
print(
151+
"Skipping Material icons that cannot be represented as Java char constants: "
152+
f"{skipped_names}"
153+
)
130154

131155
font_changed = update_font(remote_font, check_only=args.check)
132156
constants_changed = update_fontimage(constants_block, check_only=args.check)

CodenameOne/src/com/codename1/ui/FontImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,7 @@ public final class FontImage extends Image {
27502750
public static final char MATERIAL_GITE = '\uE58B';
27512751
/// Material design icon font character code see
27522752
/// https://www.material.io/resources/icons/ for full list
2753-
// public static final char MATERIAL_GOAT = '\u10FFFD';
2753+
// MATERIAL_GOAT omitted: U+10FFFD is outside the Java char range.
27542754
/// Material design icon font character code see
27552755
/// https://www.material.io/resources/icons/ for full list
27562756
public static final char MATERIAL_GOLF_COURSE = '\uEB45';

0 commit comments

Comments
 (0)