Debian Codegraph @

texk/web2c/luatexdir/luaharfbuzz/spec/subset_spec.lua

raw symbols SCIP
1 package.path = "./src/?.lua;./src/?/init.lua;" .. package.path
2
3 local harfbuzzsubset = require("harfbuzzsubset")
4 local harfbuzz = require("harfbuzz")
5
6 describe("harfbuzz module", function()
7 it("can be required when subset module is also required", function()
8 assert.is_not_nil(harfbuzz)
9 assert.is_not_nil(harfbuzzsubset)
10 end)
11 end)
12
13
14 describe("harfbuzzsubset basic usage", function()
15 local hb, hb_subset
16 local font_path = "fonts/AdventPro-VariableFont_wdth,wght.ttf"
17
18 setup(function()
19 hb = require "harfbuzz"
20 hb_subset = require "harfbuzzsubset"
21 end)
22
23 it("returns a valid version string", function()
24 assert.are_equal("string", type(hb_subset.version()))
25 end)
26
27 it("creates a subset input object", function()
28 local input = hb_subset.SubsetInput.new()
29 assert.truthy(input)
30 -- minimal test of methods existing
31 assert.is_function(input.keep_everything)
32 assert.is_function(input.pin_axis_location)
33 end)
34
35 it("can subset a variable font without errors", function()
36 local face = hb.Face.new(font_path)
37 local wght = hb.Tag.new("wght")
38 local wdth = hb.Tag.new("wdth")
39
40 local input = hb_subset.SubsetInput.new()
41 input:pin_axis_location(face, wght, 100)
42 input:pin_axis_location(face, wdth, 100)
43 input:keep_everything()
44
45 local ok, new_face = pcall(function()
46 return hb_subset.subset(face, input)
47 end)
48
49 assert.is_true(ok)
50 assert.truthy(new_face)
51 assert.are_not.equal(face, new_face)
52 end)
53
54 it("produces a non-empty blob after subsetting", function()
55 local face = hb.Face.new(font_path)
56 local wght = hb.Tag.new("wght")
57 local wdth = hb.Tag.new("wdth")
58
59 local input = hb_subset.SubsetInput.new()
60 input:pin_axis_location(face, wght, 100)
61 input:pin_axis_location(face, wdth, 100)
62 input:keep_everything()
63
64 local new_face = hb_subset.subset(face, input)
65
66 local blob = new_face:blob()
67 assert.truthy(blob)
68 assert.is_function(blob.get_data)
69
70 local data = blob:get_data()
71 assert.is_string(data)
72 assert.is_true(#data > 0)
73 end)
74
75 it("preserves glyph count when keep_everything is used", function()
76 local face = hb.Face.new(font_path)
77 local orig_glyphs = face:get_glyph_count()
78
79 local wght = hb.Tag.new("wght")
80 local wdth = hb.Tag.new("wdth")
81 local input = hb_subset.SubsetInput.new()
82 input:pin_axis_location(face, wght, 100)
83 input:pin_axis_location(face, wdth, 100)
84 input:keep_everything()
85
86 local new_face = hb_subset.subset(face, input)
87 local subset_glyphs = new_face:get_glyph_count()
88
89 assert.equals(orig_glyphs, subset_glyphs)
90 end)
91
92 it("produces different blobs for different axis locations", function()
93 local face = hb.Face.new(font_path)
94 local wght = hb.Tag.new("wght")
95 local wdth = hb.Tag.new("wdth")
96
97 local input1 = hb_subset.SubsetInput.new()
98 input1:pin_axis_location(face, wght, 100)
99 input1:pin_axis_location(face, wdth, 100)
100 input1:keep_everything()
101 local face_light = hb_subset.subset(face, input1)
102 local blob_light = face_light:blob():get_data()
103
104 local input2 = hb_subset.SubsetInput.new()
105 input2:pin_axis_location(face, wght, 900)
106 input2:pin_axis_location(face, wdth, 100)
107 input2:keep_everything()
108 local face_bold = hb_subset.subset(face, input2)
109 local blob_bold = face_bold:blob():get_data()
110
111 assert.is_true(
112 blob_light ~= blob_bold,
113 ("expected different blobs for axis locations, but they are identical (len=%d bytes)")
114 :format(#blob_light)
115 )
116 assert.is_true(#blob_light > 0, "blob_light is empty")
117 assert.is_true(#blob_bold > 0, "blob_bold is empty")
118 end)
119
120 it("reduces glyph count when subsetting to a single Unicode", function()
121 local face = hb.Face.new(font_path)
122 local orig_glyphs = face:get_glyph_count()
123
124 local input = hb_subset.SubsetInput.new()
125
126 local uset = input:unicode_set()
127 uset:add(0x41) -- oder string.byte("A")
128
129 local new_face = hb_subset.subset(face, input)
130 local subset_glyphs = new_face:get_glyph_count()
131
132 -- Sanity-Checks mit vernünftiger Fehlermeldung, ohne Binärmüll:
133 assert.is_true(
134 subset_glyphs > 0,
135 ("expected subset glyph count > 0, got %d"):format(subset_glyphs)
136 )
137 assert.is_true(
138 subset_glyphs < orig_glyphs,
139 ("expected fewer glyphs after subsetting, got %d (orig %d)")
140 :format(subset_glyphs, orig_glyphs)
141 )
142 end)
143 end)