fontisan 0.4.49-java → 0.4.50-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 +4 -4
- data/docs/guide/color-fonts/svg.md +5 -5
- data/lib/fontisan/export/ttx_generator.rb +56 -38
- data/lib/fontisan/export/ttx_parser.rb +11 -11
- data/lib/fontisan/ffi/windows-x86_64/fontisan_cdylib.dll +0 -0
- data/lib/fontisan/models/ttx/tables/binary_table.rb +14 -9
- data/lib/fontisan/svg_to_glyf/document.rb +3 -3
- data/lib/fontisan/ufo/glyph.rb +30 -18
- data/lib/fontisan/ufo/plist.rb +22 -24
- data/lib/fontisan/version.rb +1 -1
- data/lib/fontisan.rb +18 -2
- metadata +18 -5
- data/build_mingw32_stub.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 702eea844ae2f2e23fc8ddac0166235420a8aedc3f98e1f68354894576f89c69
|
|
4
|
+
data.tar.gz: 17546ffc35f74e82671fc9fab84c78f79fa994acf8eed67d801e3b6a35af225d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6923a26164c3194e2ed480bc1fe8c084c11985c2abd1fafdceb281ade078eaac1c3717286e9fc7a440f7f0b11b99139cf49ee9a175d173d8aa0cb070aec48dfe
|
|
7
|
+
data.tar.gz: 42759498acb1d661a1adc4960dc3c9936d0d3e3151abb90153f29983a6d97a9030e22a60b75a4f0e364737a70f20e95820023069034e536f0472335d73be45cd
|
|
@@ -44,22 +44,22 @@ end
|
|
|
44
44
|
### Parse SVG Content
|
|
45
45
|
|
|
46
46
|
```ruby
|
|
47
|
-
require '
|
|
47
|
+
require 'moxml'
|
|
48
48
|
|
|
49
49
|
svg = font.tables['SVG']
|
|
50
50
|
doc = svg.documents[42] # SVG for glyph 42
|
|
51
51
|
|
|
52
|
-
parsed =
|
|
52
|
+
parsed = Moxml.parse(doc)
|
|
53
53
|
|
|
54
54
|
# Find elements
|
|
55
|
-
paths = parsed.css('path')
|
|
55
|
+
paths = parsed.root.css('path')
|
|
56
56
|
puts "Paths: #{paths.length}"
|
|
57
57
|
|
|
58
|
-
rects = parsed.css('rect')
|
|
58
|
+
rects = parsed.root.css('rect')
|
|
59
59
|
puts "Rectangles: #{rects.length}"
|
|
60
60
|
|
|
61
61
|
# Find gradients
|
|
62
|
-
gradients = parsed.css('linearGradient
|
|
62
|
+
gradients = parsed.root.css('linearGradient, radialGradient')
|
|
63
63
|
puts "Gradients: #{gradients.length}"
|
|
64
64
|
```
|
|
65
65
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Fontisan
|
|
6
6
|
module Export
|
|
@@ -40,21 +40,35 @@ module Fontisan
|
|
|
40
40
|
def generate(options = {})
|
|
41
41
|
table_list = options[:tables] || :all
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
# The ttFont body lambda is created here (method context) so
|
|
44
|
+
# its self stays this generator: moxml's #build block is
|
|
45
|
+
# instance_eval'd against the builder, which would turn bare
|
|
46
|
+
# helper calls into tag names. The zero-indent context keeps
|
|
47
|
+
# the builder markup flat so the pretty reparse in
|
|
48
|
+
# format_output owns all indentation (reindenting
|
|
49
|
+
# already-indented mixed content glues sibling tags together).
|
|
50
|
+
context = Moxml.new { |config| config.default_indent = 0 }
|
|
51
|
+
builder = Moxml::Builder.new(context)
|
|
52
|
+
sfnt_version = format_sfnt_version(to_int(@font.header.sfnt_version))
|
|
53
|
+
root_body = -> {
|
|
54
|
+
generate_glyph_order(builder)
|
|
55
|
+
|
|
56
|
+
tables_to_generate = select_tables(table_list)
|
|
57
|
+
tables_to_generate.each do |tag|
|
|
58
|
+
generate_table(builder, tag)
|
|
54
59
|
end
|
|
60
|
+
}
|
|
61
|
+
builder.build do
|
|
62
|
+
declaration(version: "1.0", encoding: "UTF-8")
|
|
63
|
+
create_tag("ttFont",
|
|
64
|
+
{ "sfntVersion" => sfnt_version,
|
|
65
|
+
"ttLibVersion" => "4.0" },
|
|
66
|
+
block: root_body)
|
|
55
67
|
end
|
|
56
68
|
|
|
57
|
-
|
|
69
|
+
# expand_empty: false keeps the Nokogiri shape (empty elements
|
|
70
|
+
# self-close, e.g. <GlyphID id="0" name=".notdef"/>).
|
|
71
|
+
format_output(builder.doc.to_xml(expand_empty: false))
|
|
58
72
|
end
|
|
59
73
|
|
|
60
74
|
private
|
|
@@ -69,7 +83,7 @@ module Fontisan
|
|
|
69
83
|
|
|
70
84
|
# Generate GlyphOrder section (required first)
|
|
71
85
|
#
|
|
72
|
-
# @param xml [
|
|
86
|
+
# @param xml [Moxml::Builder] XML builder
|
|
73
87
|
# @return [void]
|
|
74
88
|
def generate_glyph_order(xml)
|
|
75
89
|
xml.GlyphOrder do
|
|
@@ -83,7 +97,7 @@ module Fontisan
|
|
|
83
97
|
|
|
84
98
|
# Generate individual table XML
|
|
85
99
|
#
|
|
86
|
-
# @param xml [
|
|
100
|
+
# @param xml [Moxml::Builder] XML builder
|
|
87
101
|
public
|
|
88
102
|
|
|
89
103
|
# Per-tag emitter dispatch table. Adding a new table's TTX
|
|
@@ -138,7 +152,7 @@ module Fontisan
|
|
|
138
152
|
|
|
139
153
|
# Generate head table XML
|
|
140
154
|
#
|
|
141
|
-
# @param xml [
|
|
155
|
+
# @param xml [Moxml::Builder] XML builder
|
|
142
156
|
# @param table [Tables::Head] Head table
|
|
143
157
|
# @return [void]
|
|
144
158
|
def generate_head_table(xml, table)
|
|
@@ -167,7 +181,7 @@ module Fontisan
|
|
|
167
181
|
|
|
168
182
|
# Generate hhea table XML
|
|
169
183
|
#
|
|
170
|
-
# @param xml [
|
|
184
|
+
# @param xml [Moxml::Builder] XML builder
|
|
171
185
|
# @param table [Tables::Hhea] Hhea table
|
|
172
186
|
# @return [void]
|
|
173
187
|
def generate_hhea_table(xml, table)
|
|
@@ -194,7 +208,7 @@ module Fontisan
|
|
|
194
208
|
|
|
195
209
|
# Generate maxp table XML
|
|
196
210
|
#
|
|
197
|
-
# @param xml [
|
|
211
|
+
# @param xml [Moxml::Builder] XML builder
|
|
198
212
|
# @param table [Tables::Maxp] Maxp table
|
|
199
213
|
# @return [void]
|
|
200
214
|
def generate_maxp_table(xml, table)
|
|
@@ -224,7 +238,7 @@ module Fontisan
|
|
|
224
238
|
|
|
225
239
|
# Generate post table XML
|
|
226
240
|
#
|
|
227
|
-
# @param xml [
|
|
241
|
+
# @param xml [Moxml::Builder] XML builder
|
|
228
242
|
# @param table [Tables::Post] Post table
|
|
229
243
|
# @return [void]
|
|
230
244
|
def generate_post_table(xml, table)
|
|
@@ -243,7 +257,7 @@ module Fontisan
|
|
|
243
257
|
|
|
244
258
|
# Generate name table XML
|
|
245
259
|
#
|
|
246
|
-
# @param xml [
|
|
260
|
+
# @param xml [Moxml::Builder] XML builder
|
|
247
261
|
# @param table [Tables::Name] Name table
|
|
248
262
|
# @return [void]
|
|
249
263
|
def generate_name_table(xml, table)
|
|
@@ -263,7 +277,7 @@ module Fontisan
|
|
|
263
277
|
|
|
264
278
|
# Generate OS/2 table XML
|
|
265
279
|
#
|
|
266
|
-
# @param xml [
|
|
280
|
+
# @param xml [Moxml::Builder] XML builder
|
|
267
281
|
# @param table [Tables::Os2] OS/2 table
|
|
268
282
|
# @return [void]
|
|
269
283
|
def generate_os2_table(xml, table)
|
|
@@ -274,10 +288,10 @@ module Fontisan
|
|
|
274
288
|
|
|
275
289
|
# Helper to add element with value attribute
|
|
276
290
|
#
|
|
277
|
-
# @param parent [
|
|
291
|
+
# @param parent [Moxml::Element] Parent element
|
|
278
292
|
# @param name [String] Element name
|
|
279
293
|
# @param value [Object] Value
|
|
280
|
-
# @param doc [
|
|
294
|
+
# @param doc [Moxml::Document] Document
|
|
281
295
|
# @return [void]
|
|
282
296
|
def add_element_with_value(parent, name, value, doc)
|
|
283
297
|
elem = doc.create_element(name)
|
|
@@ -287,7 +301,7 @@ module Fontisan
|
|
|
287
301
|
|
|
288
302
|
# Generate binary table as hexdata
|
|
289
303
|
#
|
|
290
|
-
# @param xml [
|
|
304
|
+
# @param xml [Moxml::Builder] XML builder
|
|
291
305
|
# @param tag [String] Table tag
|
|
292
306
|
# @param table [Object] Table object
|
|
293
307
|
# @return [void]
|
|
@@ -302,7 +316,7 @@ module Fontisan
|
|
|
302
316
|
|
|
303
317
|
# Generate binary table from raw data
|
|
304
318
|
#
|
|
305
|
-
# @param xml [
|
|
319
|
+
# @param xml [Moxml::Builder] XML builder
|
|
306
320
|
# @param tag [String] Table tag
|
|
307
321
|
# @param data [String] Raw binary data
|
|
308
322
|
# @return [void]
|
|
@@ -318,7 +332,7 @@ module Fontisan
|
|
|
318
332
|
|
|
319
333
|
# Generate cmap table XML (simplified for now)
|
|
320
334
|
#
|
|
321
|
-
# @param xml [
|
|
335
|
+
# @param xml [Moxml::Builder] XML builder
|
|
322
336
|
# @param table [Object] Cmap table
|
|
323
337
|
# @return [void]
|
|
324
338
|
def generate_cmap_table(xml, table)
|
|
@@ -327,7 +341,7 @@ module Fontisan
|
|
|
327
341
|
|
|
328
342
|
# Generate loca table XML
|
|
329
343
|
#
|
|
330
|
-
# @param xml [
|
|
344
|
+
# @param xml [Moxml::Builder] XML builder
|
|
331
345
|
# @param table [Object] Loca table
|
|
332
346
|
# @return [void]
|
|
333
347
|
def generate_loca_table(xml, _table)
|
|
@@ -338,7 +352,7 @@ module Fontisan
|
|
|
338
352
|
|
|
339
353
|
# Generate glyf table XML (simplified for now)
|
|
340
354
|
#
|
|
341
|
-
# @param xml [
|
|
355
|
+
# @param xml [Moxml::Builder] XML builder
|
|
342
356
|
# @param table [Object] Glyf table
|
|
343
357
|
# @return [void]
|
|
344
358
|
def generate_glyf_table(xml, table)
|
|
@@ -347,7 +361,7 @@ module Fontisan
|
|
|
347
361
|
|
|
348
362
|
# Generate CFF table XML (simplified for now)
|
|
349
363
|
#
|
|
350
|
-
# @param xml [
|
|
364
|
+
# @param xml [Moxml::Builder] XML builder
|
|
351
365
|
# @param table [Object] CFF table
|
|
352
366
|
# @return [void]
|
|
353
367
|
def generate_cff_table(xml, table)
|
|
@@ -356,7 +370,7 @@ module Fontisan
|
|
|
356
370
|
|
|
357
371
|
# Generate hmtx table XML (simplified for now)
|
|
358
372
|
#
|
|
359
|
-
# @param xml [
|
|
373
|
+
# @param xml [Moxml::Builder] XML builder
|
|
360
374
|
# @param table [Object] Hmtx table
|
|
361
375
|
# @return [void]
|
|
362
376
|
def generate_hmtx_table(xml, table)
|
|
@@ -365,7 +379,7 @@ module Fontisan
|
|
|
365
379
|
|
|
366
380
|
# Generate fvar table XML
|
|
367
381
|
#
|
|
368
|
-
# @param xml [
|
|
382
|
+
# @param xml [Moxml::Builder] XML builder
|
|
369
383
|
# @param table [Tables::Fvar] Fvar table
|
|
370
384
|
# @return [void]
|
|
371
385
|
def generate_fvar_table(xml, table)
|
|
@@ -376,10 +390,12 @@ module Fontisan
|
|
|
376
390
|
table.axes.each do |axis|
|
|
377
391
|
xml.Axis do
|
|
378
392
|
xml.AxisTag axis.axis_tag
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
xml.
|
|
382
|
-
xml.
|
|
393
|
+
# moxml builder text content must be a String (Nokogiri
|
|
394
|
+
# stringified any value); .to_s keeps the same bytes.
|
|
395
|
+
xml.MinValue (to_int(axis.min_value) / 65536.0).to_s
|
|
396
|
+
xml.DefaultValue (to_int(axis.default_value) / 65536.0).to_s
|
|
397
|
+
xml.MaxValue (to_int(axis.max_value) / 65536.0).to_s
|
|
398
|
+
xml.AxisNameID to_int(axis.axis_name_id).to_s
|
|
383
399
|
end
|
|
384
400
|
end
|
|
385
401
|
end
|
|
@@ -387,7 +403,7 @@ module Fontisan
|
|
|
387
403
|
|
|
388
404
|
# Generate variation table XML (gvar, cvar, HVAR, etc.)
|
|
389
405
|
#
|
|
390
|
-
# @param xml [
|
|
406
|
+
# @param xml [Moxml::Builder] XML builder
|
|
391
407
|
# @param tag [String] Table tag
|
|
392
408
|
# @param table [Object] Variation table
|
|
393
409
|
# @return [void]
|
|
@@ -514,8 +530,10 @@ module Fontisan
|
|
|
514
530
|
# @return [String] Formatted XML
|
|
515
531
|
def format_output(xml)
|
|
516
532
|
if @pretty
|
|
517
|
-
doc =
|
|
518
|
-
|
|
533
|
+
doc = Moxml.parse(xml)
|
|
534
|
+
# expand_empty: false keeps the Nokogiri shape (empty
|
|
535
|
+
# elements self-close).
|
|
536
|
+
doc.to_xml(indent: @indent, expand_empty: false)
|
|
519
537
|
else
|
|
520
538
|
# Remove extra whitespace for compact format
|
|
521
539
|
xml.gsub(/>\s+</, "><").gsub(/\n\s*/, "")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Fontisan
|
|
6
6
|
module Export
|
|
@@ -19,7 +19,7 @@ module Fontisan
|
|
|
19
19
|
# @param ttx_xml [String] TTX XML content
|
|
20
20
|
# @return [Hash] Parsed font data structure
|
|
21
21
|
def parse(ttx_xml)
|
|
22
|
-
doc =
|
|
22
|
+
doc = Moxml.parse(ttx_xml)
|
|
23
23
|
ttfont = doc.at_xpath("/ttFont")
|
|
24
24
|
raise "No ttFont root element found" unless ttfont
|
|
25
25
|
|
|
@@ -51,7 +51,7 @@ module Fontisan
|
|
|
51
51
|
|
|
52
52
|
# Parse GlyphOrder section
|
|
53
53
|
#
|
|
54
|
-
# @param ttfont [
|
|
54
|
+
# @param ttfont [Moxml::Element] Root element
|
|
55
55
|
# @return [Array<Hash>] Array of glyph entries
|
|
56
56
|
def parse_glyph_order(ttfont)
|
|
57
57
|
glyph_order = ttfont.at_xpath("GlyphOrder")
|
|
@@ -67,7 +67,7 @@ module Fontisan
|
|
|
67
67
|
|
|
68
68
|
# Parse all tables
|
|
69
69
|
#
|
|
70
|
-
# @param ttfont [
|
|
70
|
+
# @param ttfont [Moxml::Element] Root element
|
|
71
71
|
# @return [Hash] Hash of table data by tag
|
|
72
72
|
def parse_tables(ttfont)
|
|
73
73
|
tables = {}
|
|
@@ -88,7 +88,7 @@ module Fontisan
|
|
|
88
88
|
|
|
89
89
|
# Parse head table
|
|
90
90
|
#
|
|
91
|
-
# @param ttfont [
|
|
91
|
+
# @param ttfont [Moxml::Element] Root element
|
|
92
92
|
# @param tables [Hash] Tables hash
|
|
93
93
|
# @return [void]
|
|
94
94
|
def parse_head_table(ttfont, tables)
|
|
@@ -118,7 +118,7 @@ module Fontisan
|
|
|
118
118
|
|
|
119
119
|
# Parse hhea table
|
|
120
120
|
#
|
|
121
|
-
# @param ttfont [
|
|
121
|
+
# @param ttfont [Moxml::Element] Root element
|
|
122
122
|
# @param tables [Hash] Tables hash
|
|
123
123
|
# @return [void]
|
|
124
124
|
def parse_hhea_table(ttfont, tables)
|
|
@@ -144,7 +144,7 @@ module Fontisan
|
|
|
144
144
|
|
|
145
145
|
# Parse maxp table
|
|
146
146
|
#
|
|
147
|
-
# @param ttfont [
|
|
147
|
+
# @param ttfont [Moxml::Element] Root element
|
|
148
148
|
# @param tables [Hash] Tables hash
|
|
149
149
|
# @return [void]
|
|
150
150
|
def parse_maxp_table(ttfont, tables)
|
|
@@ -169,7 +169,7 @@ module Fontisan
|
|
|
169
169
|
|
|
170
170
|
# Parse name table
|
|
171
171
|
#
|
|
172
|
-
# @param ttfont [
|
|
172
|
+
# @param ttfont [Moxml::Element] Root element
|
|
173
173
|
# @param tables [Hash] Tables hash
|
|
174
174
|
# @return [void]
|
|
175
175
|
def parse_name_table(ttfont, tables)
|
|
@@ -191,7 +191,7 @@ module Fontisan
|
|
|
191
191
|
|
|
192
192
|
# Parse OS/2 table (stub)
|
|
193
193
|
#
|
|
194
|
-
# @param ttfont [
|
|
194
|
+
# @param ttfont [Moxml::Element] Root element
|
|
195
195
|
# @param tables [Hash] Tables hash
|
|
196
196
|
# @return [void]
|
|
197
197
|
def parse_os2_table(ttfont, tables)
|
|
@@ -204,7 +204,7 @@ module Fontisan
|
|
|
204
204
|
|
|
205
205
|
# Parse post table (stub)
|
|
206
206
|
#
|
|
207
|
-
# @param ttfont [
|
|
207
|
+
# @param ttfont [Moxml::Element] Root element
|
|
208
208
|
# @param tables [Hash] Tables hash
|
|
209
209
|
# @return [void]
|
|
210
210
|
def parse_post_table(ttfont, tables)
|
|
@@ -222,7 +222,7 @@ module Fontisan
|
|
|
222
222
|
|
|
223
223
|
# Parse binary tables (fallback)
|
|
224
224
|
#
|
|
225
|
-
# @param ttfont [
|
|
225
|
+
# @param ttfont [Moxml::Element] Root element
|
|
226
226
|
# @param tables [Hash] Tables hash
|
|
227
227
|
# @return [void]
|
|
228
228
|
def parse_binary_tables(ttfont, tables)
|
|
Binary file
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "lutaml/model"
|
|
4
|
+
require "moxml"
|
|
4
5
|
|
|
5
6
|
module Fontisan
|
|
6
7
|
module Models
|
|
@@ -17,24 +18,28 @@ module Fontisan
|
|
|
17
18
|
# Custom serialization since we need dynamic root element
|
|
18
19
|
# based on table tag
|
|
19
20
|
def to_xml(options = {})
|
|
20
|
-
builder =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
builder = Moxml::Builder.new(Moxml.new)
|
|
22
|
+
table_tag = tag
|
|
23
|
+
body = -> {
|
|
24
|
+
builder.create_tag(table_tag, block: -> {
|
|
25
|
+
builder.create_tag(
|
|
26
|
+
"hexdata",
|
|
27
|
+
text_content: "\n #{format_hexdata(hexdata)}\n ",
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
builder.build(&body)
|
|
27
32
|
|
|
28
33
|
if options[:pretty]
|
|
29
34
|
builder.doc.root.to_xml(indent: options.fetch(:indent, 2))
|
|
30
35
|
else
|
|
31
|
-
builder.to_xml
|
|
36
|
+
builder.doc.to_xml(expand_empty: false)
|
|
32
37
|
end
|
|
33
38
|
end
|
|
34
39
|
|
|
35
40
|
# Parse from XML
|
|
36
41
|
def self.from_xml(xml_string, tag)
|
|
37
|
-
doc =
|
|
42
|
+
doc = Moxml.parse(xml_string)
|
|
38
43
|
table_elem = doc.at_xpath("//#{tag}")
|
|
39
44
|
return nil unless table_elem
|
|
40
45
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Fontisan
|
|
6
6
|
module SvgToGlyf
|
|
@@ -13,7 +13,7 @@ module Fontisan
|
|
|
13
13
|
|
|
14
14
|
# @param xml [String] raw SVG XML
|
|
15
15
|
def self.from_xml(xml)
|
|
16
|
-
new(
|
|
16
|
+
new(Moxml.parse(xml))
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# @param path [String] file path to an .svg file
|
|
@@ -21,7 +21,7 @@ module Fontisan
|
|
|
21
21
|
from_xml(File.read(path))
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
# @param doc [
|
|
24
|
+
# @param doc [Moxml::Document]
|
|
25
25
|
def initialize(doc)
|
|
26
26
|
@doc = doc
|
|
27
27
|
@source = doc
|
data/lib/fontisan/ufo/glyph.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Fontisan
|
|
6
6
|
module Ufo
|
|
@@ -110,27 +110,39 @@ module Fontisan
|
|
|
110
110
|
# @param xml [String] the .glif XML body
|
|
111
111
|
# @return [Glyph] parsed glyph
|
|
112
112
|
def self.from_glif(xml)
|
|
113
|
-
doc =
|
|
113
|
+
doc = Moxml.parse(xml)
|
|
114
114
|
root = doc.root
|
|
115
115
|
new(name: root["name"]).tap { |g| g.read_from(root) }
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
# Render this glyph back to .glif XML.
|
|
119
|
+
#
|
|
120
|
+
# The glyph body block is created here (method context) so its
|
|
121
|
+
# self stays this glyph: moxml's #build block is instance_eval'd
|
|
122
|
+
# against the builder, which would turn bare helper calls into
|
|
123
|
+
# tag names.
|
|
119
124
|
# @return [String] XML text
|
|
120
125
|
def to_glif
|
|
121
|
-
builder =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
builder = Moxml::Builder.new(Moxml.new)
|
|
127
|
+
body = -> {
|
|
128
|
+
emit_advance(builder)
|
|
129
|
+
emit_unicodes(builder)
|
|
130
|
+
emit_outline(builder)
|
|
131
|
+
emit_lib(builder)
|
|
132
|
+
emit_note(builder)
|
|
133
|
+
}
|
|
134
|
+
name = @name
|
|
135
|
+
builder.build do
|
|
136
|
+
declaration(version: "1.0", encoding: "UTF-8")
|
|
137
|
+
create_tag("glyph", { "name" => name, "format" => "2" },
|
|
138
|
+
block: body)
|
|
129
139
|
end
|
|
130
|
-
|
|
140
|
+
# expand_empty: false keeps the Nokogiri shape (empty elements
|
|
141
|
+
# self-close, e.g. <advance width="0"/>).
|
|
142
|
+
builder.doc.to_xml(expand_empty: false)
|
|
131
143
|
end
|
|
132
144
|
|
|
133
|
-
# Populate this glyph from a <glyph>
|
|
145
|
+
# Populate this glyph from a <glyph> Moxml node.
|
|
134
146
|
def read_from(root)
|
|
135
147
|
read_advance(root)
|
|
136
148
|
read_unicodes(root)
|
|
@@ -325,7 +337,7 @@ module Fontisan
|
|
|
325
337
|
@note = note_node.text if note_node
|
|
326
338
|
end
|
|
327
339
|
|
|
328
|
-
# Helper: read a <dict>
|
|
340
|
+
# Helper: read a <dict> Moxml node into a Hash. Reuses the
|
|
329
341
|
# same key/value pair logic as Plist.parse but operates on the
|
|
330
342
|
# inlined lib plist.
|
|
331
343
|
def read_dict_to_hash(dict_node)
|
|
@@ -422,11 +434,11 @@ module Fontisan
|
|
|
422
434
|
|
|
423
435
|
def emit_value(xml, v)
|
|
424
436
|
case v
|
|
425
|
-
when String then xml.string(v)
|
|
426
|
-
when Integer then xml.integer(v)
|
|
427
|
-
when Float then xml.real(v)
|
|
428
|
-
when true then xml.
|
|
429
|
-
when false then xml.
|
|
437
|
+
when String then v.empty? ? xml.string_ : xml.string(v)
|
|
438
|
+
when Integer then xml.integer(v.to_s)
|
|
439
|
+
when Float then xml.real(v.to_s)
|
|
440
|
+
when true then xml.true_
|
|
441
|
+
when false then xml.false_
|
|
430
442
|
when Array then xml.array { v.each { |i| emit_value(xml, i) } }
|
|
431
443
|
when Hash then emit_dict(xml, v)
|
|
432
444
|
else xml.string(v.to_s)
|
data/lib/fontisan/ufo/plist.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Fontisan
|
|
6
6
|
module Ufo
|
|
@@ -18,10 +18,10 @@ module Fontisan
|
|
|
18
18
|
PLIST_DTD = "-//Apple//DTD PLIST 1.0//EN"
|
|
19
19
|
PLIST_NS = "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
|
|
20
20
|
|
|
21
|
-
# @param source [String,
|
|
21
|
+
# @param source [String, Moxml::Document] the XML plist
|
|
22
22
|
# @return [Object] the deserialized value
|
|
23
23
|
def self.parse(source)
|
|
24
|
-
doc =
|
|
24
|
+
doc = parse_document(source)
|
|
25
25
|
root = doc.root
|
|
26
26
|
raise ParseError, "no <plist> root element" unless root&.name == "plist"
|
|
27
27
|
|
|
@@ -33,22 +33,22 @@ module Fontisan
|
|
|
33
33
|
# @param value [Object] the value to serialize
|
|
34
34
|
# @return [String] the XML plist text
|
|
35
35
|
def self.emit(value)
|
|
36
|
-
builder =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
builder = Moxml::Builder.new(Moxml.new)
|
|
37
|
+
builder.build do
|
|
38
|
+
doctype("plist", PLIST_DTD, PLIST_NS)
|
|
39
|
+
plist(version: "1.0") do
|
|
40
|
+
Plist.emit_value(builder, value)
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
43
|
+
# indent: 0 keeps the body on the single line Nokogiri's
|
|
44
|
+
# AS_XML produced; expand_empty: false keeps its `<string/>`
|
|
45
|
+
# self-closing shape for empty elements.
|
|
46
|
+
builder.doc.to_xml(indent: 0, expand_empty: false)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
# @return [
|
|
49
|
+
# @return [Moxml::Document] the typed root
|
|
50
50
|
def self.parse_document(source)
|
|
51
|
-
source.is_a?(
|
|
51
|
+
source.is_a?(Moxml::Document) ? source : Moxml.parse(source)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# ---------- private-ish (called via module_function) ----------
|
|
@@ -90,20 +90,18 @@ module Fontisan
|
|
|
90
90
|
node.element_children.map { |child| parse_value(child) }
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
def self.create_doc_internal_subset(xml)
|
|
94
|
-
xml.doc.create_internal_subset("plist", PLIST_DTD, PLIST_NS)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
93
|
def self.emit_value(xml, value)
|
|
98
94
|
case value
|
|
99
95
|
when nil
|
|
100
96
|
# No <nil/> in Apple's plist DTD; use a sentinel string.
|
|
101
|
-
xml.
|
|
102
|
-
when true then xml.
|
|
103
|
-
when false then xml.
|
|
104
|
-
when Integer then xml.integer(value)
|
|
105
|
-
when Float then xml.real(value)
|
|
106
|
-
|
|
97
|
+
xml.string_
|
|
98
|
+
when true then xml.true_
|
|
99
|
+
when false then xml.false_
|
|
100
|
+
when Integer then xml.integer(value.to_s)
|
|
101
|
+
when Float then xml.real(value.to_s)
|
|
102
|
+
# An empty string serializes as a self-closed <string/>, like
|
|
103
|
+
# Nokogiri did; moxml keeps a paired form for a text child.
|
|
104
|
+
when String then value.empty? ? xml.string_ : xml.string(value)
|
|
107
105
|
when Symbol then xml.string(value.to_s)
|
|
108
106
|
when Array then xml.array { value.each { |v| emit_value(xml, v) } }
|
|
109
107
|
when Hash then xml.dict { emit_dict_body(xml, value) }
|
data/lib/fontisan/version.rb
CHANGED
data/lib/fontisan.rb
CHANGED
|
@@ -35,9 +35,25 @@ require "stringio"
|
|
|
35
35
|
require "tmpdir"
|
|
36
36
|
require "lutaml/model"
|
|
37
37
|
|
|
38
|
-
#
|
|
38
|
+
# The XML engine behind lutaml-model, chosen by what actually loads on
|
|
39
|
+
# this machine: leptris (pure-C99, precompiled everywhere) when its
|
|
40
|
+
# library loads, then nokogiri if present, then REXML (stdlib). The
|
|
41
|
+
# probe is load-bearing: leptris's precompiled linux builds need
|
|
42
|
+
# glibc >= 2.34, and forcing the adapter on an older glibc would crash
|
|
43
|
+
# every boot — e.g. inside the rake-compiler-dock cross builds.
|
|
44
|
+
xml_adapter = begin
|
|
45
|
+
require "leptris"
|
|
46
|
+
:leptris
|
|
47
|
+
rescue LoadError
|
|
48
|
+
begin
|
|
49
|
+
require "nokogiri"
|
|
50
|
+
:nokogiri
|
|
51
|
+
rescue LoadError
|
|
52
|
+
:rexml
|
|
53
|
+
end
|
|
54
|
+
end
|
|
39
55
|
Lutaml::Model::Config.configure do |config|
|
|
40
|
-
config.xml_adapter_type =
|
|
56
|
+
config.xml_adapter_type = xml_adapter
|
|
41
57
|
end
|
|
42
58
|
|
|
43
59
|
module Fontisan
|
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.
|
|
4
|
+
version: 0.4.50
|
|
5
5
|
platform: java
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -37,6 +37,20 @@ dependencies:
|
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: '2.5'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: leptris
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.9'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.9'
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
55
|
name: logger
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,19 +80,19 @@ dependencies:
|
|
|
66
80
|
- !ruby/object:Gem::Version
|
|
67
81
|
version: '0.8'
|
|
68
82
|
- !ruby/object:Gem::Dependency
|
|
69
|
-
name:
|
|
83
|
+
name: moxml
|
|
70
84
|
requirement: !ruby/object:Gem::Requirement
|
|
71
85
|
requirements:
|
|
72
86
|
- - "~>"
|
|
73
87
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: '
|
|
88
|
+
version: '0.6'
|
|
75
89
|
type: :runtime
|
|
76
90
|
prerelease: false
|
|
77
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
78
92
|
requirements:
|
|
79
93
|
- - "~>"
|
|
80
94
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '
|
|
95
|
+
version: '0.6'
|
|
82
96
|
- !ruby/object:Gem::Dependency
|
|
83
97
|
name: thor
|
|
84
98
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -192,7 +206,6 @@ files:
|
|
|
192
206
|
- benchmark/corpus/tiers.rb
|
|
193
207
|
- benchmark/tier_baseline.json
|
|
194
208
|
- benchmark/variation_quick_bench.rb
|
|
195
|
-
- build_mingw32_stub.rb
|
|
196
209
|
- docs/.gitignore
|
|
197
210
|
- docs/.vitepress/config.ts
|
|
198
211
|
- docs/.vitepress/theme/components/ApiMethod.vue
|
data/build_mingw32_stub.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rubygems/package"
|
|
4
|
-
|
|
5
|
-
# Builds the lib-only x64-mingw32 platform stub (the parsanol-ruby
|
|
6
|
-
# release protocol). The newest x64-mingw32 Ruby is 3.0, outside the
|
|
7
|
-
# cross-gem ABI set (3.2+), so a native gem cannot exist for that
|
|
8
|
-
# platform; the stub carries the pure-Ruby engine so the platform
|
|
9
|
-
# matrix on RubyGems is complete for resolvers and installs build
|
|
10
|
-
# nothing.
|
|
11
|
-
spec = Gem::Specification.load("fontisan.gemspec")
|
|
12
|
-
spec.platform = Gem::Platform.new("x64-mingw32")
|
|
13
|
-
spec.extensions = []
|
|
14
|
-
spec.files = spec.files.reject { |f| f.start_with?("ext/") }
|
|
15
|
-
Gem::Package.build(spec)
|