summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn-Mark Bell <jmb@netsurf-browser.org>2021-08-05 19:23:14 +0100
committerJohn-Mark Bell <jmb@netsurf-browser.org>2021-08-05 19:23:14 +0100
commitee664df8218ff38d9d90dddecc0c20cd2857a4be (patch)
treed47b0bfbd4a11b0078cdb4311baf98aac4bcc174 /src
parentec4f056527a065d95583f1c82b9d9975bd89bf2a (diff)
downloadttf2f-master.tar.gz
ttf2f-master.tar.bz2
Fix Encoding file entries for astral characters.HEADmaster
Early versions of the UCS Font Manager (3.41-3.42) supported the use of /uni followed by up to 8 upper-case hex digits to specify the Unicode codepoint represented by a glyph. Font Manager 3.43 changed this behaviour to align with Adobe's then-current specification of /uniXXXX for characters in the Basic Multilingual Plane and /uniXXXXYYYY for all other characters (where XXXX is a high UTF-16 surrogate and YYYY is a low surrogate) Font Manager 3.53 changed again to remove support for /uniXXXXYYYY and, instead, introduced support for /uXXXX to /uXXXXXXXX, where leading zeroes are forbidden if more than 4 hex digits are present. Change our behaviour to use the /uniXXXX form for characters in the Basic Multilingual Plane (which is supported by all versions of the UCS Font Manager) and use the /uXXXXX - /uXXXXXXXX form for all other characters. This effectively means that Font Manager 3.53 or later is required when astral characters are in use.
Diffstat (limited to 'src')
-rw-r--r--src/encoding.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/encoding.c b/src/encoding.c
index ae8767d..8f9671f 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -78,8 +78,15 @@ void encoding_write_glyph(int index, struct glyph *glyph,
glyph->name);
}
} else if (glyph->code != (unsigned int) -1) {
- fprintf(fp, "%4.4X;uni%04X;COMMENT\n", index,
- glyph->code);
+ if (glyph->code < 0x10000) {
+ /* Use uniXXXX for BMP codepoints */
+ fprintf(fp, "%4.4X;uni%04X;COMMENT\n", index,
+ glyph->code);
+ } else {
+ /* Use uXXXXX - uXXXXXXXX otherwise */
+ fprintf(fp, "%4.4X;u%X;COMMENT\n", index,
+ glyph->code);
+ }
} else {
fprintf(fp, "# Skipping %4.4X\n", index);
}
@@ -87,11 +94,26 @@ void encoding_write_glyph(int index, struct glyph *glyph,
if (glyph->name != 0) {
fprintf(fp, "/%s\n", glyph->name);
} else if (glyph->code != (unsigned int) -1) {
- fprintf(fp, "/uni%4.4X\n", glyph->code);
+ if (glyph->code < 0x10000) {
+ /* Use /uniXXXX for BMP codepoints */
+ fprintf(fp, "/uni%4.4X\n", glyph->code);
+ } else {
+ /* Use /uXXXXX - /uXXXXXXXX otherwise.
+ * These are supported since FM 3.53.
+ * FM 3.43 - 3.52 (inclusive) understood
+ * /uniXXXXYYYY, where XXXX and YYYY were
+ * a UTF-16 surrogate pair. We have never
+ * emitted such things and support for
+ * them was removed in FM 3.53 with the
+ * introduction of support for the /u form.
+ * Thus, take the easy option and rely on
+ * noone running a UCS FM earlier than 3.53
+ * expecting astral codepoints to work.
+ */
+ fprintf(fp, "/u%X\n", glyph->code);
+ }
} else {
fprintf(fp, "/.notdef\n");
}
}
}
-
-