[pango/fix-spaceless-fonts: 3/3] Fix handling of space-less fonts
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/fix-spaceless-fonts: 3/3] Fix handling of space-less fonts
- Date: Thu, 16 Dec 2021 20:45:49 +0000 (UTC)
commit a2b9be849c005d1c30fe2a244294d7e4a816c908
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 16 08:40:07 2021 -0500
Fix handling of space-less fonts
HarfBuzz knows how to synthesize spaces, we just
need to tickle it in the right way.
Test included.
Update affected tests.
Fixes: #641
pango/shape.c | 10 ++-
tests/fonts/README | 1 +
tests/fonts/fa-regular-f2db.ttf | Bin 0 -> 912 bytes
tests/fonts/fa-solid-f2db.ttf | Bin 0 -> 1320 bytes
tests/layouts/no-space.layout | 142 ++++++++++++++++++++++++++++++++++++++++
tests/layouts/valid-14.layout | 20 ++----
tests/meson.build | 1 +
7 files changed, 160 insertions(+), 14 deletions(-)
---
diff --git a/pango/shape.c b/pango/shape.c
index 45c979f2..d0140d5e 100644
--- a/pango/shape.c
+++ b/pango/shape.c
@@ -137,10 +137,18 @@ pango_hb_font_get_nominal_glyph (hb_font_t *font,
if (hb_font_get_nominal_glyph (context->parent, unicode, glyph))
return TRUE;
+ /* HarfBuzz knows how to synthesize spaces, so never replace them
+ * with unknown glyphs, but we do need to tell HarfBuzz that the
+ * font does not have a glyph.
+ */
+ if (g_unichar_type (unicode) == G_UNICODE_SPACE_SEPARATOR)
+ return FALSE;
+
*glyph = PANGO_GET_UNKNOWN_GLYPH (unicode);
/* We draw our own invalid-Unicode shape, so prevent HarfBuzz
- * from using REPLACEMENT CHARACTER. */
+ * from using REPLACEMENT CHARACTER.
+ */
if (unicode > 0x10FFFF)
return TRUE;
diff --git a/tests/fonts/README b/tests/fonts/README
index 9cc88ca7..ca56ca40 100644
--- a/tests/fonts/README
+++ b/tests/fonts/README
@@ -7,3 +7,4 @@ DejaVSansMono.ttf: DejaVu Sans Mono
emoji-subset.ttf: subset of Noto Color Emoji
droid-sans-subset.ttf: subset of Droid Sans Japanese
amiri-06dd.ttf: subset of Amiri containing U+06dd
+fa-regular-f2db.ttf, fa-solid-f2db.ttf: subset of FontAwesome containing U+f2db
diff --git a/tests/fonts/fa-regular-f2db.ttf b/tests/fonts/fa-regular-f2db.ttf
new file mode 100644
index 00000000..54e0f1fb
Binary files /dev/null and b/tests/fonts/fa-regular-f2db.ttf differ
diff --git a/tests/fonts/fa-solid-f2db.ttf b/tests/fonts/fa-solid-f2db.ttf
new file mode 100644
index 00000000..dc5ef3d7
Binary files /dev/null and b/tests/fonts/fa-solid-f2db.ttf differ
diff --git a/tests/layouts/no-space.layout b/tests/layouts/no-space.layout
new file mode 100644
index 00000000..c3db1841
--- /dev/null
+++ b/tests/layouts/no-space.layout
@@ -0,0 +1,142 @@
+{
+ "context" : {
+ "font" : "serif 12",
+ "base-gravity" : "south",
+ "gravity-hint" : "natural",
+ "base-dir" : "weak-ltr",
+ "round-glyph-positions" : true,
+ "transform" : [
+ 1,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0
+ ]
+ },
+ "comment" : "Test that we get synthesized spaces\nfrom HarfBuzz.",
+ "text" : " ",
+ "font" : "Font Awesome 5 Free 32",
+ "output" : {
+ "is-wrapped" : false,
+ "is-ellipsized" : false,
+ "unknown-glyphs" : 0,
+ "width" : 220160,
+ "height" : 220160,
+ "log-attrs" : [
+ {
+ "char-break" : true,
+ "white" : true,
+ "cursor-position" : true,
+ "sentence-boundary" : true,
+ "backspace-deletes-character" : true,
+ "expandable-space" : true,
+ "word-boundary" : true
+ },
+ {
+ "char-break" : true,
+ "white" : true,
+ "cursor-position" : true,
+ "expandable-space" : true
+ },
+ {
+ "line-break" : true,
+ "char-break" : true,
+ "cursor-position" : true,
+ "sentence-start" : true,
+ "word-boundary" : true
+ },
+ {
+ "char-break" : true,
+ "white" : true,
+ "cursor-position" : true,
+ "sentence-end" : true,
+ "backspace-deletes-character" : true,
+ "expandable-space" : true,
+ "word-boundary" : true
+ },
+ {
+ "char-break" : true,
+ "white" : true,
+ "cursor-position" : true,
+ "expandable-space" : true
+ },
+ {
+ "line-break" : true,
+ "mandatory-break" : true,
+ "char-break" : true,
+ "white" : true,
+ "cursor-position" : true,
+ "sentence-boundary" : true,
+ "word-boundary" : true
+ }
+ ],
+ "lines" : [
+ {
+ "start-index" : 0,
+ "length" : 7,
+ "paragraph-start" : true,
+ "direction" : "ltr",
+ "runs" : [
+ {
+ "offset" : 0,
+ "length" : 7,
+ "text" : " ",
+ "bidi-level" : 0,
+ "gravity" : "south",
+ "language" : "en-us",
+ "script" : "common",
+ "font" : {
+ "description" : "Font Awesome 5 Free Heavy 32",
+ "checksum" : "f9d6933d04c59a42aca30bd88eec38bb9cbeb69b1547fd550ef73eba0bce7a1a",
+ "matrix" : [
+ 1,
+ -0,
+ -0,
+ 1,
+ 0,
+ 0
+ ]
+ },
+ "flags" : 0,
+ "y-offset" : 0,
+ "start-x-offset" : 0,
+ "end-x-offset" : 0,
+ "glyphs" : [
+ {
+ "glyph" : 0,
+ "width" : 44032,
+ "is-cluster-start" : true,
+ "log-cluster" : 0
+ },
+ {
+ "glyph" : 0,
+ "width" : 44032,
+ "is-cluster-start" : true,
+ "log-cluster" : 1
+ },
+ {
+ "glyph" : 460,
+ "width" : 44032,
+ "is-cluster-start" : true,
+ "log-cluster" : 2
+ },
+ {
+ "glyph" : 0,
+ "width" : 44032,
+ "is-cluster-start" : true,
+ "log-cluster" : 5
+ },
+ {
+ "glyph" : 0,
+ "width" : 44032,
+ "is-cluster-start" : true,
+ "log-cluster" : 6
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/tests/layouts/valid-14.layout b/tests/layouts/valid-14.layout
index ca686814..8cfa62d9 100644
--- a/tests/layouts/valid-14.layout
+++ b/tests/layouts/valid-14.layout
@@ -23,7 +23,7 @@
"output" : {
"is-wrapped" : false,
"is-ellipsized" : true,
- "unknown-glyphs" : 1,
+ "unknown-glyphs" : 0,
"width" : 161792,
"height" : 161792,
"log-attrs" : [
@@ -189,8 +189,8 @@
"runs" : [
{
"offset" : 0,
- "length" : 3,
- "text" : "你",
+ "length" : 6,
+ "text" : "你好",
"bidi-level" : 0,
"gravity" : "south",
"language" : "en-us",
@@ -241,9 +241,9 @@
]
},
{
- "offset" : 3,
- "length" : 4,
- "text" : "好 ",
+ "offset" : 6,
+ "length" : 1,
+ "text" : " ",
"bidi-level" : 0,
"gravity" : "south",
"language" : "xx",
@@ -266,16 +266,10 @@
"end-x-offset" : 0,
"glyphs" : [
{
- "glyph" : 1,
+ "glyph" : 0,
"width" : 15360,
"is-cluster-start" : true,
"log-cluster" : 0
- },
- {
- "glyph" : 268435488,
- "width" : 0,
- "is-cluster-start" : true,
- "log-cluster" : 3
}
]
},
diff --git a/tests/meson.build b/tests/meson.build
index 79510fb6..271d9046 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -122,6 +122,7 @@ installed_test_layouts_data = [
'layouts/tab-crash.layout',
'layouts/tab-assert.layout',
'layouts/arabic-format.layout',
+ 'layouts/no-space.layout',
]
test_markups_data = [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]