At the moment the documentation of the library is a raw "html-to-pdf"
rendering of the \type{index.html} file under \type{luaharfbuzz/docs}
folder of the source code. The example is almost the verbatim copy
of the file under \type{luaharfbuzz/examples}.
\page
The example is (a small modification of) the file \type{core_types.lua}
and it requires the file \type{harfbuzz.lua}; both are
under \type{luaharfbuzz} folder of the source code.
The fonts \type{notonastaliq.ttf} and \type{amiri-regular.ttf'} are under
\type{luaharfbuzz/fonts}.
\blank[3*big]
\startbuffer[hbmod]
local hb = require("luaharfbuzz")
-- special tags
hb.Tag.NONE = hb.Tag.new()
-- special script codes (ISO 15924)
hb.Script.COMMON = hb.Script.new("Zyyy")
hb.Script.INHERITED = hb.Script.new("Zinh")
hb.Script.UNKNOWN = hb.Script.new("Zzzz")
hb.Script.INVALID = hb.Script.from_iso15924_tag(hb.Tag.NONE)
-- Apply options to buffer if they are set.
if options.language then buf:set_language(options.language) end
if options.script then buf:set_script(options.script) end
if options.direction then buf:set_direction(options.direction) end
-- Guess segment properties, in case all steps above have failed
-- to set the right properties.
buf:guess_segment_properties()
local features = {}
-- Parse features
if type(options.features) == "string" then
for fs in string.gmatch(options.features, '([^,]+)') do
local feature = hb.Feature.new(fs)
if feature then
table.insert(features, hb.Feature.new(fs))
else
error(string.format("Invalid feature string: '%s'", fs))
end
end
elseif type(options.features) == "table" then
features = options.features
elseif options.features then -- non-nil but not a string or table
error("Invalid features option")
end
return hb.shape_full(font,buf,features,options.shapers or {})
end
\startbuffer[hbex]
local harfbuzz = require('harfbuzz')
-- Harfbuzz API Version
print("Harfbuzz API version", harfbuzz.version())
-- Shapers available
print("Shapers:", harfbuzz.shapers())
-- harfbuzz.Face
local face = harfbuzz.Face.new('notonastaliq.ttf')
print('\nFace upem = '..face:get_upem())
-- harfbuzz.Font
local font = harfbuzz.Font.new(face)
local xs, xy = font:get_scale()
print("\nDefault font scale = X: "..xs..", Y: "..xy)
-- harfbuzz.Buffer
local text = "یہ" -- U+06CC U+06C1
local buf = harfbuzz.Buffer.new()
buf:add_utf8(text)
-- harfbuzz.shape (Shapes text)
print("\nShaping '"..text.."' set with Noto Nastaliq Urdu")
harfbuzz.shape(font, buf, { language = harfbuzz.Language.new("urd"),
script = harfbuzz.Script.new("Arab"), direction = harfbuzz.Direction.RTL})
local glyphs = buf:get_glyphs()
print("No. of glyphs", #glyphs)
for k,v in pairs(glyphs) do
print(k)
for k1,v1 in pairs(v) do
print("",k1,v1)
end
end
local opts = { language = harfbuzz.Language.new("eng"),
script = harfbuzz.Script.new("Latn"), direction = harfbuzz.Direction.LTR }
local amiri_face = harfbuzz.Face.new('amiri-regular.ttf')
local amiri_font = harfbuzz.Font.new(amiri_face)
-- shaping '123' w/o features
print("\nShaping '123' set with Amiri Regular and no features")
buf= harfbuzz.Buffer.new()
buf:add_utf8("123")
harfbuzz.shape(amiri_font, buf, opts)
glyphs = buf:get_glyphs()
for k,v in pairs(glyphs) do
print(k)
for k1,v1 in pairs(v) do
print("",k1,v1)
end
end
-- shaping '123' with '+numr' (numerators)
print("\nShaping '123' set with Amiri Regular with 'numr' feature turned on")
buf= harfbuzz.Buffer.new()
buf:add_utf8("123")
opts.features = "+numr"
harfbuzz.shape(amiri_font, buf, opts)
glyphs = buf:get_glyphs()
for k,v in pairs(glyphs) do
print(k)
for k1,v1 in pairs(v) do
print("",k1,v1)
end
end
\stopbuffer
The example:
\typebuffer[hbex]
\startbuffer[hbout]
Harfbuzz API version 2.6.4
Shapers: graphite2 ot fallback