Commit bda0f73
committed
Deep-check for monospacity
Before this change, a font is considered monospace if `fontdb` flags it
as such. `fontdb` checks the `post` table for this property.
But some fonts don't set that property there.
Most notably, "Noto Sans Mono" is among these fonts. Monospace as
a property is said to be communicated in other places like `OS/2`'s
`panose`, but that's not set in the Noto font either.
Loosely based on a `fontconfig` function called
`FcFreeTypeSpacing()`, this commit adds an additional check against
fonts that are not set as `monospaced` by `fontdb`. The horizontal
advances of all glyphs of a cmap unicode table are checked to see
if they are monospace. Proportionality with double-width and
treble-width advances is taken into consideration. Treble width
advances exist in the aforementioned Noto font.
The checks should be efficient, but the overhead is not in the noise.
So these extra checks are only run if the "monospace_fallback" crate
feature is enabled.
This change also requires library users to check monospacity with
`FontSystem::is_monospace()` instead of `FaceInfo::monospaced` from
`fontdb` to be in-sync with cosmic-text's view. This requirement was
probably coming in the future anyway for when cosmic-text adds support
for variable fonts.
Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>1 parent 4fe90bb commit bda0f73
3 files changed
+107
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
94 | 153 | | |
95 | 154 | | |
96 | | - | |
| 155 | + | |
97 | 156 | | |
98 | 157 | | |
99 | | - | |
100 | | - | |
101 | | - | |
| 158 | + | |
| 159 | + | |
102 | 160 | | |
103 | 161 | | |
104 | 162 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 163 | + | |
| 164 | + | |
111 | 165 | | |
112 | 166 | | |
113 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
166 | 180 | | |
167 | 181 | | |
168 | 182 | | |
| |||
197 | 211 | | |
198 | 212 | | |
199 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
200 | 229 | | |
201 | 230 | | |
202 | 231 | | |
| |||
244 | 273 | | |
245 | 274 | | |
246 | 275 | | |
247 | | - | |
| 276 | + | |
248 | 277 | | |
249 | 278 | | |
250 | 279 | | |
| |||
264 | 293 | | |
265 | 294 | | |
266 | 295 | | |
| 296 | + | |
267 | 297 | | |
268 | 298 | | |
269 | 299 | | |
270 | 300 | | |
271 | 301 | | |
272 | 302 | | |
273 | 303 | | |
274 | | - | |
| 304 | + | |
275 | 305 | | |
276 | 306 | | |
277 | 307 | | |
| |||
0 commit comments