| 1 | local harfbuzz = require("harfbuzz") |
| 2 | |
| 3 | describe("harfbuzz module", function() |
| 4 | |
| 5 | it("returns a valid version string", function() |
| 6 | assert.are_equal("string", type(harfbuzz.version())) |
| 7 | end) |
| 8 | |
| 9 | it("returns a valid list of shapers", function() |
| 10 | local shapers = { harfbuzz.shapers } |
| 11 | assert.is_not.True(#shapers == 0) |
| 12 | end) |
| 13 | |
| 14 | describe("harfbuzz.Blob", function() |
| 15 | it("can be initialized with a string", function() |
| 16 | local s = "test string" |
| 17 | local blob = harfbuzz.Blob.new(s) |
| 18 | assert.are_equal(string.len(s), blob:get_length()) |
| 19 | end) |
| 20 | end) |
| 21 | |
| 22 | describe("harfbuzz.Face", function() |
| 23 | local face = harfbuzz.Face.new('fonts/notonastaliq.ttf') |
| 24 | it("can be initialized with a blob", function() |
| 25 | local fontfile = io.open('fonts/notonastaliq.ttf', "r") |
| 26 | local fontdata = fontfile:read("*all") |
| 27 | fontfile:close() |
| 28 | |
| 29 | local blob = harfbuzz.Blob.new(fontdata) |
| 30 | harfbuzz.Face.new_from_blob(blob,0) |
| 31 | end) |
| 32 | |
| 33 | it("can be initialized with a file and a font index", function() |
| 34 | harfbuzz.Face.new('fonts/notonastaliq.ttf',0) |
| 35 | end) |
| 36 | |
| 37 | it("can be initialized with a file only", function() |
| 38 | harfbuzz.Face.new('fonts/notonastaliq.ttf') |
| 39 | end) |
| 40 | |
| 41 | it("returns a valid upem value", function() |
| 42 | assert.are_equal(2048,face:get_upem()) |
| 43 | end) |
| 44 | |
| 45 | it("can return SFNT table", function() |
| 46 | local b = face:get_table(harfbuzz.Tag.new("OS/2")) |
| 47 | local d = b:get_data() |
| 48 | assert.are_equal(96,b:get_length()) |
| 49 | assert.are_equal(96,#d) |
| 50 | assert.are_equal(4,string.unpack(">H", d, 1)) |
| 51 | assert.are_equal(1155,string.unpack(">h", d, 3)) |
| 52 | assert.are_equal(5,string.unpack(">H", d, -2)) |
| 53 | end) |
| 54 | |
| 55 | it("can return table tags", function() |
| 56 | local t = face:get_table_tags() |
| 57 | assert.are_equal(14,#t) |
| 58 | assert.are_equal("GDEF",tostring(t[1])) |
| 59 | assert.are_equal("post",tostring(t[#t])) |
| 60 | end) |
| 61 | |
| 62 | it("can return glyph count", function() |
| 63 | assert.are_equal(1133,face:get_glyph_count()) |
| 64 | end) |
| 65 | |
| 66 | it("can return unicode characters supported by face", function() |
| 67 | local u = face:collect_unicodes() |
| 68 | assert.are_equal(267,#u) |
| 69 | assert.are_equal(0x0000,u[1]) |
| 70 | assert.are_equal('0',tostring(u[1])) |
| 71 | assert.are_equal(0xFEFF,u[#u]) |
| 72 | assert.are_equal('65279',tostring(u[#u])) |
| 73 | assert.are_equal('integer',math.type(u[1])) |
| 74 | end) |
| 75 | |
| 76 | it("can return face names", function() |
| 77 | assert.are_equal("Copyright 2014 Google Inc. All Rights Reserved.",face:get_name(harfbuzz.ot.NAME_ID_COPYRIGHT)) |
| 78 | assert.are_equal("Noto Nastaliq Urdu",face:get_name(harfbuzz.ot.NAME_ID_FONT_FAMILY)) |
| 79 | assert.are_equal("Regular",face:get_name(harfbuzz.ot.NAME_ID_FONT_SUBFAMILY)) |
| 80 | assert.are_equal("Noto Nastaliq Urdu",face:get_name(harfbuzz.ot.NAME_ID_FULL_NAME)) |
| 81 | assert.are_equal("NotoNastaliqUrdu",face:get_name(harfbuzz.ot.NAME_ID_POSTSCRIPT_NAME)) |
| 82 | assert.are_equal("Noto is a trademark of Google Inc.",face:get_name(harfbuzz.ot.NAME_ID_TRADEMARK)) |
| 83 | assert.are_equal(331,#face:get_name(harfbuzz.ot.NAME_ID_LICENSE)) |
| 84 | assert.are_equal(nil,face:get_name(harfbuzz.ot.NAME_ID_INVALID)) |
| 85 | end) |
| 86 | |
| 87 | it("can return face names with language", function() |
| 88 | local f = harfbuzz.Face.new('fonts/amiri-regular.ttf') |
| 89 | local ar = harfbuzz.Language.new("ar") |
| 90 | local en = harfbuzz.Language.new("en") |
| 91 | assert.are_equal("حقوق النشر 2010-2015، خالد حسني <khaled[email protected]>.",f:get_name(harfbuzz.ot.NAME_ID_COPYRIGHT, ar)) |
| 92 | assert.are_equal("Copyright (c) 2010-2015, Khaled Hosny <[email protected]>.\nPortions copyright (c) 2010, Sebastian Kosch <[email protected]>.",f:get_name(harfbuzz.ot.NAME_ID_COPYRIGHT, en)) |
| 93 | assert.are_equal("عادي",f:get_name(harfbuzz.ot.NAME_ID_FONT_SUBFAMILY, ar)) |
| 94 | assert.are_equal("Regular",f:get_name(harfbuzz.ot.NAME_ID_FONT_SUBFAMILY, en)) |
| 95 | assert.are_equal("إصدارة 000٫108",f:get_name(harfbuzz.ot.NAME_ID_VERSION_STRING, ar)) |
| 96 | assert.are_equal("Version 000.108 ",f:get_name(harfbuzz.ot.NAME_ID_VERSION_STRING, en)) |
| 97 | assert.are_equal("خالد حسني",f:get_name(harfbuzz.ot.NAME_ID_DESIGNER, ar)) |
| 98 | assert.are_equal("Khaled Hosny",f:get_name(harfbuzz.ot.NAME_ID_DESIGNER, en)) |
| 99 | assert.are_equal(512,#f:get_name(harfbuzz.ot.NAME_ID_DESCRIPTION, ar)) |
| 100 | assert.are_equal(263,#f:get_name(harfbuzz.ot.NAME_ID_DESCRIPTION, en)) |
| 101 | assert.are_equal("صِفْ خَلْقَ خَوْدٍ كَمِثْلِ ٱلشَّمْسِ إِذْ بَزَغَتْ يَحْظَىٰ ٱلضَّجِيعُ بِهَا نَجْلَاءَ مِعْطَارِ.",f:get_name(harfbuzz.ot.NAME_ID_SAMPLE_TEXT, ar)) |
| 102 | assert.are_equal("صِفْ خَلْقَ خَوْدٍ كَمِثْلِ ٱلشَّمْسِ إِذْ بَزَغَتْ يَحْظَىٰ ٱلضَّجِيعُ بِهَا نَجْلَاءَ مِعْطَارِ.",f:get_name(harfbuzz.ot.NAME_ID_SAMPLE_TEXT, en)) |
| 103 | end) |
| 104 | |
| 105 | it("can check color palettes", function() |
| 106 | local f = harfbuzz.Face.new('fonts/amiriquran-colored.ttf') |
| 107 | assert.are_equal(false,face:ot_color_has_palettes()) |
| 108 | assert.are_equal(true,f:ot_color_has_palettes()) |
| 109 | end) |
| 110 | |
| 111 | it("can return number of color palettes", function() |
| 112 | local f = harfbuzz.Face.new('fonts/amiriquran-colored.ttf') |
| 113 | assert.are_equal(0,face:ot_color_palette_get_count()) |
| 114 | assert.are_equal(1,f:ot_color_palette_get_count()) |
| 115 | end) |
| 116 | |
| 117 | it("can return palette colors", function() |
| 118 | local f = harfbuzz.Face.new('fonts/amiriquran-colored.ttf') |
| 119 | assert.are_equal(nil,face:ot_color_palette_get_colors()) |
| 120 | local colors = { |
| 121 | { alpha = 255, blue = 51, green = 51, red = 204, }, |
| 122 | { alpha = 255, blue = 80, green = 165, red = 0, }, |
| 123 | { alpha = 255, blue = 51, green = 153, red = 238, }, |
| 124 | { alpha = 255, blue = 153, green = 102, red = 51, }, |
| 125 | } |
| 126 | assert.are_same(colors,f:ot_color_palette_get_colors()) |
| 127 | end) |
| 128 | |
| 129 | it("can check color layers", function() |
| 130 | local f = harfbuzz.Face.new('fonts/amiriquran-colored.ttf') |
| 131 | assert.are_equal(false,face:ot_color_has_layers()) |
| 132 | assert.are_equal(true,f:ot_color_has_layers()) |
| 133 | end) |
| 134 | |
| 135 | it("can return glyph color layers", function() |
| 136 | local f = harfbuzz.Face.new('fonts/amiriquran-colored.ttf') |
| 137 | assert.are_equal(nil,face:ot_color_glyph_get_layers(100)) |
| 138 | assert.are_equal(nil,f:ot_color_glyph_get_layers(2)) |
| 139 | local layers = { |
| 140 | { color_index = 65535, glyph = 1341 }, |
| 141 | { color_index = 1, glyph = 1370 }, |
| 142 | } |
| 143 | assert.are_same(layers,f:ot_color_glyph_get_layers(100)) |
| 144 | end) |
| 145 | |
| 146 | it("can check PNG glyph support", function() |
| 147 | local f = harfbuzz.Face.new('fonts/notocoloremoji-subset.ttf') |
| 148 | assert.are_equal(false,face:ot_color_has_png()) |
| 149 | assert.are_equal(true,f:ot_color_has_png()) |
| 150 | end) |
| 151 | |
| 152 | it("can check SVG glyph support", function() |
| 153 | local f = harfbuzz.Face.new('fonts/TwitterColorEmoji-SVGinOT.ttf') |
| 154 | assert.are_equal(false,face:ot_color_has_svg()) |
| 155 | assert.are_equal(true,f:ot_color_has_svg()) |
| 156 | end) |
| 157 | |
| 158 | it("can return glyph color png", function() |
| 159 | local f = harfbuzz.Face.new('fonts/TwitterColorEmoji-SVGinOT.ttf') |
| 160 | |
| 161 | assert.are_equal(nil,face:ot_color_glyph_get_svg(100)) |
| 162 | assert.are_equal(nil,f:ot_color_glyph_get_svg(0)) |
| 163 | assert.are_same(751,f:ot_color_glyph_get_svg(5):get_length()) |
| 164 | assert.are_same(804,f:ot_color_glyph_get_svg(6):get_length()) |
| 165 | assert.are_same("<?xml version='1.0' encoding='UTF-8'?>",f:ot_color_glyph_get_svg(5):get_data():sub(1, 38)) |
| 166 | end) |
| 167 | |
| 168 | it("can return script tags", function() |
| 169 | local t |
| 170 | local tags = { |
| 171 | harfbuzz.Tag.new("arab"), |
| 172 | harfbuzz.Tag.new("dflt"), |
| 173 | harfbuzz.Tag.new("latn"), |
| 174 | } |
| 175 | t = face:ot_layout_get_script_tags(harfbuzz.Tag.new("GSUB")) |
| 176 | assert.are_same(tags, t) |
| 177 | t = face:ot_layout_get_script_tags(harfbuzz.Tag.new("GPOS")) |
| 178 | assert.are_same({ tags[1] }, t) |
| 179 | end) |
| 180 | |
| 181 | it("can return language tags", function() |
| 182 | local t |
| 183 | local tags = { |
| 184 | harfbuzz.Tag.new("ARA "), |
| 185 | harfbuzz.Tag.new("FAR "), |
| 186 | harfbuzz.Tag.new("KSH "), |
| 187 | harfbuzz.Tag.new("SND "), |
| 188 | harfbuzz.Tag.new("URD "), |
| 189 | } |
| 190 | t = face:ot_layout_get_language_tags(harfbuzz.Tag.new("GSUB"), 0) |
| 191 | assert.are_same(tags, t) |
| 192 | t = face:ot_layout_get_language_tags(harfbuzz.Tag.new("GPOS"), 0) |
| 193 | assert.are_equal(nil, t) |
| 194 | end) |
| 195 | |
| 196 | it("can return feature tags", function() |
| 197 | local t, tags |
| 198 | tags = { |
| 199 | harfbuzz.Tag.new("ccmp"), |
| 200 | harfbuzz.Tag.new("isol"), |
| 201 | harfbuzz.Tag.new("init"), |
| 202 | harfbuzz.Tag.new("medi"), |
| 203 | harfbuzz.Tag.new("fina"), |
| 204 | harfbuzz.Tag.new("rlig"), |
| 205 | } |
| 206 | t = face:ot_layout_get_feature_tags(harfbuzz.Tag.new("GSUB"), 0, 0) |
| 207 | assert.are_same(tags, t) |
| 208 | tags = { |
| 209 | harfbuzz.Tag.new("curs"), |
| 210 | harfbuzz.Tag.new("mark"), |
| 211 | harfbuzz.Tag.new("mkmk"), |
| 212 | } |
| 213 | t = face:ot_layout_get_feature_tags(harfbuzz.Tag.new("GPOS"), 0, harfbuzz.ot.LAYOUT_DEFAULT_LANGUAGE_INDEX) |
| 214 | assert.are_same(tags, t) |
| 215 | end) |
| 216 | |
| 217 | it("can find scripts, languages and features", function() |
| 218 | local r, i |
| 219 | r, i = face:ot_layout_find_script(harfbuzz.Tag.new("GSUB"), harfbuzz.Tag.new("latn")) |
| 220 | assert.True(r) |
| 221 | assert.are_same(2, i) |
| 222 | r, i = face:ot_layout_find_language(harfbuzz.Tag.new("GSUB"), i, harfbuzz.Tag.new("ENG ")) |
| 223 | assert.False(r) |
| 224 | assert.are_same(harfbuzz.ot.LAYOUT_DEFAULT_LANGUAGE_INDEX, i) |
| 225 | r, i = face:ot_layout_find_language(harfbuzz.Tag.new("GSUB"), 0, harfbuzz.Tag.new("ARA ")) |
| 226 | assert.True(r) |
| 227 | assert.are_same(0, i) |
| 228 | r, i = face:ot_layout_find_feature(harfbuzz.Tag.new("GSUB"), 0, i, harfbuzz.Tag.new("rlig")) |
| 229 | assert.True(r) |
| 230 | assert.are_same(13, i) |
| 231 | |
| 232 | r, i = face:ot_layout_find_feature(harfbuzz.Tag.new("GSUB"), 1, harfbuzz.ot.LAYOUT_DEFAULT_LANGUAGE_INDEX, harfbuzz.Tag.new("rlig")) |
| 233 | assert.True(r) |
| 234 | assert.are_same(13, i) |
| 235 | end) |
| 236 | |
| 237 | it("can return variation axes", function() |
| 238 | local f = harfbuzz.Face.new('fonts/STIXTwoText[wght].ttf') |
| 239 | |
| 240 | assert.is_same(true, f:ot_var_has_data()) |
| 241 | local axes = f:ot_var_get_axis_infos() |
| 242 | assert.are_same(1, #axes) |
| 243 | assert.are_same(harfbuzz.Tag.new("wght"), axes[1].tag) |
| 244 | assert.are_same(1, axes[1].axis_index) |
| 245 | assert.are_same(400, axes[1].min_value) |
| 246 | assert.are_same(400, axes[1].default_value) |
| 247 | assert.are_same(700, axes[1].max_value) |
| 248 | assert.are_same(0, axes[1].flags) |
| 249 | assert.are_same("Weight", f:get_name(axes[1].name_id)) |
| 250 | end) |
| 251 | |
| 252 | it("can find variation axis", function() |
| 253 | local f = harfbuzz.Face.new('fonts/STIXTwoText[wght].ttf') |
| 254 | |
| 255 | local axis = f:ot_var_find_axis_info(harfbuzz.Tag.new("wght")) |
| 256 | assert.is_not_nil(axis) |
| 257 | assert.are_same(harfbuzz.Tag.new("wght"), axis.tag) |
| 258 | assert.are_same(1, axis.axis_index) |
| 259 | assert.are_same(400, axis.min_value) |
| 260 | assert.are_same(400, axis.default_value) |
| 261 | assert.are_same(700, axis.max_value) |
| 262 | assert.are_same(0, axis.flags) |
| 263 | assert.are_same("Weight", f:get_name(axis.name_id)) |
| 264 | end) |
| 265 | |
| 266 | it("can return named instances", function() |
| 267 | local f = harfbuzz.Face.new('fonts/STIXTwoText[wght].ttf') |
| 268 | |
| 269 | local instances = f:ot_var_named_instance_get_infos() |
| 270 | assert.are_same(4, #instances) |
| 271 | assert.are_same(3, instances[3].index) |
| 272 | assert.are_same("SemiBold", f:get_name(instances[3].subfamily_name_id)) |
| 273 | assert.are_same(nil, f:get_name(instances[3].postscript_name_id)) |
| 274 | assert.are_same(600, f:ot_var_named_instance_get_design_coords(3)) |
| 275 | end) |
| 276 | |
| 277 | it("can normalize variations", function() |
| 278 | local f = harfbuzz.Face.new('fonts/STIXTwoText[wght].ttf') |
| 279 | |
| 280 | local normalized, after = f:ot_var_normalize_variations(harfbuzz.Variation.new("wght=400")) |
| 281 | assert.is_nil(after) |
| 282 | assert.are_same(0, normalized) |
| 283 | |
| 284 | normalized = f:ot_var_normalize_variations(harfbuzz.Variation.new("wght=700")) |
| 285 | assert.are_same(1<<14, normalized) |
| 286 | |
| 287 | normalized, after = f:ot_var_normalize_coords(700) |
| 288 | assert.is_nil(after) |
| 289 | assert.are_same(1<<14, normalized) |
| 290 | |
| 291 | normalized = f:ot_var_normalize_coords(400) |
| 292 | assert.are_same(0, normalized) |
| 293 | end) |
| 294 | end) |
| 295 | |
| 296 | describe("harfbuzz.Font", function() |
| 297 | local face = harfbuzz.Face.new('fonts/notonastaliq.ttf') |
| 298 | it("can be initialized with a face", function() |
| 299 | harfbuzz.Font.new(face) |
| 300 | end) |
| 301 | |
| 302 | it("has a default scale set to the fonts upem", function() |
| 303 | local font = harfbuzz.Font.new(face) |
| 304 | local upem = face:get_upem() |
| 305 | local xs, ys = font:get_scale() |
| 306 | assert.are_equal(upem, xs) |
| 307 | assert.are_equal(upem, ys) |
| 308 | end) |
| 309 | |
| 310 | it("can set the scale of the font using set_scale", function() |
| 311 | local font = harfbuzz.Font.new(face) |
| 312 | font:set_scale(1024,2048) |
| 313 | local xs, ys = font:get_scale() |
| 314 | assert.are_equal(1024, xs) |
| 315 | assert.are_equal(2048, ys) |
| 316 | end) |
| 317 | |
| 318 | it("can get glyph extents using get_glyph_extents", function() |
| 319 | local font = harfbuzz.Font.new(face) |
| 320 | local extents = font:get_glyph_extents(0) |
| 321 | assert.are_equal(145, extents.x_bearing) |
| 322 | assert.are_equal(2452, extents.y_bearing) |
| 323 | assert.are_equal(1553, extents.width) |
| 324 | assert.are_equal(-2452, extents.height) |
| 325 | extents = font:get_glyph_extents(1) |
| 326 | assert.are_equal(0, extents.x_bearing) |
| 327 | assert.are_equal(0, extents.y_bearing) |
| 328 | assert.are_equal(0, extents.width) |
| 329 | assert.are_equal(0, extents.height) |
| 330 | end) |
| 331 | |
| 332 | it("can get font extents", function() |
| 333 | local font = harfbuzz.Font.new(face) |
| 334 | local extents = font:get_h_extents(0) |
| 335 | assert.are_equal(3900, extents.ascender) |
| 336 | assert.are_equal(-1220, extents.descender) |
| 337 | assert.are_equal(0, extents.line_gap) |
| 338 | extents = font:get_v_extents(1) |
| 339 | assert.are_equal(nil, extents) |
| 340 | end) |
| 341 | |
| 342 | it("can get glyph name using get_glyph_name", function() |
| 343 | local font = harfbuzz.Font.new(face) |
| 344 | assert.are_equal(".notdef", font:get_glyph_name(0)) |
| 345 | assert.are_equal("null", font:get_glyph_name(1)) |
| 346 | end) |
| 347 | |
| 348 | it("can get glyph using get_glyph_from_name", function() |
| 349 | local font = harfbuzz.Font.new(face) |
| 350 | assert.are_equal(0, font:get_glyph_from_name(".notdef")) |
| 351 | assert.are_equal(1, font:get_glyph_from_name("null")) |
| 352 | end) |
| 353 | |
| 354 | it("can get glyph advance using get_glyph_h_advance", function() |
| 355 | local font = harfbuzz.Font.new(face) |
| 356 | assert.are_equal(1843, font:get_glyph_h_advance(0)) |
| 357 | assert.are_equal(0, font:get_glyph_h_advance(1)) |
| 358 | end) |
| 359 | |
| 360 | it("can get glyph advance using get_glyph_v_advance", function() |
| 361 | local font = harfbuzz.Font.new(face) |
| 362 | assert.are_equal(-5120, font:get_glyph_v_advance(0)) |
| 363 | assert.are_equal(-5120, font:get_glyph_v_advance(1)) |
| 364 | end) |
| 365 | |
| 366 | it("can get nominal glyph for codepoint", function() |
| 367 | local font = harfbuzz.Font.new(face) |
| 368 | assert.are_equal(nil, font:get_nominal_glyph(0x0041)) |
| 369 | assert.are_equal(858, font:get_nominal_glyph(0x0627)) |
| 370 | end) |
| 371 | |
| 372 | it("can return glyph color png", function() |
| 373 | local font = harfbuzz.Font.new(face) |
| 374 | local f = harfbuzz.Font.new(harfbuzz.Face.new('fonts/notocoloremoji-subset.ttf')) |
| 375 | |
| 376 | assert.are_equal(nil,font:ot_color_glyph_get_png(100)) |
| 377 | assert.are_equal(nil,f:ot_color_glyph_get_png(0)) |
| 378 | assert.are_same(2233,f:ot_color_glyph_get_png(1):get_length()) |
| 379 | assert.are_same(2857,f:ot_color_glyph_get_png(2):get_length()) |
| 380 | assert.are_same("\137PNG",f:ot_color_glyph_get_png(2):get_data():sub(1, 4)) |
| 381 | end) |
| 382 | |
| 383 | it("can set variations", function() |
| 384 | local f = harfbuzz.Font.new(harfbuzz.Face.new('fonts/STIXTwoText[wght].ttf')) |
| 385 | |
| 386 | f:set_variations(harfbuzz.Variation.new("wght=500")) |
| 387 | local normalized1, after1 = f:get_var_coords_normalized() |
| 388 | assert.is_nil(after1) |
| 389 | assert.are_same(5174, normalized1) |
| 390 | |
| 391 | f:set_var_coords_design(600) |
| 392 | local normalized2, after2 = f:get_var_coords_normalized() |
| 393 | assert.is_nil(after2) |
| 394 | assert.are_same(10348, normalized2) |
| 395 | |
| 396 | f:set_var_coords_normalized(1<<13) |
| 397 | local normalized3, after3 = f:get_var_coords_normalized() |
| 398 | assert.is_nil(after3) |
| 399 | assert.are_same(1<<13, normalized3) |
| 400 | end) |
| 401 | |
| 402 | if not harfbuzz:version():match'^2%.' then |
| 403 | it("allows querying style parameters", function() |
| 404 | local font = harfbuzz.Font.new(face) |
| 405 | local wght = font:style_get_value(harfbuzz.Tag.new"wght") |
| 406 | assert.are_equal(400, wght) |
| 407 | end) |
| 408 | end |
| 409 | |
| 410 | it("allows querying variation metrics", function() |
| 411 | local f = harfbuzz.Font.new(harfbuzz.Face.new('fonts/STIXTwoText[wght].ttf')) |
| 412 | f:set_variations(harfbuzz.Variation.new("wght=500")) |
| 413 | |
| 414 | local subscript_offset = f:ot_metrics_get_x_variation(harfbuzz.Tag.new"sbxo") |
| 415 | local cap_height = f:ot_metrics_get_y_variation(harfbuzz.Tag.new"cpht") |
| 416 | assert.are_equal(0, cap_height) |
| 417 | assert.are_equal(0, subscript_offset) |
| 418 | end) |
| 419 | end) |
| 420 | |
| 421 | describe("harfbuzz.Feature", function() |
| 422 | it("can be initialised with a valid feature string", function() |
| 423 | harfbuzz.Feature.new('kern') |
| 424 | harfbuzz.Feature.new('+kern') |
| 425 | end) |
| 426 | |
| 427 | it("throws an error when trying to initialise a new Feature with an invalid string", function() |
| 428 | assert.are_equal(nil, harfbuzz.Feature.new('')) |
| 429 | assert.are_equal(nil, harfbuzz.Feature.new('#kern')) |
| 430 | end) |
| 431 | |
| 432 | it("has a valid tostring value", function() |
| 433 | local fs = 'kern' |
| 434 | local f = harfbuzz.Feature.new(fs) |
| 435 | assert.are_equal(fs, tostring(f)) |
| 436 | end) |
| 437 | |
| 438 | it("has visible fields", function() |
| 439 | local f = harfbuzz.Feature.new('-kern') |
| 440 | assert.are_equal(tostring(f.tag), 'kern') |
| 441 | assert.are_equal(f.value, 0) |
| 442 | assert.are_equal(f.start, nil) |
| 443 | assert.are_equal(f._end, nil) |
| 444 | |
| 445 | f = harfbuzz.Feature.new('aalt[3:5]=4') |
| 446 | assert.are_equal(tostring(f.tag), 'aalt') |
| 447 | assert.are_equal(f.value, 4) |
| 448 | assert.are_equal(f.start, 3) |
| 449 | assert.are_equal(f._end, 5) |
| 450 | end) |
| 451 | |
| 452 | it("has editable fields", function() |
| 453 | local f = harfbuzz.Feature.new('-kern') |
| 454 | f.tag, f.value, f.start, f._end = harfbuzz.Tag.new"aalt", 4, 3, 5 |
| 455 | assert.are_equal(tostring(f), "aalt[3:5]=4") |
| 456 | |
| 457 | f.tag, f.value, f.start, f._end = harfbuzz.Tag.new"harf", 0, nil, nil |
| 458 | assert.are_equal(tostring(f), "-harf") |
| 459 | end) |
| 460 | end) |
| 461 | |
| 462 | describe("harfbuzz.Variation", function() |
| 463 | it("can be initialised with a valid variation string", function() |
| 464 | harfbuzz.Variation.new('wght=default') |
| 465 | harfbuzz.Variation.new('wght=400') |
| 466 | harfbuzz.Variation.new('wght=-20') |
| 467 | end) |
| 468 | |
| 469 | it("throws an error when trying to initialise a new variation with an invalid string", function() |
| 470 | assert.are_equal(nil, harfbuzz.Variation.new('')) |
| 471 | assert.are_equal(nil, harfbuzz.Variation.new('wght')) |
| 472 | end) |
| 473 | |
| 474 | it("has a valid tostring value", function() |
| 475 | local vs = 'wght=200' |
| 476 | local v = harfbuzz.Variation.new(vs) |
| 477 | assert.are_equal(vs, tostring(v)) |
| 478 | end) |
| 479 | |
| 480 | it("has visible fields", function() |
| 481 | local v = harfbuzz.Variation.new('wght=400') |
| 482 | assert.are_equal(tostring(v.tag), 'wght') |
| 483 | assert.are_equal(v.value, 400) |
| 484 | |
| 485 | v = harfbuzz.Variation.new('slnt=-7.5') |
| 486 | assert.are_equal(tostring(v.tag), 'slnt') |
| 487 | assert.are_equal(v.value, -7.5) |
| 488 | end) |
| 489 | |
| 490 | it("has editable fields", function() |
| 491 | local f = harfbuzz.Variation.new('slnt=5') |
| 492 | f.tag, f.value = harfbuzz.Tag.new"wght", 7 |
| 493 | assert.are_equal(tostring(f), "wght=7") |
| 494 | |
| 495 | f.tag, f.value = harfbuzz.Tag.new"hght", 0 |
| 496 | assert.are_equal(tostring(f), "hght=0") |
| 497 | end) |
| 498 | end) |
| 499 | |
| 500 | describe("harfbuzz.Tag", function() |
| 501 | it("can be initialised with a valid tag string", function() |
| 502 | harfbuzz.Tag.new('Zyyy') |
| 503 | end) |
| 504 | |
| 505 | it("can be initialised to NONE with nil or empty argument", function() |
| 506 | local t = harfbuzz.Tag.new() |
| 507 | assert.are_equal(harfbuzz.Tag.NONE, t) |
| 508 | t = harfbuzz.Tag.new(nil) |
| 509 | assert.are_equal(harfbuzz.Tag.NONE, t) |
| 510 | end) |
| 511 | |
| 512 | it("has a valid tostring value", function() |
| 513 | local ts = 'Arab' |
| 514 | local t = harfbuzz.Tag.new(ts) |
| 515 | assert.are_equal(ts, tostring(t)) |
| 516 | end) |
| 517 | |
| 518 | it("has a valid equality check functions", function() |
| 519 | local ts = 'Arab' |
| 520 | local t1 = harfbuzz.Tag.new(ts) |
| 521 | local t2 = harfbuzz.Tag.new(ts) |
| 522 | local t3 = harfbuzz.Tag.new("Latn") |
| 523 | assert.are_equal(t1, t2) |
| 524 | assert.are_not_equal(t1, t3) |
| 525 | end) |
| 526 | |
| 527 | it("has a preset value for NONE", function() |
| 528 | local n = harfbuzz.Tag.NONE |
| 529 | assert.is_not_nil(n) |
| 530 | assert.are_equal("", tostring(n)) |
| 531 | assert.are_equal(harfbuzz.Tag.NONE, harfbuzz.Tag.new("")) |
| 532 | end) |
| 533 | end) |
| 534 | |
| 535 | describe("harfbuzz.Script", function() |
| 536 | it("can be initialised with a string", function() |
| 537 | harfbuzz.Script.new('Arab') |
| 538 | end) |
| 539 | |
| 540 | it("can be initialised to INVALID with nil or empty argument", function() |
| 541 | local t = harfbuzz.Script.new() |
| 542 | assert.are_equal(harfbuzz.Script.INVALID, t) |
| 543 | t = harfbuzz.Script.new(nil) |
| 544 | assert.are_equal(harfbuzz.Script.INVALID, t) |
| 545 | end) |
| 546 | |
| 547 | it("can be initialised with a tag", function() |
| 548 | local ts = "Arab" |
| 549 | local s = harfbuzz.Script.from_iso15924_tag(harfbuzz.Tag.new(ts)) |
| 550 | assert.are_equal(ts, tostring(s)) |
| 551 | end) |
| 552 | |
| 553 | it("can be converted to a tag", function() |
| 554 | local s = 'Arab' |
| 555 | local sc = harfbuzz.Script.new(s) |
| 556 | assert.are_equal(s, tostring(sc:to_iso15924_tag())) |
| 557 | end) |
| 558 | |
| 559 | it("has a valid tostring value", function() |
| 560 | local ts = 'Arab' |
| 561 | local t = harfbuzz.Script.new(ts) |
| 562 | assert.are_equal(ts, tostring(t)) |
| 563 | end) |
| 564 | |
| 565 | it("has a valid equality check functions", function() |
| 566 | local ts = 'Arab' |
| 567 | local t1 = harfbuzz.Script.new(ts) |
| 568 | local t2 = harfbuzz.Script.new(ts) |
| 569 | local t3 = harfbuzz.Script.new("Latn") |
| 570 | assert.are_equal(t1, t2) |
| 571 | assert.are_not_equal(t1, t3) |
| 572 | end) |
| 573 | end) |
| 574 | |
| 575 | describe("harfbuzz.Direction", function() |
| 576 | it("can be initialised with a valid tag string", function() |
| 577 | harfbuzz.Direction.new('LTR') |
| 578 | end) |
| 579 | |
| 580 | it("can be initialised with invalid strings", function() |
| 581 | local d1 = harfbuzz.Direction.new("i") |
| 582 | local d2 = harfbuzz.Direction.new("inv") |
| 583 | |
| 584 | assert.are_equal(d1, d2) |
| 585 | assert.are_equal("invalid", tostring(d1)) |
| 586 | end) |
| 587 | |
| 588 | it("has a valid tostring value", function() |
| 589 | local ts = 'ltr' |
| 590 | local t = harfbuzz.Direction.new(ts) |
| 591 | assert.are_equal(ts, tostring(t)) |
| 592 | |
| 593 | t = harfbuzz.Direction.new("LTR") |
| 594 | assert.are_equal(ts, tostring(t)) |
| 595 | end) |
| 596 | |
| 597 | it("has a valid equality check functions", function() |
| 598 | local ts = 'ltr' |
| 599 | local t1 = harfbuzz.Direction.new(ts) |
| 600 | local t2 = harfbuzz.Direction.new(ts) |
| 601 | local t3 = harfbuzz.Direction.new("rtl") |
| 602 | assert.are_equal(t1, t2) |
| 603 | assert.are_not_equal(t1, t3) |
| 604 | end) |
| 605 | |
| 606 | it("has a is_valid function", function() |
| 607 | assert.True(harfbuzz.Direction.LTR:is_valid()) |
| 608 | assert.False(harfbuzz.Direction.INVALID:is_valid()) |
| 609 | end) |
| 610 | |
| 611 | it("has a is_horizontal function", function() |
| 612 | assert.True(harfbuzz.Direction.LTR:is_horizontal()) |
| 613 | assert.False(harfbuzz.Direction.TTB:is_horizontal()) |
| 614 | end) |
| 615 | |
| 616 | it("has a is_vertical function", function() |
| 617 | assert.True(harfbuzz.Direction.TTB:is_vertical()) |
| 618 | assert.False(harfbuzz.Direction.LTR:is_vertical()) |
| 619 | end) |
| 620 | |
| 621 | it("has a is_forward function", function() |
| 622 | assert.True(harfbuzz.Direction.LTR:is_forward()) |
| 623 | assert.False(harfbuzz.Direction.RTL:is_forward()) |
| 624 | end) |
| 625 | |
| 626 | it("has a is_backward function", function() |
| 627 | assert.True(harfbuzz.Direction.RTL:is_backward()) |
| 628 | assert.False(harfbuzz.Direction.LTR:is_backward()) |
| 629 | end) |
| 630 | end) |
| 631 | |
| 632 | describe("harfbuzz.Language", function() |
| 633 | it("can be initialised with a valid language string", function() |
| 634 | harfbuzz.Language.new('urd') |
| 635 | end) |
| 636 | |
| 637 | it("can be initialised to INVALID with nil or empty argument", function() |
| 638 | local t = harfbuzz.Language.new() |
| 639 | assert.are_equal(harfbuzz.Language.INVALID, t) |
| 640 | t = harfbuzz.Language.new(nil) |
| 641 | assert.are_equal(harfbuzz.Language.INVALID, t) |
| 642 | end) |
| 643 | |
| 644 | it("has a valid tostring value", function() |
| 645 | local ts = 'urd' |
| 646 | local t = harfbuzz.Language.new(ts) |
| 647 | assert.are_equal(ts, tostring(t)) |
| 648 | end) |
| 649 | |
| 650 | it("has a valid equality check functions", function() |
| 651 | local ts = 'urd' |
| 652 | local t1 = harfbuzz.Language.new(ts) |
| 653 | local t2 = harfbuzz.Language.new(ts) |
| 654 | local t3 = harfbuzz.Language.new("hin") |
| 655 | assert.are_equal(t1, t2) |
| 656 | assert.are_not_equal(t1, t3) |
| 657 | end) |
| 658 | |
| 659 | it("has a preset value for INVALID", function() |
| 660 | local n = harfbuzz.Language.INVALID |
| 661 | assert.is_not_nil(n) |
| 662 | assert.are_equal(harfbuzz.Language.INVALID, harfbuzz.Language.new()) |
| 663 | assert.are_equal("", tostring(n)) |
| 664 | end) |
| 665 | end) |
| 666 | |
| 667 | describe("harfbuzz.unicode", function() |
| 668 | describe("script function returns a valid script for a codepoint",function() |
| 669 | local s = harfbuzz.unicode.script(0x0020) |
| 670 | assert.are_equal(harfbuzz.Script.COMMON, s) |
| 671 | s = harfbuzz.unicode.script(0x0041) |
| 672 | assert.are_equal(harfbuzz.Script.new("Latn"), s) |
| 673 | end) |
| 674 | end) |
| 675 | end) |