fontisan 0.4.50-java → 0.4.51-java

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 702eea844ae2f2e23fc8ddac0166235420a8aedc3f98e1f68354894576f89c69
4
- data.tar.gz: 17546ffc35f74e82671fc9fab84c78f79fa994acf8eed67d801e3b6a35af225d
3
+ metadata.gz: b2a75a79d142a84db29cdf6fc713dd4e5fbaaa78060d44b5313e49bf3535562f
4
+ data.tar.gz: 59791f20c18ad2f14baf9483e1b9f425c40ee145d85df15bab27b2287a800b1f
5
5
  SHA512:
6
- metadata.gz: 6923a26164c3194e2ed480bc1fe8c084c11985c2abd1fafdceb281ade078eaac1c3717286e9fc7a440f7f0b11b99139cf49ee9a175d173d8aa0cb070aec48dfe
7
- data.tar.gz: 42759498acb1d661a1adc4960dc3c9936d0d3e3151abb90153f29983a6d97a9030e22a60b75a4f0e364737a70f20e95820023069034e536f0472335d73be45cd
6
+ metadata.gz: 38b68b95d2b2e763db44d194c1f1fa54d1ac7fa7d28e106eb0cfc22a9e4645dcb98ea069f0a0d9c837ea249f436831050a1450265d7fc9b776c3ea78abeb0930
7
+ data.tar.gz: 3274daceec582e533843c740965c7f9b84f1115b5ce38cf0a1b1c03a93b514d7c3717bec9b83a77f36bb5871bf5fc41799914e98309b8bb9f96f930de33ab4ed
data/BENCHMARKS.md CHANGED
@@ -54,3 +54,37 @@ Native factor (ruby time / native time) from the `perf-gate.yml` `tiers` jobs, r
54
54
 
55
55
  All six rows now come from CI. arm64-darwin has no committed baseline yet, so it is checked against the 1.00x floor only. The lowest published native factor on a gated operation is 5.51x (scan_dir, arm64-darwin).
56
56
 
