@@ -357,22 +357,21 @@ cdef [[
357
357
int nobject;
358
358
int sobject;
359
359
const char** objects;
360
- }FcObjectSet;
360
+ } FcObjectSet;
361
361
typedef struct{
362
362
int nfont;
363
363
int sfont;
364
364
FcPattern** fonts;
365
- }FcFontSet;
365
+ } FcFontSet;
366
366
typedef enum{
367
- FcResultMatch ,
368
- FcResultNoMatch ,
369
- FcResultTypeMismatch ,
370
- FcResultNoId ,
371
- FcResultOutOfMemory
372
- }FcResult;
367
+ FcResultMatchILL ,
368
+ FcResultNoMatchILL ,
369
+ FcResultTypeMismatchILL ,
370
+ FcResultNoIdILL ,
371
+ FcResultOutOfMemoryILL
372
+ } FcResult;
373
373
typedef unsigned char FcChar8;
374
374
typedef int FcBool;
375
-
376
375
FcConfig* FcInitLoadConfigAndFonts(void);
377
376
FcPattern* FcPatternCreate(void);
378
377
void FcPatternDestroy(FcPattern*);
@@ -388,84 +387,83 @@ import Math from require "ILL.ILL.Math"
388
387
import UTF8 from require " ILL.ILL.UTF8"
389
388
import Init from require " ILL.ILL.Font.Init"
390
389
391
- -- https://github.com/libass/libass/blob/17cb8da964c852835881658d0d7af35ef2d92f9e /libass/ass_font.c#L502
390
+ -- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3 /libass/ass_font.c#L277
392
391
set_font_metrics = ( face) ->
393
- -- Mimicking GDI's behavior for asc/desc/height.
394
- -- These fields are (apparently) sometimes used for signed values,
395
- -- despite being unsigned in the spec.
396
- os2 = ffi. cast " TT_OS2*" , C . FT_Get_Sfnt_Table face, C . FT_SFNT_OS2
397
- if os2 and ( tonumber ( os2. usWinAscent) + tonumber ( os2. usWinDescent) != 0 )
398
- face. ascender = tonumber os2. usWinAscent
399
- face. descender = - tonumber os2. usWinDescent
400
- face. height = face. ascender - face. descender
401
-
402
- -- If we didn't have usable Win values in the OS/2 table,
403
- -- then the values from FreeType will still be in these fields.
404
- -- It'll use either the OS/2 typo metrics or the hhea ones.
405
- -- If the font has typo metrics but FreeType didn't use them
406
- -- (either old FT or USE_TYPO_METRICS not set), we'll try those.
407
- -- In the case of a very broken font that has none of those options,
408
- -- we fall back on using face.bbox.
409
- -- Anything without valid OS/2 Win values isn't supported by VSFilter,
410
- -- so at this point compatibility's out the window and we're just
411
- -- trying to render _something_ readable.
412
- if face. ascender - face. descender == 0 or face. height == 0
413
- if os2 and ( tonumber ( os2. sTypoAscender) - tonumber ( os2. sTypoDescender) != 0 )
414
- face. ascender = tonumber os2. sTypoAscender
415
- face. descender = tonumber os2. sTypoDescender
416
- face. height = face. ascender - face. descender
417
- else
418
- face. ascender = tonumber face. bbox. yMax
419
- face. descender = tonumber face. bbox. yMin
420
- face. height = face. ascender - face. descender
392
+ -- Mimicking GDI's behavior for asc/desc/height.
393
+ -- These fields are (apparently) sometimes used for signed values,
394
+ -- despite being unsigned in the spec.
395
+ os2 = ffi. cast " TT_OS2*" , C . FT_Get_Sfnt_Table face, C . FT_SFNT_OS2
396
+ if os2 and ( tonumber ( os2. usWinAscent) + tonumber ( os2. usWinDescent) != 0 )
397
+ face. ascender = tonumber os2. usWinAscent
398
+ face. descender = - tonumber os2. usWinDescent
399
+ face. height = face. ascender - face. descender
400
+
401
+ -- If we didn't have usable Win values in the OS/2 table,
402
+ -- then the values from FreeType will still be in these fields.
403
+ -- It'll use either the OS/2 typo metrics or the hhea ones.
404
+ -- If the font has typo metrics but FreeType didn't use them
405
+ -- (either old FT or USE_TYPO_METRICS not set), we'll try those.
406
+ -- In the case of a very broken font that has none of those options,
407
+ -- we fall back on using face.bbox.
408
+ -- Anything without valid OS/2 Win values isn't supported by VSFilter,
409
+ -- so at this point compatibility's out the window and we're just
410
+ -- trying to render _something_ readable.
411
+ if face. ascender - face. descender == 0 or face. height == 0
412
+ if os2 and ( tonumber ( os2. sTypoAscender) - tonumber ( os2. sTypoDescender) != 0 )
413
+ face. ascender = tonumber os2. sTypoAscender
414
+ face. descender = tonumber os2. sTypoDescender
415
+ face. height = face. ascender - face. descender
416
+ else
417
+ face. ascender = tonumber face. bbox. yMax
418
+ face. descender = tonumber face. bbox. yMin
419
+ face. height = face. ascender - face. descender
421
420
422
421
-- https://github.com/libass/libass/blob/17cb8da964c852835881658d0d7af35ef2d92f9e/libass/ass_font.c#L502
423
422
ass_face_set_size = ( face, size) ->
424
- rq = ffi. new " FT_Size_RequestRec"
425
- ffi. C . memset rq, 0 , ffi. sizeof rq
426
- rq. type = ffi. C . FT_SIZE_REQUEST_TYPE_REAL_DIM
427
- rq. width = 0
428
- rq. height = size * FONT_UPSCALE
429
- rq. horiResolution = 0
430
- rq. vertResolution = 0
431
- freetype. FT_Request_Size face, rq
432
-
433
- -- https://github.com/libass/libass/blob/17cb8da964c852835881658d0d7af35ef2d92f9e /libass/ass_font.c#L502
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
426
+ rq. width = 0
427
+ rq. height = size * FONT_UPSCALE
428
+ rq. horiResolution = 0
429
+ rq. vertResolution = 0
430
+ freetype. FT_Request_Size face, rq
431
+
432
+ -- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3 /libass/ass_font.c#L502
434
433
ass_font_get_asc_desc = ( face) ->
435
434
y_scale = face. size. metrics. y_scale
436
435
ascender = freetype. FT_MulFix face. ascender, y_scale
437
436
descender = freetype. FT_MulFix - face. descender, y_scale
438
437
return tonumber ( ascender) / FONT_UPSCALE , tonumber ( descender) / FONT_UPSCALE
439
438
439
+ -- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3/libass/ass_font.c#L516
440
440
ass_face_get_weight = ( face) ->
441
- os2 = ffi. cast " TT_OS2*" , freetype. FT_Get_Sfnt_Table face, C . FT_SFNT_OS2
442
- os2Weight = os2 and tonumber ( os2. usWeightClass) or 0
443
- styleFlags = tonumber face. style_flags
444
- if os2Weight == 0
445
- return 300 * ( styleFlags != 0x1 ) + 400
446
- elseif os2Weight >= 1 and os2Weight <= 9
447
- return os2Weight * 100
448
- else
449
- return os2Weight
450
-
451
- -- https://github.com/libass/libass/blob/ffe070bbfbc77e3ab731aac5ec24fa63aeb461af /libass/ass_font.c#L561C1-L572C2
441
+ os2 = ffi. cast " TT_OS2*" , freetype. FT_Get_Sfnt_Table face, C . FT_SFNT_OS2
442
+ os2Weight = os2 and tonumber ( os2. usWeightClass) or 0
443
+ styleFlags = tonumber face. style_flags
444
+ if os2Weight == 0
445
+ return 300 * ( styleFlags != 0x1 ) + 400
446
+ elseif os2Weight >= 1 and os2Weight <= 9
447
+ return os2Weight * 100
448
+ else
449
+ return os2Weight
450
+
451
+ -- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3 /libass/ass_font.c#L561
452
452
ass_glyph_embolden = ( slot) ->
453
- if slot. format != ffi. C . FT_GLYPH_FORMAT_OUTLINE
454
- return
455
- str = freetype. FT_MulFix ( slot. face. units_per_EM, slot. face. size. metrics. y_scale) / FONT_UPSCALE
456
- freetype. FT_Outline_Embolden slot. outline, str
457
- return
453
+ if slot. format != ffi. C . FT_GLYPH_FORMAT_OUTLINE
454
+ return
455
+ str = freetype. FT_MulFix ( slot. face. units_per_EM, slot. face. size. metrics. y_scale) / FONT_UPSCALE
456
+ freetype. FT_Outline_Embolden slot. outline, str
458
457
459
- -- https://github.com/libass/libass/blob/ffe070bbfbc77e3ab731aac5ec24fa63aeb461af /libass/ass_font.c#L577
458
+ -- https://github.com/libass/libass/blob/db83d6770ba11cb9ef72f4a9de7a0e2b1dd7baa3 /libass/ass_font.c#L577
460
459
ass_glyph_italicize = ( slot) ->
461
- xfrm = ffi. new " FT_Matrix" , {
462
- xx : 0x10000
463
- xy : 0x05700
464
- yx : 0x00000
465
- yy : 0x10000
466
- }
467
- freetype. FT_Outline_Transform slot. outline, xfrm
468
- return
460
+ xfrm = ffi. new " FT_Matrix" , {
461
+ xx : 0x10000
462
+ xy : 0x05700
463
+ yx : 0x00000
464
+ yy : 0x10000
465
+ }
466
+ freetype. FT_Outline_Transform slot. outline, xfrm
469
467
470
468
class FreeType extends Init
471
469
@@ -519,7 +517,7 @@ class FreeType extends Init
519
517
ascent : @ascender * @yscale
520
518
descent : @descender * @yscale
521
519
height : @height * @yscale
522
- internal_leading : @ascender - @descender - ( @face [ 0 ] . units_per_EM / FONT_UPSCALE )
520
+ internal_leading : ( @ascender - @descender - ( @face [ 0 ] . units_per_EM / FONT_UPSCALE )) * @yscale
523
521
external_leading : 0
524
522
}
525
523
@@ -529,7 +527,7 @@ class FreeType extends Init
529
527
@callBackChars text, ( ci, char, glyph) ->
530
528
width += tonumber ( glyph. metrics. horiAdvance) + ( ci > 1 and @hspace * FONT_UPSCALE or 0 )
531
529
{
532
- width : width / FONT_UPSCALE
530
+ width : ( width / FONT_UPSCALE ) * @xscale
533
531
height : @height * @yscale
534
532
}
535
533
@@ -570,6 +568,11 @@ class FreeType extends Init
570
568
err = freetype. FT_Outline_Decompose glyph. outline, outline_funcs, nil
571
569
if err != 0
572
570
error " Failed to load the freetype outline decompose" , 2
571
+ -- Frees up memory stored for callbacks
572
+ outline_funcs[ 0 ] . move_to\ free!
573
+ outline_funcs[ 0 ] . line_to\ free!
574
+ outline_funcs[ 0 ] . conic_to\ free!
575
+ outline_funcs[ 0 ] . cubic_to\ free!
573
576
-- Converts quadratic curves to bezier
574
577
for i = 1 , # build
575
578
val = build[ i]
@@ -602,15 +605,15 @@ class FreeType extends Init
602
605
for i = 0 , fontset[ 0 ] . nfont - 1
603
606
font = fontset[ 0 ] . fonts[ i]
604
607
family, fullname, style, outline, file = nil , nil , nil , nil , nil
605
- if fontconfig. FcPatternGetString ( font, " family" , 0 , cstr) == ffi. C . FcResultMatch
608
+ if fontconfig. FcPatternGetString ( font, " family" , 0 , cstr) == ffi. C . FcResultMatchILL
606
609
family = ffi. string cstr[ 0 ]
607
- if fontconfig. FcPatternGetString ( font, " fullname" , 0 , cstr) == ffi. C . FcResultMatch
610
+ if fontconfig. FcPatternGetString ( font, " fullname" , 0 , cstr) == ffi. C . FcResultMatchILL
608
611
fullname = ffi. string cstr[ 0 ]
609
- if fontconfig. FcPatternGetString ( font, " style" , 0 , cstr) == ffi. C . FcResultMatch
612
+ if fontconfig. FcPatternGetString ( font, " style" , 0 , cstr) == ffi. C . FcResultMatchILL
610
613
style = ffi. string cstr[ 0 ]
611
- if fontconfig. FcPatternGetBool ( font, " outline" , 0 , cbool) == ffi. C . FcResultMatch
614
+ if fontconfig. FcPatternGetBool ( font, " outline" , 0 , cbool) == ffi. C . FcResultMatchILL
612
615
outline = cbool[ 0 ]
613
- if fontconfig. FcPatternGetString ( font, " file" , 0 , cstr) == ffi. C . FcResultMatch
616
+ if fontconfig. FcPatternGetString ( font, " file" , 0 , cstr) == ffi. C . FcResultMatchILL
614
617
file = ffi. string cstr[ 0 ]
615
618
if family and fullname and style and outline
616
619
fonts. n += 1
0 commit comments