fontist 3.0.16 → 3.0.17
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 +4 -4
- data/lib/fontist/system_index.rb +62 -24
- data/lib/fontist/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aa8aac3407b7b54563dc14319ade845a761256f0ce2d324ed9a7a1da7dfe9613
|
|
4
|
+
data.tar.gz: 2ec396abab12f551459a0e7455355243c46e0f4359bf2de4f018ebcde46a30e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd1a4460fc10c117bb6d7fc3dcbced001f83c918c64e70621778575e7edce78544a94fbbbbe5e64f22294e5c0525af723043055feae62f3a21fe299020cdda71
|
|
7
|
+
data.tar.gz: 33e5d409a00bd73c39e839a9a9acad2f31aa2dde95697f1ad08ebfc4f0d2aa980cfb8cac95524b8fdc310c1e880546dbf09bb15ebd3060d44a71948821f35db9
|
data/lib/fontist/system_index.rb
CHANGED
|
@@ -100,6 +100,39 @@ module Fontist
|
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
+
# Thread-safe progress display for parallel index scans
|
|
104
|
+
class ScanProgress
|
|
105
|
+
SPINNER_CHARS = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"].freeze
|
|
106
|
+
|
|
107
|
+
def initialize(total, verbose:, &on_step)
|
|
108
|
+
@total = total
|
|
109
|
+
@verbose = verbose
|
|
110
|
+
@on_step = on_step
|
|
111
|
+
@mutex = Mutex.new
|
|
112
|
+
@processed = 0
|
|
113
|
+
# Show minimal progress for large collections even in non-verbose mode
|
|
114
|
+
@minimal = !verbose && total > 100
|
|
115
|
+
@interval = total > 1000 ? 100 : 50
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def step(path)
|
|
119
|
+
@mutex.synchronize do
|
|
120
|
+
@processed += 1
|
|
121
|
+
if @verbose
|
|
122
|
+
@on_step&.call(@processed, path)
|
|
123
|
+
elsif @minimal && report?
|
|
124
|
+
Fontist.ui.say("Scanning fonts: #{@processed}/#{@total}...")
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
private
|
|
130
|
+
|
|
131
|
+
def report?
|
|
132
|
+
(@processed % @interval).zero? || @processed == @total
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
103
136
|
# {:path=>"/Library/Fonts/Arial Unicode.ttf",
|
|
104
137
|
# :full_name=>"Arial Unicode MS",
|
|
105
138
|
# :family_name=>"Arial Unicode MS",
|
|
@@ -518,33 +551,38 @@ stats:)
|
|
|
518
551
|
if verbose
|
|
519
552
|
puts Paint["Using parallel processing with #{num_cores} cores",
|
|
520
553
|
:cyan]
|
|
521
|
-
end
|
|
522
|
-
|
|
523
|
-
# Thread-safe progress tracking
|
|
524
|
-
progress_mutex = Mutex.new
|
|
525
|
-
processed_count = 0
|
|
526
|
-
spinner_chars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
|
527
554
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
555
|
+
# Verbose runs keep threads so live progress and per-font stats
|
|
556
|
+
# stay visible; fontisan parsing is GVL-bound, so this mode is
|
|
557
|
+
# slow, but it is the human-attended path
|
|
558
|
+
process_paths_in_threads(sorted_paths, existing_fonts_by_path,
|
|
559
|
+
verbose: verbose, stats: stats,
|
|
560
|
+
num_workers: num_cores)
|
|
561
|
+
else
|
|
562
|
+
# Measured on 600 system fonts: single thread 2.3s, 8 threads
|
|
563
|
+
# 3.3s (GVL-bound, mutex contention), 8 processes 0.6s. The
|
|
564
|
+
# silent build path therefore forks instead of threading
|
|
565
|
+
results = Parallel.map(sorted_paths, in_processes: num_cores) do |path|
|
|
566
|
+
detect_font_with_cache(path, existing_fonts_by_path[path],
|
|
567
|
+
stats: nil)
|
|
568
|
+
end.flatten.compact
|
|
569
|
+
|
|
570
|
+
stats&.total_fonts = results.size
|
|
571
|
+
results
|
|
572
|
+
end
|
|
573
|
+
end
|
|
531
574
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
processed_count += 1
|
|
539
|
-
if verbose && stats
|
|
540
|
-
display_progress(processed_count, sorted_paths.size, path,
|
|
541
|
-
spinner_chars)
|
|
542
|
-
elsif show_minimal_progress && ((processed_count % progress_interval).zero? || processed_count == sorted_paths.size)
|
|
543
|
-
# Show minimal progress every N fonts or at the end
|
|
544
|
-
Fontist.ui.say("Scanning fonts: #{processed_count}/#{sorted_paths.size}...")
|
|
545
|
-
end
|
|
546
|
-
end
|
|
575
|
+
def process_paths_in_threads(sorted_paths, existing_fonts_by_path,
|
|
576
|
+
verbose:, stats:, num_workers:)
|
|
577
|
+
progress = ScanProgress.new(sorted_paths.size, verbose: verbose) do |count, path|
|
|
578
|
+
display_progress(count, sorted_paths.size, path,
|
|
579
|
+
ScanProgress::SPINNER_CHARS)
|
|
580
|
+
end
|
|
547
581
|
|
|
582
|
+
results = Parallel.map(sorted_paths, in_threads: num_workers) do |path|
|
|
583
|
+
result = detect_font_with_cache(path, existing_fonts_by_path[path],
|
|
584
|
+
stats: stats)
|
|
585
|
+
progress.step(path)
|
|
548
586
|
result
|
|
549
587
|
end.flatten.compact
|
|
550
588
|
|
data/lib/fontist/version.rb
CHANGED