@@ -10,17 +10,19 @@ use std::{mem, ptr};
10
10
use app_units:: Au ;
11
11
use euclid:: default:: { Point2D , Rect , Size2D } ;
12
12
use freetype_sys:: {
13
- FT_Byte , FT_Done_Face , FT_Error , FT_F26Dot6 , FT_FACE_FLAG_COLOR , FT_FACE_FLAG_FIXED_SIZES ,
14
- FT_FACE_FLAG_SCALABLE , FT_Face , FT_Get_Char_Index , FT_Get_Kerning , FT_GlyphSlot , FT_Int32 ,
15
- FT_KERNING_DEFAULT , FT_LOAD_COLOR , FT_LOAD_DEFAULT , FT_LOAD_NO_HINTING , FT_Load_Glyph , FT_Long ,
16
- FT_New_Face , FT_New_Memory_Face , FT_Pos , FT_Select_Size , FT_Set_Char_Size , FT_Size_Metrics ,
17
- FT_SizeRec , FT_UInt , FT_ULong , FT_Vector ,
13
+ FT_Done_Face , FT_F26Dot6 , FT_FACE_FLAG_COLOR , FT_FACE_FLAG_FIXED_SIZES , FT_FACE_FLAG_SCALABLE ,
14
+ FT_Face , FT_Get_Char_Index , FT_Get_Kerning , FT_GlyphSlot , FT_Int32 , FT_KERNING_DEFAULT ,
15
+ FT_LOAD_COLOR , FT_LOAD_DEFAULT , FT_LOAD_NO_HINTING , FT_Load_Glyph , FT_Long , FT_New_Face ,
16
+ FT_New_Memory_Face , FT_Pos , FT_Select_Size , FT_Set_Char_Size , FT_Size_Metrics , FT_SizeRec ,
17
+ FT_UInt , FT_ULong , FT_Vector ,
18
18
} ;
19
19
use log:: debug;
20
20
use memmap2:: Mmap ;
21
21
use parking_lot:: ReentrantMutex ;
22
22
use read_fonts:: tables:: os2:: SelectionFlags ;
23
+ use read_fonts:: types:: Tag ;
23
24
use read_fonts:: { FontRef , ReadError , TableProvider } ;
25
+ use servo_arc:: Arc ;
24
26
use style:: Zero ;
25
27
use style:: computed_values:: font_stretch:: T as FontStretch ;
26
28
use style:: computed_values:: font_weight:: T as FontWeight ;
@@ -49,12 +51,17 @@ fn fixed_26_dot_6_to_float(fixed: FT_F26Dot6) -> f64 {
49
51
50
52
#[ derive( Debug ) ]
51
53
pub struct FontTable {
52
- buffer : Vec < u8 > ,
54
+ data : FreeTypeFaceTableProviderData ,
55
+ tag : Tag ,
53
56
}
54
57
55
58
impl FontTableMethods for FontTable {
56
59
fn buffer ( & self ) -> & [ u8 ] {
57
- & self . buffer
60
+ let font_ref = self . data . font_ref ( ) . expect ( "Font checked before creating" ) ;
61
+ let table_data = font_ref
62
+ . table_data ( self . tag )
63
+ . expect ( "Table existence checked before creating" ) ;
64
+ table_data. as_bytes ( )
58
65
}
59
66
}
60
67
@@ -164,7 +171,7 @@ impl PlatformFontMethods for PlatformFont {
164
171
requested_face_size,
165
172
actual_face_size,
166
173
table_provider_data : FreeTypeFaceTableProviderData :: Local (
167
- memory_mapped_font_data,
174
+ Arc :: new ( memory_mapped_font_data) ,
168
175
font_identifier. index ( ) ,
169
176
) ,
170
177
} )
@@ -393,22 +400,13 @@ impl PlatformFontMethods for PlatformFont {
393
400
}
394
401
395
402
fn table_for_tag ( & self , tag : FontTableTag ) -> Option < FontTable > {
396
- let face = self . face . lock ( ) ;
397
- let tag = tag as FT_ULong ;
398
-
399
- unsafe {
400
- // Get the length
401
- let mut len = 0 ;
402
- if 0 != FT_Load_Sfnt_Table ( * face, tag, 0 , ptr:: null_mut ( ) , & mut len) {
403
- return None ;
404
- }
405
- // Get the bytes
406
- let mut buf = vec ! [ 0u8 ; len as usize ] ;
407
- if 0 != FT_Load_Sfnt_Table ( * face, tag, 0 , buf. as_mut_ptr ( ) , & mut len) {
408
- return None ;
409
- }
410
- Some ( FontTable { buffer : buf } )
411
- }
403
+ let tag = Tag :: from_u32 ( tag) ;
404
+ let font_ref = self . table_provider_data . font_ref ( ) . ok ( ) ?;
405
+ let _table_data = font_ref. table_data ( tag) ?;
406
+ Some ( FontTable {
407
+ data : self . table_provider_data . clone ( ) ,
408
+ tag,
409
+ } )
412
410
}
413
411
414
412
fn typographic_bounds ( & self , glyph_id : GlyphId ) -> Rect < f32 > {
@@ -529,19 +527,10 @@ impl FreeTypeFaceHelpers for FT_Face {
529
527
}
530
528
}
531
529
532
- unsafe extern "C" {
533
- fn FT_Load_Sfnt_Table (
534
- face : FT_Face ,
535
- tag : FT_ULong ,
536
- offset : FT_Long ,
537
- buffer : * mut FT_Byte ,
538
- length : * mut FT_ULong ,
539
- ) -> FT_Error ;
540
- }
541
-
530
+ #[ derive( Clone ) ]
542
531
enum FreeTypeFaceTableProviderData {
543
532
Web ( FontData ) ,
544
- Local ( Mmap , u32 ) ,
533
+ Local ( Arc < Mmap > , u32 ) ,
545
534
}
546
535
547
536
impl FreeTypeFaceTableProviderData {
0 commit comments