oasis-editor 0.0.99 → 0.0.100

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.
@@ -1,21 +1,30 @@
1
1
  import { GlyphRun, ParsedFontProgram, TextLayouter } from '../core/types.js';
2
2
 
3
3
  /**
4
- * A {@link TextLayouter} that applies OpenType GSUB substitution for the editor's
5
- * Latin font features (ligatures, figure style, stylistic sets, contextual
6
- * alternates) when the font carries a GSUB table and the caller requests them.
4
+ * A {@link TextLayouter} that applies OpenType shaping for the editor's Latin font
5
+ * features when the font carries the relevant tables and the caller requests them:
7
6
  *
8
- * With no requested featuresor a font without GSUB — it falls straight back to
9
- * the same 1:1 codepoint→glyph mapping as `SimpleTextLayouter`, so ordinary text
10
- * is byte-for-byte unchanged. GSUB only substitutes glyphs; advances come from
11
- * `hmtx` (GPOS positioning is out of scope), so `positions[].xAdvance` equals each
12
- * resulting glyph's advance width.
7
+ * - **GSUB** glyph substitutionligatures, figure style, stylistic sets, and
8
+ * contextual alternates (changes glyph identity and count).
9
+ * - **GPOS** glyph positioning pair kerning (`kern`), which adjusts horizontal
10
+ * advances only.
11
+ *
12
+ * With no requested features — or a font without these tables — it falls straight
13
+ * back to the same 1:1 codepoint→glyph mapping as `SimpleTextLayouter`, so ordinary
14
+ * text is byte-for-byte unchanged. Substitution runs first, then kerning adjusts
15
+ * the resulting glyphs' advances (`positions[].xAdvance`); GPOS placement, vertical
16
+ * metrics, and mark attachment are out of scope.
13
17
  */
14
18
  export declare class OpenTypeLayouter implements TextLayouter {
15
19
  private readonly font;
16
20
  private readonly gsub;
21
+ private readonly gpos;
17
22
  constructor(font: ParsedFontProgram);
18
- /** True when the font exposes a GSUB table the shaper could use. */
23
+ /** True when the font exposes a GSUB table the substitution shaper could use. */
19
24
  get hasGsub(): boolean;
25
+ /** True when the font exposes a GPOS table the kerning shaper could use. */
26
+ get hasGpos(): boolean;
27
+ /** True when either shaping table is present (so this layouter adds value). */
28
+ get hasShaping(): boolean;
20
29
  layout(text: string, features?: readonly string[]): GlyphRun;
21
30
  }
@@ -0,0 +1,15 @@
1
+ export declare class GposTable {
2
+ private readonly lookups;
3
+ private readonly featureToLookups;
4
+ private constructor();
5
+ /** Parses GPOS bytes (table-relative). Returns null on any structural failure. */
6
+ static parse(bytes: Uint8Array): GposTable | null;
7
+ /** True when at least one of the requested feature tags exists in this font. */
8
+ hasAnyFeature(tags: readonly string[]): boolean;
9
+ /**
10
+ * Applies the positioning lookups for the given features across `advances`
11
+ * (font design units), mutating it in place. `glyphIds[i]` is the glyph at
12
+ * advance slot `i`; the arrays are parallel and equal length.
13
+ */
14
+ position(glyphIds: number[], advances: number[], tags: readonly string[]): void;
15
+ }
@@ -4,9 +4,10 @@
4
4
  * style (lnum/onum/pnum/tnum), stylistic sets (ss01–ss20), and contextual
5
5
  * alternates (calt).
6
6
  *
7
- * It parses ScriptList/FeatureList/LookupList and the substitution lookup types
8
- * those features use single (1), multiple (2), alternate (3), ligature (4),
9
- * chaining contextual (6), and extension (7). Positioning (GPOS), complex-script
7
+ * It parses ScriptList/FeatureList/LookupList (the first two via the shared
8
+ * {@link otLayoutCommon}) and the substitution lookup types those features use
9
+ * single (1), multiple (2), alternate (3), ligature (4), chaining contextual (6),
10
+ * and extension (7). Positioning (GPOS — see {@link ./GposTable}), complex-script
10
11
  * shaping, and lookup-flag glyph skipping are intentionally out of scope.
11
12
  *
12
13
  * Parsing is defensive: any malformed offset or unsupported construct is skipped
@@ -0,0 +1,38 @@
1
+ import { BinaryReader } from '../../truetype/BinaryReader.js';
2
+
3
+ /**
4
+ * Shared scaffolding for the OpenType "Layout" tables (GSUB and GPOS). Both share
5
+ * an identical header (ScriptList / FeatureList / LookupList offsets), the same
6
+ * Coverage and ClassDef formats, and the same script/feature resolution; only the
7
+ * lookup subtables differ (substitution vs. positioning). This module owns the
8
+ * common pieces so {@link ../opentype/GsubTable} and {@link ../opentype/GposTable}
9
+ * stay a single source of truth for that machinery.
10
+ *
11
+ * All offsets are relative to the start of the table bytes passed to the parser.
12
+ * Parsing is defensive: callers wrap these in try/catch and degrade gracefully, so
13
+ * a malformed table never breaks export.
14
+ */
15
+ /** Returns the coverage index of a glyph id, or -1 when not covered. */
16
+ export type Coverage = (glyphId: number) => number;
17
+ /** Returns the class of a glyph id (0 when unlisted). */
18
+ export type ClassLookup = (glyphId: number) => number;
19
+ export declare function parseCoverage(reader: BinaryReader, offset: number): Coverage;
20
+ export declare function parseClassDef(reader: BinaryReader, offset: number): ClassLookup;
21
+ /** The common header of a Layout table: feature→lookup map + lookup-list offset. */
22
+ export interface LayoutTableHeader {
23
+ /**
24
+ * Maps each feature tag offered by the resolved Latin/DFLT language system to
25
+ * its ordered lookup indices.
26
+ */
27
+ featureToLookups: Map<string, number[]>;
28
+ /** Table-relative offset of the LookupList, parsed by the owning table. */
29
+ lookupListOffset: number;
30
+ }
31
+ /**
32
+ * Parses the shared GSUB/GPOS header: version, the three list offsets, the
33
+ * feature list, and the active feature set from the script list. The caller
34
+ * parses the LookupList itself (its subtables are table-specific).
35
+ */
36
+ export declare function parseLayoutTableHeader(reader: BinaryReader): LayoutTableHeader;
37
+ /** Ordered (ascending) unique lookup indices referenced by the given tags. */
38
+ export declare function collectLookupIndices(featureToLookups: Map<string, number[]>, tags: readonly string[]): number[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oasis-editor",
3
- "version": "0.0.99",
3
+ "version": "0.0.100",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",