ntk 8.29.0 → 8.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -460,16 +460,18 @@ export default class FontManager {
460
460
  /**
461
461
  * Find a font that has a glyph for `codepoint`, for use when the primary
462
462
  * font doesn't. The registered faces of the families the style names
463
- * first, in the order it names them, then any registered face, then the
464
- * source's fallback chain (filtered by the source's coverage data — font
465
- * files are only opened to confirm). Returns null when nothing on the
466
- * system covers the codepoint.
463
+ * first, in the order it names them, then the source's fallback chain
464
+ * (filtered by the source's coverage data — font files are only opened to
465
+ * confirm). Returns null when nothing on the system covers the codepoint.
467
466
  *
468
467
  * The families first because that is what a list of them is for: CSS's
469
468
  * `font-family: Icons, Arial` sets a letter the icon face lacks in Arial,
470
469
  * as a browser does. Walking every registered face instead gave it to
471
470
  * whichever was registered first — an app's serif — however far down the
472
- * list, or off it, that face was.
471
+ * list, or off it, that face was. Nor does a registered face the list does
472
+ * not name stand in for the source's: a face one document registers (a web
473
+ * font) would otherwise supply glyphs to every later document's text, and
474
+ * to text in no family of the app's at all.
473
475
  *
474
476
  * "Nothing covers it" includes "this environment has no system fonts at
475
477
  * all". An app that loaded its own faces still reaches here for the first
@@ -499,14 +501,6 @@ export default class FontManager {
499
501
  }
500
502
  }
501
503
  }
502
- if (!found) {
503
- for (const r of this._registered) {
504
- if (r.font.hasGlyph(codepoint)) {
505
- found = r.font;
506
- break;
507
- }
508
- }
509
- }
510
504
  if (!found) {
511
505
  const source = this.source;
512
506
  let candidates;
package/lib/text/shape.js CHANGED
@@ -225,7 +225,11 @@ export function shapeText(fonts, text, style, levels) {
225
225
  for (const item of items) {
226
226
  const direction = item.level & 1 ? 'rtl' : 'ltr';
227
227
  const sub = text.slice(item.start, item.end);
228
- const shaped = item.font.shape(sub, size, {
228
+ // a character with a mirrored form is drawn as it in a right-to-left run
229
+ // (UAX#9 rule L4): `>` as `<`, `(` as `)`. Every pair is one code unit,
230
+ // so offsets and clusters are the run's own
231
+ const drawn = direction === 'rtl' ? mirrored(sub, item.font) : sub;
232
+ const shaped = item.font.shape(drawn, size, {
229
233
  direction,
230
234
  features,
231
235
  language: style.language
@@ -272,3 +276,20 @@ export function reorderRuns(runs) {
272
276
  }
273
277
  return out;
274
278
  }
279
+
280
+ /**
281
+ * A right-to-left run's text with each character that has a mirrored form
282
+ * (Unicode's Bidi_Mirroring_Glyph) swapped for it, where the font has it:
283
+ * UAX#9 rule L4. The text unchanged where it holds none.
284
+ */
285
+ function mirrored(text, font) {
286
+ let out = null;
287
+ for (let i = 0; i < text.length; i++) {
288
+ const swap = bidi.getMirroredCharacter(text[i]);
289
+ if (swap && swap.length === 1 && font.hasGlyph(swap.codePointAt(0))) {
290
+ out ??= text.split('');
291
+ out[i] = swap;
292
+ }
293
+ }
294
+ return out ? out.join('') : text;
295
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ntk",
3
- "version": "8.29.0",
3
+ "version": "8.29.2",
4
4
  "description": "Desktop UI toolkit for X11 with canvas-like 2d and OpenGL rendering",
5
5
  "author": "Andrey Sidorov <sidorares@yandex.ru>",
6
6
  "license": "MIT",