package provide Freetype::ftautoh 0.1

if {![info exists _source([file tail [info script]])]} {
package require Freetype::ft2build
package require $FT_FREETYPE
package require $FT_MODULE

set FT_AUTOHINTER_SCRIPT_NONE   0
set FT_AUTOHINTER_SCRIPT_LATIN  1
set FT_AUTOHINTER_SCRIPT_CJK    2
set FT_AUTOHINTER_SCRIPT_INDIC  3

ft::struct define FT_Prop_GlyphToScriptMap {
    {face object * FT_Face 1 pointer}
    {map  int    * pointer 1 pointer}
}

oo::define FT_Prop_GlyphToScriptMap method get {varName} {
    if {$varName eq "map"} {
        set ptr [next $varName]
        if {$ptr eq 0} {return {}}
        set face [my get face]
        if {$face == {}} {return {}}
        set num [$face get num_glyphs]
        set bin [::ft::_bytearray_from_address $ptr FT_Byte $num]
        return [::ft::_bytearray_to_list $bin FT_Byte]
    }
    next $varName
}

oo::define FT_Prop_GlyphToScriptMap method set {varName varValue} {
    if {$varName eq "map"} {
        set ptr [my get $varName]
        if {$ptr == 0 || $ptr == {}} {return {}}
        set face [my get face]
        if {$face == {}} {return {}}
        set num [$face get num_glyphs]
        
        if {[llength $varValue] > $num} {
            set varValue [lrange $varValue 0 $num-1]
        }
        set bin [::ft::_bytearray_from_list $varValue FT_Byte]
        ::ft::get_bytearray_pointer bin adr len
        ::ft::memcpy $ptr $adr $len
        return [my get map]
    }
    next $varName $varValue
}



ft::struct define FT_Prop_IncreaseXHeight {
    {face  object * FT_Face 1 pointer}
    {limit int    - FT_UInt 1 FT_UInt}
}

set _source([file tail [info script]]) 1
}
