Skip to content

Commit 684319c

Browse files
committed
Update ILL
1 parent 297003d commit 684319c

File tree

2 files changed

+58
-34
lines changed

2 files changed

+58
-34
lines changed

modules/ILL/ILL.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module_version = "1.4.8"
1+
module_version = "1.4.9"
22

33
haveDepCtrl, DependencyControl = pcall require, "l0.DependencyControl"
44

modules/ILL/ILL/Font/Unx.moon

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ffi = require "ffi"
33
has_freetype, freetype = pcall ffi.load, "freetype"
44
has_fontconfig, fontconfig = pcall ffi.load, "fontconfig"
55

6-
import C, cdef, gc, new from ffi
6+
import C, cast, cdef, gc, new from ffi
77

88
-- Set C definitions for freetype / taken from https://github.com/luapower/freetype/blob/master/freetype_h.lua
99
cdef [[
@@ -392,7 +392,7 @@ set_font_metrics = (face) ->
392392
-- Mimicking GDI's behavior for asc/desc/height.
393393
-- These fields are (apparently) sometimes used for signed values,
394394
-- despite being unsigned in the spec.
395-
os2 = ffi.cast "TT_OS2*", C.FT_Get_Sfnt_Table face, C.FT_SFNT_OS2
395+
os2 = cast "TT_OS2*", C.FT_Get_Sfnt_Table face, C.FT_SFNT_OS2
396396
if os2 and (tonumber(os2.usWinAscent) + tonumber(os2.usWinDescent) != 0)
397397
face.ascender = tonumber os2.usWinAscent
398398
face.descender = -tonumber os2.usWinDescent
@@ -420,9 +420,9 @@ set_font_metrics = (face) ->
420420

421421
-- https://github.com/libass/libass/blob/17cb8da964c852835881658d0d7af35ef2d92f9e/libass/ass_font.c#L502
422422
ass_face_set_size = (face, size) ->
423-
rq = ffi.new "FT_Size_RequestRec"
424-
ffi.C.memset rq, 0, ffi.sizeof rq
425-
rq.type = ffi.C.FT_SIZE_REQUEST_TYPE_REAL_DIM
423+
rq = new "FT_Size_RequestRec"
424+
C.memset rq, 0, ffi.sizeof rq
425+
rq.type = C.FT_SIZE_REQUEST_TYPE_REAL_DIM
426426
rq.width = 0
427427
rq.height = size * FONT_UPSCALE
428428
rq.horiResolution = 0
@@ -438,7 +438,7 @@ ass_font_get_asc_desc = (face) ->
438438

439439
-- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3/libass/ass_font.c#L516
440440
ass_face_get_weight = (face) ->
441-
os2 = ffi.cast "TT_OS2*", freetype.FT_Get_Sfnt_Table face, C.FT_SFNT_OS2
441+
os2 = cast "TT_OS2*", freetype.FT_Get_Sfnt_Table face, C.FT_SFNT_OS2
442442
os2Weight = os2 and tonumber(os2.usWeightClass) or 0
443443
styleFlags = tonumber face.style_flags
444444
if os2Weight == 0
@@ -450,14 +450,14 @@ ass_face_get_weight = (face) ->
450450

451451
-- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3/libass/ass_font.c#L561
452452
ass_glyph_embolden = (slot) ->
453-
if slot.format != ffi.C.FT_GLYPH_FORMAT_OUTLINE
453+
if slot.format != C.FT_GLYPH_FORMAT_OUTLINE
454454
return
455455
str = freetype.FT_MulFix(slot.face.units_per_EM, slot.face.size.metrics.y_scale) / FONT_UPSCALE
456456
freetype.FT_Outline_Embolden slot.outline, str
457457

458458
-- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3/libass/ass_font.c#L577
459459
ass_glyph_italicize = (slot) ->
460-
xfrm = ffi.new "FT_Matrix", {
460+
xfrm = new "FT_Matrix", {
461461
xx: 0x10000
462462
xy: 0x05700
463463
yx: 0x00000
@@ -480,21 +480,22 @@ class FreeType extends Init
480480
error "Couldn't find #{@family} among your fonts"
481481

482482
-- Init FreeType
483-
@library = ffi.new "FT_Library[1]"
483+
@library = new "FT_Library[1]"
484484
err = freetype.FT_Init_FreeType @library
485485

486486
if err != 0
487487
error "Failed to load freetype library"
488488

489489
-- Load font face
490-
@face = ffi.new "FT_Face[1]"
490+
@face = new "FT_Face[1]"
491491
err = freetype.FT_New_Face @library[0], font_path, 0, @face
492492

493493
if err != 0
494494
error "Failed to load freetype face"
495495

496496
set_font_metrics @face[0]
497497
ass_face_set_size @face[0], @size
498+
498499
@ascender, @descender = ass_font_get_asc_desc @face[0]
499500
@height = @ascender + @descender
500501
@weight = tonumber ass_face_get_weight @face[0]
@@ -505,7 +506,7 @@ class FreeType extends Init
505506
width, height = 0, 0
506507
for ci, char in UTF8(text)\chars!
507508
glyph_index = freetype.FT_Get_Char_Index face_size, UTF8.charcodepoint char
508-
err = freetype.FT_Load_Glyph face_size, glyph_index, ffi.C.FT_LOAD_DEFAULT
509+
err = freetype.FT_Load_Glyph face_size, glyph_index, C.FT_LOAD_DEFAULT
509510
if err != 0
510511
error "Failed to load the freetype glyph", 2
511512
callback ci, char, face_size.glyph
@@ -545,25 +546,47 @@ class FreeType extends Init
545546
for i = 0, glyph.outline.n_points - 1
546547
glyph.outline.points[i].x += x
547548
glyph.outline.points[i].y = (glyph.outline.points[i].y * -1) + @ascender * FONT_UPSCALE
548-
-- callbacks for point decomposition
549+
-- callbacks for outline decomposition
549550
move_to = (to, user) ->
550-
table.insert build, {"m", tonumber(to.x) / FONT_UPSCALE, tonumber(to.y) / FONT_UPSCALE}
551+
table.insert build, {
552+
"m"
553+
tonumber(to.x) * FONT_DOWNSCALE
554+
tonumber(to.y) * FONT_DOWNSCALE
555+
}
551556
return 0
552557
line_to = (to, user) ->
553-
table.insert build, {"l", tonumber(to.x) / FONT_UPSCALE, tonumber(to.y) / FONT_UPSCALE}
558+
table.insert build, {
559+
"l"
560+
tonumber(to.x) * FONT_DOWNSCALE
561+
tonumber(to.y) * FONT_DOWNSCALE
562+
}
554563
return 0
555564
conic_to = (control, to, user) ->
556-
table.insert build, {"c", tonumber(control.x) / FONT_UPSCALE, tonumber(control.y) / FONT_UPSCALE, tonumber(to.x) / FONT_UPSCALE, tonumber(to.y) / FONT_UPSCALE}
565+
table.insert build, {
566+
"c"
567+
tonumber(control.x) * FONT_DOWNSCALE
568+
tonumber(control.y) * FONT_DOWNSCALE
569+
tonumber(to.x) * FONT_DOWNSCALE
570+
tonumber(to.y) * FONT_DOWNSCALE
571+
}
557572
return 0
558573
cubic_to = (control1, control2, to, user) ->
559-
table.insert build, {"b", tonumber(control1.x) / FONT_UPSCALE, tonumber(control1.y) / FONT_UPSCALE, tonumber(control2.x) / FONT_UPSCALE, tonumber(control2.y) / FONT_UPSCALE, tonumber(to.x) / FONT_UPSCALE, tonumber(to.y) / FONT_UPSCALE}
574+
table.insert build, {
575+
"b"
576+
tonumber(control1.x) * FONT_DOWNSCALE
577+
tonumber(control1.y) * FONT_DOWNSCALE
578+
tonumber(control2.x) * FONT_DOWNSCALE
579+
tonumber(control2.y) * FONT_DOWNSCALE
580+
tonumber(to.x) * FONT_DOWNSCALE
581+
tonumber(to.y) * FONT_DOWNSCALE
582+
}
560583
return 0
561584
-- Define outline functions
562-
outline_funcs = ffi.new "FT_Outline_Funcs[1]"
563-
outline_funcs[0].move_to = ffi.cast "FT_Outline_MoveToFunc", move_to
564-
outline_funcs[0].line_to = ffi.cast "FT_Outline_LineToFunc", line_to
565-
outline_funcs[0].conic_to = ffi.cast "FT_Outline_ConicToFunc", conic_to
566-
outline_funcs[0].cubic_to = ffi.cast "FT_Outline_CubicToFunc", cubic_to
585+
outline_funcs = new "FT_Outline_Funcs[1]"
586+
outline_funcs[0].move_to = cast "FT_Outline_MoveToFunc", move_to
587+
outline_funcs[0].line_to = cast "FT_Outline_LineToFunc", line_to
588+
outline_funcs[0].conic_to = cast "FT_Outline_ConicToFunc", conic_to
589+
outline_funcs[0].cubic_to = cast "FT_Outline_CubicToFunc", cubic_to
567590
-- Decompose outline
568591
err = freetype.FT_Outline_Decompose glyph.outline, outline_funcs, nil
569592
if err != 0
@@ -592,36 +615,37 @@ class FreeType extends Init
592615
x += tonumber(glyph.metrics.horiAdvance) + (@hspace * FONT_UPSCALE)
593616
return table.concat paths, " "
594617

618+
-- Gets the complete list of fonts available on the system
595619
getFonts: =>
596620
-- Check whether or not the fontconfig library was loaded
597621
unless has_fontconfig
598622
error "fontconfig library couldn't be loaded", 2
599623
-- Get fonts list from fontconfig
600-
fontset = ffi.gc fontconfig.FcFontList(fontconfig.FcInitLoadConfigAndFonts(), ffi.gc(fontconfig.FcPatternCreate(), fontconfig.FcPatternDestroy), ffi.gc(fontconfig.FcObjectSetBuild("family", "fullname", "style", "outline", "file", nil), fontconfig.FcObjectSetDestroy)),fontconfig.FcFontSetDestroy
624+
fontset = ffi.gc fontconfig.FcFontList(fontconfig.FcInitLoadConfigAndFonts(), ffi.gc(fontconfig.FcPatternCreate(), fontconfig.FcPatternDestroy), ffi.gc(fontconfig.FcObjectSetBuild("family", "fullname", "style", "outline", "file", nil), fontconfig.FcObjectSetDestroy)), fontconfig.FcFontSetDestroy
601625
local font, family, fullname, style, outline, file, cstr, cbool
602-
cstr = ffi.new "FcChar8*[1]"
603-
cbool = ffi.new "FcBool[1]"
626+
cstr = new "FcChar8*[1]"
627+
cbool = new "FcBool[1]"
604628
fonts = {n: 0}
605629
for i = 0, fontset[0].nfont - 1
606630
font = fontset[0].fonts[i]
607631
family, fullname, style, outline, file = nil, nil, nil, nil, nil
608-
if fontconfig.FcPatternGetString(font, "family", 0, cstr) == ffi.C.FcResultMatchILL
632+
if fontconfig.FcPatternGetString(font, "family", 0, cstr) == C.FcResultMatchILL
609633
family = ffi.string cstr[0]
610-
if fontconfig.FcPatternGetString(font, "fullname", 0, cstr) == ffi.C.FcResultMatchILL
634+
if fontconfig.FcPatternGetString(font, "fullname", 0, cstr) == C.FcResultMatchILL
611635
fullname = ffi.string cstr[0]
612-
if fontconfig.FcPatternGetString(font, "style", 0, cstr) == ffi.C.FcResultMatchILL
636+
if fontconfig.FcPatternGetString(font, "style", 0, cstr) == C.FcResultMatchILL
613637
style = ffi.string cstr[0]
614-
if fontconfig.FcPatternGetBool(font, "outline", 0, cbool) == ffi.C.FcResultMatchILL
638+
if fontconfig.FcPatternGetBool(font, "outline", 0, cbool) == C.FcResultMatchILL
615639
outline = cbool[0]
616-
if fontconfig.FcPatternGetString(font, "file", 0, cstr) == ffi.C.FcResultMatchILL
640+
if fontconfig.FcPatternGetString(font, "file", 0, cstr) == C.FcResultMatchILL
617641
file = ffi.string cstr[0]
618642
if family and fullname and style and outline
619643
fonts.n += 1
620644
fonts[fonts.n] = {
621-
name: family,
622-
longname: fullname,
623-
style: style,
624-
type: outline == 0 and "Raster" or "Outline",
645+
name: family
646+
longname: fullname
647+
style: style
648+
type: outline == 0 and "Raster" or "Outline"
625649
path: file
626650
}
627651
-- Order fonts by name & style

0 commit comments

Comments
 (0)