fontist 3.0.41 → 3.0.43
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/.github/workflows/discover-fonts.yml +2 -1
- data/.github/workflows/perf-gate.yml +275 -0
- data/README.adoc +0 -3
- data/lib/fontist/utils/curl_downloader.rb +80 -0
- data/lib/fontist/utils/downloader.rb +19 -6
- data/lib/fontist/utils.rb +1 -0
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +1 -1
- metadata +4 -7
- data/TODO.audit-docs.md +0 -164
- data/TODO.fontist-v5.md +0 -196
- data/TODO.improve-docs.md +0 -114
- data/TODO.upgrade-excavate.md +0 -107
- data/google-fonts-multi-format-usage.md +0 -419
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
# Google Fonts Multi-Format API Usage Guide
|
|
2
|
-
|
|
3
|
-
This guide explains how to use the new multi-format Google Fonts API integration in Fontist, which provides access to TTF, Variable Fonts (VF), and WOFF2 formats.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The Google Fonts API integration now fetches data from three endpoints and merges them into a unified database:
|
|
8
|
-
|
|
9
|
-
1. **TTF Endpoint** - Standard TrueType fonts
|
|
10
|
-
2. **VF Endpoint** - Variable fonts with axes information
|
|
11
|
-
3. **WOFF2 Endpoint** - WOFF2 format files
|
|
12
|
-
|
|
13
|
-
## Quick Start
|
|
14
|
-
|
|
15
|
-
```ruby
|
|
16
|
-
require 'fontist'
|
|
17
|
-
require 'fontist/import/google/api'
|
|
18
|
-
|
|
19
|
-
# Get all font families (includes TTF, VF, and WOFF2 data)
|
|
20
|
-
families = Fontist::Import::Google::Api.items
|
|
21
|
-
puts "Total families: #{families.count}"
|
|
22
|
-
|
|
23
|
-
# Access unified database
|
|
24
|
-
db = Fontist::Import::Google::Api.database
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Basic Operations
|
|
28
|
-
|
|
29
|
-
### Get All Fonts
|
|
30
|
-
|
|
31
|
-
```ruby
|
|
32
|
-
# Returns array of FontFamily objects
|
|
33
|
-
all_fonts = Fontist::Import::Google::Api.items
|
|
34
|
-
|
|
35
|
-
# Iterate through fonts
|
|
36
|
-
all_fonts.each do |font|
|
|
37
|
-
puts "#{font.family} (#{font.category})"
|
|
38
|
-
end
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Find Specific Font
|
|
42
|
-
|
|
43
|
-
```ruby
|
|
44
|
-
# Find by familia name
|
|
45
|
-
roboto = Fontist::Import::Google::Api.font_by_name("Roboto")
|
|
46
|
-
|
|
47
|
-
if roboto
|
|
48
|
-
puts "Family: #{roboto.family}"
|
|
49
|
-
puts "Category: #{roboto.category}"
|
|
50
|
-
puts "Variants: #{roboto.variants.join(', ')}"
|
|
51
|
-
puts "Version: #{roboto.version}"
|
|
52
|
-
puts "Last Modified: #{roboto.last_modified}"
|
|
53
|
-
end
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Filter by Category
|
|
57
|
-
|
|
58
|
-
```ruby
|
|
59
|
-
# Get all sans-serif fonts
|
|
60
|
-
sans_serif = Fontist::Import::Google::Api.by_category("sans-serif")
|
|
61
|
-
puts "Sans-serif fonts: #{sans_serif.count}"
|
|
62
|
-
|
|
63
|
-
# Get all monospace fonts
|
|
64
|
-
monospace = Fontist::Import::Google::Api.by_category("monospace")
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Variable Fonts
|
|
68
|
-
|
|
69
|
-
### Get Variable Fonts Only
|
|
70
|
-
|
|
71
|
-
```ruby
|
|
72
|
-
# Returns only fonts with variable font axes
|
|
73
|
-
variable_fonts = Fontist::Import::Google::Api.variable_fonts_only
|
|
74
|
-
puts "Variable fonts: #{variable_fonts.count}"
|
|
75
|
-
|
|
76
|
-
variable_fonts.each do |font|
|
|
77
|
-
puts "\n#{font.family}"
|
|
78
|
-
font.axes.each do |axis|
|
|
79
|
-
puts " #{axis.tag}: #{axis.start} to #{axis.end}"
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Check if Font is Variable
|
|
85
|
-
|
|
86
|
-
```ruby
|
|
87
|
-
font = Fontist::Import::Google::Api.font_by_name("Roboto Flex")
|
|
88
|
-
|
|
89
|
-
if font&.variable_font?
|
|
90
|
-
puts "#{font.family} is a variable font with #{font.axes.count} axes"
|
|
91
|
-
|
|
92
|
-
# Access specific axes
|
|
93
|
-
weight_axes = font.weight_axes
|
|
94
|
-
width_axes = font.width_axes
|
|
95
|
-
slant_axes = font.slant_axes
|
|
96
|
-
custom_axes = font.custom_axes
|
|
97
|
-
end
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Working with Axes
|
|
101
|
-
|
|
102
|
-
```ruby
|
|
103
|
-
font = Fontist::Import::Google::Api.font_by_name("Advent Pro")
|
|
104
|
-
|
|
105
|
-
if font&.variable_font?
|
|
106
|
-
font.axes.each do |axis|
|
|
107
|
-
puts "Axis: #{axis.tag}"
|
|
108
|
-
puts " Range: #{axis.start} - #{axis.end}"
|
|
109
|
-
puts " Type: #{axis.description}"
|
|
110
|
-
|
|
111
|
-
# Check axis type
|
|
112
|
-
puts " Weight axis" if axis.weight_axis?
|
|
113
|
-
puts " Width axis" if axis.width_axis?
|
|
114
|
-
puts " Slant axis" if axis.slant_axis?
|
|
115
|
-
puts " Custom axis" if axis.custom_axis?
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Find specific axis
|
|
119
|
-
weight_axis = font.axis_by_tag("wght")
|
|
120
|
-
if weight_axis
|
|
121
|
-
puts "Weight range: #{weight_axis.range.inspect}"
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Multiple Formats (TTF and WOFF2)
|
|
127
|
-
|
|
128
|
-
### Check Available Formats
|
|
129
|
-
|
|
130
|
-
```ruby
|
|
131
|
-
db = Fontist::Import::Google::Api.database
|
|
132
|
-
|
|
133
|
-
# Fonts with TTF format
|
|
134
|
-
ttf_fonts = db.fonts_with_ttf
|
|
135
|
-
puts "Fonts with TTF: #{ttf_fonts.count}"
|
|
136
|
-
|
|
137
|
-
# Fonts with WOFF2 format
|
|
138
|
-
woff2_fonts = db.fonts_with_woff2
|
|
139
|
-
puts "Fonts with WOFF2: #{woff2_fonts.count}"
|
|
140
|
-
|
|
141
|
-
# Fonts with both formats
|
|
142
|
-
both_formats = db.fonts_with_both_formats
|
|
143
|
-
puts "Fonts with both: #{both_formats.count}"
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Access Format-Specific URLs
|
|
147
|
-
|
|
148
|
-
```ruby
|
|
149
|
-
db = Fontist::Import::Google::Api.database
|
|
150
|
-
|
|
151
|
-
# Get TTF URLs for a font
|
|
152
|
-
ttf_files = db.ttf_files_for("Roboto")
|
|
153
|
-
ttf_files.each do |variant, url|
|
|
154
|
-
puts "#{variant}: #{url}"
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# Get WOFF2 URLs for a font
|
|
158
|
-
woff2_files = db.woff2_files_for("Roboto")
|
|
159
|
-
woff2_files.each do |variant, url|
|
|
160
|
-
puts "#{variant}: #{url}"
|
|
161
|
-
end
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### Font Files Structure
|
|
165
|
-
|
|
166
|
-
```ruby
|
|
167
|
-
font = Fontist::Import::Google::Api.font_by_name("Roboto")
|
|
168
|
-
|
|
169
|
-
# The files hash contains TTF URLs by default
|
|
170
|
-
font.files.each do |variant, url|
|
|
171
|
-
puts "#{variant} (TTF): #{url}"
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# Access both formats via database
|
|
175
|
-
db = Fontist::Import::Google::Api.database
|
|
176
|
-
ttf = db.ttf_files_for("Roboto")
|
|
177
|
-
woff2 = db.woff2_files_for("Roboto")
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
## Advanced Queries
|
|
181
|
-
|
|
182
|
-
### Get Statistics
|
|
183
|
-
|
|
184
|
-
```ruby
|
|
185
|
-
# Overall statistics
|
|
186
|
-
stats = Fontist::Import::Google::Api.fonts_count
|
|
187
|
-
puts "Total fonts: #{stats[:total]}"
|
|
188
|
-
puts "Variable fonts: #{stats[:variable]}"
|
|
189
|
-
puts "Static fonts: #{stats[:static]}"
|
|
190
|
-
|
|
191
|
-
# Database-level statistics
|
|
192
|
-
db = Fontist::Import::Google::Api.database
|
|
193
|
-
puts "Categories: #{db.categories.join(', ')}"
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### Filter Static Fonts
|
|
197
|
-
|
|
198
|
-
```ruby
|
|
199
|
-
# Get only static (non-variable) fonts
|
|
200
|
-
static_fonts = Fontist::Import::Google::Api.static_fonts_only
|
|
201
|
-
puts "Static fonts: #{static_fonts.count}"
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
### Access Raw Endpoint Data
|
|
205
|
-
|
|
206
|
-
```ruby
|
|
207
|
-
# For debugging or advanced use cases
|
|
208
|
-
ttf_data = Fontist::Import::Google::Api.ttf_data
|
|
209
|
-
vf_data = Fontist::Import::Google::Api.vf_data
|
|
210
|
-
woff2_data = Fontist::Import::Google::Api.woff2_data
|
|
211
|
-
|
|
212
|
-
puts "TTF endpoint: #{ttf_data.count} fonts"
|
|
213
|
-
puts "VF endpoint: #{vf_data.count} fonts"
|
|
214
|
-
puts "WOFF2 endpoint: #{woff2_data.count} fonts"
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## Caching
|
|
218
|
-
|
|
219
|
-
### Clear Cache
|
|
220
|
-
|
|
221
|
-
```ruby
|
|
222
|
-
# Clear all caches (database and client caches)
|
|
223
|
-
Fontist::Import::Google::Api.clear_cache
|
|
224
|
-
|
|
225
|
-
# Data will be re-fetched on next access
|
|
226
|
-
families = Fontist::Import::Google::Api.items
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
### Cache Behavior
|
|
230
|
-
|
|
231
|
-
- API responses are cached at the client level
|
|
232
|
-
- Database is built once and cached
|
|
233
|
-
- Call `clear_cache` to force refresh from API
|
|
234
|
-
|
|
235
|
-
## FontFamily Model
|
|
236
|
-
|
|
237
|
-
The [`FontFamily`](../lib/fontist/import/google/models/font_family.rb) model provides:
|
|
238
|
-
|
|
239
|
-
```ruby
|
|
240
|
-
font = Fontist::Import::Google::Api.font_by_name("Roboto")
|
|
241
|
-
|
|
242
|
-
# Basic attributes
|
|
243
|
-
font.family # "Roboto"
|
|
244
|
-
font.category # "sans-serif"
|
|
245
|
-
font.version # "v30"
|
|
246
|
-
font.last_modified # "2022-09-22"
|
|
247
|
-
|
|
248
|
-
# Variants and subsets
|
|
249
|
-
font.variants # ["regular", "italic", "700", ...]
|
|
250
|
-
font.subsets # ["latin", "latin-ext", ...]
|
|
251
|
-
|
|
252
|
-
# Files (TTF URLs by default)
|
|
253
|
-
font.files # {"regular" => "url", ...}
|
|
254
|
-
|
|
255
|
-
# Variable font support
|
|
256
|
-
font.variable_font? # true/false
|
|
257
|
-
font.axes # Array of Axis objects (if VF)
|
|
258
|
-
|
|
259
|
-
# Helper methods
|
|
260
|
-
font.variant_names # Array of variant names
|
|
261
|
-
font.file_urls # Array of file URLs
|
|
262
|
-
font.variant_exists?("700") # Check if variant exists
|
|
263
|
-
font.variant_url("regular") # Get URL for variant
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
## Axis Model
|
|
267
|
-
|
|
268
|
-
The [`Axis`](../lib/fontist/import/google/models/axis.rb) model for variable fonts:
|
|
269
|
-
|
|
270
|
-
```ruby
|
|
271
|
-
axis = font.axes.first
|
|
272
|
-
|
|
273
|
-
# Attributes
|
|
274
|
-
axis.tag # "wght", "wdth", "slnt", etc.
|
|
275
|
-
axis.start # Minimum value (e.g., 100)
|
|
276
|
-
axis.end # Maximum value (e.g., 900)
|
|
277
|
-
|
|
278
|
-
# Helper methods
|
|
279
|
-
axis.weight_axis? # Check if weight axis
|
|
280
|
-
axis.width_axis? # Check if width axis
|
|
281
|
-
axis.slant_axis? # Check if slant axis
|
|
282
|
-
axis.custom_axis? # Check if custom axis
|
|
283
|
-
axis.range # [start, end]
|
|
284
|
-
axis.description # Human-readable description
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
## Error Handling
|
|
288
|
-
|
|
289
|
-
```ruby
|
|
290
|
-
begin
|
|
291
|
-
families = Fontist::Import::Google::Api.items
|
|
292
|
-
rescue StandardError => e
|
|
293
|
-
puts "Error fetching fonts: #{e.message}"
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
# Check if font exists
|
|
297
|
-
font = Fontist::Import::Google::Api.font_by_name("NonExistent")
|
|
298
|
-
if font.nil?
|
|
299
|
-
puts "Font not found"
|
|
300
|
-
end
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
## Example: List Variable Fonts with Axes
|
|
304
|
-
|
|
305
|
-
```ruby
|
|
306
|
-
require 'fontist/import/google/api'
|
|
307
|
-
|
|
308
|
-
puts "Variable Fonts with Axes\n"
|
|
309
|
-
puts "=" * 60
|
|
310
|
-
|
|
311
|
-
Fontist::Import::Google::Api.variable_fonts_only.each do |font|
|
|
312
|
-
puts "\n#{font.family}"
|
|
313
|
-
puts " Category: #{font.category}"
|
|
314
|
-
puts " Variants: #{font.variants.count}"
|
|
315
|
-
puts " Axes:"
|
|
316
|
-
|
|
317
|
-
font.axes.each do |axis|
|
|
318
|
-
type = if axis.weight_axis?
|
|
319
|
-
"Weight"
|
|
320
|
-
elsif axis.width_axis?
|
|
321
|
-
"Width"
|
|
322
|
-
elsif axis.slant_axis?
|
|
323
|
-
"Slant"
|
|
324
|
-
else
|
|
325
|
-
"Custom (#{axis.tag})"
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
puts " - #{type}: #{axis.start} to #{axis.end}"
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
## Example: Download Fonts by Category
|
|
334
|
-
|
|
335
|
-
```ruby
|
|
336
|
-
require 'fontist/import/google/api'
|
|
337
|
-
require 'net/http'
|
|
338
|
-
require 'fileutils'
|
|
339
|
-
|
|
340
|
-
# Get all monospace fonts
|
|
341
|
-
monospace_fonts = Fontist::Import::Google::Api.by_category("monospace")
|
|
342
|
-
|
|
343
|
-
# Create download directory
|
|
344
|
-
download_dir = "fonts/monospace"
|
|
345
|
-
FileUtils.mkdir_p(download_dir)
|
|
346
|
-
|
|
347
|
-
monospace_fonts.each do |font|
|
|
348
|
-
puts "Downloading #{font.family}..."
|
|
349
|
-
|
|
350
|
-
font.files.each do |variant, url|
|
|
351
|
-
filename = "#{font.family.gsub(' ', '_')}-#{variant}.ttf"
|
|
352
|
-
filepath = File.join(download_dir, filename)
|
|
353
|
-
|
|
354
|
-
# Download file
|
|
355
|
-
uri = URI(url)
|
|
356
|
-
response = Net::HTTP.get_response(uri)
|
|
357
|
-
|
|
358
|
-
if response.is_a?(Net::HTTPSuccess)
|
|
359
|
-
File.binwrite(filepath, response.body)
|
|
360
|
-
puts " ✓ #{filename}"
|
|
361
|
-
else
|
|
362
|
-
puts " ✗ Failed to download #{filename}"
|
|
363
|
-
end
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
puts "\nDownload complete!"
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
## Architecture
|
|
371
|
-
|
|
372
|
-
The implementation consists of four layers:
|
|
373
|
-
|
|
374
|
-
### 1. Models Layer
|
|
375
|
-
- [`FontFamily`](../lib/fontist/import/google/models/font_family.rb) - Represents font families
|
|
376
|
-
- [`FontVariant`](../lib/fontist/import/google/models/font_variant.rb) - Represents font variants
|
|
377
|
-
- [`Axis`](../lib/fontist/import/google/models/axis.rb) - Represents variable font axes
|
|
378
|
-
|
|
379
|
-
### 2. Clients Layer
|
|
380
|
-
- [`TtfClient`](../lib/fontist/import/google/clients/ttf_client.rb) - Fetches TTF data
|
|
381
|
-
- [`VfClient`](../lib/fontist/import/google/clients/vf_client.rb) - Fetches VF data with axes
|
|
382
|
-
- [`Woff2Client`](../lib/fontist/import/google/clients/woff2_client.rb) - Fetches WOFF2 data
|
|
383
|
-
|
|
384
|
-
### 3. Database Layer
|
|
385
|
-
- [`FontDatabase`](../lib/fontist/import/google/font_database.rb) - Merges data from all endpoints
|
|
386
|
-
|
|
387
|
-
### 4. API Layer
|
|
388
|
-
- [`Api`](../lib/fontist/import/google/api.rb) - Public facade for accessing fonts
|
|
389
|
-
|
|
390
|
-
## Configuration
|
|
391
|
-
|
|
392
|
-
Set your Google Fonts API key:
|
|
393
|
-
|
|
394
|
-
```ruby
|
|
395
|
-
# Via environment variable
|
|
396
|
-
ENV['GOOGLE_FONTS_KEY'] = 'your-api-key'
|
|
397
|
-
|
|
398
|
-
# Or configure Fontist
|
|
399
|
-
Fontist.google_fonts_key = 'your-api-key'
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
## Testing
|
|
403
|
-
|
|
404
|
-
See [`spec/fontist/import/google/`](../spec/fontist/import/google/) for comprehensive test examples.
|
|
405
|
-
|
|
406
|
-
Run tests:
|
|
407
|
-
```bash
|
|
408
|
-
bundle exec rspec spec/fontist/import/google/
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
All 188 tests pass successfully! ✅
|
|
412
|
-
|
|
413
|
-
## Additional Resources
|
|
414
|
-
|
|
415
|
-
- [Google Fonts Developer API](https://developers.google.com/fonts/docs/developer_api)
|
|
416
|
-
- [Variable Fonts Guide](https://web.dev/variable-fonts/)
|
|
417
|
-
- [Architecture Plan](google-fonts-api-architecture.md)
|
|
418
|
-
- [API Analysis](../temp-test/api_analysis.md)
|
|
419
|
-
- [Implementation Summary](../temp-test/implementation_summary.md)
|