@ -80,6 +80,14 @@ void DynamicFontData::set_force_autohinter(bool p_force) {
void DynamicFontData : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_font_path " , " path " ) , & DynamicFontData : : set_font_path ) ;
ClassDB : : bind_method ( D_METHOD ( " get_font_path " ) , & DynamicFontData : : get_font_path ) ;
ClassDB : : bind_method ( D_METHOD ( " set_hinting " , " mode " ) , & DynamicFontData : : set_hinting ) ;
ClassDB : : bind_method ( D_METHOD ( " get_hinting " ) , & DynamicFontData : : get_hinting ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " hinting " , PROPERTY_HINT_ENUM , " None,Light,Normal " ) , " set_hinting " , " get_hinting " ) ;
BIND_ENUM_CONSTANT ( HINTING_NONE ) ;
BIND_ENUM_CONSTANT ( HINTING_LIGHT ) ;
BIND_ENUM_CONSTANT ( HINTING_NORMAL ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " font_path " , PROPERTY_HINT_FILE , " *.ttf,*.otf " ) , " set_font_path " , " get_font_path " ) ;
}
@ -87,6 +95,7 @@ void DynamicFontData::_bind_methods() {
DynamicFontData : : DynamicFontData ( ) {
force_autohinter = false ;
hinting = DynamicFontData : : HINTING_NORMAL ;
font_mem = NULL ;
font_mem_size = 0 ;
}
@ -197,8 +206,6 @@ Error DynamicFontAtSize::_load() {
if ( id . filter )
texture_flags | = Texture : : FLAG_FILTER ;
//print_line("ASCENT: "+itos(ascent)+" descent "+itos(descent)+" hinted: "+itos(face->face_flags&FT_FACE_FLAG_HINTER));
valid = true ;
return OK ;
}
@ -431,15 +438,28 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
char_map [ p_char ] = ch ;
return ;
}
int error = FT_Load_Char ( face , p_char , FT_LOAD_RENDER | ( font - > force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0 ) ) ;
int ft_hinting ;
switch ( font - > hinting ) {
case DynamicFontData : : HINTING_NONE :
ft_hinting = FT_LOAD_NO_HINTING ;
break ;
case DynamicFontData : : HINTING_LIGHT :
ft_hinting = FT_LOAD_TARGET_LIGHT ;
break ;
default :
ft_hinting = FT_LOAD_TARGET_NORMAL ;
break ;
}
int error = FT_Load_Char ( face , p_char , FT_HAS_COLOR ( face ) ? FT_LOAD_COLOR : FT_LOAD_DEFAULT | ( font - > force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0 ) | ft_hinting ) ;
if ( ! error ) {
error = FT_Render_Glyph ( face - > glyph , ft_render_mode_normal ) ;
}
if ( error ) {
int advance = 0 ;
//stbtt_GetCodepointHMetrics(&font->info, p_char, &advance, 0);
//print_line("char has no bitmap: "+itos(p_char)+" but advance is "+itos(advance*scale));
Character ch ;
ch . texture_idx = - 1 ;
ch . advance = advance ;
@ -454,7 +474,6 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
int w = slot - > bitmap . width ;
int h = slot - > bitmap . rows ;
//int p = slot->bitmap.pitch;
int yofs = slot - > bitmap_top ;
int xofs = slot - > bitmap_left ;
int advance = slot - > advance . x > > 6 ;
@ -508,8 +527,6 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
break ;
}
//print_line("CHAR: "+String::chr(p_char)+" TEX INDEX: "+itos(tex_index)+" X: "+itos(tex_x)+" Y: "+itos(tex_y));
if ( tex_index = = - 1 ) {
//could not find texture to fit, create one
tex_x = 0 ;
@ -610,8 +627,6 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
chr . rect . position / = oversampling ;
chr . rect . size / = oversampling ;
//print_line("CHAR: "+String::chr(p_char)+" TEX INDEX: "+itos(tex_index)+" RECT: "+chr.rect+" X OFS: "+itos(xofs)+" Y OFS: "+itos(yofs));
char_map [ p_char ] = chr ;
}
@ -722,6 +737,18 @@ void DynamicFont::set_use_filter(bool p_enable) {
_reload_cache ( ) ;
}
DynamicFontData : : Hinting DynamicFontData : : get_hinting ( ) const {
return hinting ;
}
void DynamicFontData : : set_hinting ( Hinting p_hinting ) {
if ( hinting = = p_hinting )
return ;
hinting = p_hinting ;
}
int DynamicFont : : get_spacing ( int p_type ) const {
if ( p_type = = SPACING_TOP ) {