@@ -379,18 +379,6 @@ cdef [[
379
379
} PS_FontInfoRec;
380
380
381
381
FT_Error FT_Get_PS_Font_Info(FT_Face face, PS_FontInfoRec *afont_info);
382
-
383
- enum {
384
- FT_FACE_FLAG_KERNING = 1 << 6
385
- };
386
-
387
- enum {
388
- FT_KERNING_DEFAULT = 0,
389
- FT_KERNING_UNFITTED = 1,
390
- FT_KERNING_UNSCALED = 2
391
- };
392
-
393
- FT_Error FT_Get_Kerning( FT_Face face, FT_UInt left_glyph, FT_UInt right_glyph, FT_UInt kern_mode, FT_Vector* akerning );
394
382
]]
395
383
396
384
-- Set C definitions for fontconfig
@@ -503,9 +491,9 @@ ass_glyph_embolden = (slot) ->
503
491
504
492
-- https://github.com/libass/libass/blob/5298859c298d3c570d8d7e3b883a0d63490659b8/libass/ass_font.c#L518
505
493
ass_face_is_postscript = ( face) ->
506
- postscript_info = new " PS_FontInfoRec[1]"
507
- err = freetype. FT_Get_PS_Font_Info face, postscript_info
508
- return err == 0
494
+ postscript_info = new " PS_FontInfoRec[1]"
495
+ err = freetype. FT_Get_PS_Font_Info face, postscript_info
496
+ return err == 0
509
497
510
498
-- https://github.com/libass/libass/blob/5298859c298d3c570d8d7e3b883a0d63490659b8/libass/ass_font.c#L611
511
499
ass_glyph_italicize = ( slot) ->
@@ -574,42 +562,42 @@ ass_get_glyph_outline = (face, has_underline, has_strikeout, addx, addy) ->
574
562
575
563
class FreeType extends Init
576
564
577
- init : =>
578
- unless has_freetype
579
- error " freetype library couldn't be loaded" , 2
565
+ init : =>
566
+ unless has_freetype
567
+ error " freetype library couldn't be loaded" , 2
580
568
581
- -- Check that the font has a bold and italic variant if necessary
582
- @found_bold , @found_italic = false , false
569
+ -- Check that the font has a bold and italic variant if necessary
570
+ @found_bold , @found_italic = false , false
583
571
584
- -- Get the font path
585
- font_path = @getFontPath !
586
- unless font_path
587
- error " Couldn't find #{@family} among your fonts"
572
+ -- Get the font path
573
+ font_path = @getFontPath !
574
+ unless font_path
575
+ error " Couldn't find #{@family} among your fonts"
588
576
589
- -- Init FreeType
590
- @library = new " FT_Library[1]"
591
- err = freetype. FT_Init_FreeType @library
577
+ -- Init FreeType
578
+ @library = new " FT_Library[1]"
579
+ err = freetype. FT_Init_FreeType @library
592
580
593
- if err != 0
594
- error " Failed to load freetype library"
581
+ if err != 0
582
+ error " Failed to load freetype library"
595
583
596
- ffi. gc @library , ( lib) -> freetype. FT_Done_FreeType lib[ 0 ]
584
+ ffi. gc @library , ( lib) -> freetype. FT_Done_FreeType lib[ 0 ]
597
585
598
- -- Load font face
599
- @face = new " FT_Face[1]"
600
- err = freetype. FT_New_Face @library [ 0 ] , font_path, 0 , @face
586
+ -- Load font face
587
+ @face = new " FT_Face[1]"
588
+ err = freetype. FT_New_Face @library [ 0 ] , font_path, 0 , @face
601
589
602
- if err != 0
603
- error " Failed to load freetype face"
590
+ if err != 0
591
+ error " Failed to load freetype face"
604
592
605
- ffi. gc @face , ( face) -> freetype. FT_Done_Face face[ 0 ]
593
+ ffi. gc @face , ( face) -> freetype. FT_Done_Face face[ 0 ]
606
594
607
- set_font_metrics @face [ 0 ]
608
- ass_face_set_size @face [ 0 ] , @size
595
+ set_font_metrics @face [ 0 ]
596
+ ass_face_set_size @face [ 0 ] , @size
609
597
610
- @ascender , @descender = ass_font_get_asc_desc @face [ 0 ]
611
- @height = @ascender + @descender
612
- @weight = tonumber ass_face_get_weight @face [ 0 ]
598
+ @ascender , @descender = ass_font_get_asc_desc @face [ 0 ]
599
+ @height = @ascender + @descender
600
+ @weight = tonumber ass_face_get_weight @face [ 0 ]
613
601
614
602
-- Callback to access the glyphs for each character
615
603
callBackChars : ( text, callback) =>
@@ -772,49 +760,49 @@ class FreeType extends Init
772
760
773
761
-- Gets the directory path of the fonts
774
762
getFontPath : =>
775
- fonts = @getFonts !
776
- font_variants = {}
763
+ fonts = @getFonts !
764
+ font_variants = {}
777
765
778
766
-- Collect all fonts matching the requested family
779
- for font in * fonts
780
- if font. name\ lower! == @family \ lower!
781
- table.insert font_variants, font
767
+ for font in * fonts
768
+ if font. name\ lower! == @family \ lower!
769
+ table.insert font_variants, font
782
770
783
- if # font_variants == 0
784
- return false
771
+ if # font_variants == 0
772
+ return false
785
773
786
774
style_preference = {
787
- [ " bold italic" ] : 1
788
- [ " bold oblique" ] : 2
789
- [ " italic" ] : 3
790
- [ " oblique" ] : 4
791
- [ " bold" ] : 5
792
- [ " regular" ] : 6
793
- [ " normal" ] : 7
794
- }
775
+ [ " bold italic" ] : 1
776
+ [ " bold oblique" ] : 2
777
+ [ " italic" ] : 3
778
+ [ " oblique" ] : 4
779
+ [ " bold" ] : 5
780
+ [ " regular" ] : 6
781
+ [ " normal" ] : 7
782
+ }
795
783
796
784
-- Sort fonts by style preference
797
- table.sort font_variants, ( a, b) ->
798
- a_style = a. style\ lower!
799
- b_style = b. style\ lower!
800
- a_pref = style_preference[ a_style] or 99
801
- b_pref = style_preference[ b_style] or 99
802
- return a_pref < b_pref
803
-
804
- -- Find the best match based on requested styles
805
- for font in * font_variants
806
- style = font. style\ lower!
807
- is_bold = style\ find( " bold" ) != nil
808
- is_italic = ( style\ find( " italic" ) or style\ find( " oblique" )) != nil
809
- if @bold == is_bold and @italic == is_italic
810
- @found_bold = is_bold
811
- @found_italic = is_italic
812
- return font. path
813
-
814
- -- If no exact match, return the first variant
815
- first_font = font_variants[ 1 ]
785
+ table.sort font_variants, ( a, b) ->
786
+ a_style = a. style\ lower!
787
+ b_style = b. style\ lower!
788
+ a_pref = style_preference[ a_style] or 99
789
+ b_pref = style_preference[ b_style] or 99
790
+ return a_pref < b_pref
791
+
792
+ -- Find the best match based on requested styles
793
+ for font in * font_variants
794
+ style = font. style\ lower!
795
+ is_bold = style\ find( " bold" ) != nil
796
+ is_italic = ( style\ find( " italic" ) or style\ find( " oblique" )) != nil
797
+ if @bold == is_bold and @italic == is_italic
798
+ @found_bold = is_bold
799
+ @found_italic = is_italic
800
+ return font. path
801
+
802
+ -- If no exact match, return the first variant
803
+ first_font = font_variants[ 1 ]
816
804
@found_bold = first_font. style\ lower!\ find( " bold" ) != nil
817
805
@found_italic = first_font. style\ lower!\ find( " italic" ) != nil or first_font. style\ lower!\ find( " oblique" ) != nil
818
- return first_font. path
806
+ return first_font. path
819
807
820
808
{ : FreeType }
0 commit comments