57
+
58
+ ## Compile pipeline (TODO.remaining/20)
59
+
60
+ - Ruby: 4.0.7 (arm64-darwin23); local macOS arm64, single runs (runner
61
+ noise +-20%; rerun the scripts rather than comparing one line)
62
+ - Scripts: `benchmark/compile_benchmark.rb` (also `--large` for 65k),
63
+ `benchmark/collection_benchmark.rb`, `benchmark/fonttools_compare.rb`
64
+
65
+ fontisan in-memory compiler (synthetic 1-contour glyphs, 1 UPM):
66
+
67
+ | op | 1k glyphs | 10k glyphs |
68
+ |---|---|---|
69
+ | TTF compile | ~30-40 ms (25-31k glyphs/s) | ~190 ms (~50k glyphs/s) |
70
+ | OTF compile | ~25-30 ms (34-40k glyphs/s) | ~178 ms (~56k glyphs/s) |
71
+ | CFF2 OTF compile | ~24 ms (41k glyphs/s) | ~183 ms (~55k glyphs/s) |
72
+
73
+ Collection assembly (dedup pack, after compiling N x 1000-glyph faces):
74
+ 4 faces ~17 ms (output 74% smaller than the raw faces), 8 faces ~10 ms
75
+ (86% smaller).
76
+
77
+ fontisan vs ufo2ft (fontTools), same on-disk synthetic UFO, full
78
+ read+compile pipeline, 1000 glyphs, single runs:
79
+
80
+ | op | fontisan | ufo2ft | fontisan output vs ufo2ft |
81
+ |---|---|---|---|
82
+ | TTF | ~0.7-1.3 s | ~0.7-1.0 s | 32,752 B vs 40,532 B (smaller) |
83
+ | OTF | ~1.2-2.9 s | ~0.7-1.1 s | 23,752 B vs 13,616 B (larger) |
84
+
85
+ The gap sits almost entirely in the UFO reader: compiling the SAME font
86
+ from memory costs ~30 ms, so ~95% of fontisan's disk-path time is .glif
87
+ parsing (~1.2 ms/glyph). The TODO's ">2x slower than fontTools triggers
88
+ optimization" threshold is brushed by the OTF row on some runs; if it
89
+ holds under median-of-N measurement, the hot path to optimize is
90
+ Ufo::Reader, not the compilers.
data/Cargo.lock CHANGED
@@ -185,7 +185,7 @@ dependencies = [
185
185
  [[package]]
186
186
  name = "fontisan"
187
187
  version = "0.0.0"
188
- source = "git+https://github.com/fontist/fontisan-rs?rev=f45057a12e15ba9f2c02526cd8ca0603c80edaf9#f45057a12e15ba9f2c02526cd8ca0603c80edaf9"
188
+ source = "git+https://github.com/fontist/fontisan-rs?rev=8de6ac6bc838d2bf796a032c76cee78fe32ec671#8de6ac6bc838d2bf796a032c76cee78fe32ec671"
189
189
  dependencies = [
190
190
  "brotli",
191
191
  "brotli-decompressor",
data/README.adoc CHANGED
@@ -60,10 +60,9 @@ operations from three tiers: `native` (a precompiled Rust extension), `ffi` (the
60
60
  bundled Rust shared library, loaded through the `ffi` gem) and `ruby` (the pure
61
61
  Ruby implementation, always present).
62
62
 
63
- The default is `auto`, which currently serves everything from `ruby`: the Rust
64
- tiers are used only when selected with `FONTISAN_ENGINE=native` or `ffi`, until
65
- the native tier's release gates pass (see fontist/fontisan#160). After that,
66
- `auto` will pick the first available tier in the order `native`, `ffi`, `ruby`.
63
+ The default is `auto`: the first available tier in the order `native`, `ffi`,
64
+ `ruby` (the phase-3 gates passed; see fontist/fontisan#160). Platforms without
65
+ the bundled extension keep the `ruby` tier as the floor.
67
66
 
68
67
  [cols="1,3"]
69
68
  |===
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Benchmark: collection assembly performance.
4
+ #
5
+ # Compiles N synthetic UFO fonts to TTF, then packs them into a TTC
6
+ # with the shared-table deduplicator, measuring assembly time and the
7
+ # space the dedup saves. Complements compile_benchmark.rb
8
+ # (TODO.remaining/20: "Collection time: multi-font -> TTC/OTC").
9
+
10
+ require "tmpdir"
11
+ require "fontisan"
12
+ require_relative "compile_benchmark"
13
+
14
+ module FontisanBench
15
+ end
16
+
17
+ if __FILE__ == $PROGRAM_NAME
18
+ face_counts = ARGV.include?("--large") ? [4, 8, 16] : [4, 8]
19
+ face_counts.each do |count|
20
+ Dir.mktmpdir do |dir|
21
+ paths = Array.new(count) do |i|
22
+ ufo = FontisanBench.build_synthetic_font(1000)
23
+ ufo.info.family_name = "Bench#{i}"
24
+ File.join(dir, "face#{i}.ttf").tap do |path|
25
+ Fontisan::Ufo::Compile::TtfCompiler.new(ufo).compile(output_path: path)
26
+ end
27
+ end
28
+ fonts = paths.map { |p| Fontisan::FontLoader.load(p) }
29
+ out = File.join(dir, "packed.ttfc")
30
+ raw = paths.sum { |p| File.size(p) }
31
+ FontisanBench.measure("TTC pack (#{count} faces, ~1000 glyphs each)",
32
+ glyph_count: 1000 * count) do
33
+ Fontisan::Collection::Builder.new(fonts).build_to_file(out)
34
+ end
35
+ packed = File.size(out)
36
+ smaller = (1 - packed.to_f / raw) * 100
37
+ puts "collection size".ljust(40) +
38
+ "#{raw} B raw #{packed} B packed #{smaller.round(1)}% smaller"
39
+ end
40
+ end
41
+ end
@@ -30,7 +30,10 @@ module FontisanBench
30
30
  x: 100, y: 0, type: "line",
31
31
  ),
32
32
  Fontisan::Ufo::Point.new(
33
- x: 100, y: 100, type: "offcurve",
33
+ x: 95, y: 40, type: "offcurve",
34
+ ),
35
+ Fontisan::Ufo::Point.new(
36
+ x: 80, y: 90, type: "offcurve",
34
37
  ),
35
38
  Fontisan::Ufo::Point.new(
36
39
  x: 50, y: 150, type: "curve",
@@ -41,38 +44,46 @@ module FontisanBench
41
44
  font
42
45
  end
43
46
 
44
- def measure(label)
47
+ def rss_mb
48
+ # VmHWM is the true high-water mark on Linux; ps gives current RSS on
49
+ # macOS (close enough for one short compile, labelled RSS not peak).
50
+ if RUBY_PLATFORM.include?("linux")
51
+ File.read("/proc/self/status")[/VmHWM:\s+(\d+)/, 1].to_f / 1024
52
+ else
53
+ `ps -o rss= -p #{Process.pid}`.to_f / 1024
54
+ end
55
+ end
56
+
57
+ def measure(label, glyph_count: nil)
58
+ GC.start
45
59
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
46
60
  yield
47
61
  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
48
- puts format("%-40<label>s %8.<elapsed>.2f ms", label: label,
49
- elapsed: elapsed * 1000)
62
+ throughput = if glyph_count && elapsed.positive?
63
+ "#{(glyph_count / elapsed).round(0)} glyphs/s"
64
+ else
65
+ ""
66
+ end
67
+ puts "#{label.ljust(40)} #{format('%10.2f ms', elapsed * 1000)} " \
68
+ "#{format('%8.1f MB rss', rss_mb)} #{throughput}"
50
69
  elapsed
51
70
  end
52
71
  end
53
72
 
54
73
  if __FILE__ == $PROGRAM_NAME
55
- ufo = FontisanBench.build_synthetic_font(1000)
56
-
57
- Dir.mktmpdir do |dir|
58
- FontisanBench.measure("TTF compile (1000 glyphs)") do
59
- Fontisan::Ufo::Compile::TtfCompiler.new(ufo).compile(output_path: "#{dir}/a.ttf")
60
- end
61
- FontisanBench.measure("OTF compile (1000 glyphs)") do
62
- Fontisan::Ufo::Compile::OtfCompiler.new(ufo).compile(output_path: "#{dir}/a.otf")
63
- end
64
- FontisanBench.measure("CFF2 OTF compile (1000 glyphs)") do
65
- Fontisan::Ufo::Compile::Otf2Compiler.new(ufo).compile(output_path: "#{dir}/a-cff2.otf")
66
- end
67
- end
68
-
69
- Dir.mktmpdir do |dir|
70
- ufo_big = FontisanBench.build_synthetic_font(10_000)
71
- FontisanBench.measure("TTF compile (10k glyphs)") do
72
- Fontisan::Ufo::Compile::TtfCompiler.new(ufo_big).compile(output_path: "#{dir}/a.ttf")
73
- end
74
- FontisanBench.measure("CFF2 OTF compile (10k glyphs)") do
75
- Fontisan::Ufo::Compile::Otf2Compiler.new(ufo_big).compile(output_path: "#{dir}/a-cff2.otf")
74
+ sizes = ARGV.include?("--large") ? [1000, 10_000, 65_000] : [1000, 10_000]
75
+ sizes.each do |count|
76
+ ufo = FontisanBench.build_synthetic_font(count)
77
+ Dir.mktmpdir do |dir|
78
+ FontisanBench.measure("TTF compile (#{count} glyphs)", glyph_count: count) do
79
+ Fontisan::Ufo::Compile::TtfCompiler.new(ufo).compile(output_path: "#{dir}/a.ttf")
80
+ end
81
+ FontisanBench.measure("OTF compile (#{count} glyphs)", glyph_count: count) do
82
+ Fontisan::Ufo::Compile::OtfCompiler.new(ufo).compile(output_path: "#{dir}/a.otf")
83
+ end
84
+ FontisanBench.measure("CFF2 OTF compile (#{count} glyphs)", glyph_count: count) do
85
+ Fontisan::Ufo::Compile::Otf2Compiler.new(ufo).compile(output_path: "#{dir}/a-cff2.otf")
86
+ end
76
87
  end
77
88
  end
78
89
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Benchmark: fontisan's TTF/OTF compile vs ufo2ft (fontTools), the
4
+ # industry UFO compiler. Both consume the SAME on-disk UFO (written
5
+ # from one synthetic font, TODO.remaining/20), so the comparison is
6
+ # wall time and output size on identical input. Requires python3 with
7
+ # ufo2ft; the script reports SKIP and keeps running without it.
8
+
9
+ require "open3"
10
+ require "tmpdir"
11
+ require "fontisan"
12
+ require_relative "compile_benchmark"
13
+
14
+ module FontisanBench
15
+ module_function
16
+
17
+ # Minimal UFO 3 writer: enough structure for both compilers
18
+ # (metainfo, fontinfo, contents.plist, one .glif per glyph).
19
+ def write_ufo(font, dir)
20
+ require "fileutils"
21
+ FileUtils.mkdir_p(dir)
22
+ meta = File.join(dir, "metainfo.plist")
23
+ File.write(meta, Fontisan::Ufo::Plist.emit(
24
+ "formatVersion" => 3, "creator" => "fontisan-bench",
25
+ ))
26
+ File.write(File.join(dir, "fontinfo.plist"), Fontisan::Ufo::Plist.emit(
27
+ "familyName" => font.info.family_name,
28
+ "unitsPerEm" => font.info.units_per_em,
29
+ "ascender" => 800, "descender" => -200
30
+ ))
31
+ glyphs_dir = File.join(dir, "glyphs")
32
+ Dir.mkdir(glyphs_dir)
33
+ File.write(File.join(dir, "layercontents.plist"),
34
+ Fontisan::Ufo::Plist.emit([["public.default", "glyphs"]]))
35
+ contents = font.glyphs.to_h { |name, _| [name, "#{name}.glif"] }
36
+ File.write(File.join(glyphs_dir, "contents.plist"),
37
+ Fontisan::Ufo::Plist.emit(contents))
38
+ font.glyphs.each do |name, glyph|
39
+ File.write(File.join(glyphs_dir, "#{name}.glif"), glyph.to_glif)
40
+ end
41
+ dir
42
+ end
43
+
44
+ def python_has_ufo2ft?
45
+ _out, err, status = Open3.capture3("python3", "-c", "import ufo2ft")
46
+ warn "SKIP: ufo2ft not importable (#{err.strip.lines.first})" unless status.success?
47
+ status.success?
48
+ end
49
+
50
+ def python_compile(entry, ufo_dir, out_path)
51
+ script = <<~PY
52
+ from defcon import Font
53
+ from ufo2ft import #{entry}
54
+ ufo = Font("#{ufo_dir}")
55
+ font = #{entry}(ufo)
56
+ font.save("#{out_path}")
57
+ PY
58
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
59
+ _out, err, status = Open3.capture3("python3", "-c", script)
60
+ raise "ufo2ft failed: #{err.lines.last(3).join}" unless status.success?
61
+
62
+ Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
63
+ end
64
+ end
65
+
66
+ if __FILE__ == $PROGRAM_NAME
67
+ exit 0 unless FontisanBench.python_has_ufo2ft?
68
+
69
+ count = ARGV.include?("--large") ? 10_000 : 1000
70
+ rounds = ARGV.include?("--single") ? 1 : 5
71
+ ufo = FontisanBench.build_synthetic_font(count)
72
+ Dir.mktmpdir do |dir|
73
+ ufo_dir = FontisanBench.write_ufo(ufo, File.join(dir, "Bench.ufo"))
74
+ puts "#{count} glyphs, same on-disk UFO, median of #{rounds} rounds"
75
+ [
76
+ ["TTF", "compileTTF", Fontisan::Ufo::Compile::TtfCompiler, "a.ttf"],
77
+ ["OTF", "compileOTF", Fontisan::Ufo::Compile::OtfCompiler, "a.otf"],
78
+ ].each do |name, entry, compiler, out_name|
79
+ fontisan_out = File.join(dir, "fontisan-#{out_name}")
80
+ ufo2ft_out = File.join(dir, "ufo2ft-#{out_name}")
81
+ fontisan_times = []
82
+ ufo2ft_times = []
83
+ rounds.times do
84
+ fontisan_times << FontisanBench.measure(
85
+ "fontisan #{name} compile round", glyph_count: count
86
+ ) do
87
+ compiler.new(Fontisan::Ufo::Font.open(ufo_dir)).compile(output_path: fontisan_out)
88
+ end
89
+ ufo2ft_times << FontisanBench.python_compile(entry, ufo_dir, ufo2ft_out)
90
+ end
91
+ t = fontisan_times.sort[rounds / 2]
92
+ t2 = ufo2ft_times.sort[rounds / 2]
93
+ factor = t2.positive? ? format("%5.2fx", t2 / t) : "n/a"
94
+ throughput = t.positive? ? "#{(count / t).round(0)} glyphs/s" : ""
95
+ puts "#{"#{name} median: fontisan".ljust(40)} #{format('%8.2f ms', t * 1000)} #{throughput}"
96
+ puts "#{"#{name} median: ufo2ft ".ljust(40)} #{format('%8.2f ms', t2 * 1000)} " \
97
+ "output #{File.size(fontisan_out)} B vs #{File.size(ufo2ft_out)} B " \
98
+ "ufo2ft/fontisan time #{factor}"
99
+ end
100
+ end
101
+ end
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "tolerance": 0.25,
4
- "note": "Expected native factor (ruby time / native time) per platform and op, from the perf-gate.yml tiers jobs (run 42233249352 on 2b648ed, BENCHMARKS.md). audit_dir re-measured in run 42789182973 on 91beb5b: the Ruby tier got about 26% faster at audit_dir (one budgeted layout parse, 8e55ebd) while native time stayed flat, so the ratio fell. The tiers gate fails when a measured factor is more than `tolerance` below it. Both tiers run in the same job, so the factor cancels runner speed. A platform without an entry is held to the 1.00x floor only: arm64-darwin has no CI measurement yet. Raise a value only deliberately, from a green CI run.",
4
+ "note": "Expected native factor (ruby time / native time) per platform and op, from the perf-gate.yml tiers jobs (run 42233249352 on 2b648ed, BENCHMARKS.md). audit_dir re-measured in run 42789182973 on 91beb5b: the Ruby tier got about 26% faster at audit_dir (one budgeted layout parse, 8e55ebd) while native time stayed flat, so the ratio fell. The tiers gate fails when a measured factor is more than `tolerance` below it. Both tiers run in the same job, so the factor cancels runner speed. arm64-darwin measured in run 44723488635 (2026-11-20, the first green tiers run after the #160 flip). Raise a value only deliberately, from a green CI run.",
5
5
  "platforms": {
6
6
  "x86_64-linux": { "audit_file": 43.14, "audit_dir": 19.93, "scan_dir": 13.58 },
7
7
  "x86_64-linux-musl": { "audit_file": 21.07, "audit_dir": 14.96, "scan_dir": 10.76 },
8
8
  "aarch64-linux": { "audit_file": 45.51, "audit_dir": 11.15, "scan_dir": 7.86 },
9
9
  "x86_64-darwin": { "audit_file": 36.89, "audit_dir": 11.90, "scan_dir": 7.78 },
10
- "x64-mingw-ucrt": { "audit_file": 29.71, "audit_dir": 17.69, "scan_dir": 10.57 }
10
+ "x64-mingw-ucrt": { "audit_file": 29.71, "audit_dir": 17.69, "scan_dir": 10.57 },
11
+ "arm64-darwin": { "audit_file": 38.43, "audit_dir": 5.93, "scan_dir": 4.75 }
11
12
  }
12
13
  }
@@ -31,7 +31,7 @@ Set `FONTISAN_ENGINE` before the process starts. Unset or empty means `auto`:
31
31
  | `ruby` | Use the Ruby tier only. |
32
32
  | `native` | Use the native tier. |
33
33
  | `ffi` | Use the ffi tier. |
34
- | `auto` | The default. Currently serves everything from ruby; the Rust tiers are used only when selected explicitly, until the phase-3 gates pass (fontisan#160). After that, the first available tier in the order native, ffi, ruby. |
34
+ | `auto` | The default. The first available tier in the order native, ffi, ruby; the phase-3 gates passed (fontisan#160), so native serves wherever the gem bundles the extension. |
35
35
 
36
36
  ```sh
37
37
  FONTISAN_ENGINE=native FONTISAN_ENGINE_STRICT=1 fontisan convert MyFont.ttf --to woff2 --output out.woff2
@@ -68,12 +68,27 @@ Fontisan::Engine.served_by(:audit) # => :native
68
68
 
69
69
  ## What stays on Ruby
70
70
 
71
- These always run on the Ruby tier, whichever engine is selected, and strict mode does not raise for them:
71
+ The full capability matrix (a 2026-11 audit of the engine tier, `lib/fontisan/native.rb` / `lib/fontisan/ffi.rb` option gates). Everything not marked "Ruby only" serves from the selected tier, byte-identical to the Ruby tier (the `parity` workflow proves this per platform):
72
+
73
+ | Operation | native / ffi serve | Ruby only |
74
+ |---|---|---|
75
+ | `read` (metadata/full, lazy) | every format the engine reads, dfont included | Type 1 (PFB/PFA) |
76
+ | `audit`, `audit_dir` (+ `validate`) | engine-readable files and directories | entries the engine cannot read |
77
+ | `scan` | engine-readable files | non-font files |
78
+ | `convert` to ttf/otf/woff/woff2/svg; collections to ttc/otc/woff2 | engine-readable inputs; an `.otc` input carries the caller's source hint (#192 gap 7) | Type 1 conversions; a single font to a collection format |
79
+ | `extract` (collection member) | collections | |
80
+ | `instance` (TTF variable font) | single fonts | |
81
+ | `subset` (web/pdf/minimal) | engine-readable single fonts and collections | |
82
+ | `glyph_ids` | single fonts, dfonts and collections on both tiers | Type 1 |
83
+ | `outline_hashes` | single fonts, dfonts and collections on both tiers | Type 1 |
84
+
85
+ An SVG font as a *source* is not a format fontisan reads at all (there is no `from: svg` conversion), so it is not a tier question.
86
+
87
+ Also always on Ruby, whichever engine is selected — strict mode does not raise for any of these:
72
88
 
73
89
  - The object-based API: `Fontisan::Subset::Builder.new(font, ...)` and `Fontisan::Variable::Instancer`. Only the path-based `Reference.subset` and `Reference.instance` can use another tier.
74
- - Apple dfont files.
75
- - CLI commands other than `convert`, `unpack` and `subset`, and the non-plain `convert` cases listed above.
76
- - Type 1 fonts (PFB/PFA).
90
+ - A FIFO, device or socket as an input path (the engine's released read would block uninterruptibly; Ruby's read is interruptible).
91
+ - CLI commands other than `convert`, `unpack`, `subset` and `instance`, and the non-plain convert cases listed above (several targets, instance coordinates, conversion options, hinting, a font index).
77
92
 
78
93
  ## Platforms
79
94
 
@@ -7,9 +7,13 @@ module Fontisan
7
7
  # classes; the methods are private to the tier.
8
8
  module ByteOps
9
9
  # Convert target codes of the engine (extension and C ABI alike).
10
- TARGET_CODES = { ttf: 0, otf: 1, woff: 2, woff2: 3, ttc: 4, otc: 5 }.freeze
11
- SINGLE_TARGETS = %i[ttf otf woff woff2].freeze
10
+ TARGET_CODES = { ttf: 0, otf: 1, woff: 2, woff2: 3, ttc: 4, otc: 5,
11
+ svg: 6 }.freeze
12
+ SINGLE_TARGETS = %i[ttf otf woff woff2 svg].freeze
12
13
  COLLECTION_TARGETS = %i[ttc otc woff2].freeze
14
+ # The caller's `.ttc`/`.otc` extension decision for a `ttcf` input
15
+ # (#192 gap 7): the engine's bytes carry no path.
16
+ SOURCE_HINT_CODES = { ttc: 1, otc: 2 }.freeze
13
17
  CONVERT_OPTIONS = %i[to output timestamp quiet].freeze
14
18
  SUBSET_PROFILES = %w[web pdf minimal].freeze
15
19
  MAX_CODEPOINT = 0x10FFFF
@@ -75,14 +79,18 @@ module Fontisan
75
79
  false
76
80
  end
77
81
 
78
- # `.otc` decision (card 2f): Ruby picks a collection's source type from
79
- # the input path's extension (`.otc` vs anything else), and the engine
80
- # only sees bytes and assumes `.ttc`. No hint is passed: `.otc`
81
- # inputs stay on the Ruby tier.
82
+ # `.otc` decision (card 2f, served since #192 gap 7): Ruby picks a
83
+ # collection's source type from the input path's extension (`.otc` vs
84
+ # anything else); the hint rides the op prefix.
82
85
  def otc_hint?(path)
83
86
  File.extname(path).casecmp?(".otc")
84
87
  end
85
88
 
89
+ # The wire value of the source hint for +path+.
90
+ def source_hint(path)
91
+ otc_hint?(path) ? SOURCE_HINT_CODES.fetch(:otc) : SOURCE_HINT_CODES.fetch(:ttc)
92
+ end
93
+
86
94
  # Single target `to:` (no multi-format), a format pair the engine
87
95
  # serves, no `coordinates:` / `preserve_hints` / compression knobs.
88
96
  def convert_options?(options, path)
@@ -92,7 +100,6 @@ module Fontisan
92
100
 
93
101
  target = convert_target(options[:to]) or return false
94
102
  return false unless path.is_a?(String)
95
- return false if otc_hint?(path)
96
103
 
97
104
  (collection_file?(path) ? COLLECTION_TARGETS : SINGLE_TARGETS).include?(target)
98
105
  end
@@ -115,14 +122,14 @@ module Fontisan
115
122
 
116
123
  def instance_options?(options, path)
117
124
  return false unless options.keys.all? { |key| %i[coords timestamp].include?(key) }
118
- return false unless options[:coords].is_a?(Hash) && !path.nil? && !collection_file?(path)
125
+ return false unless options[:coords].is_a?(Hash) && !path.nil?
119
126
 
120
127
  options[:coords].all? { |tag, value| tag.to_s.bytesize == 4 && numeric?(value) }
121
128
  end
122
129
 
123
130
  def subset_options?(options, path)
124
131
  return false unless options.keys.all? { |key| %i[unicodes text profile timestamp].include?(key) }
125
- return false if path.nil? || collection_file?(path)
132
+ return false if path.nil?
126
133
  return false unless SUBSET_PROFILES.include?(options.fetch(:profile, "web"))
127
134
 
128
135
  text = options[:text]
@@ -131,6 +138,31 @@ module Fontisan
131
138
  Array(options[:unicodes]).all? { |cp| cp.is_a?(Integer) && cp.between?(0, MAX_CODEPOINT) }
132
139
  end
133
140
 
141
+ # One Integer face index on an engine-readable single font or
142
+ # collection; Type 1 files stay with the Ruby tier.
143
+ def outline_hashes_options?(options, path)
144
+ return false unless options.keys.sort == %i[index]
145
+ return false unless options[:index].is_a?(Integer) && options[:index].between?(0, MAX_FONT_INDEX)
146
+ return false unless path.is_a?(String)
147
+
148
+ format = FontLoader.detect_format(path)
149
+ !format.nil? && !%i[pfa pfb].include?(format)
150
+ rescue StandardError
151
+ false
152
+ end
153
+
154
+ # Codepoints and/or text on any engine-readable input; collections
155
+ # included (the engine runs face 0, as Ruby's loader does).
156
+ def glyph_ids_options?(options, path)
157
+ return false unless options.keys.all? { |key| %i[unicodes text].include?(key) }
158
+ return false if path.nil?
159
+
160
+ text = options[:text]
161
+ return false unless text.nil? || text.is_a?(String)
162
+
163
+ Array(options[:unicodes]).all? { |cp| cp.is_a?(Integer) && cp.between?(0, MAX_CODEPOINT) }
164
+ end
165
+
134
166
  def numeric?(value)
135
167
  Float(value)
136
168
  true
@@ -179,7 +211,13 @@ module Fontisan
179
211
  def convert_formats(path, target)
180
212
  return { source_format: single_format(path), target_format: target } unless collection_file?(path)
181
213
 
182
- source = File.binread(path, 4) == "wOF2" ? :woff2_collection : :ttc
214
+ source = if File.binread(path, 4) == "wOF2"
215
+ :woff2_collection
216
+ else
217
+ # Ruby's detect_collection_type: the extension decides
218
+ # `.otc` vs `.ttc` (gap 7's decision, now reported too).
219
+ otc_hint?(path) ? :otc : :ttc
220
+ end
183
221
  { source_format: source, target_format: target == :woff2 ? :woff2_collection : target }
184
222
  end
185
223
 
@@ -6,10 +6,10 @@ module Fontisan
6
6
  # FONTISAN_ENGINE=ruby|native|ffi|auto (default auto)
7
7
  # FONTISAN_ENGINE_STRICT=1 (no fallback)
8
8
  #
9
- # `auto` resolves to the Ruby tier until the phase-3 gates pass
10
- # (fontisan#160); only an explicit native or ffi selection uses the Rust
11
- # tiers. The post-gate order (native, ffi, ruby) is
12
- # {NATIVE_PREFERRED_ORDER}. A forced tier that is unavailable
9
+ # `auto` resolves to the phase-3 order (fontisan#160, flipped): the Rust
10
+ # native tier when this gem carries it, then the FFI tier, then Ruby —
11
+ # the Ruby tier is the floor, so platforms without the extension keep
12
+ # working. A forced tier that is unavailable
13
13
  # falls back to Ruby silently, or raises {TierUnavailable} at setup when
14
14
  # strict. An operation (or a path, e.g. dfont) a tier cannot serve always goes to
15
15
  # Ruby, strict or not. FONTISAN_MODE and FONTISAN_LAZY are not read here.
@@ -29,11 +29,9 @@ module Fontisan
29
29
  SELECTIONS = %w[ruby native ffi auto].freeze
30
30
  STRICT_ON = %w[1 true yes on].freeze
31
31
  STRICT_OFF = ["", "0", "false", "no", "off"].freeze
32
- # The order `auto` will use once the phase-3 gates pass (fontisan#160).
33
- # Until then `auto` resolves to ruby only; the 2d flip is replacing
34
- # AUTO_ORDER with this constant.
35
- NATIVE_PREFERRED_ORDER = %i[native ffi ruby].freeze
36
- AUTO_ORDER = %i[ruby].freeze
32
+ # The order `auto` resolves (fontisan#160, phase-3 gates passed): the
33
+ # Rust native tier first, the FFI tier second, Ruby as the floor.
34
+ AUTO_ORDER = %i[native ffi ruby].freeze
37
35
  OPS = %i[read outline_hashes audit audit_dir scan convert extract
38
36
  instance glyph_ids subset].freeze
39
37
  REPLACEABLE_TIERS = %i[native ffi].freeze
@@ -4,12 +4,12 @@ require "ffi"
4
4
 
5
5
  module Fontisan
6
6
  module Ffi
7
- # One loaded copy of the cdylib: the C structs of fontisan.h (ABI 1) and
7
+ # One loaded copy of the cdylib: the C structs of fontisan.h (ABI 2) and
8
8
  # the three exported functions. Only this file requires the optional `ffi`
9
9
  # gem, and only {Fontisan::Ffi} requires this file.
10
10
  class Client
11
11
  MAGIC = 0x4E415346 # "FSAN"
12
- ABI_VERSION = 1
12
+ ABI_VERSION = 3
13
13
 
14
14
  OK = 0
15
15
  INVALID_ARG = 7
data/lib/fontisan/ffi.rb CHANGED
@@ -7,15 +7,18 @@ require "rbconfig"
7
7
  require "fontisan/ffi_platform"
8
8
 
9
9
  module Fontisan
10
- # The `:ffi` engine tier: the Rust engine's C ABI (fontisan.h, version 1)
10
+ # The `:ffi` engine tier: the Rust engine's C ABI (fontisan.h, version 2)
11
11
  # loaded through the optional `ffi` gem. It serves the read-side
12
12
  # {Fontisan::Reference} operations (read, audit, audit_dir, scan) and the
13
13
  # byte operations (convert, extract, instance, subset: card 2f-ffi, the same
14
14
  # routing rules as {Fontisan::Native} through {Fontisan::ByteOps}); every
15
15
  # other operation, and dfont / Type 1 files, are the Ruby tier's.
16
16
  #
17
- # The C ABI has no glyph-id operation: a subset's glyph ids come from the
18
- # Ruby facade's `glyph_ids` (a pure cmap read, run on the Ruby tier).
17
+ # `glyph_ids` is the one operation the tiers split on: the native tier
18
+ # serves it through magnus, this tier through the ABI's OP_GLYPH_IDS
19
+ # (#192 gap 1). A subset's glyph ids still come from the Ruby facade's
20
+ # `glyph_ids` — the engine reads WOFF2 natively, so only a WOFF2 source
21
+ # on a platform without the `brotli` gem takes the decode detour.
19
22
  #
20
23
  # The `ffi` gem and the shared library are loaded lazily, on the first probe.
21
24
  # A missing gem, missing or unloadable library, missing symbol or ABI
@@ -32,8 +35,10 @@ module Fontisan
32
35
  class AbiMismatch < Fontisan::Error; end
33
36
 
34
37
  LIBRARY = "fontisan_cdylib"
35
- OPERATIONS = %i[read audit audit_dir scan convert extract instance subset].freeze
36
- RUBY_ONLY_FORMATS = %i[dfont pfa pfb].freeze
38
+ OPERATIONS = %i[read audit audit_dir scan convert extract instance subset
39
+ glyph_ids outline_hashes].freeze
40
+ # dfont is served since #192 gap 5; Type 1 stays Ruby until gap 4.
41
+ RUBY_ONLY_FORMATS = %i[pfa pfb].freeze
37
42
 
38
43
  OP_CONVERT = 1
39
44
  OP_EXTRACT = 2
@@ -43,6 +48,8 @@ module Fontisan
43
48
  OP_AUDIT = 9
44
49
  OP_SCAN = 10
45
50
  OP_AUDIT_DIR = 11
51
+ OP_GLYPH_IDS = 12
52
+ OP_OUTLINE_HASHES = 4
46
53
  FLAG_METADATA = 1
47
54
  FLAG_LAZY = 2
48
55
  FLAG_VALIDATE = 1
@@ -88,6 +95,8 @@ module Fontisan
88
95
 
89
96
  return operation != :instance || fixed_coordinates?(options[:coords])
90
97
  end
98
+ return glyph_ids_options?(options, path) if operation == :glyph_ids
99
+ return outline_hashes_options?(options, path) if operation == :outline_hashes
91
100
 
92
101
  OPERATIONS.include?(operation)
93
102
  end
@@ -156,14 +165,15 @@ module Fontisan
156
165
  target = convert_target(options.fetch(:to))
157
166
  output = convert_output(path, output, target)
158
167
  stamp = timestamp ? unix_seconds(timestamp) : Time.now.to_i
159
- prefix = [ByteOps::TARGET_CODES.fetch(target), 0, stamp].pack("NNq>")
168
+ prefix = [ByteOps::TARGET_CODES.fetch(target), source_hint(path), stamp].pack("NNq>")
160
169
  bytes = byte_op(OP_CONVERT, prefix + File.binread(path))
161
170
  finish_convert(path, target, File.path(output), bytes)
162
171
  end
163
172
 
164
173
  # Same file layout as UnpackCommand: <output_dir>/<basename>.
165
174
  def serve_extract(path, index:, output_dir:)
166
- payload = byte_op(OP_EXTRACT, [index, 0, 0, 0].pack("NNNN") + unpacking_io { File.binread(File.path(path)) })
175
+ payload = byte_op(OP_EXTRACT, [index, source_hint(path), 0, 0].pack("NNNN") +
176
+ unpacking_io { File.binread(File.path(path)) })
167
177
  length = payload.unpack1("N")
168
178
  name = payload.byteslice(4, length).force_encoding(Encoding::UTF_8)
169
179
  unpacking_io do
@@ -186,6 +196,28 @@ module Fontisan
186
196
  byte_op(OP_SUBSET, head + gids.pack("N*") + File.binread(path))
187
197
  end
188
198
 
199
+ # The standalone glyph-id lookup (ABI 2, OP_GLYPH_IDS): the engine reads
200
+ # the cmap, so a WOFF2 source needs no `brotli` here, unlike subset's
201
+ # own gid computation which still goes through the Ruby facade.
202
+ def serve_glyph_ids(path, unicodes: nil, text: nil)
203
+ path = File.path(path)
204
+ codepoints = Array(unicodes).map(&:to_i) + text.to_s.codepoints
205
+ name = File.basename(path)
206
+ input = [name.bytesize].pack("N") + name.b +
207
+ [codepoints.size].pack("N") + codepoints.pack("N*") +
208
+ File.binread(path)
209
+ byte_op(OP_GLYPH_IDS, input).unpack("N*")
210
+ end
211
+
212
+ # The facade's outline_hashes (ABI 3, OP_OUTLINE_HASHES): the engine's
213
+ # canonical JSON row with string keys (#192 gap 2).
214
+ def serve_outline_hashes(path, index: 0)
215
+ require "json"
216
+ path = File.path(path)
217
+ input = [index, 0, 0, 0].pack("NNNN") + File.binread(path)
218
+ JSON.parse(byte_op(OP_OUTLINE_HASHES, input))
219
+ end
220
+
189
221
  # Glyph ids of a subset request. A WOFF2 source on a platform without the
190
222
  # `brotli` gem (the java gem on JRuby) cannot be read by the Ruby tier, so
191
223
  # the engine decodes it (a convert to the same flavor) and the Ruby tier
@@ -20,19 +20,20 @@ module Fontisan
20
20
  # Cross-compiled platform gems ship one build per Ruby minor, in a
21
21
  # directory named for it (rake-compiler's fat-binary layout).
22
22
  VERSIONED_EXTENSION = "fontisan/native/#{RUBY_VERSION[/\A\d+\.\d+/]}/fontisan_native".freeze
23
- ABI_VERSION = 1
23
+ ABI_VERSION = 2
24
24
 
25
25
  # The fontisan-rs commit both binaries must be built from: the `rev` of the
26
26
  # engine pin in ext/*/Cargo.toml, which each build embeds. ABI_VERSION does
27
27
  # not move on a repin, so this is what keeps a stale binary from serving old
28
28
  # behaviour. A repin seds it with the Cargo files (repin-push162.sh).
29
- ENGINE_REV = "f45057a12e15ba9f2c02526cd8ca0603c80edaf9"
29
+ ENGINE_REV = "8de6ac6bc838d2bf796a032c76cee78fe32ec671"
30
30
 
31
31
  # Operations served natively. Convert, extract, instance and subset are
32
32
  # path-based only (card 2f): the object-based entry points
33
33
  # (`Subset::Builder.new(font, ...)`, `Variable::Instancer.new(font)`) are
34
34
  # not Reference operations, so they never reach a gate and stay on Ruby.
35
- OPERATIONS = %i[read audit audit_dir scan convert extract instance subset].freeze
35
+ OPERATIONS = %i[read audit audit_dir scan convert extract instance subset
36
+ glyph_ids outline_hashes].freeze
36
37
 
37
38
  # Raised by the extension for an engine failure; `details` is
38
39
  # `[class name, message, [[cause class, cause message], ...], error kind]`;
@@ -85,6 +86,8 @@ module Fontisan
85
86
  case operation
86
87
  when :read then read_options?(options)
87
88
  when *ByteOps::BYTE_OPERATIONS then byte_options?(operation, options, path)
89
+ when :glyph_ids then glyph_ids_options?(options, path)
90
+ when :outline_hashes then outline_hashes_options?(options, path)
88
91
  when :audit, :audit_dir then options.keys.all?(:validate) && [true, false, nil].include?(options[:validate])
89
92
  when :scan then options.empty?
90
93
  else false
@@ -101,6 +104,8 @@ module Fontisan
101
104
  when :extract then extract(*, **)
102
105
  when :instance then instance(*, **)
103
106
  when :subset then subset(*, **)
107
+ when :glyph_ids then glyph_ids(*, **)
108
+ when :outline_hashes then outline_hashes(*, **)
104
109
  else raise Fontisan::Error, "native tier cannot serve #{operation}"
105
110
  end
106
111
  rescue Failure => e
@@ -160,13 +165,14 @@ module Fontisan
160
165
  path = File.path(path)
161
166
  target = convert_target(options.fetch(:to))
162
167
  output = convert_output(path, output, target)
163
- bytes = native_convert(path, ByteOps::TARGET_CODES.fetch(target), timestamp ? unix_seconds(timestamp) : Time.now.to_i)
168
+ bytes = native_convert(path, ByteOps::TARGET_CODES.fetch(target), source_hint(path),
169
+ timestamp ? unix_seconds(timestamp) : Time.now.to_i)
164
170
  finish_convert(path, target, File.path(output), bytes)
165
171
  end
166
172
 
167
173
  # Same file layout as UnpackCommand: <output_dir>/<basename>.
168
174
  def extract(path, index:, output_dir:)
169
- name, bytes = native_extract(File.path(path), index)
175
+ name, bytes = native_extract(File.path(path), index, source_hint(path))
170
176
  unpacking_io do
171
177
  FileUtils.mkdir_p(output_dir)
172
178
  File.join(output_dir, name).tap { |out| File.binwrite(out, bytes) }
@@ -187,6 +193,21 @@ module Fontisan
187
193
  native_subset(path, gids, profile.to_s)
188
194
  end
189
195
 
196
+ # Sorted, unique glyph ids, the same lookup the subset path uses.
197
+ def glyph_ids(path, unicodes: nil, text: nil)
198
+ path = File.path(path)
199
+ codepoints = Array(unicodes).map(&:to_i) + text.to_s.codepoints
200
+ native_glyph_ids(path, codepoints, File.basename(path))
201
+ end
202
+
203
+ # The facade's outline_hashes row, rendered by the engine as canonical
204
+ # JSON with string keys (#192 gap 2).
205
+ def outline_hashes(path, index: 0)
206
+ require "json"
207
+ path = File.path(path)
208
+ JSON.parse(native_outline_hashes(path, index))
209
+ end
210
+
190
211
  def read(path, mode: :metadata, lazy: true)
191
212
  native_read(File.path(path), mode == :metadata, lazy)
192
213
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fontisan
4
- VERSION = "0.4.50"
4
+ VERSION = "0.4.51"
5
5
  end
@@ -218,6 +218,21 @@ module MalformedGoldens
218
218
  end
219
219
  end
220
220
 
221
+ # First few leaf paths that differ, so a failure names what changed.
222
+ def leaf_diffs(want, got)
223
+ flat = lambda do |node, path = "", out = {}|
224
+ case node
225
+ when Hash then node.each { |k, v| flat.call(v, "#{path}/#{k}", out) }
226
+ else out[path] = node
227
+ end
228
+ out
229
+ end
230
+ a = flat.call(want)
231
+ b = flat.call(got)
232
+ (a.keys | b.keys).reject { |k| a[k] == b[k] }.first(4)
233
+ .map { |k| "#{k}: #{a[k].inspect} -> #{b[k].inspect}" }.join("; ")
234
+ end
235
+
221
236
  # @return [Array<String>] problems; empty when the committed goldens match
222
237
  def verify(dir: DERIVED_DIR)
223
238
  problems = []
@@ -228,8 +243,12 @@ module MalformedGoldens
228
243
  next
229
244
  end
230
245
  actual = render(e, dir: dir)
231
- same = File.read(gp) == actual || matches?(JSON.parse(File.read(gp)), JSON.parse(actual))
232
- problems << "#{e['id']}: golden differs from current behaviour" unless same
246
+ golden = File.read(gp)
247
+ same = golden == actual || matches?(JSON.parse(golden), JSON.parse(actual))
248
+ unless same
249
+ detail = leaf_diffs(JSON.parse(golden), JSON.parse(actual))
250
+ problems << "#{e['id']}: golden differs from current behaviour (#{detail})"
251
+ end
233
252
  end
234
253
  extra = Dir[File.join(GOLDEN_DIR, "*.json")].map { |f| File.basename(f, ".json") } - entries.map { |e| e["id"] }
235
254
  problems.concat(extra.map { |x| "#{x}: golden has no manifest entry" })
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ground truth for the dfont conversion surfaces (#192 gap 5): what the Ruby
4
+ # tier raises for each convert target on a dfont source.
5
+ require "fontisan"
6
+
7
+ path = "../fontisan-rs/.corpus/fontisan/corpus/fonts/TestDFONT.dfont"
8
+
9
+ def try_convert(path, target, out)
10
+ Fontisan::Reference.convert(path, to: target, output: out)
11
+ size = File.size(out)
12
+ if target == :dfont
13
+ same = File.binread(out) == File.binread(path)
14
+ puts "dfont->#{target}: #{size} bytes, byte-identical to input: #{same}"
15
+ else
16
+ puts "dfont->#{target}: ok, #{size} bytes"
17
+ end
18
+ rescue StandardError => e
19
+ puts "dfont->#{target} raise #{e.class}: #{e.message[0, 90]}"
20
+ end
21
+
22
+ try_convert(path, :dfont, "/tmp/dfont-out.dfont")
23
+ try_convert(path, :ttc, "/tmp/dfont-out.ttc")
24
+ try_convert(path, :otc, "/tmp/dfont-out.otc")
25
+ try_convert(path, :woff2, "/tmp/dfont-out.woff2")
26
+ try_convert(path, :ttf, "/tmp/dfont-out.ttf")
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "fontisan"
5
+
6
+ path = ARGV[0] || File.expand_path("../../fontisan-rs/.corpus/fontisan/corpus/fonts/SourceSans3-Regular.otf.woff2", __dir__)
7
+ options = { text: "AB a." }
8
+
9
+ def show(label)
10
+ result = yield
11
+ puts "#{label}: #{result.inspect}"
12
+ rescue StandardError, ScriptError => e
13
+ puts "#{label}: RAISE #{e.class}: #{e.message.to_s[0, 120]}"
14
+ end
15
+
16
+ show("Ffi.available?") { Fontisan::Ffi.available? }
17
+ show("ops include glyph_ids") { Fontisan::Ffi::OPERATIONS.include?(:glyph_ids) }
18
+ show("BYTE_OPERATIONS") { Fontisan::ByteOps::BYTE_OPERATIONS.inspect }
19
+ show("path") { path }
20
+ show("File.file?") { File.file?(path) }
21
+ show("detect_format") { Fontisan::FontLoader.detect_format(path) }
22
+ show("head") { File.binread(path, 8).unpack1("A8") }
23
+ show("Ffi.supports?(2arg)") { Fontisan::Ffi.supports?(:glyph_ids, path) }
24
+ show("Ffi.supports?(read)") { Fontisan::Ffi.supports?(:read, path) }
25
+ show("Ffi.supports?(glyph_ids, nil path)") { Fontisan::Ffi.supports?(:glyph_ids, nil) }
26
+ show("Ffi.supports?(glyph_ids, ttf path)") do
27
+ ttf = File.expand_path("../../fontisan-rs/.corpus/fontisan/corpus/fonts/NotoSans-Regular.ttf", __dir__)
28
+ Fontisan::Ffi.supports?(:glyph_ids, ttf)
29
+ end
30
+ show("arity") { Fontisan::Ffi.method(:supports_options?).arity }
31
+ show("Ffi.supports_options?(direct)") { Fontisan::Ffi.supports_options?(:glyph_ids, options, path) }
32
+ show("Engine.available?(:ffi)") { Fontisan::Engine.available?(:ffi) }
33
+ show("Engine.resolve(auto)") do
34
+ ENV.delete("FONTISAN_ENGINE")
35
+ Fontisan::Engine.reset!
36
+ Fontisan::Engine.resolve(:glyph_ids, path, options)
37
+ end
38
+ show("Engine.resolve(forced ffi)") do
39
+ ENV["FONTISAN_ENGINE"] = "ffi"
40
+ Fontisan::Engine.reset!
41
+ v = Fontisan::Engine.resolve(:glyph_ids, path, options)
42
+ ENV.delete("FONTISAN_ENGINE")
43
+ Fontisan::Engine.reset!
44
+ v
45
+ end
46
+ show("Reference.glyph_ids outcome") do
47
+ ENV["FONTISAN_ENGINE"] = "ffi"
48
+ Fontisan::Engine.reset!
49
+ v = begin
50
+ Fontisan::Reference.glyph_ids(path, text: "AB a.")
51
+ :ok
52
+ rescue StandardError => e
53
+ "#{e.class}: #{e.message[0, 80]}"
54
+ end
55
+ ENV.delete("FONTISAN_ENGINE")
56
+ Fontisan::Engine.reset!
57
+ v
58
+ end
59
+ show("served_by") { Fontisan::Engine.served_by(:glyph_ids) }
@@ -15,7 +15,7 @@
15
15
  # native_abi_mismatch, another ABI: the tier probes unavailable, nothing
16
16
  # ffi_missing_symbol, raises (no NameError) and ruby serves golden rows
17
17
  # ffi_abi_mismatch
18
- # mixed dfont and Type 1 rows are served by ruby, the
18
+ # mixed Type 1 rows are served by ruby, the
19
19
  # rest by the forced tier
20
20
  # auto_all, auto_no_native, `auto` resolves to the first Engine::AUTO_ORDER tier
21
21
  # auto_none still present (ruby until the #160 gates flip it)
@@ -117,7 +117,7 @@ end
117
117
 
118
118
  # --- checks ---------------------------------------------------------------
119
119
 
120
- HANDED_TO_RUBY = %w[.dfont .pfa .pfb].freeze
120
+ HANDED_TO_RUBY = %w[.pfa .pfb].freeze # dfont is served since #192 gap 5
121
121
  manifest = JSON.parse(File.read(File.join(root, "manifest.json"))).fetch("fonts")
122
122
  entries = manifest.select { |f| f["tier"] == "ci" }.sort_by { |f| f["id"] }
123
123
  problems = []
@@ -184,18 +184,20 @@ begin
184
184
  tiers.each do |tier|
185
185
  ENV["FONTISAN_ENGINE"] = tier
186
186
  Fontisan::Engine.reset!
187
- # dfont and PFB must be ruby's. Ruby's detect_format does not recognise a
188
- # PFA (nil), so the tier may take it; its error row equals the golden either way.
189
- # Anything detect_format cannot name (empty or garbage bytes) is Ruby's too.
187
+ # PFB must be ruby's; dfont is served since #192 gap 5. Ruby's
188
+ # detect_format does not recognise a PFA (nil), so the tier may take it;
189
+ # its error row equals the golden either way. Anything detect_format
190
+ # cannot name (empty or garbage bytes) is Ruby's too.
190
191
  scan_corpus.call(lambda { |path|
191
192
  case File.extname(path).downcase
192
- when ".dfont", ".pfb" then ["ruby"]
193
+ when ".pfb" then ["ruby"]
193
194
  when ".pfa" then ["ruby", tier]
194
195
  else Fontisan::FontLoader.detect_format(path).nil? ? ["ruby"] : [tier]
195
196
  end
196
197
  })
197
198
  end
198
- # dfont and Type 1 in one audit_dir: ruby serves those entries, the tier the rest.
199
+ # Type 1 in one audit_dir with a dfont: ruby serves the PFB entry, the
200
+ # tier the rest (dfont included, #192 gap 5).
199
201
  Dir.mktmpdir("fontisan-mixed") do |dir|
200
202
  %w[fonttools-test-ttf fonttools-test-dfont fonttools-test-t1-pfb].each do |id|
201
203
  entry = entries.find { |e| e["id"] == id }
@@ -205,7 +207,7 @@ begin
205
207
  ENV["FONTISAN_ENGINE"] = tier
206
208
  Fontisan::Engine.reset!
207
209
  by_file = Fontisan::Engine.audit_dir(dir).to_h { |e| [e["path"], e["served_by"]] }
208
- want = { "TestTTF.ttf" => tier, "TestDFONT.dfont" => "ruby", "TestT1-Regular.pfb" => "ruby" }
210
+ want = { "TestTTF.ttf" => tier, "TestDFONT.dfont" => tier, "TestT1-Regular.pfb" => "ruby" }
209
211
  problems << "#{tier} audit_dir served #{by_file.inspect}, expected #{want.inspect}" unless by_file == want
210
212
  end
211
213
  end
@@ -216,7 +218,14 @@ begin
216
218
  present = { "auto_all" => tiers, "auto_no_native" => tiers - ["native"], "auto_none" => [] }.fetch(scenario)
217
219
  want = Fontisan::Engine::AUTO_ORDER.map(&:to_s).find { |t| t == "ruby" || present.include?(t) }
218
220
  problems << "auto resolved #{resolved.call}, expected #{want}" unless resolved.call == want
219
- served = scan_corpus.call(->(path) { [want, *("ruby" if HANDED_TO_RUBY.include?(File.extname(path).downcase))] })
221
+ # The allowed set per row mirrors scripts/tier_smoke.rb: handed extensions
222
+ # AND detect_format-nil files (the malformed corpus) always serve via Ruby,
223
+ # whatever tier auto picks — post-flip `want` can be native/ffi, which
224
+ # previously masked these rows.
225
+ served = scan_corpus.call(lambda { |path|
226
+ handed = HANDED_TO_RUBY.include?(File.extname(path).downcase) || Fontisan::FontLoader.detect_format(path).nil?
227
+ [want, *("ruby" if handed)]
228
+ })
220
229
  problems << "no #{want} row served" if served[want].zero?
221
230
  end
222
231
  rescue StandardError => e # NameError included: a fallback must never raise it
@@ -7,11 +7,12 @@
7
7
  # Run it against an INSTALLED fontisan gem (never the checkout's lib/). It scans
8
8
  # every `ci`-tier corpus font through Fontisan::Engine with FONTISAN_ENGINE=EXPECTED_TIER (strict off),
9
9
  # then checks that
10
- # * auto resolves to the first tier of Engine::AUTO_ORDER this gem has (ruby until the
11
- # phase-3 gates flip it, fontist/fontisan#160);
10
+ # * auto resolves to the first tier of Engine::AUTO_ORDER this gem has (the
11
+ # phase-3 order native, ffi, ruby; #160),
12
12
  # * every row equals the committed scan golden (minus the served_by key);
13
13
  # * served_by is EXPECTED_TIER, except for files the engine hands to Ruby
14
- # (dfont, Type 1), which may say ruby; with EXPECTED_TIER=ruby nothing else.
14
+ # (Type 1; dfont is served natively since #192 gap 5), which may say ruby;
15
+ # with EXPECTED_TIER=ruby nothing else.
15
16
  # Exit status 0 only when all hold.
16
17
  require "json"
17
18
 
@@ -27,7 +28,7 @@ Fontisan::Reference # autoloading it installs the engine gates
27
28
  lib_dir = Gem.loaded_specs.fetch("fontisan").full_gem_path
28
29
  abort "smoke must run an installed gem, loaded #{lib_dir}" unless File.basename(File.dirname(lib_dir)) == "gems"
29
30
 
30
- HANDED_TO_RUBY = %w[.dfont .pfa .pfb].freeze
31
+ HANDED_TO_RUBY = %w[.pfa .pfb].freeze # dfont is served since #192 gap 5
31
32
 
32
33
  manifest = JSON.parse(File.read(File.join(root, "manifest.json"))).fetch("fonts")
33
34
  entries = manifest.select { |f| f["tier"] == "ci" }.sort_by { |f| f["id"] }
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Cross-tier validation for the gap campaign (#192 gaps 7/2/3/5): every new
4
+ # engine capability under native and ffi must equal the Ruby tier's outcome.
5
+ require "fontisan"
6
+ require "json"
7
+ require "fileutils"
8
+
9
+ FONT = "../fontisan-rs/.corpus/fontisan/corpus/fonts"
10
+ OTC = "/tmp/validation-src.otc"
11
+
12
+ failures = []
13
+
14
+ def outcome(tier, operation, path, **)
15
+ ENV["FONTISAN_ENGINE"] = tier
16
+ Fontisan::Engine.reset!
17
+ result = Fontisan::Reference.public_send(operation, path, **)
18
+ result.is_a?(String) ? result.bytes : result
19
+ rescue StandardError, ScriptError => e
20
+ "#{e.class}: #{e.message}"
21
+ end
22
+
23
+ def served(tier, operation, path, **)
24
+ ENV["FONTISAN_ENGINE"] = tier
25
+ Fontisan::Engine.reset!
26
+ begin
27
+ Fontisan::Reference.public_send(operation, path, **)
28
+ rescue StandardError
29
+ nil
30
+ end
31
+ Fontisan::Engine.served_by(operation).to_s
32
+ end
33
+
34
+ files = Dir.glob("#{FONT}/*").select { |f| File.file?(f) }
35
+ # A .otc copy of a ttc exercises the source hint.
36
+ FileUtils.cp("#{FONT}/TestTTC.ttc", OTC)
37
+
38
+ checks = lambda do |tier|
39
+ files.each do |path|
40
+ rel = File.basename(path)
41
+
42
+ # outline_hashes: outcome parity + served tier.
43
+ ruby = outcome("ruby", :outline_hashes, path, index: 0)
44
+ got = outcome(tier, :outline_hashes, path, index: 0)
45
+ failures << "#{tier} outline_hashes #{rel}: #{got.inspect[0, 80]} != #{ruby.inspect[0, 80]}" if got != ruby
46
+ next unless File.basename(path) == "TestTTF.ttf"
47
+
48
+ served_tier = served(tier, :outline_hashes, path, index: 0)
49
+ failures << "#{tier} outline_hashes served_by #{served_tier}" unless served_tier == tier
50
+
51
+ # glyph_ids: outcome parity.
52
+ ruby = outcome("ruby", :glyph_ids, path, text: "AB a.")
53
+ got = outcome(tier, :glyph_ids, path, text: "AB a.")
54
+ failures << "#{tier} glyph_ids #{rel}: #{got.inspect[0, 60]} != #{ruby.inspect[0, 60]}" if got != ruby
55
+ end
56
+
57
+ # dfont read parity (full doc).
58
+ ruby = outcome("ruby", :read, "#{FONT}/TestDFONT.dfont")
59
+ got = outcome(tier, :read, "#{FONT}/TestDFONT.dfont")
60
+ failures << "#{tier} dfont read mismatch" if got != ruby
61
+
62
+ # convert → svg: byte parity against the Ruby tier (small font for speed).
63
+ ruby = outcome("ruby", :convert, "#{FONT}/TestTTF.ttf", to: :svg,
64
+ output: "/tmp/v-ruby.svg")
65
+ got = outcome(tier, :convert, "#{FONT}/TestTTF.ttf", to: :svg,
66
+ output: "/tmp/v-#{tier}.svg")
67
+ same = ruby.is_a?(Hash) && ruby[:success] && got.is_a?(Hash) && got[:success] &&
68
+ File.binread("/tmp/v-ruby.svg") == File.binread("/tmp/v-#{tier}.svg")
69
+ failures << "#{tier} convert svg differs" unless same
70
+
71
+ # convert .otc → :otc (same-type copy) vs Ruby.
72
+ ruby = outcome("ruby", :convert, OTC, to: :otc, output: "/tmp/v-ruby.otc")
73
+ got = outcome(tier, :convert, OTC, to: :otc, output: "/tmp/v-#{tier}.otc")
74
+ same = ruby.is_a?(Hash) && ruby[:success] && got.is_a?(Hash) && got[:success] &&
75
+ File.binread("/tmp/v-ruby.otc") == File.binread("/tmp/v-#{tier}.otc")
76
+ failures << "#{tier} convert .otc→otc differs: #{ruby.inspect[0, 60]} vs #{got.inspect[0, 60]}" unless same
77
+
78
+ # extract from a .otc names members .otf.
79
+ served(tier, :extract, OTC, index: 0, output_dir: "/tmp/v-extract-#{tier}")
80
+ name = Dir["/tmp/v-extract-#{tier}/*"].map { |f| File.basename(f) }.first.to_s
81
+ failures << "#{tier} extract .otc basename #{name.inspect} (want .otf)" unless name.end_with?(".otf")
82
+
83
+ # Collections through the face-0 ops: glyph_ids, subset (bytes), instance
84
+ # (bytes) must equal the Ruby tier's.
85
+ %w[TestTTC.ttc TestWOFF2.woff2].each do |collection|
86
+ path = "#{FONT}/#{collection}"
87
+ next unless File.file?(path)
88
+
89
+ ruby = outcome("ruby", :glyph_ids, path, text: "AB a.")
90
+ got = outcome(tier, :glyph_ids, path, text: "AB a.")
91
+ failures << "#{tier} glyph_ids #{collection}: #{got.inspect[0, 50]} vs #{ruby.inspect[0, 50]}" if ruby != got
92
+
93
+ ruby = outcome("ruby", :subset, path, text: "AB", profile: "web")
94
+ got = outcome(tier, :subset, path, text: "AB", profile: "web")
95
+ same = ruby.is_a?(String) && got.is_a?(String) && ruby == got
96
+ failures << "#{tier} subset #{collection} bytes differ" unless same
97
+
98
+ ruby = outcome("ruby", :instance, path, coords: { "wght" => 500 })
99
+ got = outcome(tier, :instance, path, coords: { "wght" => 500 })
100
+ same = ruby == got
101
+ failures << "#{tier} instance #{collection}: #{got.inspect[0, 60]} vs #{ruby.inspect[0, 60]}" unless same
102
+ end
103
+
104
+ # A dfont through the face-0 ops.
105
+ ruby = outcome("ruby", :subset, "#{FONT}/TestDFONT.dfont", text: "AB", profile: "web")
106
+ got = outcome(tier, :subset, "#{FONT}/TestDFONT.dfont", text: "AB", profile: "web")
107
+ failures << "#{tier} subset dfont: #{got.inspect[0, 60]} vs #{ruby.inspect[0, 60]}" if ruby != got
108
+ end
109
+
110
+ checks.call("native")
111
+ checks.call("ffi")
112
+
113
+ if failures.empty?
114
+ puts "ALL CROSS-TIER CHECKS PASS (native + ffi)"
115
+ else
116
+ puts "FAILURES (#{failures.length}):"
117
+ failures.first(12).each { |f| puts " #{f}" }
118
+ exit 1
119
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontisan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.50
4
+ version: 0.4.51
5
5
  platform: java
6
6
  authors:
7
7
  - Ribose Inc.
@@ -198,12 +198,14 @@ files:
198
198
  - TODO.improvements/README.md
199
199
  - benchmark/baseline.json
200
200
  - benchmark/ci_gate.rb
201
+ - benchmark/collection_benchmark.rb
201
202
  - benchmark/compile_benchmark.rb
202
203
  - benchmark/corpus/harness.rb
203
204
  - benchmark/corpus/ops.rb
204
205
  - benchmark/corpus/run.rb
205
206
  - benchmark/corpus/scan_child.rb
206
207
  - benchmark/corpus/tiers.rb
208
+ - benchmark/fonttools_compare.rb
207
209
  - benchmark/tier_baseline.json
208
210
  - benchmark/variation_quick_bench.rb
209
211
  - docs/.gitignore
@@ -922,9 +924,12 @@ files:
922
924
  - scripts/corpus/generate_goldens.rb
923
925
  - scripts/corpus/generate_malformed_goldens.rb
924
926
  - scripts/corpus/generate_scan_goldens.rb
927
+ - scripts/dfont_ground_truth.rb
925
928
  - scripts/measure_optimization.rb
929
+ - scripts/probe_jruby_glyph_ids.rb
926
930
  - scripts/tier_fallback.rb
927
931
  - scripts/tier_smoke.rb
932
+ - scripts/validate_gap_campaign.rb
928
933
  homepage: https://github.com/fontist/fontisan
929
934
  licenses:
930
935
  - BSD-2-Clause